changeset 13526:f5dd157e3889 mvt

8186439: [MVT] ClassFileParser should ignore JVM_ACC_VALUE for class file version < 53.1 Reviewed-by: dsimms
author thartmann
date Mon, 21 Aug 2017 12:26:21 +0200
parents bc075a2f87ad
children d9b9c6c9c4b2
files src/share/vm/classfile/classFileParser.cpp src/share/vm/classfile/classFileParser.hpp src/share/vm/oops/instanceKlass.cpp src/share/vm/oops/instanceKlass.hpp src/share/vm/prims/jvm.h
diffstat 5 files changed, 37 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/classfile/classFileParser.cpp	Thu Aug 10 09:23:41 2017 +0200
+++ b/src/share/vm/classfile/classFileParser.cpp	Mon Aug 21 12:26:21 2017 +0200
@@ -3165,14 +3165,20 @@
       guarantee_property(inner_class_info_index != outer_class_info_index,
                          "Class is both outer and inner class in class file %s", CHECK_0);
     }
-    // Access flags
-    jint flags;
+
+    jint recognized_modifiers = RECOGNIZED_INNER_CLASS_MODIFIERS;
     // JVM_ACC_MODULE is defined in JDK-9 and later.
     if (_major_version >= JAVA_9_VERSION) {
-      flags = cfs->get_u2_fast() & (RECOGNIZED_INNER_CLASS_MODIFIERS | JVM_ACC_MODULE);
-    } else {
-      flags = cfs->get_u2_fast() & RECOGNIZED_INNER_CLASS_MODIFIERS;
+      recognized_modifiers |= JVM_ACC_MODULE;
     }
+    // JVM_ACC_VALUE is defined for class file version 53.1 and later
+    if (supports_value_types()) {
+      recognized_modifiers |= JVM_ACC_VALUE;
+    }
+
+    // Access flags
+    jint flags = cfs->get_u2_fast() & recognized_modifiers;
+
     if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) {
       // Set abstract bit for old class files for backward compatibility
       flags |= JVM_ACC_ABSTRACT;
@@ -4517,6 +4523,11 @@
   }
 }
 
