@@ -149,26 +149,8 @@ public Object doPreEvaluated(final VirtualFrame frame,
149
149
return cache .doPreEvaluated (frame , arguments );
150
150
}
151
151
} catch (InvalidAssumptionException e ) {
152
- // Remove invalid node from dispatch chain
153
152
CompilerDirectives .transferToInterpreterAndInvalidate ();
154
- if (cache .getParent () == this ) {
155
- if (cache .next == null ) {
156
- dispatchCache = null ;
157
- cache = null ;
158
- } else {
159
- dispatchCache = insert (cache .next );
160
- cache = cache .next ;
161
- }
162
- } else {
163
- GuardedDispatchNode parent = (GuardedDispatchNode ) cache .getParent ();
164
- if (cache .next == null ) {
165
- parent .next = null ;
166
- cache = null ;
167
- } else {
168
- parent .next = insert (cache .next );
169
- cache = cache .next ;
170
- }
171
- }
153
+ cache = removeInvalidEntryAndReturnNext (cache );
172
154
continue ;
173
155
}
174
156
cache = cache .next ;
@@ -179,11 +161,43 @@ public Object doPreEvaluated(final VirtualFrame frame,
179
161
return specialize (arguments ).doPreEvaluated (frame , arguments );
180
162
}
181
163
164
+ private GuardedDispatchNode removeInvalidEntryAndReturnNext (
165
+ final GuardedDispatchNode cache ) {
166
+ if (cache .getParent () == this ) {
167
+ if (cache .next == null ) {
168
+ dispatchCache = null ;
169
+ return null ;
170
+ } else {
171
+ dispatchCache = insert (cache .next );
172
+ return cache .next ;
173
+ }
174
+ } else {
175
+ GuardedDispatchNode parent = (GuardedDispatchNode ) cache .getParent ();
176
+ if (cache .next == null ) {
177
+ parent .next = null ;
178
+ return null ;
179
+ } else {
180
+ parent .next = parent .insertHere (cache .next );
181
+ return cache .next ;
182
+ }
183
+ }
184
+ }
185
+
182
186
@ Override
183
187
public String toString () {
184
188
return "GMsgSend(" + selector .getString () + ")" ;
185
189
}
186
190
191
+ private int getCacheSize (GuardedDispatchNode cache ) {
192
+ int cacheSize = 0 ;
193
+ while (cache != null ) {
194
+ cache = cache .next ;
195
+ cacheSize += 1 ;
196
+ }
197
+
198
+ return cacheSize ;
199
+ }
200
+
187
201
@ Override
188
202
public NodeCost getCost () {
189
203
if (!triedEager ) {
@@ -196,11 +210,7 @@ public NodeCost getCost() {
196
210
return NodeCost .MEGAMORPHIC ;
197
211
}
198
212
199
- int cacheSize = 0 ;
200
- while (cache != null ) {
201
- cache = cache .next ;
202
- cacheSize += 1 ;
203
- }
213
+ int cacheSize = getCacheSize (cache );
204
214
205
215
if (cacheSize == 0 ) {
206
216
return NodeCost .UNINITIALIZED ;
@@ -223,12 +233,8 @@ private PreevaluatedExpression specialize(final Object[] arguments) {
223
233
}
224
234
225
235
final GuardedDispatchNode first = dispatchCache ;
226
- GuardedDispatchNode cache = first ;
227
- int cacheSize = 0 ;
228
- while (cache != null ) {
229
- cache = cache .next ;
230
- cacheSize += 1 ;
231
- }
236
+
237
+ int cacheSize = getCacheSize (first );
232
238
233
239
Object rcvr = arguments [0 ];
234
240
assert rcvr != null ;
0 commit comments