Skip to content

Commit

Permalink
Revise PrimEnterCriticalSection(1|2)Node
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Dec 16, 2023
1 parent 5205c66 commit 652e482
Showing 1 changed file with 25 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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.Fallback;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.NodeFactory;
Expand Down Expand Up @@ -58,6 +59,7 @@
import de.hpi.swa.trufflesqueak.model.layout.ObjectLayouts.PROCESS;
import de.hpi.swa.trufflesqueak.model.layout.ObjectLayouts.PROCESS_SCHEDULER;
import de.hpi.swa.trufflesqueak.model.layout.ObjectLayouts.SEMAPHORE;
import de.hpi.swa.trufflesqueak.nodes.AbstractNode;
import de.hpi.swa.trufflesqueak.nodes.InheritsFromNode;
import de.hpi.swa.trufflesqueak.nodes.LookupMethodNode;
import de.hpi.swa.trufflesqueak.nodes.accessing.AbstractPointersObjectNodes.AbstractPointersObjectReadNode;
Expand Down Expand Up @@ -995,79 +997,46 @@ protected final Object doExitNonEmpty(final VirtualFrame frame, final PointersOb

@GenerateNodeFactory
@SqueakPrimitive(indices = 186)
protected abstract static class AbstractPrimEnterCriticalSectionNode extends AbstractPrimitiveNode {
@Child private AbstractPointersObjectReadNode readNode = AbstractPointersObjectReadNode.create();

protected final boolean ownerIsNil(final PointersObject mutex) {
return readNode.execute(mutex, MUTEX.OWNER) == NilObject.SINGLETON;
}

protected final boolean activeProcessMutexOwner(final PointersObject mutex, final GetActiveProcessNode getActiveProcessNode, final Node inlineTarget) {
return readNode.execute(mutex, MUTEX.OWNER) == getActiveProcessNode.execute(inlineTarget);
}

protected final boolean isMutexOwner(final PointersObject mutex, final PointersObject effectiveProcess) {
return readNode.execute(mutex, MUTEX.OWNER) == effectiveProcess;
protected abstract static class PrimEnterCriticalSection1Node extends AbstractPrimitiveNode implements UnaryPrimitiveFallback {
@Specialization
protected static final Object doEnter(final VirtualFrame frame, final PointersObject mutex,
@Bind("this") final Node node,
@Cached final AbstractPointersObjectReadNode readNode,
@Cached final EnterCriticalSectionNode enterCriticalSectionNode,
@Cached final GetActiveProcessNode getActiveProcessNode) {
return enterCriticalSectionNode.execute(frame, mutex, readNode.execute(mutex, MUTEX.OWNER), getActiveProcessNode.execute(node));
}
}

@GenerateNodeFactory
@SqueakPrimitive(indices = 186)
protected abstract static class PrimEnterCriticalSection1Node extends AbstractPrimEnterCriticalSectionNode implements UnaryPrimitiveFallback {
@Specialization(guards = "ownerIsNil(mutex)")
protected static final boolean doEnterNilOwner(final PointersObject mutex,
@Bind("this") final Node node,
@Cached final AbstractPointersObjectWriteNode writeNode,
@Shared("getActiveProcessNode") @Cached final GetActiveProcessNode getActiveProcessNode) {
writeNode.execute(mutex, MUTEX.OWNER, getActiveProcessNode.execute(node));
return BooleanObject.FALSE;
}

@SuppressWarnings("unused")
@Specialization(guards = "activeProcessMutexOwner(mutex, getActiveProcessNode, node)")
protected static final boolean doEnterActiveProcessOwner(final PointersObject mutex,
@Bind("this") final Node node,
@Shared("getActiveProcessNode") @Cached final GetActiveProcessNode getActiveProcessNode) {
return BooleanObject.TRUE;
}

@Specialization(guards = {"!ownerIsNil(mutex)", "!activeProcessMutexOwner(mutex, getActiveProcessNode, node)"}, limit = "1")
protected static final Object doEnter(final VirtualFrame frame, final PointersObject mutex,
@Bind("this") final Node node,
@Cached final AddLastLinkToListNode addLastLinkToListNode,
@Cached final WakeHighestPriorityNode wakeHighestPriorityNode,
@Exclusive @Cached final GetActiveProcessNode getActiveProcessNode,
@Cached final FrameStackPushNode pushNode) {
addLastLinkToListNode.execute(node, getActiveProcessNode.execute(node), mutex);
try {
wakeHighestPriorityNode.executeWake(frame, node);
} catch (final ProcessSwitch ps) {
/* Leave `false` as result on stack. */
pushNode.execute(frame, BooleanObject.FALSE);
throw ps;
}
throw CompilerDirectives.shouldNotReachHere();
protected abstract static class PrimEnterCriticalSection2Node extends AbstractPrimitiveNode implements BinaryPrimitiveFallback {
@Specialization
protected static final Object doEnter(final VirtualFrame frame, final PointersObject mutex, final PointersObject effectiveProcess,
@Cached final AbstractPointersObjectReadNode readNode,
@Cached final EnterCriticalSectionNode enterCriticalSectionNode) {
return enterCriticalSectionNode.execute(frame, mutex, readNode.execute(mutex, MUTEX.OWNER), effectiveProcess);
}
}

@GenerateNodeFactory
@SqueakPrimitive(indices = 186)
protected abstract static class PrimEnterCriticalSection2Node extends AbstractPrimEnterCriticalSectionNode implements BinaryPrimitiveFallback {
@Specialization(guards = "ownerIsNil(mutex)")
protected static final boolean doEnterNilOwner(final PointersObject mutex, @SuppressWarnings("unused") final PointersObject effectiveProcess,
protected abstract static class EnterCriticalSectionNode extends AbstractNode {
protected abstract Object execute(VirtualFrame frame, PointersObject mutex, Object mutexOwner, PointersObject effectiveProcess);

@Specialization
protected static final boolean doEnterNilOwner(final PointersObject mutex, @SuppressWarnings("unused") final NilObject mutexOwner, final PointersObject effectiveProcess,
@Cached final AbstractPointersObjectWriteNode writeNode) {
writeNode.execute(mutex, MUTEX.OWNER, effectiveProcess);
return BooleanObject.FALSE;
}

@SuppressWarnings("unused")
@Specialization(guards = "isMutexOwner(mutex, effectiveProcess)")
protected static final boolean doEnterActiveProcessOwner(final PointersObject mutex, final PointersObject effectiveProcess) {
@Specialization(guards = "mutexOwner == effectiveProcess")
protected static final boolean doEnterActiveProcessOwner(final PointersObject mutex, final PointersObject mutexOwner, final PointersObject effectiveProcess) {
return BooleanObject.TRUE;
}

@Specialization(guards = {"!ownerIsNil(mutex)", "!isMutexOwner(mutex, effectiveProcess)"})
protected static final Object doEnter(final VirtualFrame frame, final PointersObject mutex, @SuppressWarnings("unused") final PointersObject effectiveProcess,
@Fallback
protected static final Object doEnter(final VirtualFrame frame, final PointersObject mutex, @SuppressWarnings("unused") final Object mutexOwner, final PointersObject effectiveProcess,
@Bind("this") final Node node,
@Cached final AddLastLinkToListNode addLastLinkToListNode,
@Cached final WakeHighestPriorityNode wakeHighestPriorityNode,
Expand Down

1 comment on commit 652e482

@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 (652e482)

Benchmarks ran on graalvm-jdk-21+35.1.

Steady (after 100 iterations)

Benchmark Name Min Geomean Median Mean Max Total (ms) Total (min)
Bounce 529 539 531.95 530 531.94 106390 1.77
CD 475 489 479.97 478 479.95 95994 1.6
DeltaBlue 274 465 404.93 402 403.57 80985 1.35
Havlak 1116 1172 1150.59 1156 1150.5 230118 3.84
Json 369 380 371.63 370 371.62 74326 1.24
List 293 307 295.39 294 295.37 59078 0.98
Mandelbrot 125 135 125.75 126 125.74 25150 0.42
NBody 248 263 251.69 250 251.67 50338 0.84
Permute 149 160 150.45 150 150.44 30090 0.5
Queens 232 244 234.45 234 234.44 46889 0.78
Richards 1210 1225 1214.27 1215 1214.27 242854 4.05
Sieve 163 173 164.1 164 164.08 32819 0.55
Storage 140 151 141.87 141 141.85 28374 0.47
Towers 194 210 195.83 195 195.82 39166 0.65
5517 5913 5712.86 5705 5711.28 1142571 19.04

652e482-2-steady.svg

Warmup (first 100 iterations)

652e482-3-warmup.svg

Please sign in to comment.