Skip to content

Commit

Permalink
Introduce some node object inlining
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Dec 6, 2023
1 parent 1ff0ce9 commit c06fcd1
Show file tree
Hide file tree
Showing 33 changed files with 520 additions and 338 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -466,13 +466,13 @@ public void testDup() {
public void testPushNewArray() {
final AbstractSqueakObject rcvr = image.specialObjectsArray;
final SqueakObjectAt0Node at0Node = SqueakObjectAt0Node.create();
final SqueakObjectSizeNode sizeNode = SqueakObjectSizeNode.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(resultList));
assertEquals(127, sizeNode.execute(null, resultList));

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

final Object[] literals = {2097154L, NilObject.SINGLETON, NilObject.SINGLETON}; // header
// with
Expand All @@ -542,7 +542,7 @@ public void testStoreRemoteTemp() {
final Object result = createContext(method, rcvr).execute(frame);
assertTrue(result instanceof ArrayObject);
final ArrayObject resultList = (ArrayObject) result;
assertEquals(2, sizeNode.execute(resultList));
assertEquals(2, sizeNode.execute(null, resultList));
assertEquals(BooleanObject.FALSE, at0Node.execute(resultList, 0));
assertEquals(BooleanObject.FALSE, at0Node.execute(resultList, 1));
} catch (NonLocalReturn | NonVirtualReturn | ProcessSwitch e) {
Expand All @@ -553,7 +553,7 @@ public void testStoreRemoteTemp() {
@Test
public void testStoreAndPopRemoteTemp() {
final SqueakObjectAt0Node at0Node = SqueakObjectAt0Node.create();
final SqueakObjectSizeNode sizeNode = SqueakObjectSizeNode.create();
final SqueakObjectSizeNode sizeNode = SqueakObjectSizeNode.getUncached();

final Object[] literals = {2097154L, NilObject.SINGLETON, NilObject.SINGLETON}; // header
// with
Expand All @@ -568,7 +568,7 @@ public void testStoreAndPopRemoteTemp() {
final Object result = createContext(method, rcvr).execute(frame);
assertTrue(result instanceof ArrayObject);
final ArrayObject resultList = (ArrayObject) result;
assertEquals(2, sizeNode.execute(resultList));
assertEquals(2, sizeNode.execute(null, resultList));
assertEquals(BooleanObject.FALSE, at0Node.execute(resultList, 0));
assertEquals(BooleanObject.TRUE, at0Node.execute(resultList, 1));
} catch (NonLocalReturn | NonVirtualReturn | ProcessSwitch e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.TruffleLanguage;
import com.oracle.truffle.api.TruffleOptions;
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.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.dsl.UnsupportedSpecializationException;
Expand Down Expand Up @@ -588,9 +591,9 @@ protected boolean hasArrayElements(@Shared("lib") @CachedLibrary(limit = "LIMIT"
@ExportMessage
@ExportMessage(name = "isArrayElementModifiable")
@TruffleBoundary
protected boolean isArrayElementReadable(final long index, @Shared("sizeNode") @Cached final ArraySizeNode sizeNode) {
protected boolean isArrayElementReadable(final long index, @Bind("$node") final Node node, @Shared("sizeNode") @Cached final ArraySizeNode sizeNode) {
try {
return 0 <= index && index < sizeNode.execute(wrappedObject);
return 0 <= index && index < sizeNode.execute(node, wrappedObject);
} catch (final UnsupportedSpecializationException | UnsupportedMessageException e) {
return false;
}
Expand All @@ -603,17 +606,19 @@ protected boolean isArrayElementInsertable(@SuppressWarnings("unused") final lon

@ExportMessage
@TruffleBoundary
protected long getArraySize(@Shared("sizeNode") @Cached final ArraySizeNode sizeNode) throws UnsupportedMessageException {
protected long getArraySize(@Bind("$node") final Node node, @Shared("sizeNode") @Cached final ArraySizeNode sizeNode) throws UnsupportedMessageException {
try {
return sizeNode.execute(wrappedObject);
return sizeNode.execute(node, wrappedObject);
} catch (final UnsupportedSpecializationException e) {
throw UnsupportedMessageException.create();
}
}

@GenerateInline
@GenerateUncached
@GenerateCached(false)
protected abstract static class ArraySizeNode extends Node {
protected abstract int execute(Object object) throws UnsupportedSpecializationException, UnsupportedMessageException;
protected abstract int execute(Node node, Object object) throws UnsupportedSpecializationException, UnsupportedMessageException;

@Specialization
protected static final int doBoolean(final boolean[] object) {
Expand Down Expand Up @@ -667,19 +672,21 @@ protected static final int doTruffleObject(final TruffleObject object, @CachedLi
}

@ExportMessage
protected Object readArrayElement(final long index, @Cached final ReadArrayElementNode readNode) throws InvalidArrayIndexException, UnsupportedMessageException {
protected Object readArrayElement(final long index, @Bind("$node") final Node node, @Cached final ReadArrayElementNode readNode) throws InvalidArrayIndexException, UnsupportedMessageException {
try {
return readNode.execute(wrappedObject, (int) index);
return readNode.execute(node, wrappedObject, (int) index);
} catch (final ArrayIndexOutOfBoundsException e) {
throw InvalidArrayIndexException.create(index);
} catch (final UnsupportedSpecializationException e) {
throw UnsupportedMessageException.create();
}
}

@GenerateInline
@GenerateUncached
@GenerateCached(false)
protected abstract static class ReadArrayElementNode extends Node {
protected abstract Object execute(Object object, int index) throws UnsupportedMessageException, InvalidArrayIndexException;
protected abstract Object execute(Node node, Object object, int index) throws UnsupportedMessageException, InvalidArrayIndexException;

@Specialization
protected static final boolean doBoolean(final boolean[] object, final int index) {
Expand Down Expand Up @@ -734,20 +741,22 @@ protected static final Object doTruffleObject(final TruffleObject object, final
}

@ExportMessage
protected void writeArrayElement(final long index, final Object value, @Cached final WriteArrayElementNode writeNode)
protected void writeArrayElement(final long index, final Object value, @Bind("$node") final Node node, @Cached final WriteArrayElementNode writeNode)
throws InvalidArrayIndexException, UnsupportedMessageException, UnsupportedTypeException {
try {
writeNode.execute(wrappedObject, (int) index, value);
writeNode.execute(node, wrappedObject, (int) index, value);
} catch (final ArrayIndexOutOfBoundsException e) {
throw InvalidArrayIndexException.create(index);
} catch (final UnsupportedSpecializationException e) {
throw UnsupportedMessageException.create();
}
}

@GenerateInline
@GenerateUncached
@GenerateCached(false)
protected abstract static class WriteArrayElementNode extends Node {
protected abstract void execute(Object object, int index, Object value) throws UnsupportedMessageException, InvalidArrayIndexException, UnsupportedTypeException;
protected abstract void execute(Node node, Object object, int index, Object value) throws UnsupportedMessageException, InvalidArrayIndexException, UnsupportedTypeException;

@Specialization
protected static final void doBoolean(final boolean[] object, final int index, final boolean value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

import java.util.Arrays;

import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
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.model.NativeObject;
Expand Down Expand Up @@ -45,12 +47,13 @@ protected static final Object doCached(final ClassObject classObject, final Stri
}

protected static final Object doUncachedSlow(final ClassObject classObject, final String selector) {
return doUncached(classObject, selector, AbstractPointersObjectReadNode.getUncached(), ArrayObjectReadNode.getUncached());
return doUncached(classObject, selector, null, AbstractPointersObjectReadNode.getUncached(), ArrayObjectReadNode.getUncached());
}

@ReportPolymorphism.Megamorphic
@Specialization(replaces = "doCached")
protected static final Object doUncached(final ClassObject classObject, final String selector,
@Bind("this") final Node node,
/**
* An AbstractPointersObjectReadNode is sufficient for accessing `values`
* instance variable here.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,16 @@ protected static final long doLong(final long value) {

@Specialization
protected static final Object doFloat(final float value,
@Bind("this") final Node node,
@Shared("boxNode") @Cached final AsFloatObjectIfNessaryNode boxNode) {
return boxNode.execute(value);
return boxNode.execute(node, value);
}

@Specialization
protected static final Object doDouble(final double value,
@Bind("this") final Node node,
@Shared("boxNode") @Cached final AsFloatObjectIfNessaryNode boxNode) {
return boxNode.execute(value);
return boxNode.execute(node, value);
}

@Specialization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.nodes.Node;

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

protected final boolean layoutValuesPointTo(final SqueakObjectIdentityNode identityNode, final Object thang) {
protected final boolean layoutValuesPointTo(final SqueakObjectIdentityNode identityNode, final Node inlineTarget, final Object thang) {
final boolean pointTo = object0 == thang || object1 == thang || object2 == thang || objectExtension != null && ArrayUtils.contains(objectExtension, thang);
if (pointTo) {
return true;
} else {
return primitiveLocationsPointTo(identityNode, thang);
return primitiveLocationsPointTo(identityNode, inlineTarget, thang);
}
}

@TruffleBoundary
private boolean primitiveLocationsPointTo(final SqueakObjectIdentityNode identityNode, final Object thang) {
private boolean primitiveLocationsPointTo(final SqueakObjectIdentityNode identityNode, final Node inlineTarget, final Object thang) {
if (SqueakGuards.isUsedJavaPrimitive(thang)) {
// TODO: This could be more efficient.
for (final SlotLocation slotLocation : getLayout().getLocations()) {
if (slotLocation.isPrimitive() && identityNode.execute(slotLocation.read(this), thang)) {
if (slotLocation.isPrimitive() && identityNode.execute(inlineTarget, slotLocation.read(this), thang)) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import java.util.Arrays;

import com.oracle.truffle.api.nodes.Node;

import de.hpi.swa.trufflesqueak.image.SqueakImageContext;
import de.hpi.swa.trufflesqueak.model.layout.ObjectLayout;
import de.hpi.swa.trufflesqueak.nodes.accessing.SqueakObjectIdentityNode;
Expand Down Expand Up @@ -48,8 +50,8 @@ public final int size() {
return instsize() + variablePart.length;
}

public boolean pointsTo(final SqueakObjectIdentityNode identityNode, final Object thang) {
return layoutValuesPointTo(identityNode, thang) || ArrayUtils.contains(variablePart, thang);
public boolean pointsTo(final SqueakObjectIdentityNode identityNode, final Node inlineTarget, final Object thang) {
return layoutValuesPointTo(identityNode, inlineTarget, thang) || ArrayUtils.contains(variablePart, thang);
}

public final Object[] getVariablePart() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public int instsize() {
@Override
public int size() {
CompilerAsserts.neverPartOfCompilation();
return NativeObjectSizeNode.getUncached().execute(this);
return NativeObjectSizeNode.getUncached().execute(null, this);
}

public void become(final NativeObject other) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package de.hpi.swa.trufflesqueak.model;

import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.nodes.Node;

import de.hpi.swa.trufflesqueak.image.SqueakImageContext;
import de.hpi.swa.trufflesqueak.image.SqueakImageWriter;
Expand Down Expand Up @@ -71,8 +72,8 @@ public int size() {
return instsize();
}

public boolean pointsTo(final SqueakObjectIdentityNode identityNode, final Object thang) {
return layoutValuesPointTo(identityNode, thang);
public boolean pointsTo(final SqueakObjectIdentityNode identityNode, final Node inlineTarget, final Object thang) {
return layoutValuesPointTo(identityNode, inlineTarget, thang);
}

public boolean isEmptyList(final AbstractPointersObjectReadNode readNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public void putIntoVariablePart(final long index, final Object value, final Inli
}

@Override
public boolean pointsTo(final SqueakObjectIdentityNode identityNode, final Object thang) {
return layoutValuesPointTo(identityNode, thang) || variablePartPointsTo(thang);
public boolean pointsTo(final SqueakObjectIdentityNode identityNode, final Node inlineTarget, final Object thang) {
return layoutValuesPointTo(identityNode, inlineTarget, thang) || variablePartPointsTo(thang);
}

private boolean variablePartPointsTo(final Object thang) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
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;
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.NeverDefault;
Expand Down Expand Up @@ -150,9 +152,11 @@ protected static final void doWriteGeneric(final AbstractPointersObject object,
}
}

@GenerateInline
@GenerateUncached
@GenerateCached(false)
public abstract static class AbstractPointersObjectInstSizeNode extends AbstractNode {
public abstract int execute(AbstractPointersObject obj);
public abstract int execute(Node node, AbstractPointersObject obj);

@Specialization(guards = {"object.getLayout() == cachedLayout"}, assumptions = "cachedLayout.getValidAssumption()", limit = "1")
protected static final int doSizeCached(@SuppressWarnings("unused") final AbstractPointersObject object,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
import com.oracle.truffle.api.dsl.Cached.Shared;
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.ImportStatic;
import com.oracle.truffle.api.dsl.NeverDefault;
Expand All @@ -32,7 +34,9 @@
import de.hpi.swa.trufflesqueak.util.FrameAccess;

public final class ArrayObjectNodes {

@GenerateUncached
@GenerateCached
public abstract static class ArrayObjectReadNode extends AbstractNode {

@NeverDefault
Expand Down Expand Up @@ -100,9 +104,11 @@ protected static final Object doArrayOfObjects(final ArrayObject obj, final long
}
}

@GenerateInline
@GenerateCached(false)
public abstract static class ArrayObjectShallowCopyNode extends AbstractNode {

public abstract ArrayObject execute(ArrayObject obj);
public abstract ArrayObject execute(Node node, ArrayObject obj);

@Specialization(guards = "obj.isEmptyType()")
protected static final ArrayObject doEmptyArray(final ArrayObject obj) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
*/
package de.hpi.swa.trufflesqueak.nodes.accessing;

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.ImportStatic;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.nodes.Node;

import de.hpi.swa.trufflesqueak.model.AbstractSqueakObject;
import de.hpi.swa.trufflesqueak.model.BlockClosureObject;
Expand All @@ -19,11 +22,13 @@
import de.hpi.swa.trufflesqueak.nodes.AbstractNode;

public final class BlockClosureObjectNodes {
@GenerateInline
@GenerateUncached
@GenerateCached(false)
@ImportStatic(BLOCK_CLOSURE.class)
public abstract static class BlockClosureObjectReadNode extends AbstractNode {

public abstract Object execute(BlockClosureObject closure, long index);
public abstract Object execute(Node node, BlockClosureObject closure, long index);

@Specialization(guards = "index == OUTER_CONTEXT")
protected static final AbstractSqueakObject doClosureOuterContext(final BlockClosureObject closure, @SuppressWarnings("unused") final long index) {
Expand Down Expand Up @@ -61,11 +66,13 @@ protected static final Object doFullClosureCopiedValues(final BlockClosureObject
}
}

@GenerateInline
@GenerateUncached
@GenerateCached(false)
@ImportStatic(BLOCK_CLOSURE.class)
public abstract static class BlockClosureObjectWriteNode extends AbstractNode {

public abstract void execute(BlockClosureObject closure, long index, Object value);
public abstract void execute(Node node, BlockClosureObject closure, long index, Object value);

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

1 comment on commit c06fcd1

@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 (c06fcd1)

Benchmarks ran on graalvm-jdk-21+35.1.

Steady (after 100 iterations)

Benchmark Name Min Geomean Median Mean Max Total (ms) Total (min)
Bounce 531 541 533.62 532 533.61 106723 1.78
CD 436 447 439.07 437 439.06 87814 1.46
DeltaBlue 276 501 408.96 400 407.21 81792 1.36
Havlak 1127 1184 1159.4 1165 1159.32 231880 3.86
Json 343 353 345.24 344 345.23 69048 1.15
List 291 306 294 294 293.99 58800 0.98
Mandelbrot 125 144 126 126 125.98 25200 0.42
NBody 249 259 251.81 250 251.79 50361 0.84
Permute 149 162 150.6 150 150.58 30119 0.5
Queens 232 249 235.72 235 235.71 47144 0.79
Richards 1224 1236 1227.4 1227.5 1227.39 245479 4.09
Sieve 163 173 164.14 164 164.12 32827 0.55
Storage 139 154 141.01 140 140.98 28201 0.47
Towers 195 211 196.7 196 196.68 39339 0.66
5480 5920 5673.63 5660.5 5671.67 1134727 18.91

c06fcd1-2-steady.svg

Warmup (first 100 iterations)

c06fcd1-3-warmup.svg

Please sign in to comment.