@@ -1851,6 +1851,9 @@ JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass,
18511851}
18521852JVM_END
18531853
1854+
1855+ // A class is a record if and only if it is final and a direct subclass of
1856+ // java.lang.Record and has a Record attribute; otherwise, it is not a record.
18541857JVM_ENTRY (jboolean, JVM_IsRecord(JNIEnv *env, jclass cls))
18551858{
18561859 JVMWrapper (" JVM_IsRecord" );
@@ -1864,38 +1867,38 @@ JVM_ENTRY(jboolean, JVM_IsRecord(JNIEnv *env, jclass cls))
18641867}
18651868JVM_END
18661869
1870+ // Returns an array containing the components of the Record attribute,
1871+ // or NULL if the attribute is not present.
1872+ //
1873+ // Note that this function returns the components of the Record attribute
1874+ // even if the class is not a record.
18671875JVM_ENTRY (jobjectArray, JVM_GetRecordComponents(JNIEnv* env, jclass ofClass))
18681876{
18691877 JVMWrapper (" JVM_GetRecordComponents" );
18701878 Klass* c = java_lang_Class::as_Klass (JNIHandles::resolve_non_null (ofClass));
18711879 assert (c->is_instance_klass (), " must be" );
18721880 InstanceKlass* ik = InstanceKlass::cast (c);
18731881
1874- if (ik->is_record ()) {
1875- Array<RecordComponent*>* components = ik->record_components ();
1876- assert (components != NULL , " components should not be NULL" );
1877- {
1878- JvmtiVMObjectAllocEventCollector oam;
1879- constantPoolHandle cp (THREAD, ik->constants ());
1880- int length = components->length ();
1881- assert (length >= 0 , " unexpected record_components length" );
1882- objArrayOop record_components =
1883- oopFactory::new_objArray (SystemDictionary::RecordComponent_klass (), length, CHECK_NULL);
1884- objArrayHandle components_h (THREAD, record_components);
1885-
1886- for (int x = 0 ; x < length; x++) {
1887- RecordComponent* component = components->at (x);
1888- assert (component != NULL , " unexpected NULL record component" );
1889- oop component_oop = java_lang_reflect_RecordComponent::create (ik, component, CHECK_NULL);
1890- components_h->obj_at_put (x, component_oop);
1891- }
1892- return (jobjectArray)JNIHandles::make_local (THREAD, components_h ());
1882+ Array<RecordComponent*>* components = ik->record_components ();
1883+ if (components != NULL ) {
1884+ JvmtiVMObjectAllocEventCollector oam;
1885+ constantPoolHandle cp (THREAD, ik->constants ());
1886+ int length = components->length ();
1887+ assert (length >= 0 , " unexpected record_components length" );
1888+ objArrayOop record_components =
1889+ oopFactory::new_objArray (SystemDictionary::RecordComponent_klass (), length, CHECK_NULL);
1890+ objArrayHandle components_h (THREAD, record_components);
1891+
1892+ for (int x = 0 ; x < length; x++) {
1893+ RecordComponent* component = components->at (x);
1894+ assert (component != NULL , " unexpected NULL record component" );
1895+ oop component_oop = java_lang_reflect_RecordComponent::create (ik, component, CHECK_NULL);
1896+ components_h->obj_at_put (x, component_oop);
18931897 }
1898+ return (jobjectArray)JNIHandles::make_local (THREAD, components_h ());
18941899 }
18951900
1896- // Return empty array if ofClass is not a record.
1897- objArrayOop result = oopFactory::new_objArray (SystemDictionary::RecordComponent_klass (), 0 , CHECK_NULL);
1898- return (jobjectArray)JNIHandles::make_local (THREAD, result);
1901+ return NULL ;
18991902}
19001903JVM_END
19011904
0 commit comments