changeset 56899:93144cfc2d71 amber-demo-II

Automatic merge with records-and-sealed
author mcimadamore
date Tue, 25 Jun 2019 01:40:58 +0200
parents 6f4f37689df0 d4e8276ce5b3
children 74b05fef33c6
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java
diffstat 5 files changed, 15 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/classfile/classFileParser.cpp	Mon Jun 24 11:00:53 2019 -0400
+++ b/src/hotspot/share/classfile/classFileParser.cpp	Tue Jun 25 01:40:58 2019 +0200
@@ -3668,6 +3668,9 @@
           _nest_host = class_info_index;
         } else if (tag == vmSymbols::tag_permitted_subtypes()) {
             // Check for PermittedSubtypes tag
+            if (!_access_flags.is_final()) {
+                classfile_parse_error("PermittedSubtypes attribute in non-final class file %s", CHECK);
+            }
             if (parsed_permitted_subtypes_attribute) {
               classfile_parse_error("Multiple PermittedSubtypes attributes in class file %s", CHECK);
             } else {
@@ -6461,7 +6464,8 @@
   _all_mirandas = new GrowableArray<Method*>(20);
 
   Handle loader(THREAD, _loader_data->class_loader());
-  bool is_sealed = _permitted_subtypes != NULL &&
+  bool is_sealed = _access_flags.is_final() &&
+                         _permitted_subtypes != NULL &&
                          _permitted_subtypes != Universe::the_empty_short_array() &&
                          _permitted_subtypes->length() > 0;
   klassVtable::compute_vtable_size_and_num_mirandas(&_vtable_size,
@@ -6496,11 +6500,9 @@
   assert(NULL != _klass, "_klass should have been resolved before calling this method");
   if (_super_klass != NULL) {
     if (_super_klass->is_final()) {
-      THROW_MSG(vmSymbols::java_lang_VerifyError(), "Cannot inherit from final class");
-    } else if (_super_klass->is_sealed()) {
       bool isPermittedSubtype = _super_klass->has_as_permitted_subtype(_klass, CHECK);
       if (!isPermittedSubtype) {
-        THROW_MSG(vmSymbols::java_lang_VerifyError(), "Cannot inherit from sealed class");
+        THROW_MSG(vmSymbols::java_lang_VerifyError(), "Cannot inherit from final class");
       }
     }
   }
@@ -6509,11 +6511,9 @@
     for (int i = 0; i < local_interfaces->length(); i++) {
       InstanceKlass* intf = local_interfaces->at(i);
       if (intf->is_final()) {
-        THROW_MSG(vmSymbols::java_lang_VerifyError(), "Cannot inherit from final interface");
-      } else if (intf->is_sealed()) {
         bool isPermittedSubtype = intf->has_as_permitted_subtype(_klass, CHECK);
         if (!isPermittedSubtype) {
-          THROW_MSG(vmSymbols::java_lang_VerifyError(), "Cannot inherit from sealed interface");
+          THROW_MSG(vmSymbols::java_lang_VerifyError(), "Cannot inherit from final interface");
         }
       }
     }
--- a/src/hotspot/share/oops/instanceKlass.cpp	Mon Jun 24 11:00:53 2019 -0400
+++ b/src/hotspot/share/oops/instanceKlass.cpp	Tue Jun 25 01:40:58 2019 +0200
@@ -677,7 +677,8 @@
 }
 
 bool InstanceKlass::is_sealed() const {
-  return _permitted_subtypes != NULL &&
+  return is_final() &&
+        _permitted_subtypes != NULL &&
         _permitted_subtypes != Universe::the_empty_short_array() &&
         _permitted_subtypes->length() > 0;
 }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Mon Jun 24 11:00:53 2019 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Tue Jun 25 01:40:58 2019 +0200
@@ -4970,9 +4970,10 @@
 
         for (Pair<ClassType, JCExpression> sealedParentPair: potentiallySealedParents) {
             if (!sealedParentPair.fst.permitted.map(t -> t.tsym).contains(c.type.tsym)) {
-                boolean areNestmates = sealedParentPair.fst.tsym.outermostClass() == tree.sym.outermostClass();
+                boolean areInSameCompilationUnit = TreeInfo.declarationFor(sealedParentPair.fst.tsym, env.toplevel) != null &&
+                        TreeInfo.declarationFor(tree.sym.outermostClass(), env.toplevel) != null;
                 boolean isSealed = sealedParentPair.fst.tsym.isSealed();
-                if (areNestmates) {
+                if (areInSameCompilationUnit) {
                     if (sealedParentPair.fst.tsym.isSealed() && !((ClassType)sealedParentPair.fst.tsym.type).isPermittedExplicit) {
                         sealedParentPair.fst.permitted = sealedParentPair.fst.permitted.prepend(tree.sym.type);
                     } else if (!dontErrorIfSealedExtended) {
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Mon Jun 24 11:00:53 2019 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Tue Jun 25 01:40:58 2019 +0200
@@ -2485,6 +2485,7 @@
 
         if (ct.permitted != null && !ct.permitted.isEmpty()) {
             c.flags_field |= SEALED;
+            c.flags_field &= ~FINAL;
         }
 
         // reset and read rest of classinfo
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Mon Jun 24 11:00:53 2019 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Tue Jun 25 01:40:58 2019 +0200
@@ -1696,6 +1696,8 @@
             result |= ACC_VARARGS;
         if ((flags & DEFAULT) != 0)
             result &= ~ABSTRACT;
+        if ((flags & SEALED) != 0)
+            result |= FINAL;
         return result;
     }