various bugfixes

This commit is contained in:
Joel Dice 2008-09-23 15:18:41 -06:00
parent b8dd495ada
commit d4938115ef
3 changed files with 144 additions and 49 deletions

View File

@ -836,26 +836,34 @@ class Frame {
} }
void pushQuiet(unsigned size, Compiler::Operand* o) { void pushQuiet(unsigned size, Compiler::Operand* o) {
if (size == 8 and BytesPerWord == 8) {
c->push(8);
context->eventLog.append(PushEvent);
context->eventLog.appendAddress(c->top());
}
c->push(size, o); c->push(size, o);
context->eventLog.append(PushEvent); context->eventLog.append(PushEvent);
context->eventLog.appendAddress(c->top()); context->eventLog.appendAddress(c->top());
} }
void pushLongQuiet(Compiler::Operand* o) {
if (BytesPerWord == 8) {
c->push(8);
context->eventLog.append(PushEvent);
context->eventLog.appendAddress(c->top());
}
pushQuiet(8, o);
}
Compiler::Operand* popQuiet(unsigned size) { Compiler::Operand* popQuiet(unsigned size) {
context->eventLog.append(PopEvent); context->eventLog.append(PopEvent);
context->eventLog.appendAddress(c->top()); context->eventLog.appendAddress(c->top());
Compiler::Operand* r = c->pop(size); return c->pop(size);
}
if (size == 8 and BytesPerWord == 8) { Compiler::Operand* popLongQuiet() {
Compiler::Operand* r = popQuiet(8);
if (BytesPerWord == 8) {
context->eventLog.append(PopEvent); context->eventLog.append(PopEvent);
context->eventLog.appendAddress(c->top()); context->eventLog.appendAddress(c->top());
@ -890,7 +898,7 @@ class Frame {
} }
void pushLong(Compiler::Operand* o) { void pushLong(Compiler::Operand* o) {
pushQuiet(8, o); pushLongQuiet(o);
pushedLong(); pushedLong();
} }
@ -919,7 +927,7 @@ class Frame {
Compiler::Operand* popLong() { Compiler::Operand* popLong() {
poppedLong(); poppedLong();
return popQuiet(8); return popLongQuiet();
} }
Compiler::Operand* popObject() { Compiler::Operand* popObject() {
@ -992,10 +1000,10 @@ class Frame {
Compiler::Operand* s0 = popQuiet(BytesPerWord); Compiler::Operand* s0 = popQuiet(BytesPerWord);
if (get(sp - 2) == Long) { if (get(sp - 2) == Long) {
Compiler::Operand* s1 = popQuiet(8); Compiler::Operand* s1 = popLongQuiet();
pushQuiet(BytesPerWord, s0); pushQuiet(BytesPerWord, s0);
pushQuiet(8, s1); pushLongQuiet(s1);
pushQuiet(BytesPerWord, s0); pushQuiet(BytesPerWord, s0);
} else { } else {
Compiler::Operand* s1 = popQuiet(BytesPerWord); Compiler::Operand* s1 = popQuiet(BytesPerWord);
@ -1012,7 +1020,7 @@ class Frame {
void dup2() { void dup2() {
if (get(sp - 1) == Long) { if (get(sp - 1) == Long) {
pushQuiet(8, peekLong(0)); pushLongQuiet(peekLong(0));
} else { } else {
Compiler::Operand* s0 = popQuiet(BytesPerWord); Compiler::Operand* s0 = popQuiet(BytesPerWord);
Compiler::Operand* s1 = popQuiet(BytesPerWord); Compiler::Operand* s1 = popQuiet(BytesPerWord);
@ -1028,12 +1036,12 @@ class Frame {
void dup2X1() { void dup2X1() {
if (get(sp - 1) == Long) { if (get(sp - 1) == Long) {
Compiler::Operand* s0 = popQuiet(8); Compiler::Operand* s0 = popLongQuiet();
Compiler::Operand* s1 = popQuiet(BytesPerWord); Compiler::Operand* s1 = popQuiet(BytesPerWord);
pushQuiet(8, s0); pushLongQuiet(s0);
pushQuiet(BytesPerWord, s1); pushQuiet(BytesPerWord, s1);
pushQuiet(8, s0); pushLongQuiet(s0);
} else { } else {
Compiler::Operand* s0 = popQuiet(BytesPerWord); Compiler::Operand* s0 = popQuiet(BytesPerWord);
Compiler::Operand* s1 = popQuiet(BytesPerWord); Compiler::Operand* s1 = popQuiet(BytesPerWord);
@ -1051,22 +1059,22 @@ class Frame {
void dup2X2() { void dup2X2() {
if (get(sp - 1) == Long) { if (get(sp - 1) == Long) {
Compiler::Operand* s0 = popQuiet(8); Compiler::Operand* s0 = popLongQuiet();
if (get(sp - 3) == Long) { if (get(sp - 3) == Long) {
Compiler::Operand* s1 = popQuiet(8); Compiler::Operand* s1 = popLongQuiet();
pushQuiet(8, s0); pushLongQuiet(s0);
pushQuiet(8, s1); pushLongQuiet(s1);
pushQuiet(8, s0); pushLongQuiet(s0);
} else { } else {
Compiler::Operand* s1 = popQuiet(BytesPerWord); Compiler::Operand* s1 = popQuiet(BytesPerWord);
Compiler::Operand* s2 = popQuiet(BytesPerWord); Compiler::Operand* s2 = popQuiet(BytesPerWord);
pushQuiet(8, s0); pushLongQuiet(s0);
pushQuiet(BytesPerWord, s2); pushQuiet(BytesPerWord, s2);
pushQuiet(BytesPerWord, s1); pushQuiet(BytesPerWord, s1);
pushQuiet(8, s0); pushLongQuiet(s0);
} }
} else { } else {
Compiler::Operand* s0 = popQuiet(BytesPerWord); Compiler::Operand* s0 = popQuiet(BytesPerWord);
@ -1847,6 +1855,10 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, bool exceptionHandler)
handleEntrance(t, frame); handleEntrance(t, frame);
int index = 0; int index = 0;
if ((methodFlags(t, context->method) & ACC_STATIC) == 0) {
c->initParameter(1, index++);
}
for (MethodSpecIterator it for (MethodSpecIterator it
(t, reinterpret_cast<const char*> (t, reinterpret_cast<const char*>
(&byteArrayBody(t, methodSpec(t, context->method), 0))); (&byteArrayBody(t, methodSpec(t, context->method), 0)));
@ -1860,8 +1872,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, bool exceptionHandler)
break; break;
default: default:
c->initParameter(1, index); c->initParameter(1, index++);
index += 1;
break; break;
} }
} }
@ -3856,15 +3867,15 @@ finish(MyThread* t, Context* context)
} }
// for debugging: // for debugging:
if (//false and if (false and
strcmp strcmp
(reinterpret_cast<const char*> (reinterpret_cast<const char*>
(&byteArrayBody(t, className(t, methodClass(t, context->method)), 0)), (&byteArrayBody(t, className(t, methodClass(t, context->method)), 0)),
"Simple") == 0 and "Hello") == 0 and
strcmp strcmp
(reinterpret_cast<const char*> (reinterpret_cast<const char*>
(&byteArrayBody(t, methodName(t, context->method), 0)), (&byteArrayBody(t, methodName(t, context->method), 0)),
"pow") == 0) "main") == 0)
{ {
asm("int3"); asm("int3");
} }

View File

@ -264,6 +264,7 @@ class Context {
localFootprint(0), localFootprint(0),
maxStackFootprint(0), maxStackFootprint(0),
stackPadding(0), stackPadding(0),
machineCodeSize(0),
constantCompare(CompareNone), constantCompare(CompareNone),
pass(ScanPass) pass(ScanPass)
{ {
@ -296,6 +297,7 @@ class Context {
unsigned localFootprint; unsigned localFootprint;
unsigned maxStackFootprint; unsigned maxStackFootprint;
unsigned stackPadding; unsigned stackPadding;
unsigned machineCodeSize;
ConstantCompare constantCompare; ConstantCompare constantCompare;
Pass pass; Pass pass;
}; };
@ -307,7 +309,7 @@ class PoolPromise: public Promise {
virtual int64_t value() { virtual int64_t value() {
if (resolved()) { if (resolved()) {
return reinterpret_cast<intptr_t> return reinterpret_cast<intptr_t>
(c->machineCode + pad(c->assembler->length()) + (key * BytesPerWord)); (c->machineCode + pad(c->machineCodeSize) + (key * BytesPerWord));
} }
abort(c); abort(c);
@ -1681,7 +1683,7 @@ class CallEvent: public Event {
int footprint = stackArgumentFootprint; int footprint = stackArgumentFootprint;
for (Stack* s = stack; s; s = s->next) { for (Stack* s = stack; s; s = s->next) {
frameIndex -= s->size; frameIndex -= s->size;
if (footprint) { if (footprint > 0) {
addRead(c, this, s->value, read(c, s->size * BytesPerWord, addRead(c, this, s->value, read(c, s->size * BytesPerWord,
1 << MemoryOperand, 0, frameIndex)); 1 << MemoryOperand, 0, frameIndex));
} else { } else {
@ -1690,8 +1692,8 @@ class CallEvent: public Event {
assert(c, index <= frameIndex); assert(c, index <= frameIndex);
s->padding = frameIndex - index; s->padding = frameIndex - index;
} }
addRead(c, this, s->value, read(c, s->size * BytesPerWord, addRead(c, this, s->value, read
1 << MemoryOperand, 0, index)); (c, s->size * BytesPerWord, 1 << MemoryOperand, 0, index));
} }
footprint -= s->size; footprint -= s->size;
} }
@ -2005,6 +2007,13 @@ class CombineEvent: public Event {
nextRead(c, first); nextRead(c, first);
nextRead(c, second); nextRead(c, second);
if (c->arch->condensedAddressing()) {
removeSite(c, second, second->source);
if (result->reads) {
addSite(c, 0, 0, resultSize, result, second->source);
}
}
} }
TernaryOperation type; TernaryOperation type;
@ -2564,9 +2573,11 @@ populateSiteTables(Context* c, Event* e)
if (e->junctionSites) { if (e->junctionSites) {
for (unsigned i = 0; i < c->localFootprint; ++i) { for (unsigned i = 0; i < c->localFootprint; ++i) {
frozenSiteIndex = resolveJunctionSite if (successor->locals[i]) {
(c, e, successor, successor->locals[i], i, frozenSites, frozenSiteIndex = resolveJunctionSite
frozenSiteIndex); (c, e, successor, successor->locals[i], i, frozenSites,
frozenSiteIndex);
}
} }
if (successor->stack) { if (successor->stack) {
@ -2588,9 +2599,12 @@ populateSiteTables(Context* c, Event* e)
if (e->successors->next) { if (e->successors->next) {
unsigned size = sizeof(Site*) * frameFootprint; unsigned size = sizeof(Site*) * frameFootprint;
Site** savedSites = static_cast<Site**>(c->zone->allocate(size)); Site** savedSites = static_cast<Site**>(c->zone->allocate(size));
memset(savedSites, 0, size);
for (unsigned i = 0; i < c->localFootprint; ++i) { for (unsigned i = 0; i < c->localFootprint; ++i) {
savedSites[i] = successor->locals[i]->sites; if (successor->locals[i]) {
savedSites[i] = successor->locals[i]->sites;
}
} }
if (successor->stack) { if (successor->stack) {
@ -2613,9 +2627,11 @@ setSites(Context* c, Event* e, Site** sites)
{ {
for (unsigned i = 0; i < c->localFootprint; ++i) { for (unsigned i = 0; i < c->localFootprint; ++i) {
Value* v = e->locals[i]; Value* v = e->locals[i];
clearSites(c, v); if (v) {
if (live(v)) { clearSites(c, v);
addSite(c, 0, 0, v->reads->size(c), v, sites[i]); if (live(v)) {
addSite(c, 0, 0, v->reads->size(c), v, sites[i]);
}
} }
} }
@ -2705,7 +2721,9 @@ updateJunctionReads(Context* c, Event* e, Event* successor)
StubReadPair* reads = e->junctionReads; StubReadPair* reads = e->junctionReads;
for (unsigned i = 0; i < c->localFootprint; ++i) { for (unsigned i = 0; i < c->localFootprint; ++i) {
updateStubRead(c, reads++, successor->locals[i]->reads); if (successor->locals[i]) {
updateStubRead(c, reads++, successor->locals[i]->reads);
}
} }
for (Stack* s = successor->stack; s; s = s->next) { for (Stack* s = successor->stack; s; s = s->next) {
@ -3182,7 +3200,6 @@ class MyCompiler: public Compiler {
Value* result = value(&c); Value* result = value(&c);
appendCall(&c, static_cast<Value*>(address), flags, traceHandler, result, appendCall(&c, static_cast<Value*>(address), flags, traceHandler, result,
resultSize, c.stack, 0, argumentFootprint); resultSize, c.stack, 0, argumentFootprint);
return result; return result;
} }
@ -3193,6 +3210,7 @@ class MyCompiler: public Compiler {
virtual void initParameter(unsigned size, unsigned index) { virtual void initParameter(unsigned size, unsigned index) {
assert(&c, index < c.parameterFootprint); assert(&c, index < c.parameterFootprint);
fprintf(stderr, "init parameter %d size %d\n", index, size);
Value* v = value(&c); Value* v = value(&c);
appendParameter(&c, v, size, index); appendParameter(&c, v, size, index);
c.locals[index] = v; c.locals[index] = v;
@ -3370,7 +3388,7 @@ class MyCompiler: public Compiler {
} }
virtual unsigned compile() { virtual unsigned compile() {
return ::compile(&c); return c.machineCodeSize = ::compile(&c);
} }
virtual unsigned poolSize() { virtual unsigned poolSize() {
@ -3383,7 +3401,7 @@ class MyCompiler: public Compiler {
int i = 0; int i = 0;
for (ConstantPoolNode* n = c.firstConstant; n; n = n->next) { for (ConstantPoolNode* n = c.firstConstant; n; n = n->next) {
*reinterpret_cast<intptr_t*>(dst + pad(c.assembler->length()) + i) *reinterpret_cast<intptr_t*>(dst + pad(c.machineCodeSize) + i)
= n->promise->value(); = n->promise->value();
i += BytesPerWord; i += BytesPerWord;
} }

View File

@ -744,6 +744,34 @@ moveRM(Context* c, unsigned aSize, Assembler::Register* a,
} }
} }
void
moveMM(Context* c, unsigned aSize, Assembler::Memory* a,
unsigned bSize, Assembler::Memory* b)
{
assert(c, aSize == bSize);
if (BytesPerWord == 8 or aSize <= 4) {
uint32_t mask;
if (BytesPerWord == 4 and aSize == 1) {
mask = (1 << rax) | (1 << rcx) | (1 << rdx) | (1 << rbx);
} else {
mask = ~static_cast<uint32_t>(0);
}
Assembler::Register tmp(c->client->acquireTemporary(mask));
moveMR(c, aSize, a, aSize, &tmp);
moveRM(c, aSize, &tmp, bSize, b);
c->client->releaseTemporary(tmp.low);
} else {
Assembler::Register tmp(c->client->acquireTemporary(),
c->client->acquireTemporary());
moveMR(c, aSize, a, aSize, &tmp);
moveRM(c, aSize, &tmp, bSize, b);
c->client->releaseTemporary(tmp.low);
c->client->releaseTemporary(tmp.high);
}
}
void void
moveAR(Context* c, unsigned aSize, Assembler::Address* a, moveAR(Context* c, unsigned aSize, Assembler::Address* a,
unsigned bSize, Assembler::Register* b) unsigned bSize, Assembler::Register* b)
@ -851,6 +879,33 @@ compareRR(Context* c, unsigned aSize, Assembler::Register* a,
c->code.append(0xc0 | (a->low << 3) | b->low); c->code.append(0xc0 | (a->low << 3) | b->low);
} }
void
compareCR(Context* c, unsigned aSize, Assembler::Constant* a,
unsigned bSize, Assembler::Register* b)
{
assert(c, aSize == bSize);
assert(c, BytesPerWord == 8 or aSize == 4);
int64_t v = a->value->value();
if (isInt32(v)) {
if (aSize == 8) rex(c);
if (isInt8(v)) {
c->code.append(0x83);
c->code.append(0xf8 | b->low);
c->code.append(v);
} else {
c->code.append(0x81);
c->code.append(0xf8 | b->low);
c->code.append4(v);
}
} else {
Assembler::Register tmp(c->client->acquireTemporary());
moveCR(c, aSize, a, aSize, &tmp);
compareRR(c, aSize, &tmp, bSize, b);
c->client->releaseTemporary(tmp.low);
}
}
void void
addCarryRR(Context* c, unsigned size, Assembler::Register* a, addCarryRR(Context* c, unsigned size, Assembler::Register* a,
Assembler::Register* b) Assembler::Register* b)
@ -1141,6 +1196,7 @@ populateTables(ArchitectureContext* c)
zo[Return] = return_; zo[Return] = return_;
uo[index(Call, C)] = CAST1(callC); uo[index(Call, C)] = CAST1(callC);
uo[index(Call, R)] = CAST1(callR);
uo[index(AlignedCall, C)] = CAST1(alignedCallC); uo[index(AlignedCall, C)] = CAST1(alignedCallC);
@ -1165,8 +1221,11 @@ populateTables(ArchitectureContext* c)
bo[index(Move, R, M)] = CAST2(moveRM); bo[index(Move, R, M)] = CAST2(moveRM);
bo[index(Move, C, M)] = CAST2(moveCM); bo[index(Move, C, M)] = CAST2(moveCM);
bo[index(Move, A, M)] = CAST2(moveAM); bo[index(Move, A, M)] = CAST2(moveAM);
bo[index(Move, A, R)] = CAST2(moveAR);
bo[index(Move, M, M)] = CAST2(moveMM);
bo[index(Compare, R, R)] = CAST2(compareRR); bo[index(Compare, R, R)] = CAST2(compareRR);
bo[index(Compare, C, R)] = CAST2(compareCR);
bo[index(Add, C, R)] = CAST2(addCR); bo[index(Add, C, R)] = CAST2(addCR);
@ -1454,11 +1513,18 @@ class MyAssembler: public Assembler {
unsigned offset = 0; unsigned offset = 0;
for (unsigned i = 0; i < argumentCount; ++i) { for (unsigned i = 0; i < argumentCount; ++i) {
Memory dst(rsp, offset * BytesPerWord); if (i < arch_->argumentRegisterCount()) {
apply(Move, Register dst(arch_->argumentRegister(i));
arguments[i].size, arguments[i].type, arguments[i].operand, apply(Move,
pad(arguments[i].size), MemoryOperand, &dst); arguments[i].size, arguments[i].type, arguments[i].operand,
offset += ceiling(arguments[i].size, BytesPerWord); pad(arguments[i].size), RegisterOperand, &dst);
} else {
Memory dst(rsp, offset * BytesPerWord);
apply(Move,
arguments[i].size, arguments[i].type, arguments[i].operand,
pad(arguments[i].size), MemoryOperand, &dst);
offset += ceiling(arguments[i].size, BytesPerWord);
}
} }
} }