From cb038ba3d24c52e3a949104532b02fd1b2c82439 Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Tue, 23 Aug 2022 10:26:26 +0200 Subject: [PATCH] Revisit usage of `@ReportPolymorphism` Reduce splitting and avoid excessive splitting in List benchmark --- .../trufflesqueak/nodes/LookupMethodNode.java | 2 +- .../nodes/dispatch/DispatchEagerlyNode.java | 3 ++- .../nodes/dispatch/DispatchLookupResultNode.java | 2 +- .../primitives/impl/BlockClosurePrimitives.java | 16 ++++++++++++++-- .../primitives/impl/MiscellaneousPrimitives.java | 2 -- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/LookupMethodNode.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/LookupMethodNode.java index 4ca17bd32..a691acae2 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/LookupMethodNode.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/LookupMethodNode.java @@ -16,7 +16,6 @@ import de.hpi.swa.trufflesqueak.util.MethodCacheEntry; @GenerateUncached -@ReportPolymorphism public abstract class LookupMethodNode extends AbstractNode { protected static final int LOOKUP_CACHE_SIZE = 6; @@ -40,6 +39,7 @@ protected static final Object doCached(final ClassObject classObject, final Nati return cachedMethod; } + @ReportPolymorphism.Megamorphic @Specialization(replaces = "doCached") protected final Object doUncached(final ClassObject classObject, final NativeObject selector) { final MethodCacheEntry cachedEntry = getContext().findMethodCacheEntry(classObject, selector); diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/dispatch/DispatchEagerlyNode.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/dispatch/DispatchEagerlyNode.java index 60a15039c..c21242459 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/dispatch/DispatchEagerlyNode.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/dispatch/DispatchEagerlyNode.java @@ -29,7 +29,6 @@ import de.hpi.swa.trufflesqueak.util.FrameAccess; import de.hpi.swa.trufflesqueak.util.PrimitiveFailedCounter; -@ReportPolymorphism @ImportStatic({PrimitiveNodeFactory.class, ArgumentsLocation.class}) public abstract class DispatchEagerlyNode extends AbstractNode { protected static final int INLINE_CACHE_SIZE = 6; @@ -79,6 +78,7 @@ protected final Object doDirectWithSender(final VirtualFrame frame, @SuppressWar return callDirect(callNode, cachedMethod, getOrCreateContext(frame), receiverAndArguments); } + @ReportPolymorphism.Megamorphic @Specialization(guards = "doesNotNeedSender(method, assumptionProfile)", replaces = {"doDirect", "doDirectWithSender"}, limit = "1") protected static final Object doIndirect(final VirtualFrame frame, final CompiledCodeObject method, final Object[] receiverAndArguments, @Cached final GetContextOrMarkerNode getContextOrMarkerNode, @@ -87,6 +87,7 @@ protected static final Object doIndirect(final VirtualFrame frame, final Compile return callIndirect(callNode, method, getContextOrMarkerNode.execute(frame), receiverAndArguments); } + @ReportPolymorphism.Megamorphic @Specialization(guards = "!doesNotNeedSender(method, assumptionProfile)", replaces = {"doDirect", "doDirectWithSender"}, limit = "1") protected final Object doIndirectWithSender(final VirtualFrame frame, final CompiledCodeObject method, final Object[] receiverAndArguments, @SuppressWarnings("unused") @Shared("assumptionProfile") @Cached("createClassProfile()") final ValueProfile assumptionProfile, diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/dispatch/DispatchLookupResultNode.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/dispatch/DispatchLookupResultNode.java index a94666061..00c345d91 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/dispatch/DispatchLookupResultNode.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/dispatch/DispatchLookupResultNode.java @@ -19,7 +19,6 @@ import de.hpi.swa.trufflesqueak.nodes.bytecodes.SendBytecodes.SelfSendNode; import de.hpi.swa.trufflesqueak.nodes.dispatch.CreateFrameArgumentNodes.CreateFrameArgumentsForIndirectCallNode; -@ReportPolymorphism @ImportStatic(SelfSendNode.class) public abstract class DispatchLookupResultNode extends AbstractDispatchNode { public DispatchLookupResultNode(final NativeObject selector, final int argumentCount) { @@ -40,6 +39,7 @@ protected static final Object doCached(final VirtualFrame frame, final Object re return dispatchNode.execute(frame); } + @ReportPolymorphism.Megamorphic @Specialization(replaces = "doCached") protected final Object doIndirect(final VirtualFrame frame, final Object receiver, final ClassObject receiverClass, final Object lookupResult, @Cached final ResolveMethodNode methodNode, diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/BlockClosurePrimitives.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/BlockClosurePrimitives.java index 4065435a6..fb330369d 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/BlockClosurePrimitives.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/BlockClosurePrimitives.java @@ -38,7 +38,6 @@ public final class BlockClosurePrimitives extends AbstractPrimitiveFactoryHolder { - @ReportPolymorphism public abstract static class AbstractClosurePrimitiveNode extends AbstractPrimitiveNode { protected static final int INLINE_CACHE_SIZE = 3; @@ -92,7 +91,6 @@ protected final Object[] createFrameArguments(final VirtualFrame frame, final Bl } } - @ReportPolymorphism @GenerateNodeFactory @SqueakPrimitive(indices = {201, 221}) @ImportStatic(AbstractClosurePrimitiveNode.class) @@ -106,6 +104,7 @@ protected final Object doValueDirect(final VirtualFrame frame, final BlockClosur return directCallNode.call(FrameAccess.newClosureArgumentsTemplate(closure, cachedBlock.getOuterMethod(), getContextOrMarkerNode.execute(frame), 0)); } + @ReportPolymorphism.Megamorphic @Specialization(guards = {"closure.getNumArgs() == 0"}, replaces = "doValueDirect") protected final Object doValueIndirect(final VirtualFrame frame, final BlockClosureObject closure, @Cached final IndirectCallNode indirectCallNode) { @@ -124,6 +123,7 @@ protected final Object doValueDirect(final VirtualFrame frame, final BlockClosur return directCallNode.call(createFrameArguments(frame, closure, cachedBlock.getOuterMethod(), arg)); } + @ReportPolymorphism.Megamorphic @Specialization(guards = {"closure.getNumArgs() == 1"}, replaces = "doValueDirect") protected final Object doValueIndirect(final VirtualFrame frame, final BlockClosureObject closure, final Object arg, @Cached final IndirectCallNode indirectCallNode) { @@ -142,6 +142,7 @@ protected final Object doValueDirect(final VirtualFrame frame, final BlockClosur return directCallNode.call(createFrameArguments(frame, closure, cachedBlock.getOuterMethod(), arg1, arg2)); } + @ReportPolymorphism.Megamorphic @Specialization(guards = {"closure.getNumArgs() == 2"}, replaces = "doValueDirect") protected final Object doValueIndirect(final VirtualFrame frame, final BlockClosureObject closure, final Object arg1, final Object arg2, @Cached final IndirectCallNode indirectCallNode) { @@ -160,6 +161,7 @@ protected final Object doValueDirect(final VirtualFrame frame, final BlockClosur return directCallNode.call(createFrameArguments(frame, closure, cachedBlock.getOuterMethod(), arg1, arg2, arg3)); } + @ReportPolymorphism.Megamorphic @Specialization(guards = {"closure.getNumArgs() == 3"}, replaces = "doValueDirect") protected final Object doValueIndirect(final VirtualFrame frame, final BlockClosureObject closure, final Object arg1, final Object arg2, final Object arg3, @Cached final IndirectCallNode indirectCallNode) { @@ -178,6 +180,7 @@ protected final Object doValueDirect(final VirtualFrame frame, final BlockClosur return directCallNode.call(createFrameArguments(frame, closure, cachedBlock.getOuterMethod(), arg1, arg2, arg3, arg4)); } + @ReportPolymorphism.Megamorphic @Specialization(guards = {"closure.getNumArgs() == 4"}, replaces = "doValueDirect") protected final Object doValueIndirect(final VirtualFrame frame, final BlockClosureObject closure, final Object arg1, final Object arg2, final Object arg3, final Object arg4, @Cached final IndirectCallNode indirectCallNode) { @@ -197,6 +200,7 @@ protected final Object doValue5Direct(final VirtualFrame frame, final BlockClosu return directCallNode.call(createFrameArguments(frame, closure, cachedBlock.getOuterMethod(), arg1, arg2, arg3, arg4, arg5)); } + @ReportPolymorphism.Megamorphic @Specialization(guards = {"closure.getNumArgs() == 5"}, replaces = "doValue5Direct") protected final Object doValue5Indirect(final VirtualFrame frame, final BlockClosureObject closure, final Object arg1, final Object arg2, final Object arg3, final Object arg4, final Object arg5, @@ -221,6 +225,7 @@ protected final Object doValueDirect(final VirtualFrame frame, final BlockClosur return directCallNode.call(frameArguments); } + @ReportPolymorphism.Megamorphic @Specialization(guards = {"closure.getNumArgs() == sizeNode.execute(argArray)"}, replaces = "doValueDirect", limit = "1") protected final Object doValueIndirect(final VirtualFrame frame, final BlockClosureObject closure, final ArrayObject argArray, @SuppressWarnings("unused") @Cached final SqueakObjectSizeNode sizeNode, @@ -244,6 +249,7 @@ protected final Object doValue0Direct(final VirtualFrame frame, final BlockClosu return directCallNode.call(createFrameArguments(frame, closure, cachedBlock)); } + @ReportPolymorphism.Megamorphic @Specialization(guards = {"block.getNumArgs() == 0"}, replaces = "doValue0Direct") protected final Object doValue0Indirect(final VirtualFrame frame, final BlockClosureObject closure, @Bind("closure.getCompiledBlock()") final CompiledCodeObject block, @@ -263,6 +269,7 @@ protected final Object doValue1Direct(final VirtualFrame frame, final BlockClosu return directCallNode.call(createFrameArguments(frame, closure, cachedBlock, arg1)); } + @ReportPolymorphism.Megamorphic @Specialization(guards = {"block.getNumArgs() == 1"}, replaces = "doValue1Direct") protected final Object doValue1Indirect(final VirtualFrame frame, final BlockClosureObject closure, final Object arg1, @Bind("closure.getCompiledBlock()") final CompiledCodeObject block, @@ -282,6 +289,7 @@ protected final Object doValue2Direct(final VirtualFrame frame, final BlockClosu return directCallNode.call(createFrameArguments(frame, closure, cachedBlock, arg1, arg2)); } + @ReportPolymorphism.Megamorphic @Specialization(guards = {"block.getNumArgs() == 2"}, replaces = "doValue2Direct") protected final Object doValue2Indirect(final VirtualFrame frame, final BlockClosureObject closure, final Object arg1, final Object arg2, @Bind("closure.getCompiledBlock()") final CompiledCodeObject block, @@ -301,6 +309,7 @@ protected final Object doValue3Direct(final VirtualFrame frame, final BlockClosu return directCallNode.call(createFrameArguments(frame, closure, cachedBlock, arg1, arg2, arg3)); } + @ReportPolymorphism.Megamorphic @Specialization(guards = {"block.getNumArgs() == 3"}, replaces = "doValue3Direct") protected final Object doValue3Indirect(final VirtualFrame frame, final BlockClosureObject closure, final Object arg1, final Object arg2, final Object arg3, @Bind("closure.getCompiledBlock()") final CompiledCodeObject block, @@ -320,6 +329,7 @@ protected final Object doValue4Direct(final VirtualFrame frame, final BlockClosu return directCallNode.call(createFrameArguments(frame, closure, cachedBlock, arg1, arg2, arg3, arg4)); } + @ReportPolymorphism.Megamorphic @Specialization(guards = {"block.getNumArgs() == 4"}, replaces = "doValue4Direct") protected final Object doValue4Indirect(final VirtualFrame frame, final BlockClosureObject closure, final Object arg1, final Object arg2, final Object arg3, final Object arg4, @Bind("closure.getCompiledBlock()") final CompiledCodeObject block, @@ -340,6 +350,7 @@ protected final Object doValue5Direct(final VirtualFrame frame, final BlockClosu return directCallNode.call(createFrameArguments(frame, closure, cachedBlock, arg1, arg2, arg3, arg4, arg5)); } + @ReportPolymorphism.Megamorphic @Specialization(guards = {"block.getNumArgs() == 5"}, replaces = "doValue5Direct") protected final Object doValue5Indirect(final VirtualFrame frame, final BlockClosureObject closure, final Object arg1, final Object arg2, final Object arg3, final Object arg4, final Object arg5, @@ -364,6 +375,7 @@ protected final Object doValueDirect(final VirtualFrame frame, final BlockClosur return directCallNode.call(frameArguments); } + @ReportPolymorphism.Megamorphic @Specialization(guards = {"closure.getCompiledBlock().getNumArgs() == sizeNode.execute(argArray)"}, replaces = "doValueDirect", limit = "1") protected final Object doValueIndirect(final VirtualFrame frame, final BlockClosureObject closure, final ArrayObject argArray, @SuppressWarnings("unused") @Cached final SqueakObjectSizeNode sizeNode, diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/MiscellaneousPrimitives.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/MiscellaneousPrimitives.java index 976db8e27..3549fc611 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/MiscellaneousPrimitives.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/MiscellaneousPrimitives.java @@ -18,7 +18,6 @@ import com.oracle.truffle.api.dsl.GenerateNodeFactory; import com.oracle.truffle.api.dsl.ImportStatic; import com.oracle.truffle.api.dsl.NodeFactory; -import com.oracle.truffle.api.dsl.ReportPolymorphism; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.nodes.DenyReplace; import com.oracle.truffle.api.nodes.NodeCost; @@ -583,7 +582,6 @@ protected final Object doShallowCopy(final Object receiver, } } - @ReportPolymorphism @GenerateNodeFactory @ImportStatic(MiscUtils.class) @SqueakPrimitive(indices = 149)