Skip to content

Commit

Permalink
Add comment for getting canonical name. Remove redundant deduplicatio…
Browse files Browse the repository at this point in the history
…n structure
  • Loading branch information
jiekang committed Aug 12, 2021
1 parent 7496416 commit e7476d8
Showing 1 changed file with 7 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import com.oracle.svm.core.util.VMError;
import jdk.vm.ci.meta.ResolvedJavaType;
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;
Expand Down Expand Up @@ -106,8 +104,6 @@
@AutomaticFeature
public class JfrFeature implements Feature {

private final ConcurrentHashMap<Class, Boolean> fieldRegistration = new ConcurrentHashMap<>();

@Override
public boolean isInConfiguration(IsInConfigurationAccess access) {
return JfrEnabled.get();
Expand Down Expand Up @@ -181,24 +177,19 @@ public void duringAnalysis(DuringAnalysisAccess access) {
if (eventClass != null && access.isReachable(eventClass)) {
Set<Class<?>> s = access.reachableSubtypes(eventClass);
for (Class<?> c : s) {
// Use canonical name for package private AbstractJDKEvent
if (c.getCanonicalName().equals("jdk.jfr.Event")
|| c.getCanonicalName().equals("jdk.internal.event.Event")
|| c.getCanonicalName().equals("jdk.jfr.events.AbstractJDKEvent")) {
continue;
}
fieldRegistration.computeIfAbsent(c, this::registerEventHandler);

try {
Field f = c.getDeclaredField("eventHandler");
RuntimeReflection.register(f);
} catch (Exception e) {
throw VMError.shouldNotReachHere("Unable to register eventHandler for: " + c.getCanonicalName(), e);
}
}
}
}

private boolean registerEventHandler(Class c) {
try {
Field f = c.getDeclaredField("eventHandler");
RuntimeReflection.register(f);
} catch (Exception e) {
throw VMError.shouldNotReachHere("Unable to register eventHandler for: " + c.getCanonicalName(), e);
}
return Boolean.TRUE;
}
}

0 comments on commit e7476d8

Please sign in to comment.