This commit is contained in:
Joel Dice 2008-09-20 17:42:46 -06:00
parent fadb66044b
commit 1b4ad1db42
3 changed files with 109 additions and 138 deletions

View File

@ -1808,6 +1808,19 @@ handleExit(MyThread* t, Frame* frame)
(t, frame, getThunk(t, releaseMonitorForObjectThunk)); (t, frame, getThunk(t, releaseMonitorForObjectThunk));
} }
void
compile(MyThread* t, Frame* initialFrame, unsigned ip,
bool exceptionHandler = false);
void
saveStateAndCompile(MyThread* t, Frame* initialFrame, unsigned ip,
bool exceptionHandler = false)
{
Compiler::State* state = c->saveState();
compile(t, frame, ipTable[i], exceptionHandler);
c->restoreState(state);
}
void void
compile(MyThread* t, Frame* initialFrame, unsigned ip, compile(MyThread* t, Frame* initialFrame, unsigned ip,
bool exceptionHandler = false) bool exceptionHandler = false)
@ -2511,12 +2524,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip,
c->jne(target); c->jne(target);
} }
Compiler::State* state = c->saveState(); saveStateAndCompile(t, frame, newIp);
compile(t, frame, newIp);
if (UNLIKELY(t->exception)) return; if (UNLIKELY(t->exception)) return;
c->restoreState(state);
} break; } break;
case if_icmpeq: case if_icmpeq:
@ -2554,12 +2563,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip,
break; break;
} }
Compiler::State* state = c->saveState(); saveStateAndCompile(t, frame, newIp);
compile(t, frame, newIp);
if (UNLIKELY(t->exception)) return; if (UNLIKELY(t->exception)) return;
c->restoreState(state);
} break; } break;
case ifeq: case ifeq:
@ -2596,12 +2601,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip,
break; break;
} }
Compiler::State* state = c->saveState(); saveStateAndCompile(t, frame, newIp);
compile(t, frame, newIp);
if (UNLIKELY(t->exception)) return; if (UNLIKELY(t->exception)) return;
c->restoreState(state);
} break; } break;
case ifnull: case ifnull:
@ -2619,12 +2620,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip,
c->jne(target); c->jne(target);
} }
Compiler::State* state = c->saveState(); saveStateAndCompile(t, frame, newIp);
compile(t, frame, newIp);
if (UNLIKELY(t->exception)) return; if (UNLIKELY(t->exception)) return;
c->restoreState(state);
} break; } break;
case iinc: { case iinc: {
@ -3394,22 +3391,21 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip,
} }
assert(t, start); assert(t, start);
Compiler::Operand* defaultCase = c->label();
Compiler::Operand* key = frame->popInt(); Compiler::Operand* key = frame->popInt();
c->cmp(4, c->constant(bottom), key); c->cmp(4, c->constant(bottom), key);
c->jl(defaultCase); c->jl(frame->machineIp(defaultIp));
saveStateAndCompile(t, frame, defaultIp);
c->cmp(4, c->constant(top), key); c->cmp(4, c->constant(top), key);
c->jg(defaultCase); c->jg(frame->machineIp(defaultIp));
saveStateAndCompile(t, frame, defaultIp);
c->jmp(c->memory(start, 0, c->sub(4, c->constant(bottom), key), c->jmp(c->memory(start, 0, c->sub(4, c->constant(bottom), key),
BytesPerWord)); BytesPerWord));
c->mark(defaultCase);
c->jmp(frame->machineIp(defaultIp));
Compiler::State* state = c->saveState(); Compiler::State* state = c->saveState();
for (int32_t i = 0; i < top - bottom + 1; ++i) { for (int32_t i = 0; i < top - bottom + 1; ++i) {

View File

@ -106,19 +106,29 @@ class Stack: public Compiler::StackElement {
Stack* next; Stack* next;
}; };
class ReadPair {
public:
Value* value;
MultiRead* read;
};
class MyState: public Compiler::State { class MyState: public Compiler::State {
public: public:
MyState(Stack* stack, Value** locals, Cell* predecessors): MyState(Stack* stack, Value** locals, Event* predecessor,
unsigned logicalIp):
stack(stack), stack(stack),
locals(locals), locals(locals),
predecessors(predecessors), predecessor(predecessor),
reads(0) logicalIp(logicalIp),
readCount(0)
{ } { }
Stack* stack; Stack* stack;
Value** locals; Value** locals;
Cell* predecessors; Event* predecessor;
MultiRead** reads; unsigned logicalIp;
unsigned readCount;
ReadPair reads[0];
}; };
class LogicalInstruction { class LogicalInstruction {
@ -203,7 +213,8 @@ intersectFrameIndexes(int a, int b)
class Value: public Compiler::Operand { class Value: public Compiler::Operand {
public: public:
Value(Site* site, Site* target): Value(Site* site, Site* target):
reads(0), lastRead(0), sites(site), source(0), target(target) reads(0), lastRead(0), sites(site), source(0), target(target),
visited(false)
{ } { }
virtual ~Value() { } virtual ~Value() { }
@ -215,6 +226,7 @@ class Value: public Compiler::Operand {
Site* sites; Site* sites;
Site* source; Site* source;
Site* target; Site* target;
bool visited;
}; };
enum Pass { enum Pass {
@ -233,7 +245,7 @@ class Context {
client(client), client(client),
stack(0), stack(0),
locals(0), locals(0),
predecessors(0), predecessor(0),
logicalCode(0), logicalCode(0),
registers registers
(static_cast<Register**> (static_cast<Register**>
@ -246,7 +258,6 @@ class Context {
state(0), state(0),
logicalIp(-1), logicalIp(-1),
constantCount(0), constantCount(0),
nextSequence(0),
logicalCodeLength(0), logicalCodeLength(0),
parameterFootprint(0), parameterFootprint(0),
localFootprint(0), localFootprint(0),
@ -268,7 +279,7 @@ class Context {
Compiler::Client* client; Compiler::Client* client;
Stack* stack; Stack* stack;
Value** locals; Value** locals;
Cell* predecessors; Event* predecessor;
LogicalInstruction** logicalCode; LogicalInstruction** logicalCode;
Register** registers; Register** registers;
ConstantPoolNode* firstConstant; ConstantPoolNode* firstConstant;
@ -279,7 +290,6 @@ class Context {
MyState* state; MyState* state;
int logicalIp; int logicalIp;
unsigned constantCount; unsigned constantCount;
unsigned nextSequence;
unsigned logicalCodeLength; unsigned logicalCodeLength;
unsigned parameterFootprint; unsigned parameterFootprint;
unsigned localFootprint; unsigned localFootprint;
@ -340,12 +350,7 @@ class CodePromise: public Promise {
unsigned unsigned
machineOffset(Context* c, int logicalIp) machineOffset(Context* c, int logicalIp)
{ {
for (unsigned n = logicalIp; n < c->logicalCodeLength; ++n) { return c->logicalCode[n]->machineOffset->value();
LogicalInstruction* i = c->logicalCode[n];
if (i and i->machineOffset) return i->machineOffset->value();
}
abort(c);
} }
class IpPromise: public Promise { class IpPromise: public Promise {
@ -431,9 +436,9 @@ class Event {
public: public:
Event(Context* c): Event(Context* c):
next(0), stack(c->stack), locals(c->locals), promises(0), next(0), stack(c->stack), locals(c->locals), promises(0),
reads(0), junctionSites(0), savedSites(0), predecessors(c->predecessors), reads(0), junctionSites(0), savedSites(0), predecessors(0),
successors(0), block(0), logicalInstruction(c->logicalCode[c->logicalIp]), successors(0), block(0), logicalInstruction(c->logicalCode[c->logicalIp]),
state(c->state), readCount(0), sequence(c->nextSequence++) state(c->state), readCount(0)
{ {
assert(c, c->logicalIp >= 0); assert(c, c->logicalIp >= 0);
@ -444,12 +449,13 @@ class Event {
} }
c->lastEvent = this; c->lastEvent = this;
for (Cell* cell = predecessors; cell; cell = cell->next) { Event* p = c->predecessor;
Event* p = static_cast<Event*>(cell->value); if (p) {
predecessors = cons(c, p, 0);
p->successors = cons(c, this, p->successors); p->successors = cons(c, this, p->successors);
} }
c->predecessors = cons(c, this, 0); c->predecessor = this;
if (logicalInstruction->firstEvent == 0) { if (logicalInstruction->firstEvent == 0) {
logicalInstruction->firstEvent = this; logicalInstruction->firstEvent = this;
@ -479,7 +485,6 @@ class Event {
LogicalInstruction* logicalInstruction; LogicalInstruction* logicalInstruction;
MyState* state; MyState* state;
unsigned readCount; unsigned readCount;
unsigned sequence;
}; };
unsigned unsigned
@ -1944,24 +1949,6 @@ value(Context* c, Site* site = 0, Site* target = 0)
return new (c->zone->allocate(sizeof(Value))) Value(site, target); return new (c->zone->allocate(sizeof(Value))) Value(site, target);
} }
class LabelValue: public Value {
public:
LabelValue(Site* site): Value(site, 0), predecessors(0) { }
virtual void addPredecessor(Context* c, Event* e) {
predecessors = cons(c, e, predecessors);
}
Cell* predecessors;
};
LabelValue*
labelValue(Context* c)
{
return new (c->zone->allocate(sizeof(LabelValue))) LabelValue
(constantSite(c, static_cast<Promise*>(0)));
}
Stack* Stack*
stack(Context* c, Value* value, unsigned size, unsigned index, Stack* next) stack(Context* c, Value* value, unsigned size, unsigned index, Stack* next)
{ {
@ -2176,8 +2163,10 @@ class BranchEvent: public Event {
BranchEvent(Context* c, UnaryOperation type, Value* address): BranchEvent(Context* c, UnaryOperation type, Value* address):
Event(c), type(type), address(address) Event(c), type(type), address(address)
{ {
addRead(c, this, address, read(c, BytesPerWord, ~0, ~static_cast<uint64_t>(0), address->addPredecessor(c, this);
AnyFrameIndex));
addRead(c, this, address, read
(c, BytesPerWord, ~0, ~static_cast<uint64_t>(0), AnyFrameIndex));
} }
virtual const char* name() { virtual const char* name() {
@ -2646,15 +2635,9 @@ compile(Context* c)
MyState* state = e->state; MyState* state = e->state;
if (state) { if (state) {
MultiRead** reads = state->reads; for (unsigned i = 0; i < state->readCount; ++i) {
for (unsigned i = 0; i < c->localFootprint; ++i) { ReadPair* p = state->reads[i];
if (state->locals[i]) { p->value->reads = p->read->nextTarget();
state->locals[i]->reads = (*(reads++))->nextTarget();
}
}
for (Stack* s = state->stack; s; s = s->next) {
s->value->reads = (*(reads++))->nextTarget();
} }
} }
@ -2681,9 +2664,7 @@ compile(Context* c)
p->offset = a->offset(); p->offset = a->offset();
} }
if (e->logicalInstruction->lastEvent == e) { if (e->next == 0 or e->next->blockStart) {
LogicalInstruction* nextInstruction = next(c, e->logicalInstruction);
if (e->next == 0 or nextInstruction != e->next->logicalInstruction) {
block->nextInstruction = nextInstruction; block->nextInstruction = nextInstruction;
block->assemblerBlock = a->endBlock(e->next != 0); block->assemblerBlock = a->endBlock(e->next != 0);
if (e->next) { if (e->next) {
@ -2691,7 +2672,6 @@ compile(Context* c)
} }
} }
} }
}
block = firstBlock; block = firstBlock;
while (block->nextInstruction) { while (block->nextInstruction) {
@ -2716,52 +2696,63 @@ count(Stack* s)
} }
void void
allocateTargets(Context* c, MultiRead** reads) allocateTargets(Context* c, MyState* state)
{ {
for (unsigned i = 0; i < c->localFootprint; ++i) { for (unsigned i = 0; i < state->readCount; ++i) {
if (c->locals[i]) { ReadPair* p = state->reads[i];
MultiRead* r = *(reads++); p->value->lastRead = p->read;
c->locals[i]->lastRead = r; p->read->allocateTarget(c);
r->allocateTarget(c);
}
}
for (Stack* s = c->stack; s; s = s->next) {
MultiRead* r = *(reads++);
s->value->lastRead = r;
r->allocateTarget(c);
} }
} }
MyState* MyState*
saveState(Context* c) saveState(Context* c)
{ {
MyState* state = new (c->zone->allocate(sizeof(MyState))) MyState* state = new
MyState(c->stack, c->locals, c->predecessors); (c->zone->allocate(sizeof(MyState))
+ (c->zone->allocate(sizeof(ReadPair) * frameFootprint(c, c->stack))))
MyState(c->stack, c->locals, c->predecessor, c->logicalIp);
if (c->predecessors) { if (c->predecessor) {
c->state = state; c->state = state;
MultiRead** reads = static_cast<MultiRead**> unsigned count = 0;
(c->zone->allocate(sizeof(MultiRead*) * frameFootprint(c, c->stack)));
state->reads = reads;
for (unsigned i = 0; i < c->localFootprint; ++i) { for (unsigned i = 0; i < c->localFootprint; ++i) {
if (c->locals[i]) { Value* v = c->locals[i];
if (v and not v->visited) {
v->visited = true;
MultiRead* r = multiRead(c); MultiRead* r = multiRead(c);
addRead(c, 0, c->locals[i], r); addRead(c, 0, c->locals[i], r);
*(reads++) = r;
ReadPair* p = state->reads + (count++);
p->value = v;
p->read = r;
} }
} }
for (Stack* s = c->stack; s; s = s->next) { for (Stack* s = c->stack; s; s = s->next) {
Value* v = s->value;
if (not v->visited) {
v->visited = true;
MultiRead* r = multiRead(c); MultiRead* r = multiRead(c);
addRead(c, 0, s->value, r); addRead(c, 0, s->value, r);
*(reads++) = r;
ReadPair* p = state->reads + (count++);
p->value = v;
p->read = r;
}
} }
allocateTargets(c, state->reads); for (unsigned i = 0; i < count; ++i) {
state->reads[i]->value->visited = false;
}
state->readCount = count;
allocateTargets(c, state);
} }
return state; return state;
@ -2776,11 +2767,12 @@ restoreState(Context* c, MyState* s)
c->stack = s->stack; c->stack = s->stack;
c->locals = s->locals; c->locals = s->locals;
c->predecessors = s->predecessors; c->predecessor = s->predecessor;
c->logicalIp = logicalIp;
if (c->predecessors) { if (c->predecessor) {
c->state = s; c->state = s;
allocateTargets(c, s->reads); allocateTargets(c, s);
} }
} }
@ -2853,12 +2845,12 @@ class MyCompiler: public Compiler {
Event* e = c.logicalCode[logicalIp]->firstEvent; Event* e = c.logicalCode[logicalIp]->firstEvent;
for (Cell* cell = c.predecessors; cell; cell = cell->next) { if (c.predecessor) {
Event* p = static_cast<Event*>(cell->value); c.predecessor->successors = cons(&c, e, c.predecessor->successors);
p->successors = cons(&c, e, p->successors); #error tbc
populateJunctionReads(&c, c.predecessor);
e->predecessors = cons(&c, c.predecessor, e->predecessors);
} }
e->predecessors = append(&c, c.predecessors, e->predecessors);
} }
virtual void startLogicalIp(unsigned logicalIp) { virtual void startLogicalIp(unsigned logicalIp) {
@ -2947,23 +2939,10 @@ class MyCompiler: public Compiler {
return value(&c, s, s); return value(&c, s, s);
} }
virtual Operand* label() {
return labelValue(&c);
}
Promise* machineIp() { Promise* machineIp() {
return codePromise(&c, c.logicalCode[c.logicalIp]->lastEvent); return codePromise(&c, c.logicalCode[c.logicalIp]->lastEvent);
} }
virtual void mark(Operand* label) {
LabelValue* v = static_cast<LabelValue*>(label);
assert(&c, v->sites);
assert(&c, v->sites->next == 0);
assert(&c, v->sites->type(&c) == ConstantOperand);
static_cast<ConstantSite*>(v->sites)->value.value = machineIp();
c.predecessors = append(&c, v->predecessors, c.predecessors);
}
virtual void push(unsigned size) { virtual void push(unsigned size) {
assert(&c, ceiling(size, BytesPerWord)); assert(&c, ceiling(size, BytesPerWord));

View File

@ -63,10 +63,6 @@ class Compiler {
virtual Operand* stackTop() = 0; virtual Operand* stackTop() = 0;
virtual Operand* label() = 0;
virtual void mark(Operand* label) = 0;
virtual void push(unsigned size) = 0;
virtual void push(unsigned size, Operand* value) = 0; virtual void push(unsigned size, Operand* value) = 0;
virtual Operand* pop(unsigned size) = 0; virtual Operand* pop(unsigned size) = 0;
virtual void pushed() = 0; virtual void pushed() = 0;