Skip to content

Commit

Permalink
Introduce more node object inlining
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Dec 7, 2023
1 parent c06fcd1 commit fdb6469
Show file tree
Hide file tree
Showing 21 changed files with 269 additions and 296 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
}
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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) {
Expand All @@ -296,28 +300,28 @@ 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);
}

@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")
Expand All @@ -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) {
Expand All @@ -347,17 +350,15 @@ 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);
}

@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);
}
Expand Down
Loading

1 comment on commit fdb6469

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

Benchmarks ran on graalvm-jdk-21+35.1.

Steady (after 100 iterations)

Benchmark Name Min Geomean Median Mean Max Total (ms) Total (min)
Bounce 532 540 535.15 534 535.14 107030 1.78
CD 439 450 442.55 440 442.53 88509 1.48
DeltaBlue 271 480 407.96 400 405.99 81592 1.36
Havlak 1149 1204 1183.04 1189 1182.95 236607 3.94
Json 350 360 353.09 351 353.07 70617 1.18
List 291 302 292.35 292 292.34 58469 0.97
Mandelbrot 132 141 132.98 133 132.97 26596 0.44
NBody 248 260 251.88 250 251.86 50375 0.84
Permute 149 161 150.64 150 150.62 30127 0.5
Queens 231 252 236.38 238 236.36 47276 0.79
Richards 1222 1232 1225.81 1226 1225.81 245162 4.09
Sieve 163 173 164.08 164 164.07 32815 0.55
Storage 137 147 139.5 138 139.48 27900 0.47
Towers 197 211 199.77 198 199.75 39954 0.67
5511 5913 5715.15 5703 5712.94 1143029 19.05

fdb6469-2-steady.svg

Warmup (first 100 iterations)

fdb6469-3-warmup.svg

Please sign in to comment.