Skip to content

Commit 4442044

Browse files
DSouzaMchumerprofMagija
committed
Add Bytecode DSL
Co-authored-by: Christian Humer <[email protected]> Co-authored-by: Nikola Bebić <[email protected]>
1 parent 2b69a66 commit 4442044

File tree

240 files changed

+74709
-656
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

240 files changed

+74709
-656
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/host/HostInliningPhase.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ private List<CallTree> exploreGraph(InliningPhaseContext context, CallTree calle
512512
*/
513513
boolean forceShallowInline = context.isBytecodeSwitch && (caller.forceShallowInline || caller.parent == null) && isBytecodeInterpreterSwitch(context.env, invoke.getTargetMethod());
514514

515-
double frequency = context.isFrequencyCutoffEnabled() ? block.getRelativeFrequency() : 1.0d;
515+
double frequency = (!forceShallowInline && context.isFrequencyCutoffEnabled()) ? block.getRelativeFrequency() : 1.0d;
516516
CallTree callee = new CallTree(caller, invoke, deoptimized, unwind, inInterpreter, forceShallowInline, frequency);
517517
children.add(callee);
518518

@@ -953,10 +953,6 @@ private boolean shouldInline(InliningPhaseContext context, CallTree call) {
953953
/*
954954
* Always force inline bytecode switches into bytecode switches.
955955
*/
956-
if (call.frequency <= context.minimumFrequency) {
957-
call.reason = "frequency < minimumFrequency";
958-
return false;
959-
}
960956
return true;
961957
}
962958

tools/src/com.oracle.truffle.tools.chromeinspector.test/src/com/oracle/truffle/tools/chromeinspector/test/InspectorMessageTransportTest.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@
3535

3636
import org.junit.Assert;
3737
import org.junit.Test;
38-
38+
import org.junit.runner.RunWith;
39+
import org.junit.runners.Parameterized;
40+
import org.junit.runners.Parameterized.Parameter;
41+
import org.junit.runners.Parameterized.Parameters;
3942
import org.graalvm.polyglot.Context;
4043
import org.graalvm.polyglot.Engine;
4144
import org.graalvm.polyglot.PolyglotException;
@@ -46,8 +49,16 @@
4649
/**
4750
* Tests the use of {@link MessageTransport} with the Inspector.
4851
*/
52+
@RunWith(Parameterized.class)
4953
public class InspectorMessageTransportTest extends EnginesGCedTest {
5054

55+
@Parameters(name = "useBytecode={0}")
56+
public static List<Boolean> getParameters() {
57+
return List.of(false, true);
58+
}
59+
60+
@Parameter(0) public Boolean useBytecode;
61+
5162
private static final String PORT = "54367";
5263
private static final Pattern URI_PATTERN = Pattern.compile("ws://.*:" + PORT + "/[\\dA-Za-z_\\-]+");
5364
private static final String[] INITIAL_MESSAGES = {
@@ -97,6 +108,10 @@ public void inspectorEndpointRaceTest() {
97108
inspectorEndpointTest(null, rc);
98109
}
99110

111+
private Context.Builder newContextBuilder() {
112+
return Context.newBuilder().allowExperimentalOptions(true).option("sl.UseBytecode", Boolean.toString(useBytecode));
113+
}
114+
100115
private void inspectorEndpointTest(String path) {
101116
inspectorEndpointTest(path, null);
102117
}
@@ -105,7 +120,7 @@ private void inspectorEndpointTest(String path, RaceControl rc) {
105120
Session session = new Session(rc);
106121
DebuggerEndpoint endpoint = new DebuggerEndpoint(path, rc);
107122
try (Engine engine = endpoint.onOpen(session)) {
108-
Context context = Context.newBuilder().engine(engine).build();
123+
Context context = newContextBuilder().engine(engine).build();
109124
Value result = context.eval("sl", "function main() {\n x = 1;\n return x;\n}");
110125
Assert.assertEquals("Result", "1", result.toString());
111126

@@ -140,7 +155,7 @@ public void inspectorReconnectTest() throws IOException, InterruptedException {
140155
DebuggerEndpoint endpoint = new DebuggerEndpoint("simplePath" + SecureInspectorPathGenerator.getToken(), null);
141156
try (Engine engine = endpoint.onOpen(session)) {
142157

143-
try (Context context = Context.newBuilder().engine(engine).build()) {
158+
try (Context context = newContextBuilder().engine(engine).build()) {
144159
Value result = context.eval("sl", "function main() {\n x = 1;\n return x;\n}");
145160
Assert.assertEquals("Result", "1", result.toString());
146161

@@ -174,7 +189,7 @@ public void inspectorClosedTest() throws IOException, InterruptedException {
174189
DebuggerEndpoint endpoint = new DebuggerEndpoint("simplePath" + SecureInspectorPathGenerator.getToken(), null);
175190
endpoint.setOpenCountLimit(1);
176191
try (Engine engine = endpoint.onOpen(session)) {
177-
try (Context context = Context.newBuilder().engine(engine).build()) {
192+
try (Context context = newContextBuilder().engine(engine).build()) {
178193
Value result = context.eval("sl", "function main() {\n x = 1;\n return x;\n}");
179194
Assert.assertEquals("Result", "1", result.toString());
180195

@@ -185,7 +200,7 @@ public void inspectorClosedTest() throws IOException, InterruptedException {
185200
Assert.assertEquals("Result", "2", result.toString());
186201
}
187202
try (Engine engine2 = endpoint.onOpen(session)) {
188-
try (Context context = Context.newBuilder().engine(engine2).build()) {
203+
try (Context context = newContextBuilder().engine(engine2).build()) {
189204
Value result = context.eval("sl", "function main() {\n x = 3;\n debugger; return x;\n}");
190205
Assert.assertEquals("Result", "3", result.toString());
191206
}
@@ -209,7 +224,7 @@ public void inspectorCloseAfterDisposeTest() {
209224
DebuggerEndpoint endpoint = new DebuggerEndpoint("simplePath" + SecureInspectorPathGenerator.getToken(), null);
210225
MessageEndpoint peerEndpoint;
211226
try (Engine engine = endpoint.onOpen(session)) {
212-
try (Context context = Context.newBuilder().engine(engine).build()) {
227+
try (Context context = newContextBuilder().engine(engine).build()) {
213228
context.eval("sl", "function main() {\n x = 1;\n return x;\n}");
214229
peerEndpoint = endpoint.peer;
215230
}
@@ -245,7 +260,7 @@ public void inspectorTimeoutTest() {
245260
Session session = new Session(true);
246261
DebuggerEndpoint endpoint = new DebuggerEndpoint("simplePath" + SecureInspectorPathGenerator.getToken(), null);
247262
try (Engine engine = endpoint.onOpen(session, Engine.newBuilder().option("inspect.SuspensionTimeout", "1s"))) {
248-
try (Context context = Context.newBuilder().engine(engine).build()) {
263+
try (Context context = newContextBuilder().engine(engine).build()) {
249264
context.eval("sl", "function main() {\n x = 1;\n return x;\n}");
250265
}
251266
}
@@ -427,7 +442,7 @@ public Engine onOpen(final Session session, Engine.Builder engineBuilder) {
427442

428443
public Context onOpenContext(final Session session) {
429444
assert this != null;
430-
Context.Builder contextBuilder = Context.newBuilder().serverTransport(new EndpointMessageTransport(session)).option("inspect", PORT);
445+
Context.Builder contextBuilder = newContextBuilder().serverTransport(new EndpointMessageTransport(session)).option("inspect", PORT);
431446
if (path != null) {
432447
contextBuilder.option("inspect.Path", path);
433448
}

tools/src/com.oracle.truffle.tools.chromeinspector.test/src/com/oracle/truffle/tools/chromeinspector/test/InspectorObjectTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.io.ByteArrayOutputStream;
2828
import java.io.IOException;
2929
import java.net.ServerSocket;
30+
import java.util.List;
3031

3132
import org.graalvm.polyglot.Context;
3233
import org.graalvm.polyglot.Instrument;
@@ -36,14 +37,26 @@
3637
import org.junit.Assert;
3738
import org.junit.Before;
3839
import org.junit.Test;
40+
import org.junit.runner.RunWith;
41+
import org.junit.runners.Parameterized;
42+
import org.junit.runners.Parameterized.Parameter;
43+
import org.junit.runners.Parameterized.Parameters;
3944

4045
import com.oracle.truffle.api.interop.TruffleObject;
4146

4247
/**
4348
* Test of the provided inspector TruffleObject.
4449
*/
50+
@RunWith(Parameterized.class)
4551
public class InspectorObjectTest {
4652

53+
@Parameters(name = "useBytecode={0}")
54+
public static List<Boolean> getParameters() {
55+
return List.of(false, true);
56+
}
57+
58+
@Parameter(0) public Boolean useBytecode;
59+
4760
private static final String NL = System.lineSeparator();
4861

4962
private ByteArrayOutputStream out;
@@ -54,7 +67,7 @@ public class InspectorObjectTest {
5467
@Before
5568
public void setUp() {
5669
out = new ByteArrayOutputStream();
57-
context = Context.newBuilder().out(out).err(out).build();
70+
context = Context.newBuilder().out(out).err(out).option("sl.UseBytecode", Boolean.toString(useBytecode)).build();
5871
Instrument inspect = context.getEngine().getInstruments().get("inspect");
5972
inspector = inspect.lookup(TruffleObject.class);
6073
try (ServerSocket testSocket = new ServerSocket(0)) {

tools/src/com.oracle.truffle.tools.chromeinspector.test/src/com/oracle/truffle/tools/chromeinspector/test/MultiEngineTest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
import org.graalvm.shadowed.org.json.JSONArray;
5454
import org.graalvm.shadowed.org.json.JSONObject;
5555
import org.junit.Test;
56+
import org.junit.runner.RunWith;
57+
import org.junit.runners.Parameterized;
58+
import org.junit.runners.Parameterized.Parameter;
59+
import org.junit.runners.Parameterized.Parameters;
5660

5761
import com.oracle.truffle.tools.utils.java_websocket.client.WebSocketClient;
5862
import com.oracle.truffle.tools.utils.java_websocket.handshake.ServerHandshake;
@@ -65,7 +69,14 @@
6569
/**
6670
* Test handling of multiple engines by the Inspector.
6771
*/
72+
@RunWith(Parameterized.class)
6873
public class MultiEngineTest extends EnginesGCedTest {
74+
@Parameters(name = "useBytecode={0}")
75+
public static List<Boolean> getParameters() {
76+
return List.of(false, true);
77+
}
78+
79+
@Parameter(0) public Boolean useBytecode;
6980

7081
private static final String[] INITIAL_MESSAGES = {
7182
"{\"id\":1,\"method\":\"Runtime.enable\"}",
@@ -281,7 +292,7 @@ private String runEngine(Source src, AtomicInteger port, OutputStream out, Count
281292
private String runEngine(Source src, AtomicInteger port, String path, OutputStream out, CountDownLatch isUp) {
282293
try (Engine e = Engine.newBuilder().option("inspect", Integer.toString(port.get())).option("inspect.Path", path).err(out).build()) {
283294
addEngineReference(e);
284-
Context c = Context.newBuilder().engine(e).allowAllAccess(true).build();
295+
Context c = Context.newBuilder().engine(e).option("sl.UseBytecode", Boolean.toString(useBytecode)).allowAllAccess(true).build();
285296
if (port.get() == 0) {
286297
port.set(InspectorAddressTest.parseWSPort(out.toString()));
287298
}

tools/src/com.oracle.truffle.tools.dap.test/src/com/oracle/truffle/tools/dap/test/DAPTester.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.util.Collections;
3434
import java.util.Iterator;
3535
import java.util.List;
36+
import java.util.Map;
3637
import java.util.Objects;
3738
import java.util.concurrent.CompletableFuture;
3839
import java.util.concurrent.ExecutionException;
@@ -78,9 +79,13 @@ public static DAPTester start(boolean suspend, Consumer<Context> prolog) throws
7879
}
7980

8081
public static DAPTester start(boolean suspend, Consumer<Context> prolog, List<URI> sourcePath) throws IOException {
82+
return start(suspend, prolog, sourcePath, Collections.emptyMap());
83+
}
84+
85+
public static DAPTester start(boolean suspend, Consumer<Context> prolog, List<URI> sourcePath, Map<String, String> options) throws IOException {
8186
final ProxyOutputStream err = new ProxyOutputStream(System.err);
8287
Engine engine = Engine.newBuilder().err(err).build();
83-
Context context = Context.newBuilder().engine(engine).allowAllAccess(true).build();
88+
Context context = Context.newBuilder().engine(engine).options(options).allowAllAccess(true).build();
8489
Runnable runProlog;
8590
if (prolog != null) {
8691
runProlog = () -> prolog.accept(context);

0 commit comments

Comments
 (0)