From fdb6469bb9686414ddb083605917a349f6774c93 Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Thu, 7 Dec 2023 10:49:40 +0100 Subject: [PATCH] Introduce more node object inlining --- .../test/AbstractSqueakTestCaseWithImage.java | 2 +- .../image/SqueakImageReader.java | 2 +- .../interop/LookupMethodByStringNode.java | 2 +- .../swa/trufflesqueak/model/ArrayObject.java | 4 +- .../nodes/HandlePrimitiveFailedNode.java | 11 +- .../trufflesqueak/nodes/InheritsFromNode.java | 11 +- .../AbstractPointersObjectNodes.java | 35 ++--- .../nodes/accessing/ArrayObjectNodes.java | 106 +++++---------- .../nodes/accessing/SqueakObjectAt0Node.java | 9 +- .../accessing/SqueakObjectAtPut0Node.java | 9 +- .../nodes/accessing/SqueakObjectSizeNode.java | 4 +- .../context/frame/FrameStackReadNode.java | 100 ++++---------- .../nodes/plugins/BitBltPlugin.java | 2 +- .../nodes/plugins/NullPlugin.java | 11 +- .../nodes/plugins/PolyglotPlugin.java | 26 ++-- .../nodes/plugins/SqueakFFIPrims.java | 5 +- .../primitives/impl/ControlPrimitives.java | 126 ++++++++++-------- .../nodes/primitives/impl/IOPrimitives.java | 57 ++++---- .../primitives/impl/StoragePrimitives.java | 11 +- .../nodes/process/PutToSleepNode.java | 25 ++-- .../process/WakeHighestPriorityNode.java | 7 +- 21 files changed, 269 insertions(+), 296 deletions(-) diff --git a/src/de.hpi.swa.trufflesqueak.test/src/de/hpi/swa/trufflesqueak/test/AbstractSqueakTestCaseWithImage.java b/src/de.hpi.swa.trufflesqueak.test/src/de/hpi/swa/trufflesqueak/test/AbstractSqueakTestCaseWithImage.java index ea73aee01..7db6a0fec 100644 --- a/src/de.hpi.swa.trufflesqueak.test/src/de/hpi/swa/trufflesqueak/test/AbstractSqueakTestCaseWithImage.java +++ b/src/de.hpi.swa.trufflesqueak.test/src/de/hpi/swa/trufflesqueak/test/AbstractSqueakTestCaseWithImage.java @@ -99,7 +99,7 @@ protected static void reloadImage() { private static void patchImageForTesting() { image.interrupt.start(); final ArrayObject lists = (ArrayObject) image.getScheduler().instVarAt0Slow(PROCESS_SCHEDULER.PROCESS_LISTS); - final PointersObject priority10List = (PointersObject) ArrayObjectReadNode.getUncached().execute(lists, PRIORITY_10_LIST_INDEX); + final PointersObject priority10List = (PointersObject) ArrayObjectReadNode.getUncached().execute(null, lists, PRIORITY_10_LIST_INDEX); final Object firstLink = priority10List.instVarAt0Slow(LINKED_LIST.FIRST_LINK); final Object lastLink = priority10List.instVarAt0Slow(LINKED_LIST.LAST_LINK); assert firstLink != NilObject.SINGLETON && firstLink == lastLink : "Unexpected idleProcess state"; diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/image/SqueakImageReader.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/image/SqueakImageReader.java index 14573da4f..4b681f62f 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/image/SqueakImageReader.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/image/SqueakImageReader.java @@ -433,7 +433,7 @@ private ClassObject lookupClassInCompactClassList(final int compactIndex) { final int majorIndex = SqueakImageConstants.majorClassIndexOf(compactIndex); final int minorIndex = SqueakImageConstants.minorClassIndexOf(compactIndex); final ArrayObject classTablePage = (ArrayObject) getChunk(hiddenRootsChunk.getWord(majorIndex)).asObject(); - final Object result = ArrayObjectReadNode.getUncached().execute(classTablePage, minorIndex); + final Object result = ArrayObjectReadNode.getUncached().execute(null, classTablePage, minorIndex); return result instanceof final ClassObject c ? c : null; } diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/interop/LookupMethodByStringNode.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/interop/LookupMethodByStringNode.java index b0cca59dc..4eba93bdb 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/interop/LookupMethodByStringNode.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/interop/LookupMethodByStringNode.java @@ -68,7 +68,7 @@ protected static final Object doUncached(final ClassObject classObject, final St for (int i = 0; i < methodDictVariablePart.length; i++) { final Object methodSelector = methodDictVariablePart[i]; if (methodSelector instanceof final NativeObject m && Arrays.equals(selectorBytes, m.getByteStorage())) { - return arrayReadNode.execute(pointersReadValuesNode.executeArray(methodDict, METHOD_DICT.VALUES), i); + return arrayReadNode.execute(node, pointersReadValuesNode.executeArray(methodDict, METHOD_DICT.VALUES), i); } } lookupClass = lookupClass.getSuperclassOrNull(); diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/ArrayObject.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/ArrayObject.java index e587cff3f..df7b61ef9 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/ArrayObject.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/ArrayObject.java @@ -84,7 +84,7 @@ public void fillin(final SqueakImageChunk chunk) { // Use a fresh write node because uncached node is too generic. final ArrayObjectWriteNode writeNode = ArrayObjectWriteNode.create(); for (int i = 0; i < valuesLength; i++) { - writeNode.execute(this, i, pointers[i]); + writeNode.execute(writeNode, this, i, pointers[i]); } } } @@ -208,7 +208,7 @@ public int instsize() { @Override public int size() { CompilerAsserts.neverPartOfCompilation(); - return ArrayObjectSizeNode.getUncached().execute(this); + return ArrayObjectSizeNode.getUncached().execute(null, this); } public ArrayObject shallowCopy(final Object storageCopy) { diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/HandlePrimitiveFailedNode.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/HandlePrimitiveFailedNode.java index f23529a24..5a0e5e403 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/HandlePrimitiveFailedNode.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/HandlePrimitiveFailedNode.java @@ -6,6 +6,7 @@ */ package de.hpi.swa.trufflesqueak.nodes; +import com.oracle.truffle.api.dsl.Bind; import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Cached.Shared; import com.oracle.truffle.api.dsl.NeverDefault; @@ -35,16 +36,18 @@ public static HandlePrimitiveFailedNode create(final CompiledCodeObject code) { public abstract void executeHandle(VirtualFrame frame, int reasonCode); protected abstract static class HandlePrimitiveFailedImplNode extends HandlePrimitiveFailedNode { - @Specialization(guards = {"reasonCode < sizeNode.execute(getContext().primitiveErrorTable)"}) - protected final void doHandleWithLookup(final VirtualFrame frame, final int reasonCode, + @Specialization(guards = {"reasonCode < sizeNode.execute(node, getContext().primitiveErrorTable)"}) + protected static final void doHandleWithLookup(final VirtualFrame frame, final int reasonCode, + @Bind("this") final Node node, @SuppressWarnings("unused") @Shared("sizeNode") @Cached final ArrayObjectSizeNode sizeNode, @Cached final ArrayObjectReadNode readNode, @Cached("createStackTopNode(frame)") final FrameStackWriteNode tempWriteNode) { - tempWriteNode.executeWrite(frame, readNode.execute(getContext().primitiveErrorTable, reasonCode)); + tempWriteNode.executeWrite(frame, readNode.execute(node, getContext(node).primitiveErrorTable, reasonCode)); } - @Specialization(guards = {"reasonCode >= sizeNode.execute(getContext().primitiveErrorTable)"}) + @Specialization(guards = {"reasonCode >= sizeNode.execute(node, getContext().primitiveErrorTable)"}) protected static final void doHandleRawValue(final VirtualFrame frame, final int reasonCode, + @SuppressWarnings("unused") @Bind("this") final Node node, @SuppressWarnings("unused") @Shared("sizeNode") @Cached final ArrayObjectSizeNode sizeNode, @Cached("createStackTopNode(frame)") final FrameStackWriteNode tempWriteNode) { tempWriteNode.executeWrite(frame, (long) reasonCode); diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/InheritsFromNode.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/InheritsFromNode.java index 7d6a4e41b..79f5d0a2d 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/InheritsFromNode.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/InheritsFromNode.java @@ -7,22 +7,23 @@ package de.hpi.swa.trufflesqueak.nodes; import com.oracle.truffle.api.dsl.Cached; +import com.oracle.truffle.api.dsl.GenerateCached; +import com.oracle.truffle.api.dsl.GenerateInline; import com.oracle.truffle.api.dsl.GenerateUncached; import com.oracle.truffle.api.dsl.ReportPolymorphism; import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.api.nodes.Node; import de.hpi.swa.trufflesqueak.model.ClassObject; import de.hpi.swa.trufflesqueak.nodes.accessing.SqueakObjectClassNode; +@GenerateInline @GenerateUncached +@GenerateCached(false) public abstract class InheritsFromNode extends AbstractNode { protected static final int CACHE_SIZE = 3; - public static InheritsFromNode create() { - return InheritsFromNodeGen.create(); - } - - public abstract boolean execute(Object object, ClassObject classObject); + public abstract boolean execute(Node node, Object object, ClassObject classObject); @SuppressWarnings("unused") @Specialization(limit = "CACHE_SIZE", guards = {"object == cachedObject", "classObject == cachedClass"}, assumptions = {"cachedClass.getClassHierarchyStable()"}) diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/accessing/AbstractPointersObjectNodes.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/accessing/AbstractPointersObjectNodes.java index 700a63a83..b689e9459 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/accessing/AbstractPointersObjectNodes.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/accessing/AbstractPointersObjectNodes.java @@ -8,7 +8,6 @@ import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; -import com.oracle.truffle.api.dsl.Bind; import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Cached.Exclusive; import com.oracle.truffle.api.dsl.GenerateCached; @@ -171,12 +170,14 @@ protected static final int doSizeGeneric(final AbstractPointersObject object) { } } + @GenerateInline @GenerateUncached + @GenerateCached(false) @NodeInfo(cost = NodeCost.NONE) @ImportStatic(AbstractPointersObjectNodes.class) public abstract static class VariablePointersObjectReadNode extends Node { - public abstract Object execute(VariablePointersObject object, long index); + public abstract Object execute(Node node, VariablePointersObject object, long index); @Specialization(guards = {"cachedIndex == index", "object.getLayout() == cachedLayout", "cachedIndex < cachedLayout.getInstSize()"}, // assumptions = "cachedLayout.getValidAssumption()", limit = "CACHE_LIMIT") @@ -216,12 +217,14 @@ protected static final Object doReadFromVariablePartGeneric(final VariablePointe } } + @GenerateInline @GenerateUncached + @GenerateCached(false) @NodeInfo(cost = NodeCost.NONE) @ImportStatic(AbstractPointersObjectNodes.class) public abstract static class VariablePointersObjectWriteNode extends Node { - public abstract void execute(VariablePointersObject object, long index, Object value); + public abstract void execute(Node node, VariablePointersObject object, long index, Object value); @Specialization(guards = {"cachedIndex == index", "object.getLayout() == cachedLayout", "cachedIndex < cachedLayout.getInstSize()"}, // assumptions = "cachedLayout.getValidAssumption()", limit = "CACHE_LIMIT") @@ -261,12 +264,14 @@ protected static final void doWriteIntoVariablePartGeneric(final VariablePointer } } + @GenerateInline @GenerateUncached + @GenerateCached(false) @NodeInfo(cost = NodeCost.NONE) @ImportStatic(AbstractPointersObjectNodes.class) public abstract static class WeakVariablePointersObjectReadNode extends Node { - public abstract Object execute(WeakVariablePointersObject object, long index); + public abstract Object execute(Node node, WeakVariablePointersObject object, long index); @Specialization(guards = {"cachedIndex == index", "object.getLayout() == cachedLayout", "cachedIndex < cachedLayout.getInstSize()"}, // assumptions = "cachedLayout.getValidAssumption()", limit = "CACHE_LIMIT") @@ -286,8 +291,7 @@ protected static final Object doReadGeneric(final WeakVariablePointersObject obj @Specialization(guards = {"cachedIndex == index", "object.getLayout() == cachedLayout", "cachedIndex >= cachedLayout.getInstSize()"}, // assumptions = "cachedLayout.getValidAssumption()", limit = "VARIABLE_PART_INDEX_CACHE_LIMIT") - protected static final Object doReadFromVariablePartCachedIndex(final WeakVariablePointersObject object, @SuppressWarnings("unused") final long index, - @Bind("this") final Node node, + protected static final Object doReadFromVariablePartCachedIndex(final Node node, final WeakVariablePointersObject object, @SuppressWarnings("unused") final long index, @Cached("index") final long cachedIndex, @Cached("object.getLayout()") final ObjectLayout cachedLayout, @Exclusive @Cached final InlinedConditionProfile weakRefProfile) { @@ -296,8 +300,7 @@ protected static final Object doReadFromVariablePartCachedIndex(final WeakVariab @Specialization(guards = {"object.getLayout() == cachedLayout", "index >= cachedLayout.getInstSize()"}, assumptions = "cachedLayout.getValidAssumption()", // replaces = "doReadFromVariablePartCachedIndex", limit = "VARIABLE_PART_LAYOUT_CACHE_LIMIT") - protected static final Object doReadFromVariablePartCachedLayout(final WeakVariablePointersObject object, final long index, - @Bind("this") final Node node, + protected static final Object doReadFromVariablePartCachedLayout(final Node node, final WeakVariablePointersObject object, final long index, @Cached("object.getLayout()") final ObjectLayout cachedLayout, @Exclusive @Cached final InlinedConditionProfile weakRefProfile) { return object.getFromVariablePart(index - cachedLayout.getInstSize(), weakRefProfile, node); @@ -305,19 +308,20 @@ protected static final Object doReadFromVariablePartCachedLayout(final WeakVaria @ReportPolymorphism.Megamorphic @Specialization(guards = "index >= object.instsize()", replaces = {"doReadFromVariablePartCachedIndex", "doReadFromVariablePartCachedLayout"}) - protected static final Object doReadFromVariablePartGeneric(final WeakVariablePointersObject object, final long index, - @Bind("this") final Node node, + protected static final Object doReadFromVariablePartGeneric(final Node node, final WeakVariablePointersObject object, final long index, @Exclusive @Cached final InlinedConditionProfile weakRefProfile) { return object.getFromVariablePart(index - object.instsize(), weakRefProfile, node); } } + @GenerateInline @GenerateUncached + @GenerateCached(false) @NodeInfo(cost = NodeCost.NONE) @ImportStatic(AbstractPointersObjectNodes.class) public abstract static class WeakVariablePointersObjectWriteNode extends Node { - public abstract void execute(WeakVariablePointersObject object, long index, Object value); + public abstract void execute(Node node, WeakVariablePointersObject object, long index, Object value); @Specialization(guards = {"cachedIndex == index", "object.getLayout() == cachedLayout", "cachedIndex < cachedLayout.getInstSize()"}, // assumptions = "cachedLayout.getValidAssumption()", limit = "CACHE_LIMIT") @@ -337,8 +341,7 @@ protected static final void doWriteGeneric(final WeakVariablePointersObject obje @Specialization(guards = {"cachedIndex == index", "object.getLayout() == cachedLayout", "cachedIndex >= cachedLayout.getInstSize()"}, // assumptions = "cachedLayout.getValidAssumption()", limit = "VARIABLE_PART_INDEX_CACHE_LIMIT") - protected static final void doWriteIntoVariablePartCachedIndex(final WeakVariablePointersObject object, @SuppressWarnings("unused") final long index, final Object value, - @Bind("this") final Node node, + protected static final void doWriteIntoVariablePartCachedIndex(final Node node, final WeakVariablePointersObject object, @SuppressWarnings("unused") final long index, final Object value, @Cached("index") final long cachedIndex, @Cached("object.getLayout()") final ObjectLayout cachedLayout, @Exclusive @Cached final InlinedConditionProfile primitiveProfile) { @@ -347,8 +350,7 @@ protected static final void doWriteIntoVariablePartCachedIndex(final WeakVariabl @Specialization(guards = {"object.getLayout() == cachedLayout", "index >= cachedLayout.getInstSize()"}, assumptions = "cachedLayout.getValidAssumption()", // replaces = "doWriteIntoVariablePartCachedIndex", limit = "VARIABLE_PART_LAYOUT_CACHE_LIMIT") - protected static final void doWriteIntoVariablePartCachedLayout(final WeakVariablePointersObject object, final long index, final Object value, - @Bind("this") final Node node, + protected static final void doWriteIntoVariablePartCachedLayout(final Node node, final WeakVariablePointersObject object, final long index, final Object value, @Cached("object.getLayout()") final ObjectLayout cachedLayout, @Exclusive @Cached final InlinedConditionProfile primitiveProfile) { object.putIntoVariablePart(index - cachedLayout.getInstSize(), value, primitiveProfile, node); @@ -356,8 +358,7 @@ protected static final void doWriteIntoVariablePartCachedLayout(final WeakVariab @ReportPolymorphism.Megamorphic @Specialization(guards = "index >= object.instsize()", replaces = {"doWriteIntoVariablePartCachedIndex", "doWriteIntoVariablePartCachedLayout"}) - protected static final void doWriteIntoVariablePartGeneric(final WeakVariablePointersObject object, final long index, final Object value, - @Bind("this") final Node node, + protected static final void doWriteIntoVariablePartGeneric(final Node node, final WeakVariablePointersObject object, final long index, final Object value, @Exclusive @Cached final InlinedConditionProfile primitiveProfile) { object.putIntoVariablePart(index - object.instsize(), value, primitiveProfile, node); } diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/accessing/ArrayObjectNodes.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/accessing/ArrayObjectNodes.java index 8c72254a5..60332d95c 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/accessing/ArrayObjectNodes.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/accessing/ArrayObjectNodes.java @@ -35,20 +35,16 @@ public final class ArrayObjectNodes { + @GenerateInline @GenerateUncached - @GenerateCached + @GenerateCached(false) public abstract static class ArrayObjectReadNode extends AbstractNode { - @NeverDefault - public static ArrayObjectReadNode create() { - return ArrayObjectReadNodeGen.create(); - } - public static ArrayObjectReadNode getUncached() { return ArrayObjectReadNodeGen.getUncached(); } - public abstract Object execute(ArrayObject obj, long index); + public abstract Object execute(Node node, ArrayObject obj, long index); @SuppressWarnings("unused") @Specialization(guards = {"obj.isEmptyType()"}) @@ -58,8 +54,7 @@ protected static final NilObject doEmptyArray(final ArrayObject obj, final long } @Specialization(guards = "obj.isBooleanType()") - protected static final Object doArrayOfBooleans(final ArrayObject obj, final long index, - @Bind("this") final Node node, + protected static final Object doArrayOfBooleans(final Node node, final ArrayObject obj, final long index, @Exclusive @Cached final InlinedConditionProfile falseProfile, @Exclusive @Cached final InlinedConditionProfile trueProfile) { final byte value = obj.getByte(index); @@ -74,24 +69,21 @@ protected static final Object doArrayOfBooleans(final ArrayObject obj, final lon } @Specialization(guards = "obj.isCharType()") - protected static final Object doArrayOfChars(final ArrayObject obj, final long index, - @Bind("this") final Node node, + protected static final Object doArrayOfChars(final Node node, final ArrayObject obj, final long index, @Shared("nilProfile") @Cached final InlinedConditionProfile nilProfile) { final char value = obj.getChar(index); return nilProfile.profile(node, value == ArrayObject.CHAR_NIL_TAG) ? NilObject.SINGLETON : value; } @Specialization(guards = "obj.isLongType()") - protected static final Object doArrayOfLongs(final ArrayObject obj, final long index, - @Bind("this") final Node node, + protected static final Object doArrayOfLongs(final Node node, final ArrayObject obj, final long index, @Shared("nilProfile") @Cached final InlinedConditionProfile nilProfile) { final long value = obj.getLong(index); return nilProfile.profile(node, value == ArrayObject.LONG_NIL_TAG) ? NilObject.SINGLETON : value; } @Specialization(guards = "obj.isDoubleType()") - protected static final Object doArrayOfDoubles(final ArrayObject obj, final long index, - @Bind("this") final Node node, + protected static final Object doArrayOfDoubles(final Node node, final ArrayObject obj, final long index, @Shared("nilProfile") @Cached final InlinedConditionProfile nilProfile) { final double value = obj.getDouble(index); return nilProfile.profile(node, Double.doubleToRawLongBits(value) == ArrayObject.DOUBLE_NIL_TAG_LONG) ? NilObject.SINGLETON : value; @@ -141,19 +133,16 @@ protected static final ArrayObject doArrayOfObjects(final ArrayObject obj) { } } + @GenerateInline @GenerateUncached + @GenerateCached(false) public abstract static class ArrayObjectSizeNode extends AbstractNode { - @NeverDefault - public static ArrayObjectSizeNode create() { - return ArrayObjectSizeNodeGen.create(); - } - public static ArrayObjectSizeNode getUncached() { return ArrayObjectSizeNodeGen.getUncached(); } - public abstract int execute(ArrayObject obj); + public abstract int execute(Node node, ArrayObject obj); @Specialization(guards = "obj.isEmptyType()") protected static final int doEmptyArrayObject(final ArrayObject obj) { @@ -186,19 +175,16 @@ protected static final int doArrayObjectOfObjects(final ArrayObject obj) { } } + @GenerateInline @GenerateUncached + @GenerateCached(false) public abstract static class ArrayObjectToObjectArrayCopyNode extends AbstractNode { - @NeverDefault - public static ArrayObjectToObjectArrayCopyNode create() { - return ArrayObjectToObjectArrayCopyNodeGen.create(); - } - public static ArrayObjectToObjectArrayCopyNode getUncached() { return ArrayObjectToObjectArrayCopyNodeGen.getUncached(); } - public abstract Object[] execute(ArrayObject obj); + public abstract Object[] execute(Node node, ArrayObject obj); @Specialization(guards = "obj.isObjectType()") protected static final Object[] doArrayOfObjects(final ArrayObject obj) { @@ -211,8 +197,7 @@ protected static final Object[] doEmptyArray(final ArrayObject obj) { } @Specialization(guards = "obj.isBooleanType()") - protected static final Object[] doArrayOfBooleans(final ArrayObject obj, - @Bind("this") final Node node, + protected static final Object[] doArrayOfBooleans(final Node node, final ArrayObject obj, @Cached final InlinedBranchProfile isNilTagProfile) { final byte[] booleans = obj.getBooleanStorage(); final int length = booleans.length; @@ -224,8 +209,7 @@ protected static final Object[] doArrayOfBooleans(final ArrayObject obj, } @Specialization(guards = "obj.isCharType()") - protected static final Object[] doArrayOfChars(final ArrayObject obj, - @Bind("this") final Node node, + protected static final Object[] doArrayOfChars(final Node node, final ArrayObject obj, @Shared("isNilTagProfile") @Cached final InlinedConditionProfile isNilTagProfile) { final char[] chars = obj.getCharStorage(); final int length = chars.length; @@ -238,8 +222,7 @@ protected static final Object[] doArrayOfChars(final ArrayObject obj, } @Specialization(guards = "obj.isLongType()") - protected static final Object[] doArrayOfLongs(final ArrayObject obj, - @Bind("this") final Node node, + protected static final Object[] doArrayOfLongs(final Node node, final ArrayObject obj, @Shared("isNilTagProfile") @Cached final InlinedConditionProfile isNilTagProfile) { final long[] longs = obj.getLongStorage(); final int length = longs.length; @@ -251,8 +234,7 @@ protected static final Object[] doArrayOfLongs(final ArrayObject obj, } @Specialization(guards = "obj.isDoubleType()") - protected static final Object[] doArrayOfDoubles(final ArrayObject obj, - @Bind("this") final Node node, + protected static final Object[] doArrayOfDoubles(final Node node, final ArrayObject obj, @Shared("isNilTagProfile") @Cached final InlinedConditionProfile isNilTagProfile) { final double[] doubles = obj.getDoubleStorage(); final int length = doubles.length; @@ -264,19 +246,16 @@ protected static final Object[] doArrayOfDoubles(final ArrayObject obj, } } + @GenerateInline @GenerateUncached + @GenerateCached(false) public abstract static class ArrayObjectToObjectArrayWithFirstNode extends AbstractNode { - @NeverDefault - public static ArrayObjectToObjectArrayWithFirstNode create() { - return ArrayObjectToObjectArrayWithFirstNodeGen.create(); - } - public static ArrayObjectToObjectArrayWithFirstNode getUncached() { return ArrayObjectToObjectArrayWithFirstNodeGen.getUncached(); } - public abstract Object[] execute(Object first, ArrayObject obj); + public abstract Object[] execute(Node node, Object first, ArrayObject obj); @Specialization(guards = "obj.isObjectType()") protected static final Object[] doArrayOfObjects(final Object first, final ArrayObject obj) { @@ -294,8 +273,7 @@ protected static final Object[] doEmptyArray(final Object first, final ArrayObje } @Specialization(guards = "obj.isBooleanType()") - protected static final Object[] doArrayOfBooleans(final Object first, final ArrayObject obj, - @Bind("this") final Node node, + protected static final Object[] doArrayOfBooleans(final Node node, final Object first, final ArrayObject obj, @Cached final InlinedBranchProfile isNilTagProfile) { final byte[] booleans = obj.getBooleanStorage(); final int length = booleans.length; @@ -308,8 +286,7 @@ protected static final Object[] doArrayOfBooleans(final Object first, final Arra } @Specialization(guards = "obj.isCharType()") - protected static final Object[] doArrayOfChars(final Object first, final ArrayObject obj, - @Bind("this") final Node node, + protected static final Object[] doArrayOfChars(final Node node, final Object first, final ArrayObject obj, @Shared("isNilTagProfile") @Cached final InlinedConditionProfile isNilTagProfile) { final char[] chars = obj.getCharStorage(); final int length = chars.length; @@ -323,8 +300,7 @@ protected static final Object[] doArrayOfChars(final Object first, final ArrayOb } @Specialization(guards = "obj.isLongType()") - protected static final Object[] doArrayOfLongs(final Object first, final ArrayObject obj, - @Bind("this") final Node node, + protected static final Object[] doArrayOfLongs(final Node node, final Object first, final ArrayObject obj, @Shared("isNilTagProfile") @Cached final InlinedConditionProfile isNilTagProfile) { final long[] longs = obj.getLongStorage(); final int length = longs.length; @@ -337,8 +313,7 @@ protected static final Object[] doArrayOfLongs(final Object first, final ArrayOb } @Specialization(guards = "obj.isDoubleType()") - protected static final Object[] doArrayOfDoubles(final Object first, final ArrayObject obj, - @Bind("this") final Node node, + protected static final Object[] doArrayOfDoubles(final Node node, final Object first, final ArrayObject obj, @Shared("isNilTagProfile") @Cached final InlinedConditionProfile isNilTagProfile) { final double[] doubles = obj.getDoubleStorage(); final int length = doubles.length; @@ -421,6 +396,7 @@ protected final void doArrayOfDoubles(final Object[] target, final ArrayObject o } } + @GenerateInline @GenerateUncached @ImportStatic(ArrayObject.class) public abstract static class ArrayObjectWriteNode extends AbstractNode { @@ -430,7 +406,7 @@ public static ArrayObjectWriteNode create() { return ArrayObjectWriteNodeGen.create(); } - public abstract void execute(ArrayObject obj, long index, Object value); + public abstract void execute(Node node, ArrayObject obj, long index, Object value); @Specialization(guards = {"obj.isEmptyType()"}) protected static final void doEmptyArray(final ArrayObject obj, final long index, @SuppressWarnings("unused") final NilObject value) { @@ -445,8 +421,7 @@ protected static final void doEmptyArrayToBoolean(final ArrayObject obj, final l } @Specialization(guards = {"obj.isEmptyType()"}) - protected static final void doEmptyArrayToChar(final ArrayObject obj, final long index, final char value, - @Bind("this") final Node node, + protected static final void doEmptyArrayToChar(final Node node, final ArrayObject obj, final long index, final char value, @Shared("nilTagProfile") @Cached final InlinedBranchProfile nilTagProfile) { if (ArrayObject.isCharNilTag(value)) { nilTagProfile.enter(node); @@ -458,8 +433,7 @@ protected static final void doEmptyArrayToChar(final ArrayObject obj, final long } @Specialization(guards = {"obj.isEmptyType()"}) - protected static final void doEmptyArrayToLong(final ArrayObject obj, final long index, final long value, - @Bind("this") final Node node, + protected static final void doEmptyArrayToLong(final Node node, final ArrayObject obj, final long index, final long value, @Shared("nilTagProfile") @Cached final InlinedBranchProfile nilTagProfile) { if (ArrayObject.isLongNilTag(value)) { nilTagProfile.enter(node); @@ -471,8 +445,7 @@ protected static final void doEmptyArrayToLong(final ArrayObject obj, final long } @Specialization(guards = {"obj.isEmptyType()"}) - protected static final void doEmptyArrayToDouble(final ArrayObject obj, final long index, final double value, - @Bind("this") final Node node, + protected static final void doEmptyArrayToDouble(final Node node, final ArrayObject obj, final long index, final double value, @Shared("isNilTagBranchProfile") @Cached final InlinedBranchProfile isNilTagBranchProfile) { if (ArrayObject.isDoubleNilTag(value)) { isNilTagBranchProfile.enter(node); @@ -501,8 +474,7 @@ protected static final void doArrayOfBooleansNil(final ArrayObject obj, final lo } @Specialization(guards = {"obj.isBooleanType()"}, replaces = {"doArrayOfBooleans", "doArrayOfBooleansNil"}) - protected static final void doArrayOfBooleansGeneric(final ArrayObject obj, final long index, final Object value, - @Bind("this") final Node node, + protected static final void doArrayOfBooleansGeneric(final Node node, final ArrayObject obj, final long index, final Object value, @Shared("isNilTagBranchProfile") @Cached final InlinedBranchProfile isNilTagBranchProfile) { obj.transitionFromBooleansToObjects(isNilTagBranchProfile, node); doArrayOfObjects(obj, index, value); @@ -514,8 +486,7 @@ protected static final void doArrayOfChars(final ArrayObject obj, final long ind } @Specialization(guards = {"obj.isCharType()", "isCharNilTag(value)"}) - protected static final void doArrayOfCharsNilTagClash(final ArrayObject obj, final long index, final char value, - @Bind("this") final Node node, + protected static final void doArrayOfCharsNilTagClash(final Node node, final ArrayObject obj, final long index, final char value, @Shared("isNilTagProfile") @Cached final InlinedConditionProfile isNilTagProfile) { /** `value` happens to be char nil tag, need to despecialize to be able store it. */ obj.transitionFromCharsToObjects(isNilTagProfile, node); @@ -528,8 +499,7 @@ protected static final void doArrayOfCharsNil(final ArrayObject obj, final long } @Specialization(guards = {"obj.isCharType()"}, replaces = {"doArrayOfChars", "doArrayOfCharsNilTagClash", "doArrayOfCharsNil"}) - protected static final void doArrayOfCharsGeneric(final ArrayObject obj, final long index, final Object value, - @Bind("this") final Node node, + protected static final void doArrayOfCharsGeneric(final Node node, final ArrayObject obj, final long index, final Object value, @Shared("isNilTagProfile") @Cached final InlinedConditionProfile isNilTagProfile) { obj.transitionFromCharsToObjects(isNilTagProfile, node); doArrayOfObjects(obj, index, value); @@ -541,8 +511,7 @@ protected static final void doArrayOfLongs(final ArrayObject obj, final long ind } @Specialization(guards = {"obj.isLongType()", "isLongNilTag(value)"}) - protected static final void doArrayOfLongsNilTagClash(final ArrayObject obj, final long index, final long value, - @Bind("this") final Node node, + protected static final void doArrayOfLongsNilTagClash(final Node node, final ArrayObject obj, final long index, final long value, @Shared("isNilTagProfile") @Cached final InlinedConditionProfile isNilTagProfile) { /** `value` happens to be long nil tag, need to despecialize to be able store it. */ obj.transitionFromLongsToObjects(isNilTagProfile, node); @@ -555,8 +524,7 @@ protected static final void doArrayOfLongsNil(final ArrayObject obj, final long } @Specialization(guards = {"obj.isLongType()"}, replaces = {"doArrayOfLongs", "doArrayOfLongsNilTagClash", "doArrayOfLongsNil"}) - protected static final void doArrayOfLongsGeneric(final ArrayObject obj, final long index, final Object value, - @Bind("this") final Node node, + protected static final void doArrayOfLongsGeneric(final Node node, final ArrayObject obj, final long index, final Object value, @Shared("isNilTagProfile") @Cached final InlinedConditionProfile isNilTagProfile) { obj.transitionFromLongsToObjects(isNilTagProfile, node); doArrayOfObjects(obj, index, value); @@ -568,8 +536,7 @@ protected static final void doArrayOfDoubles(final ArrayObject obj, final long i } @Specialization(guards = {"obj.isDoubleType()", "isDoubleNilTag(value)"}) - protected static final void doArrayOfDoublesNilTagClash(final ArrayObject obj, final long index, final double value, - @Bind("this") final Node node, + protected static final void doArrayOfDoublesNilTagClash(final Node node, final ArrayObject obj, final long index, final double value, @Shared("isNilTagProfile") @Cached final InlinedConditionProfile isNilTagProfile) { // `value` happens to be double nil tag, need to despecialize to be able store it. obj.transitionFromDoublesToObjects(isNilTagProfile, node); @@ -582,8 +549,7 @@ protected static final void doArrayOfDoublesNil(final ArrayObject obj, final lon } @Specialization(guards = {"obj.isDoubleType()"}, replaces = {"doArrayOfDoubles", "doArrayOfDoublesNilTagClash", "doArrayOfDoublesNil"}) - protected static final void doArrayOfDoublesGeneric(final ArrayObject obj, final long index, final Object value, - @Bind("this") final Node node, + protected static final void doArrayOfDoublesGeneric(final Node node, final ArrayObject obj, final long index, final Object value, @Shared("isNilTagProfile") @Cached final InlinedConditionProfile isNilTagProfile) { obj.transitionFromDoublesToObjects(isNilTagProfile, node); doArrayOfObjects(obj, index, value); diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/accessing/SqueakObjectAt0Node.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/accessing/SqueakObjectAt0Node.java index 5ca934aac..1a04c561f 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/accessing/SqueakObjectAt0Node.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/accessing/SqueakObjectAt0Node.java @@ -51,8 +51,9 @@ public static SqueakObjectAt0Node getUncached() { @Specialization protected static final Object doArray(final ArrayObject obj, final long index, + @Bind("this") final Node node, @Cached final ArrayObjectReadNode readNode) { - return readNode.execute(obj, index); + return readNode.execute(node, obj, index); } @Specialization @@ -63,8 +64,9 @@ protected static final Object doPointers(final PointersObject obj, final long in @Specialization protected static final Object doVariablePointers(final VariablePointersObject obj, final long index, + @Bind("this") final Node node, @Cached final VariablePointersObjectReadNode readNode) { - return readNode.execute(obj, index); + return readNode.execute(node, obj, index); } @Specialization @@ -76,8 +78,9 @@ protected static final Object doClass(final ClassObject obj, final long index, @Specialization protected static final Object doWeakPointersVariable(final WeakVariablePointersObject obj, final long index, + @Bind("this") final Node node, @Cached final WeakVariablePointersObjectReadNode readNode) { - return readNode.execute(obj, index); + return readNode.execute(node, obj, index); } @Specialization diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/accessing/SqueakObjectAtPut0Node.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/accessing/SqueakObjectAtPut0Node.java index 9b15e49ac..bb01d59f6 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/accessing/SqueakObjectAtPut0Node.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/accessing/SqueakObjectAtPut0Node.java @@ -54,8 +54,9 @@ protected static final void doNative(final NativeObject obj, final long index, f @Specialization protected static final void doArray(final ArrayObject obj, final long index, final Object value, + @Bind("this") final Node node, @Cached final ArrayObjectWriteNode writeNode) { - writeNode.execute(obj, index, value); + writeNode.execute(node, obj, index, value); } @Specialization @@ -66,8 +67,9 @@ protected static final void doPointers(final PointersObject obj, final long inde @Specialization protected static final void doVariablePointers(final VariablePointersObject obj, final long index, final Object value, + @Bind("this") final Node node, @Cached final VariablePointersObjectWriteNode writeNode) { - writeNode.execute(obj, (int) index, value); + writeNode.execute(node, obj, (int) index, value); } @Specialization @@ -77,8 +79,9 @@ protected final void doLargeInteger(final LargeIntegerObject receiver, final lon @Specialization protected static final void doWeakPointers(final WeakVariablePointersObject obj, final long index, final Object value, + @Bind("this") final Node node, @Cached final WeakVariablePointersObjectWriteNode writeNode) { - writeNode.execute(obj, (int) index, value); + writeNode.execute(node, obj, (int) index, value); } @Specialization diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/accessing/SqueakObjectSizeNode.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/accessing/SqueakObjectSizeNode.java index 31411df6b..130aa8934 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/accessing/SqueakObjectSizeNode.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/accessing/SqueakObjectSizeNode.java @@ -53,8 +53,8 @@ protected static final int doNil(final NilObject obj) { } @Specialization - protected static final int doArray(final ArrayObject obj, @Cached final ArrayObjectSizeNode sizeNode) { - return sizeNode.execute(obj); + protected static final int doArray(final Node node, final ArrayObject obj, @Cached final ArrayObjectSizeNode sizeNode) { + return sizeNode.execute(node, obj); } @Specialization diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/context/frame/FrameStackReadNode.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/context/frame/FrameStackReadNode.java index db2bd160e..f59ad8a73 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/context/frame/FrameStackReadNode.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/context/frame/FrameStackReadNode.java @@ -21,8 +21,7 @@ import de.hpi.swa.trufflesqueak.model.BlockClosureObject; import de.hpi.swa.trufflesqueak.nodes.AbstractNode; -import de.hpi.swa.trufflesqueak.nodes.context.frame.FrameStackReadNodeFactory.FrameSlotReadClearNodeGen; -import de.hpi.swa.trufflesqueak.nodes.context.frame.FrameStackReadNodeFactory.FrameSlotReadNoClearNodeGen; +import de.hpi.swa.trufflesqueak.nodes.context.frame.FrameStackReadNodeFactory.FrameSlotReadNodeGen; import de.hpi.swa.trufflesqueak.util.FrameAccess; @ImportStatic(FrameSlotKind.class) @@ -33,7 +32,6 @@ public static final FrameStackReadNode create(final Frame frame, final int index if (index < numArgs) { return FrameArgumentReadNode.getOrCreate(index); } - // Only clear stack values, not receiver, arguments, or temporary variables. final int initialSP; if (!FrameAccess.hasClosure(frame)) { initialSP = FrameAccess.getCodeObject(frame).getNumTemps(); @@ -46,18 +44,12 @@ public static final FrameStackReadNode create(final Frame frame, final int index assert initialSP >= numArgs; final int stackSlotIndex = FrameAccess.toStackSlotIndex(frame, index); final int numberOfSlots = frame.getFrameDescriptor().getNumberOfSlots(); - if (clear && index >= initialSP) { // only ever clear non-temp slots - if (stackSlotIndex < numberOfSlots) { - return FrameSlotReadClearNodeGen.create(stackSlotIndex); - } else { - return new FrameAuxiliarySlotReadClearNode(frame, stackSlotIndex); - } + // Only clear stack values, not receiver, arguments, or temporary variables. + final boolean shouldClear = clear && index >= initialSP; + if (stackSlotIndex < numberOfSlots) { + return FrameSlotReadNodeGen.create(stackSlotIndex, shouldClear); } else { - if (stackSlotIndex < numberOfSlots) { - return FrameSlotReadNoClearNodeGen.create(stackSlotIndex); - } else { - return new FrameAuxiliarySlotReadNoClearNode(frame, stackSlotIndex); - } + return new FrameAuxiliarySlotReadNode(frame, stackSlotIndex, shouldClear); } } @@ -69,9 +61,9 @@ public static final FrameStackReadNode createTemporaryReadNode(final Frame frame final int stackSlotIndex = FrameAccess.toStackSlotIndex(frame, index); final int numberOfSlots = frame.getFrameDescriptor().getNumberOfSlots(); if (stackSlotIndex < numberOfSlots) { - return FrameSlotReadNoClearNodeGen.create(stackSlotIndex); + return FrameSlotReadNodeGen.create(stackSlotIndex, false); } else { - return new FrameAuxiliarySlotReadNoClearNode(frame, stackSlotIndex); + return new FrameAuxiliarySlotReadNode(frame, stackSlotIndex, false); } } } @@ -85,11 +77,14 @@ public final Object executeRead(final Frame frame) { /* Unsafe as it may return `null` values. */ public abstract Object executeReadUnsafe(Frame frame); - protected abstract static class AbstractFrameSlotReadNode extends FrameStackReadNode { - protected final int slotIndex; + protected abstract static class FrameSlotReadNode extends FrameStackReadNode { + protected final byte slotIndex; + protected final boolean clearSlotAfterRead; - AbstractFrameSlotReadNode(final int slotIndex) { - this.slotIndex = slotIndex; + FrameSlotReadNode(final int slotIndex, final boolean clearSlotAfterRead) { + this.slotIndex = (byte) slotIndex; + assert this.slotIndex == slotIndex; + this.clearSlotAfterRead = clearSlotAfterRead; } @Specialization(guards = "frame.isBoolean(slotIndex)") @@ -106,43 +101,9 @@ protected final long readLong(final Frame frame) { protected final double readDouble(final Frame frame) { return frame.getDouble(slotIndex); } - } - - protected abstract static class FrameSlotReadNoClearNode extends AbstractFrameSlotReadNode { - - FrameSlotReadNoClearNode(final int slotIndex) { - super(slotIndex); - } @Specialization(replaces = {"readBoolean", "readLong", "readDouble"}) protected final Object readObject(final Frame frame) { - if (!frame.isObject(slotIndex)) { - /* - * The FrameSlotKind has been set to Object, so from now on all writes to the slot - * will be Object writes. However, now we are in a frame that still has an old - * non-Object value. This is a slow-path operation: we read the non-Object value, - * and write it immediately as an Object value so that we do not hit this path again - * multiple times for the same slot of the same frame. - */ - CompilerDirectives.transferToInterpreter(); - final Object value = frame.getValue(slotIndex); - assert value != null : "Unexpected `null` value"; - frame.setObject(slotIndex, value); - return value; - } else { - return frame.getObject(slotIndex); - } - } - } - - protected abstract static class FrameSlotReadClearNode extends AbstractFrameSlotReadNode { - - FrameSlotReadClearNode(final int slotIndex) { - super(slotIndex); - } - - @Specialization(replaces = {"readBoolean", "readLong", "readDouble"}) - protected final Object readAndClearObject(final Frame frame) { final Object value; if (!frame.isObject(slotIndex)) { /* @@ -157,7 +118,9 @@ protected final Object readAndClearObject(final Frame frame) { } else { value = frame.getObject(slotIndex); } - frame.setObject(slotIndex, null); + if (clearSlotAfterRead) { + frame.setObject(slotIndex, null); + } return value; } } @@ -203,30 +166,21 @@ public Node deepCopy() { } } - private static class FrameAuxiliarySlotReadNoClearNode extends FrameStackReadNode { - private final int auxiliarySlotIndex; + private static class FrameAuxiliarySlotReadNode extends FrameStackReadNode { + private final short auxiliarySlotIndex; + private final boolean clearSlotAfterRead; - FrameAuxiliarySlotReadNoClearNode(final Frame frame, final int slotIndex) { - auxiliarySlotIndex = frame.getFrameDescriptor().findOrAddAuxiliarySlot(slotIndex); - } - - @Override - public Object executeReadUnsafe(final Frame frame) { - return frame.getAuxiliarySlot(auxiliarySlotIndex); - } - } - - private static class FrameAuxiliarySlotReadClearNode extends FrameStackReadNode { - private final int auxiliarySlotIndex; - - FrameAuxiliarySlotReadClearNode(final Frame frame, final int slotIndex) { - auxiliarySlotIndex = frame.getFrameDescriptor().findOrAddAuxiliarySlot(slotIndex); + FrameAuxiliarySlotReadNode(final Frame frame, final int slotIndex, final boolean clearSlotAfterRead) { + auxiliarySlotIndex = (short) frame.getFrameDescriptor().findOrAddAuxiliarySlot(slotIndex); + this.clearSlotAfterRead = clearSlotAfterRead; } @Override public Object executeReadUnsafe(final Frame frame) { final Object value = frame.getAuxiliarySlot(auxiliarySlotIndex); - frame.setAuxiliarySlot(auxiliarySlotIndex, null); + if (clearSlotAfterRead) { + frame.setAuxiliarySlot(auxiliarySlotIndex, null); + } return value; } } diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/BitBltPlugin.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/BitBltPlugin.java index 3144df328..e9642dfed 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/BitBltPlugin.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/BitBltPlugin.java @@ -91,7 +91,7 @@ protected final PointersObject doDisplayString(final PointersObject receiver, fi private static void respecializeArrayToLongOrPrimFail(final ArrayObject array) { CompilerAsserts.neverPartOfCompilation(); - final Object[] values = ArrayObjectToObjectArrayCopyNode.getUncached().execute(array); + final Object[] values = ArrayObjectToObjectArrayCopyNode.getUncached().execute(null, array); final long[] longs = new long[values.length]; try { for (int i = 0; i < values.length; i++) { diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/NullPlugin.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/NullPlugin.java index e4a5a5273..8a461e547 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/NullPlugin.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/NullPlugin.java @@ -11,11 +11,13 @@ import java.util.List; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; +import com.oracle.truffle.api.dsl.Bind; import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.GenerateNodeFactory; import com.oracle.truffle.api.dsl.NodeFactory; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.nodes.DenyReplace; +import com.oracle.truffle.api.nodes.Node; import de.hpi.swa.trufflesqueak.image.SqueakImageConstants; import de.hpi.swa.trufflesqueak.model.ArrayObject; @@ -90,12 +92,13 @@ protected static final PointersObject doUTC(@SuppressWarnings("unused") final Ob return objectWithTwoSlots; } - @Specialization(guards = "sizeNode.execute(arrayWithTwoSlots) == 2", limit = "1") + @Specialization(guards = "sizeNode.execute(node, arrayWithTwoSlots) == 2", limit = "1") protected static final ArrayObject doUTC(@SuppressWarnings("unused") final Object receiver, final ArrayObject arrayWithTwoSlots, + @Bind("this") final Node node, @SuppressWarnings("unused") @Cached final ArrayObjectSizeNode sizeNode, - @Cached final ArrayObjectWriteNode writeNode) { - writeNode.execute(arrayWithTwoSlots, 0, getUTCMicroseconds()); - writeNode.execute(arrayWithTwoSlots, 1, getOffsetFromGTMInSeconds()); + @Cached(inline = true) final ArrayObjectWriteNode writeNode) { + writeNode.execute(node, arrayWithTwoSlots, 0, getUTCMicroseconds()); + writeNode.execute(node, arrayWithTwoSlots, 1, getOffsetFromGTMInSeconds()); return arrayWithTwoSlots; } } diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/PolyglotPlugin.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/PolyglotPlugin.java index 9f22a5c39..d85b165c5 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/PolyglotPlugin.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/PolyglotPlugin.java @@ -20,6 +20,7 @@ import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.TruffleContext; import com.oracle.truffle.api.TruffleLanguage; +import com.oracle.truffle.api.dsl.Bind; import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.GenerateNodeFactory; import com.oracle.truffle.api.dsl.ImportStatic; @@ -37,6 +38,7 @@ import com.oracle.truffle.api.interop.UnsupportedTypeException; import com.oracle.truffle.api.library.CachedLibrary; import com.oracle.truffle.api.nodes.LanguageInfo; +import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.nodes.NodeCost; import com.oracle.truffle.api.nodes.NodeInfo; import com.oracle.truffle.api.source.Source; @@ -117,11 +119,11 @@ protected final boolean doIsPolyglotEvalAllowed(@SuppressWarnings("unused") fina } protected abstract static class AbstractEvalStringPrimitiveNode extends AbstractPrimitiveNode { - protected static final Object evalString(final AbstractEvalStringPrimitiveNode node, final NativeObject languageIdOrMimeTypeObj, final NativeObject sourceObject) { + protected static final Object evalString(final Node node, final NativeObject languageIdOrMimeTypeObj, final NativeObject sourceObject) { return evalString(node, languageIdOrMimeTypeObj, sourceObject, ArrayUtils.EMPTY_STRINGS_ARRAY, ArrayUtils.EMPTY_ARRAY); } - protected static final Object evalString(final AbstractEvalStringPrimitiveNode node, final NativeObject languageIdOrMimeTypeObj, final NativeObject sourceObject, + protected static final Object evalString(final Node node, final NativeObject languageIdOrMimeTypeObj, final NativeObject sourceObject, final String[] argumentNames, final Object[] argumentValues) { final String languageIdOrMimeType = languageIdOrMimeTypeObj.asStringUnsafe(); final String sourceText = sourceObject.asStringUnsafe(); @@ -156,13 +158,14 @@ protected final Object doEval(@SuppressWarnings("unused") final Object receiver, @SqueakPrimitive(names = "primitiveEvalStringWithArguments") protected abstract static class PrimEvalStringWithArgumentsNode extends AbstractEvalStringPrimitiveNode implements QuinaryPrimitiveFallback { @TruffleBoundary(transferToInterpreterOnException = false) - @Specialization(guards = {"languageIdOrMimeTypeObj.isByteType()", "sourceObject.isByteType()", "sizeNode.execute(argumentNames) == sizeNode.execute(argumentValues)"}, limit = "1") - protected final Object doEvalWithArguments(@SuppressWarnings("unused") final Object receiver, final NativeObject languageIdOrMimeTypeObj, final NativeObject sourceObject, + @Specialization(guards = {"languageIdOrMimeTypeObj.isByteType()", "sourceObject.isByteType()", "sizeNode.execute(node, argumentNames) == sizeNode.execute(node, argumentValues)"}, limit = "1") + protected static final Object doEvalWithArguments(@SuppressWarnings("unused") final Object receiver, final NativeObject languageIdOrMimeTypeObj, final NativeObject sourceObject, final ArrayObject argumentNames, final ArrayObject argumentValues, + @Bind("this") final Node node, @SuppressWarnings("unused") @Cached final ArrayObjectSizeNode sizeNode, @Cached final ArrayObjectToObjectArrayCopyNode toObjectArrayNode, @Cached final WrapToSqueakNode wrapNode) { - final Object[] namesObjects = toObjectArrayNode.execute(argumentNames); + final Object[] namesObjects = toObjectArrayNode.execute(node, argumentNames); final String[] names = new String[namesObjects.length]; for (int i = 0; i < namesObjects.length; i++) { final Object name = namesObjects[i]; @@ -172,8 +175,8 @@ protected final Object doEvalWithArguments(@SuppressWarnings("unused") final Obj throw PrimitiveFailed.andTransferToInterpreter(); } } - final Object[] values = toObjectArrayNode.execute(argumentValues); - return wrapNode.executeWrap(evalString(this, languageIdOrMimeTypeObj, sourceObject, names, values)); + final Object[] values = toObjectArrayNode.execute(node, argumentValues); + return wrapNode.executeWrap(evalString(node, languageIdOrMimeTypeObj, sourceObject, names, values)); } } @@ -366,11 +369,12 @@ public final Object exportSymbol(@SuppressWarnings("unused") final Object receiv protected abstract static class PrimExecuteNode extends AbstractPrimitiveNode implements TernaryPrimitiveFallback { @Specialization(guards = {"lib.isExecutable(object)"}, limit = "2") protected static final Object doExecute(@SuppressWarnings("unused") final Object receiver, final Object object, final ArrayObject argumentArray, + @Bind("this") final Node node, @Cached final ArrayObjectToObjectArrayCopyNode getObjectArrayNode, @Cached final WrapToSqueakNode wrapNode, @CachedLibrary("object") final InteropLibrary lib) { try { - return wrapNode.executeWrap(lib.execute(object, getObjectArrayNode.execute(argumentArray))); + return wrapNode.executeWrap(lib.execute(object, getObjectArrayNode.execute(node, argumentArray))); } catch (final Exception e) { /* * Workaround: catch all exceptions raised by other languages to avoid crashes (see @@ -398,11 +402,12 @@ protected abstract static class PrimInstantiateNode extends AbstractPrimitiveNod @Specialization protected static final Object doIsInstantiable(@SuppressWarnings("unused") final Object receiver, final Object object, final ArrayObject argumentArray, + @Bind("this") final Node node, @Cached final ArrayObjectToObjectArrayCopyNode getObjectArrayNode, @Cached final WrapToSqueakNode wrapNode, @CachedLibrary(limit = "2") final InteropLibrary lib) { try { - return wrapNode.executeWrap(lib.instantiate(object, getObjectArrayNode.execute(argumentArray))); + return wrapNode.executeWrap(lib.instantiate(object, getObjectArrayNode.execute(node, argumentArray))); } catch (final Exception e) { /* * Workaround: catch all exceptions raised by other languages to avoid crashes (see @@ -1085,11 +1090,12 @@ protected static final boolean doIsMemberWritable(@SuppressWarnings("unused") fi protected abstract static class PrimInvokeMemberNode extends AbstractPrimitiveNode implements QuaternaryPrimitiveFallback { @Specialization(guards = {"member.isByteType()", "lib.isMemberInvocable(object, member.asStringUnsafe())"}, limit = "2") protected static final Object doInvokeMember(@SuppressWarnings("unused") final Object receiver, final Object object, final NativeObject member, final ArrayObject argumentArray, + @Bind("this") final Node node, @Cached final ArrayObjectToObjectArrayCopyNode getObjectArrayNode, @Cached final WrapToSqueakNode wrapNode, @CachedLibrary("object") final InteropLibrary lib) { try { - return wrapNode.executeWrap(lib.invokeMember(object, member.asStringUnsafe(), getObjectArrayNode.execute(argumentArray))); + return wrapNode.executeWrap(lib.invokeMember(object, member.asStringUnsafe(), getObjectArrayNode.execute(node, argumentArray))); } catch (final Exception e) { /* * Workaround: catch all exceptions raised by other languages to avoid crashes (see diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/SqueakFFIPrims.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/SqueakFFIPrims.java index ea6aac258..3a096fd45 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/SqueakFFIPrims.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/SqueakFFIPrims.java @@ -267,13 +267,12 @@ private static String generateNfiCodeParamsString(final List argumentLis @GenerateNodeFactory @SqueakPrimitive(names = "primitiveCalloutWithArgs") protected abstract static class PrimCalloutWithArgsNode extends AbstractFFIPrimitiveNode implements BinaryPrimitiveFallback { - @Child private ArrayObjectToObjectArrayCopyNode getObjectArrayNode = ArrayObjectToObjectArrayCopyNode.create(); - @Specialization protected final Object doCalloutWithArgs(final PointersObject receiver, final ArrayObject argArray, @Bind("this") final Node node, + @Cached final ArrayObjectToObjectArrayCopyNode getObjectArrayNode, @Cached final ArgTypeConversionNode conversionNode) { - return doCallout(conversionNode, node, asExternalFunctionOrFail(receiver), receiver, getObjectArrayNode.execute(argArray)); + return doCallout(conversionNode, node, asExternalFunctionOrFail(receiver), receiver, getObjectArrayNode.execute(node, argArray)); } } diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/ControlPrimitives.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/ControlPrimitives.java index 5892c29e0..347106d68 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/ControlPrimitives.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/ControlPrimitives.java @@ -318,28 +318,30 @@ protected static final Object perform5(final VirtualFrame frame, final Object re @GenerateNodeFactory @SqueakPrimitive(indices = 84) protected abstract static class PrimPerformWithArgumentsNode extends AbstractPerformPrimitiveNode implements TernaryPrimitiveFallback { - @Child private ArrayObjectToObjectArrayWithFirstNode getObjectArrayNode = ArrayObjectToObjectArrayWithFirstNode.create(); - @Specialization(guards = "selector == cachedSelector", limit = "CACHE_LIMIT") - protected final Object performCached(final VirtualFrame frame, final Object receiver, @SuppressWarnings("unused") final NativeObject selector, final ArrayObject arguments, + protected static final Object performCached(final VirtualFrame frame, final Object receiver, @SuppressWarnings("unused") final NativeObject selector, final ArrayObject arguments, + @Bind("this") final Node node, @Cached("selector") final NativeObject cachedSelector, + @Exclusive @Cached final ArrayObjectToObjectArrayWithFirstNode getObjectArrayNode, @Exclusive @Cached final SqueakObjectClassNode lookupClassNode, @Exclusive @Cached final LookupMethodNode lookupMethodNode, @Cached("createDispatchSendNode(cachedSelector)") final DispatchSendNode dispatchNode) { final ClassObject rcvrClass = lookupClassNode.executeLookup(receiver); final Object lookupResult = lookupMethodNode.executeLookup(rcvrClass, cachedSelector); - return dispatchNode.executeSend(frame, cachedSelector, lookupResult, rcvrClass, getObjectArrayNode.execute(receiver, arguments)); + return dispatchNode.executeSend(frame, cachedSelector, lookupResult, rcvrClass, getObjectArrayNode.execute(node, receiver, arguments)); } @ReportPolymorphism.Megamorphic @Specialization(replaces = "performCached") - protected final Object perform(final VirtualFrame frame, final Object receiver, final NativeObject selector, final ArrayObject arguments, + protected static final Object perform(final VirtualFrame frame, final Object receiver, final NativeObject selector, final ArrayObject arguments, + @Bind("this") final Node node, + @Exclusive @Cached final ArrayObjectToObjectArrayWithFirstNode getObjectArrayNode, @Exclusive @Cached final SqueakObjectClassNode lookupClassNode, @Exclusive @Cached final LookupMethodNode lookupMethodNode, @Cached final DispatchSendSelectorNode dispatchNode) { final ClassObject rcvrClass = lookupClassNode.executeLookup(receiver); final Object lookupResult = lookupMethodNode.executeLookup(rcvrClass, selector); - return dispatchNode.executeSend(frame, selector, lookupResult, rcvrClass, getObjectArrayNode.execute(receiver, arguments)); + return dispatchNode.executeSend(frame, selector, lookupResult, rcvrClass, getObjectArrayNode.execute(node, receiver, arguments)); } } @@ -524,25 +526,24 @@ protected final Object doFlush(final Object receiver) { } protected abstract static class AbstractPrimPerformWithArgumentsInSuperclassNode extends AbstractPerformPrimitiveNode { - @Child private ArrayObjectToObjectArrayWithFirstNode getObjectArrayNode = ArrayObjectToObjectArrayWithFirstNode.create(); - @Child private InheritsFromNode inheritsFromNode = InheritsFromNode.create(); - - protected final Object performCached(final VirtualFrame frame, final Object receiver, final ArrayObject arguments, final ClassObject superClass, final NativeObject cachedSelector, - final LookupMethodNode lookupMethodNode, final DispatchSendNode dispatchNode) { - if (inheritsFromNode.execute(receiver, superClass)) { + protected static final Object performCached(final VirtualFrame frame, final Object receiver, final ArrayObject arguments, final ClassObject superClass, final NativeObject cachedSelector, + final InheritsFromNode inheritsFromNode, final LookupMethodNode lookupMethodNode, final DispatchSendNode dispatchNode, + final ArrayObjectToObjectArrayWithFirstNode getObjectArrayNode, final Node inlineTarget) { + if (inheritsFromNode.execute(inlineTarget, receiver, superClass)) { final Object lookupResult = lookupMethodNode.executeLookup(superClass, cachedSelector); - return dispatchNode.executeSend(frame, cachedSelector, lookupResult, superClass, getObjectArrayNode.execute(receiver, arguments)); + return dispatchNode.executeSend(frame, cachedSelector, lookupResult, superClass, getObjectArrayNode.execute(inlineTarget, receiver, arguments)); } else { CompilerDirectives.transferToInterpreter(); throw PrimitiveFailed.BAD_RECEIVER; } } - protected final Object performGeneric(final VirtualFrame frame, final Object receiver, final NativeObject selector, final ArrayObject arguments, final ClassObject superClass, - final LookupMethodNode lookupMethodNode, final DispatchSendSelectorNode dispatchNode) { - if (inheritsFromNode.execute(receiver, superClass)) { + protected static final Object performGeneric(final VirtualFrame frame, final Object receiver, final NativeObject selector, final ArrayObject arguments, final ClassObject superClass, + final InheritsFromNode inheritsFromNode, final LookupMethodNode lookupMethodNode, final DispatchSendSelectorNode dispatchNode, + final ArrayObjectToObjectArrayWithFirstNode getObjectArrayNode, final Node inlineTarget) { + if (inheritsFromNode.execute(inlineTarget, receiver, superClass)) { final Object lookupResult = lookupMethodNode.executeLookup(superClass, selector); - return dispatchNode.executeSend(frame, selector, lookupResult, superClass, getObjectArrayNode.execute(receiver, arguments)); + return dispatchNode.executeSend(frame, selector, lookupResult, superClass, getObjectArrayNode.execute(inlineTarget, receiver, arguments)); } else { CompilerDirectives.transferToInterpreter(); throw PrimitiveFailed.BAD_RECEIVER; @@ -555,20 +556,26 @@ protected final Object performGeneric(final VirtualFrame frame, final Object rec /* Object>>#perform:withArguments:inSuperclass: */ protected abstract static class PrimPerformWithArgumentsInSuperclass4Node extends AbstractPrimPerformWithArgumentsInSuperclassNode implements QuaternaryPrimitiveFallback { @Specialization(guards = "selector == cachedSelector", limit = "CACHE_LIMIT") - protected final Object performCached(final VirtualFrame frame, final Object receiver, @SuppressWarnings("unused") final NativeObject selector, final ArrayObject arguments, + protected static final Object performCached(final VirtualFrame frame, final Object receiver, @SuppressWarnings("unused") final NativeObject selector, final ArrayObject arguments, final ClassObject superClass, + @Bind("this") final Node node, @Cached("selector") final NativeObject cachedSelector, + @Exclusive @Cached final InheritsFromNode inheritsFromNode, @Exclusive @Cached final LookupMethodNode lookupMethodNode, - @Cached("createDispatchSendNode(cachedSelector)") final DispatchSendNode dispatchNode) { - return performCached(frame, receiver, arguments, superClass, cachedSelector, lookupMethodNode, dispatchNode); + @Cached("createDispatchSendNode(cachedSelector)") final DispatchSendNode dispatchNode, + @Exclusive @Cached final ArrayObjectToObjectArrayWithFirstNode getObjectArrayNode) { + return performCached(frame, receiver, arguments, superClass, cachedSelector, inheritsFromNode, lookupMethodNode, dispatchNode, getObjectArrayNode, node); } @ReportPolymorphism.Megamorphic @Specialization(replaces = "performCached") - protected final Object perform(final VirtualFrame frame, final Object receiver, final NativeObject selector, final ArrayObject arguments, final ClassObject superClass, + protected static final Object perform(final VirtualFrame frame, final Object receiver, final NativeObject selector, final ArrayObject arguments, final ClassObject superClass, + @Bind("this") final Node node, + @Exclusive @Cached final InheritsFromNode inheritsFromNode, @Exclusive @Cached final LookupMethodNode lookupMethodNode, - @Cached final DispatchSendSelectorNode dispatchNode) { - return performGeneric(frame, receiver, selector, arguments, superClass, lookupMethodNode, dispatchNode); + @Cached final DispatchSendSelectorNode dispatchNode, + @Exclusive @Cached final ArrayObjectToObjectArrayWithFirstNode getObjectArrayNode) { + return performGeneric(frame, receiver, selector, arguments, superClass, inheritsFromNode, lookupMethodNode, dispatchNode, getObjectArrayNode, node); } } @@ -577,21 +584,27 @@ protected final Object perform(final VirtualFrame frame, final Object receiver, /* Context>>#object:perform:withArguments:inClass: */ protected abstract static class PrimPerformWithArgumentsInSuperclass5Node extends AbstractPrimPerformWithArgumentsInSuperclassNode implements QuinaryPrimitiveFallback { @Specialization(guards = "selector == cachedSelector", limit = "CACHE_LIMIT") - protected final Object performContextCached(final VirtualFrame frame, @SuppressWarnings("unused") final Object receiver, final Object target, + protected static final Object performContextCached(final VirtualFrame frame, @SuppressWarnings("unused") final Object receiver, final Object target, @SuppressWarnings("unused") final NativeObject selector, final ArrayObject arguments, final ClassObject superClass, + @Bind("this") final Node node, @Cached("selector") final NativeObject cachedSelector, + @Exclusive @Cached final InheritsFromNode inheritsFromNode, @Exclusive @Cached final LookupMethodNode lookupMethodNode, - @Cached("createDispatchSendNode(cachedSelector)") final DispatchSendNode dispatchNode) { - return performCached(frame, target, arguments, superClass, cachedSelector, lookupMethodNode, dispatchNode); + @Cached("createDispatchSendNode(cachedSelector)") final DispatchSendNode dispatchNode, + @Exclusive @Cached final ArrayObjectToObjectArrayWithFirstNode getObjectArrayNode) { + return performCached(frame, target, arguments, superClass, cachedSelector, inheritsFromNode, lookupMethodNode, dispatchNode, getObjectArrayNode, node); } @ReportPolymorphism.Megamorphic @Specialization(replaces = "performContextCached") - protected final Object performContext(final VirtualFrame frame, @SuppressWarnings("unused") final Object receiver, final Object target, final NativeObject selector, + protected static final Object performContext(final VirtualFrame frame, @SuppressWarnings("unused") final Object receiver, final Object target, final NativeObject selector, final ArrayObject arguments, final ClassObject superClass, + @Bind("this") final Node node, + @Exclusive @Cached final InheritsFromNode inheritsFromNode, @Exclusive @Cached final LookupMethodNode lookupMethodNode, - @Cached final DispatchSendSelectorNode dispatchNode) { - return performGeneric(frame, target, selector, arguments, superClass, lookupMethodNode, dispatchNode); + @Cached final DispatchSendSelectorNode dispatchNode, + @Exclusive @Cached final ArrayObjectToObjectArrayWithFirstNode getObjectArrayNode) { + return performGeneric(frame, target, selector, arguments, superClass, inheritsFromNode, lookupMethodNode, dispatchNode, getObjectArrayNode, node); } } @@ -724,19 +737,19 @@ protected static final AbstractPrimitiveNode createPrimitiveNode(final long prim } protected static final Object primitiveWithArgs(final VirtualFrame frame, final Object receiver, final ArrayObject argumentArray, - final AbstractPrimitiveNode primitiveNode, final ArrayObjectToObjectArrayWithFirstNode toObjectArrayNode) { - return primitiveNode.executeWithArguments(frame, toObjectArrayNode.execute(receiver, argumentArray)); + final AbstractPrimitiveNode primitiveNode, final ArrayObjectToObjectArrayWithFirstNode toObjectArrayNode, final Node inlineTarget) { + return primitiveNode.executeWithArguments(frame, toObjectArrayNode.execute(inlineTarget, receiver, argumentArray)); } protected final Object primitiveWithArgsSlow(final VirtualFrame frame, final Object receiver, final long primitiveIndex, final ArrayObject argumentArray) { /* Deopt might be acceptable because primitive is mostly used for debugging anyway. */ CompilerDirectives.transferToInterpreter(); - final int arraySize = ArrayObjectSizeNode.getUncached().execute(argumentArray); + final int arraySize = ArrayObjectSizeNode.getUncached().execute(null, argumentArray); final AbstractPrimitiveNode primitiveNode = insert(createPrimitiveNode(primitiveIndex, arraySize)); if (primitiveNode == null) { throw PrimitiveFailed.GENERIC_ERROR; } else { - final Object[] receiverAndArguments = ArrayObjectToObjectArrayWithFirstNode.getUncached().execute(receiver, argumentArray); + final Object[] receiverAndArguments = ArrayObjectToObjectArrayWithFirstNode.getUncached().execute(null, receiver, argumentArray); return primitiveNode.executeWithArguments(frame, receiverAndArguments); } } @@ -745,14 +758,15 @@ protected final Object primitiveWithArgsSlow(final VirtualFrame frame, final Obj @GenerateNodeFactory @SqueakPrimitive(indices = 118) protected abstract static class PrimDoPrimitiveWithArgs3Node extends AbstractPrimDoPrimitiveWithArgsNode implements TernaryPrimitiveFallback { - @Specialization(guards = {"primitiveIndex == cachedPrimitiveIndex", "primitiveNode != null", "sizeNode.execute(argumentArray) == cachedArraySize"}, limit = "2") + @Specialization(guards = {"primitiveIndex == cachedPrimitiveIndex", "primitiveNode != null", "sizeNode.execute(node, argumentArray) == cachedArraySize"}, limit = "2") protected static final Object doPrimitiveWithArgsCached(final VirtualFrame frame, final Object receiver, @SuppressWarnings("unused") final long primitiveIndex, final ArrayObject argumentArray, + @Bind("this") final Node node, @SuppressWarnings("unused") @Cached("primitiveIndex") final long cachedPrimitiveIndex, @SuppressWarnings("unused") @Cached final ArrayObjectSizeNode sizeNode, - @SuppressWarnings("unused") @Cached("sizeNode.execute(argumentArray)") final int cachedArraySize, + @SuppressWarnings("unused") @Cached("sizeNode.execute(node, argumentArray)") final int cachedArraySize, @Cached("createPrimitiveNode(cachedPrimitiveIndex, cachedArraySize)") final AbstractPrimitiveNode primitiveNode, @Cached final ArrayObjectToObjectArrayWithFirstNode toObjectArrayNode) { - return primitiveWithArgs(frame, receiver, argumentArray, primitiveNode, toObjectArrayNode); + return primitiveWithArgs(frame, receiver, argumentArray, primitiveNode, toObjectArrayNode, node); } @ReportPolymorphism.Megamorphic @@ -765,15 +779,16 @@ protected final Object doPrimitiveWithArgs(final VirtualFrame frame, final Objec @GenerateNodeFactory @SqueakPrimitive(indices = 118) protected abstract static class PrimDoPrimitiveWithArgs4Node extends AbstractPrimDoPrimitiveWithArgsNode implements QuaternaryPrimitiveFallback { - @Specialization(guards = {"primitiveIndex == cachedPrimitiveIndex", "primitiveNode != null", "sizeNode.execute(argumentArray) == cachedArraySize"}, limit = "2") + @Specialization(guards = {"primitiveIndex == cachedPrimitiveIndex", "primitiveNode != null", "sizeNode.execute(node, argumentArray) == cachedArraySize"}, limit = "2") protected static final Object doPrimitiveWithArgsContextCached(final VirtualFrame frame, @SuppressWarnings("unused") final Object context, final Object receiver, @SuppressWarnings("unused") final long primitiveIndex, final ArrayObject argumentArray, + @Bind("this") final Node node, @SuppressWarnings("unused") @Cached("primitiveIndex") final long cachedPrimitiveIndex, @SuppressWarnings("unused") @Cached final ArrayObjectSizeNode sizeNode, - @SuppressWarnings("unused") @Cached("sizeNode.execute(argumentArray)") final int cachedArraySize, + @SuppressWarnings("unused") @Cached("sizeNode.execute(node, argumentArray)") final int cachedArraySize, @Cached("createPrimitiveNode(cachedPrimitiveIndex, cachedArraySize)") final AbstractPrimitiveNode primitiveNode, @Cached final ArrayObjectToObjectArrayWithFirstNode toObjectArrayNode) { - return primitiveWithArgs(frame, receiver, argumentArray, primitiveNode, toObjectArrayNode); + return primitiveWithArgs(frame, receiver, argumentArray, primitiveNode, toObjectArrayNode, node); } @ReportPolymorphism.Megamorphic @@ -893,6 +908,7 @@ protected static final ClassObject doPrimAdoptInstance(final ClassObject receive protected abstract static class PrimYieldNode extends AbstractPrimitiveStackIncrementNode implements UnaryPrimitiveFallback { @Specialization protected final Object doYield(final VirtualFrame frame, final PointersObject scheduler, + @Bind("this") final Node node, @Cached final ArrayObjectReadNode arrayReadNode, @Cached final GetActiveProcessNode getActiveProcessNode, @Cached final AbstractPointersObjectReadNode pointersReadNode, @@ -901,7 +917,7 @@ protected final Object doYield(final VirtualFrame frame, final PointersObject sc final PointersObject activeProcess = getActiveProcessNode.execute(); final long priority = pointersReadNode.executeLong(activeProcess, PROCESS.PRIORITY); final ArrayObject processLists = pointersReadNode.executeArray(scheduler, PROCESS_SCHEDULER.PROCESS_LISTS); - final PointersObject processList = (PointersObject) arrayReadNode.execute(processLists, priority - 1); + final PointersObject processList = (PointersObject) arrayReadNode.execute(node, processLists, priority - 1); if (processList.isEmptyList(pointersReadNode)) { return NilObject.SINGLETON; } @@ -1082,16 +1098,13 @@ protected final boolean ownerIsActiveProcess(final PointersObject mutex) { } protected abstract static class AbstractPrimExecuteMethodArgsArrayNode extends AbstractPrimitiveNode { - @Child private ArrayObjectSizeNode sizeNode = ArrayObjectSizeNode.create(); - @Child private ArrayObjectReadNode readNode = ArrayObjectReadNode.create(); - protected final Object doExecuteMethod(final VirtualFrame frame, final Object receiver, final ArrayObject argArray, final CompiledCodeObject methodObject, - final DispatchEagerlyNode dispatchNode) { - final int numArgs = sizeNode.execute(argArray); + final ArrayObjectSizeNode sizeNode, final ArrayObjectReadNode readNode, final DispatchEagerlyNode dispatchNode, final Node inlineTarget) { + final int numArgs = sizeNode.execute(inlineTarget, argArray); final Object[] dispatchRcvrAndArgs = new Object[1 + numArgs]; dispatchRcvrAndArgs[0] = receiver; for (int i = 0; i < numArgs; i++) { - dispatchRcvrAndArgs[1 + i] = readNode.execute(argArray, i); + dispatchRcvrAndArgs[1 + i] = readNode.execute(inlineTarget, argArray, i); } return dispatchNode.executeDispatch(frame, methodObject, dispatchRcvrAndArgs); } @@ -1103,8 +1116,11 @@ protected abstract static class PrimExecuteMethodArgsArray3Node extends Abstract /** Deprecated since Kernel-eem.1204. Kept for backward compatibility. */ @Specialization protected final Object doExecute(final VirtualFrame frame, final Object receiver, final ArrayObject argArray, final CompiledCodeObject methodObject, + @Bind("this") final Node node, + @Cached final ArrayObjectSizeNode sizeNode, + @Cached final ArrayObjectReadNode readNode, @Cached final DispatchEagerlyNode dispatchNode) { - return doExecuteMethod(frame, receiver, argArray, methodObject, dispatchNode); + return doExecuteMethod(frame, receiver, argArray, methodObject, sizeNode, readNode, dispatchNode, node); } } @@ -1114,8 +1130,11 @@ protected abstract static class PrimExecuteMethodArgsArray4Node extends Abstract @Specialization protected final Object doExecute(final VirtualFrame frame, @SuppressWarnings("unused") final ClassObject compiledMethodClass, final Object receiver, final ArrayObject argArray, final CompiledCodeObject methodObject, + @Bind("this") final Node node, + @Cached final ArrayObjectSizeNode sizeNode, + @Cached final ArrayObjectReadNode readNode, @Cached final DispatchEagerlyNode dispatchNode) { - return doExecuteMethod(frame, receiver, argArray, methodObject, dispatchNode); + return doExecuteMethod(frame, receiver, argArray, methodObject, sizeNode, readNode, dispatchNode, node); } } @@ -1174,16 +1193,17 @@ protected static final Object doExecute(final VirtualFrame frame, final Object r @SqueakPrimitive(indices = 218) protected abstract static class PrimDoNamedPrimitiveWithArgsNode extends AbstractPrimitiveNode implements QuaternaryPrimitiveFallback { - @Specialization(guards = {"methodObject == cachedMethodObject", "primitiveNode != null", "sizeNode.execute(argumentArray) == cachedArraySize", + @Specialization(guards = {"methodObject == cachedMethodObject", "primitiveNode != null", "sizeNode.execute(node, argumentArray) == cachedArraySize", "cachedArraySize == cachedMethodObject.getNumArgs()"}, limit = "2") protected static final Object doNamedPrimitiveWithArgsContextCached(final VirtualFrame frame, @SuppressWarnings("unused") final Object context, @SuppressWarnings("unused") final CompiledCodeObject methodObject, final Object target, final ArrayObject argumentArray, + @Bind("this") final Node node, @SuppressWarnings("unused") @Cached("methodObject") final CompiledCodeObject cachedMethodObject, @SuppressWarnings("unused") @Cached final ArrayObjectSizeNode sizeNode, - @SuppressWarnings("unused") @Cached("sizeNode.execute(argumentArray)") final int cachedArraySize, + @SuppressWarnings("unused") @Cached("sizeNode.execute(node, argumentArray)") final int cachedArraySize, @Cached("createPrimitiveNode(methodObject)") final AbstractPrimitiveNode primitiveNode, @Cached final ArrayObjectToObjectArrayWithFirstNode toObjectArrayNode) { - return primitiveNode.executeWithArguments(frame, toObjectArrayNode.execute(target, argumentArray)); + return primitiveNode.executeWithArguments(frame, toObjectArrayNode.execute(node, target, argumentArray)); } @ReportPolymorphism.Megamorphic @@ -1192,13 +1212,13 @@ protected final Object doNamedPrimitiveWithArgsContextUncached(final VirtualFram final Object target, final ArrayObject argumentArray) { /* Deopt might be acceptable because primitive is mostly used for debugging anyway. */ CompilerDirectives.transferToInterpreter(); - final int arraySize = ArrayObjectSizeNode.getUncached().execute(argumentArray); + final int arraySize = ArrayObjectSizeNode.getUncached().execute(null, argumentArray); assert arraySize == methodObject.getNumArgs(); final AbstractPrimitiveNode primitiveNode = insert(createPrimitiveNode(methodObject)); if (primitiveNode == null) { throw PrimitiveFailed.GENERIC_ERROR; } else { - final Object[] receiverAndArguments = ArrayObjectToObjectArrayWithFirstNode.getUncached().execute(target, argumentArray); + final Object[] receiverAndArguments = ArrayObjectToObjectArrayWithFirstNode.getUncached().execute(null, target, argumentArray); return primitiveNode.executeWithArguments(frame, receiverAndArguments); } } diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/IOPrimitives.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/IOPrimitives.java index f2aefcd55..76b08a3d3 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/IOPrimitives.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/IOPrimitives.java @@ -254,49 +254,50 @@ protected abstract static class PrimScanCharactersNode extends AbstractPrimitive private static final long END_OF_RUN = 257 - 1; private static final long CROSSED_X = 258 - 1; - @Child private ArrayObjectReadNode arrayReadNode = ArrayObjectReadNode.create(); - @Child protected ArrayObjectSizeNode arraySizeNode = ArrayObjectSizeNode.create(); @Child protected AbstractPointersObjectReadNode pointersReadNode = AbstractPointersObjectReadNode.create(); @Child private AbstractPointersObjectWriteNode pointersWriteNode = AbstractPointersObjectWriteNode.create(); @Specialization(guards = {"startIndex > 0", "stopIndex > 0", "sourceString.isByteType()", "stopIndex <= sourceString.getByteLength()", "receiver.size() >= 4", - "arraySizeNode.execute(stops) >= 258", "hasCorrectSlots(receiver)"}) + "arraySizeNode.execute(node, stops) >= 258", "hasCorrectSlots(receiver, arraySizeNode, node)"}, limit = "1") protected final Object doScan(final PointersObject receiver, final long startIndex, final long stopIndex, final NativeObject sourceString, final long rightX, - final ArrayObject stops, final long kernData) { + final ArrayObject stops, final long kernData, + @Bind("this") final Node node, + @Cached final ArrayObjectSizeNode arraySizeNode, + @Cached final ArrayObjectReadNode arrayReadNode) { final ArrayObject scanXTable = pointersReadNode.executeArray(receiver, CHARACTER_SCANNER.XTABLE); final ArrayObject scanMap = pointersReadNode.executeArray(receiver, CHARACTER_SCANNER.MAP); - final int maxGlyph = arraySizeNode.execute(scanXTable) - 2; + final int maxGlyph = arraySizeNode.execute(node, scanXTable) - 2; long scanDestX = pointersReadNode.executeLong(receiver, CHARACTER_SCANNER.DEST_X); long scanLastIndex = startIndex; while (scanLastIndex <= stopIndex) { final long ascii = sourceString.getByte(scanLastIndex - 1) & 0xFF; - final Object stopReason = arrayReadNode.execute(stops, ascii); + final Object stopReason = arrayReadNode.execute(node, stops, ascii); if (stopReason != NilObject.SINGLETON) { storeStateInReceiver(receiver, scanDestX, scanLastIndex); return stopReason; } - if (arraySizeNode.execute(scanMap) <= ascii) { + if (arraySizeNode.execute(node, scanMap) <= ascii) { throw PrimitiveFailed.andTransferToInterpreter(); } - final long glyphIndex = (long) arrayReadNode.execute(scanMap, ascii); + final long glyphIndex = (long) arrayReadNode.execute(node, scanMap, ascii); if (glyphIndex < 0 || glyphIndex > maxGlyph) { throw PrimitiveFailed.andTransferToInterpreter(); } final long sourceX1; final long sourceX2; - sourceX1 = (long) arrayReadNode.execute(scanXTable, glyphIndex); - sourceX2 = (long) arrayReadNode.execute(scanXTable, glyphIndex + 1); + sourceX1 = (long) arrayReadNode.execute(node, scanXTable, glyphIndex); + sourceX2 = (long) arrayReadNode.execute(node, scanXTable, glyphIndex + 1); final long nextDestX = scanDestX + sourceX2 - sourceX1; if (nextDestX > rightX) { storeStateInReceiver(receiver, scanDestX, scanLastIndex); - return arrayReadNode.execute(stops, CROSSED_X); + return arrayReadNode.execute(node, stops, CROSSED_X); } scanDestX = nextDestX + kernData; scanLastIndex++; } storeStateInReceiver(receiver, scanDestX, stopIndex); - return arrayReadNode.execute(stops, END_OF_RUN); + return arrayReadNode.execute(node, stops, END_OF_RUN); } private void storeStateInReceiver(final PointersObject receiver, final long scanDestX, final long scanLastIndex) { @@ -304,9 +305,9 @@ private void storeStateInReceiver(final PointersObject receiver, final long scan pointersWriteNode.execute(receiver, CHARACTER_SCANNER.LAST_INDEX, scanLastIndex); } - protected final boolean hasCorrectSlots(final PointersObject receiver) { + protected final boolean hasCorrectSlots(final PointersObject receiver, final ArrayObjectSizeNode arraySizeNode, final Node inlineTarget) { return pointersReadNode.execute(receiver, CHARACTER_SCANNER.DEST_X) instanceof Long && pointersReadNode.execute(receiver, CHARACTER_SCANNER.XTABLE) instanceof ArrayObject && - pointersReadNode.execute(receiver, CHARACTER_SCANNER.MAP) instanceof final ArrayObject scanMap && arraySizeNode.execute(scanMap) == 256; + pointersReadNode.execute(receiver, CHARACTER_SCANNER.MAP) instanceof final ArrayObject scanMap && arraySizeNode.execute(inlineTarget, scanMap) == 256; } } @@ -478,13 +479,13 @@ protected static final void doArraysWithDifferenStorageTypes(final Node node, fi @Cached final ArrayObjectReadNode readNode, @Shared("arrayWriteNode") @Cached final ArrayObjectWriteNode writeNode, @Shared("errorProfile") @Cached final InlinedBranchProfile errorProfile) { - if (!inBounds(sizeNode.execute(rcvr), start, stop, replSizeNode.execute(repl), replStart)) { + if (!inBounds(sizeNode.execute(node, rcvr), start, stop, replSizeNode.execute(node, repl), replStart)) { errorProfile.enter(node); throw PrimitiveFailed.BAD_INDEX; } final long repOff = replStart - start; for (long i = start - 1; i < stop; i++) { - writeNode.execute(rcvr, i, readNode.execute(repl, repOff + i)); + writeNode.execute(node, rcvr, i, readNode.execute(node, repl, repOff + i)); } } @@ -494,13 +495,13 @@ protected static final void doArrayObjectPointers(final Node node, final ArrayOb @Cached final VariablePointersObjectReadNode readNode, @Shared("arrayWriteNode") @Cached final ArrayObjectWriteNode writeNode, @Shared("errorProfile") @Cached final InlinedBranchProfile errorProfile) { - if (!inBounds(rcvr.instsize(), sizeNode.execute(rcvr), start, stop, repl.instsize(), repl.size(), replStart)) { + if (!inBounds(rcvr.instsize(), sizeNode.execute(node, rcvr), start, stop, repl.instsize(), repl.size(), replStart)) { errorProfile.enter(node); throw PrimitiveFailed.BAD_INDEX; } final long repOff = replStart - start; for (long i = start - 1; i < stop; i++) { - writeNode.execute(rcvr, i, readNode.execute(repl, repOff + i)); + writeNode.execute(node, rcvr, i, readNode.execute(node, repl, repOff + i)); } } @@ -511,13 +512,13 @@ protected static final void doArrayObjectWeakPointers(final Node node, final Arr @Cached final WeakVariablePointersObjectReadNode readNode, @Shared("arrayWriteNode") @Cached final ArrayObjectWriteNode writeNode, @Shared("errorProfile") @Cached final InlinedBranchProfile errorProfile) { - if (!inBounds(rcvr.instsize(), sizeNode.execute(rcvr), start, stop, repl.instsize(), repl.size(), replStart)) { + if (!inBounds(rcvr.instsize(), sizeNode.execute(node, rcvr), start, stop, repl.instsize(), repl.size(), replStart)) { errorProfile.enter(node); throw PrimitiveFailed.BAD_INDEX; } final long repOff = replStart - start; for (long i = start - 1; i < stop; i++) { - writeNode.execute(rcvr, i, readNode.execute(repl, repOff + i)); + writeNode.execute(node, rcvr, i, readNode.execute(node, repl, repOff + i)); } } @@ -693,13 +694,13 @@ protected static final void doPointersArray(final Node node, final PointersObjec @Shared("writeNode") @Cached final AbstractPointersObjectWriteNode writeNode, @Shared("errorProfile") @Cached final InlinedBranchProfile errorProfile) { final int rcvrSize = rcvrSizeNode.execute(node, rcvr); - if (!inBounds(rcvrSize, rcvrSize, start, stop, repl.instsize(), sizeNode.execute(repl), replStart)) { + if (!inBounds(rcvrSize, rcvrSize, start, stop, repl.instsize(), sizeNode.execute(node, repl), replStart)) { errorProfile.enter(node); throw PrimitiveFailed.BAD_INDEX; } final long repOff = replStart - start; for (long i = start - 1; i < stop; i++) { - writeNode.execute(rcvr, i, readNode.execute(repl, repOff + i)); + writeNode.execute(rcvr, i, readNode.execute(node, repl, repOff + i)); } } @@ -731,7 +732,7 @@ protected static final void doVariablePointers(final Node node, final VariablePo } final long repOff = replStart - start; for (long i = start - 1; i < stop; i++) { - writeNode.execute(rcvr, i, readNode.execute(repl, repOff + i)); + writeNode.execute(node, rcvr, i, readNode.execute(node, repl, repOff + i)); } } @@ -743,13 +744,13 @@ protected static final void doVariablePointersArray(final Node node, final Varia @Shared("writeNode") @Cached final VariablePointersObjectWriteNode writeNode, @Shared("errorProfile") @Cached final InlinedBranchProfile errorProfile) { final int rcvrInstSize = rcvrInstSizeNode.execute(node, rcvr); - if (!inBounds(rcvrInstSize, rcvrInstSize + rcvr.getVariablePartSize(), start, stop, repl.instsize(), sizeNode.execute(repl), replStart)) { + if (!inBounds(rcvrInstSize, rcvrInstSize + rcvr.getVariablePartSize(), start, stop, repl.instsize(), sizeNode.execute(node, repl), replStart)) { errorProfile.enter(node); throw PrimitiveFailed.BAD_INDEX; } final long repOff = replStart - start; for (long i = start - 1; i < stop; i++) { - writeNode.execute(rcvr, i, readNode.execute(repl, repOff + i)); + writeNode.execute(node, rcvr, i, readNode.execute(node, repl, repOff + i)); } } @@ -781,7 +782,7 @@ protected static final void doWeakPointers(final Node node, final WeakVariablePo } final long repOff = replStart - start; for (long i = start - 1; i < stop; i++) { - writeNode.execute(rcvr, i, readNode.execute(repl, repOff + i)); + writeNode.execute(node, rcvr, i, readNode.execute(node, repl, repOff + i)); } } @@ -793,13 +794,13 @@ protected static final void doWeakPointersArray(final Node node, final WeakVaria @Shared("writeNode") @Cached final WeakVariablePointersObjectWriteNode writeNode, @Shared("errorProfile") @Cached final InlinedBranchProfile errorProfile) { final int rcvrInstSize = rcvrInstSizeNode.execute(node, rcvr); - if (!inBounds(rcvrInstSize, rcvrInstSize + rcvr.getVariablePartSize(), start, stop, repl.instsize(), sizeNode.execute(repl), replStart)) { + if (!inBounds(rcvrInstSize, rcvrInstSize + rcvr.getVariablePartSize(), start, stop, repl.instsize(), sizeNode.execute(node, repl), replStart)) { errorProfile.enter(node); throw PrimitiveFailed.BAD_INDEX; } final long repOff = replStart - start; for (long i = start - 1; i < stop; i++) { - writeNode.execute(rcvr, i, readNode.execute(repl, repOff + i)); + writeNode.execute(node, rcvr, i, readNode.execute(node, repl, repOff + i)); } } diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/StoragePrimitives.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/StoragePrimitives.java index 09a4c171f..71efe636a 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/StoragePrimitives.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/StoragePrimitives.java @@ -379,20 +379,20 @@ protected final CompiledCodeObject newMethod(final ClassObject receiver, final l @GenerateNodeFactory @SqueakPrimitive(indices = 128) protected abstract static class PrimArrayBecomeNode extends AbstractPrimitiveNode implements BinaryPrimitiveFallback { - @Specialization(guards = {"sizeNode.execute(receiver) == sizeNode.execute(other)"}) + @Specialization(guards = {"sizeNode.execute(node, receiver) == sizeNode.execute(node, other)"}) protected final ArrayObject doBecome(final ArrayObject receiver, final ArrayObject other, @Bind("this") final Node node, @Shared("sizeNode") @Cached final ArrayObjectSizeNode sizeNode, @Cached final SqueakObjectBecomeNode becomeNode, @Cached final ArrayObjectReadNode readNode, @Cached final InlinedBranchProfile failProfile) { - final int receiverSize = sizeNode.execute(receiver); + final int receiverSize = sizeNode.execute(node, receiver); int numBecomes = 0; final Object[] lefts = new Object[receiverSize]; final Object[] rights = new Object[receiverSize]; for (int i = 0; i < receiverSize; i++) { - final Object left = readNode.execute(receiver, i); - final Object right = readNode.execute(other, i); + final Object left = readNode.execute(node, receiver, i); + final Object right = readNode.execute(node, other, i); if (becomeNode.execute(node, left, right)) { lefts[numBecomes] = left; rights[numBecomes] = right; @@ -409,9 +409,10 @@ protected final ArrayObject doBecome(final ArrayObject receiver, final ArrayObje return receiver; } - @Specialization(guards = {"sizeNode.execute(receiver) != sizeNode.execute(other)"}) + @Specialization(guards = {"sizeNode.execute(node, receiver) != sizeNode.execute(node, other)"}) @SuppressWarnings("unused") protected static final ArrayObject doBadSize(final ArrayObject receiver, final ArrayObject other, + @SuppressWarnings("unused") @Bind("this") final Node node, @Shared("sizeNode") @Cached final ArrayObjectSizeNode sizeNode) { throw PrimitiveFailed.BAD_ARGUMENT; } diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/process/PutToSleepNode.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/process/PutToSleepNode.java index 58a369d89..edc477f78 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/process/PutToSleepNode.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/process/PutToSleepNode.java @@ -6,6 +6,11 @@ */ package de.hpi.swa.trufflesqueak.nodes.process; +import com.oracle.truffle.api.dsl.Bind; +import com.oracle.truffle.api.dsl.Cached; +import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.api.nodes.Node; + import de.hpi.swa.trufflesqueak.model.ArrayObject; import de.hpi.swa.trufflesqueak.model.PointersObject; import de.hpi.swa.trufflesqueak.model.layout.ObjectLayouts.PROCESS; @@ -17,19 +22,23 @@ /* * Save the given process on the scheduler process list for its priority. */ -public final class PutToSleepNode extends AbstractNode { - @Child private ArrayObjectReadNode arrayReadNode = ArrayObjectReadNode.create(); - @Child private AbstractPointersObjectReadNode pointersReadNode = AbstractPointersObjectReadNode.create(); - @Child private AddLastLinkToListNode addLastLinkToListNode = AddLastLinkToListNode.create(); +public abstract class PutToSleepNode extends AbstractNode { public static PutToSleepNode create() { - return new PutToSleepNode(); + return PutToSleepNodeGen.create(); } - public void executePutToSleep(final PointersObject process) { + public abstract void executePutToSleep(PointersObject process); + + @Specialization + protected static final void putToSleep(final PointersObject process, + @Bind("this") final Node node, + @Cached final ArrayObjectReadNode arrayReadNode, + @Cached final AbstractPointersObjectReadNode pointersReadNode, + @Cached final AddLastLinkToListNode addLastLinkToListNode) { final long priority = pointersReadNode.executeLong(process, PROCESS.PRIORITY); - final ArrayObject processLists = pointersReadNode.executeArray(getContext().getScheduler(), PROCESS_SCHEDULER.PROCESS_LISTS); - final PointersObject processList = (PointersObject) arrayReadNode.execute(processLists, priority - 1); + final ArrayObject processLists = pointersReadNode.executeArray(getContext(node).getScheduler(), PROCESS_SCHEDULER.PROCESS_LISTS); + final PointersObject processList = (PointersObject) arrayReadNode.execute(node, processLists, priority - 1); addLastLinkToListNode.execute(process, processList); } } diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/process/WakeHighestPriorityNode.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/process/WakeHighestPriorityNode.java index 6d4f585be..3b2e55bcc 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/process/WakeHighestPriorityNode.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/process/WakeHighestPriorityNode.java @@ -6,10 +6,12 @@ */ package de.hpi.swa.trufflesqueak.nodes.process; +import com.oracle.truffle.api.dsl.Bind; import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.NeverDefault; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.frame.VirtualFrame; +import com.oracle.truffle.api.nodes.Node; import de.hpi.swa.trufflesqueak.exceptions.SqueakExceptions.SqueakException; import de.hpi.swa.trufflesqueak.image.SqueakImageContext; @@ -36,6 +38,7 @@ public static WakeHighestPriorityNode create() { @Specialization protected final void doWake(final VirtualFrame frame, + @Bind("this") final Node node, @Cached final ArrayObjectReadNode arrayReadNode, @Cached final ArrayObjectSizeNode arraySizeNode, @Cached final AbstractPointersObjectReadNode pointersReadNode, @@ -46,8 +49,8 @@ protected final void doWake(final VirtualFrame frame, // Return the highest priority process that is ready to run. // Note: It is a fatal VM error if there is no runnable process. final ArrayObject schedLists = pointersReadNode.executeArray(image.getScheduler(), PROCESS_SCHEDULER.PROCESS_LISTS); - for (long p = arraySizeNode.execute(schedLists) - 1; p >= 0; p--) { - final PointersObject processList = (PointersObject) arrayReadNode.execute(schedLists, p); + for (long p = arraySizeNode.execute(node, schedLists) - 1; p >= 0; p--) { + final PointersObject processList = (PointersObject) arrayReadNode.execute(node, schedLists, p); while (!processList.isEmptyList(pointersReadNode)) { final PointersObject newProcess = processList.removeFirstLinkOfList(pointersReadNode, pointersWriteNode); final Object newContext = pointersReadNode.execute(newProcess, PROCESS.SUSPENDED_CONTEXT);