comparison 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
comparison
equal deleted inserted replaced
28:9a65902e1195 29:f8ca93edd20d
216 break; 216 break;
217 default: 217 default:
218 fatal("Unexpected call kind %d", call_kind()); 218 fatal("Unexpected call kind %d", call_kind());
219 } 219 }
220 } 220 }
221 #endif //ASSERT 221 #endif // ASSERT
222 222
223 #ifndef PRODUCT 223 #ifndef PRODUCT
224 void CallInfo::print() { 224 void CallInfo::print() {
225 ResourceMark rm; 225 ResourceMark rm;
226 const char* kindstr; 226 const char* kindstr;
292 if (fold_type_to_class) { 292 if (fold_type_to_class) {
293 if (sel_klass->is_objArray_klass()) { 293 if (sel_klass->is_objArray_klass()) {
294 base_klass = ObjArrayKlass::cast(sel_klass)->bottom_klass(); 294 base_klass = ObjArrayKlass::cast(sel_klass)->bottom_klass();
295 } 295 }
296 // The element type could be a typeArray - we only need the access 296 // The element type could be a typeArray - we only need the access
297 // check if it is an reference to another class. 297 // check if it is a reference to another class.
298 if (!base_klass->is_instance_klass()) { 298 if (!base_klass->is_instance_klass()) {
299 return; // no relevant check to do 299 return; // no relevant check to do
300 } 300 }
301 } 301 }
302 Reflection::VerifyClassAccessResults vca_result = 302 Reflection::VerifyClassAccessResults vca_result =
304 if (vca_result != Reflection::ACCESS_OK) { 304 if (vca_result != Reflection::ACCESS_OK) {
305 ResourceMark rm(THREAD); 305 ResourceMark rm(THREAD);
306 char* msg = Reflection::verify_class_access_msg(ref_klass, 306 char* msg = Reflection::verify_class_access_msg(ref_klass,
307 InstanceKlass::cast(base_klass), 307 InstanceKlass::cast(base_klass),
308 vca_result); 308 vca_result);
309 bool same_module = (base_klass->module() == ref_klass->module());
309 if (msg == NULL) { 310 if (msg == NULL) {
310 Exceptions::fthrow( 311 Exceptions::fthrow(
311 THREAD_AND_LOCATION, 312 THREAD_AND_LOCATION,
312 vmSymbols::java_lang_IllegalAccessError(), 313 vmSymbols::java_lang_IllegalAccessError(),
313 "failed to access class %s from class %s", 314 "failed to access class %s from class %s (%s%s%s)",
314 base_klass->external_name(), 315 base_klass->external_name(),
315 ref_klass->external_name()); 316 ref_klass->external_name(),
317 (same_module) ? base_klass->joint_in_module_of_loader(ref_klass) : base_klass->class_in_module_of_loader(),
318 (same_module) ? "" : "; ",
319 (same_module) ? "" : ref_klass->class_in_module_of_loader());
316 } else { 320 } else {
317 // Use module specific message returned by verify_class_access_msg(). 321 // Use module specific message returned by verify_class_access_msg().
318 Exceptions::fthrow( 322 Exceptions::fthrow(
319 THREAD_AND_LOCATION, 323 THREAD_AND_LOCATION,
320 vmSymbols::java_lang_IllegalAccessError(), 324 vmSymbols::java_lang_IllegalAccessError(),
594 ResourceMark rm(THREAD); 598 ResourceMark rm(THREAD);
595 bool same_module = (sel_klass->module() == ref_klass->module()); 599 bool same_module = (sel_klass->module() == ref_klass->module());
596 Exceptions::fthrow( 600 Exceptions::fthrow(
597 THREAD_AND_LOCATION, 601 THREAD_AND_LOCATION,
598 vmSymbols::java_lang_IllegalAccessError(), 602 vmSymbols::java_lang_IllegalAccessError(),
599 "class %s tried to access method %s.%s%s (%s%s%s)", 603 "class %s tried to access %s%s%smethod %s.%s%s (%s%s%s)",
600 ref_klass->external_name(), 604 ref_klass->external_name(),
605 sel_method->is_abstract() ? "abstract " : "",
606 sel_method->is_protected() ? "protected " : "",
607 sel_method->is_private() ? "private " : "",
601 sel_klass->external_name(), 608 sel_klass->external_name(),
602 sel_method->name()->as_C_string(), 609 sel_method->name()->as_C_string(),
603 sel_method->signature()->as_C_string(), 610 sel_method->signature()->as_C_string(),
604 (same_module) ? ref_klass->joint_in_module_of_loader(sel_klass) : ref_klass->class_in_module_of_loader(), 611 (same_module) ? ref_klass->joint_in_module_of_loader(sel_klass) : ref_klass->class_in_module_of_loader(),
605 (same_module) ? "" : "; ", 612 (same_module) ? "" : "; ",
925 fd.access_flags(), 932 fd.access_flags(),
926 true, false, CHECK); 933 true, false, CHECK);
927 // Any existing exceptions that may have been thrown, for example LinkageErrors 934 // Any existing exceptions that may have been thrown, for example LinkageErrors
928 // from nest-host resolution, have been allowed to propagate. 935 // from nest-host resolution, have been allowed to propagate.
929 if (!can_access) { 936 if (!can_access) {
937 bool same_module = (sel_klass->module() == ref_klass->module());
930 ResourceMark rm(THREAD); 938 ResourceMark rm(THREAD);
931 Exceptions::fthrow( 939 Exceptions::fthrow(
932 THREAD_AND_LOCATION, 940 THREAD_AND_LOCATION,
933 vmSymbols::java_lang_IllegalAccessError(), 941 vmSymbols::java_lang_IllegalAccessError(),
934 "tried to access field %s.%s from class %s", 942 "class %s tried to access %s%sfield %s.%s (%s%s%s)",
943 ref_klass->external_name(),
944 fd.is_protected() ? "protected " : "",
945 fd.is_private() ? "private " : "",
935 sel_klass->external_name(), 946 sel_klass->external_name(),
936 fd.name()->as_C_string(), 947 fd.name()->as_C_string(),
937 ref_klass->external_name() 948 (same_module) ? ref_klass->joint_in_module_of_loader(sel_klass) : ref_klass->class_in_module_of_loader(),
949 (same_module) ? "" : "; ",
950 (same_module) ? "" : sel_klass->class_in_module_of_loader()
938 ); 951 );
939 return; 952 return;
940 } 953 }
941 } 954 }
942 955