various bugfixes

This commit is contained in:
Joel Dice 2009-04-22 01:39:25 +00:00
parent 717f359666
commit 3113ae74eb
5 changed files with 63 additions and 53 deletions

View File

@ -282,8 +282,6 @@ class Assembler {
virtual void updateCall(UnaryOperation op, bool assertAlignment, virtual void updateCall(UnaryOperation op, bool assertAlignment,
void* returnAddress, void* newTarget) = 0; void* returnAddress, void* newTarget) = 0;
virtual unsigned constantCallSize() = 0;
virtual uintptr_t getConstant(const void* src) = 0; virtual uintptr_t getConstant(const void* src) = 0;
virtual void setConstant(void* dst, uintptr_t constant) = 0; virtual void setConstant(void* dst, uintptr_t constant) = 0;
@ -293,8 +291,8 @@ class Assembler {
virtual unsigned frameHeaderSize() = 0; virtual unsigned frameHeaderSize() = 0;
virtual unsigned frameReturnAddressSize() = 0; virtual unsigned frameReturnAddressSize() = 0;
virtual unsigned frameFooterSize() = 0; virtual unsigned frameFooterSize() = 0;
virtual unsigned returnAddressOffset() = 0; virtual int returnAddressOffset() = 0;
virtual unsigned framePointerOffset() = 0; virtual int framePointerOffset() = 0;
virtual void nextFrame(void** stack, void** base) = 0; virtual void nextFrame(void** stack, void** base) = 0;
virtual void plan virtual void plan

View File

@ -487,11 +487,11 @@ class TraceElementPromise: public Promise {
virtual int64_t value() { virtual int64_t value() {
assert(s, resolved()); assert(s, resolved());
return reinterpret_cast<uintptr_t>(trace->address); return trace->address->value();
} }
virtual bool resolved() { virtual bool resolved() {
return trace->address != 0; return trace->address != 0 and trace->address->resolved();
} }
System* s; System* s;
@ -1943,7 +1943,7 @@ compileDirectInvoke(MyThread* t, Frame* frame, object target, bool tailCall,
Compiler::Operand* result = c->stackCall Compiler::Operand* result = c->stackCall
(returnAddress, (returnAddress,
flags | Compiler::Aligned, flags | Compiler::Aligned,
0, trace,
rSize, rSize,
methodParameterFootprint(t, target)); methodParameterFootprint(t, target));
@ -1982,14 +1982,16 @@ compileDirectInvoke(MyThread* t, Frame* frame, object target, bool tailCall,
} }
} }
void bool
compileDirectInvoke(MyThread* t, Frame* frame, object target, bool tailCall) compileDirectInvoke(MyThread* t, Frame* frame, object target, bool tailCall)
{ {
unsigned rSize = resultSize(t, methodReturnCode(t, target)); unsigned rSize = resultSize(t, methodReturnCode(t, target));
Compiler::Operand* result = 0; Compiler::Operand* result = 0;
if (not emptyMethod(t, target)) { if (emptyMethod(t, target)) {
tailCall = false;
} else {
BootContext* bc = frame->context->bootContext; BootContext* bc = frame->context->bootContext;
if (bc) { if (bc) {
if (methodClass(t, target) == methodClass(t, frame->context->method) if (methodClass(t, target) == methodClass(t, frame->context->method)
@ -2024,6 +2026,8 @@ compileDirectInvoke(MyThread* t, Frame* frame, object target, bool tailCall)
if (rSize) { if (rSize) {
pushReturnValue(t, frame, methodReturnCode(t, target), result); pushReturnValue(t, frame, methodReturnCode(t, target), result);
} }
return tailCall;
} }
void void
@ -3157,7 +3161,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip,
tailCall = isTailCall(t, code, ip, context->method, target); tailCall = isTailCall(t, code, ip, context->method, target);
compileDirectInvoke(t, frame, target, tailCall); tailCall = compileDirectInvoke(t, frame, target, tailCall);
} break; } break;
case invokestatic: { case invokestatic: {
@ -3170,7 +3174,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip,
tailCall = isTailCall(t, code, ip, context->method, target); tailCall = isTailCall(t, code, ip, context->method, target);
compileDirectInvoke(t, frame, target, tailCall); tailCall = compileDirectInvoke(t, frame, target, tailCall);
} break; } break;
case invokevirtual: { case invokevirtual: {
@ -3199,7 +3203,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip,
Compiler::Operand* result = c->stackCall Compiler::Operand* result = c->stackCall
(c->memory(classOperand, offset, 0, 1), (c->memory(classOperand, offset, 0, 1),
tailCall ? Compiler::TailCall : 0, tailCall ? Compiler::TailJump : 0,
frame->trace(0, 0), frame->trace(0, 0),
rSize, rSize,
parameterFootprint); parameterFootprint);
@ -4594,11 +4598,9 @@ compileMethod2(MyThread* t, void* ip)
} else { } else {
void* address = reinterpret_cast<void*>(methodAddress(t, target)); void* address = reinterpret_cast<void*>(methodAddress(t, target));
uint8_t* updateIp = static_cast<uint8_t*>(ip); uint8_t* updateIp = static_cast<uint8_t*>(ip);
if (callNodeFlags(t, node) & TraceElement::TailCall) {
updateIp -= t->arch->constantCallSize();
}
updateCall(t, Call, true, updateIp, address); updateCall(t, (callNodeFlags(t, node) & TraceElement::TailCall)
? Jump : Call, true, updateIp, address);
return address; return address;
} }

View File

@ -649,10 +649,8 @@ int
frameIndex(Context* c, int localIndex) frameIndex(Context* c, int localIndex)
{ {
assert(c, localIndex >= 0); assert(c, localIndex >= 0);
assert(c, localIndex < static_cast<int>
(c->parameterFootprint + c->localFootprint));
int index = c->alignedFrameSize + c->parameterFootprint - localIndex; int index = c->alignedFrameSize + c->parameterFootprint - localIndex - 1;
if (localIndex < static_cast<int>(c->parameterFootprint)) { if (localIndex < static_cast<int>(c->parameterFootprint)) {
index += c->arch->frameHeaderSize(); index += c->arch->frameHeaderSize();
@ -661,6 +659,7 @@ frameIndex(Context* c, int localIndex)
} }
assert(c, index >= 0); assert(c, index >= 0);
assert(c, static_cast<unsigned>(index) < totalFrameSize(c));
return index; return index;
} }
@ -668,15 +667,31 @@ frameIndex(Context* c, int localIndex)
unsigned unsigned
frameIndexToOffset(Context* c, unsigned frameIndex) frameIndexToOffset(Context* c, unsigned frameIndex)
{ {
assert(c, frameIndex < totalFrameSize(c));
return (frameIndex + c->arch->frameFooterSize()) * BytesPerWord; return (frameIndex + c->arch->frameFooterSize()) * BytesPerWord;
} }
unsigned unsigned
offsetToFrameIndex(Context* c, unsigned offset) offsetToFrameIndex(Context* c, unsigned offset)
{ {
assert(c, static_cast<int>
((offset / BytesPerWord) - c->arch->frameFooterSize()) >= 0);
assert(c, (offset / BytesPerWord) - c->arch->frameFooterSize()
< totalFrameSize(c));
return (offset / BytesPerWord) - c->arch->frameFooterSize(); return (offset / BytesPerWord) - c->arch->frameFooterSize();
} }
unsigned
frameBase(Context* c)
{
return c->alignedFrameSize - 1
- c->arch->frameFooterSize()
+ c->arch->frameHeaderSize();
}
class FrameIterator { class FrameIterator {
public: public:
class Element { class Element {
@ -2307,10 +2322,10 @@ class CallEvent: public Event {
int returnAddressIndex = -1; int returnAddressIndex = -1;
int framePointerIndex = -1; int framePointerIndex = -1;
if (flags & (Compiler::TailJump | Compiler::TailCall)) { if (flags & Compiler::TailJump) {
assert(c, argumentCount == 0); assert(c, argumentCount == 0);
unsigned base = c->alignedFrameSize - c->arch->frameFooterSize(); int base = frameBase(c);
returnAddressIndex = base + c->arch->returnAddressOffset(); returnAddressIndex = base + c->arch->returnAddressOffset();
framePointerIndex = base + c->arch->framePointerOffset(); framePointerIndex = base + c->arch->framePointerOffset();
@ -2387,9 +2402,7 @@ class CallEvent: public Event {
addRead(c, this, s->value, read addRead(c, this, s->value, read
(c, SiteMask(1 << MemoryOperand, 0, frameIndex))); (c, SiteMask(1 << MemoryOperand, 0, frameIndex)));
} }
} } else if ((flags & Compiler::TailJump) == 0) {
else if ((flags & (Compiler::TailJump | Compiler::TailCall)) == 0)
{
unsigned logicalIndex = ::frameIndex unsigned logicalIndex = ::frameIndex
(c, s->index + c->localFootprint); (c, s->index + c->localFootprint);
@ -2405,7 +2418,7 @@ class CallEvent: public Event {
-- footprint; -- footprint;
if (footprint == 0) { if (footprint == 0 and (flags & Compiler::TailJump) == 0) {
unsigned logicalIndex = ::frameIndex unsigned logicalIndex = ::frameIndex
(c, s->index + c->localFootprint); (c, s->index + c->localFootprint);
@ -2418,7 +2431,7 @@ class CallEvent: public Event {
++ frameIndex; ++ frameIndex;
} }
if ((flags & (Compiler::TailJump | Compiler::TailCall)) == 0) { if ((flags & Compiler::TailJump) == 0) {
popIndex popIndex
= c->alignedFrameSize = c->alignedFrameSize
- c->arch->frameFooterSize() - c->arch->frameFooterSize()
@ -2438,19 +2451,11 @@ class CallEvent: public Event {
virtual void compile(Context* c) { virtual void compile(Context* c) {
UnaryOperation op; UnaryOperation op;
if (flags & (Compiler::TailJump | Compiler::TailCall)) { if (flags & Compiler::TailJump) {
if (flags & Compiler::TailJump) { if (flags & Compiler::Aligned) {
if (flags & Compiler::Aligned) { op = AlignedJump;
op = AlignedJump;
} else {
op = Jump;
}
} else { } else {
if (flags & Compiler::Aligned) { op = Jump;
op = AlignedCall;
} else {
op = Call;
}
} }
assert(c, returnAddressSurrogate == 0 assert(c, returnAddressSurrogate == 0
@ -2464,8 +2469,8 @@ class CallEvent: public Event {
(framePointerSurrogate->source)->number : NoRegister); (framePointerSurrogate->source)->number : NoRegister);
int offset int offset
= static_cast<int>(c->arch->argumentFootprint(c->parameterFootprint)) = static_cast<int>(c->arch->argumentFootprint(stackArgumentFootprint))
- static_cast<int>(c->arch->argumentFootprint(stackArgumentFootprint)); - static_cast<int>(c->arch->argumentFootprint(c->parameterFootprint));
c->assembler->popFrameForTailCall(c->alignedFrameSize, offset, ras, fps); c->assembler->popFrameForTailCall(c->alignedFrameSize, offset, ras, fps);
} else if (flags & Compiler::Aligned) { } else if (flags & Compiler::Aligned) {
@ -4920,7 +4925,7 @@ class MyCompiler: public Compiler {
new (c.frameResources + i) FrameResource; new (c.frameResources + i) FrameResource;
} }
unsigned base = alignedFrameSize - c.arch->frameFooterSize(); unsigned base = frameBase(&c);
c.frameResources[base + c.arch->returnAddressOffset()].reserved = true; c.frameResources[base + c.arch->returnAddressOffset()].reserved = true;
c.frameResources[base + c.arch->framePointerOffset()].reserved = true; c.frameResources[base + c.arch->framePointerOffset()].reserved = true;

View File

@ -27,8 +27,7 @@ class Compiler {
static const unsigned Aligned = 1 << 0; static const unsigned Aligned = 1 << 0;
static const unsigned NoReturn = 1 << 1; static const unsigned NoReturn = 1 << 1;
static const unsigned TailCall = 1 << 2; static const unsigned TailJump = 1 << 2;
static const unsigned TailJump = 1 << 3;
class Operand { }; class Operand { };
class StackElement { }; class StackElement { };

View File

@ -673,6 +673,13 @@ alignedCallC(Context* c, unsigned size, Assembler::Constant* a)
callC(c, size, a); callC(c, size, a);
} }
void
alignedJumpC(Context* c, unsigned size, Assembler::Constant* a)
{
new (c->zone->allocate(sizeof(AlignmentPadding))) AlignmentPadding(c);
jumpC(c, size, a);
}
void void
pushR(Context* c, unsigned size, Assembler::Register* a) pushR(Context* c, unsigned size, Assembler::Register* a)
{ {
@ -1938,6 +1945,8 @@ populateTables(ArchitectureContext* c)
uo[index(Jump, C)] = CAST1(jumpC); uo[index(Jump, C)] = CAST1(jumpC);
uo[index(Jump, M)] = CAST1(jumpM); uo[index(Jump, M)] = CAST1(jumpM);
uo[index(AlignedJump, C)] = CAST1(alignedJumpC);
uo[index(JumpIfEqual, C)] = CAST1(jumpIfEqualC); uo[index(JumpIfEqual, C)] = CAST1(jumpIfEqualC);
uo[index(JumpIfNotEqual, C)] = CAST1(jumpIfNotEqualC); uo[index(JumpIfNotEqual, C)] = CAST1(jumpIfNotEqualC);
uo[index(JumpIfGreater, C)] = CAST1(jumpIfGreaterC); uo[index(JumpIfGreater, C)] = CAST1(jumpIfGreaterC);
@ -2126,10 +2135,6 @@ class MyArchitecture: public Assembler::Architecture {
} }
} }
virtual unsigned constantCallSize() {
return 5;
}
virtual uintptr_t getConstant(const void* src) { virtual uintptr_t getConstant(const void* src) {
uintptr_t v; uintptr_t v;
memcpy(&v, src, BytesPerWord); memcpy(&v, src, BytesPerWord);
@ -2162,12 +2167,12 @@ class MyArchitecture: public Assembler::Architecture {
return 0; return 0;
} }
virtual unsigned returnAddressOffset() { virtual int returnAddressOffset() {
return 1; return 0;
} }
virtual unsigned framePointerOffset() { virtual int framePointerOffset() {
return 0; return -1;
} }
virtual void nextFrame(void** stack, void** base) { virtual void nextFrame(void** stack, void** base) {
@ -2427,12 +2432,13 @@ class MyAssembler: public Assembler {
c.client->releaseTemporary(tmp.low); c.client->releaseTemporary(tmp.low);
Memory baseSrc(rbp, footprint * BytesPerWord); Memory baseSrc(rsp, footprint * BytesPerWord);
Register base(rbp); Register base(rbp);
moveMR(&c, BytesPerWord, &baseSrc, BytesPerWord, &base); moveMR(&c, BytesPerWord, &baseSrc, BytesPerWord, &base);
Register stack(rsp); Register stack(rsp);
Constant footprintConstant(resolved(&c, footprint * BytesPerWord)); Constant footprintConstant
(resolved(&c, (footprint - offset + 1) * BytesPerWord));
addCR(&c, BytesPerWord, &footprintConstant, BytesPerWord, &stack); addCR(&c, BytesPerWord, &footprintConstant, BytesPerWord, &stack);
if (returnAddressSurrogate != NoRegister) { if (returnAddressSurrogate != NoRegister) {