From e7476d8f4d66aecc8ae15b4ce9f705d2146bbcd9 Mon Sep 17 00:00:00 2001 From: Jie Kang Date: Wed, 11 Aug 2021 21:11:25 -0400 Subject: [PATCH] Add comment for getting canonical name. Remove redundant deduplication structure --- .../src/com/oracle/svm/jfr/JfrFeature.java | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/substratevm/src/com.oracle.svm.jfr/src/com/oracle/svm/jfr/JfrFeature.java b/substratevm/src/com.oracle.svm.jfr/src/com/oracle/svm/jfr/JfrFeature.java index f103d0dc39f9..1a719a2b9db6 100644 --- a/substratevm/src/com.oracle.svm.jfr/src/com/oracle/svm/jfr/JfrFeature.java +++ b/substratevm/src/com.oracle.svm.jfr/src/com/oracle/svm/jfr/JfrFeature.java @@ -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; @@ -106,8 +104,6 @@ @AutomaticFeature public class JfrFeature implements Feature { - private final ConcurrentHashMap fieldRegistration = new ConcurrentHashMap<>(); - @Override public boolean isInConfiguration(IsInConfigurationAccess access) { return JfrEnabled.get(); @@ -181,24 +177,19 @@ public void duringAnalysis(DuringAnalysisAccess access) { if (eventClass != null && access.isReachable(eventClass)) { Set> 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; - } }