changeset 56908:8cbd278a7204 records-and-sealed

implementation of java.lang.Class::isRecord
author vromero
date Thu, 27 Jun 2019 10:55:30 -0400
parents 7241fb1920dc
children 72b424f08068 5261a2b6a653
files make/hotspot/symbols/symbols-unix src/hotspot/share/classfile/classFileParser.cpp src/hotspot/share/include/jvm.h src/hotspot/share/prims/jvm.cpp src/java.base/share/classes/java/lang/Class.java src/java.base/share/native/libjava/Class.c
diffstat 6 files changed, 14 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/make/hotspot/symbols/symbols-unix	Wed Jun 26 20:09:35 2019 -0400
+++ b/make/hotspot/symbols/symbols-unix	Thu Jun 27 10:55:30 2019 -0400
@@ -146,6 +146,7 @@
 JVM_IsInterface
 JVM_IsInterrupted
 JVM_IsPrimitiveClass
+JVM_IsRecord
 JVM_IsSameClassPackage
 JVM_IsSupportedJNIVersion
 JVM_IsThreadAlive
--- a/src/hotspot/share/classfile/classFileParser.cpp	Wed Jun 26 20:09:35 2019 -0400
+++ b/src/hotspot/share/classfile/classFileParser.cpp	Thu Jun 27 10:55:30 2019 -0400
@@ -5994,7 +5994,7 @@
   _super_class_index(0),
   _itfs_len(0),
   _java_fields_count(0),
-  _record_params_count(0),
+  _record_params_count(-1),
   _need_verify(false),
   _relax_verify(false),
   _has_nonstatic_concrete_methods(false),
--- a/src/hotspot/share/include/jvm.h	Wed Jun 26 20:09:35 2019 -0400
+++ b/src/hotspot/share/include/jvm.h	Thu Jun 27 10:55:30 2019 -0400
@@ -520,6 +520,9 @@
 JNIEXPORT jobjectArray JNICALL
 JVM_GetRecordComponentNames(JNIEnv *env, jclass ofClass);
 
+JNIEXPORT jboolean JNICALL
+JVM_IsRecord(JNIEnv *env, jclass cls);
+
 /* Differs from JVM_GetClassModifiers in treatment of inner classes.
    This returns the access flags for the class as specified in the
    class file rather than searching the InnerClasses attribute (if
--- a/src/hotspot/share/prims/jvm.cpp	Wed Jun 26 20:09:35 2019 -0400
+++ b/src/hotspot/share/prims/jvm.cpp	Thu Jun 27 10:55:30 2019 -0400
@@ -1698,6 +1698,12 @@
 }
 JVM_END
 
+JVM_ENTRY(jboolean, JVM_IsRecord(JNIEnv *env, jclass cls))
+  JVMWrapper("JVM_IsRecord");
+  InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)));
+  return (jboolean) k->record_params_count() >= 0;
+JVM_END
+
 static bool select_method(const methodHandle& method, bool want_constructor) {
   if (want_constructor) {
     return (method->is_initializer() && !method->is_static());
--- a/src/java.base/share/classes/java/lang/Class.java	Wed Jun 26 20:09:35 2019 -0400
+++ b/src/java.base/share/classes/java/lang/Class.java	Thu Jun 27 10:55:30 2019 -0400
@@ -3435,6 +3435,7 @@
     private native Constructor<T>[] getDeclaredConstructors0(boolean publicOnly);
     private native Class<?>[]   getDeclaredClasses0();
     private native String[]     getRecordComponentNames0();
+    private native boolean      isRecord0();
 
     /**
      * Helper method to get the method name from arguments.
@@ -3540,8 +3541,7 @@
      * @since 1.12
      */
     public boolean isRecord() {
-        // we need to create a native method that checks if the Record attribute is present or not
-        return false;
+        return isRecord0();
     }
 
     // Fetches the factory for reflective objects
--- a/src/java.base/share/native/libjava/Class.c	Wed Jun 26 20:09:35 2019 -0400
+++ b/src/java.base/share/native/libjava/Class.c	Thu Jun 27 10:55:30 2019 -0400
@@ -78,6 +78,7 @@
     {"getNestMembers0",      "()[" CLS,         (void *)&JVM_GetNestMembers},
     {"getPermittedSubtypes0", "()[" CLS,        (void *)&JVM_GetPermittedSubtypes},
     {"getRecordComponentNames0",  "()[" STR,    (void *)&JVM_GetRecordComponentNames},
+    {"isRecord0",                 "()Z",        (void *)&JVM_IsRecord},
 };
 
 #undef OBJ