diff src/hotspot/share/interpreter/linkResolver.cpp @ 51450:a73848f8d0ad

8199940: Print more information about class loaders in IllegalAccessErrors. Reviewed-by: lfoltan, mchung
author goetz
date Wed, 27 Jun 2018 09:52:23 +0200
parents cb07f4b539fc
children c661b8a1b310 8cc36fac7f3d
line wrap: on
line diff
--- a/src/hotspot/share/interpreter/linkResolver.cpp	Wed Jun 27 12:46:15 2018 +0200
+++ b/src/hotspot/share/interpreter/linkResolver.cpp	Wed Jun 27 09:52:23 2018 +0200
@@ -218,7 +218,7 @@
     fatal("Unexpected call kind %d", call_kind());
   }
 }
-#endif //ASSERT
+#endif // ASSERT
 
 #ifndef PRODUCT
 void CallInfo::print() {
@@ -294,7 +294,7 @@
       base_klass = ObjArrayKlass::cast(sel_klass)->bottom_klass();
     }
     // The element type could be a typeArray - we only need the access
-    // check if it is an reference to another class.
+    // check if it is a reference to another class.
     if (!base_klass->is_instance_klass()) {
       return;  // no relevant check to do
     }
@@ -306,13 +306,17 @@
     char* msg = Reflection::verify_class_access_msg(ref_klass,
                                                     InstanceKlass::cast(base_klass),
                                                     vca_result);
+    bool same_module = (base_klass->module() == ref_klass->module());
     if (msg == NULL) {
       Exceptions::fthrow(
         THREAD_AND_LOCATION,
         vmSymbols::java_lang_IllegalAccessError(),
-        "failed to access class %s from class %s",
+        "failed to access class %s from class %s (%s%s%s)",
         base_klass->external_name(),
-        ref_klass->external_name());
+        ref_klass->external_name(),
+        (same_module) ? base_klass->joint_in_module_of_loader(ref_klass) : base_klass->class_in_module_of_loader(),
+        (same_module) ? "" : "; ",
+        (same_module) ? "" : ref_klass->class_in_module_of_loader());
     } else {
       // Use module specific message returned by verify_class_access_msg().
       Exceptions::fthrow(
@@ -596,8 +600,11 @@
     Exceptions::fthrow(
       THREAD_AND_LOCATION,
       vmSymbols::java_lang_IllegalAccessError(),
-      "class %s tried to access method %s.%s%s (%s%s%s)",
+      "class %s tried to access %s%s%smethod %s.%s%s (%s%s%s)",
       ref_klass->external_name(),
+      sel_method->is_abstract()  ? "abstract "  : "",
+      sel_method->is_protected() ? "protected " : "",
+      sel_method->is_private()   ? "private "   : "",
       sel_klass->external_name(),
       sel_method->name()->as_C_string(),
       sel_method->signature()->as_C_string(),
@@ -927,14 +934,20 @@
   // Any existing exceptions that may have been thrown, for example LinkageErrors
   // from nest-host resolution, have been allowed to propagate.
   if (!can_access) {
+    bool same_module = (sel_klass->module() == ref_klass->module());
     ResourceMark rm(THREAD);
     Exceptions::fthrow(
       THREAD_AND_LOCATION,
       vmSymbols::java_lang_IllegalAccessError(),
-      "tried to access field %s.%s from class %s",
+      "class %s tried to access %s%sfield %s.%s (%s%s%s)",
+      ref_klass->external_name(),
+      fd.is_protected() ? "protected " : "",
+      fd.is_private()   ? "private "   : "",
       sel_klass->external_name(),
       fd.name()->as_C_string(),
-      ref_klass->external_name()
+      (same_module) ? ref_klass->joint_in_module_of_loader(sel_klass) : ref_klass->class_in_module_of_loader(),
+      (same_module) ? "" : "; ",
+      (same_module) ? "" : sel_klass->class_in_module_of_loader()
     );
     return;
   }