Skip to content

Commit bfb23ef

Browse files
committed
Fix: check location tier of ContinuationRootNodeImpl in prepareForCompilation
1 parent 03373de commit bfb23ef

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

truffle/src/com.oracle.truffle.api.bytecode.test/src/com/oracle/truffle/api/bytecode/test/RootNodeOverridesTest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,17 @@ public void testPrepareForCompilationContinuation() {
126126
cont = (ContinuationResult) root.getCallTarget().call();
127127
assertEquals(BytecodeTier.CACHED, root.getBytecodeNode().getTier());
128128

129-
// When the interpreter is cached, the parent impl should be delegated to.
129+
// The continuation root does not transition to cached until its next execution.
130+
// Until then, it should not be ready for compilation.
131+
assertEquals(BytecodeTier.UNCACHED, cont.getBytecodeLocation().getBytecodeNode().getTier());
132+
root.readyForCompilation = false;
133+
assertEquals(false, invokePrepareForCompilation(cont.getContinuationRootNode()));
134+
root.readyForCompilation = true;
135+
assertEquals(false, invokePrepareForCompilation(cont.getContinuationRootNode()));
136+
137+
// After the continuation root transitions to cached, delegate to the root node.
138+
cont.continueWith(123L);
139+
assertEquals(BytecodeTier.CACHED, cont.getBytecodeLocation().getBytecodeNode().getTier());
130140
root.readyForCompilation = false;
131141
assertEquals(false, invokePrepareForCompilation(cont.getContinuationRootNode()));
132142
root.readyForCompilation = true;

truffle/src/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/bytecode/generator/BytecodeRootNodeElement.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17937,7 +17937,12 @@ private CodeExecutableElement createPrepareForCompilation() {
1793717937

1793817938
CodeExecutableElement ex = overrideImplementRootNodeMethod(model, "prepareForCompilation", new String[]{"rootCompilation", "compilationTier", "lastTier"});
1793917939
CodeTreeBuilder b = ex.createBuilder();
17940-
b.startReturn().startCall("root.prepareForCompilation").string("rootCompilation").string("compilationTier").string("lastTier").end(2);
17940+
b.startReturn();
17941+
b.startCall("root.prepareForCompilation").string("rootCompilation").string("compilationTier").string("lastTier").end();
17942+
b.string(" && ");
17943+
// Even if the root is ready, the continuation location may not have updated yet.
17944+
b.string("location.getBytecodeNode().getTier() != ").staticReference(types.BytecodeTier, "UNCACHED");
17945+
b.end();
1794117946
return ex;
1794217947
}
1794317948

0 commit comments

Comments
 (0)