diff --git a/src/trufflesom/interpreter/nodes/MessageSendNode.java b/src/trufflesom/interpreter/nodes/MessageSendNode.java index 71fbaf744..e497b213a 100644 --- a/src/trufflesom/interpreter/nodes/MessageSendNode.java +++ b/src/trufflesom/interpreter/nodes/MessageSendNode.java @@ -64,7 +64,7 @@ public static GenericMessageSendNode createGeneric(final SSymbol selector, final ExpressionNode[] argumentNodes, final SourceSection source, final Universe universe) { return new GenericMessageSendNode( - selector, argumentNodes, universe, true).initialize(source); + selector, argumentNodes, universe, 0).initialize(source); } public static AbstractMessageSendNode createSuperSend(final SClass superClass, @@ -123,22 +123,22 @@ public static final class GenericMessageSendNode private final int numberOfSignatureArguments; - @CompilationFinal private boolean triedEager; + @CompilationFinal private int numCacheNodes; @Child private GuardedDispatchNode dispatchCache; private GenericMessageSendNode(final SSymbol selector, final ExpressionNode[] arguments, - final Universe universe, final boolean triedEager) { + final Universe universe, final int numCacheNodes) { super(arguments); this.selector = selector; this.universe = universe; - this.triedEager = triedEager; + this.numCacheNodes = numCacheNodes; this.numberOfSignatureArguments = selector.getNumberOfSignatureArguments(); } private GenericMessageSendNode(final SSymbol selector, final ExpressionNode[] arguments, final Universe universe) { - this(selector, arguments, universe, false); + this(selector, arguments, universe, -1); } @Override @@ -197,19 +197,9 @@ public String toString() { return "GMsgSend(" + selector.getString() + ")"; } - private int getCacheSize(GuardedDispatchNode cache) { - int cacheSize = 0; - while (cache != null) { - cache = cache.next; - cacheSize += 1; - } - - return cacheSize; - } - @Override public NodeCost getCost() { - if (!triedEager) { + if (numCacheNodes < 0) { return NodeCost.UNINITIALIZED; } @@ -219,7 +209,7 @@ public NodeCost getCost() { return NodeCost.MEGAMORPHIC; } - int cacheSize = getCacheSize(cache); + int cacheSize = numCacheNodes; if (cacheSize == 0) { return NodeCost.UNINITIALIZED; @@ -233,8 +223,9 @@ public NodeCost getCost() { } private PreevaluatedExpression specialize(final Object[] arguments) { - if (!triedEager) { - triedEager = true; + int cacheSize = numCacheNodes; + if (cacheSize < 0) { + cacheSize = numCacheNodes = 0; PreevaluatedExpression eager = attemptEagerSpecialization(arguments); if (eager != null) { return eager; @@ -243,8 +234,6 @@ private PreevaluatedExpression specialize(final Object[] arguments) { final GuardedDispatchNode first = dispatchCache; - int cacheSize = getCacheSize(first); - Object rcvr = arguments[0]; assert rcvr != null; @@ -287,6 +276,7 @@ private PreevaluatedExpression specialize(final Object[] arguments) { node.next = node.insertHere(first); } dispatchCache = insert(node); + numCacheNodes = cacheSize + 1; return node; } @@ -295,6 +285,7 @@ private PreevaluatedExpression specialize(final Object[] arguments) { GenericDispatchNode generic = new GenericDispatchNode(selector, universe); dispatchCache = insert(generic); reportPolymorphicSpecialize(); + numCacheNodes = cacheSize + 1; return generic; }