From c2dc3286222bc260ed0d0d20554195b6f240f509 Mon Sep 17 00:00:00 2001 From: d-kozak Date: Thu, 10 Oct 2024 12:28:29 +0200 Subject: [PATCH] extend the registrations done by TruffleFeature.beforeAnalysis --- .../oracle/svm/truffle/TruffleFeature.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleFeature.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleFeature.java index 93d380abcc11..d2cfe53574da 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleFeature.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleFeature.java @@ -100,7 +100,6 @@ import java.util.function.ToLongFunction; import java.util.function.UnaryOperator; -import jdk.graal.compiler.phases.common.InsertGuardFencesPhase; import org.graalvm.collections.Pair; import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.nativeimage.ImageSingletons; @@ -141,6 +140,7 @@ import com.oracle.svm.truffle.api.SubstrateTruffleRuntime; import com.oracle.svm.truffle.api.SubstrateTruffleUniverseFactory; import com.oracle.svm.util.LogUtils; +import com.oracle.svm.util.ReflectionUtil; import com.oracle.svm.util.StringUtil; import com.oracle.truffle.api.CompilerAsserts; import com.oracle.truffle.api.CompilerDirectives; @@ -150,6 +150,8 @@ import com.oracle.truffle.api.frame.Frame; import com.oracle.truffle.api.nodes.BytecodeOSRNode; import com.oracle.truffle.api.nodes.ExplodeLoop; +import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.runtime.OptimizedCallTarget; import com.oracle.truffle.runtime.TruffleCallBoundary; import jdk.graal.compiler.core.phases.HighTier; @@ -164,6 +166,7 @@ import jdk.graal.compiler.options.Option; import jdk.graal.compiler.options.OptionValues; import jdk.graal.compiler.phases.common.CanonicalizerPhase; +import jdk.graal.compiler.phases.common.InsertGuardFencesPhase; import jdk.graal.compiler.phases.tiers.Suites; import jdk.graal.compiler.phases.util.Providers; import jdk.graal.compiler.truffle.KnownTruffleTypes; @@ -409,12 +412,16 @@ public void beforeAnalysis(BeforeAnalysisAccess access) { } /* - * The concrete subclass of OptimizedCallTarget needs to be registered as in heap for the - * forced compilation of frame methods to work. Forcing compilation of a method effectively - * adds it as a root and non-static root methods are only compiled if types implementing - * them or any of their subtypes are allocated. + * GR-57561: The constructor of the concrete subclass of OptimizedCallTarget needs to be + * seen by the analysis, otherwise the analysis will not see any writes to its fields + * (namely rootNode and engine), which will make a lot of Truffle code look unreachable. + * Since the createOptimizedCallTarget is a member method, we also need to ensure that an + * instance of TruffleSupport is always seen as instantiated, otherwise the method might not + * be considered reachable. */ - config.registerAsInHeap(TruffleSupport.singleton().getOptimizedCallTargetClass(), "Concrete subclass of OptimizedCallTarget registered by " + TruffleFeature.class); + config.registerAsInHeap(TruffleSupport.singleton().getClass(), "Concrete subclass of TruffleSupport needs to be seen as instantiated, registered by " + TruffleFeature.class); + config.registerAsRoot(ReflectionUtil.lookupMethod(TruffleSupport.singleton().getClass(), "createOptimizedCallTarget", OptimizedCallTarget.class, RootNode.class), true, + "The constructor of the concrete subclass of OptimizedCallTarget needs to be seen by the analysis, registered by " + TruffleFeature.class); /* * This effectively initializes the Truffle fallback engine which does all the system