From 1daead2a5691745155e84eba2515cb2b3d841170 Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Sun, 17 Dec 2023 12:54:48 +0100 Subject: [PATCH] Minor perf-related improvements --- .../model/CompiledCodeObject.java | 6 +++--- .../nodes/bytecodes/JumpBytecodes.java | 4 ++-- .../nodes/bytecodes/SendBytecodes.java | 11 ++++++----- .../nodes/dispatch/DispatchSuperSendNode.java | 18 ++++++++---------- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/CompiledCodeObject.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/CompiledCodeObject.java index 0697e4569..38926b2f4 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/CompiledCodeObject.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/CompiledCodeObject.java @@ -574,7 +574,7 @@ public NativeObject getCompiledInSelector() { } /** CompiledMethod>>#methodClassAssociation. */ - private AbstractSqueakObject getMethodClassAssociation() { + private Object getMethodClassAssociation() { /** * From the CompiledMethod class description: * @@ -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; } diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/bytecodes/JumpBytecodes.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/bytecodes/JumpBytecodes.java index 508751978..37b8ba0f0 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/bytecodes/JumpBytecodes.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/bytecodes/JumpBytecodes.java @@ -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()); diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/bytecodes/SendBytecodes.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/bytecodes/SendBytecodes.java index 2904cad16..588f7c011 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/bytecodes/SendBytecodes.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/bytecodes/SendBytecodes.java @@ -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) { diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/dispatch/DispatchSuperSendNode.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/dispatch/DispatchSuperSendNode.java index 64cd09001..075605d14 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/dispatch/DispatchSuperSendNode.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/dispatch/DispatchSuperSendNode.java @@ -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) { @@ -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); } }