Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit dc0b72f

Browse files
committedDec 4, 2021
Avoid traversing cache to determine size, instead keep it explicitly
Signed-off-by: Stefan Marr <[email protected]>
1 parent 31e20e0 commit dc0b72f

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed
 

‎src/trufflesom/interpreter/nodes/MessageSendNode.java

+12-21
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static GenericMessageSendNode createGeneric(final SSymbol selector,
5757
final ExpressionNode[] argumentNodes, final SourceSection source,
5858
final Universe universe) {
5959
return new GenericMessageSendNode(
60-
selector, argumentNodes, universe, true).initialize(source);
60+
selector, argumentNodes, universe, 0).initialize(source);
6161
}
6262

6363
public static AbstractMessageSendNode createSuperSend(final SClass superClass,
@@ -116,22 +116,22 @@ public static final class GenericMessageSendNode
116116

117117
private final int numberOfSignatureArguments;
118118

119-
@CompilationFinal private boolean triedEager;
119+
@CompilationFinal private int numCacheNodes;
120120

121121
@Child private GuardedDispatchNode dispatchCache;
122122

123123
private GenericMessageSendNode(final SSymbol selector, final ExpressionNode[] arguments,
124-
final Universe universe, final boolean triedEager) {
124+
final Universe universe, final int numCacheNodes) {
125125
super(arguments);
126126
this.selector = selector;
127127
this.universe = universe;
128-
this.triedEager = triedEager;
128+
this.numCacheNodes = numCacheNodes;
129129
this.numberOfSignatureArguments = selector.getNumberOfSignatureArguments();
130130
}
131131

132132
private GenericMessageSendNode(final SSymbol selector, final ExpressionNode[] arguments,
133133
final Universe universe) {
134-
this(selector, arguments, universe, false);
134+
this(selector, arguments, universe, -1);
135135
}
136136

137137
@Override
@@ -190,19 +190,9 @@ public String toString() {
190190
return "GMsgSend(" + selector.getString() + ")";
191191
}
192192

193-
private int getCacheSize(GuardedDispatchNode cache) {
194-
int cacheSize = 0;
195-
while (cache != null) {
196-
cache = cache.next;
197-
cacheSize += 1;
198-
}
199-
200-
return cacheSize;
201-
}
202-
203193
@Override
204194
public NodeCost getCost() {
205-
if (!triedEager) {
195+
if (numCacheNodes < 0) {
206196
return NodeCost.UNINITIALIZED;
207197
}
208198

@@ -212,7 +202,7 @@ public NodeCost getCost() {
212202
return NodeCost.MEGAMORPHIC;
213203
}
214204

215-
int cacheSize = getCacheSize(cache);
205+
int cacheSize = numCacheNodes;
216206

217207
if (cacheSize == 0) {
218208
return NodeCost.UNINITIALIZED;
@@ -226,8 +216,9 @@ public NodeCost getCost() {
226216
}
227217

228218
private PreevaluatedExpression specialize(final Object[] arguments) {
229-
if (!triedEager) {
230-
triedEager = true;
219+
int cacheSize = numCacheNodes;
220+
if (cacheSize < 0) {
221+
cacheSize = numCacheNodes = 0;
231222
PreevaluatedExpression eager = attemptEagerSpecialization(arguments);
232223
if (eager != null) {
233224
return eager;
@@ -236,8 +227,6 @@ private PreevaluatedExpression specialize(final Object[] arguments) {
236227

237228
final GuardedDispatchNode first = dispatchCache;
238229

239-
int cacheSize = getCacheSize(first);
240-
241230
Object rcvr = arguments[0];
242231
assert rcvr != null;
243232

@@ -280,6 +269,7 @@ private PreevaluatedExpression specialize(final Object[] arguments) {
280269
node.next = node.insertHere(first);
281270
}
282271
dispatchCache = insert(node);
272+
numCacheNodes = cacheSize + 1;
283273
return node;
284274
}
285275

@@ -288,6 +278,7 @@ private PreevaluatedExpression specialize(final Object[] arguments) {
288278
GenericDispatchNode generic = new GenericDispatchNode(selector, universe);
289279
dispatchCache = insert(generic);
290280
reportPolymorphicSpecialize();
281+
numCacheNodes = cacheSize + 1;
291282
return generic;
292283
}
293284

0 commit comments

Comments
 (0)
Please sign in to comment.