Skip to content
Permalink
Browse files
8247247: JFR tests fail due to JDK-8235521 missing doPrivileged block
Reviewed-by: egahlin
  • Loading branch information
Mandy Chung committed Jun 11, 2020
1 parent 65455ff commit 6dec50a7e88e6dee2e8d85c9cded522ee4bbcedd
Showing 2 changed files with 21 additions and 6 deletions.
@@ -109,7 +109,7 @@ public synchronized List<EventType> getRegisteredEventTypes() {
}

public synchronized EventType getEventType(Class<? extends jdk.internal.event.Event> eventClass) {
EventHandler h = getHandler(eventClass);
EventHandler h = getHandler(eventClass, false);
if (h != null && h.isRegistered()) {
return h.getEventType();
}
@@ -118,7 +118,7 @@ public synchronized EventType getEventType(Class<? extends jdk.internal.event.Ev

public synchronized void unregister(Class<? extends Event> eventClass) {
Utils.checkRegisterPermission();
EventHandler handler = getHandler(eventClass);
EventHandler handler = getHandler(eventClass, false);
if (handler != null) {
handler.setRegistered(false);
}
@@ -130,7 +130,7 @@ public synchronized EventType register(Class<? extends jdk.internal.event.Event>

public synchronized EventType register(Class<? extends jdk.internal.event.Event> eventClass, List<AnnotationElement> dynamicAnnotations, List<ValueDescriptor> dynamicFields) {
Utils.checkRegisterPermission();
EventHandler handler = getHandler(eventClass);
EventHandler handler = getHandler(eventClass, true);
if (handler == null) {
if (eventClass.getAnnotation(MirrorEvent.class) != null) {
// don't register mirrors
@@ -165,10 +165,12 @@ private PlatformEventType findMirrorType(Class<? extends jdk.internal.event.Even
return et;
}

private EventHandler getHandler(Class<? extends jdk.internal.event.Event> eventClass) {
private EventHandler getHandler(Class<? extends jdk.internal.event.Event> eventClass, boolean ensureInitialized) {
Utils.ensureValidEventSubclass(eventClass);
SecuritySupport.makeVisibleToJFR(eventClass);
Utils.ensureInitialized(eventClass);
if (ensureInitialized) {
Utils.ensureInitialized(eventClass);
}
return Utils.getHandler(eventClass);
}

@@ -432,9 +432,22 @@ static void setAccessible(Constructor<?> constructor) {

static void ensureClassIsInitialized(Class<?> clazz) {
try {
MethodHandles.privateLookupIn(clazz, LOOKUP).ensureInitialized(clazz);
MethodHandles.Lookup lookup;
if (System.getSecurityManager() == null) {
lookup = MethodHandles.privateLookupIn(clazz, LOOKUP);
} else {
lookup = AccessController.doPrivileged(new PrivilegedExceptionAction<>() {
@Override
public MethodHandles.Lookup run() throws IllegalAccessException {
return MethodHandles.privateLookupIn(clazz, LOOKUP);
}
}, null, new ReflectPermission("suppressAccessChecks"));
}
lookup.ensureInitialized(clazz);
} catch (IllegalAccessException e) {
throw new InternalError(e);
} catch (PrivilegedActionException e) {
throw new InternalError(e.getCause());
}
}

0 comments on commit 6dec50a

Please sign in to comment.