Commit d289a144 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Stopgap for rewrite-being-too-large

Just let the rewrite continue but stop emitting any assembly,
and then at the end abort the rewrite.
parent 66c4a807
......@@ -98,6 +98,11 @@ void Assembler::emitArith(Immediate imm, Register r, int opcode) {
void Assembler::emitByte(uint8_t b) {
if (addr >= end_addr) {
failed = true;
return;
}
assert(addr < end_addr);
*addr = b;
++addr;
......
......@@ -51,6 +51,7 @@ class Assembler {
private:
uint8_t* const start_addr, *const end_addr;
uint8_t* addr;
bool failed; // if the rewrite failed at the assembly-generation level for some reason
static const uint8_t OPCODE_ADD = 0b000, OPCODE_SUB = 0b101;
static const uint8_t REX_B = 1, REX_X = 2, REX_R = 4, REX_W = 8;
......@@ -64,7 +65,9 @@ private:
void emitArith(Immediate imm, Register reg, int opcode);
public:
Assembler(uint8_t* start, int size) : start_addr(start), end_addr(start + size), addr(start_addr) {}
Assembler(uint8_t* start, int size) : start_addr(start), end_addr(start + size), addr(start_addr), failed(false) {}
bool hasFailed() { return failed; }
void nop() { emitByte(0x90); }
void trap() { emitByte(0xcc); }
......
......@@ -664,6 +664,15 @@ void Rewriter::abort() {
void Rewriter::commit() {
assert(!finished);
if (assembler->hasFailed()) {
static StatCounter rewriter_assemblyfail("rewriter_assemblyfail");
rewriter_assemblyfail.log();
this->abort();
return;
}
finished = true;
static StatCounter rewriter_commits("rewriter_commits");
......
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