various bugfixes

This commit is contained in:
Joel Dice 2009-05-14 20:08:01 -06:00
parent 3d1ef68001
commit 57cec2d068
4 changed files with 40 additions and 70 deletions

View File

@ -738,13 +738,6 @@ translateLocalIndex(Context* context, unsigned footprint, unsigned index)
} }
} }
void
initLocal(Context* context, unsigned footprint, unsigned index)
{
context->compiler->initLocal
(footprint, translateLocalIndex(context, footprint, index));
}
Compiler::Operand* Compiler::Operand*
loadLocal(Context* context, unsigned footprint, unsigned index) loadLocal(Context* context, unsigned footprint, unsigned index)
{ {
@ -1105,13 +1098,7 @@ class Frame {
void pop(unsigned count) { void pop(unsigned count) {
popped(count); popped(count);
c->popped(count);
for (unsigned i = count; i;) {
Compiler::StackElement* s = c->top();
unsigned footprint = c->footprint(s);
c->popped(footprint);
i -= footprint;
}
} }
Compiler::Operand* popInt() { Compiler::Operand* popInt() {
@ -3261,8 +3248,9 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip,
uint8_t index = codeBody(t, code, ip++); uint8_t index = codeBody(t, code, ip++);
int8_t count = codeBody(t, code, ip++); int8_t count = codeBody(t, code, ip++);
c->storeLocal storeLocal
(1, c->add(4, c->constant(count), loadLocal(context, 1, index)), (context, 1,
c->add(4, c->constant(count), loadLocal(context, 1, index)),
index); index);
} break; } break;
@ -3810,7 +3798,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip,
unsigned offset unsigned offset
= (localOffset = (localOffset
(t, localSize(t, context->method) + c->index(c->top()), (t, localSize(t, context->method) + c->topOfStack(),
context->method) / BytesPerWord) context->method) / BytesPerWord)
+ t->arch->frameReturnAddressSize(); + t->arch->frameReturnAddressSize();
@ -4117,8 +4105,9 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip,
uint16_t index = codeReadInt16(t, code, ip); uint16_t index = codeReadInt16(t, code, ip);
uint16_t count = codeReadInt16(t, code, ip); uint16_t count = codeReadInt16(t, code, ip);
c->storeLocal storeLocal
(1, c->add(4, c->constant(count), loadLocal(context, 1, index)), (context, 1,
c->add(4, c->constant(count), loadLocal(context, 1, index)),
index); index);
} break; } break;
@ -4611,10 +4600,10 @@ compile(MyThread* t, Allocator* allocator, Context* context)
uint8_t stackMap[codeMaxStack(t, methodCode(t, context->method))]; uint8_t stackMap[codeMaxStack(t, methodCode(t, context->method))];
Frame frame(context, stackMap); Frame frame(context, stackMap);
unsigned index = 0; unsigned index = methodParameterFootprint(t, context->method);
if ((methodFlags(t, context->method) & ACC_STATIC) == 0) { if ((methodFlags(t, context->method) & ACC_STATIC) == 0) {
initLocal(context, 1, index); frame.set(--index, Frame::Object);
frame.set(index++, Frame::Object); c->initLocal(1, index);
} }
for (MethodSpecIterator it for (MethodSpecIterator it
@ -4625,20 +4614,20 @@ compile(MyThread* t, Allocator* allocator, Context* context)
switch (*it.next()) { switch (*it.next()) {
case 'L': case 'L':
case '[': case '[':
initLocal(context, 1, index); frame.set(--index, Frame::Object);
frame.set(index++, Frame::Object); c->initLocal(1, index);
break; break;
case 'J': case 'J':
case 'D': case 'D':
initLocal(context, 2, index); frame.set(--index, Frame::Long);
frame.set(index++, Frame::Long); frame.set(--index, Frame::Long);
frame.set(index++, Frame::Long); c->initLocal(2, index);
break; break;
default: default:
initLocal(context, 1, index); frame.set(--index, Frame::Integer);
frame.set(index++, Frame::Integer); c->initLocal(1, index);
break; break;
} }
} }
@ -5151,11 +5140,10 @@ visitStackAndLocals(MyThread* t, Heap::Visitor* v, void* frame, object method,
} }
void void
visitArgument(MyThread* t, Heap::Visitor* v, void* stack, object method, visitArgument(MyThread* t, Heap::Visitor* v, void* stack, unsigned index)
unsigned index)
{ {
v->visit(static_cast<object*>(stack) v->visit(static_cast<object*>(stack)
+ (methodParameterFootprint(t, method) - index - 1) + index
+ t->arch->frameReturnAddressSize() + t->arch->frameReturnAddressSize()
+ t->arch->frameFooterSize()); + t->arch->frameFooterSize());
} }
@ -5166,7 +5154,7 @@ visitArguments(MyThread* t, Heap::Visitor* v, void* stack, object method)
unsigned index = 0; unsigned index = 0;
if ((methodFlags(t, method) & ACC_STATIC) == 0) { if ((methodFlags(t, method) & ACC_STATIC) == 0) {
visitArgument(t, v, stack, method, index++); visitArgument(t, v, stack, index++);
} }
for (MethodSpecIterator it for (MethodSpecIterator it
@ -5177,7 +5165,7 @@ visitArguments(MyThread* t, Heap::Visitor* v, void* stack, object method)
switch (*it.next()) { switch (*it.next()) {
case 'L': case 'L':
case '[': case '[':
visitArgument(t, v, stack, method, index++); visitArgument(t, v, stack, index++);
break; break;
case 'J': case 'J':
@ -5435,13 +5423,14 @@ invoke(Thread* thread, object method, ArgumentList* arguments)
trace.nativeMethod = method; trace.nativeMethod = method;
} }
unsigned count = arguments->size - arguments->position; assert(t, arguments->position == arguments->size);
result = vmInvoke result = vmInvoke
(t, reinterpret_cast<void*>(methodAddress(t, method)), (t, reinterpret_cast<void*>(methodAddress(t, method)),
arguments->array + arguments->position, arguments->array,
count * BytesPerWord, arguments->position * BytesPerWord,
t->arch->alignFrameSize(count + t->arch->frameFootprint(0)) t->arch->alignFrameSize
(arguments->position + t->arch->frameFootprint(0))
* BytesPerWord, * BytesPerWord,
returnType); returnType);
} }

