8160487: JVM should validate a module by checking for an instance of java.lang.reflect.Module
authorlfoltan
Thu, 28 Jul 2016 09:57:49 -0400
changeset 40020 20738e6bef83
parent 40019 d9fd741c3467
child 40021 a7d6cce8c431
child 40093 f94d179a730b
child 40098 8db886f4617c
8160487: JVM should validate a module by checking for an instance of java.lang.reflect.Module Summary: Correct the checking of an instance of java.lang.reflect.Module to validate a module Reviewed-by: alanb, coleenp, redestad
hotspot/src/share/vm/classfile/javaClasses.hpp
hotspot/src/share/vm/classfile/javaClasses.inline.hpp
hotspot/src/share/vm/classfile/modules.cpp
hotspot/test/runtime/modules/JVMDefineModule.java
--- a/hotspot/src/share/vm/classfile/javaClasses.hpp	Wed Jul 27 18:43:52 2016 +0300
+++ b/hotspot/src/share/vm/classfile/javaClasses.hpp	Thu Jul 28 09:57:49 2016 -0400
@@ -777,9 +777,6 @@
     static Handle create(Handle loader, Handle module_name, TRAPS);
 
     // Testers
-    static bool is_subclass(Klass* klass) {
-      return klass->is_subclass_of(SystemDictionary::reflect_Module_klass());
-    }
     static bool is_instance(oop obj);
 
     // Accessors
--- a/hotspot/src/share/vm/classfile/javaClasses.inline.hpp	Wed Jul 27 18:43:52 2016 +0300
+++ b/hotspot/src/share/vm/classfile/javaClasses.inline.hpp	Thu Jul 28 09:57:49 2016 -0400
@@ -168,11 +168,8 @@
   return obj != NULL && is_subclass(obj->klass());
 }
 
-
-
-
 inline bool java_lang_reflect_Module::is_instance(oop obj) {
-  return obj != NULL && is_subclass(obj->klass());
+  return obj != NULL && obj->klass() == SystemDictionary::reflect_Module_klass();
 }
 
 inline int Backtrace::merge_bci_and_version(int bci, int version) {
--- a/hotspot/src/share/vm/classfile/modules.cpp	Wed Jul 27 18:43:52 2016 +0300
+++ b/hotspot/src/share/vm/classfile/modules.cpp	Thu Jul 28 09:57:49 2016 -0400
@@ -102,7 +102,8 @@
 static ModuleEntry* get_module_entry(jobject module, TRAPS) {
   Handle module_h(THREAD, JNIHandles::resolve(module));
   if (!java_lang_reflect_Module::is_instance(module_h())) {
-    THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "Bad module object");
+    THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(),
+                   "module is not an instance of type java.lang.reflect.Module");
   }
   return java_lang_reflect_Module::module_entry(module_h(), CHECK_NULL);
 }
@@ -267,9 +268,9 @@
     THROW_MSG(vmSymbols::java_lang_NullPointerException(), "Null module object");
   }
   Handle module_handle(THREAD, JNIHandles::resolve(module));
-  if (!java_lang_reflect_Module::is_subclass(module_handle->klass())) {
+  if (!java_lang_reflect_Module::is_instance(module_handle())) {
     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
-              "module is not a subclass of java.lang.reflect.Module");
+              "module is not an instance of type java.lang.reflect.Module");
   }
 
   char* module_name = get_module_name(module_handle(), CHECK);
@@ -452,9 +453,9 @@
     THROW_MSG(vmSymbols::java_lang_NullPointerException(), "Null module object");
   }
   Handle module_handle(THREAD, JNIHandles::resolve(module));
-  if (!java_lang_reflect_Module::is_subclass(module_handle->klass())) {
+  if (!java_lang_reflect_Module::is_instance(module_handle())) {
     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
-              "module is not a subclass of java.lang.reflect.Module");
+              "module is not an instance of type java.lang.reflect.Module");
   }
 
   // Ensure that this is an unnamed module
@@ -728,7 +729,7 @@
   oop module = java_lang_Class::module(mirror);
 
   assert(module != NULL, "java.lang.Class module field not set");
-  assert(java_lang_reflect_Module::is_subclass(module->klass()), "Module is not a java.lang.reflect.Module");
+  assert(java_lang_reflect_Module::is_instance(module), "module is not an instance of type java.lang.reflect.Module");
 
   if (log_is_enabled(Debug, modules)) {
     ResourceMark rm(THREAD);
--- a/hotspot/test/runtime/modules/JVMDefineModule.java	Wed Jul 27 18:43:52 2016 +0300
+++ b/hotspot/test/runtime/modules/JVMDefineModule.java	Thu Jul 28 09:57:49 2016 -0400
@@ -77,7 +77,7 @@
             ModuleHelper.DefineModule(new Object(),  "9.0", "mymodule/here", new String[] { "mypackage1" });
             throw new RuntimeException("Failed to get expected IAE or NPE for bad module");
         } catch(IllegalArgumentException e) {
-            if (!e.getMessage().contains("module is not a subclass")) {
+            if (!e.getMessage().contains("module is not an instance of type java.lang.reflect.Module")) {
               throw new RuntimeException("Failed to get expected IAE message for bad module: " + e.getMessage());
             }
         }