diff --git a/src/assembler.h b/src/assembler.h index 0b9470a605..779c71bfd7 100644 --- a/src/assembler.h +++ b/src/assembler.h @@ -187,6 +187,7 @@ class Assembler { virtual void* frameIp(void* stack) = 0; virtual unsigned frameHeaderSize() = 0; + virtual unsigned frameReturnAddressSize() = 0; virtual unsigned frameFooterSize() = 0; virtual void nextFrame(void** stack, void** base) = 0; virtual void* popReturnAddress(void* stack) = 0; diff --git a/src/compile.cpp b/src/compile.cpp index 8eb522bf96..c81cdb61fb 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -31,7 +31,7 @@ const bool Verbose = true; const bool DebugNatives = false; const bool DebugCallTable = false; const bool DebugMethodTree = false; -const bool DebugFrameMaps = true; +const bool DebugFrameMaps = false; const bool CheckArrayBounds = true; @@ -376,7 +376,9 @@ inline object* localObject(MyThread* t, void* stack, object method, unsigned index) { return reinterpret_cast - (static_cast(stack) + localOffset(t, index, method)); + (static_cast(stack) + + localOffset(t, index, method) + + (t->arch->frameReturnAddressSize() * BytesPerWord)); } class PoolElement { @@ -1192,7 +1194,7 @@ findUnwindTarget(MyThread* t, void** targetIp, void** targetBase, if (methodFlags(t, method) & ACC_STATIC) { lock = methodClass(t, method); } else { - lock = *localObject(t, base, method, savedTargetIndex(t, method)); + lock = *localObject(t, stack, method, savedTargetIndex(t, method)); } release(t, lock); @@ -3664,7 +3666,7 @@ calculateFrameMaps(MyThread* t, Context* context, uintptr_t* originalRoots, unsigned i = context->eventLog.get2(eventIndex); eventIndex += 2; - if (i > localSize) { + if (i >= localSize) { i += stackPadding; } @@ -3675,7 +3677,7 @@ calculateFrameMaps(MyThread* t, Context* context, uintptr_t* originalRoots, unsigned i = context->eventLog.get2(eventIndex); eventIndex += 2; - if (i > localSize) { + if (i >= localSize) { i += stackPadding; } @@ -3862,11 +3864,11 @@ finish(MyThread* t, Context* context) strcmp (reinterpret_cast (&byteArrayBody(t, className(t, methodClass(t, context->method)), 0)), - "Simple") == 0 and + "GC") == 0 and strcmp (reinterpret_cast (&byteArrayBody(t, methodName(t, context->method), 0)), - "size") == 0) + "main") == 0) { asm("int3"); } diff --git a/src/compiler.cpp b/src/compiler.cpp index 8ce66726d7..12443467ad 100644 --- a/src/compiler.cpp +++ b/src/compiler.cpp @@ -2207,6 +2207,17 @@ codePromise(Context* c, Promise* offset) return new (c->zone->allocate(sizeof(CodePromise))) CodePromise(c, offset); } +void +setPadding(Context* c, Stack* s, unsigned realIndex) +{ + unsigned logicalIndex = frameIndex + (c, s->index + c->localFootprint, s->footprint); + + assert(c, logicalIndex >= realIndex); + + s->paddingInWords = logicalIndex - realIndex; +} + void append(Context* c, Event* e); @@ -2228,29 +2239,38 @@ class CallEvent: public Event { Stack* s = argumentStack; unsigned index = 0; unsigned frameIndex = 0; - for (unsigned i = 0; i < argumentCount; ++i) { - Read* target; - if (index < c->arch->argumentRegisterCount()) { - int r = c->arch->argumentRegister(index); + + if (argumentCount) { + unsigned ai = 0; + while (true) { + Read* target; + if (index < c->arch->argumentRegisterCount()) { + int r = c->arch->argumentRegister(index); - if (DebugReads) { - fprintf(stderr, "reg %d arg read %p\n", r, s->value); - } + if (DebugReads) { + fprintf(stderr, "reg %d arg read %p\n", r, s->value); + } - target = fixedRegisterRead(c, footprintSizeInBytes(s->footprint), r); - mask &= ~(1 << r); - } else { - if (DebugReads) { - fprintf(stderr, "stack %d arg read %p\n", frameIndex, s->value); - } + target = fixedRegisterRead(c, footprintSizeInBytes(s->footprint), r); + mask &= ~(1 << r); + } else { + if (DebugReads) { + fprintf(stderr, "stack %d arg read %p\n", frameIndex, s->value); + } - target = read(c, footprintSizeInBytes(s->footprint), - 1 << MemoryOperand, 0, frameIndex); - frameIndex += s->footprint; + target = read(c, footprintSizeInBytes(s->footprint), + 1 << MemoryOperand, 0, frameIndex); + frameIndex += s->footprint; + } + addRead(c, this, s->value, target); + index += s->footprint; + + if ((++ ai) < argumentCount) { + s = s->next; + } else { + break; + } } - addRead(c, this, s->value, target); - index += s->footprint; - s = s->next; } if (DebugReads) { @@ -2262,40 +2282,60 @@ class CallEvent: public Event { AnyFrameIndex)); int footprint = stackArgumentFootprint; + + if (footprint == 0 and s) { + setPadding(c, s, frameIndex); + } + for (Stack* s = stackBefore; s; s = s->next) { if (footprint > 0) { if (DebugReads) { - fprintf(stderr, "stack arg read %p of footprint %d at %d of %d\n", s->value, s->footprint, frameIndex, c->alignedFrameSize + c->parameterFootprint); + fprintf(stderr, "stack arg read %p of footprint %d at %d of %d\n", + s->value, s->footprint, frameIndex, + c->alignedFrameSize + c->parameterFootprint); } addRead(c, this, s->value, read (c, footprintSizeInBytes(s->footprint), 1 << MemoryOperand, 0, frameIndex)); - } else { - unsigned index = ::frameIndex - (c, s->index + c->localFootprint, s->footprint); + } else { if (footprint == 0) { - assert(c, index >= frameIndex); - s->paddingInWords = index - frameIndex; - popIndex = index; + popIndex = frameIndex; } + unsigned index = ::frameIndex + (c, s->index + c->localFootprint, s->footprint); + if (DebugReads) { - fprintf(stderr, "stack save read %p of footprint %d at %d of %d\n", s->value, s->footprint, index, c->alignedFrameSize + c->parameterFootprint); + fprintf(stderr, "stack save read %p of footprint %d at %d of %d\n", + s->value, s->footprint, index, + c->alignedFrameSize + c->parameterFootprint); } addRead(c, this, s->value, read - (c, footprintSizeInBytes(s->footprint), 1 << MemoryOperand, 0, - index)); + (c, footprintSizeInBytes(s->footprint), 1 << MemoryOperand, + 0, index)); } - frameIndex += s->footprint; + footprint -= s->footprint; + + if (footprint == 0) { + setPadding(c, s, frameIndex); + } + + frameIndex += s->footprint; } for (unsigned li = 0; li < c->localFootprint; ++li) { Local* local = localsBefore + li; if (local->value) { - fprintf(stderr, "local save read %p of footprint %d at %d of %d\n", local->value, local->footprint, ::frameIndex(c, li, local->footprint), c->alignedFrameSize + c->parameterFootprint); + if (DebugReads) { + fprintf(stderr, "local save read %p of footprint %d at %d of %d\n", + local->value, local->footprint, + ::frameIndex(c, li, local->footprint), + c->alignedFrameSize + c->parameterFootprint); + } + addRead(c, this, local->value, read (c, footprintSizeInBytes(local->footprint), 1 << MemoryOperand, 0, ::frameIndex(c, li, local->footprint))); @@ -3988,8 +4028,8 @@ class MyCompiler: public Compiler { Event* p = c.predecessor; if (p) { - fprintf(stderr, "visit %d pred %d\n", logicalIp, - p->logicalInstruction->index); +// fprintf(stderr, "visit %d pred %d\n", logicalIp, +// p->logicalInstruction->index); p->stackAfter = c.stack; p->localsAfter = c.locals; diff --git a/src/x86.cpp b/src/x86.cpp index 954efe34ef..0cf9d22960 100644 --- a/src/x86.cpp +++ b/src/x86.cpp @@ -1958,6 +1958,10 @@ class MyArchitecture: public Assembler::Architecture { return FrameHeaderSize; } + virtual unsigned frameReturnAddressSize() { + return 1; + } + virtual unsigned frameFooterSize() { return 0; }