Skip to content

Commit 81c744b

Browse files
authored
Merge pull request #1318 from undingen/slot_info_clear
ICSlotInfo: remove old invalidator entries
2 parents d817b29 + c7bd5c4 commit 81c744b

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

src/asm_writing/icinfo.cpp

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,21 @@ void ICInvalidator::invalidateAll() {
7373
dependents.clear();
7474
}
7575

76-
void ICSlotInfo::clear() {
77-
ic->clear(this);
76+
void ICSlotInfo::clear(bool should_invalidate) {
77+
if (should_invalidate)
78+
ic->invalidate(this);
7879
used = false;
7980

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+
8091
if (num_inside == 0)
8192
decref_infos.clear();
8293
}
@@ -163,11 +174,6 @@ void ICSlotRewrite::commit(CommitHook* hook, std::vector<void*> gc_references,
163174
assert(original_size == assembler.bytesWritten());
164175
}
165176

166-
for (int i = 0; i < dependencies.size(); i++) {
167-
ICInvalidator* invalidator = dependencies[i].first;
168-
invalidator->addDependent(ic_entry);
169-
}
170-
171177
ic->next_slot_to_try++;
172178

173179
// 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,
202208
// if (VERBOSITY()) printf("Commiting to %p-%p\n", start, start + ic->slot_size);
203209
memcpy(slot_start, buf, original_size);
204210

205-
for (auto p : ic_entry->gc_references) {
206-
Py_DECREF(p);
207-
}
211+
ic_entry->clear(false /* don't invalidate */);
212+
208213
ic_entry->gc_references = std::move(gc_references);
209214
ic_entry->used = true;
210215
ic->times_rewritten++;
211216

217+
for (int i = 0; i < dependencies.size(); i++) {
218+
ICInvalidator* invalidator = dependencies[i].first;
219+
invalidator->addDependent(ic_entry);
220+
}
221+
212222
if (ic->times_rewritten == IC_MEGAMORPHIC_THRESHOLD) {
213223
static StatCounter megamorphic_ics("megamorphic_ics");
214224
megamorphic_ics.log();
@@ -416,7 +426,7 @@ ICInfo* getICInfo(void* rtn_addr) {
416426
return it->second;
417427
}
418428

419-
void ICInfo::clear(ICSlotInfo* icentry) {
429+
void ICInfo::invalidate(ICSlotInfo* icentry) {
420430
assert(icentry);
421431

422432
uint8_t* start = (uint8_t*)icentry->start_addr;
@@ -429,11 +439,6 @@ void ICInfo::clear(ICSlotInfo* icentry) {
429439
writer.jmp(JumpDestination::fromStart(icentry->size));
430440
assert(writer.bytesWritten() <= IC_INVALDITION_HEADER_SIZE);
431441

432-
for (auto p : icentry->gc_references) {
433-
Py_DECREF(p);
434-
}
435-
icentry->gc_references.clear();
436-
437442
// std::unique_ptr<MCWriter> writer(createMCWriter(start, getSlotSize(), 0));
438443
// writer->emitNop();
439444
// writer->emitGuardFalse();

src/asm_writing/icinfo.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct ICSlotInfo {
7171
std::vector<DecrefInfo> decref_infos;
7272
std::vector<ICInvalidator*> invalidators; // ICInvalidators that reference this slotinfo
7373

74-
void clear();
74+
void clear(bool should_invalidate = true);
7575
};
7676

7777
typedef BitSet<16> LiveOutSet;
@@ -120,10 +120,10 @@ class ICInfo {
120120
const LiveOutSet& getLiveOuts() { return live_outs; }
121121

122122
std::unique_ptr<ICSlotRewrite> startRewrite(const char* debug_name);
123-
void clear(ICSlotInfo* entry);
123+
void invalidate(ICSlotInfo* entry);
124124
void clearAll() {
125125
for (ICSlotInfo& slot_info : slots) {
126-
clear(&slot_info);
126+
slot_info.clear();
127127
}
128128
}
129129

src/core/types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ class ICInvalidator {
297297
void addDependent(ICSlotInfo* icentry);
298298
int64_t version();
299299
void invalidateAll();
300+
void remove(ICSlotInfo* icentry) { dependents.erase(icentry); }
300301

301302
friend class ICInfo;
302303
friend class ICSlotInfo;

0 commit comments

Comments
 (0)