View File

@ -138,7 +138,7 @@ class SitePair {
Site* high; Site* high;
}; };
class Stack: public Compiler::StackElement { class Stack {
public: public:
Stack(unsigned index, Value* value, Stack* next): Stack(unsigned index, Value* value, Stack* next):
index(index), value(value), next(next) index(index), value(value), next(next)
@ -5140,35 +5140,19 @@ class MyCompiler: public Compiler {
} }
virtual void popped(unsigned footprint) { virtual void popped(unsigned footprint) {
assert(&c, c.stack->value->home >= 0); for (; footprint; -- footprint) {
assert(&c, c.stack->value == 0 or c.stack->value->home >= 0);
if (footprint > 1) { if (DebugFrame) {
assert(&c, footprint == 2); fprintf(stderr, "popped %p\n", c.stack->value);
assert(&c, c.stack->value->high == c.stack->next->value }
and ((BytesPerWord == 8) xor (c.stack->value->high != 0)));
c.stack = c.stack->next;
popped(1);
} }
if (DebugFrame) {
fprintf(stderr, "popped %p\n", c.stack->value);
}
c.stack = c.stack->next;
} }
virtual StackElement* top() { virtual unsigned topOfStack() {
return c.stack; return c.stack->index;
}
virtual unsigned footprint(StackElement* e) {
return (static_cast<Stack*>(e)->next
and (static_cast<Stack*>(e)->next->value
== static_cast<Stack*>(e)->value->high)) ? 2 : 1;
}
virtual unsigned index(StackElement* e) {
return static_cast<Stack*>(e)->index;
} }
virtual Operand* peek(unsigned footprint, unsigned index) { virtual Operand* peek(unsigned footprint, unsigned index) {

View File

@ -35,7 +35,6 @@ class Compiler {
static const unsigned TailJump = 1 << 2; static const unsigned TailJump = 1 << 2;
class Operand { }; class Operand { };
class StackElement { };
class State { }; class State { };
class Subroutine { }; class Subroutine { };
@ -73,9 +72,7 @@ class Compiler {
virtual Operand* pop(unsigned footprint) = 0; virtual Operand* pop(unsigned footprint) = 0;
virtual void pushed() = 0; virtual void pushed() = 0;
virtual void popped(unsigned footprint) = 0; virtual void popped(unsigned footprint) = 0;
virtual StackElement* top() = 0; virtual unsigned topOfStack() = 0;
virtual unsigned footprint(StackElement*) = 0;
virtual unsigned index(StackElement*) = 0;
virtual Operand* peek(unsigned footprint, unsigned index) = 0; virtual Operand* peek(unsigned footprint, unsigned index) = 0;
virtual Operand* call(Operand* address, virtual Operand* call(Operand* address,

View File

@ -115,11 +115,11 @@ LOCAL(exit):
.globl vmJump .globl vmJump
vmJump: vmJump:
movq %r8,%rax
movq %r9,%rdx
movq %rsi,%rbp movq %rsi,%rbp
movq %rdx,%rsp movq %rdx,%rsp
movq %rcx,%rbx movq %rcx,%rbx
movq %r8,%rax
movq %r9,%rdx
jmp *%rdi jmp *%rdi
#elif defined __i386__ #elif defined __i386__