Skip to content

Commit 44a1ff6

Browse files
committed
[GR-24401] Generalize the object model of Espresso.
PullRequest: graal/8738
2 parents e13e9a5 + e81575d commit 44a1ff6

39 files changed

+3079
-1160
lines changed

espresso/ci.jsonnet

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,28 @@
3535
builds: common.builds + [
3636
// Benchmarks
3737
// AWFY peak perf. benchmarks
38-
common.jdk8_weekly_bench_linux + common.espresso_benchmark('jvm-ce', 'awfy:*', extra_args=['--vm.Xmx1g', '--vm.Xms1g']) + {name: 'weekly-bench-espresso-jvm-ce-awfy-jdk8-linux-amd64'},
39-
common.jdk8_weekly_bench_linux + common.espresso_benchmark('native-ce', 'awfy:*', extra_args=['--vm.Xmx1g', '--vm.Xms1g']) + {name: 'weekly-bench-espresso-native-ce-awfy-jdk8-linux-amd64'},
38+
common.jdk8_weekly_bench_linux + common.espresso_benchmark('jvm-ce', 'awfy:*' , extra_args=['--vm.Xmx1g', '--vm.Xms1g']) + {name: 'weekly-bench-espresso-jvm-ce-awfy-jdk8-linux-amd64'},
39+
common.jdk8_weekly_bench_linux + common.espresso_benchmark('jvm-ce', 'awfy:*' , guest_jvm_config='shape-checks' , extra_args=['--vm.Xmx1g', '--vm.Xms1g']) + {name: 'weekly-bench-espresso-jvm-ce-awfy-shape-checks-jdk8-linux-amd64'},
40+
common.jdk8_weekly_bench_linux + common.espresso_benchmark('jvm-ce', 'awfy:*' , guest_jvm_config='array-based' , extra_args=['--vm.Xmx1g', '--vm.Xms1g']) + {name: 'weekly-bench-espresso-jvm-ce-awfy-array-based-jdk8-linux-amd64'},
41+
common.jdk8_weekly_bench_linux + common.espresso_benchmark('native-ce', 'awfy:*' , extra_args=['--vm.Xmx1g', '--vm.Xms1g']) + {name: 'weekly-bench-espresso-native-ce-awfy-jdk8-linux-amd64'},
42+
common.jdk8_weekly_bench_linux + common.espresso_benchmark('native-ce', 'awfy:*', guest_jvm_config='shape-checks' , extra_args=['--vm.Xmx1g', '--vm.Xms1g']) + {name: 'weekly-bench-espresso-native-ce-awfy-shape-checks-jdk8-linux-amd64'},
4043

4144
// AWFY interpreter benchmarks
42-
common.jdk8_weekly_bench_linux + common.espresso_interpreter_benchmark('jvm-ce', 'awfy:*') + {name: 'weekly-bench-espresso-jvm-ce-awfy_interpreter-jdk8-linux-amd64'},
43-
common.jdk8_weekly_bench_linux + common.espresso_interpreter_benchmark('native-ce', 'awfy:*') + {name: 'weekly-bench-espresso-native-ce-awfy_interpreter-jdk8-linux-amd64'},
45+
common.jdk8_weekly_bench_linux + common.espresso_interpreter_benchmark('jvm-ce', 'awfy:*') + {name: 'weekly-bench-espresso-jvm-ce-awfy_interpreter-jdk8-linux-amd64'},
46+
common.jdk8_weekly_bench_linux + common.espresso_interpreter_benchmark('native-ce', 'awfy:*') + {name: 'weekly-bench-espresso-native-ce-awfy_interpreter-jdk8-linux-amd64'},
4447

4548
// Scala DaCapo warmup benchmarks
46-
common.jdk8_weekly_bench_linux + common.scala_dacapo_warmup_benchmark('jvm-ce', 'single-tier', extra_args=['--vm.XX:ReservedCodeCacheSize=1g']) + {name: 'weekly-bench-espresso-jvm-ce-scala_dacapo_warmup-single_tier-jdk8-linux-amd64'},
47-
common.jdk8_weekly_bench_linux + common.scala_dacapo_warmup_benchmark('native-ce', 'single-tier') + {name: 'weekly-bench-espresso-native-ce-scala_dacapo_warmup-single_tier-jdk8-linux-amd64'},
48-
common.jdk8_weekly_bench_linux + common.scala_dacapo_warmup_benchmark('jvm-ce', 'multi-tier', extra_args=['--vm.XX:ReservedCodeCacheSize=1g']) + {name: 'weekly-bench-espresso-jvm-ce-scala_dacapo_warmup-multi_tier-jdk8-linux-amd64'},
49-
common.jdk8_weekly_bench_linux + common.scala_dacapo_warmup_benchmark('native-ce', 'multi-tier') + {name: 'weekly-bench-espresso-native-ce-scala_dacapo_warmup-multi_tier-jdk8-linux-amd64'},
49+
common.jdk8_weekly_bench_linux + common.scala_dacapo_warmup_benchmark('jvm-ce', 'single-tier' , extra_args=['--vm.XX:ReservedCodeCacheSize=1g']) + {name: 'weekly-bench-espresso-jvm-ce-scala_dacapo_warmup-single_tier-jdk8-linux-amd64'},
50+
common.jdk8_weekly_bench_linux + common.scala_dacapo_warmup_benchmark('native-ce', 'single-tier') + {name: 'weekly-bench-espresso-native-ce-scala_dacapo_warmup-single_tier-jdk8-linux-amd64'},
51+
common.jdk8_weekly_bench_linux + common.scala_dacapo_warmup_benchmark('jvm-ce', 'multi-tier' , extra_args=['--vm.XX:ReservedCodeCacheSize=1g']) + {name: 'weekly-bench-espresso-jvm-ce-scala_dacapo_warmup-multi_tier-jdk8-linux-amd64'},
52+
common.jdk8_weekly_bench_linux + common.scala_dacapo_warmup_benchmark('native-ce', 'multi-tier') + {name: 'weekly-bench-espresso-native-ce-scala_dacapo_warmup-multi_tier-jdk8-linux-amd64'},
5053

5154
// On-demand benchmarks
5255
// Scala DaCapo warmup benchmarks
53-
common.jdk8_on_demand_bench_linux + common.graal_benchmark('jvm-ce', common.scala_dacapo_jvm_fast(warmup=true)) + {name: 'ondemand-bench-espresso-jvm-ce-scala_dacapo_warmup-jdk8-linux-amd64'},
56+
common.jdk8_on_demand_bench_linux + common.graal_benchmark('jvm-ce', common.scala_dacapo_jvm_fast(warmup=true)) + {name: 'ondemand-bench-espresso-jvm-ce-scala_dacapo_warmup-jdk8-linux-amd64'},
5457

5558
// Memory footprint
56-
common.jdk8_on_demand_linux + common.espresso_minheap_benchmark('jvm-ce', 'awfy:*', 'infinite-overhead') + {name: 'ondemand-bench-espresso-jvm-ce-awfy-minheap-infinite-ovh-jdk8-linux-amd64'},
57-
common.jdk8_on_demand_bench_linux + common.espresso_minheap_benchmark('jvm-ce', 'awfy:*', '1.5-overhead') + {name: 'ondemand-bench-espresso-jvm-ce-awfy-minheap-1.5-ovh-jdk8-linux-amd64'},
59+
common.jdk8_on_demand_linux + common.espresso_minheap_benchmark('jvm-ce', 'awfy:*', 'infinite-overhead') + {name: 'ondemand-bench-espresso-jvm-ce-awfy-minheap-infinite-ovh-jdk8-linux-amd64'},
60+
common.jdk8_on_demand_bench_linux + common.espresso_minheap_benchmark('jvm-ce', 'awfy:*', '1.5-overhead') + {name: 'ondemand-bench-espresso-jvm-ce-awfy-minheap-1.5-ovh-jdk8-linux-amd64'},
5861
]
5962
}

