Skip to content

Commit

Permalink
Minor perf-related improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Dec 17, 2023
1 parent c54f576 commit 1daead2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ public NativeObject getCompiledInSelector() {
}

/** CompiledMethod>>#methodClassAssociation. */
private AbstractSqueakObject getMethodClassAssociation() {
private Object getMethodClassAssociation() {
/**
* From the CompiledMethod class description:
*
Expand All @@ -584,11 +584,11 @@ private AbstractSqueakObject getMethodClassAssociation() {
* may be nil (as would be the case for example of methods providing a pool of inst var
* accessors).
*/
return (AbstractSqueakObject) literals[literals.length - 1];
return literals[literals.length - 1];
}

public boolean hasMethodClass(final AbstractPointersObjectReadNode readNode, final Node inlineTarget) {
final AbstractSqueakObject mca = getMethodClassAssociation();
final Object mca = getMethodClassAssociation();
return mca != NilObject.SINGLETON && readNode.execute(inlineTarget, (AbstractPointersObject) mca, CLASS_BINDING.VALUE) != NilObject.SINGLETON;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public final void executeVoid(final VirtualFrame frame) {

public final boolean executeCondition(final VirtualFrame frame) {
final Object result = popNode.execute(frame);
if (result instanceof Boolean) {
return conditionProfile.profile(check((boolean) result));
if (result instanceof Boolean r) {
return conditionProfile.profile(check(r));
} else {
CompilerDirectives.transferToInterpreter();
FrameAccess.setInstructionPointer(frame, FrameAccess.getCodeObject(frame).getInitialPC() + getSuccessorIndex());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,25 @@ private AbstractSendNode(final CompiledCodeObject code, final int index, final i

@Override
public final void executeVoid(final VirtualFrame frame) {
Object result;
try {
decrementStackPointerByNumReceiverAndArguments(frame);
final Object result = dispatchSend(frame);
assert result != null : "Result of a message send should not be null";
getPushNode().execute(frame, result);
result = dispatchSend(frame);
} catch (final NonLocalReturn nlr) {
if (nlrProfile.profile(nlr.getTargetContextOrMarker() == FrameAccess.getMarker(frame) || nlr.getTargetContextOrMarker() == FrameAccess.getContext(frame))) {
getPushNode().execute(frame, nlr.getReturnValue());
result = nlr.getReturnValue();
} else {
throw nlr;
}
} catch (final NonVirtualReturn nvr) {
if (nvrProfile.profile(nvr.getTargetContext() == FrameAccess.getContext(frame))) {
getPushNode().execute(frame, nvr.getReturnValue());
result = nvr.getReturnValue();
} else {
throw nvr;
}
}
assert result != null : "Result of a message send should not be null";
getPushNode().execute(frame, result);
}

private void decrementStackPointerByNumReceiverAndArguments(final VirtualFrame frame) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@
*/
package de.hpi.swa.trufflesqueak.nodes.dispatch;

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 de.hpi.swa.trufflesqueak.model.ClassObject;
import de.hpi.swa.trufflesqueak.model.CompiledCodeObject;
import de.hpi.swa.trufflesqueak.model.NativeObject;
import de.hpi.swa.trufflesqueak.nodes.accessing.AbstractPointersObjectNodes.AbstractPointersObjectReadNode;

public abstract class DispatchSuperSendNode extends AbstractDispatchNode {
protected final CompiledCodeObject method;
protected final ClassObject methodClass;

public DispatchSuperSendNode(final CompiledCodeObject code, final NativeObject selector, final int argumentCount) {
super(selector, argumentCount);
method = code.getMethod();
/*
* Assuming method literals can no longer change the moment the method is executed for the
* first time, cache the method class. Its hierarchy must still be checked for stability.
*/
methodClass = code.getMethod().getMethodClassSlow();
}

public static DispatchSuperSendNode create(final CompiledCodeObject code, final NativeObject selector, final int argumentCount) {
Expand All @@ -31,12 +32,9 @@ public static DispatchSuperSendNode create(final CompiledCodeObject code, final

public abstract Object execute(VirtualFrame frame);

@Specialization(guards = {"method.getMethodClass(readNode, node) == cachedMethodClass"}, assumptions = {"cachedMethodClass.getClassHierarchyStable()", "dispatchNode.getCallTargetStable()"})
@Specialization(assumptions = {"methodClass.getClassHierarchyStable()", "dispatchNode.getCallTargetStable()"})
protected static final Object doCached(final VirtualFrame frame,
@SuppressWarnings("unused") @Bind("this") final Node node,
@SuppressWarnings("unused") @Cached final AbstractPointersObjectReadNode readNode,
@SuppressWarnings("unused") @Cached(value = "method.getMethodClassSlow()", neverDefault = false) final ClassObject cachedMethodClass,
@Cached("create(frame, selector, argumentCount, cachedMethodClass, lookupInSuperClassSlow(cachedMethodClass))") final CachedDispatchNode dispatchNode) {
@Cached("create(frame, selector, argumentCount, methodClass, lookupInSuperClassSlow(methodClass))") final CachedDispatchNode dispatchNode) {
return dispatchNode.execute(frame);
}
}

1 comment on commit 1daead2

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

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 539 534.3 533 534.29 106860 1.78
CD 475 487 478.29 476 478.27 95657 1.59
DeltaBlue 270 454 408.79 405 407.21 81758 1.36
Havlak 1124 1172 1154.9 1161 1154.82 230980 3.85
Json 367 378 370.29 369 370.27 74057 1.23
List 291 302 292.17 292 292.16 58433 0.97
Mandelbrot 125 141 126.49 126 126.48 25298 0.42
NBody 249 264 251.89 251 251.87 50377 0.84
Permute 150 162 151.16 151 151.14 30231 0.5
Queens 231 243 232.33 232 232.32 46465 0.77
Richards 1229 1245 1234.4 1234 1234.4 246880 4.11
Sieve 163 178 164.06 164 164.05 32812 0.55
Storage 137 146 138.81 138 138.79 27762 0.46
Towers 202 217 203.91 204 203.9 40781 0.68
5545 5928 5741.76 5736 5739.97 1148351 19.14

1daead2-2-steady.svg

Warmup (first 100 iterations)

1daead2-3-warmup.svg

Please sign in to comment.