8196601: IllegalAccessError: cannot access class jdk.jfr.internal.handlers.EventHandler
authorlfoltan
Tue, 06 Feb 2018 10:28:22 -0500
changeset 48836 423bcbb288ff
parent 48835 62004f705d27
child 48837 a262b919311a
8196601: IllegalAccessError: cannot access class jdk.jfr.internal.handlers.EventHandler Summary: Do not perform access check when returning a reflection field or method or performing internal signature processing. Reviewed-by: acorn, psandoz
src/hotspot/share/runtime/reflection.cpp
src/hotspot/share/runtime/signature.cpp
src/hotspot/share/runtime/signature.hpp
--- a/src/hotspot/share/runtime/reflection.cpp	Mon Feb 05 23:12:03 2018 +0100
+++ b/src/hotspot/share/runtime/reflection.cpp	Tue Feb 06 10:28:22 2018 -0500
@@ -765,26 +765,27 @@
 static oop get_mirror_from_signature(const methodHandle& method,
                                      SignatureStream* ss,
                                      TRAPS) {
-  Klass* accessing_klass = method->method_holder();
-  assert(accessing_klass != NULL, "method has no accessing_klass");
+
 
-  oop mirror_oop = ss->as_java_mirror(Handle(THREAD, accessing_klass->class_loader()),
-                                      Handle(THREAD, accessing_klass->protection_domain()),
-                                      SignatureStream::NCDFError,
-                                      CHECK_NULL);
-
-  // Special tracing logic for resolution of class names during reflection.
-  if (log_is_enabled(Debug, class, resolve)) {
-    Klass* result = java_lang_Class::as_Klass(mirror_oop);
-    if (result != NULL) {
-      trace_class_resolution(result);
+  if (T_OBJECT == ss->type() || T_ARRAY == ss->type()) {
+    Symbol* name = ss->as_symbol(CHECK_NULL);
+    oop loader = method->method_holder()->class_loader();
+    oop protection_domain = method->method_holder()->protection_domain();
+    const Klass* k = SystemDictionary::resolve_or_fail(name,
+                                                       Handle(THREAD, loader),
+                                                       Handle(THREAD, protection_domain),
+                                                       true,
+                                                       CHECK_NULL);
+    if (log_is_enabled(Debug, class, resolve)) {
+      trace_class_resolution(k);
     }
+    return k->java_mirror();
   }
 
   assert(ss->type() != T_VOID || ss->at_return_type(),
     "T_VOID should only appear as return type");
 
-  return mirror_oop;
+  return java_lang_Class::primitive_mirror(ss->type());
 }
 
 static objArrayHandle get_parameter_types(const methodHandle& method,
@@ -818,17 +819,24 @@
 }
 
 static Handle new_type(Symbol* signature, Klass* k, TRAPS) {
-  Handle mirror = SystemDictionary::find_java_mirror_for_type(signature, k, SignatureStream::NCDFError, CHECK_(Handle()));
-
-  // Special tracing logic for resolution of class names during reflection.
-  if (log_is_enabled(Debug, class, resolve)) {
-    Klass* result = java_lang_Class::as_Klass(mirror());
-    if (result != NULL) {
-      trace_class_resolution(result);
-    }
+  // Basic types
+  BasicType type = vmSymbols::signature_type(signature);
+  if (type != T_OBJECT) {
+    return Handle(THREAD, Universe::java_mirror(type));
   }
 
-  return mirror;
+  Klass* result =
+    SystemDictionary::resolve_or_fail(signature,
+                                      Handle(THREAD, k->class_loader()),
+                                      Handle(THREAD, k->protection_domain()),
+                                      true, CHECK_(Handle()));
+
+  if (log_is_enabled(Debug, class, resolve)) {
+    trace_class_resolution(result);
+  }
+
+  oop nt = result->java_mirror();
+  return Handle(THREAD, nt);
 }
 
 
--- a/src/hotspot/share/runtime/signature.cpp	Mon Feb 05 23:12:03 2018 +0100
+++ b/src/hotspot/share/runtime/signature.cpp	Tue Feb 06 10:28:22 2018 -0500
@@ -392,19 +392,11 @@
 
 oop SignatureStream::as_java_mirror(Handle class_loader, Handle protection_domain,
                                     FailureMode failure_mode, TRAPS) {
-  if (raw_length() == 1) {
-    // short-cut in a common case
-    return SystemDictionary::find_java_mirror_for_type((char) raw_byte_at(0));
-  }
-  TempNewSymbol signature = SymbolTable::new_symbol(_signature, _begin, _end, CHECK_NULL);
-  Klass* no_accessing_klass = NULL;
-  Handle mirror = SystemDictionary::find_java_mirror_for_type(signature,
-                                                              no_accessing_klass,
-                                                              class_loader,
-                                                              protection_domain,
-                                                              failure_mode,
-                                                              CHECK_NULL);
-  return mirror();
+  if (!is_object())
+    return Universe::java_mirror(type());
+  Klass* klass = as_klass(class_loader, protection_domain, failure_mode, CHECK_NULL);
+  if (klass == NULL)  return NULL;
+  return klass->java_mirror();
 }
 
 Symbol* SignatureStream::as_symbol_or_null() {
--- a/src/hotspot/share/runtime/signature.hpp	Mon Feb 05 23:12:03 2018 +0100
+++ b/src/hotspot/share/runtime/signature.hpp	Tue Feb 06 10:28:22 2018 -0500
@@ -409,11 +409,6 @@
   const jbyte* raw_bytes()  { return _signature->bytes() + _begin; }
   int          raw_length() { return _end - _begin; }
 
-  jbyte raw_byte_at(int index) {
-    assert(index >= 0 && index < raw_length(), "index overflow");
-    return _signature->byte_at(_begin + index);
-  }
-
   // return same as_symbol except allocation of new symbols is avoided.
   Symbol* as_symbol_or_null();