changeset 56897:4b162290687a records-and-sealed

delta applying patch to dont add final flag to sealed classes
author vromero
date Mon, 24 Jun 2019 18:07:26 -0400
parents 76ea6cf6e40a
children d4e8276ce5b3
files src/hotspot/share/classfile/classFileParser.cpp src/hotspot/share/oops/instanceKlass.cpp src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassWriter.java
diffstat 4 files changed, 12 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/classfile/classFileParser.cpp	Fri Jun 21 16:51:43 2019 -0400
+++ b/src/hotspot/share/classfile/classFileParser.cpp	Mon Jun 24 18:07:26 2019 -0400
@@ -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	Fri Jun 21 16:51:43 2019 -0400
+++ b/src/hotspot/share/oops/instanceKlass.cpp	Mon Jun 24 18:07:26 2019 -0400
@@ -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/jvm/ClassReader.java	Fri Jun 21 16:51:43 2019 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Mon Jun 24 18:07:26 2019 -0400
@@ -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	Fri Jun 21 16:51:43 2019 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Mon Jun 24 18:07:26 2019 -0400
@@ -1696,6 +1696,8 @@
             result |= ACC_VARARGS;
         if ((flags & DEFAULT) != 0)
             result &= ~ABSTRACT;
+        if ((flags & SEALED) != 0)
+            result |= FINAL;
         return result;
     }