espresso/mx.espresso/mx_espresso_benchmarks.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ def run_with_heap(heap, args, timeout, suppressStderr=True, nonZeroIsFatal=False
133133
mx_benchmark.java_vm_registry.add_vm(EspressoVm('multi-tier', ['--experimental-options', '--engine.MultiTier=true']), _suite)
134134
mx_benchmark.java_vm_registry.add_vm(EspressoVm('multi-tier-inline-accessors', ['--experimental-options', '--engine.MultiTier', '--java.InlineFieldAccessors']), _suite)
135135
mx_benchmark.java_vm_registry.add_vm(EspressoVm('no-inlining', ['--experimental-options', '--engine.Inlining=false']), _suite)
136+
mx_benchmark.java_vm_registry.add_vm(EspressoVm('array-based', ['--vm.Dcom.oracle.truffle.espresso.staticobject.ArrayBasedStorage=true']), _suite)
137+
mx_benchmark.java_vm_registry.add_vm(EspressoVm('shape-checks', ['--vm.Dcom.oracle.truffle.espresso.staticobject.ArrayBasedStorage=true', '--vm.Dcom.oracle.truffle.espresso.staticobject.ShapeChecks=true']), _suite)
136138

137139
mx_benchmark.java_vm_registry.add_vm(EspressoMinHeapVm(0, 0, 64, 'infinite-overhead', []), _suite)
138140
mx_benchmark.java_vm_registry.add_vm(EspressoMinHeapVm(1.5, 0, 2048, '1.5-overhead', []), _suite)

espresso/mx.espresso/reflectconfig.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,19 @@
2323
"fields": [
2424
{ "name": "VM_SUPPORTS_LONG_CAS" }
2525
]
26+
},
27+
{
28+
"name": "com.oracle.truffle.espresso.runtime.StaticObject$DefaultArrayBasedStaticObjectFactory",
29+
"methods": [
30+
{ "name" : "<init>", "parameterTypes": ["java.lang.Object", "int", "int"] }
31+
]
32+
},
33+
{
34+
"name": "com.oracle.truffle.espresso.runtime.StaticObject$DefaultArrayBasedStaticObject",
35+
"fields": [
36+
{ "name": "shape", "allowUnsafeAccess": true },
37+
{ "name": "primitive", "allowUnsafeAccess": true },
38+
{ "name": "object", "allowUnsafeAccess": true }
39+
]
2640
}
2741
]

