Skip to content

Commit

Permalink
Avoid traversing cache to determine size, instead keep it explicitly
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Marr <[email protected]>
  • Loading branch information
smarr committed Nov 24, 2021
1 parent d27013f commit 1b070e8
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions src/trufflesom/interpreter/nodes/MessageSendNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand All @@ -219,7 +209,7 @@ public NodeCost getCost() {
return NodeCost.MEGAMORPHIC;
}

int cacheSize = getCacheSize(cache);
int cacheSize = numCacheNodes;

if (cacheSize == 0) {
return NodeCost.UNINITIALIZED;
Expand All @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -287,6 +276,7 @@ private PreevaluatedExpression specialize(final Object[] arguments) {
node.next = node.insertHere(first);
}
dispatchCache = insert(node);
numCacheNodes = cacheSize + 1;
return node;
}

Expand All @@ -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;
}

Expand Down

0 comments on commit 1b070e8

Please sign in to comment.