Skip to content

Commit f3b06c0

Browse files
committed
Implement RootNode#prepareForCompilation to disable compilation of uncached nodes
1 parent a702589 commit f3b06c0

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,10 @@ final class BytecodeRootNodeElement extends CodeTypeElement {
383383
this.add(createTransitionToCached());
384384
this.add(createUpdateBytecode());
385385

386+
// Other root node overrides.
386387
this.add(createIsInstrumentable());
387388
this.addOptional(createPrepareForInstrumentation());
389+
this.addOptional(createPrepareForCompilation());
388390

389391
this.add(createEncodeTags());
390392
if (model.enableTagInstrumentation) {
@@ -1650,6 +1652,18 @@ private CodeExecutableElement createPrepareForInstrumentation() {
16501652
return ex;
16511653
}
16521654

1655+
private CodeExecutableElement createPrepareForCompilation() {
1656+
if (!model.enableUncachedInterpreter) {
1657+
return null;
1658+
}
1659+
1660+
CodeExecutableElement ex = overrideImplementRootNodeMethod(model, "prepareForCompilation", new String[]{"rootCompilation", "compilationTier", "lastTier"});
1661+
CodeTreeBuilder b = ex.createBuilder();
1662+
// Disable compilation for the uncached interpreter.
1663+
b.startReturn().string("bytecode.getTier() != ").staticReference(types.BytecodeTier, "UNCACHED").end();
1664+
return ex;
1665+
}
1666+
16531667
private CodeExecutableElement createEncodeTags() {
16541668
CodeExecutableElement ex = new CodeExecutableElement(Set.of(PRIVATE, STATIC), type(int.class), "encodeTags");
16551669
ex.addParameter(new CodeVariableElement(arrayOf(type(Class.class)), "tags"));
@@ -13104,8 +13118,6 @@ private List<CodeExecutableElement> createContinueAt() {
1310413118
b.statement("$root.transitionToCached()");
1310513119
b.startReturn().string("startState").end();
1310613120
return methods;
13107-
} else if (tier.isUncached()) {
13108-
b.tree(GeneratorUtils.createTransferToInterpreterAndInvalidate());
1310913121
}
1311013122

1311113123
b.startDeclaration(types.VirtualFrame, "frame").startCall("ACCESS.uncheckedCast").string("frame_").string("FRAME_TYPE").end().end();
@@ -16273,6 +16285,7 @@ void lazyInit() {
1627316285
// RootNode overrides.
1627416286
this.add(createIsCloningAllowed());
1627516287
this.add(createIsCloneUninitializedSupported());
16288+
this.addOptional(createPrepareForCompilation());
1627616289
// Should appear last. Uses current method set to determine which methods need to be
1627716290
// implemented.
1627816291
this.addAll(createRootNodeProxyMethods());
@@ -16432,6 +16445,17 @@ private CodeExecutableElement createIsCloneUninitializedSupported() {
1643216445
return ex;
1643316446
}
1643416447

16448+
private CodeExecutableElement createPrepareForCompilation() {
16449+
if (!model.enableUncachedInterpreter) {
16450+
return null;
16451+
}
16452+
16453+
CodeExecutableElement ex = overrideImplementRootNodeMethod(model, "prepareForCompilation", new String[]{"rootCompilation", "compilationTier", "lastTier"});
16454+
CodeTreeBuilder b = ex.createBuilder();
16455+
b.startReturn().startCall("root.prepareForCompilation").string("rootCompilation").string("compilationTier").string("lastTier").end(2);
16456+
return ex;
16457+
}
16458+
1643516459
private List<CodeExecutableElement> createRootNodeProxyMethods() {
1643616460
List<CodeExecutableElement> result = new ArrayList<>();
1643716461

0 commit comments

Comments
 (0)