Skip to content

Commit

Permalink
Revisit usage of @ReportPolymorphism
Browse files Browse the repository at this point in the history
Reduce splitting and avoid excessive splitting in List benchmark
  • Loading branch information
fniephaus committed Aug 23, 2022
1 parent 90236d4 commit cb038ba
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -92,7 +91,6 @@ protected final Object[] createFrameArguments(final VirtualFrame frame, final Bl
}
}

@ReportPolymorphism
@GenerateNodeFactory
@SqueakPrimitive(indices = {201, 221})
@ImportStatic(AbstractClosurePrimitiveNode.class)
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -583,7 +582,6 @@ protected final Object doShallowCopy(final Object receiver,
}
}

@ReportPolymorphism
@GenerateNodeFactory
@ImportStatic(MiscUtils.class)
@SqueakPrimitive(indices = 149)
Expand Down

1 comment on commit cb038ba

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

Benchmarks ran on graalvm-ce-java17-22.2.0.

Steady (after 100 iterations)

Benchmark Name Min Geomean Median Mean Max Total (ms) Total (min)
Bounce 183 189 184.22 184 184.22 36844 0.61
CD 734 747 737.26 737 737.26 147452 2.46
DeltaBlue 384 555 477.7 490 476.57 95539 1.59
Havlak 1557 1631 1587.58 1586 1587.45 317515 5.29
Json 907 923 911.39 912 911.39 182278 3.04
List 507 514 508.64 508 508.63 101727 1.7
Mandelbrot 144 148 145.18 145 145.18 29036 0.48
NBody 271 282 274 274 273.99 54799 0.91
Permute 226 232 227.65 227 227.65 45530 0.76
Queens 249 277 251.6 251 251.57 50319 0.84
Richards 1073 1079 1076.53 1077 1076.53 215306 3.59
Sieve 208 242 209.43 209 209.42 41886 0.7
Storage 261 267 263.15 264 263.14 52629 0.88
Towers 341 349 342.63 342 342.63 68526 1.14
7045 7435 7196.93 7206 7195.61 1439386 23.99

cb038ba-2-steady.svg

Warmup (first 100 iterations)

cb038ba-3-warmup.svg

Please sign in to comment.