@@ -73,10 +73,21 @@ void ICInvalidator::invalidateAll() {
73
73
dependents.clear ();
74
74
}
75
75
76
- void ICSlotInfo::clear () {
77
- ic->clear (this );
76
+ void ICSlotInfo::clear (bool should_invalidate) {
77
+ if (should_invalidate)
78
+ ic->invalidate (this );
78
79
used = false ;
79
80
81
+ for (auto p : gc_references) {
82
+ Py_DECREF (p);
83
+ }
84
+ gc_references.clear ();
85
+
86
+ for (auto && invalidator : invalidators) {
87
+ invalidator->remove (this );
88
+ }
89
+ invalidators.clear ();
90
+
80
91
if (num_inside == 0 )
81
92
decref_infos.clear ();
82
93
}
@@ -163,11 +174,6 @@ void ICSlotRewrite::commit(CommitHook* hook, std::vector<void*> gc_references,
163
174
assert (original_size == assembler.bytesWritten ());
164
175
}
165
176
166
- for (int i = 0 ; i < dependencies.size (); i++) {
167
- ICInvalidator* invalidator = dependencies[i].first ;
168
- invalidator->addDependent (ic_entry);
169
- }
170
-
171
177
ic->next_slot_to_try ++;
172
178
173
179
// we can create a new IC slot if this is the last slot in the IC in addition we are checking that the new slot is
@@ -202,13 +208,17 @@ void ICSlotRewrite::commit(CommitHook* hook, std::vector<void*> gc_references,
202
208
// if (VERBOSITY()) printf("Commiting to %p-%p\n", start, start + ic->slot_size);
203
209
memcpy (slot_start, buf, original_size);
204
210
205
- for (auto p : ic_entry->gc_references ) {
206
- Py_DECREF (p);
207
- }
211
+ ic_entry->clear (false /* don't invalidate */ );
212
+
208
213
ic_entry->gc_references = std::move (gc_references);
209
214
ic_entry->used = true ;
210
215
ic->times_rewritten ++;
211
216
217
+ for (int i = 0 ; i < dependencies.size (); i++) {
218
+ ICInvalidator* invalidator = dependencies[i].first ;
219
+ invalidator->addDependent (ic_entry);
220
+ }
221
+
212
222
if (ic->times_rewritten == IC_MEGAMORPHIC_THRESHOLD) {
213
223
static StatCounter megamorphic_ics (" megamorphic_ics" );
214
224
megamorphic_ics.log ();
@@ -416,7 +426,7 @@ ICInfo* getICInfo(void* rtn_addr) {
416
426
return it->second ;
417
427
}
418
428
419
- void ICInfo::clear (ICSlotInfo* icentry) {
429
+ void ICInfo::invalidate (ICSlotInfo* icentry) {
420
430
assert (icentry);
421
431
422
432
uint8_t * start = (uint8_t *)icentry->start_addr ;
@@ -429,11 +439,6 @@ void ICInfo::clear(ICSlotInfo* icentry) {
429
439
writer.jmp (JumpDestination::fromStart (icentry->size ));
430
440
assert (writer.bytesWritten () <= IC_INVALDITION_HEADER_SIZE);
431
441
432
- for (auto p : icentry->gc_references ) {
433
- Py_DECREF (p);
434
- }
435
- icentry->gc_references .clear ();
436
-
437
442
// std::unique_ptr<MCWriter> writer(createMCWriter(start, getSlotSize(), 0));
438
443
// writer->emitNop();
439
444
// writer->emitGuardFalse();
0 commit comments