Commit af59d5ae authored by Kevin Modzelewski's avatar Kevin Modzelewski

Change from "never retry ICs" to exponential backoff

parent 49a830b6
......@@ -30,6 +30,9 @@ namespace pyston {
using namespace pyston::assembler;
#define MEGAMORPHIC_THRESHOLD 100
#define MAX_RETRY_BACKOFF 1024
// TODO not right place for this...
int64_t ICInvalidator::version() {
return cur_version;
......@@ -68,7 +71,8 @@ ICSlotRewrite::~ICSlotRewrite() {
}
void ICSlotRewrite::abort() {
ic->failed = true;
ic->retry_backoff = std::max(MAX_RETRY_BACKOFF, 2 * ic->retry_backoff);
ic->retry_in = ic->retry_backoff;
}
void ICSlotRewrite::commit(CommitHook* hook) {
......@@ -109,6 +113,11 @@ void ICSlotRewrite::commit(CommitHook* hook) {
ic->times_rewritten++;
if (ic->times_rewritten == MEGAMORPHIC_THRESHOLD) {
static StatCounter megamorphic_ics("megamorphic_ics");
megamorphic_ics.log();
}
llvm::sys::Memory::InvalidateInstructionCache(slot_start, ic->getSlotSize());
}
......@@ -177,7 +186,7 @@ ICInfo::ICInfo(void* start_addr, void* slowpath_rtn_addr, void* continue_addr, S
assembler::GenericRegister return_register, TypeRecorder* type_recorder)
: next_slot_to_try(0), stack_info(stack_info), num_slots(num_slots), slot_size(slot_size),
calling_conv(calling_conv), live_outs(live_outs.begin(), live_outs.end()), return_register(return_register),
type_recorder(type_recorder), failed(false), times_rewritten(0), start_addr(start_addr),
type_recorder(type_recorder), retry_in(0), retry_backoff(1), times_rewritten(0), start_addr(start_addr),
slowpath_rtn_addr(slowpath_rtn_addr), continue_addr(continue_addr) {
for (int i = 0; i < num_slots; i++) {
slots.push_back(ICSlotInfo(this, i));
......@@ -269,6 +278,10 @@ void ICInfo::clear(ICSlotInfo* icentry) {
}
bool ICInfo::shouldAttempt() {
return !failed && times_rewritten < 100;
if (retry_in) {
retry_in--;
return false;
}
return times_rewritten < MEGAMORPHIC_THRESHOLD;
}
}
......@@ -100,7 +100,7 @@ private:
const std::vector<int> live_outs;
const assembler::GenericRegister return_register;
TypeRecorder* const type_recorder;
bool failed;
int retry_in, retry_backoff;
int times_rewritten;
// for ICSlotRewrite:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment