Skip to content

Commit

Permalink
Enable node inlining for SqueakObjectAt0Node
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Dec 9, 2023
1 parent 79e6a0d commit 7fa1e6d
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -465,14 +465,12 @@ public void testDup() {
@Test
public void testPushNewArray() {
final AbstractSqueakObject rcvr = image.specialObjectsArray;
final SqueakObjectAt0Node at0Node = SqueakObjectAt0Node.create();
final SqueakObjectSizeNode sizeNode = SqueakObjectSizeNode.getUncached();
// pushNewArray (size 127), returnTop
CompiledCodeObject method = makeMethod(new Object[]{makeHeader(0, 0, 0, false, true)}, 138, 127, 124);
Object result = runMethod(method, rcvr);
assertTrue(result instanceof ArrayObject);
ArrayObject resultList = (ArrayObject) result;
assertEquals(127, sizeNode.execute(null, resultList));
assertEquals(127, SqueakObjectSizeNode.executeUncached(resultList));

// pushNewArray and pop
final int arraySize = CONTEXT.MAX_STACK_SIZE;
Expand All @@ -487,9 +485,9 @@ public void testPushNewArray() {
result = runMethod(method, rcvr);
assertTrue(result instanceof ArrayObject);
resultList = (ArrayObject) result;
assertEquals(arraySize, sizeNode.execute(null, resultList));
assertEquals(arraySize, SqueakObjectSizeNode.executeUncached(resultList));
for (int i = 0; i < arraySize; i++) {
assertEquals(BooleanObject.wrap(i % 2 == 0), at0Node.execute(resultList, i));
assertEquals(BooleanObject.wrap(i % 2 == 0), SqueakObjectAt0Node.executeUncached(resultList, i));
}
}

Expand Down Expand Up @@ -526,9 +524,6 @@ public void testPushRemoteTemp() {

@Test
public void testStoreRemoteTemp() {
final SqueakObjectAt0Node at0Node = SqueakObjectAt0Node.create();
final SqueakObjectSizeNode sizeNode = SqueakObjectSizeNode.getUncached();

final Object[] literals = {2097154L, NilObject.SINGLETON, NilObject.SINGLETON}; // header
// with
// numTemp=8
Expand All @@ -542,19 +537,16 @@ public void testStoreRemoteTemp() {
final Object result = createContext(method, rcvr).execute(frame);
assertTrue(result instanceof ArrayObject);
final ArrayObject resultList = (ArrayObject) result;
assertEquals(2, sizeNode.execute(null, resultList));
assertEquals(BooleanObject.FALSE, at0Node.execute(resultList, 0));
assertEquals(BooleanObject.FALSE, at0Node.execute(resultList, 1));
assertEquals(2, SqueakObjectSizeNode.executeUncached(resultList));
assertEquals(BooleanObject.FALSE, SqueakObjectAt0Node.executeUncached(resultList, 0));
assertEquals(BooleanObject.FALSE, SqueakObjectAt0Node.executeUncached(resultList, 1));
} catch (NonLocalReturn | NonVirtualReturn | ProcessSwitch e) {
fail("broken test");
}
}

@Test
public void testStoreAndPopRemoteTemp() {
final SqueakObjectAt0Node at0Node = SqueakObjectAt0Node.create();
final SqueakObjectSizeNode sizeNode = SqueakObjectSizeNode.getUncached();

final Object[] literals = {2097154L, NilObject.SINGLETON, NilObject.SINGLETON}; // header
// with
// numTemp=8
Expand All @@ -568,9 +560,9 @@ public void testStoreAndPopRemoteTemp() {
final Object result = createContext(method, rcvr).execute(frame);
assertTrue(result instanceof ArrayObject);
final ArrayObject resultList = (ArrayObject) result;
assertEquals(2, sizeNode.execute(null, resultList));
assertEquals(BooleanObject.FALSE, at0Node.execute(resultList, 0));
assertEquals(BooleanObject.TRUE, at0Node.execute(resultList, 1));
assertEquals(2, SqueakObjectSizeNode.executeUncached(resultList));
assertEquals(BooleanObject.FALSE, SqueakObjectAt0Node.executeUncached(resultList, 0));
assertEquals(BooleanObject.TRUE, SqueakObjectAt0Node.executeUncached(resultList, 1));
} catch (NonLocalReturn | NonVirtualReturn | ProcessSwitch e) {
fail("broken test");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
*/
package de.hpi.swa.trufflesqueak.nodes.accessing;

import com.oracle.truffle.api.dsl.Bind;
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.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
Expand All @@ -35,23 +35,19 @@
import de.hpi.swa.trufflesqueak.nodes.accessing.ContextObjectNodes.ContextObjectReadNode;
import de.hpi.swa.trufflesqueak.nodes.accessing.NativeObjectNodes.NativeObjectReadNode;

@GenerateInline
@GenerateUncached
@GenerateCached(false)
public abstract class SqueakObjectAt0Node extends AbstractNode {

@NeverDefault
public static SqueakObjectAt0Node create() {
return SqueakObjectAt0NodeGen.create();
}
public abstract Object execute(Node node, Object obj, long index);

public static SqueakObjectAt0Node getUncached() {
return SqueakObjectAt0NodeGen.getUncached();
public static final Object executeUncached(final Object obj, final long index) {
return SqueakObjectAt0NodeGen.getUncached().execute(null, obj, index);
}

public abstract Object execute(Object obj, long index);

@Specialization
protected static final Object doArray(final ArrayObject obj, final long index,
@Bind("this") final Node node,
protected static final Object doArray(final Node node, final ArrayObject obj, final long index,
@Cached final ArrayObjectReadNode readNode) {
return readNode.execute(node, obj, index);
}
Expand All @@ -63,29 +59,25 @@ 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,
protected static final Object doVariablePointers(final Node node, final VariablePointersObject obj, final long index,
@Cached final VariablePointersObjectReadNode readNode) {
return readNode.execute(node, obj, index);
}

@Specialization
protected static final Object doClass(final ClassObject obj, final long index,
@Bind("this") final Node node,
protected static final Object doClass(final Node node, final ClassObject obj, final long index,
@Cached final ClassObjectReadNode readNode) {
return readNode.execute(node, obj, index);
}

@Specialization
protected static final Object doWeakPointersVariable(final WeakVariablePointersObject obj, final long index,
@Bind("this") final Node node,
protected static final Object doWeakPointersVariable(final Node node, final WeakVariablePointersObject obj, final long index,
@Cached final WeakVariablePointersObjectReadNode readNode) {
return readNode.execute(node, obj, index);
}

@Specialization
protected static final Object doNative(final NativeObject obj, final long index,
@Bind("this") final Node node,
protected static final Object doNative(final Node node, final NativeObject obj, final long index,
@Cached final NativeObjectReadNode readNode) {
return readNode.execute(node, obj, index);
}
Expand All @@ -101,22 +93,19 @@ protected static final long doCode(final CompiledCodeObject obj, final long inde
}

@Specialization
protected static final Object doClosure(final BlockClosureObject obj, final long index,
@Bind("this") final Node node,
protected static final Object doClosure(final Node node, final BlockClosureObject obj, final long index,
@Cached final BlockClosureObjectReadNode readNode) {
return readNode.execute(node, obj, index);
}

@Specialization
protected static final Object doContext(final ContextObject obj, final long index,
@Bind("this") final Node node,
protected static final Object doContext(final Node node, final ContextObject obj, final long index,
@Cached final ContextObjectReadNode readNode) {
return readNode.execute(node, obj, index);
}

@Specialization
protected static final long doFloat(final FloatObject obj, final long index,
@Bind("this") final Node node,
protected static final long doFloat(final Node node, final FloatObject obj, final long index,
@Cached final InlinedBranchProfile indexZeroProfile,
@Cached final InlinedBranchProfile indexOneProfile) {
if (index == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
@NodeInfo(cost = NodeCost.NONE)
public abstract class SqueakObjectSizeNode extends AbstractNode {

public static final SqueakObjectSizeNode getUncached() {
return SqueakObjectSizeNodeGen.getUncached();
}

public abstract int execute(Node node, Object obj);

public static final int executeUncached(final Object obj) {
return SqueakObjectSizeNodeGen.getUncached().execute(null, obj);
}

@Specialization
protected static final int doNil(final NilObject obj) {
return obj.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@

import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.CompilerDirectives;
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.frame.VirtualFrame;
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.profiles.ValueProfile;
import com.oracle.truffle.api.profiles.InlinedExactClassProfile;

import de.hpi.swa.trufflesqueak.image.SqueakImageContext;
import de.hpi.swa.trufflesqueak.model.AbstractSqueakObjectWithClassAndHash;
Expand All @@ -25,6 +29,9 @@
import de.hpi.swa.trufflesqueak.model.layout.ObjectLayouts.ASSOCIATION;
import de.hpi.swa.trufflesqueak.nodes.AbstractNode;
import de.hpi.swa.trufflesqueak.nodes.accessing.SqueakObjectAt0Node;
import de.hpi.swa.trufflesqueak.nodes.bytecodes.PushBytecodesFactory.PushLiteralVariableNodeFactory.PushLiteralVariableWritableNodeGen;
import de.hpi.swa.trufflesqueak.nodes.bytecodes.PushBytecodesFactory.PushReceiverVariableNodeGen;
import de.hpi.swa.trufflesqueak.nodes.bytecodes.PushBytecodesFactory.PushRemoteTempNodeGen;
import de.hpi.swa.trufflesqueak.nodes.context.frame.FrameStackPopNNode;
import de.hpi.swa.trufflesqueak.nodes.context.frame.FrameStackPopNode;
import de.hpi.swa.trufflesqueak.nodes.context.frame.FrameStackPushNode;
Expand Down Expand Up @@ -382,7 +389,7 @@ public static final AbstractPushNode create(final CompiledCodeObject code, final
return new PushLiteralVariableReadonlyNode(code, index, numBytecodes, literal);
}
}
return new PushLiteralVariableWritableNode(code, index, numBytecodes, literal);
return PushLiteralVariableWritableNodeGen.create(code, index, numBytecodes, literal);
}

@Override
Expand All @@ -391,17 +398,19 @@ public final String toString() {
return "pushLitVar: " + literal;
}

private static final class PushLiteralVariableWritableNode extends PushLiteralVariableNode {
@Child private SqueakObjectAt0Node at0Node = SqueakObjectAt0Node.create();
private final ValueProfile valueProfile = ValueProfile.createIdentityProfile();
protected abstract static class PushLiteralVariableWritableNode extends PushLiteralVariableNode {

protected PushLiteralVariableWritableNode(final CompiledCodeObject code, final int index, final int numBytecodes, final Object literal) {
super(code, index, numBytecodes, literal);
}

@Override
public void executeVoid(final VirtualFrame frame) {
pushNode.execute(frame, valueProfile.profile(at0Node.execute(literal, ASSOCIATION.VALUE)));
@Specialization
protected final void doPushLiteralVariable(final VirtualFrame frame,
@Bind("this") final Node node,
@Cached final InlinedExactClassProfile valueProfile,
@Cached final SqueakObjectAt0Node at0Node,
@Cached final FrameStackPushNode pushNode) {
pushNode.execute(frame, valueProfile.profile(node, at0Node.execute(node, literal, ASSOCIATION.VALUE)));
}
}

Expand All @@ -420,7 +429,8 @@ public void executeVoid(final VirtualFrame frame) {
}

private static Object getPushValue(final Object literal) {
return SqueakObjectAt0Node.getUncached().execute(literal, ASSOCIATION.VALUE);
CompilerAsserts.neverPartOfCompilation();
return SqueakObjectAt0Node.executeUncached(literal, ASSOCIATION.VALUE);
}
}
}
Expand Down Expand Up @@ -518,8 +528,7 @@ public String toString() {
}

@NodeInfo(cost = NodeCost.NONE)
public static final class PushReceiverVariableNode extends AbstractPushNode {
@Child private SqueakObjectAt0Node at0Node = SqueakObjectAt0Node.create();
public abstract static class PushReceiverVariableNode extends AbstractInstrumentableBytecodeNode {
private final int variableIndex;

protected PushReceiverVariableNode(final CompiledCodeObject code, final int index, final int numBytecodes, final int varIndex) {
Expand All @@ -528,12 +537,15 @@ protected PushReceiverVariableNode(final CompiledCodeObject code, final int inde
}

public static PushReceiverVariableNode create(final CompiledCodeObject code, final int index, final int numBytecodes, final int varIndex) {
return new PushReceiverVariableNode(code, index, numBytecodes, varIndex);
return PushReceiverVariableNodeGen.create(code, index, numBytecodes, varIndex);
}

@Override
public void executeVoid(final VirtualFrame frame) {
pushNode.execute(frame, at0Node.execute(FrameAccess.getReceiver(frame), variableIndex));
@Specialization
protected final void doPushReceiver(final VirtualFrame frame,
@Bind("this") final Node node,
@Cached final SqueakObjectAt0Node at0Node,
@Cached final FrameStackPushNode pushNode) {
pushNode.execute(frame, at0Node.execute(node, FrameAccess.getReceiver(frame), variableIndex));
}

@Override
Expand All @@ -544,25 +556,27 @@ public String toString() {
}

@NodeInfo(cost = NodeCost.NONE)
public static final class PushRemoteTempNode extends AbstractPushNode {
@Child private SqueakObjectAt0Node at0Node = SqueakObjectAt0Node.create();
@Child private FrameStackReadNode readTempNode;
private final int indexInArray;
private final int indexOfArray;
public abstract static class PushRemoteTempNode extends AbstractInstrumentableBytecodeNode {
protected final int indexInArray;
protected final int indexOfArray;

public PushRemoteTempNode(final CompiledCodeObject code, final int index, final int numBytecodes, final byte indexInArray, final byte indexOfArray) {
super(code, index, numBytecodes);
this.indexInArray = Byte.toUnsignedInt(indexInArray);
this.indexOfArray = Byte.toUnsignedInt(indexOfArray);
}

@Override
public void executeVoid(final VirtualFrame frame) {
if (readTempNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
readTempNode = insert(FrameStackReadNode.create(frame, indexOfArray, false));
}
pushNode.execute(frame, at0Node.execute(readTempNode.executeRead(frame), indexInArray));
public static PushRemoteTempNode create(final CompiledCodeObject code, final int index, final int numBytecodes, final byte indexInArray, final byte indexOfArray) {
return PushRemoteTempNodeGen.create(code, index, numBytecodes, indexInArray, indexOfArray);
}

@Specialization
protected final void doPushRemoteTemp(final VirtualFrame frame,
@Bind("this") final Node node,
@Cached("create(frame, indexOfArray, false)") final FrameStackReadNode readTempNode,
@Cached final SqueakObjectAt0Node at0Node,
@Cached final FrameStackPushNode pushNode) {
pushNode.execute(frame, at0Node.execute(node, readTempNode.executeRead(frame), indexInArray));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ yield switch (primitiveIndex) {
}
case 0xF9 -> PushBytecodes.AbstractPushFullClosureNode.createExtended(code, index, 3, extA, bytecode[indexWithExt + 1], bytecode[indexWithExt + 2]);
case 0xFA -> PushBytecodes.PushClosureNode.createExtended(code, index, 3 + extBytes, extA, extB, bytecode[indexWithExt + 1], bytecode[indexWithExt + 2]);
case 0xFB -> new PushBytecodes.PushRemoteTempNode(code, index, 3, bytecode[indexWithExt + 1], bytecode[indexWithExt + 2]);
case 0xFB -> PushBytecodes.PushRemoteTempNode.create(code, index, 3, bytecode[indexWithExt + 1], bytecode[indexWithExt + 2]);
case 0xFC -> new StoreBytecodes.StoreIntoRemoteTempNode(code, index, 3, bytecode[indexWithExt + 1], bytecode[indexWithExt + 2]);
case 0xFD -> new StoreBytecodes.PopIntoRemoteTempNode(code, index, 3, bytecode[indexWithExt + 1], bytecode[indexWithExt + 2]);
case 0xFE, 0xFF -> new MiscellaneousBytecodes.UnknownBytecodeNode(code, index, 3, b);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public AbstractBytecodeNode decodeBytecode(final VirtualFrame frame, final Compi
case 0x89 -> new PushBytecodes.PushActiveContextNode(code, index);
case 0x8A -> PushBytecodes.PushNewArrayNode.create(code, index, 2, bytecode[index + 1]);
case 0x8B -> MiscellaneousBytecodes.CallPrimitiveNode.create(code, index, bytecode[index + 1], bytecode[index + 2]);
case 0x8C -> new PushBytecodes.PushRemoteTempNode(code, index, 3, bytecode[index + 1], bytecode[index + 2]);
case 0x8C -> PushBytecodes.PushRemoteTempNode.create(code, index, 3, bytecode[index + 1], bytecode[index + 2]);
case 0x8D -> new StoreBytecodes.StoreIntoRemoteTempNode(code, index, 3, bytecode[index + 1], bytecode[index + 2]);
case 0x8E -> new StoreBytecodes.PopIntoRemoteTempNode(code, index, 3, bytecode[index + 1], bytecode[index + 2]);
case 0x8F -> PushBytecodes.PushClosureNode.create(code, index, bytecode[index + 1], bytecode[index + 2], bytecode[index + 3]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private AbstractStoreIntoAssociationNode(final CompiledCodeObject code, final in
@Override
public final String toString() {
CompilerAsserts.neverPartOfCompilation();
return getTypeName() + "IntoLit: " + SqueakObjectAt0Node.getUncached().execute(literalVariable, ASSOCIATION.KEY);
return getTypeName() + "IntoLit: " + SqueakObjectAt0Node.executeUncached(literalVariable, ASSOCIATION.KEY);
}
}

Expand Down
Loading

1 comment on commit 7fa1e6d

@TruffleSqueak-Bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performance Report (7fa1e6d)

Benchmarks ran on graalvm-jdk-21+35.1.

Steady (after 100 iterations)

Benchmark Name Min Geomean Median Mean Max Total (ms) Total (min)
Bounce 539 646 568.76 562.5 568.28 113751 1.9
CD 474 486 477.86 476 477.84 95571 1.59
DeltaBlue 276 454 401.38 402 400.02 80276 1.34
Havlak 1115 1168 1145.51 1151 1145.43 229102 3.82
Json 357 369 360.03 358 360.02 72006 1.2
List 292 303 293.27 293 293.27 58655 0.98
Mandelbrot 126 185 129.05 127 128.82 25810 0.43
NBody 249 261 251.92 250 251.9 50383 0.84
Permute 149 193 151.38 150 151.32 30275 0.5
Queens 231 248 232.25 232 232.24 46450 0.77
Richards 1220 1468 1275.9 1269.5 1275.35 255179 4.25
Sieve 163 177 164.07 164 164.06 32814 0.55
Storage 139 332 148.07 141 146.99 29613 0.49
Towers 200 220 206.16 210 206.09 41231 0.69
5530 6510 5805.58 5786 5801.64 1161116 19.35

7fa1e6d-2-steady.svg

Warmup (first 100 iterations)

7fa1e6d-3-warmup.svg

Please sign in to comment.