Skip to content

Commit

Permalink
Revise AboutToReturnImplNode
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Dec 22, 2023
1 parent 678bb1a commit be5b7f8
Showing 1 changed file with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
import de.hpi.swa.trufflesqueak.model.BooleanObject;
import de.hpi.swa.trufflesqueak.model.CompiledCodeObject;
import de.hpi.swa.trufflesqueak.model.ContextObject;
import de.hpi.swa.trufflesqueak.model.NilObject;
import de.hpi.swa.trufflesqueak.nodes.AboutToReturnNodeFactory.AboutToReturnImplNodeGen;
import de.hpi.swa.trufflesqueak.nodes.context.TemporaryWriteMarkContextsNode;
import de.hpi.swa.trufflesqueak.nodes.context.frame.FrameStackReadNode;
import de.hpi.swa.trufflesqueak.nodes.context.frame.FrameStackWriteNode;
import de.hpi.swa.trufflesqueak.nodes.context.frame.GetContextOrMarkerNode;
import de.hpi.swa.trufflesqueak.nodes.context.frame.GetOrCreateContextNode;
import de.hpi.swa.trufflesqueak.nodes.dispatch.DispatchClosureNode;
import de.hpi.swa.trufflesqueak.util.FrameAccess;

Expand All @@ -42,6 +44,26 @@ public static AboutToReturnNode create(final CompiledCodeObject code) {

@ImportStatic(FrameStackReadNode.class)
protected abstract static class AboutToReturnImplNode extends AboutToReturnNode {
@Specialization(guards = {"!hasModifiedSender(frame)"})
protected final void doAboutToReturnVirtualizedNothing(final VirtualFrame frame, final NonLocalReturn nlr,
@Cached("createTemporaryReadNode(frame, 1)") final FrameStackReadNode completeTempReadNode,
@Cached final DispatchVirtualAboutToReturnNode dispatchVirtualAboutToReturnNode) {
dispatchVirtualAboutToReturnNode.execute(frame, completeTempReadNode.executeRead(frame) == NilObject.SINGLETON);
}

@Specialization(guards = {"hasModifiedSender(frame)"})
protected static final void doAboutToReturn(final VirtualFrame frame, final NonLocalReturn nlr,
@Bind("this") final Node node,
@Cached final GetOrCreateContextNode getOrCreateContextNode,
@Cached("createAboutToReturnSend()") final SendSelectorNode sendAboutToReturnNode) {
assert nlr.getTargetContextOrMarker() instanceof ContextObject;
sendAboutToReturnNode.executeSend(frame, new Object[]{getOrCreateContextNode.executeGet(frame, node), nlr.getReturnValue(), nlr.getTargetContextOrMarker()});
}
}

protected abstract static class DispatchVirtualAboutToReturnNode extends AbstractNode {

protected abstract void execute(VirtualFrame frame, boolean completeTempIsNil);

/*
* Virtualized version of Context>>aboutToReturn:through:, more specifically
Expand All @@ -50,32 +72,22 @@ protected abstract static class AboutToReturnImplNode extends AboutToReturnNode
* handled. Note that this however does not check if the current context isDead nor does it
* terminate contexts (this may be a problem).
*/
@Specialization(guards = {"!hasModifiedSender(frame)", "isNil(completeTempReadNode.executeRead(frame))"}, limit = "1")
protected static final void doAboutToReturnVirtualized(final VirtualFrame frame, @SuppressWarnings("unused") final NonLocalReturn nlr,
@Specialization(guards = {"completeTempIsNil"})
protected static final void doVirtualized(final VirtualFrame frame, @SuppressWarnings("unused") final boolean completeTempIsNil,
@Bind("this") final Node node,
@Cached("createTemporaryReadNode(frame, 0)") final FrameStackReadNode blockArgumentNode,
@SuppressWarnings("unused") @Cached("createTemporaryReadNode(frame, 1)") final FrameStackReadNode completeTempReadNode,
@Cached("create(frame, 1)") final TemporaryWriteMarkContextsNode completeTempWriteNode,
@Cached("create(frame, 1)") final FrameStackWriteNode completeTempWriteNode,
@Cached final GetContextOrMarkerNode getContextOrMarkerNode,
@Cached final DispatchClosureNode dispatchNode) {
completeTempWriteNode.executeWrite(frame, BooleanObject.TRUE);
final BlockClosureObject closure = (BlockClosureObject) blockArgumentNode.executeRead(frame);
dispatchNode.execute(node, closure, FrameAccess.newClosureArgumentsTemplate(closure, getContextOrMarkerNode.execute(frame), 0));
}

@SuppressWarnings("unused")
@Specialization(guards = {"!hasModifiedSender(frame)", "!isNil(completeTempReadNode.executeRead(frame))"}, limit = "1")
protected final void doAboutToReturnVirtualizedNothing(final VirtualFrame frame, final NonLocalReturn nlr,
@Cached("createTemporaryReadNode(frame, 1)") final FrameStackReadNode completeTempReadNode) {
@Specialization(guards = {"!completeTempIsNil"})
protected static final void doAboutToReturnVirtualizedNothing(@SuppressWarnings("unused") final boolean completeTempIsNil) {
// Nothing to do.
}

@Specialization(guards = {"hasModifiedSender(frame)"})
protected static final void doAboutToReturn(final VirtualFrame frame, final NonLocalReturn nlr,
@Cached("createAboutToReturnSend()") final SendSelectorNode sendAboutToReturnNode) {
assert nlr.getTargetContextOrMarker() instanceof ContextObject;
sendAboutToReturnNode.executeSend(frame, new Object[]{FrameAccess.getContext(frame), nlr.getReturnValue(), nlr.getTargetContextOrMarker()});
}
}

@DenyReplace
Expand Down

1 comment on commit be5b7f8

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

Benchmarks ran on graalvm-jdk-21+35.1.

Steady (after 100 iterations)

Benchmark Name Min Geomean Median Mean Max Total (ms) Total (min)
Bounce 556 568 559.12 558 559.11 111823 1.86
CD 519 670 606.32 608 605.94 121264 2.02
DeltaBlue 303 845 624.71 641 615.9 124941 2.08
Havlak 1146 1203 1177.74 1182 1177.67 235548 3.93
Json 412 490 443.89 439 443.06 88778 1.48
List 377 390 377.69 377 377.69 75538 1.26
Mandelbrot 229 251 233.09 234 233.07 46618 0.78
NBody 260 320 280.03 279 279.92 56006 0.93
Permute 154 164 155.52 155 155.51 31104 0.52
Queens 247 268 249.71 248 249.68 49941 0.83
Richards 1229 1274 1236.36 1236 1236.35 247272 4.12
Sieve 178 252 183.01 182 182.89 36602 0.61
Storage 140 149 142.38 141 142.35 28475 0.47
Towers 195 212 196.08 196 196.06 39215 0.65
5945 7056 6465.63 6476 6455.21 1293125 21.55

be5b7f8-2-steady.svg

Warmup (first 100 iterations)

be5b7f8-3-warmup.svg

Please sign in to comment.