From fab77e4d96db1ffe3cf5e45b088e3bc30f2c5daf Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 11 Dec 2007 18:19:03 -0700 Subject: [PATCH] don't call prologue and epilogue from compileDefault, since we want the original rbp and rsp values --- src/compile.cpp | 13 ++++++--- src/compiler.cpp | 76 +++++++++++++++++++++++++++++++++--------------- test/Misc.java | 6 ++-- 3 files changed, 64 insertions(+), 31 deletions(-) diff --git a/src/compile.cpp b/src/compile.cpp index 9c2f43b902..b4e70e5296 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -3158,13 +3158,9 @@ visitStack(MyThread* t, Heap::Visitor* v) object compileDefault(MyThread* t, Compiler* c) { - c->prologue(); - c->mov(c->base(), c->memory(c->thread(), difference(&(t->base), t))); c->mov(c->stack(), c->memory(c->thread(), difference(&(t->stack), t))); - c->epilogue(); - c->jmp (c->directCall (c->constant(reinterpret_cast(compileMethod)), @@ -3693,6 +3689,10 @@ compile(MyThread* t, object method) object findTraceNode(MyThread* t, void* address) { + if (Verbose) { + fprintf(stderr, "find trace node %p\n", address); + } + MyProcessor* p = processor(t); ACQUIRE(t, t->m->classLock); @@ -3739,6 +3739,11 @@ resizeTable(MyThread* t, object oldTable, unsigned newLength) void insertTraceNode(MyThread* t, object node) { + if (Verbose) { + fprintf(stderr, "insert trace node %p\n", + reinterpret_cast(traceNodeAddress(t, node))); + } + MyProcessor* p = processor(t); PROTECT(t, node); ACQUIRE(t, t->m->classLock); diff --git a/src/compiler.cpp b/src/compiler.cpp index a57eeeff97..eb5d853729 100644 --- a/src/compiler.cpp +++ b/src/compiler.cpp @@ -285,7 +285,10 @@ class MemoryOperand: public MyOperand { displacement(displacement), index(index), scale(scale) - { } + { + assert(static_cast(0), index == 0); // todo + assert(static_cast(0), scale == 1); // todo + } virtual StackOperand* logicalPush(Context* c); @@ -347,6 +350,10 @@ class StackOperand: public MyOperand { return base->logicalPush(c); } + virtual Register asRegister(Context* c) { + return base->asRegister(c); + } + virtual void accept(Context* c, Operation operation, RegisterOperand* operand) { @@ -677,12 +684,9 @@ void RegisterOperand::apply(Context* c, Operation operation) { switch (operation) { - case push: - c->code.append(0x50 | value); - break; - - case pop: - c->code.append(0x58 | value); + case call: + c->code.append(0xff); + c->code.append(0xd0 | value); break; case jmp: @@ -690,9 +694,12 @@ RegisterOperand::apply(Context* c, Operation operation) c->code.append(0xe0 | value); break; - case call: - c->code.append(0xff); - c->code.append(0xd0 | value); + case pop: + c->code.append(0x58 | value); + break; + + case push: + c->code.append(0x50 | value); break; default: abort(c); @@ -704,6 +711,12 @@ RegisterOperand::accept(Context* c, Operation operation, RegisterOperand* operand) { switch (operation) { + case add: + rex(c); + c->code.append(0x01); + c->code.append(0xc0 | (operand->value << 3) | value); + break; + case mov: if (value != operand->value) { rex(c); @@ -712,12 +725,6 @@ RegisterOperand::accept(Context* c, Operation operation, } break; - case add: - rex(c); - c->code.append(0x01); - c->code.append(0xc0 | (operand->value << 3) | value); - break; - default: abort(c); } } @@ -727,6 +734,23 @@ RegisterOperand::accept(Context* c, Operation operation, ImmediateOperand* operand) { switch (operation) { + case and_: + if (operand->value) { + rex(c); + if (isInt8(operand->value)) { + c->code.append(0x83); + c->code.append(0xe0 | value); + c->code.append(operand->value); + } else { + assert(c, isInt32(operand->value)); + + c->code.append(0x81); + c->code.append(0xe0 | value); + c->code.append(operand->value); + } + } + break; + case mov: rex(c); c->code.append(0xb8 | value); @@ -811,7 +835,7 @@ class DirectCallTask: public IpTask { uint8_t* instruction = code + offset + (this->start - start); assert(c, *instruction == 0xe8); - intptr_t v = address - instruction; + intptr_t v = address - instruction - 5; assert(c, isInt32(v)); int32_t v32 = v; @@ -833,6 +857,13 @@ void ImmediateOperand::apply(Context* c, Operation operation) { switch (operation) { + case alignedCall: { + while ((c->code.length() + 1) % 4) { + c->code.append(0x90); + } + apply(c, call); + } break; + case call: { IpMapping* mapping = currentMapping(c); mapping->task = new (c->zone.allocate(sizeof(DirectCallTask))) @@ -842,13 +873,6 @@ ImmediateOperand::apply(Context* c, Operation operation) c->code.append(0xE8); c->code.append4(0); } break; - - case alignedCall: { - while ((c->code.length() + 1) % 4) { - c->code.append(0x90); - } - apply(c, call); - } break; default: abort(c); } @@ -884,6 +908,10 @@ void MemoryOperand::apply(Context* c, Operation operation) { switch (operation) { + case call: + encode(c, 0xff, 0x10, 0x50, 0x90, rax, base->asRegister(c), displacement); + break; + case pop: encode(c, 0x8f, 0, 0x40, 0x80, rax, base->asRegister(c), displacement); break; diff --git a/test/Misc.java b/test/Misc.java index 292b9c8b1a..ae2e84d5da 100644 --- a/test/Misc.java +++ b/test/Misc.java @@ -25,9 +25,9 @@ public class Misc { Misc m = new Misc(); String s = "hello"; -// m.foo(s); -// m.bar(s); -// baz(s); + m.foo(s); + m.bar(s); + baz(s); // int d = alpha; // beta = 42;