@@ -76,6 +76,7 @@ void ICInvalidator::invalidateAll() {
76
76
void ICSlotInfo::clear () {
77
77
ic->clear (this );
78
78
decref_infos.clear ();
79
+ empty = true ;
79
80
}
80
81
81
82
ICSlotRewrite::ICSlotRewrite (ICInfo* ic, const char * debug_name)
@@ -175,6 +176,7 @@ void ICSlotRewrite::commit(CommitHook* hook, std::vector<void*> gc_references,
175
176
}
176
177
177
178
llvm::sys::Memory::InvalidateInstructionCache (slot_start, ic->getSlotSize ());
179
+ ic_entry->empty = false ;
178
180
}
179
181
180
182
void ICSlotRewrite::addDependenceOn (ICInvalidator& invalidator) {
@@ -209,7 +211,24 @@ std::unique_ptr<ICSlotRewrite> ICInfo::startRewrite(const char* debug_name) {
209
211
}
210
212
211
213
ICSlotInfo* ICInfo::pickEntryForRewrite (const char * debug_name) {
212
- int num_slots = getNumSlots ();
214
+ int num_slots = slots.size ();
215
+
216
+ for (int _i = 0 ; _i < num_slots; _i++) {
217
+ int i = (_i + next_slot_to_try) % num_slots;
218
+
219
+ ICSlotInfo& sinfo = slots[i];
220
+ assert (sinfo.num_inside >= 0 );
221
+ if (sinfo.num_inside || !sinfo.empty )
222
+ continue ;
223
+
224
+ if (VERBOSITY () >= 4 ) {
225
+ printf (" picking %s icentry to in-use slot %d at %p\n " , debug_name, i, start_addr);
226
+ }
227
+
228
+ next_slot_to_try = i;
229
+ return &sinfo;
230
+ }
231
+
213
232
for (int _i = 0 ; _i < num_slots; _i++) {
214
233
int i = (_i + next_slot_to_try) % num_slots;
215
234
@@ -371,6 +390,15 @@ void ICInfo::clear(ICSlotInfo* icentry) {
371
390
372
391
// writer->endWithSlowpath();
373
392
llvm::sys::Memory::InvalidateInstructionCache (start, getSlotSize ());
393
+
394
+ for (int i = 0 ; i < slots.size (); ++i) {
395
+ if (&slots[i] == icentry) {
396
+ next_slot_to_try = i;
397
+ break ;
398
+ }
399
+ }
400
+
401
+ icentry->empty = true ;
374
402
}
375
403
376
404
bool ICInfo::shouldAttempt () {
0 commit comments