changeset 52951:859f3cb2cd75 datum

moving the check for array and primitive to the java side
author vromero
date Wed, 31 Oct 2018 18:56:28 -0400
parents 9e4fc2e97fd0
children ad3177db8f2c
files src/hotspot/share/prims/jvm.cpp src/java.base/share/classes/java/lang/Class.java src/java.base/share/native/libjava/Class.c
diffstat 3 files changed, 6 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/prims/jvm.cpp	Wed Oct 31 13:21:55 2018 -0400
+++ b/src/hotspot/share/prims/jvm.cpp	Wed Oct 31 18:56:28 2018 -0400
@@ -1793,13 +1793,6 @@
   JVMWrapper("JVM_GetRecordParametersCount");
   JvmtiVMObjectAllocEventCollector oam;
 
-  // Exclude primitive types and array types
-  if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) ||
-      java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->is_array_klass()) {
-    // Return 0
-    return 0;
-  }
-
   InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass)));
   // Ensure class is linked
   k->link_class(CHECK_0);
@@ -1813,14 +1806,6 @@
   JVMWrapper("JVM_GetRecordParameters");
   JvmtiVMObjectAllocEventCollector oam;
 
-  // Exclude primitive types and array types
-  if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) ||
-      java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->is_array_klass()) {
-    // Return empty array
-    oop res = oopFactory::new_objArray(SystemDictionary::reflect_Field_klass(), 0, CHECK_NULL);
-    return (jobjectArray) JNIHandles::make_local(env, res);
-  }
-
   InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass)));
   constantPoolHandle cp(THREAD, k->constants());
 
--- a/src/java.base/share/classes/java/lang/Class.java	Wed Oct 31 13:21:55 2018 -0400
+++ b/src/java.base/share/classes/java/lang/Class.java	Wed Oct 31 18:56:28 2018 -0400
@@ -2248,7 +2248,7 @@
         if (sm != null) {
             checkMemberAccess(sm, Member.DECLARED, Reflection.getCallerClass(), true);
         }
-        return copyFields(privateGetRecordParameters());
+        return isPrimitive() || isArray() ? new Field[0] : copyFields(privateGetRecordParameters());
     }
 
     /**
@@ -2256,7 +2256,9 @@
      * @return the number of record parameters
      * @since 1.12
      */
-    public native int getRecordParametersCount();
+    public int getRecordParametersCount() {
+        return isPrimitive() || isArray() ? 0 : getRecordParametersCount0();
+    }
 
     /**
      * Returns an array containing {@code Method} objects reflecting all the
@@ -3433,6 +3435,7 @@
     private native Constructor<T>[] getDeclaredConstructors0(boolean publicOnly);
     private native Class<?>[]   getDeclaredClasses0();
     private native Field[]      getRecordParameters0();
+    private native int          getRecordParametersCount0();
 
     /**
      * Helper method to get the method name from arguments.
--- a/src/java.base/share/native/libjava/Class.c	Wed Oct 31 13:21:55 2018 -0400
+++ b/src/java.base/share/native/libjava/Class.c	Wed Oct 31 18:56:28 2018 -0400
@@ -77,7 +77,7 @@
     {"getNestHost0",         "()" CLS,      (void *)&JVM_GetNestHost},
     {"getNestMembers0",      "()[" CLS,     (void *)&JVM_GetNestMembers},
     {"getRecordParameters0",  "()[" FLD,    (void *)&JVM_GetRecordParameters},
-    {"getRecordParametersCount", "()I",     (void *)&JVM_GetRecordParametersCount},
+    {"getRecordParametersCount0", "()I",    (void *)&JVM_GetRecordParametersCount},
 };
 
 #undef OBJ