changeset 9740:ec9ad3190695

Improve module related IAE error messages, add unnamed module identity hash to messages.
author hseigel
date Wed, 02 Dec 2015 10:23:26 -0500
parents 94ae06d1ae14
children dc5bb2b5fd78
files src/share/vm/classfile/modules.cpp src/share/vm/runtime/reflection.cpp test/runtime/modules/AccessCheck/NmodNpkgDiffCL_PkgExpQualOther.java test/runtime/modules/AccessCheck/NmodNpkgDiffCL_PkgNotExp.java test/runtime/modules/AccessCheck/NmodNpkg_PkgExpQualOther.java test/runtime/modules/AccessCheck/NmodNpkg_PkgNotExp.java test/runtime/modules/AccessCheck/NmodNpkg_UmodUPkg.java test/runtime/modules/AccessCheck/UmodNpkgDiffCL_PkgExpQualOther.java test/runtime/modules/AccessCheck/UmodNpkgDiffCL_PkgNotExp.java test/runtime/modules/AccessCheck/UmodNpkg_PkgExpQualOther.java test/runtime/modules/AccessCheck/UmodNpkg_PkgNotExp.java test/runtime/modules/AccessCheck/UmodUpkgDiffCL_PkgExpQualOther.java test/runtime/modules/AccessCheck/UmodUpkgDiffCL_PkgNotExp.java test/runtime/modules/AccessCheck/UmodUpkg_PkgExpQualOther.java test/runtime/modules/AccessCheck/UmodUpkg_PkgNotExp.java test/runtime/modules/AccessCheckExp.java test/runtime/modules/AccessCheckRead.java test/runtime/modules/AccessCheckSuper.java test/runtime/modules/AccessCheckUnnamed.java test/runtime/modules/JVMAddModuleExportToAllUnnamed.java
diffstat 20 files changed, 75 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/classfile/modules.cpp	Mon Nov 30 14:57:39 2015 -0800
+++ b/src/share/vm/classfile/modules.cpp	Wed Dec 02 10:23:26 2015 -0500
@@ -449,14 +449,6 @@
       if (module_entry == NULL) {
         dupl_modules = true;
       } else {
-        if (TraceModules) {
-          tty->print("[define_module(): Definition of module: %s, version: %s, location: %s, ",
-            module_name, module_version != NULL ? module_version : "NULL",
-            module_location != NULL ? module_location : "NULL");
-          loader_data->print_value();
-          tty->print_cr(", package #: %d]", pkg_list->length());
-        }
-
         // Add the packages.
         assert(pkg_list->length() == 0 || package_table != NULL, "Bad package table");
         PackageEntry* pkg;
@@ -464,11 +456,6 @@
           pkg = package_table->locked_create_entry_or_null(pkg_list->at(y), module_entry);
           assert(pkg != NULL, "Unable to create a module's package entry");
 
-          if (TraceModules) {
-            tty->print_cr("[define_module(): creation of package %s for module %s]",
-                          (pkg_list->at(y))->as_C_string(), module_name);
-          }
-
           // Unable to have a GrowableArray of TempNewSymbol.  Must decrement the refcount of
           // the Symbol* that was created above for each package. The refcount was incremented
           // by SymbolTable::new_symbol and as well by the PackageEntry creation.
@@ -492,6 +479,18 @@
                       pkg_list->at(dupl_pkg_index)->as_C_string(), module_name));
   }
 
