Skip to content

Commit 8035502

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

File tree

93 files changed

+5781
-2545
lines changed

Some content is hidden

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

93 files changed

+5781
-2545
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Copyright (c) 2024, 2024, 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.sl.test;
42+
43+
import java.util.List;
44+
45+
import org.graalvm.polyglot.Context;
46+
import org.graalvm.polyglot.Engine;
47+
import org.junit.runner.RunWith;
48+
import org.junit.runners.Parameterized;
49+
import org.junit.runners.Parameterized.Parameter;
50+
import org.junit.runners.Parameterized.Parameters;
51+
52+
@RunWith(Parameterized.class)
53+
public abstract class AbstractSLTest {
54+
55+
public enum RunMode {
56+
AST,
57+
BYTECODE_UNCACHED,
58+
BYTECODE_DEFAULT,
59+
BYTECODE_CACHED;
60+
61+
public boolean isBytecode() {
62+
switch (this) {
63+
case BYTECODE_CACHED:
64+
case BYTECODE_UNCACHED:
65+
case BYTECODE_DEFAULT:
66+
return true;
67+
default:
68+
return false;
69+
}
70+
}
71+
}
72+
73+
@Parameters(name = "{0}")
74+
public static List<RunMode> getModes() {
75+
return List.of(RunMode.values());
76+
}
77+
78+
@Parameter(0) public RunMode mode;
79+
80+
protected Engine.Builder newEngineBuilder(String... languages) {
81+
var b = Engine.newBuilder(languages);
82+
b.allowExperimentalOptions(true);
83+
b.option("sl.UseBytecode", Boolean.toString(mode.isBytecode()));
84+
if (mode.isBytecode()) {
85+
if (mode == RunMode.BYTECODE_CACHED) {
86+
b.option("sl.ForceBytecodeTier", "CACHED");
87+
} else if (mode == RunMode.BYTECODE_UNCACHED) {
88+
b.option("sl.ForceBytecodeTier", "UNCACHED");
89+
if (TruffleTestAssumptions.isOptimizingRuntime()) {
90+
// The uncached interpreter compiles to a deopt. Disable compilation because
91+
// compilation tests can time out due to lack of progress.
92+
b.option("engine.Compilation", "false");
93+
}
94+
} else {
95+
assert mode == RunMode.BYTECODE_DEFAULT;
96+
b.option("sl.ForceBytecodeTier", "");
97+
}
98+
}
99+
return b;
100+
}
101+
102+
protected Context.Builder newContextBuilder(String... languages) {
103+
var b = Context.newBuilder(languages);
104+
b.allowExperimentalOptions(true);
105+
b.option("sl.UseBytecode", Boolean.toString(mode.isBytecode()));
106+
return b;
107+
}
108+
109+
}

truffle/src/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLCodeSharingTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -48,7 +48,7 @@
4848
import org.graalvm.polyglot.Source;
4949
import org.junit.Test;
5050

51-
public class SLCodeSharingTest {
51+
public class SLCodeSharingTest extends AbstractSLTest {
5252

5353
private static Source createFib() {
5454
return Source.newBuilder("sl", "" +
@@ -64,14 +64,14 @@ private static Source createFib() {
6464
@Test
6565
public void testFibSharing() throws Exception {
6666
Source fib = createFib();
67-
try (Engine engine = Engine.create()) {
68-
try (Context context = Context.newBuilder().engine(engine).build()) {
67+
try (Engine engine = newEngineBuilder().build()) {
68+
try (Context context = newContextBuilder().engine(engine).build()) {
6969
assertEquals(0, engine.getCachedSources().size());
7070
context.eval(fib);
7171
assertEquals(1, engine.getCachedSources().size());
7272
assertTrue(engine.getCachedSources().contains(fib));
7373
}
74-
try (Context context = Context.newBuilder().engine(engine).build()) {
74+
try (Context context = newContextBuilder().engine(engine).build()) {
7575
assertEquals(1, engine.getCachedSources().size());
7676
assertTrue(engine.getCachedSources().contains(fib));
7777
context.eval(fib);

truffle/src/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLDebugALot.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -51,7 +51,7 @@
5151
/**
5252
* Basic test of debug-a-lot instrument applied to simple language.
5353
*/
54-
public class SLDebugALot {
54+
public class SLDebugALot extends AbstractSLTest {
5555

5656
private final Source slCode = Source.create("sl", "function main() {\n" +
5757
" n = 2;\n" +
@@ -92,8 +92,8 @@ public class SLDebugALot {
9292

9393
@Test
9494
public void test() {
95-
try (Engine engine = Engine.newBuilder().out(out).err(err).allowExperimentalOptions(true).option("debugalot", "true").build()) {
96-
try (Context context = Context.newBuilder().engine(engine).build()) {
95+
try (Engine engine = newEngineBuilder().out(out).err(err).allowExperimentalOptions(true).option("debugalot", "true").build()) {
96+
try (Context context = newContextBuilder().engine(engine).build()) {
9797
context.eval(slCode);
9898
}
9999
}

0 commit comments

Comments
 (0)