Skip to content

Commit c06fcd1

Browse files
committed
Introduce some node object inlining
1 parent 1ff0ce9 commit c06fcd1

33 files changed

+520
-338
lines changed

src/de.hpi.swa.trufflesqueak.test/src/de/hpi/swa/trufflesqueak/test/SqueakBytecodeTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -466,13 +466,13 @@ public void testDup() {
466466
public void testPushNewArray() {
467467
final AbstractSqueakObject rcvr = image.specialObjectsArray;
468468
final SqueakObjectAt0Node at0Node = SqueakObjectAt0Node.create();
469-
final SqueakObjectSizeNode sizeNode = SqueakObjectSizeNode.create();
469+
final SqueakObjectSizeNode sizeNode = SqueakObjectSizeNode.getUncached();
470470
// pushNewArray (size 127), returnTop
471471
CompiledCodeObject method = makeMethod(new Object[]{makeHeader(0, 0, 0, false, true)}, 138, 127, 124);
472472
Object result = runMethod(method, rcvr);
473473
assertTrue(result instanceof ArrayObject);
474474
ArrayObject resultList = (ArrayObject) result;
475-
assertEquals(127, sizeNode.execute(resultList));
475+
assertEquals(127, sizeNode.execute(null, resultList));
476476

477477
// pushNewArray and pop
478478
final int arraySize = CONTEXT.MAX_STACK_SIZE;
@@ -487,7 +487,7 @@ public void testPushNewArray() {
487487
result = runMethod(method, rcvr);
488488
assertTrue(result instanceof ArrayObject);
489489
resultList = (ArrayObject) result;
490-
assertEquals(arraySize, sizeNode.execute(resultList));
490+
assertEquals(arraySize, sizeNode.execute(null, resultList));
491491
for (int i = 0; i < arraySize; i++) {
492492
assertEquals(BooleanObject.wrap(i % 2 == 0), at0Node.execute(resultList, i));
493493
}
@@ -527,7 +527,7 @@ public void testPushRemoteTemp() {
527527
@Test
528528
public void testStoreRemoteTemp() {
529529
final SqueakObjectAt0Node at0Node = SqueakObjectAt0Node.create();
530-
final SqueakObjectSizeNode sizeNode = SqueakObjectSizeNode.create();
530+
final SqueakObjectSizeNode sizeNode = SqueakObjectSizeNode.getUncached();
531531

532532
final Object[] literals = {2097154L, NilObject.SINGLETON, NilObject.SINGLETON}; // header
533533
// with
@@ -542,7 +542,7 @@ public void testStoreRemoteTemp() {
542542
final Object result = createContext(method, rcvr).execute(frame);
543543
assertTrue(result instanceof ArrayObject);
544544
final ArrayObject resultList = (ArrayObject) result;
545-
assertEquals(2, sizeNode.execute(resultList));
545+
assertEquals(2, sizeNode.execute(null, resultList));
546546
assertEquals(BooleanObject.FALSE, at0Node.execute(resultList, 0));
547547
assertEquals(BooleanObject.FALSE, at0Node.execute(resultList, 1));
548548
} catch (NonLocalReturn | NonVirtualReturn | ProcessSwitch e) {
@@ -553,7 +553,7 @@ public void testStoreRemoteTemp() {
553553
@Test
554554
public void testStoreAndPopRemoteTemp() {
555555
final SqueakObjectAt0Node at0Node = SqueakObjectAt0Node.create();
556-
final SqueakObjectSizeNode sizeNode = SqueakObjectSizeNode.create();
556+
final SqueakObjectSizeNode sizeNode = SqueakObjectSizeNode.getUncached();
557557

558558
final Object[] literals = {2097154L, NilObject.SINGLETON, NilObject.SINGLETON}; // header
559559
// with
@@ -568,7 +568,7 @@ public void testStoreAndPopRemoteTemp() {
568568
final Object result = createContext(method, rcvr).execute(frame);
569569
assertTrue(result instanceof ArrayObject);
570570
final ArrayObject resultList = (ArrayObject) result;
571-
assertEquals(2, sizeNode.execute(resultList));
571+
assertEquals(2, sizeNode.execute(null, resultList));
572572
assertEquals(BooleanObject.FALSE, at0Node.execute(resultList, 0));
573573
assertEquals(BooleanObject.TRUE, at0Node.execute(resultList, 1));
574574
} catch (NonLocalReturn | NonVirtualReturn | ProcessSwitch e) {

src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/interop/JavaObjectWrapper.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@
2424
import com.oracle.truffle.api.Truffle;
2525
import com.oracle.truffle.api.TruffleLanguage;
2626
import com.oracle.truffle.api.TruffleOptions;
27+
import com.oracle.truffle.api.dsl.Bind;
2728
import com.oracle.truffle.api.dsl.Cached;
2829
import com.oracle.truffle.api.dsl.Cached.Shared;
30+
import com.oracle.truffle.api.dsl.GenerateCached;
31+
import com.oracle.truffle.api.dsl.GenerateInline;
2932
import com.oracle.truffle.api.dsl.GenerateUncached;
3033
import com.oracle.truffle.api.dsl.Specialization;
3134
import com.oracle.truffle.api.dsl.UnsupportedSpecializationException;
@@ -588,9 +591,9 @@ protected boolean hasArrayElements(@Shared("lib") @CachedLibrary(limit = "LIMIT"
588591
@ExportMessage
589592
@ExportMessage(name = "isArrayElementModifiable")
590593
@TruffleBoundary
591-
protected boolean isArrayElementReadable(final long index, @Shared("sizeNode") @Cached final ArraySizeNode sizeNode) {
594+
protected boolean isArrayElementReadable(final long index, @Bind("$node") final Node node, @Shared("sizeNode") @Cached final ArraySizeNode sizeNode) {
592595
try {
593-
return 0 <= index && index < sizeNode.execute(wrappedObject);
596+
return 0 <= index && index < sizeNode.execute(node, wrappedObject);
594597
} catch (final UnsupportedSpecializationException | UnsupportedMessageException e) {
595598
return false;
596599
}
@@ -603,17 +606,19 @@ protected boolean isArrayElementInsertable(@SuppressWarnings("unused") final lon
603606

604607
@ExportMessage
605608
@TruffleBoundary
606-
protected long getArraySize(@Shared("sizeNode") @Cached final ArraySizeNode sizeNode) throws UnsupportedMessageException {
609+
protected long getArraySize(@Bind("$node") final Node node, @Shared("sizeNode") @Cached final ArraySizeNode sizeNode) throws UnsupportedMessageException {
607610
try {
608-
return sizeNode.execute(wrappedObject);
611+
return sizeNode.execute(node, wrappedObject);
609612
} catch (final UnsupportedSpecializationException e) {
610613
throw UnsupportedMessageException.create();
611614
}
612615
}
613616

617+
@GenerateInline
614618
@GenerateUncached
619+
@GenerateCached(false)
615620
protected abstract static class ArraySizeNode extends Node {
616-
protected abstract int execute(Object object) throws UnsupportedSpecializationException, UnsupportedMessageException;
621+
protected abstract int execute(Node node, Object object) throws UnsupportedSpecializationException, UnsupportedMessageException;
617622

618623
@Specialization
619624
protected static final int doBoolean(final boolean[] object) {
@@ -667,19 +672,21 @@ protected static final int doTruffleObject(final TruffleObject object, @CachedLi
667672
}
668673

669674
@ExportMessage
670-
protected Object readArrayElement(final long index, @Cached final ReadArrayElementNode readNode) throws InvalidArrayIndexException, UnsupportedMessageException {
675+
protected Object readArrayElement(final long index, @Bind("$node") final Node node, @Cached final ReadArrayElementNode readNode) throws InvalidArrayIndexException, UnsupportedMessageException {
671676
try {
672-
return readNode.execute(wrappedObject, (int) index);
677+
return readNode.execute(node, wrappedObject, (int) index);
673678
} catch (final ArrayIndexOutOfBoundsException e) {
674679
throw InvalidArrayIndexException.create(index);
675680
} catch (final UnsupportedSpecializationException e) {
676681
throw UnsupportedMessageException.create();
677682
}
678683
}
679684

685+
@GenerateInline
680686
@GenerateUncached
687+
@GenerateCached(false)
681688
protected abstract static class ReadArrayElementNode extends Node {
682-
protected abstract Object execute(Object object, int index) throws UnsupportedMessageException, InvalidArrayIndexException;
689+
protected abstract Object execute(Node node, Object object, int index) throws UnsupportedMessageException, InvalidArrayIndexException;
683690

684691
@Specialization
685692
protected static final boolean doBoolean(final boolean[] object, final int index) {
@@ -734,20 +741,22 @@ protected static final Object doTruffleObject(final TruffleObject object, final
734741
}
735742

736743
@ExportMessage
737-
protected void writeArrayElement(final long index, final Object value, @Cached final WriteArrayElementNode writeNode)
744+
protected void writeArrayElement(final long index, final Object value, @Bind("$node") final Node node, @Cached final WriteArrayElementNode writeNode)
738745
throws InvalidArrayIndexException, UnsupportedMessageException, UnsupportedTypeException {
739746
try {
740-
writeNode.execute(wrappedObject, (int) index, value);
747+
writeNode.execute(node, wrappedObject, (int) index, value);
741748
} catch (final ArrayIndexOutOfBoundsException e) {
742749
throw InvalidArrayIndexException.create(index);
743750
} catch (final UnsupportedSpecializationException e) {
744751
throw UnsupportedMessageException.create();
745752
}
746753
}
747754

755+
@GenerateInline
748756
@GenerateUncached
757+
@GenerateCached(false)
749758
protected abstract static class WriteArrayElementNode extends Node {
750-
protected abstract void execute(Object object, int index, Object value) throws UnsupportedMessageException, InvalidArrayIndexException, UnsupportedTypeException;
759+
protected abstract void execute(Node node, Object object, int index, Object value) throws UnsupportedMessageException, InvalidArrayIndexException, UnsupportedTypeException;
751760

752761
@Specialization
753762
protected static final void doBoolean(final boolean[] object, final int index, final boolean value) {

src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/interop/LookupMethodByStringNode.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88

99
import java.util.Arrays;
1010

11+
import com.oracle.truffle.api.dsl.Bind;
1112
import com.oracle.truffle.api.dsl.Cached;
1213
import com.oracle.truffle.api.dsl.GenerateUncached;
1314
import com.oracle.truffle.api.dsl.ReportPolymorphism;
1415
import com.oracle.truffle.api.dsl.Specialization;
16+
import com.oracle.truffle.api.nodes.Node;
1517

1618
import de.hpi.swa.trufflesqueak.model.ClassObject;
1719
import de.hpi.swa.trufflesqueak.model.NativeObject;
@@ -45,12 +47,13 @@ protected static final Object doCached(final ClassObject classObject, final Stri
4547
}
4648

4749
protected static final Object doUncachedSlow(final ClassObject classObject, final String selector) {
48-
return doUncached(classObject, selector, AbstractPointersObjectReadNode.getUncached(), ArrayObjectReadNode.getUncached());
50+
return doUncached(classObject, selector, null, AbstractPointersObjectReadNode.getUncached(), ArrayObjectReadNode.getUncached());
4951
}
5052

5153
@ReportPolymorphism.Megamorphic
5254
@Specialization(replaces = "doCached")
5355
protected static final Object doUncached(final ClassObject classObject, final String selector,
56+
@Bind("this") final Node node,
5457
/**
5558
* An AbstractPointersObjectReadNode is sufficient for accessing `values`
5659
* instance variable here.

src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/interop/WrapToSqueakNode.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,16 @@ protected static final long doLong(final long value) {
7373

7474
@Specialization
7575
protected static final Object doFloat(final float value,
76+
@Bind("this") final Node node,
7677
@Shared("boxNode") @Cached final AsFloatObjectIfNessaryNode boxNode) {
77-
return boxNode.execute(value);
78+
return boxNode.execute(node, value);
7879
}
7980

8081
@Specialization
8182
protected static final Object doDouble(final double value,
83+
@Bind("this") final Node node,
8284
@Shared("boxNode") @Cached final AsFloatObjectIfNessaryNode boxNode) {
83-
return boxNode.execute(value);
85+
return boxNode.execute(node, value);
8486
}
8587

8688
@Specialization

src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/AbstractPointersObject.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.oracle.truffle.api.CompilerDirectives;
1313
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
1414
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
15+
import com.oracle.truffle.api.nodes.Node;
1516

1617
import de.hpi.swa.trufflesqueak.image.SqueakImageChunk;
1718
import de.hpi.swa.trufflesqueak.image.SqueakImageContext;
@@ -296,21 +297,21 @@ public final void instVarAtPut0Slow(final long index, final Object value) {
296297
AbstractPointersObjectWriteNode.getUncached().execute(this, index, value);
297298
}
298299

299-
protected final boolean layoutValuesPointTo(final SqueakObjectIdentityNode identityNode, final Object thang) {
300+
protected final boolean layoutValuesPointTo(final SqueakObjectIdentityNode identityNode, final Node inlineTarget, final Object thang) {
300301
final boolean pointTo = object0 == thang || object1 == thang || object2 == thang || objectExtension != null && ArrayUtils.contains(objectExtension, thang);
301302
if (pointTo) {
302303
return true;
303304
} else {
304-
return primitiveLocationsPointTo(identityNode, thang);
305+
return primitiveLocationsPointTo(identityNode, inlineTarget, thang);
305306
}
306307
}
307308

308309
@TruffleBoundary
309-
private boolean primitiveLocationsPointTo(final SqueakObjectIdentityNode identityNode, final Object thang) {
310+
private boolean primitiveLocationsPointTo(final SqueakObjectIdentityNode identityNode, final Node inlineTarget, final Object thang) {
310311
if (SqueakGuards.isUsedJavaPrimitive(thang)) {
311312
// TODO: This could be more efficient.
312313
for (final SlotLocation slotLocation : getLayout().getLocations()) {
313-
if (slotLocation.isPrimitive() && identityNode.execute(slotLocation.read(this), thang)) {
314+
if (slotLocation.isPrimitive() && identityNode.execute(inlineTarget, slotLocation.read(this), thang)) {
314315
return true;
315316
}
316317
}

src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/AbstractVariablePointersObject.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
import java.util.Arrays;
1010

11+
import com.oracle.truffle.api.nodes.Node;
12+
1113
import de.hpi.swa.trufflesqueak.image.SqueakImageContext;
1214
import de.hpi.swa.trufflesqueak.model.layout.ObjectLayout;
1315
import de.hpi.swa.trufflesqueak.nodes.accessing.SqueakObjectIdentityNode;
@@ -48,8 +50,8 @@ public final int size() {
4850
return instsize() + variablePart.length;
4951
}
5052

51-
public boolean pointsTo(final SqueakObjectIdentityNode identityNode, final Object thang) {
52-
return layoutValuesPointTo(identityNode, thang) || ArrayUtils.contains(variablePart, thang);
53+
public boolean pointsTo(final SqueakObjectIdentityNode identityNode, final Node inlineTarget, final Object thang) {
54+
return layoutValuesPointTo(identityNode, inlineTarget, thang) || ArrayUtils.contains(variablePart, thang);
5355
}
5456

5557
public final Object[] getVariablePart() {

src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/NativeObject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public int instsize() {
147147
@Override
148148
public int size() {
149149
CompilerAsserts.neverPartOfCompilation();
150-
return NativeObjectSizeNode.getUncached().execute(this);
150+
return NativeObjectSizeNode.getUncached().execute(null, this);
151151
}
152152

153153
public void become(final NativeObject other) {

src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/PointersObject.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package de.hpi.swa.trufflesqueak.model;
88

99
import com.oracle.truffle.api.CompilerAsserts;
10+
import com.oracle.truffle.api.nodes.Node;
1011

1112
import de.hpi.swa.trufflesqueak.image.SqueakImageContext;
1213
import de.hpi.swa.trufflesqueak.image.SqueakImageWriter;
@@ -71,8 +72,8 @@ public int size() {
7172
return instsize();
7273
}
7374

74-
public boolean pointsTo(final SqueakObjectIdentityNode identityNode, final Object thang) {
75-
return layoutValuesPointTo(identityNode, thang);
75+
public boolean pointsTo(final SqueakObjectIdentityNode identityNode, final Node inlineTarget, final Object thang) {
76+
return layoutValuesPointTo(identityNode, inlineTarget, thang);
7677
}
7778

7879
public boolean isEmptyList(final AbstractPointersObjectReadNode readNode) {

src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/WeakVariablePointersObject.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ public void putIntoVariablePart(final long index, final Object value, final Inli
8787
}
8888

8989
@Override
90-
public boolean pointsTo(final SqueakObjectIdentityNode identityNode, final Object thang) {
91-
return layoutValuesPointTo(identityNode, thang) || variablePartPointsTo(thang);
90+
public boolean pointsTo(final SqueakObjectIdentityNode identityNode, final Node inlineTarget, final Object thang) {
91+
return layoutValuesPointTo(identityNode, inlineTarget, thang) || variablePartPointsTo(thang);
9292
}
9393

9494
private boolean variablePartPointsTo(final Object thang) {

src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/accessing/AbstractPointersObjectNodes.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import com.oracle.truffle.api.dsl.Bind;
1212
import com.oracle.truffle.api.dsl.Cached;
1313
import com.oracle.truffle.api.dsl.Cached.Exclusive;
14+
import com.oracle.truffle.api.dsl.GenerateCached;
15+
import com.oracle.truffle.api.dsl.GenerateInline;
1416
import com.oracle.truffle.api.dsl.GenerateUncached;
1517
import com.oracle.truffle.api.dsl.ImportStatic;
1618
import com.oracle.truffle.api.dsl.NeverDefault;
@@ -150,9 +152,11 @@ protected static final void doWriteGeneric(final AbstractPointersObject object,
150152
}
151153
}
152154

155+
@GenerateInline
153156
@GenerateUncached
157+
@GenerateCached(false)
154158
public abstract static class AbstractPointersObjectInstSizeNode extends AbstractNode {
155-
public abstract int execute(AbstractPointersObject obj);
159+
public abstract int execute(Node node, AbstractPointersObject obj);
156160

157161
@Specialization(guards = {"object.getLayout() == cachedLayout"}, assumptions = "cachedLayout.getValidAssumption()", limit = "1")
158162
protected static final int doSizeCached(@SuppressWarnings("unused") final AbstractPointersObject object,

src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/accessing/ArrayObjectNodes.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import com.oracle.truffle.api.dsl.Cached;
1111
import com.oracle.truffle.api.dsl.Cached.Exclusive;
1212
import com.oracle.truffle.api.dsl.Cached.Shared;
13+
import com.oracle.truffle.api.dsl.GenerateCached;
14+
import com.oracle.truffle.api.dsl.GenerateInline;
1315
import com.oracle.truffle.api.dsl.GenerateUncached;
1416
import com.oracle.truffle.api.dsl.ImportStatic;
1517
import com.oracle.truffle.api.dsl.NeverDefault;
@@ -32,7 +34,9 @@
3234
import de.hpi.swa.trufflesqueak.util.FrameAccess;
3335

3436
public final class ArrayObjectNodes {
37+
3538
@GenerateUncached
39+
@GenerateCached
3640
public abstract static class ArrayObjectReadNode extends AbstractNode {
3741

3842
@NeverDefault
@@ -100,9 +104,11 @@ protected static final Object doArrayOfObjects(final ArrayObject obj, final long
100104
}
101105
}
102106

107+
@GenerateInline
108+
@GenerateCached(false)
103109
public abstract static class ArrayObjectShallowCopyNode extends AbstractNode {
104110

105-
public abstract ArrayObject execute(ArrayObject obj);
111+
public abstract ArrayObject execute(Node node, ArrayObject obj);
106112

107113
@Specialization(guards = "obj.isEmptyType()")
108114
protected static final ArrayObject doEmptyArray(final ArrayObject obj) {

src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/accessing/BlockClosureObjectNodes.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
*/
77
package de.hpi.swa.trufflesqueak.nodes.accessing;
88

9+
import com.oracle.truffle.api.dsl.GenerateCached;
10+
import com.oracle.truffle.api.dsl.GenerateInline;
911
import com.oracle.truffle.api.dsl.GenerateUncached;
1012
import com.oracle.truffle.api.dsl.ImportStatic;
1113
import com.oracle.truffle.api.dsl.Specialization;
14+
import com.oracle.truffle.api.nodes.Node;
1215

1316
import de.hpi.swa.trufflesqueak.model.AbstractSqueakObject;
1417
import de.hpi.swa.trufflesqueak.model.BlockClosureObject;
@@ -19,11 +22,13 @@
1922
import de.hpi.swa.trufflesqueak.nodes.AbstractNode;
2023

2124
public final class BlockClosureObjectNodes {
25+
@GenerateInline
2226
@GenerateUncached
27+
@GenerateCached(false)
2328
@ImportStatic(BLOCK_CLOSURE.class)
2429
public abstract static class BlockClosureObjectReadNode extends AbstractNode {
2530

26-
public abstract Object execute(BlockClosureObject closure, long index);
31+
public abstract Object execute(Node node, BlockClosureObject closure, long index);
2732

2833
@Specialization(guards = "index == OUTER_CONTEXT")
2934
protected static final AbstractSqueakObject doClosureOuterContext(final BlockClosureObject closure, @SuppressWarnings("unused") final long index) {
@@ -61,11 +66,13 @@ protected static final Object doFullClosureCopiedValues(final BlockClosureObject
6166
}
6267
}
6368

69+
@GenerateInline
6470
@GenerateUncached
71+
@GenerateCached(false)
6572
@ImportStatic(BLOCK_CLOSURE.class)
6673
public abstract static class BlockClosureObjectWriteNode extends AbstractNode {
6774

68-
public abstract void execute(BlockClosureObject closure, long index, Object value);
75+
public abstract void execute(Node node, BlockClosureObject closure, long index, Object value);
6976

7077
@Specialization(guards = "index == OUTER_CONTEXT")
7178
protected static final void doClosureOuterContext(final BlockClosureObject closure, @SuppressWarnings("unused") final long index, final ContextObject value) {

0 commit comments

Comments
 (0)