changeset 56949:7ffbb586462a amber-demo-II

Automatic merge with records-and-sealed
author mcimadamore
date Tue, 23 Jul 2019 22:45:54 +0000
parents 36abd263dca2 7880389d8172
children 960e2b3680da
files
diffstat 26 files changed, 945 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/classfile/classFileParser.cpp	Thu Jul 18 21:05:42 2019 +0000
+++ b/src/hotspot/share/classfile/classFileParser.cpp	Tue Jul 23 22:45:54 2019 +0000
@@ -4676,6 +4676,22 @@
   const Klass* const super = this_klass->super();
   if (super != NULL) {
 
+    if (super->is_final()) {
+      assert(super->is_instance_klass(), "super is not instance klass");
+      const InstanceKlass* super_ik = InstanceKlass::cast(super);
+      bool isPermittedSubtype = super_ik->has_as_permitted_subtype(this_klass, CHECK);
+      if (!isPermittedSubtype) {
+        ResourceMark rm(THREAD);
+        Exceptions::fthrow(
+          THREAD_AND_LOCATION,
+          vmSymbols::java_lang_VerifyError(),
+          "class %s cannot inherit from final class %s",
+          this_klass->external_name(),
+          super_ik->external_name());
+        return;
+      }
+    }
+
     // If the loader is not the boot loader then throw an exception if its
     // superclass is in package jdk.internal.reflect and its loader is not a
     // special reflection class loader
@@ -4736,6 +4752,20 @@
   for (int i = lng - 1; i >= 0; i--) {
     InstanceKlass* const k = local_interfaces->at(i);
     assert (k != NULL && k->is_interface(), "invalid interface");
+    if (k->is_final()) {
+      bool isPermittedSubtype = k->has_as_permitted_subtype(this_klass, CHECK);
+      if (!isPermittedSubtype) {
+        ResourceMark rm(THREAD);
+        Exceptions::fthrow(
+          THREAD_AND_LOCATION,
+          vmSymbols::java_lang_VerifyError(),
+          "class %s cannot implement sealed interface %s",
+          this_klass->external_name(),
+          k->external_name());
+        return;
+      }
+    }
+
     Reflection::VerifyClassAccessResults vca_result =
       Reflection::verify_class_access(this_klass, k, false);
     if (vca_result != Reflection::ACCESS_OK) {
@@ -5836,8 +5866,6 @@
   // it's official
   set_klass(ik);
 
-  check_subtyping(CHECK);
-
   debug_only(ik->verify();)
 }
 
@@ -6085,7 +6113,7 @@
   if (_record_params != NULL && _record_params != Universe::the_empty_short_array()) {
     MetadataFactory::free_array<u2>(_loader_data, _record_params);
   }
-  
+
   if (_permitted_subtypes != NULL && _permitted_subtypes != Universe::the_empty_short_array()) {
     MetadataFactory::free_array<u2>(_loader_data, _permitted_subtypes);
   }
@@ -6471,30 +6499,6 @@
 
 }
 
-void ClassFileParser::check_subtyping(TRAPS) {
-  assert(NULL != _klass, "_klass should have been resolved before calling this method");
-  if (_super_klass != NULL) {
-    if (_super_klass->is_final()) {
-      bool isPermittedSubtype = _super_klass->has_as_permitted_subtype(_klass, CHECK);
-      if (!isPermittedSubtype) {
-        THROW_MSG(vmSymbols::java_lang_VerifyError(), "Cannot inherit from final class");
-      }
-    }
-  }
-  Array<InstanceKlass*>* local_interfaces = _klass->local_interfaces();
-  if (local_interfaces != NULL && local_interfaces != Universe::the_empty_instance_klass_array()) {
-    for (int i = 0; i < local_interfaces->length(); i++) {
-      InstanceKlass* intf = local_interfaces->at(i);
-      if (intf->is_final()) {
-        bool isPermittedSubtype = intf->has_as_permitted_subtype(_klass, CHECK);
-        if (!isPermittedSubtype) {
-          THROW_MSG(vmSymbols::java_lang_VerifyError(), "Cannot inherit from final interface");
-        }
-      }
-    }
-  }
-}
-
 void ClassFileParser::set_klass(InstanceKlass* klass) {
 
 #ifdef ASSERT
--- a/src/hotspot/share/classfile/classFileParser.hpp	Thu Jul 18 21:05:42 2019 +0000
+++ b/src/hotspot/share/classfile/classFileParser.hpp	Tue Jul 23 22:45:54 2019 +0000
@@ -500,9 +500,6 @@
                      FieldLayoutInfo* info,
                      TRAPS);
 
-   // check that the current class is not extending a final class or interface
-   void check_subtyping(TRAPS);
-
    void update_class_name(Symbol* new_name);
 
  public:
--- a/src/hotspot/share/oops/instanceKlass.cpp	Thu Jul 18 21:05:42 2019 +0000
+++ b/src/hotspot/share/oops/instanceKlass.cpp	Tue Jul 23 22:45:54 2019 +0000
@@ -212,7 +212,7 @@
 }
 
 // Called to verify that k is a permitted subtype of this class
