@@ -162,26 +162,8 @@ public Object doPreEvaluated(final VirtualFrame frame,
162
162
return cache .doPreEvaluated (frame , arguments );
163
163
}
164
164
} catch (InvalidAssumptionException e ) {
165
- // Remove invalid node from dispatch chain
166
165
CompilerDirectives .transferToInterpreterAndInvalidate ();
167
- if (cache .getParent () == this ) {
168
- if (cache .next == null ) {
169
- dispatchCache = null ;
170
- cache = null ;
171
- } else {
172
- dispatchCache = insert (cache .next );
173
- cache = cache .next ;
174
- }
175
- } else {
176
- GuardedDispatchNode parent = (GuardedDispatchNode ) cache .getParent ();
177
- if (cache .next == null ) {
178
- parent .next = null ;
179
- cache = null ;
180
- } else {
181
- parent .next = insert (cache .next );
182
- cache = cache .next ;
183
- }
184
- }
166
+ cache = removeInvalidEntryAndReturnNext (cache );
185
167
continue ;
186
168
}
187
169
cache = cache .next ;
@@ -192,11 +174,43 @@ public Object doPreEvaluated(final VirtualFrame frame,
192
174
return specialize (arguments ).doPreEvaluated (frame , arguments );
193
175
}
194
176
177
+ private GuardedDispatchNode removeInvalidEntryAndReturnNext (
178
+ final GuardedDispatchNode cache ) {
179
+ if (cache .getParent () == this ) {
180
+ if (cache .next == null ) {
181
+ dispatchCache = null ;
182
+ return null ;
183
+ } else {
184
+ dispatchCache = insert (cache .next );
185
+ return cache .next ;
186
+ }
187
+ } else {
188
+ GuardedDispatchNode parent = (GuardedDispatchNode ) cache .getParent ();
189
+ if (cache .next == null ) {
190
+ parent .next = null ;
191
+ return null ;
192
+ } else {
193
+ parent .next = parent .insertHere (cache .next );
194
+ return cache .next ;
195
+ }
196
+ }
197
+ }
198
+
195
199
@ Override
196
200
public String toString () {
197
201
return "GMsgSend(" + selector .getString () + ")" ;
198
202
}
199
203
204
+ private int getCacheSize (GuardedDispatchNode cache ) {
205
+ int cacheSize = 0 ;
206
+ while (cache != null ) {
207
+ cache = cache .next ;
208
+ cacheSize += 1 ;
209
+ }
210
+
211
+ return cacheSize ;
212
+ }
213
+
200
214
@ Override
201
215
public NodeCost getCost () {
202
216
if (!triedEager ) {
@@ -209,11 +223,7 @@ public NodeCost getCost() {
209
223
return NodeCost .MEGAMORPHIC ;
210
224
}
211
225
212
- int cacheSize = 0 ;
213
- while (cache != null ) {
214
- cache = cache .next ;
215
- cacheSize += 1 ;
216
- }
226
+ int cacheSize = getCacheSize (cache );
217
227
218
228
if (cacheSize == 0 ) {
219
229
return NodeCost .UNINITIALIZED ;
@@ -236,12 +246,8 @@ private PreevaluatedExpression specialize(final Object[] arguments) {
236
246
}
237
247
238
248
final GuardedDispatchNode first = dispatchCache ;
239
- GuardedDispatchNode cache = first ;
240
- int cacheSize = 0 ;
241
- while (cache != null ) {
242
- cache = cache .next ;
243
- cacheSize += 1 ;
244
- }
249
+
250
+ int cacheSize = getCacheSize (first );
245
251
246
252
Object rcvr = arguments [0 ];
247
253
assert rcvr != null ;
0 commit comments