+bool ClassFileParser::supports_value_types() const {
+  // Value types are only supported by class file version 53.1 and later
+  return _major_version > JAVA_9_VERSION || (_major_version == JAVA_9_VERSION && _minor_version >= 1);
+}
+
 // Attach super classes and interface classes to class loader data
 static void record_defined_class_dependencies(const InstanceKlass* defined_klass,
                                               TRAPS) {
@@ -4807,7 +4818,9 @@
 
 void ClassFileParser::verify_legal_class_modifiers(jint flags, TRAPS) const {
   const bool is_module = (flags & JVM_ACC_MODULE) != 0;
+  const bool is_value_type = (flags & JVM_ACC_VALUE) != 0;
   assert(_major_version >= JAVA_9_VERSION || !is_module, "JVM_ACC_MODULE should not be set");
+  assert(supports_value_types() || !is_value_type, "JVM_ACC_VALUE should not be set");
   if (is_module) {
     ResourceMark rm(THREAD);
     Exceptions::fthrow(
@@ -4853,7 +4866,7 @@
           (is_protected && is_private));
 }
 
-static bool is_supported_version(u2 major, u2 minor){
+static bool is_supported_version(u2 major, u2 minor) {
   const u2 max_version = JAVA_MAX_SUPPORTED_VERSION;
   return (major >= JAVA_MIN_SUPPORTED_VERSION) &&
          (major <= max_version) &&
@@ -6077,14 +6090,18 @@
   // ACCESS FLAGS
   stream->guarantee_more(8, CHECK);  // flags, this_class, super_class, infs_len
 
-  // Access flags
-  jint flags;
+  jint recognized_modifiers = JVM_RECOGNIZED_CLASS_MODIFIERS;
   // JVM_ACC_MODULE is defined in JDK-9 and later.
   if (_major_version >= JAVA_9_VERSION) {
-    flags = stream->get_u2_fast() & (JVM_RECOGNIZED_CLASS_MODIFIERS | JVM_ACC_MODULE);
-  } else {
-    flags = stream->get_u2_fast() & JVM_RECOGNIZED_CLASS_MODIFIERS;
-  }
+    recognized_modifiers |= JVM_ACC_MODULE;
+  }
+  // JVM_ACC_VALUE is defined for class file version 53.1 and later
+  if (supports_value_types()) {
+    recognized_modifiers |= JVM_ACC_VALUE;
+  }
+
+  // Access flags
+  jint flags = stream->get_u2_fast() & recognized_modifiers;
 
   if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) {
     // Set abstract bit for old class files for backward compatibility
--- a/src/share/vm/classfile/classFileParser.hpp	Thu Aug 10 09:23:41 2017 +0200
+++ b/src/share/vm/classfile/classFileParser.hpp	Mon Aug 21 12:26:21 2017 +0200
@@ -507,6 +507,9 @@
                      FieldLayoutInfo* info,
                      TRAPS);
 
+  // Check if the class file supports value types
+  bool supports_value_types() const;
+
  public:
   ClassFileParser(ClassFileStream* stream,
                   Symbol* name,
--- a/src/share/vm/oops/instanceKlass.cpp	Thu Aug 10 09:23:41 2017 +0200
+++ b/src/share/vm/oops/instanceKlass.cpp	Mon Aug 21 12:26:21 2017 +0200
@@ -167,8 +167,7 @@
     if (class_name == vmSymbols::java_lang_Class()) {
       // mirror
       ik = new (loader_data, size, THREAD) InstanceMirrorKlass(parser);
-    }
-    else if (is_class_loader(class_name, parser)) {
+    } else if (is_class_loader(class_name, parser)) {
       // class loader
       ik = new (loader_data, size, THREAD) InstanceClassLoaderKlass(parser);
     } else if (parser.is_value_type()) {
@@ -178,8 +177,7 @@
       // normal
       ik = new (loader_data, size, THREAD) InstanceKlass(parser, InstanceKlass::_misc_kind_other);
     }
-  }
-  else {
+  } else {
     // reference
     ik = new (loader_data, size, THREAD) InstanceRefKlass(parser);
   }
--- a/src/share/vm/oops/instanceKlass.hpp	Thu Aug 10 09:23:41 2017 +0200
+++ b/src/share/vm/oops/instanceKlass.hpp	Mon Aug 21 12:26:21 2017 +0200
@@ -385,14 +385,14 @@
     return (_extra_flags & _extra_has_value_fields) != 0;
   }
   void set_has_value_fields()  {
-      _extra_flags |= _extra_has_value_fields;
+    _extra_flags |= _extra_has_value_fields;
   }
 
   bool has_vcc_klass() const {
     return (_extra_flags & _extra_has_vcc_klass) != 0;
   }
   void set_has_vcc_klass() {
-        _extra_flags |= _extra_has_vcc_klass;
+    _extra_flags |= _extra_has_vcc_klass;
   }
 
 
--- a/src/share/vm/prims/jvm.h	Thu Aug 10 09:23:41 2017 +0200
+++ b/src/share/vm/prims/jvm.h	Mon Aug 21 12:26:21 2017 +0200
@@ -1144,8 +1144,7 @@
                                         JVM_ACC_ABSTRACT | \
                                         JVM_ACC_ANNOTATION | \
                                         JVM_ACC_ENUM | \
-                                        JVM_ACC_SYNTHETIC | \
-                                        JVM_ACC_VALUE)
+                                        JVM_ACC_SYNTHETIC)
 
 #define JVM_RECOGNIZED_FIELD_MODIFIERS (JVM_ACC_PUBLIC | \
                                         JVM_ACC_PRIVATE | \