Skip to content

Commit 095232a

Browse files
committed
[GR-80723] Fix publishOldBytecodes emission.
PullRequest: graal/25835
2 parents a6322fd + 39f474d commit 095232a

3 files changed

Lines changed: 99 additions & 13 deletions

File tree

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
package com.oracle.truffle.api.bytecode.test;
42+
43+
import com.oracle.truffle.api.bytecode.BytecodeRootNode;
44+
import com.oracle.truffle.api.bytecode.GenerateBytecode;
45+
import com.oracle.truffle.api.bytecode.Operation;
46+
import com.oracle.truffle.api.dsl.Specialization;
47+
import com.oracle.truffle.api.frame.FrameDescriptor;
48+
import com.oracle.truffle.api.nodes.RootNode;
49+
50+
/**
51+
* Compile-time regression for a bytecode root that is not updatable.
52+
* <p>
53+
* Instruction tracing counts as an instrumentation, so a root with tracing left at its default
54+
* stays updatable even when it declares no {@code @Instrumentation} and no tags. Disabling tracing
55+
* removes that instrumentation. With no other instrumentations or tags, {@code publishOldBytecodes()}
56+
* is not generated, and {@code updateBytecode} must not call it. This root fails to compile if the
57+
* generated interpreter still emits that call.
58+
*
59+
* @see <a href="https://github.com/oracle/graal/issues/14682">oracle/graal#14682</a>
60+
*/
61+
public class NotUpdatableBytecodeTest {
62+
63+
@GenerateBytecode(languageClass = BytecodeDSLTestLanguage.class, enableInstructionTracing = false)
64+
public abstract static class TracingDisabledRootNode extends RootNode implements BytecodeRootNode {
65+
66+
protected TracingDisabledRootNode(BytecodeDSLTestLanguage language, FrameDescriptor frameDescriptor) {
67+
super(language, frameDescriptor);
68+
}
69+
70+
@Operation
71+
public static final class Add {
72+
@Specialization
73+
public static int doInts(int a, int b) {
74+
return a + b;
75+
}
76+
}
77+
}
78+
79+
}

‎truffle/src/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/bytecode/generator/AbstractBytecodeNodeElement.java‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,21 +1343,21 @@ private CodeExecutableElement createTransition() {
13431343

13441344
String transitionBciExpr;
13451345
if (parent.model.isBytecodeUpdatable()) {
1346-
transitionBciExpr = "newBci";
1346+
transitionBciExpr = parent.castBytecodeIndexToInt("newBci");
13471347
} else {
13481348
transitionBciExpr = BytecodeRootNodeElement.decodeBci("state");
13491349
}
13501350
if (parent.model.needsCachedTagsTransition()) {
13511351
b.newLine();
13521352
// When transitioning from uncached to cached we need to update local tags.
13531353
if (!parent.model.isBytecodeUpdatable()) {
1354-
b.declaration(parent.getBytecodeIndexType(), "currentBci", BytecodeRootNodeElement.decodeBci("state"));
1354+
b.declaration(type(int.class), "currentBci", BytecodeRootNodeElement.decodeBci("state"));
13551355
transitionBciExpr = "currentBci";
13561356
}
13571357
b.startIf().string(transitionBciExpr).string(" > 0 && this.getTier().ordinal() < bc.getTier().ordinal()").end().startBlock();
13581358
b.lineComment("Populate cached tags for any locals already stored in the frame.");
13591359

1360-
b.startDeclaration(type(int.class), "localCount").startCall("bc.getLocalCount").string(parent.castBytecodeIndexToInt(transitionBciExpr)).end(2);
1360+
b.startDeclaration(type(int.class), "localCount").startCall("bc.getLocalCount").string(transitionBciExpr).end(2);
13611361
b.startFor().string("int localOffset = 0; localOffset < localCount; localOffset++").end().startBlock();
13621362
b.startIf().startCall("FRAMES.getTag").string("frame").string(BytecodeRootNodeElement.USER_LOCALS_START_INDEX + " + localOffset").end().string(" == ").staticReference(
13631363
parent.frameTagsElement.getIllegal()).end().startBlock();
@@ -1366,10 +1366,10 @@ private CodeExecutableElement createTransition() {
13661366
b.end();
13671367

13681368
b.startStatement().startCall("bc.setLocalValue");
1369-
b.string(parent.castBytecodeIndexToInt(transitionBciExpr));
1369+
b.string(transitionBciExpr);
13701370
b.string("frame");
13711371
b.string("localOffset");
1372-
b.startCall("bc.getLocalValue").string(parent.castBytecodeIndexToInt(transitionBciExpr)).string("frame").string("localOffset").end();
1372+
b.startCall("bc.getLocalValue").string(transitionBciExpr).string("frame").string("localOffset").end();
13731373
b.end(2);
13741374
b.end();
13751375
b.end();
@@ -1384,7 +1384,7 @@ private CodeExecutableElement createTransition() {
13841384
b.string("this");
13851385
b.string(BytecodeRootNodeElement.decodeBci("state"));
13861386
b.string("bc");
1387-
b.string(parent.castBytecodeIndexToInt(transitionBciExpr));
1387+
b.string(transitionBciExpr);
13881388
b.string("wasCompiled");
13891389
b.end(2); // createTransition + declaration
13901390

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,13 +1532,20 @@ private CodeExecutableElement createUpdateBytecode() {
15321532
b.end().end(); // call, call
15331533
b.end(); // statement
15341534

1535-
b.startIf().string("bytecodes_ != null").end().startBlock();
1536-
b.lineComment("Ensure old bytecodes are published before the new bytecode node.");
1537-
b.statement("oldBytecode.publishOldBytecodes()");
1538-
b.end().startElseBlock();
1539-
b.lineComment("When bytecode doesn't change, nodes are reused and should be re-adopted.");
1540-
b.statement("newBytecode.adoptNodesAfterUpdate()");
1541-
b.end();
1535+
if (model.isBytecodeUpdatable()) {
1536+
b.startIf().string("bytecodes_ != null").end().startBlock();
1537+
b.lineComment("Ensure old bytecodes are published before the new bytecode node.");
1538+
b.statement("oldBytecode.publishOldBytecodes()");
1539+
b.end().startElseBlock();
1540+
b.lineComment("When bytecode doesn't change, nodes are reused and should be re-adopted.");
1541+
b.statement("newBytecode.adoptNodesAfterUpdate()");
1542+
b.end();
1543+
} else {
1544+
b.startIf().string("bytecodes_ == null").end().startBlock();
1545+
b.lineComment("When bytecode doesn't change, nodes are reused and should be re-adopted.");
1546+
b.statement("newBytecode.adoptNodesAfterUpdate()");
1547+
b.end();
1548+
}
15421549
emitFence(b);
15431550
b.end().startDoWhile().startCall("!BYTECODE_UPDATER", "compareAndSet").string("this").string("oldBytecode").string("newBytecode").end().end();
15441551
b.newLine();

0 commit comments

Comments
 (0)