Skip to content

Commit 98460ee

Browse files
committed
Bytecode DSL: Implement ability to configure whether the bytecode index is stored. Emit warning if it is recommended to configure it.
1 parent 5c704c9 commit 98460ee

File tree

25 files changed

+1160
-90
lines changed

25 files changed

+1160
-90
lines changed

truffle/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ This changelog summarizes major changes between Truffle versions relevant to lan
1515
* GR-69188: Added `@HostCompilerDirectives.InliningRoot` to explicitly trigger host inlining for a method designed for partial evaluation. Note that on SubstrateVM, host inlining is automatically enabled for all runtime-compilable methods, while on HotSpot you must add either `@HostCompilerDirectives.InliningRoot` or `@HostCompilerDirectives.BytecodeInterpreterSwitch` to enable it. Host inlining is only enabled if Graal is enabled as a Java host compiler.
1616
* GR-67146: Specialization DSL: Added `@Bind` support for frames (including materialized frames).
1717
* GR-67146: Bytecode DSL: Added support for user-defined yield operations using `@Yield`. These operations behave like the built-in yield but allow you to customize the yield result or perform custom logic on yield.
18+
* GR-69495: Bytecode DSL: Added a new `storeBytecodeIndex` attribute to all operation annotations to configure whether the bytecode index needs to be stored. When `@GenerateBytecode(storeBytecodeIndexInFrame = true)` is set and the attribute is left at its default, the DSL will emit a warning recommending explicit configuration. Additionally, introduced the `@StoreBytecodeIndex` annotation, which lets you specify bytecode index updates for individual specializations or fallbacks.
19+
1820

1921
## Version 25.0
2022
* GR-31495 Added ability to specify language and instrument specific options using `Source.Builder.option(String, String)`. Languages may describe available source options by implementing `TruffleLanguage.getSourceOptionDescriptors()` and `TruffleInstrument.getSourceOptionDescriptors()` respectively.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) 2025, 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.OperationProxy;
44+
import com.oracle.truffle.api.dsl.Bind;
45+
import com.oracle.truffle.api.dsl.GenerateInline;
46+
import com.oracle.truffle.api.dsl.GenerateUncached;
47+
import com.oracle.truffle.api.dsl.Specialization;
48+
import com.oracle.truffle.api.frame.VirtualFrame;
49+
import com.oracle.truffle.api.nodes.Node;
50+
51+
@GenerateUncached
52+
@GenerateInline(false)
53+
@OperationProxy.Proxyable(allowUncached = true)
54+
public abstract class ExternalProxyNode extends Node {
55+
public abstract boolean execute(VirtualFrame frame, Object object);
56+
57+
@SuppressWarnings("unused")
58+
@Specialization
59+
public static boolean doBoolean(boolean object, @Bind Node node) {
60+
return object;
61+
}
62+
63+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@ protected InheritanceError1Node(BytecodeDSLTestLanguage language, FrameDescripto
147147
super(language, frameDescriptor);
148148
}
149149

150-
@ExpectError("All super types of operation classes must be declared as static nested classes of the operation root node. " +
151-
"Modify the super class 'BaseBaseClass' to be an inner class of type 'InheritanceError1Node' to resolve this or use @OperationProxy instead.")
152150
static class BaseClass extends BaseBaseClass {
153151
@Specialization(guards = "guard1(v)")
154152
public static Object s0(int v) {
@@ -160,6 +158,8 @@ static boolean guard1(int v) {
160158
}
161159
}
162160

161+
@ExpectError("All super types of operation classes must be declared as static nested classes of the operation root node. " +
162+
"Modify the super class 'BaseBaseClass' to be an inner class of type 'InheritanceError1Node' to resolve this or use @OperationProxy instead.")
163163
@Operation
164164
public static final class SubClass extends BaseClass {
165165
@Specialization(guards = "v >= 3")

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,29 +284,29 @@ public String getSourceCharacters() {
284284
}
285285
}
286286

287-
@Prolog
287+
@Prolog(storeBytecodeIndex = false)
288288
public static final class DoNothingProlog {
289289
@Specialization
290290
public static void doNothing() {
291291
}
292292
}
293293

294-
@EpilogReturn
294+
@EpilogReturn(storeBytecodeIndex = false)
295295
public static final class DoNothingEpilog {
296296
@Specialization
297297
public static Object doNothing(Object returnValue) {
298298
return returnValue;
299299
}
300300
}
301301

302-
@EpilogExceptional
302+
@EpilogExceptional(storeBytecodeIndex = false)
303303
public static final class DoNothingEpilogExceptional {
304304
@Specialization
305305
public static void doNothing(@SuppressWarnings("unused") AbstractTruffleException ex) {
306306
}
307307
}
308308

309-
@Operation
309+
@Operation(storeBytecodeIndex = true)
310310
public static final class MakeRootAndFrame {
311311
@Specialization
312312
public static BytecodeAndFrame perform(VirtualFrame frame,
@@ -316,15 +316,15 @@ public static BytecodeAndFrame perform(VirtualFrame frame,
316316
}
317317
}
318318

319-
@Operation
319+
@Operation(storeBytecodeIndex = false)
320320
public static final class GetSourceCharacters {
321321
@Specialization
322322
public static String perform(@SuppressWarnings("unused") VirtualFrame frame, BytecodeAndFrame rootAndFrame) {
323323
return rootAndFrame.getSourceCharacters();
324324
}
325325
}
326326

327-
@Operation
327+
@Operation(storeBytecodeIndex = false)
328328
public static final class Throw {
329329
@Specialization
330330
public static Object perform(Object result) {

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ static void doDefault() {
386386
}
387387
}
388388

389-
@Operation
389+
@Operation(storeBytecodeIndex = true)
390390
@ConstantOperand(type = CallTarget.class)
391391
static final class Call {
392392
@Specialization
@@ -395,7 +395,8 @@ static Object doDefault(CallTarget target, @Bind Node node) {
395395
}
396396
}
397397

398-
@Operation
398+
@SuppressWarnings("truffle-interpreted-performance")
399+
@Operation(storeBytecodeIndex = true)
399400
@ConstantOperand(type = CallTarget.class)
400401
static final class CallNoLocation {
401402
@Specialization
@@ -404,7 +405,7 @@ static Object doDefault(CallTarget target) {
404405
}
405406
}
406407

407-
@Operation
408+
@Operation(storeBytecodeIndex = true)
408409
static final class ThrowErrorBehindInterop {
409410

410411
@Specialization(limit = "1")
@@ -417,7 +418,7 @@ static Object doDefault(Object executable, @CachedLibrary("executable") InteropL
417418
}
418419
}
419420

420-
@Operation
421+
@Operation(storeBytecodeIndex = true)
421422
static final class ThrowError {
422423

423424
@Specialization
@@ -426,7 +427,7 @@ static Object doDefault(@Bind Node node) {
426427
}
427428
}
428429

429-
@Operation
430+
@Operation(storeBytecodeIndex = false)
430431
static final class ThrowErrorNoLocation {
431432

432433
@Specialization
@@ -435,7 +436,7 @@ static Object doDefault() {
435436
}
436437
}
437438

438-
@Operation
439+
@Operation(storeBytecodeIndex = true)
439440
static final class CaptureStack {
440441

441442
@Specialization

0 commit comments

Comments
 (0)