@@ -64,7 +64,7 @@ public static GenericMessageSendNode createGeneric(final SSymbol selector,
64
64
final ExpressionNode [] argumentNodes , final SourceSection source ,
65
65
final Universe universe ) {
66
66
return new GenericMessageSendNode (
67
- selector , argumentNodes , universe , true ).initialize (source );
67
+ selector , argumentNodes , universe , 0 ).initialize (source );
68
68
}
69
69
70
70
public static AbstractMessageSendNode createSuperSend (final SClass superClass ,
@@ -123,22 +123,22 @@ public static final class GenericMessageSendNode
123
123
124
124
private final int numberOfSignatureArguments ;
125
125
126
- @ CompilationFinal private boolean triedEager ;
126
+ @ CompilationFinal private int numCacheNodes ;
127
127
128
128
@ Child private GuardedDispatchNode dispatchCache ;
129
129
130
130
private GenericMessageSendNode (final SSymbol selector , final ExpressionNode [] arguments ,
131
- final Universe universe , final boolean triedEager ) {
131
+ final Universe universe , final int numCacheNodes ) {
132
132
super (arguments );
133
133
this .selector = selector ;
134
134
this .universe = universe ;
135
- this .triedEager = triedEager ;
135
+ this .numCacheNodes = numCacheNodes ;
136
136
this .numberOfSignatureArguments = selector .getNumberOfSignatureArguments ();
137
137
}
138
138
139
139
private GenericMessageSendNode (final SSymbol selector , final ExpressionNode [] arguments ,
140
140
final Universe universe ) {
141
- this (selector , arguments , universe , false );
141
+ this (selector , arguments , universe , - 1 );
142
142
}
143
143
144
144
@ Override
@@ -197,19 +197,9 @@ public String toString() {
197
197
return "GMsgSend(" + selector .getString () + ")" ;
198
198
}
199
199
200
- private int getCacheSize (GuardedDispatchNode cache ) {
201
- int cacheSize = 0 ;
202
- while (cache != null ) {
203
- cache = cache .next ;
204
- cacheSize += 1 ;
205
- }
206
-
207
- return cacheSize ;
208
- }
209
-
210
200
@ Override
211
201
public NodeCost getCost () {
212
- if (! triedEager ) {
202
+ if (numCacheNodes < 0 ) {
213
203
return NodeCost .UNINITIALIZED ;
214
204
}
215
205
@@ -219,7 +209,7 @@ public NodeCost getCost() {
219
209
return NodeCost .MEGAMORPHIC ;
220
210
}
221
211
222
- int cacheSize = getCacheSize ( cache ) ;
212
+ int cacheSize = numCacheNodes ;
223
213
224
214
if (cacheSize == 0 ) {
225
215
return NodeCost .UNINITIALIZED ;
@@ -233,8 +223,9 @@ public NodeCost getCost() {
233
223
}
234
224
235
225
private PreevaluatedExpression specialize (final Object [] arguments ) {
236
- if (!triedEager ) {
237
- triedEager = true ;
226
+ int cacheSize = numCacheNodes ;
227
+ if (cacheSize < 0 ) {
228
+ cacheSize = numCacheNodes = 0 ;
238
229
PreevaluatedExpression eager = attemptEagerSpecialization (arguments );
239
230
if (eager != null ) {
240
231
return eager ;
@@ -243,8 +234,6 @@ private PreevaluatedExpression specialize(final Object[] arguments) {
243
234
244
235
final GuardedDispatchNode first = dispatchCache ;
245
236
246
- int cacheSize = getCacheSize (first );
247
-
248
237
Object rcvr = arguments [0 ];
249
238
assert rcvr != null ;
250
239
@@ -287,6 +276,7 @@ private PreevaluatedExpression specialize(final Object[] arguments) {
287
276
node .next = node .insertHere (first );
288
277
}
289
278
dispatchCache = insert (node );
279
+ numCacheNodes = cacheSize + 1 ;
290
280
return node ;
291
281
}
292
282
@@ -295,6 +285,7 @@ private PreevaluatedExpression specialize(final Object[] arguments) {
295
285
GenericDispatchNode generic = new GenericDispatchNode (selector , universe );
296
286
dispatchCache = insert (generic );
297
287
reportPolymorphicSpecialize ();
288
+ numCacheNodes = cacheSize + 1 ;
298
289
return generic ;
299
290
}
300
291
0 commit comments