changeset 58512:c084dcf36e75 records

Summary: Review comments to clean up code and move parsing of Record attribute under "if (JAVA_14_VERSION)" code block Reviewed-by: dholmes, sspitsyn
author hseigel
date Fri, 25 Oct 2019 12:42:19 +0000
parents 383430f2d47a
children 63df7c75ac89
files src/hotspot/share/classfile/classFileParser.cpp src/hotspot/share/classfile/javaClasses.cpp src/hotspot/share/oops/instanceKlass.cpp test/jdk/java/lang/instrument/RedefineRecordAttr/HostBA/redef/Host.java
diffstat 4 files changed, 24 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/classfile/classFileParser.cpp	Thu Oct 24 22:07:35 2019 -0400
+++ b/src/hotspot/share/classfile/classFileParser.cpp	Fri Oct 25 12:42:19 2019 +0000
@@ -3715,23 +3715,28 @@
                          "Nest-host class_info_index %u has bad constant type in class file %s",
                          class_info_index, CHECK);
           _nest_host = class_info_index;
-        } else if (tag == vmSymbols::tag_record()) {
-          // Skip over Record attribute if not supported or if super class is
-          // not java.lang.Record.
-          if (supports_records() &&
-              cp->klass_name_at(_super_class_index) == vmSymbols::java_lang_Record()) {
-            if (parsed_record_attribute) {
-              classfile_parse_error("Multiple Record attributes in class file %s", CHECK);
+        } else if (_major_version >= JAVA_14_VERSION) {
+          if (tag == vmSymbols::tag_record()) {
+            // Skip over Record attribute if not supported or if super class is
+            // not java.lang.Record.
+            if (supports_records() &&
+                cp->klass_name_at(_super_class_index) == vmSymbols::java_lang_Record()) {
+              if (parsed_record_attribute) {
+                classfile_parse_error("Multiple Record attributes in class file %s", CHECK);
+              }
+              // Check that class is final and not abstract.
+              if (!_access_flags.is_final() || _access_flags.is_abstract()) {
+                classfile_parse_error("Record attribute in non-final or abstract class file %s", CHECK);
+              }
+              parsed_record_attribute = true;
+              record_attribute_start = cfs->current();
+              record_attribute_length = attribute_length;
             }
-            // Check that class is final and not abstract.
-            if (!_access_flags.is_final() || _access_flags.is_abstract()) {
-              classfile_parse_error("Record attribute in non-final or abstract class file %s", CHECK);
-            }
-            parsed_record_attribute = true;
-            record_attribute_start = cfs->current();
-            record_attribute_length = attribute_length;
+            cfs->skip_u1(attribute_length, CHECK);
+          } else {
+            // Unknown attribute
+            cfs->skip_u1(attribute_length, CHECK);
           }
-          cfs->skip_u1(attribute_length, CHECK);
         } else {
           // Unknown attribute
           cfs->skip_u1(attribute_length, CHECK);
--- a/src/hotspot/share/classfile/javaClasses.cpp	Thu Oct 24 22:07:35 2019 -0400
+++ b/src/hotspot/share/classfile/javaClasses.cpp	Fri Oct 25 12:42:19 2019 +0000
@@ -3084,9 +3084,7 @@
   HandleMark hm(THREAD);
   InstanceKlass* ik = SystemDictionary::RecordComponent_klass();
   assert(ik != NULL, "must be loaded");
-  if (ik->should_be_initialized()) {
-    ik->initialize(CHECK_0);
-  }
+  ik->initialize(CHECK_0);
 
   Handle element = ik->allocate_instance_handle(CHECK_0);
 
@@ -3108,7 +3106,7 @@
     ResourceMark rm(THREAD);
     int sig_len = type->utf8_length() + 3; // "()" and null char
     char* sig = NEW_RESOURCE_ARRAY(char, sig_len);
-    jio_snprintf(sig, sig_len, "()%s", type->as_C_string());
+    jio_snprintf(sig, sig_len, "%c%c%s", JVM_SIGNATURE_FUNC, JVM_SIGNATURE_ENDFUNC, type->as_C_string());
     TempNewSymbol full_sig = SymbolTable::new_symbol(sig);
     accessor_method = holder->find_instance_method(name, full_sig);
   }
--- a/src/hotspot/share/oops/instanceKlass.cpp	Thu Oct 24 22:07:35 2019 -0400
+++ b/src/hotspot/share/oops/instanceKlass.cpp	Fri Oct 25 12:42:19 2019 +0000
@@ -3545,7 +3545,7 @@
   if (components != NULL) {
     for (int i = 0; i < components->length(); i++) {
       RecordComponent* component = components->at(i);
-      if (component) {
+      if (component != NULL) {
         component->collect_statistics(sz);
       }
     }
--- a/test/jdk/java/lang/instrument/RedefineRecordAttr/HostBA/redef/Host.java	Thu Oct 24 22:07:35 2019 -0400
+++ b/test/jdk/java/lang/instrument/RedefineRecordAttr/HostBA/redef/Host.java	Fri Oct 25 12:42:19 2019 +0000
@@ -27,7 +27,7 @@
         return 2; // redefined class
     }
     public Host(int A, long B, char C) {
+        this.B = B;
         this.A = A;
-        this.B = B;
     }
 }