+  if (TraceModules) {
+    tty->print("[define_module(): creation of module: %s, version: %s, location: %s, ",
+      module_name, module_version != NULL ? module_version : "NULL",
+      module_location != NULL ? module_location : "NULL");
+    loader_data->print_value();
+    tty->print_cr(", package #: %d]", pkg_list->length());
+    for (int y = 0; y < pkg_list->length(); y++) {
+      tty->print_cr("[define_module(): creation of package %s for module %s]",
+                    (pkg_list->at(y))->as_C_string(), module_name);
+    }
+  }
+
   if (loader == NULL && !Universe::is_module_initialized()) {
     // Now that the module is defined, if it is in the bootloader, make sure that
     // its classes can be found.  Check if -Xpatch:<path> was specified.  If
--- a/src/share/vm/runtime/reflection.cpp	Mon Nov 30 14:57:39 2015 -0800
+++ b/src/share/vm/runtime/reflection.cpp	Wed Dec 02 10:23:26 2015 -0500
@@ -533,29 +533,55 @@
     ModuleEntry* module_from = InstanceKlass::cast(current_class)->module();
     const char * module_from_name = module_from->is_named() ?
       module_from->name()->as_C_string() : UNNAMED_MODULE;
-    size_t len = 122 + strlen(current_class_name) + strlen(new_class_name) +
-      strlen(module_to_name) + 2 * strlen(module_from_name);
 
     if (result == MODULE_NOT_READABLE) {
-      len = len + strlen(module_to_name);
-      msg = NEW_RESOURCE_ARRAY(char, len);
-      jio_snprintf(msg, len - 1,
-        "class %s (in%s module: %s) cannot access class %s (in module: %s), %s cannot read %s",
-        current_class_name,
-        module_to->is_named() ? "" : " strict",
-        module_from_name, new_class_name,
-        module_to_name, module_from_name, module_to_name);
+      assert(module_from->is_named(), "Unnamed modules can read all modules");
+      if (module_to->is_named()) {
+        size_t len = 100 + strlen(current_class_name) + 2*strlen(module_from_name) +
+          strlen(new_class_name) + 2*strlen(module_to_name);
+        msg = NEW_RESOURCE_ARRAY(char, len);
+        jio_snprintf(msg, len - 1,
+          "class %s (in module %s) cannot access class %s (in module %s) because module %s does not read module %s",
+          current_class_name, module_from_name, new_class_name,
+          module_to_name, module_from_name, module_to_name);
+      } else {
+        jobject jlrm = module_to->jlrM_module();
+        assert(jlrm != NULL, "Null jlrm in module_to ModuleEntry");
+        intptr_t identity_hash = JNIHandles::resolve(jlrm)->identity_hash();
+        size_t len = 160 + strlen(current_class_name) + 2*strlen(module_from_name) +
+          strlen(new_class_name) + 2*sizeof(uintx);
+        msg = NEW_RESOURCE_ARRAY(char, len);
+        jio_snprintf(msg, len - 1,
+          "class %s (in module %s) cannot access class %s (in unnamed module @" SIZE_FORMAT_HEX ") because module %s does not read unnamed module @" SIZE_FORMAT_HEX,
+          current_class_name, module_from_name, new_class_name, uintx(identity_hash),
+          module_from_name, uintx(identity_hash));
+      }
 
     } else if (result == TYPE_NOT_EXPORTED) {
-      if (InstanceKlass::cast(new_class)->package() != NULL) {
-          const char * package_name =
-            InstanceKlass::cast(new_class)->package()->name()->as_klass_external_name();
-          len = len + strlen(package_name);
-          msg = NEW_RESOURCE_ARRAY(char, len);
-          jio_snprintf(msg, len - 1,
-            "class %s (in module: %s) cannot access class %s (in module: %s), %s is not exported to %s",
-            current_class_name, module_from_name, new_class_name,
-            module_to_name, package_name, module_from_name);
+      assert(InstanceKlass::cast(new_class)->package() != NULL,
+             "Unnamed packages are always exported");
+      const char * package_name =
+        InstanceKlass::cast(new_class)->package()->name()->as_klass_external_name();
+      assert(module_to->is_named(), "Unnamed modules export all packages");
+      if (module_from->is_named()) {
+        size_t len = 118 + strlen(current_class_name) + 2*strlen(module_from_name) +
+          strlen(new_class_name) + 2*strlen(module_to_name) + strlen(package_name);
+        msg = NEW_RESOURCE_ARRAY(char, len);
+        jio_snprintf(msg, len - 1,
+          "class %s (in module %s) cannot access class %s (in module %s) because module %s does not export %s to module %s",
+          current_class_name, module_from_name, new_class_name,
+          module_to_name, module_to_name, package_name, module_from_name);
+      } else {
+        jobject jlrm = module_from->jlrM_module();
+        assert(jlrm != NULL, "Null jlrm in module_from ModuleEntry");
+        intptr_t identity_hash = JNIHandles::resolve(jlrm)->identity_hash();
+        size_t len = 170 + strlen(current_class_name) + strlen(new_class_name) +
+          2*strlen(module_to_name) + strlen(package_name) + 2*sizeof(uintx);
+        msg = NEW_RESOURCE_ARRAY(char, len);
+        jio_snprintf(msg, len - 1,
+          "class %s (in unnamed module @" SIZE_FORMAT_HEX ") cannot access class %s (in module %s) because module %s does not export %s to unnamed module @" SIZE_FORMAT_HEX,
+          current_class_name, uintx(identity_hash), new_class_name, module_to_name,
+          module_to_name, package_name, uintx(identity_hash));
       }
     } else {
         ShouldNotReachHere();
--- a/test/runtime/modules/AccessCheck/NmodNpkgDiffCL_PkgExpQualOther.java	Mon Nov 30 14:57:39 2015 -0800
+++ b/test/runtime/modules/AccessCheck/NmodNpkgDiffCL_PkgExpQualOther.java	Wed Dec 02 10:23:26 2015 -0500
@@ -129,7 +129,7 @@
             throw new RuntimeException("Failed to get IAE (p2 in m2 is exported to m3 not to m1)");
         } catch (IllegalAccessError e) {
             System.out.println(e.getMessage());
-            if (!e.getMessage().contains("not exported")) {
+            if (!e.getMessage().contains("does not export")) {
                 throw new RuntimeException("Wrong message: " + e.getMessage());
             }
         }
--- a/test/runtime/modules/AccessCheck/NmodNpkgDiffCL_PkgNotExp.java	Mon Nov 30 14:57:39 2015 -0800
+++ b/test/runtime/modules/AccessCheck/NmodNpkgDiffCL_PkgNotExp.java	Wed Dec 02 10:23:26 2015 -0500
@@ -113,7 +113,7 @@
             throw new RuntimeException("Failed to get IAE (p2 in m2 is not exported)");
         } catch (IllegalAccessError e) {
           System.out.println(e.getMessage());
-          if (!e.getMessage().contains("not exported")) {
+          if (!e.getMessage().contains("does not export")) {
               throw new RuntimeException("Wrong message: " + e.getMessage());
           }
         }
--- a/test/runtime/modules/AccessCheck/NmodNpkg_PkgExpQualOther.java	Mon Nov 30 14:57:39 2015 -0800
+++ b/test/runtime/modules/AccessCheck/NmodNpkg_PkgExpQualOther.java	Wed Dec 02 10:23:26 2015 -0500
@@ -129,7 +129,7 @@
             throw new RuntimeException("Failed to get IAE (p2 in m2 is exported to m3 not to m1)");
         } catch (IllegalAccessError e) {
             System.out.println(e.getMessage());
-            if (!e.getMessage().contains("not exported")) {
+            if (!e.getMessage().contains("does not export")) {
                 throw new RuntimeException("Wrong message: " + e.getMessage());
             }
         }
--- a/test/runtime/modules/AccessCheck/NmodNpkg_PkgNotExp.java	Mon Nov 30 14:57:39 2015 -0800
+++ b/test/runtime/modules/AccessCheck/NmodNpkg_PkgNotExp.java	Wed Dec 02 10:23:26 2015 -0500
@@ -112,7 +112,7 @@
             throw new RuntimeException("Failed to get IAE (p2 in m2 is not exported)");
         } catch (IllegalAccessError e) {
           System.out.println(e.getMessage());
-          if (!e.getMessage().contains("not exported")) {
+          if (!e.getMessage().contains("does not export")) {
               throw new RuntimeException("Wrong message: " + e.getMessage());
           }
         }
--- a/test/runtime/modules/AccessCheck/NmodNpkg_UmodUPkg.java	Mon Nov 30 14:57:39 2015 -0800
+++ b/test/runtime/modules/AccessCheck/NmodNpkg_UmodUPkg.java	Wed Dec 02 10:23:26 2015 -0500
@@ -25,7 +25,7 @@
 
 /*
  * @test
- * @summary class p3.c3 defined in module m1 tries tries to access c4 defined in unnamed module.
+ * @summary class p3.c3 defined in module m1 tries to access c4 defined in unnamed module.
  * @library /testlibrary /../../test/lib
  * @compile myloaders/MySameClassLoader.java
  * @compile c4.java
--- a/test/runtime/modules/AccessCheck/UmodNpkgDiffCL_PkgExpQualOther.java	Mon Nov 30 14:57:39 2015 -0800
+++ b/test/runtime/modules/AccessCheck/UmodNpkgDiffCL_PkgExpQualOther.java	Wed Dec 02 10:23:26 2015 -0500
@@ -116,7 +116,7 @@
             throw new RuntimeException("Failed to get IAE (p2 in m2 is exported to m1, not unqualifiedly");
         } catch (IllegalAccessError e) {
             System.out.println(e.getMessage());
-            if (!e.getMessage().contains("not exported")) {
+            if (!e.getMessage().contains("does not export")) {
                 throw new RuntimeException("Wrong message: " + e.getMessage());
             }
         }
--- a/test/runtime/modules/AccessCheck/UmodNpkgDiffCL_PkgNotExp.java	Mon Nov 30 14:57:39 2015 -0800
+++ b/test/runtime/modules/AccessCheck/UmodNpkgDiffCL_PkgNotExp.java	Wed Dec 02 10:23:26 2015 -0500
@@ -115,7 +115,7 @@
             throw new RuntimeException("Failed to get IAE (p2 in m2 is not exported to an unnamed module)");
         } catch (IllegalAccessError e) {
           System.out.println(e.getMessage());
-          if (!e.getMessage().contains("not exported")) {
+          if (!e.getMessage().contains("does not export")) {
               throw new RuntimeException("Wrong message: " + e.getMessage());
           }
         }
--- a/test/runtime/modules/AccessCheck/UmodNpkg_PkgExpQualOther.java	Mon Nov 30 14:57:39 2015 -0800
+++ b/test/runtime/modules/AccessCheck/UmodNpkg_PkgExpQualOther.java	Wed Dec 02 10:23:26 2015 -0500
@@ -125,7 +125,7 @@
             throw new RuntimeException("Failed to get IAE (p2 in m2 is exported to m3, not unqualifiedly to everyone)");
         } catch (IllegalAccessError e) {
             System.out.println(e.getMessage());
-            if (!e.getMessage().contains("not exported")) {
+            if (!e.getMessage().contains("does not export")) {
                 throw new RuntimeException("Wrong message: " + e.getMessage());
             }
         }
--- a/test/runtime/modules/AccessCheck/UmodNpkg_PkgNotExp.java	Mon Nov 30 14:57:39 2015 -0800
+++ b/test/runtime/modules/AccessCheck/UmodNpkg_PkgNotExp.java	Wed Dec 02 10:23:26 2015 -0500
@@ -111,7 +111,7 @@
             throw new RuntimeException("Failed to get IAE (p2 in m2 is not exported)");
         } catch (IllegalAccessError e) {
           System.out.println(e.getMessage());
-          if (!e.getMessage().contains("not exported")) {
+          if (!e.getMessage().contains("does not export")) {
               throw new RuntimeException("Wrong message: " + e.getMessage());
           }
         }
--- a/test/runtime/modules/AccessCheck/UmodUpkgDiffCL_PkgExpQualOther.java	Mon Nov 30 14:57:39 2015 -0800
+++ b/test/runtime/modules/AccessCheck/UmodUpkgDiffCL_PkgExpQualOther.java	Wed Dec 02 10:23:26 2015 -0500
@@ -114,7 +114,7 @@
             throw new RuntimeException("Failed to get IAE (p6 in m2 is exported to m1, not unqualifiedly");
         } catch (IllegalAccessError e) {
             System.out.println(e.getMessage());
-            if (!e.getMessage().contains("not exported")) {
+            if (!e.getMessage().contains("does not export")) {
                 throw new RuntimeException("Wrong message: " + e.getMessage());
             }
         }
--- a/test/runtime/modules/AccessCheck/UmodUpkgDiffCL_PkgNotExp.java	Mon Nov 30 14:57:39 2015 -0800
+++ b/test/runtime/modules/AccessCheck/UmodUpkgDiffCL_PkgNotExp.java	Wed Dec 02 10:23:26 2015 -0500
@@ -116,7 +116,7 @@
                                        "an unnamed module that c5 is defined within)");
         } catch (IllegalAccessError e) {
           System.out.println(e.getMessage());
-          if (!e.getMessage().contains("not exported")) {
+          if (!e.getMessage().contains("does not export")) {
               throw new RuntimeException("Wrong message: " + e.getMessage());
           }
         }
--- a/test/runtime/modules/AccessCheck/UmodUpkg_PkgExpQualOther.java	Mon Nov 30 14:57:39 2015 -0800
+++ b/test/runtime/modules/AccessCheck/UmodUpkg_PkgExpQualOther.java	Wed Dec 02 10:23:26 2015 -0500
@@ -125,7 +125,7 @@
             throw new RuntimeException("Failed to get IAE (p6 in m2 is exported to m3, not unqualifiedly to everyone)");
         } catch (IllegalAccessError e) {
             System.out.println(e.getMessage());
-            if (!e.getMessage().contains("not exported")) {
+            if (!e.getMessage().contains("does not export")) {
                 throw new RuntimeException("Wrong message: " + e.getMessage());
             }
         }
--- a/test/runtime/modules/AccessCheck/UmodUpkg_PkgNotExp.java	Mon Nov 30 14:57:39 2015 -0800
+++ b/test/runtime/modules/AccessCheck/UmodUpkg_PkgNotExp.java	Wed Dec 02 10:23:26 2015 -0500
@@ -111,7 +111,7 @@
             throw new RuntimeException("Failed to get IAE (p6 in m2 is not exported)");
         } catch (IllegalAccessError e) {
           System.out.println(e.getMessage());
-          if (!e.getMessage().contains("not exported")) {
+          if (!e.getMessage().contains("does not export")) {
               throw new RuntimeException("Wrong message: " + e.getMessage());
           }
         }
--- a/test/runtime/modules/AccessCheckExp.java	Mon Nov 30 14:57:39 2015 -0800
+++ b/test/runtime/modules/AccessCheckExp.java	Wed Dec 02 10:23:26 2015 -0500
@@ -77,7 +77,7 @@
             throw new RuntimeException("Failed to get IAE (p2 in m2 is not exported");
         } catch (IllegalAccessError f) {
             System.out.println(f.getMessage());
-            if (!f.getMessage().contains("not exported")) {
+            if (!f.getMessage().contains("does not export")) {
                 throw new RuntimeException("Wrong message: " + f.getMessage());
             }
         }
--- a/test/runtime/modules/AccessCheckRead.java	Mon Nov 30 14:57:39 2015 -0800
+++ b/test/runtime/modules/AccessCheckRead.java	Wed Dec 02 10:23:26 2015 -0500
@@ -77,7 +77,7 @@
             throw new RuntimeException("Failed to get IAE (m1 can't read m2)");
         } catch (IllegalAccessError e) {
             System.out.println(e.getMessage());
-            if (!e.getMessage().contains("cannot read") ||
+            if (!e.getMessage().contains("does not read") ||
                 e.getMessage().contains("strict")) {
                 throw new RuntimeException("Wrong message: " + e.getMessage());
             }
--- a/test/runtime/modules/AccessCheckSuper.java	Mon Nov 30 14:57:39 2015 -0800
+++ b/test/runtime/modules/AccessCheckSuper.java	Wed Dec 02 10:23:26 2015 -0500
@@ -57,7 +57,7 @@
             throw new RuntimeException("Failed to get IAE (can't read superclass)");
         } catch (IllegalAccessError e) {
             if (!e.getMessage().contains("superclass access check failed") ||
-                !e.getMessage().contains("cannot read")) {
+                !e.getMessage().contains("does not read")) {
                 throw new RuntimeException("Wrong message: " + e.getMessage());
             }
         }
--- a/test/runtime/modules/AccessCheckUnnamed.java	Mon Nov 30 14:57:39 2015 -0800
+++ b/test/runtime/modules/AccessCheckUnnamed.java	Wed Dec 02 10:23:26 2015 -0500
@@ -66,7 +66,7 @@
             throw new RuntimeException("Failed to get IAE (p2 in m2 is not exported to unnamed module)");
         } catch (IllegalAccessError f) {
             System.out.println(f.getMessage());
-            if (!f.getMessage().contains("p2 is not exported to Unnamed Module")) {
+            if (!f.getMessage().contains("does not export p2 to unnamed module")) {
                 throw new RuntimeException("Wrong message: " + f.getMessage());
             }
         }
--- a/test/runtime/modules/JVMAddModuleExportToAllUnnamed.java	Mon Nov 30 14:57:39 2015 -0800
+++ b/test/runtime/modules/JVMAddModuleExportToAllUnnamed.java	Wed Dec 02 10:23:26 2015 -0500
@@ -68,8 +68,7 @@
             p1_c1_class.newInstance();
         } catch (IllegalAccessError e) {
             System.out.println(e.getMessage());
-            if (!e.getMessage().contains("cannot read Unnamed") ||
-                (!e.getMessage().contains("strict"))) {
+            if (!e.getMessage().contains("does not read unnamed module")) {
                 throw new RuntimeException("Wrong message: " + e.getMessage());
             }
         }