@@ -57,7 +57,7 @@ public static GenericMessageSendNode createGeneric(final SSymbol selector,
57
57
final ExpressionNode [] argumentNodes , final SourceSection source ,
58
58
final Universe universe ) {
59
59
return new GenericMessageSendNode (
60
- selector , argumentNodes , universe , true ).initialize (source );
60
+ selector , argumentNodes , universe , 0 ).initialize (source );
61
61
}
62
62
63
63
public static AbstractMessageSendNode createSuperSend (final SClass superClass ,
@@ -116,22 +116,22 @@ public static final class GenericMessageSendNode
116
116
117
117
private final int numberOfSignatureArguments ;
118
118
119
- @ CompilationFinal private boolean triedEager ;
119
+ @ CompilationFinal private int numCacheNodes ;
120
120
121
121
@ Child private GuardedDispatchNode dispatchCache ;
122
122
123
123
private GenericMessageSendNode (final SSymbol selector , final ExpressionNode [] arguments ,
124
- final Universe universe , final boolean triedEager ) {
124
+ final Universe universe , final int numCacheNodes ) {
125
125
super (arguments );
126
126
this .selector = selector ;
127
127
this .universe = universe ;
128
- this .triedEager = triedEager ;
128
+ this .numCacheNodes = numCacheNodes ;
129
129
this .numberOfSignatureArguments = selector .getNumberOfSignatureArguments ();
130
130
}
131
131
132
132
private GenericMessageSendNode (final SSymbol selector , final ExpressionNode [] arguments ,
133
133
final Universe universe ) {
134
- this (selector , arguments , universe , false );
134
+ this (selector , arguments , universe , - 1 );
135
135
}
136
136
137
137
@ Override
@@ -190,19 +190,9 @@ public String toString() {
190
190
return "GMsgSend(" + selector .getString () + ")" ;
191
191
}
192
192
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
-
203
193
@ Override
204
194
public NodeCost getCost () {
205
- if (! triedEager ) {
195
+ if (numCacheNodes < 0 ) {
206
196
return NodeCost .UNINITIALIZED ;
207
197
}
208
198
@@ -212,7 +202,7 @@ public NodeCost getCost() {
212
202
return NodeCost .MEGAMORPHIC ;
213
203
}
214
204
215
- int cacheSize = getCacheSize ( cache ) ;
205
+ int cacheSize = numCacheNodes ;
216
206
217
207
if (cacheSize == 0 ) {
218
208
return NodeCost .UNINITIALIZED ;
@@ -226,8 +216,9 @@ public NodeCost getCost() {
226
216
}
227
217
228
218
private PreevaluatedExpression specialize (final Object [] arguments ) {
229
- if (!triedEager ) {
230
- triedEager = true ;
219
+ int cacheSize = numCacheNodes ;
220
+ if (cacheSize < 0 ) {
221
+ cacheSize = numCacheNodes = 0 ;
231
222
PreevaluatedExpression eager = attemptEagerSpecialization (arguments );
232
223
if (eager != null ) {
233
224
return eager ;
@@ -236,8 +227,6 @@ private PreevaluatedExpression specialize(final Object[] arguments) {
236
227
237
228
final GuardedDispatchNode first = dispatchCache ;
238
229
239
- int cacheSize = getCacheSize (first );
240
-
241
230
Object rcvr = arguments [0 ];
242
231
assert rcvr != null ;
243
232
@@ -280,6 +269,7 @@ private PreevaluatedExpression specialize(final Object[] arguments) {
280
269
node .next = node .insertHere (first );
281
270
}
282
271
dispatchCache = insert (node );
272
+ numCacheNodes = cacheSize + 1 ;
283
273
return node ;
284
274
}
285
275
@@ -288,6 +278,7 @@ private PreevaluatedExpression specialize(final Object[] arguments) {
288
278
GenericDispatchNode generic = new GenericDispatchNode (selector , universe );
289
279
dispatchCache = insert (generic );
290
280
reportPolymorphicSpecialize ();
281
+ numCacheNodes = cacheSize + 1 ;
291
282
return generic ;
292
283
}
293
284
0 commit comments