changeset 57823:7e1b4cb3ee6b records-and-sealed

Summary: Add --enable-preview to tests and minor fixes Reviewed-by: vromero
author hseigel
date Tue, 10 Sep 2019 13:04:16 +0000
parents 6351a6bd9253
children e2902493b389 51781035a19a 362ffdb9571b
files src/hotspot/share/classfile/classFileParser.cpp src/hotspot/share/oops/instanceKlass.cpp src/hotspot/share/prims/jvmtiClassFileReconstituter.cpp src/hotspot/share/prims/jvmtiRedefineClasses.cpp test/hotspot/jtreg/runtime/modules/SealedModuleTest.java test/hotspot/jtreg/runtime/records/recordAccessorsTest.java test/hotspot/jtreg/runtime/records/recordAttribute.jcod test/hotspot/jtreg/runtime/records/recordAttributeTest.java test/hotspot/jtreg/runtime/sealedTypes/SealedUnnamedModuleIntfTest.java test/hotspot/jtreg/runtime/sealedTypes/SealedUnnamedModuleTest.java test/hotspot/jtreg/runtime/sealedTypes/abstractSealedTest.java test/hotspot/jtreg/runtime/sealedTypes/getPermittedSubtypes.jcod test/hotspot/jtreg/runtime/sealedTypes/getPermittedSubtypesTest.java test/hotspot/jtreg/runtime/sealedTypes/overrideSealedTest.java test/hotspot/jtreg/runtime/sealedTypes/sealedTest.java
diffstat 15 files changed, 74 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/classfile/classFileParser.cpp	Fri Sep 06 16:25:41 2019 -0400
+++ b/src/hotspot/share/classfile/classFileParser.cpp	Tue Sep 10 13:04:16 2019 +0000
@@ -3437,13 +3437,15 @@
 }
 
 bool ClassFileParser::supports_sealed_types() {
-  return _major_version == JAVA_14_VERSION;
-    // TBD: add: && _minor_version == JAVA_PREVIEW_MINOR_VERSION && Arguments::enable_preview()
+  return _major_version == JAVA_14_VERSION /* TBD &&
+    _minor_version == JAVA_PREVIEW_MINOR_VERSION &&
+    Arguments::enable_preview() */ ;
 }
 
 bool ClassFileParser::supports_records() {
-  return _major_version == JAVA_14_VERSION;
-    // TBD: add: && _minor_version == JAVA_PREVIEW_MINOR_VERSION && Arguments::enable_preview()
+  return _major_version == JAVA_14_VERSION /* TBD &&
+    _minor_version == JAVA_PREVIEW_MINOR_VERSION &&
+    Arguments::enable_preview() */ ;
 }
 
 void ClassFileParser::parse_classfile_attributes(const ClassFileStream* const cfs,
@@ -6526,10 +6528,9 @@
   _all_mirandas = new GrowableArray<Method*>(20);
 
   Handle loader(THREAD, _loader_data->class_loader());
-  bool is_sealed = _access_flags.is_final() &&
-                         _permitted_subtypes != NULL &&
-                         _permitted_subtypes != Universe::the_empty_short_array() &&
-                         _permitted_subtypes->length() > 0;
+  bool is_sealed = _permitted_subtypes != NULL &&
+                   _permitted_subtypes != Universe::the_empty_short_array() &&
+                   _permitted_subtypes->length() > 0;
   klassVtable::compute_vtable_size_and_num_mirandas(&_vtable_size,
                                                     &_num_miranda_methods,
                                                     _all_mirandas,
--- a/src/hotspot/share/oops/instanceKlass.cpp	Fri Sep 06 16:25:41 2019 -0400
+++ b/src/hotspot/share/oops/instanceKlass.cpp	Tue Sep 10 13:04:16 2019 +0000
@@ -243,22 +243,11 @@
       return false;
   }
 
-  // Check that the class and its super are either in the same named module or
-  // in the same package.
-  ModuleEntry* k_module = k->module();
-  if (k_module->is_named()) {
-    if (k_module != this->module()) {
-      log_trace(class, sealed)("Check failed for same module of permitted subtype of %s and sealed class %s",
-                               k->external_name(), this->external_name());
-      return false;
-    }
-  } else {
-    // In unnamed module, check that the classes are in the same package.
-    if (k->package() != this->package()) {
-      log_trace(class, sealed)("Check failed for same package of permitted subtype of %s and sealed class %s",
-                               k->external_name(), this->external_name());
-      return false;
-    }
+  // Check that the class and its super are in the same module.
+  if (k->module() != this->module()) {
+    log_trace(class, sealed)("Check failed for same module of permitted subtype of %s and sealed class %s",
+                             k->external_name(), this->external_name());
+    return false;
   }
 
   // Check for a resolved cp entry, else fall back to a name check.
--- a/src/hotspot/share/prims/jvmtiClassFileReconstituter.cpp	Fri Sep 06 16:25:41 2019 -0400
+++ b/src/hotspot/share/prims/jvmtiClassFileReconstituter.cpp	Tue Sep 10 13:04:16 2019 +0000
@@ -454,10 +454,11 @@
   Array<RecordComponent*>* components = ik()->record_components();
   int number_of_components = components->length();
 
-  int length = sizeof(u2) + (RecordComponent::size() * number_of_components);
+  // Each component has a u2 for name, descr, attribute count
+  int length = sizeof(u2) + (sizeof(u2) * 3 * number_of_components);
   for (int x = 0; x < number_of_components; x++) {
     RecordComponent* component = components->at(x);
-    if (component->descriptor_index() != 0) {
+    if (component->generic_signature_index() != 0) {
       length += 8; // Signature attribute size
       assert(component->attributes_count() > 0, "Bad component attributes count");
     }
--- a/src/hotspot/share/prims/jvmtiRedefineClasses.cpp	Fri Sep 06 16:25:41 2019 -0400
+++ b/src/hotspot/share/prims/jvmtiRedefineClasses.cpp	Tue Sep 10 13:04:16 2019 +0000
@@ -298,7 +298,7 @@
 
   // Cannot redefine or retransform a record.
   if (InstanceKlass::cast(k)->is_record()) {
-    return false;
+    /* TBD: can we support redefining a record with annotations ? */  return false;
   }
   return true;
 }
--- a/test/hotspot/jtreg/runtime/modules/SealedModuleTest.java	Fri Sep 06 16:25:41 2019 -0400
+++ b/test/hotspot/jtreg/runtime/modules/SealedModuleTest.java	Tue Sep 10 13:04:16 2019 +0000
@@ -25,12 +25,12 @@
  * @test
  * @modules java.base/jdk.internal.misc
  * @library /test/lib ..
- * @compile sealedP1/superClass.java sealedP1/c1.java sealedP2/c2.java sealedP3/c3.java
+ * @compile --enable-preview --source 14 sealedP1/superClass.java sealedP1/c1.java sealedP2/c2.java sealedP3/c3.java
  * @build sun.hotspot.WhiteBox
  * @compile/module=java.base java/lang/ModuleHelper.java
  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  *                              sun.hotspot.WhiteBox$WhiteBoxPermission
- * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI SealedModuleTest
+ * @run main/othervm -Xbootclasspath/a:. --enable-preview -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI SealedModuleTest
  */
 
 public class SealedModuleTest {
--- a/test/hotspot/jtreg/runtime/records/recordAccessorsTest.java	Fri Sep 06 16:25:41 2019 -0400
+++ b/test/hotspot/jtreg/runtime/records/recordAccessorsTest.java	Tue Sep 10 13:04:16 2019 +0000
@@ -23,7 +23,8 @@
 
 /*
  * @test
- * @run main recordAccessorsTest
+ * @compile --enable-preview --source 14 recordAccessorsTest.java
+ * @run main/othervm --enable-preview recordAccessorsTest
  */
 
 
@@ -43,6 +44,18 @@
         }
     }
 
+    record recordGeneric<T>(T xx, String yy) {
+        public Method[] getMethods() throws Throwable {
+            return recordGeneric.class.getRecordAccessors();
+        }
+    }
+
+    record recordEmpty() {
+        public Method[] getMethods() throws Throwable {
+            return recordEmpty.class.getRecordAccessors();
+        }
+    }
+
     notRecord nr = new notRecord();
 
     public static boolean hasMethod(Method[] methods, String method) {
@@ -68,6 +81,19 @@
         if (methods.length != 0) {
             throw new RuntimeException("Non-empty component accessors returned for notRecord");
         }
+
+        recordGeneric rg = new recordGeneric(35, "abcd");
+        methods = rg.getMethods();
+        if (methods.length != 2 ||
+            !hasMethod(methods, "java.lang.Object recordAccessorsTest$recordGeneric.xx()") ||
+            !hasMethod(methods, "java.lang.String recordAccessorsTest$recordGeneric.yy()")) {
+            throw new RuntimeException("Bad component accessors returned for recordGeneric");
+        }
+
+        recordEmpty re = new recordEmpty();
+        methods = re.getMethods();
+        if (methods.length != 0) {
+            throw new RuntimeException("Non-empty component accessors returned for recordEmpty");
+        }
     }
 }
-
--- a/test/hotspot/jtreg/runtime/records/recordAttribute.jcod	Fri Sep 06 16:25:41 2019 -0400
+++ b/test/hotspot/jtreg/runtime/records/recordAttribute.jcod	Tue Sep 10 13:04:16 2019 +0000
@@ -29,7 +29,7 @@
 // exception.
 class twoRecordAttributes {
   0xCAFEBABE;
-  0; // minor version
+  65535; // minor version
   58; // version
   [69] { // Constant Pool
     ; // first element is empty
@@ -355,7 +355,7 @@
 // exception.
 class abstractRecord {
   0xCAFEBABE;
-  0; // minor version
+  65535; // minor version
   58; // version
   [69] { // Constant Pool
     ; // first element is empty
@@ -676,7 +676,7 @@
 // exception.
 class notFinalRecord {
   0xCAFEBABE;
-  0; // minor version
+  65535; // minor version
   58; // version
   [69] { // Constant Pool
     ; // first element is empty
@@ -997,7 +997,7 @@
 // Utf8.  It should result in a ClassFormatError exception.
 class badRecordAttribute {
   0xCAFEBABE;
-  0; // minor version
+  65535; // minor version
   58; // version
   [69] { // Constant Pool
     ; // first element is empty
@@ -1318,7 +1318,7 @@
 // attribute_count field.  It should result in a ClassFormatError exception.
 class shortRecordAttribute {
   0xCAFEBABE;
-  0; // minor version
+  65535; // minor version
   58; // version
   [69] { // Constant Pool
     ; // first element is empty
@@ -1960,7 +1960,7 @@
 // not java.lang.Record.  So, the bogus Record attribute should be ignored.
 class superNotJLRecord {
   0xCAFEBABE;
-  0; // minor version
+  65535; // minor version
   58; // version
   [69] { // Constant Pool
     ; // first element is empty
--- a/test/hotspot/jtreg/runtime/records/recordAttributeTest.java	Fri Sep 06 16:25:41 2019 -0400
+++ b/test/hotspot/jtreg/runtime/records/recordAttributeTest.java	Tue Sep 10 13:04:16 2019 +0000
@@ -24,7 +24,7 @@
 /*
  * @test
  * @compile recordAttribute.jcod
- * @run main recordAttributeTest
+ * @run main/othervm --enable-preview recordAttributeTest
  */
 
 
--- a/test/hotspot/jtreg/runtime/sealedTypes/SealedUnnamedModuleIntfTest.java	Fri Sep 06 16:25:41 2019 -0400
+++ b/test/hotspot/jtreg/runtime/sealedTypes/SealedUnnamedModuleIntfTest.java	Tue Sep 10 13:04:16 2019 +0000
@@ -24,7 +24,8 @@
 /*
  * @test
  * @compile otherPkg/wrongPackage.java Pkg/Permitted.java Pkg/notPermitted.jcod Pkg/sealedInterface.java
- * @run main/othervm SealedUnnamedModuleIntfTest
+ * @compile --enable-preview --source 14 Pkg/sealedInterface.java
+ * @run main/othervm --enable-preview SealedUnnamedModuleIntfTest
  */
 
 public class SealedUnnamedModuleIntfTest {
--- a/test/hotspot/jtreg/runtime/sealedTypes/SealedUnnamedModuleTest.java	Fri Sep 06 16:25:41 2019 -0400
+++ b/test/hotspot/jtreg/runtime/sealedTypes/SealedUnnamedModuleTest.java	Tue Sep 10 13:04:16 2019 +0000
@@ -23,8 +23,8 @@
 
 /*
  * @test
- * @compile asteroids/Pluto.java planets/Neptune.java planets/Mars.jcod planets/outerPlanets.java
- * @run main/othervm SealedUnnamedModuleTest
+ * @compile --enable-preview --source 14 asteroids/Pluto.java planets/Neptune.java planets/Mars.jcod planets/outerPlanets.java
+ * @run main/othervm --enable-preview SealedUnnamedModuleTest
  */
 
 public class SealedUnnamedModuleTest {
--- a/test/hotspot/jtreg/runtime/sealedTypes/abstractSealedTest.java	Fri Sep 06 16:25:41 2019 -0400
+++ b/test/hotspot/jtreg/runtime/sealedTypes/abstractSealedTest.java	Tue Sep 10 13:04:16 2019 +0000
@@ -23,10 +23,11 @@
 
 /*
  * @test
- * @run main abstractSealedTest
+ * @compile  --enable-preview --source 14 abstractSealedTest.java
+ * @run main/othervm --enable-preview abstractSealedTest
  */
 
-// Test that sealed class abstractShape can be both ACC_FINAL and ACC_ABSTRACT
+// Test that a sealed class can be abstract
 public class abstractSealedTest {
 
     abstract sealed class abstractShape permits Circle {
--- a/test/hotspot/jtreg/runtime/sealedTypes/getPermittedSubtypes.jcod	Fri Sep 06 16:25:41 2019 -0400
+++ b/test/hotspot/jtreg/runtime/sealedTypes/getPermittedSubtypes.jcod	Tue Sep 10 13:04:16 2019 +0000
@@ -29,7 +29,7 @@
 //
 class noLoadSubtypes {
   0xCAFEBABE;
-  0; // minor version
+  65535; // minor version
   58; // version
   [18] { // Constant Pool
     ; // first element is empty
@@ -105,7 +105,7 @@
 // this does not cause an exception to get thrown.
 class noSubtypes {
   0xCAFEBABE;
-  0; // minor version
+  65535; // minor version
   58; // version
   [14] { // Constant Pool
     ; // first element is empty
@@ -256,7 +256,7 @@
 // should throw ClassFormatError.
 class badPermittedAttr {
   0xCAFEBABE;
-  0; // minor version
+  65535; // minor version
   58; // version
   [18] { // Constant Pool
     ; // first element is empty
@@ -334,7 +334,7 @@
 //
 class sealedButFinal {
   0xCAFEBABE;
-  0; // minor version
+  65535; // minor version
   58; // version
   [18] { // Constant Pool
     ; // first element is empty
@@ -403,4 +403,3 @@
     } // end PermittedSubtypes
   } // Attributes
 } // end class sealedButFinal
-
--- a/test/hotspot/jtreg/runtime/sealedTypes/getPermittedSubtypesTest.java	Fri Sep 06 16:25:41 2019 -0400
+++ b/test/hotspot/jtreg/runtime/sealedTypes/getPermittedSubtypesTest.java	Tue Sep 10 13:04:16 2019 +0000
@@ -24,7 +24,8 @@
 /*
  * @test
  * @compile getPermittedSubtypes.jcod
- * @run main getPermittedSubtypesTest
+ * @compile --enable-preview --source 14 getPermittedSubtypesTest.java
+ * @run main/othervm --enable-preview getPermittedSubtypesTest
  */
 
 import java.lang.constant.ClassDesc;
@@ -122,8 +123,8 @@
         testBadSealedType("badPermittedAttr",
                           "Permitted subtype class_info_index 15 has bad constant type");
 
-        // Test that loading a sealed final class with a non-empty PermitedSubtypes attribute
-        // causes a ClassFormatError.
+        // Test that loading a sealed final class with a non-empty PermittedSubtypes
+        // attribute causes a ClassFormatError.
         testBadSealedType("sealedButFinal", "PermittedSubtypes attribute in final class file");
     }
 }
--- a/test/hotspot/jtreg/runtime/sealedTypes/overrideSealedTest.java	Fri Sep 06 16:25:41 2019 -0400
+++ b/test/hotspot/jtreg/runtime/sealedTypes/overrideSealedTest.java	Tue Sep 10 13:04:16 2019 +0000
@@ -23,7 +23,8 @@
 
 /*
  * @test
- * @run main overrideSealedTest
+ * compile --enable-preview --source 14 overrideSealedTest.java
+ * @run main/othervm --enable-preview overrideSealedTest
  */
 
 // Test that a method in a sealed class or interface can be overridden.
--- a/test/hotspot/jtreg/runtime/sealedTypes/sealedTest.java	Fri Sep 06 16:25:41 2019 -0400
+++ b/test/hotspot/jtreg/runtime/sealedTypes/sealedTest.java	Tue Sep 10 13:04:16 2019 +0000
@@ -23,7 +23,8 @@
 
 /*
  * @test
- * @run main sealedTest
+ * compile --enable-preview --source 14 sealedTest.java
+ * @run main/othervm --enable-preview sealedTest
  */
 
 public class sealedTest {