From d2627b2c4b64f1fb453629c36b1f087ab19250ad Mon Sep 17 00:00:00 2001 From: David Leopoldseder Date: Mon, 1 Sep 2025 14:13:42 +0200 Subject: [PATCH] do not inline hasNextTier in parsing, is required for correct host inlining (cherry picked from commit 3a3230502eeaa639588c830ed84f0cddd6a7e4a2) --- .../compiler/truffle/test/HostInliningTest.java | 17 +++++++++++++++++ .../compiler/host/HostInliningPhase.java | 1 + .../compiler/host/TruffleKnownHostTypes.java | 5 +++++ 3 files changed, 23 insertions(+) diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/HostInliningTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/HostInliningTest.java index 779c12eab85..62bf942599e 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/HostInliningTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/HostInliningTest.java @@ -148,6 +148,23 @@ public void test() { runTest("testThrow"); runTest("testRangeCheck"); runTest("testImplicitCast"); + runTest("testBCDSLPrologIfVersion"); + } + + /* + * Test for GR-69170 + */ + @SuppressWarnings("unused") + @BytecodeInterpreterSwitch + static Object testBCDSLPrologIfVersion(int value) { + Object o = null; + if (!CompilerDirectives.inInterpreter() && CompilerDirectives.hasNextTier()) { + GraalDirectives.deoptimize(); + o = new Object(); + } + // must be inlined + trivialMethod(); + return o; } @SuppressWarnings("try") diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/host/HostInliningPhase.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/host/HostInliningPhase.java index 7648a02bfab..36420e3937b 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/host/HostInliningPhase.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/host/HostInliningPhase.java @@ -1342,6 +1342,7 @@ public static boolean shouldDenyTrivialInlining(TruffleHostEnvironment env, Reso info.isTruffleBoundary() || types.isInInterpreter(callee) || types.isInInterpreterFastPath(callee) || + types.isHasNextTier(callee) || types.isTransferToInterpreterMethod(callee)); } diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/host/TruffleKnownHostTypes.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/host/TruffleKnownHostTypes.java index 3d0e364b03c..d708d6ce4cd 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/host/TruffleKnownHostTypes.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/host/TruffleKnownHostTypes.java @@ -51,6 +51,7 @@ public final class TruffleKnownHostTypes extends AbstractKnownTruffleTypes { public final ResolvedJavaMethod CompilerDirectives_transferToInterpreter = findMethod(CompilerDirectives, "transferToInterpreter"); public final ResolvedJavaMethod CompilerDirectives_transferToInterpreterAndInvalidate = findMethod(CompilerDirectives, "transferToInterpreterAndInvalidate"); public final ResolvedJavaMethod CompilerDirectives_inInterpreter = findMethod(CompilerDirectives, "inInterpreter"); + public final ResolvedJavaMethod CompilerDirectives_hasNextTier = findMethod(CompilerDirectives, "hasNextTier"); public final ResolvedJavaType HostCompilerDirectives = lookupTypeCached("com.oracle.truffle.api.HostCompilerDirectives"); public final ResolvedJavaMethod HostCompilerDirectives_inInterpreterFastPath = findMethod(HostCompilerDirectives, "inInterpreterFastPath"); @@ -75,6 +76,10 @@ public boolean isInInterpreterFastPath(ResolvedJavaMethod method) { return method.equals(HostCompilerDirectives_inInterpreterFastPath); } + public boolean isHasNextTier(ResolvedJavaMethod method) { + return method.equals(CompilerDirectives_hasNextTier); + } + /** * Determines if {@code method} is a method is a transferToInterpreter method from * CompilerDirectives.