-bool InstanceKlass::has_as_permitted_subtype(InstanceKlass* k, TRAPS) const {
+bool InstanceKlass::has_as_permitted_subtype(const InstanceKlass* k, TRAPS) const {
   if (k == NULL) {
     if (log_is_enabled(Trace, class, sealed)) {
       ResourceMark rm(THREAD);
@@ -224,7 +224,7 @@
     if (log_is_enabled(Trace, class, sealed)) {
       ResourceMark rm(THREAD);
       log_trace(class, sealed)("Checked for permitted subtype of %s in non-sealed class %s",
-                                  k->external_name(), this->external_name());
+                               k->external_name(), this->external_name());
     }
     return false;
   }
@@ -232,17 +232,35 @@
   if (log_is_enabled(Trace, class, sealed)) {
     ResourceMark rm(THREAD);
     log_trace(class, sealed)("Checking for permitted subtype of %s in %s",
-                                k->external_name(), this->external_name());
+                             k->external_name(), this->external_name());
   }
 
   oop classloader1 = this->class_loader();
   oop classloader2 = k->class_loader();
   if (!oopDesc::equals(classloader1, classloader2)) {
-      log_trace(class, sealed)("Checked for same class loader of permitted subtype of %s and sealed class %s",
-                                        k->external_name(), this->external_name());
+      log_trace(class, sealed)("Check failed for same class loader 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 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 for a resolved cp entry, else fall back to a name check.
   // We don't want to resolve any class other than the one being checked.
   for (int i = 0; i < _permitted_subtypes->length(); i++) {
--- a/src/hotspot/share/oops/instanceKlass.hpp	Thu Jul 18 21:05:42 2019 +0000
+++ b/src/hotspot/share/oops/instanceKlass.hpp	Tue Jul 23 22:45:54 2019 +0000
@@ -476,9 +476,10 @@
   // Called to verify that k is a member of this nest - does not look at k's nest-host
   bool has_nest_member(InstanceKlass* k, TRAPS) const;
 
+public:
   // Called to verify that k is a permitted subtype of this class
-  bool has_as_permitted_subtype(InstanceKlass* k, TRAPS) const;
-public:
+  bool has_as_permitted_subtype(const InstanceKlass* k, TRAPS) const;
+
   // Returns nest-host class, resolving and validating it if needed
   // Returns NULL if an exception occurs during loading, or validation fails
   InstanceKlass* nest_host(Symbol* validationException, TRAPS);
--- a/src/hotspot/share/prims/jvmti.xml	Thu Jul 18 21:05:42 2019 +0000
+++ b/src/hotspot/share/prims/jvmti.xml	Tue Jul 23 22:45:54 2019 +0000
@@ -7628,8 +7628,8 @@
         (unless explicitly prohibited).
         The retransformation must not add, remove or rename fields or methods, change the
         signatures of methods, change modifiers, or change inheritance.
-        The retransformation must not change the <code>NestHost</code> or
-        <code>NestMembers</code> attributes.
+        The retransformation must not change the <code>NestHost</code>,
+        <code>NestMembers</code>, or <code>PermittedSubtypes</code> attributes.
         These restrictions may be lifted in future versions.
         See the error return description below for information on error codes
         returned if an unsupported retransformation is attempted.
@@ -7781,8 +7781,8 @@
         (unless explicitly prohibited).
         The redefinition must not add, remove or rename fields or methods, change the
         signatures of methods, change modifiers, or change inheritance.
-        The retransformation must not change the <code>NestHost</code> or
-        <code>NestMembers</code> attributes.
+        The retransformation must not change the <code>NestHost</code>,
+        <code>NestMembers</code>, or <code>PermittedSubtypes</code> attributes.
         These restrictions may be lifted in future versions.
 	See the error return description below for information on error codes
 	returned if an unsupported redefinition is attempted.
@@ -14969,6 +14969,11 @@
         - The specified thread must be suspended or must be the current thread.
           (It was not allowed to be the current thread before.)
   </change>
+  <change date="22 July 2019" version="14.0.0">
+      Minor update for new class file PermittedSubtypes attribute:
+        - Specify that RedefineClasses and RetransformClasses are not allowed
+          to change the class file PemittedSubtypes attribute.
+  </change>
 </changehistory>
 
 </specification>
--- a/src/hotspot/share/prims/jvmtiClassFileReconstituter.cpp	Thu Jul 18 21:05:42 2019 +0000
+++ b/src/hotspot/share/prims/jvmtiClassFileReconstituter.cpp	Tue Jul 23 22:45:54 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -423,6 +423,26 @@
   }
 }
 
+//  PermittedSubtypes {
+//    u2 attribute_name_index;
+//    u4 attribute_length;
+//    u2 number_of_classes;
+//    u2 classes[number_of_classes];
+//  }
+void JvmtiClassFileReconstituter::write_permitted_subtypes_attribute() {
+  Array<u2>* permitted_subtypes = ik()->permitted_subtypes();
+  int number_of_classes = permitted_subtypes->length();
+  int length = sizeof(u2) * (1 + number_of_classes);
+
+  write_attribute_name_index("PermittedSubtypes");
+  write_u4(length);
+  write_u2(number_of_classes);
+  for (int i = 0; i < number_of_classes; i++) {
+    u2 class_cp_index = permitted_subtypes->at(i);
+    write_u2(class_cp_index);
+  }
+}
+
 
 // Write InnerClasses attribute
 // JVMSpec|   InnerClasses_attribute {
@@ -699,6 +719,9 @@
   if (ik()->nest_members() != Universe::the_empty_short_array()) {
     ++attr_count;
   }
+  if (ik()->permitted_subtypes() != Universe::the_empty_short_array()) {
+    ++attr_count;
+  }
 
   write_u2(attr_count);
 
@@ -729,6 +752,9 @@
   if (ik()->nest_members() != Universe::the_empty_short_array()) {
     write_nest_members_attribute();
   }
+  if (ik()->permitted_subtypes() != Universe::the_empty_short_array()) {
+    write_permitted_subtypes_attribute();
+  }
 }
 
 // Write the method information portion of ClassFile structure
--- a/src/hotspot/share/prims/jvmtiClassFileReconstituter.hpp	Thu Jul 18 21:05:42 2019 +0000
+++ b/src/hotspot/share/prims/jvmtiClassFileReconstituter.hpp	Tue Jul 23 22:45:54 2019 +0000
@@ -118,6 +118,7 @@
   void write_bootstrapmethod_attribute();
   void write_nest_host_attribute();
   void write_nest_members_attribute();
+  void write_permitted_subtypes_attribute();
 
   address writeable_address(size_t size);
   void write_u1(u1 x);
--- a/src/hotspot/share/prims/jvmtiRedefineClasses.cpp	Thu Jul 18 21:05:42 2019 +0000
+++ b/src/hotspot/share/prims/jvmtiRedefineClasses.cpp	Tue Jul 23 22:45:54 2019 +0000
@@ -788,6 +788,63 @@
   return JVMTI_ERROR_NONE;
 }
 