espresso/mx.espresso/suite.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@
8585
"subDir": "src",
8686
"sourceDirs": ["src"],
8787
"dependencies": [
88-
"truffle:TRUFFLE_API",
8988
"truffle:TRUFFLE_NFI",
9089
"com.oracle.truffle.espresso.jdwp",
90+
"com.oracle.truffle.espresso.staticobject",
9191
],
9292
"uses": [
9393
"com.oracle.truffle.espresso._native.NativeAccess.Provider",
@@ -99,6 +99,28 @@
9999
"checkPackagePrefix": False, # java.lang.ref.PublicFinalReference
100100
},
101101

102+
"com.oracle.truffle.espresso.staticobject": {
103+
"subDir": "src",
104+
"sourceDirs": ["src"],
105+
"dependencies": [
106+
"truffle:TRUFFLE_API",
107+
"truffle:TRUFFLE_ASM_7.2",
108+
],
109+
"javaCompliance": "1.8+",
110+
"checkstyle": "com.oracle.truffle.espresso",
111+
},
112+
113+
"com.oracle.truffle.espresso.staticobject.test": {
114+
"subDir" : "src",
115+
"sourceDirs" : ["src"],
116+
"dependencies" : [
117+
"com.oracle.truffle.espresso.staticobject",
118+
"mx:JUNIT"
119+
],
120+
"javaCompliance": "1.8+",
121+
"checkstyle": "com.oracle.truffle.espresso",
122+
},
123+
102124
"com.oracle.truffle.espresso.processor": {
103125
"subDir": "src",
104126
"sourceDirs": ["src"],
@@ -257,12 +279,28 @@
257279
"truffle:TRUFFLE_NFI_LIBFFI",
258280
"tools:TRUFFLE_PROFILER",
259281
],
282+
"exclude": [
283+
"truffle:TRUFFLE_ASM_7.2",
284+
],
260285
"javaProperties": {
261286
"org.graalvm.language.java.home": "<path:ESPRESSO_SUPPORT>",
262287
"polyglot.java.JVMLibraryPath": "<path:ESPRESSO_JVM_SUPPORT>/truffle",
263288
},
264289
},
265290

