changeset 52914:c40c92b3249b amber-demo

Automatic merge with datum
author mcimadamore
date Wed, 24 Oct 2018 23:15:33 +0200
parents 334332456aa1 2b7b9c2711b3
children 7d3c741eb854
files
diffstat 5 files changed, 60 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/classfile/classFileParser.cpp	Wed Oct 24 20:50:34 2018 +0200
+++ b/src/hotspot/share/classfile/classFileParser.cpp	Wed Oct 24 23:15:33 2018 +0200
@@ -3314,6 +3314,13 @@
     const Symbol* const sig = cp->symbol_at(signature_index);
     // DEBUG
     // tty->print_cr("signature read %s", sig->as_klass_external_name());
+
+    RecordParamInfo* const record_param_info = RecordParamInfo::from_record_params_array(record_params_array, n);
+    record_param_info->initialize(
+                      access_flags.as_short(),
+                      name_index,
+                      descriptor_index,
+                      signature_index);
   }
 
   assert(NULL == _record_params, "invariant");
--- a/src/hotspot/share/oops/instanceKlass.hpp	Wed Oct 24 20:50:34 2018 +0200
+++ b/src/hotspot/share/oops/instanceKlass.hpp	Wed Oct 24 23:15:33 2018 +0200
@@ -434,7 +434,7 @@
   friend class fieldDescriptor;
   FieldInfo* field(int index) const { return FieldInfo::from_field_array(_fields, index); }
 
-  RecordParamInfo* record_param(int index) const { return RecordParamInfo::from_record_params_array(_fields, index); }
+  RecordParamInfo* record_param(int index) const { return RecordParamInfo::from_record_params_array(_record_params, index); }
 
  public:
   int     field_offset      (int index) const { return field(index)->offset(); }
--- a/src/hotspot/share/oops/recordParamInfo.hpp	Wed Oct 24 20:50:34 2018 +0200
+++ b/src/hotspot/share/oops/recordParamInfo.hpp	Wed Oct 24 23:15:33 2018 +0200
@@ -61,10 +61,20 @@
   static RecordParamInfo* from_record_params_array(Array<u2>* record_params, int index) {
     return ((RecordParamInfo*)record_params->adr_at(index * param_slots));
   }
-  static RecordParamInfo* from_record_param_array(u2* record_params, int index) {
+  static RecordParamInfo* from_record_params_array(u2* record_params, int index) {
     return ((RecordParamInfo*)(record_params + index * param_slots));
   }
 
+  void initialize(u2 access_flags,
+                  u2 name_index,
+                  u2 descriptor_index,
+                  u2 signature_index) {
+    _shorts[access_flags_offset] = access_flags;
+    _shorts[name_index_offset] = name_index;
+    _shorts[descriptor_index_offset] = descriptor_index;
+    _shorts[signature_index_offset] = signature_index;
+  }
+
   u2 access_flags() const                                   { return _shorts[access_flags_offset];      }
   Symbol* name(const constantPoolHandle& cp) const          { return cp->symbol_at(name_index());       }
   Symbol* signature(const constantPoolHandle& cp) const     { return cp->symbol_at(signature_index());  }
--- a/src/hotspot/share/prims/jvm.cpp	Wed Oct 24 20:50:34 2018 +0200
+++ b/src/hotspot/share/prims/jvm.cpp	Wed Oct 24 23:15:33 2018 +0200
@@ -1809,40 +1809,27 @@
 
   // Allocate result
   int num_record_params = k->record_params_count();
+  Array<u2>* record_parameters = k->record_params();
+  // DEBUG
+  //tty->print_cr("num_record_params == %d", num_record_params);
+
   if (num_record_params == 0) {
     oop res = oopFactory::new_objArray(SystemDictionary::reflect_Field_klass(), 0, CHECK_NULL);
     return (jobjectArray) JNIHandles::make_local(env, res);
   }
 
-  // all record components are public
-  int num_of_public_fields = 0;
-  for (JavaFieldStream fileStream(k); !fileStream.done(); fileStream.next()) {
-    if (fileStream.access_flags().is_public()) ++num_of_public_fields;
-  }
-
   objArrayOop r = oopFactory::new_objArray(SystemDictionary::reflect_Field_klass(), num_record_params, CHECK_NULL);
   objArrayHandle result (THREAD, r);
 
   int out_idx = 0;
   fieldDescriptor fd;
-  if (num_record_params == num_of_public_fields) {
-    // all the fields are record components so just return the fields
+  for (JavaRecordParameterStream recordParamsStream(k); !recordParamsStream.done(); recordParamsStream.next()) {
     for (JavaFieldStream fileStream(k); !fileStream.done(); fileStream.next()) {
-      fd.reinitialize(k, fileStream.index());
-      oop field = Reflection::new_field(&fd, CHECK_NULL);
-      result->obj_at_put(out_idx, field);
-      ++out_idx;
-    }
-  } else {
-    // it gets a bit more complicated some fields are record params and some not
-    for (JavaRecordParameterStream recordParamsStream(k); !recordParamsStream.done(); recordParamsStream.next()) {
-      for (JavaFieldStream fileStream(k); !fileStream.done(); fileStream.next()) {
-        if (fileStream.name() == recordParamsStream.name()) {
-          fd.reinitialize(k, fileStream.index());
-          oop field = Reflection::new_field(&fd, CHECK_NULL);
-          result->obj_at_put(out_idx, field);
-          ++out_idx;
-        }
+      if (fileStream.name() == recordParamsStream.name()) {
+        fd.reinitialize(k, fileStream.index());
+        oop field = Reflection::new_field(&fd, CHECK_NULL);
+        result->obj_at_put(out_idx, field);
+        ++out_idx;
       }
     }
   }
--- a/src/java.base/share/classes/java/lang/Class.java	Wed Oct 24 20:50:34 2018 +0200
+++ b/src/java.base/share/classes/java/lang/Class.java	Wed Oct 24 23:15:33 2018 +0200
@@ -2236,6 +2236,20 @@
         return copyFields(privateGetDeclaredFields(false));
     }
 
+    /**
+     * TBD
+     * @return TBD
+     * @throws SecurityException TBD
+     * @since 1.12
+     */
+    @CallerSensitive
+    public Field[] getRecordParameters() throws SecurityException {
+        SecurityManager sm = System.getSecurityManager();
+        if (sm != null) {
+            checkMemberAccess(sm, Member.DECLARED, Reflection.getCallerClass(), true);
+        }
+        return copyFields(privateGetRecordParameters());
+    }
 
     /**
      * Returns an array containing {@code Method} objects reflecting all the
@@ -2937,6 +2951,8 @@
         volatile Field[] declaredPublicFields;
         volatile Method[] declaredPublicMethods;
         volatile Class<?>[] interfaces;
+        // record parameters
+        volatile Field[] recordParameters;
 
         // Cached names
         String simpleName;
@@ -3057,6 +3073,21 @@
         return res;
     }
 
+    private Field[] privateGetRecordParameters() {
+        Field[] res;
+        ReflectionData<T> rd = reflectionData();
+        if (rd != null) {
+            res = rd.recordParameters;
+            if (res != null) return res;
+        }
+        // No cached value available; request value from VM
+        res = Reflection.filterFields(this, getRecordParameters0());
+        if (rd != null) {
+            rd.recordParameters = res;
+        }
+        return res;
+    }
+
     // Returns an array of "root" fields. These Field objects must NOT
     // be propagated to the outside world, but must instead be copied
     // via ReflectionFactory.copyField.