+static jvmtiError check_permitted_subtypes_attribute(InstanceKlass* the_class,
+                                                     InstanceKlass* scratch_class) {
+  // Check whether the class NestMembers attribute has been changed.
+  Array<u2>* the_permitted_subtypes = the_class->permitted_subtypes();
+  Array<u2>* scr_permitted_subtypes = scratch_class->permitted_subtypes();
+  bool the_subtypes_exists = the_permitted_subtypes != Universe::the_empty_short_array();
+  bool scr_subtypes_exists = scr_permitted_subtypes != Universe::the_empty_short_array();
+  int subtypes_len = the_permitted_subtypes->length();
+  if (the_subtypes_exists && scr_subtypes_exists) {
+    if (subtypes_len != scr_permitted_subtypes->length()) {
+      log_trace(redefine, class, sealed)
+        ("redefined class %s attribute change error: PermittedSubtypes len=%d changed to len=%d",
+         the_class->external_name(), subtypes_len, scr_permitted_subtypes->length());
+      return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_CLASS_ATTRIBUTE_CHANGED;
+    }
+
+    // The order of entries in the PermittedSubtypes array is not specified so
+    // we have to explicitly check for the same contents. We do this by copying
+    // the referenced symbols into their own arrays, sorting them and then
+    // comparing each element pair.
+
+    Symbol** the_syms = NEW_RESOURCE_ARRAY_RETURN_NULL(Symbol*, subtypes_len);
+    Symbol** scr_syms = NEW_RESOURCE_ARRAY_RETURN_NULL(Symbol*, subtypes_len);
+
+    if (the_syms == NULL || scr_syms == NULL) {
+      return JVMTI_ERROR_OUT_OF_MEMORY;
+    }
+
+    for (int i = 0; i < subtypes_len; i++) {
+      int the_cp_index = the_permitted_subtypes->at(i);
+      int scr_cp_index = scr_permitted_subtypes->at(i);
+      the_syms[i] = the_class->constants()->klass_name_at(the_cp_index);
+      scr_syms[i] = scratch_class->constants()->klass_name_at(scr_cp_index);
+    }
+
+    qsort(the_syms, subtypes_len, sizeof(Symbol*), symcmp);
+    qsort(scr_syms, subtypes_len, sizeof(Symbol*), symcmp);
+
+    for (int i = 0; i < subtypes_len; i++) {
+      if (the_syms[i] != scr_syms[i]) {
+        log_trace(redefine, class, sealed)
+          ("redefined class %s attribute change error: PermittedSubtypes[%d]: %s changed to %s",
+           the_class->external_name(), i, the_syms[i]->as_C_string(), scr_syms[i]->as_C_string());
+        return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_CLASS_ATTRIBUTE_CHANGED;
+      }
+    }
+  } else if (the_subtypes_exists ^ scr_subtypes_exists) {
+    const char* action_str = (the_subtypes_exists) ? "removed" : "added";
+    log_trace(redefine, class, sealed)
+      ("redefined class %s attribute change error: PermittedSubtypes attribute %s",
+       the_class->external_name(), action_str);
+    return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_CLASS_ATTRIBUTE_CHANGED;
+  }
+
+  return JVMTI_ERROR_NONE;
+}
+
 static bool can_add_or_delete(Method* m) {
       // Compatibility mode
   return (AllowRedefinitionToAddDeleteMethods &&
@@ -841,6 +898,12 @@
     return err;
   }
 
+  // Check whether the PermittedSubtypes attribute has been changed.
+  err = check_permitted_subtypes_attribute(the_class, scratch_class);
+  if (err != JVMTI_ERROR_NONE) {
+    return err;
+  }
+
   // Check whether class modifiers are the same.
   jushort old_flags = (jushort) the_class->access_flags().get_flags();
   jushort new_flags = (jushort) scratch_class->access_flags().get_flags();
--- a/src/java.instrument/share/native/libinstrument/JavaExceptions.c	Thu Jul 18 21:05:42 2019 +0000
+++ b/src/java.instrument/share/native/libinstrument/JavaExceptions.c	Tue Jul 23 22:45:54 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -216,7 +216,7 @@
 
         case JVMTI_ERROR_UNSUPPORTED_REDEFINITION_CLASS_ATTRIBUTE_CHANGED:
                 throwableClassName = "java/lang/UnsupportedOperationException";
-                message = "class redefinition failed: attempted to change the class NestHost or NestMembers attribute";
+                message = "class redefinition failed: attempted to change the class NestHost, NestMembers, or PermittedSubtypes attribute";
                 break;
 
         case JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_MODIFIERS_CHANGED:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/runtime/modules/SealedModuleTest.java	Tue Jul 23 22:45:54 2019 +0000
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @modules java.base/jdk.internal.misc
+ * @library /test/lib ..
+ * @compile 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
+ */
+
+public class SealedModuleTest {
+
+    // Test sub-classing a sealed super class in a named module. In this test,
+    // sealed class sealedP1/superClass permits sealedP1.c1, sealedP2.c2, and
+    // sealedP3.c3.  All three of those classes extend sealedP1/superClass.
+
+    public static void main(String args[]) throws Throwable {
+        Object m1x, m2x;
+
+        // Get the class loader for SealedModuleTest and assume it's also used
+        // to load the other classes.
+        ClassLoader this_cldr = AccessCheckRead.class.getClassLoader();
+
+        // Define a module for packages sealedP1 and sealedP2.
+        m1x = ModuleHelper.ModuleObject("module_one", this_cldr,
+                                        new String[] { "sealedP1", "sealedP2" });
+        ModuleHelper.DefineModule(m1x, false, "9.0", "m1x/here",
+                                  new String[] { "sealedP1", "sealedP2" });
+
+        // Define a module for package sealedP3 with the same class loader.
+        m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "sealedP3" });
+        ModuleHelper.DefineModule(m2x, false, "9.0", "m2x/there", new String[] { "sealedP3" });
+
+        // Make package sealedP1 in m1x visible to everyone because it contains
+        // the super class for c1, c2, and c3.
+        ModuleHelper.AddModuleExportsToAll(m1x, "sealedP1");
+        ModuleHelper.AddReadsModule(m2x, m1x);
+
+        // Test subtype in the same named package and named module as its super
+        // class.  This should succeed.
+        // Class sealedP1.c1 extends class sealedP1.superClass.
+        Class p1_c1_class = Class.forName("sealedP1.c1");
+
+        // Test subtype in different named package but same named module as its
+        // super class. This should succeed.
+        // Class sealedP2.c2 extends class sealedP1.superClass.
+        Class p2_c2_class = Class.forName("sealedP2.c2");
+
+        // Test subtype in a different module than its super type.  This should
+        // fail even though they have the same class loader.
+        // Class sealedP3.c3 extends class sealedP1.superClass.
+        try {
+            Class p3_c3_class = Class.forName("sealedP3.c3");
+            throw new RuntimeException("Expected VerifyError exception not thrown");
+        } catch (VerifyError e) {
+            if (!e.getMessage().contains("cannot inherit from final class")) {
+                throw new RuntimeException("Wrong VerifyError exception thrown: " + e.getMessage());
+            }
+        }
+
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/runtime/modules/sealedP1/c1.java	Tue Jul 23 22:45:54 2019 +0000
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+// Small class used by SealedModuleTest
+package sealedP1;
+
+public class c1 extends sealedP1.superClass {
+
+    public c1 () { }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/runtime/modules/sealedP1/superClass.java	Tue Jul 23 22:45:54 2019 +0000
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+// Sealed super class used by SealedModuleTest.
+
+package sealedP1;
+
+public sealed class superClass permits sealedP1.c1, sealedP2.c2, sealedP3.c3 { }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/runtime/modules/sealedP2/c2.java	Tue Jul 23 22:45:54 2019 +0000
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+// Small class used by SealedModuleTest
+package sealedP2;
+
+public class c2 extends sealedP1.superClass {
+    public void method2() { }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/runtime/modules/sealedP3/c3.java	Tue Jul 23 22:45:54 2019 +0000
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+// Small class used by SealedModuleTest
+package sealedP3;
+
+public class c3 extends sealedP1.superClass {
+    public void method3() { }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/runtime/sealedTypes/Pkg/Permitted.java	Tue Jul 23 22:45:54 2019 +0000
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package Pkg;
+
+public class Permitted implements sealedInterface { }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/runtime/sealedTypes/Pkg/notPermitted.jcod	Tue Jul 23 22:45:54 2019 +0000
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+// This class was written using jcod because it implements sealed interface
+// sealedInterface but is not listed in its PermittedSubtypes attribute.
+// It consists of the following:
+//
+//    package Pkg;
+//    public class notPermitted implements sealedInterface { }
+//
+class Pkg/notPermitted {
+  0xCAFEBABE;
+  0; // minor version
+  58; // version
+  [15] { // Constant Pool
+    ; // first element is empty
+    Method #2 #3; // #1     at 0x0A
+    class #4; // #2     at 0x0F
+    NameAndType #5 #6; // #3     at 0x12
+    Utf8 "java/lang/Object"; // #4     at 0x17
+    Utf8 "<init>"; // #5     at 0x2A
+    Utf8 "()V"; // #6     at 0x33
+    class #8; // #7     at 0x39
+    Utf8 "Pkg/notPermitted"; // #8     at 0x3C
+    class #10; // #9     at 0x4C
+    Utf8 "Pkg/sealedInterface"; // #10     at 0x4F
+    Utf8 "Code"; // #11     at 0x65
+    Utf8 "LineNumberTable"; // #12     at 0x6C
+    Utf8 "SourceFile"; // #13     at 0x7E
+    Utf8 "notPermitted.java"; // #14     at 0x8B
+  } // Constant Pool
+
+  0x0031; // access [ ACC_PUBLIC ACC_SUPER ACC_FINAL ]
+  #7;// this_cpx
+  #2;// super_cpx
+
+  [1] { // Interfaces
+    #9;
+  } // Interfaces
+
+  [0] { // fields
+  } // fields
+
+  [1] { // methods
+    { // Member at 0xAA
+      0x0001; // access
+      #5; // name_cpx
+      #6; // sig_cpx
+      [1] { // Attributes
+        Attr(#11, 29) { // Code at 0xB2
+          1; // max_stack
+          1; // max_locals
+          Bytes[5]{
+            0x2AB70001B1;
+          };
+          [0] { // Traps
+          } // end Traps
+          [1] { // Attributes
+            Attr(#12, 6) { // LineNumberTable at 0xC9
+              [1] { // LineNumberTable
+                0  26; //  at 0xD5
+              }
+            } // end LineNumberTable
+          } // Attributes
+        } // end Code
+      } // Attributes
+    } // Member
+  } // methods
+
+  [1] { // Attributes
+    Attr(#13, 2) { // SourceFile at 0xD7
+      #14;
+    } // end SourceFile
+  } // Attributes
+} // end class Pkg/notPermitted
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/runtime/sealedTypes/Pkg/sealedInterface.java	Tue Jul 23 22:45:54 2019 +0000
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package Pkg;
+
+sealed public interface sealedInterface permits Permitted, otherPkg.wrongPackage { }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/runtime/sealedTypes/SealedUnnamedModuleIntfTest.java	Tue Jul 23 22:45:54 2019 +0000
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @compile otherPkg/wrongPackage.java Pkg/Permitted.java Pkg/notPermitted.jcod Pkg/sealedInterface.java
+ * @run main/othervm SealedUnnamedModuleIntfTest
+ */
+
+public class SealedUnnamedModuleIntfTest {
+
+    public static void main(String args[]) throws Throwable {
+
+        // Classes Permitted, notPermitted, and wrongPackage all try to implement
+        // sealed interface sealedInterface.
+        // Interface sealedInterface permits classes Permitted and wrongPackage.
+
+        // Test permitted subtype and supertype in unnamed module and same package.
+        // This should succeed.
+        Class permitted = Class.forName("Pkg.Permitted");
+
+        // Test unpermitted subtype and supertype in unnamed module and same package.
+        // This should throw an exception.
+        try {
+            Class notPermitted = Class.forName("Pkg.notPermitted");
+            throw new RuntimeException("Expected VerifyError exception not thrown");
+        } catch (VerifyError e) {
+            if (!e.getMessage().contains("cannot implement sealed interface")) {
+                throw new RuntimeException("Wrong VerifyError exception thrown: " + e.getMessage());
+            }
+        }
+
+        // Test both permitted subtype and supertype in unnamed module but in different
+        // packages.  This should throw an exception.
+        try {
+            Class wrongPkg = Class.forName("otherPkg.wrongPackage");
+        } catch (VerifyError e) {
+            if (!e.getMessage().contains("cannot implement sealed interface")) {
+                throw new RuntimeException("Wrong VerifyError exception thrown: " + e.getMessage());
+            }
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/runtime/sealedTypes/SealedUnnamedModuleTest.java	Tue Jul 23 22:45:54 2019 +0000
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @compile asteroids/Pluto.java planets/Neptune.java planets/Mars.jcod planets/outerPlanets.java
+ * @run main/othervm SealedUnnamedModuleTest
+ */
+
+public class SealedUnnamedModuleTest {
+
+    public static void main(String args[]) throws Throwable {
+
+        // Classes Neptune, Mars, and Pluto all try to extend sealed class outerPlanets.
+        // Class outerPlanets permits Nepturn and Pluto.
+
+        // Test permitted subtype and supertype in unnamed module and same package.
+        // This should succeed.
+        Class neptune = Class.forName("planets.Neptune");
+
+        // Test unpermitted subtype and supertype in unnamed module and same package.
+        // This should fail.
+        try {
+            Class mars = Class.forName("planets.Mars");
+            throw new RuntimeException("Expected VerifyError exception not thrown");
+        } catch (VerifyError e) {
+            if (!e.getMessage().contains("cannot inherit from final class")) {
+                throw new RuntimeException("Wrong VerifyError exception thrown: " + e.getMessage());
+            }
+        }
+
+        // Test both permitted subtype and supertype in unnamed module but in different
+        // packages.  This should fail.
+        try {
+            Class pluto = Class.forName("asteroids.Pluto");
+        } catch (VerifyError e) {
+            if (!e.getMessage().contains("cannot inherit from final class")) {
+                throw new RuntimeException("Wrong VerifyError exception thrown: " + e.getMessage());
+            }
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/runtime/sealedTypes/asteroids/Pluto.java	Tue Jul 23 22:45:54 2019 +0000
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package asteroids;
+
+public class Pluto extends planets.outerPlanets { }
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/runtime/sealedTypes/otherPkg/wrongPackage.java	Tue Jul 23 22:45:54 2019 +0000
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package otherPkg;
+
+public class wrongPackage implements Pkg.sealedInterface { }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/runtime/sealedTypes/planets/Mars.jcod	Tue Jul 23 22:45:54 2019 +0000
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+// This class was written using jcod because it extends sealed class
+// planets.outerPlanets but is not listed in its PermittedSubtypes
+// attribute.  It consists of the following:
+//
+//    package planets;
+//    public class Mars extends outerPlanets { }
+//
+class planets/Mars {
+  0xCAFEBABE;
+  0; // minor version
+  58; // version
+  [13] { // Constant Pool
+    ; // first element is empty
+    Method #2 #3; // #1     at 0x0A
+    class #4; // #2     at 0x0F
+    NameAndType #5 #6; // #3     at 0x12
+    Utf8 "planets/outerPlanets"; // #4     at 0x17
+    Utf8 "<init>"; // #5     at 0x2E
+    Utf8 "()V"; // #6     at 0x37
+    class #8; // #7     at 0x3D
+    Utf8 "planets/Mars"; // #8     at 0x40
+    Utf8 "Code"; // #9     at 0x52
+    Utf8 "LineNumberTable"; // #10     at 0x59
+    Utf8 "SourceFile"; // #11     at 0x6B
+    Utf8 "Mars.java"; // #12     at 0x78
+  } // Constant Pool
+
+  0x0031; // access [ ACC_PUBLIC ACC_SUPER ACC_FINAL ]
+  #7;// this_cpx
+  #2;// super_cpx
+
+  [0] { // Interfaces
+  } // Interfaces
+
+  [0] { // fields
+  } // fields
+
+  [1] { // methods
+    { // Member at 0x93
+      0x0001; // access
+      #5; // name_cpx
+      #6; // sig_cpx
+      [1] { // Attributes
+        Attr(#9, 29) { // Code at 0x9B
+          1; // max_stack
+          1; // max_locals
+          Bytes[5]{
+            0x2AB70001B1;
+          };
+          [0] { // Traps
+          } // end Traps
+          [1] { // Attributes
+            Attr(#10, 6) { // LineNumberTable at 0xB2
+              [1] { // LineNumberTable
+                0  3; //  at 0xBE
+              }
+            } // end LineNumberTable
+          } // Attributes
+        } // end Code
+      } // Attributes
+    } // Member
+  } // methods
+
+  [1] { // Attributes
+    Attr(#11, 2) { // SourceFile at 0xC0
+      #12;
+    } // end SourceFile
+  } // Attributes
+} // end class planets/Mars
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/runtime/sealedTypes/planets/Neptune.java	Tue Jul 23 22:45:54 2019 +0000
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package planets;
+
+public class Neptune extends outerPlanets { }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/runtime/sealedTypes/planets/outerPlanets.java	Tue Jul 23 22:45:54 2019 +0000
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package planets;
+
+sealed public class outerPlanets permits Neptune, asteroids.Pluto { }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/runtime/sealedTypes/sealedTest.java	Tue Jul 23 22:45:54 2019 +0000
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @run main sealedTest
+ */
+
+public class sealedTest {
+
+    sealed class Sealed1 permits Sub1 {}
+
+    class Sub1 extends Sealed1 {}
+
+    sealed interface SealedI1 permits Sub2 {}
+
+    class Sub2 implements SealedI1 {}
+
+    sealed class Sealed2 {}
+
+    class Sub3 extends Sealed2 {}
+
+    Sub1 sub1 = new Sub1();
+    Sub2 sub2 = new Sub2();
+    Sub3 sub3 = new Sub3();
+
+    public static void main(String... args) {
+        System.out.println("Basic testing of sealed types");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/serviceability/jvmti/RedefineClasses/RedefinePermittedSubtypes.java	Tue Jul 23 22:45:54 2019 +0000
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @summary Test that PermittedSubtypes attribute cannot be redefined.
+ * @library /test/lib
+ * @modules java.base/jdk.internal.misc
+ * @modules java.compiler
+ *          java.instrument
+ *          jdk.jartool/sun.tools.jar
+ * @run main RedefineClassHelper
+ * @run main/othervm -javaagent:redefineagent.jar RedefinePermittedSubtypes
+ */
+
+// package access top-level class to avoid problem with RedefineClassHelper
+// and nested types.
+sealed class RedefinePermittedSubtypes_B permits java.lang.String, java.lang.Class { }
+
+public class RedefinePermittedSubtypes {
+
+    public static String newBGood =
+        "sealed class RedefinePermittedSubtypes_B permits java.lang.Class, java.lang.String { }";
+
+    public static String newBBad =
+        "sealed class RedefinePermittedSubtypes_B permits java.lang.String { }";
+
+    public static void main(String[] args) throws Exception {
+
+        // Test redefinition is okay if permitted types are the same.
+        RedefineClassHelper.redefineClass(RedefinePermittedSubtypes_B.class, newBGood);
+
+        // Test redefinition fails if permitted types are different.
+        try {
+            RedefineClassHelper.redefineClass(RedefinePermittedSubtypes_B.class, newBBad);
+           throw new RuntimeException("Expected UnsupportedOperationException not thrown");
+        } catch (java.lang.UnsupportedOperationException e) {
+            if (!e.getMessage().contains("class redefinition failed: attempted to change the class NestHost, NestMembers, or PermittedSubtypes attribute")) {
+                throw new RuntimeException(
+                    "Wrong UnsupportedOperationException thrown:" + e.getMessage());
+            }
+        }
+    }
+}