291+
"ESPRESSO_STATICOBJECT_TESTS": {
292+
"subDir": "src",
293+
"dependencies": [
294+
"com.oracle.truffle.espresso.staticobject.test",
295+
],
296+
"distDependencies": [
297+
"espresso:ESPRESSO",
298+
],
299+
"exclude": [
300+
"mx:JUNIT",
301+
],
302+
},
303+
266304
"ESPRESSO_LAUNCHER": {
267305
"subDir": "src",
268306
"dependencies": [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
/*
2+
* Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
package com.oracle.truffle.espresso.staticobject.test;
24+
25+
import com.oracle.truffle.espresso.staticobject.DefaultStaticObject;
26+
import com.oracle.truffle.espresso.staticobject.DefaultStaticProperty;
27+
import com.oracle.truffle.espresso.staticobject.StaticProperty;
28+
import com.oracle.truffle.espresso.staticobject.StaticPropertyKind;
29+
import com.oracle.truffle.espresso.staticobject.StaticShape;
30+
import org.junit.Assert;
31+
import org.junit.Assume;
32+
import org.junit.Test;
33+
34+
import java.lang.reflect.Field;
35+
import java.lang.reflect.Modifier;
36+
37+
public class BuilderPropertyTest extends StaticObjectTest {
38+
@Test
39+
public void sameBuilderSameProperty() {
40+
StaticShape.Builder builder = StaticShape.newBuilder(this);
41+
StaticProperty property = new DefaultStaticProperty("property", StaticPropertyKind.Int, false);
42+
builder.property(property);
43+
try {
44+
// You cannot add the same property twice
45+
builder.property(property);
46+
Assert.fail();
47+
} catch (IllegalArgumentException e) {
48+
// You cannot add the same property twice
49+
Assert.assertEquals("This builder already contains a property with id 'property'", e.getMessage());
50+
}
51+
}
52+
53+
@Test
54+
public void sameBuilderSameName() throws IllegalArgumentException {
55+
StaticShape.Builder builder = StaticShape.newBuilder(this);
56+
StaticProperty p1 = new DefaultStaticProperty("property", StaticPropertyKind.Int, false);
57+
StaticProperty p2 = new DefaultStaticProperty("property", StaticPropertyKind.Int, false);
58+
builder.property(p1);
59+
try {
60+
// You cannot add two properties with the same name
61+
builder.property(p2);
62+
Assert.fail();
63+
} catch (IllegalArgumentException e) {
64+
Assert.assertEquals("This builder already contains a property with id 'property'", e.getMessage());
65+
}
66+
}
67+
68+
@Test
69+
public void differentBuildersSameProperty() {
70+
StaticShape.Builder b1 = StaticShape.newBuilder(this);
71+
StaticShape.Builder b2 = StaticShape.newBuilder(this);
72+
StaticProperty property = new DefaultStaticProperty("property", StaticPropertyKind.Int, false);
73+
b1.property(property);
74+
b2.property(property);
75+
b1.build();
76+
try {
77+
// You cannot build shapes that share properties
78+
b2.build();
79+
Assert.fail();
80+
} catch (RuntimeException e) {
81+
Assert.assertEquals("Attempt to reinitialize the offset of static property 'property' of kind 'Int'.\nWas it added to more than one builder or multiple times to the same builder?",
82+
e.getMessage());
83+
}
84+
}
85+
86+
@Test
87+
public void propertyName() throws NoSuchFieldException {
88+
Assume.assumeFalse(ARRAY_BASED_STORAGE);
89+
90+
StaticShape.Builder builder = StaticShape.newBuilder(this);
91+
StaticProperty property = new DefaultStaticProperty("property", StaticPropertyKind.Int, false);
92+
builder.property(property);
93+
StaticShape<DefaultStaticObject.Factory> shape = builder.build();
94+
DefaultStaticObject object = shape.getFactory().create();
95+
object.getClass().getField(guessGeneratedFieldName(property));
96+
}
97+
98+
@Test
99+
public void propertyFinal() throws NoSuchFieldException {
100+
Assume.assumeFalse(ARRAY_BASED_STORAGE);
101+
102+
StaticShape.Builder builder = StaticShape.newBuilder(this);
103+
StaticProperty p1 = new DefaultStaticProperty("p1", StaticPropertyKind.Int, true);
104+
StaticProperty p2 = new DefaultStaticProperty("p2", StaticPropertyKind.Int, false);
105+
builder.property(p1);
106+
builder.property(p2);
107+
StaticShape<DefaultStaticObject.Factory> shape = builder.build();
108+
DefaultStaticObject object = shape.getFactory().create();
109+
Field f1 = object.getClass().getField(guessGeneratedFieldName(p1));
110+
Field f2 = object.getClass().getField(guessGeneratedFieldName(p2));
111+
Assert.assertTrue(Modifier.isFinal(f1.getModifiers()));
112+
Assert.assertFalse(Modifier.isFinal(f2.getModifiers()));
113+
}
114+
115+
@Test
116+
public void propertyKind() throws NoSuchFieldException {
117+
Assume.assumeFalse(ARRAY_BASED_STORAGE);
118+
119+
StaticShape.Builder builder = StaticShape.newBuilder(this);
120+
StaticPropertyKind[] kinds = StaticPropertyKind.values();
121+
StaticProperty[] properties = new StaticProperty[kinds.length];
122+
for (int i = 0; i < properties.length; i++) {
123+
properties[i] = new DefaultStaticProperty(kinds[i].name(), kinds[i], false);
124+
builder.property(properties[i]);
125+
}
126+
StaticShape<DefaultStaticObject.Factory> shape = builder.build();
127+
DefaultStaticObject object = shape.getFactory().create();
128+
for (int i = 0; i < properties.length; i++) {
129+
Class<?> expectedType;
130+
switch (kinds[i]) {
131+
case Boolean:
132+
expectedType = boolean.class;
133+
break;
134+
case Byte:
135+
expectedType = byte.class;
136+
break;
137+
case Char:
138+
expectedType = char.class;
139+
break;
140+
case Double:
141+
expectedType = double.class;
142+
break;
143+
case Float:
144+
expectedType = float.class;
145+
break;
146+
case Int:
147+
expectedType = int.class;
148+
break;
149+
case Long:
150+
expectedType = long.class;
151+
break;
152+
case Object:
153+
expectedType = Object.class;
154+
break;
155+
case Short:
156+
expectedType = short.class;
157+
break;
158+
default:
159+
expectedType = null;
160+
Assert.fail("Unexpected type: " + kinds[i]);
161+
}
162+
Assert.assertEquals(expectedType, object.getClass().getField(guessGeneratedFieldName(properties[i])).getType());
163+
}
164+
}
165+
}

0 commit comments

Comments
 (0)