Skip to content

Commit

Permalink
Use more node inlining.
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Dec 8, 2023
1 parent 38c1c5e commit 1ed720a
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ private static ClassObject createFreshTestClass() {
}

private static PointersObject instantiate(final ClassObject dummyClass) {
return (PointersObject) SqueakObjectNewNode.create().execute(image, dummyClass);
return (PointersObject) SqueakObjectNewNode.executeUncached(image, dummyClass);
}

private static void writeAndValidate(final AbstractPointersObject obj, final int index, final Object value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected final void doMaterialize(final VirtualFrame frame,
@Bind("this") final Node node,
@Cached final InlinedConditionProfile isNotLastSeenContextProfile,
@Cached final InlinedConditionProfile continueProfile,
@Cached final GetOrCreateContextNode getOrCreateContextNode) {
@Cached(inline = true) final GetOrCreateContextNode getOrCreateContextNode) {
final SqueakImageContext image = getContext();
final ContextObject lastSeenContext = image.lastSeenContext;
final ContextObject context = getOrCreateContextNode.executeGet(frame, node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ 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) {
@Cached(inline = true) final ArrayObjectWriteNode writeNode) {
writeNode.execute(node, obj, index, value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@

import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.NeverDefault;
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.nodes.Node;

import de.hpi.swa.trufflesqueak.exceptions.SqueakExceptions.SqueakException;
import de.hpi.swa.trufflesqueak.image.SqueakImageContext;
Expand All @@ -31,24 +34,26 @@
import de.hpi.swa.trufflesqueak.model.layout.ObjectLayouts.METACLASS;
import de.hpi.swa.trufflesqueak.nodes.AbstractNode;

@GenerateInline
@GenerateUncached
@GenerateCached(false)
public abstract class SqueakObjectNewNode extends AbstractNode {
public static final int NEW_CACHE_SIZE = 6;

@NeverDefault
public static SqueakObjectNewNode create() {
return SqueakObjectNewNodeGen.create();
public final AbstractSqueakObjectWithClassAndHash execute(final Node node, final SqueakImageContext image, final ClassObject classObject) {
return execute(node, image, classObject, 0);
}

public final AbstractSqueakObjectWithClassAndHash execute(final SqueakImageContext image, final ClassObject classObject) {
return execute(image, classObject, 0);
public static final AbstractSqueakObjectWithClassAndHash executeUncached(final SqueakImageContext image, final ClassObject classObject) {
return SqueakObjectNewNodeGen.getUncached().execute(null, image, classObject);
}

public final AbstractSqueakObjectWithClassAndHash execute(final SqueakImageContext image, final ClassObject classObject, final int extraSize) {
public final AbstractSqueakObjectWithClassAndHash execute(final Node node, final SqueakImageContext image, final ClassObject classObject, final int extraSize) {
CompilerAsserts.partialEvaluationConstant(image);
return image.reportAllocation(executeAllocation(image, classObject, extraSize));
return image.reportAllocation(executeAllocation(node, image, classObject, extraSize));
}

protected abstract AbstractSqueakObjectWithClassAndHash executeAllocation(SqueakImageContext image, ClassObject classObject, int extraSize);
protected abstract AbstractSqueakObjectWithClassAndHash executeAllocation(Node node, SqueakImageContext image, ClassObject classObject, int extraSize);

@Specialization(guards = "classObject.isZeroSized()")
protected static final EmptyObject doEmpty(final SqueakImageContext image, final ClassObject classObject, @SuppressWarnings("unused") final int extraSize) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ protected static final Object doGetContextOrMarker(final VirtualFrame frame, @Su
protected static final ContextObject doGetOrCreateContext(final VirtualFrame frame, @SuppressWarnings("unused") final CompiledCodeObject code,
@SuppressWarnings("unused") @Bind("this") final Node node,
@SuppressWarnings("unused") @Shared("assumptionProfile") @Cached final InlinedExactClassProfile assumptionProfile,
@Cached final GetOrCreateContextNode getOrCreateContextNode) {
return getOrCreateContextNode.executeGet(frame);
@Cached(inline = true) final GetOrCreateContextNode getOrCreateContextNode) {
return getOrCreateContextNode.executeGet(frame, node);
}

protected static final boolean doesNotNeedSender(final CompiledCodeObject code, final InlinedExactClassProfile assumptionProfile, final Node node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,12 @@ public abstract static class PrimNewNode extends AbstractPrimitiveNode implement
public static final int NEW_CACHE_SIZE = 6;

@Specialization(limit = "NEW_CACHE_SIZE", guards = {"receiver == cachedReceiver"}, assumptions = {"cachedReceiver.getClassFormatStable()"})
protected final AbstractSqueakObjectWithClassAndHash newDirect(@SuppressWarnings("unused") final ClassObject receiver,
protected static final AbstractSqueakObjectWithClassAndHash newDirect(@SuppressWarnings("unused") final ClassObject receiver,
@Bind("this") final Node node,
@Cached("receiver.withEnsuredBehaviorHash()") final ClassObject cachedReceiver,
@Exclusive @Cached final SqueakObjectNewNode newNode) {
try {
return newNode.execute(getContext(), cachedReceiver);
return newNode.execute(node, getContext(node), cachedReceiver);
} catch (final OutOfMemoryError e) {
CompilerDirectives.transferToInterpreter();
throw PrimitiveFailed.INSUFFICIENT_OBJECT_MEMORY;
Expand All @@ -200,11 +201,12 @@ protected final AbstractSqueakObjectWithClassAndHash newDirect(@SuppressWarnings

@ReportPolymorphism.Megamorphic
@Specialization(replaces = "newDirect")
protected final AbstractSqueakObjectWithClassAndHash newIndirect(final ClassObject receiver,
protected static final AbstractSqueakObjectWithClassAndHash newIndirect(final ClassObject receiver,
@Bind("this") final Node node,
@Exclusive @Cached final SqueakObjectNewNode newNode) {
receiver.ensureBehaviorHash();
try {
return newNode.execute(getContext(), receiver);
return newNode.execute(node, getContext(node), receiver);
} catch (final OutOfMemoryError e) {
CompilerDirectives.transferToInterpreter();
throw PrimitiveFailed.INSUFFICIENT_OBJECT_MEMORY;
Expand All @@ -224,7 +226,7 @@ protected static final AbstractSqueakObjectWithClassAndHash newWithArgDirect(@Su
@Cached("receiver.withEnsuredBehaviorHash()") final ClassObject cachedReceiver,
@Exclusive @Cached final SqueakObjectNewNode newNode) {
try {
return newNode.execute(getContext(node), cachedReceiver, sizeProfile.profile(node, (int) size));
return newNode.execute(node, getContext(node), cachedReceiver, sizeProfile.profile(node, (int) size));
} catch (final OutOfMemoryError e) {
CompilerDirectives.transferToInterpreter();
throw PrimitiveFailed.INSUFFICIENT_OBJECT_MEMORY;
Expand All @@ -233,11 +235,12 @@ protected static final AbstractSqueakObjectWithClassAndHash newWithArgDirect(@Su

@ReportPolymorphism.Megamorphic
@Specialization(replaces = "newWithArgDirect", guards = "isInstantiable(receiver, size)")
protected final AbstractSqueakObjectWithClassAndHash newWithArg(final ClassObject receiver, final long size,
protected static final AbstractSqueakObjectWithClassAndHash newWithArg(final ClassObject receiver, final long size,
@Bind("this") final Node node,
@Exclusive @Cached final SqueakObjectNewNode newNode) {
receiver.ensureBehaviorHash();
try {
return newNode.execute(getContext(), receiver, (int) size);
return newNode.execute(node, getContext(node), receiver, (int) size);
} catch (final OutOfMemoryError e) {
CompilerDirectives.transferToInterpreter();
throw PrimitiveFailed.INSUFFICIENT_OBJECT_MEMORY;
Expand Down

2 comments on commit 1ed720a

@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 (1ed720a)

Benchmarks ran on graalvm-jdk-21+35.1.

Steady (after 100 iterations)

Benchmark Name Min Geomean Median Mean Max Total (ms) Total (min)
Bounce 526 535 528.66 527 528.65 105732 1.76
CD 439 476 442.69 440 442.67 88538 1.48
DeltaBlue 274 460 405.6 402 403.4 81120 1.35
Havlak 1145 1201 1177.16 1183 1177.08 235431 3.92
Json 353 363 356.13 354 356.12 71226 1.19
List 292 307 293.55 293 293.54 58710 0.98
Mandelbrot 125 143 126.36 126 126.34 25271 0.42
NBody 248 264 251.83 250 251.81 50366 0.84
Permute 149 165 151.38 150 151.34 30275 0.5
Queens 231 250 239.62 239.5 239.6 47923 0.8
Richards 1218 1261 1222.22 1222 1222.21 244444 4.07
Sieve 163 174 164.12 164 164.11 32824 0.55
Storage 138 147 140.32 139 140.3 28063 0.47
Towers 200 212 201.86 202 201.85 40371 0.67
5501 5958 5701.47 5691.5 5699.02 1140294 19

1ed720a-2-steady.svg

Warmup (first 100 iterations)

1ed720a-3-warmup.svg

@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 (1ed720a)

Benchmarks ran on graalvm-jdk-21+35.1.

Steady (after 100 iterations)

Benchmark Name Min Geomean Median Mean Max Total (ms) Total (min)
Bounce 525 533 527.71 526 527.7 105542 1.76
CD 439 532 453.46 449 453.25 90692 1.51
DeltaBlue 271 465 406.22 396 404.34 81244 1.35
Havlak 1110 1172 1144.51 1150 1144.41 228901 3.82
Json 395 566 454.48 457.5 452.62 90895 1.51
List 292 368 302.29 300 302.1 60457 1.01
Mandelbrot 125 137 125.86 126 125.85 25171 0.42
NBody 248 342 272.46 267 271.99 54492 0.91
Permute 149 165 150.55 150 150.53 30110 0.5
Queens 231 253 234.22 232 234.16 46843 0.78
Richards 1227 1237 1230.08 1229 1230.07 246015 4.1
Sieve 163 173 164.16 164 164.14 32831 0.55
Storage 137 144 138.93 138 138.9 27785 0.46
Towers 195 207 196.55 196 196.54 39310 0.66
5507 6294 5801.44 5780.5 5796.61 1160288 19.34

1ed720a-2-steady.svg

Warmup (first 100 iterations)

1ed720a-3-warmup.svg

Please sign in to comment.