From ba03aa88df8e7cfc62cbea5a45503d20d8ed837c Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 2 Oct 2007 19:54:21 -0600 Subject: [PATCH] snapshot --- src/compile.cpp | 122 +++++++++++++++++++++++++++--------------------- src/types.def | 10 ++++ 2 files changed, 78 insertions(+), 54 deletions(-) diff --git a/src/compile.cpp b/src/compile.cpp index 5b7a32cd60..21594f3fd6 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -124,27 +124,44 @@ class Buffer { class Code { public: Code(Buffer* code, Buffer* lineNumbers, Buffer* exceptionHandlers): - codeLength(code->length()), - lineNumberTableLength(lineNumbers->length()), - exceptionHandlerTableLength(exceptionHandlers->length()) + codeLength_(code->length()), + lineNumberTableLength_(lineNumbers->length()), + exceptionHandlerTableLength_(exceptionHandlers->length()) { code->copyTo(body); - lineNumbers->copyTo(lineNumberTable()); - exceptionHandlers->copyTo(exceptionHandlerTable()); + lineNumbers->copyTo(lineNumber(0)); + exceptionHandlers->copyTo(exceptionHandler(0)); + } + + uint8_t* code() { + return body; + } + + unsigned codeLength() { + return codeLength_; } - uint32_t* lineNumberTable() { - return reinterpret_cast(body + pad(codeLength)); + NativeLineNumber* lineNumber(unsigned index) { + return reinterpret_cast + (body + pad(codeLength_)) + index; } - uint32_t* exceptionHandlerTable() { - return reinterpret_cast - (body + pad(codeLength) + pad(lineNumberTableLength)); + unsigned lineNumberTableLength() { + return lineNumberTableLength_ / sizeof(NativeLineNumber); } - uint32_t codeLength; - uint32_t lineNumberTableLength; - uint32_t exceptionHandlerTableLength; + NativeExceptionHandler* exceptionHandler(unsigned index) { + return reinterpret_cast + (body + pad(codeLength_) + pad(lineNumberTableLength_)) + index; + } + + unsigned exceptionHandlerTableLength() { + return exceptionHandlerTableLength_ / sizeof(NativeExceptionHandler); + } + + uint32_t codeLength_; + uint32_t lineNumberTableLength_; + uint32_t exceptionHandlerTableLength_; uint8_t body[0]; }; @@ -202,33 +219,27 @@ inline unsigned addressOffset(Thread* t, object method, void* address) { Code* code = static_cast(methodCompiled(t, method)); - return static_cast(address) - code->body; + return static_cast(address) - code->code(); } -const unsigned EHStart = 0; -const unsigned EHEnd = 1; -const unsigned EHIp = 2; -const unsigned EHCatchType = 3; -const unsigned EHFootprint = 4; - -uint32_t* +NativeExceptionHandler* findExceptionHandler(Thread* t, void* frame) { object method = frameMethod(frame); Code* code = static_cast(methodCompiled(t, method)); - uint32_t* table = code->exceptionHandlerTable(); - for (unsigned i = 0; i < code->exceptionHandlerTableLength / 4; ++i) { - uint32_t* handler = table + (i * EHFootprint); + for (unsigned i = 0; i < code->exceptionHandlerTableLength(); ++i) { + NativeExceptionHandler* handler = code->exceptionHandler(i); unsigned offset = addressOffset(t, method, frameAddress(frame)); - if (offset - 1 >= handler[EHStart] - and offset - 1 < handler[EHEnd]) + if (offset - 1 >= nativeExceptionHandlerStart(handler) + and offset - 1 < nativeExceptionHandlerEnd(handler)) { object catchType; - if (handler[EHCatchType]) { + if (nativeExceptionHandlerCatchType(handler)) { catchType = arrayBody - (t, methodCode(t, method), handler[EHCatchType] - 1); + (t, methodCode(t, method), + nativeExceptionHandlerCatchType(handler) - 1); } else { catchType = 0; } @@ -253,11 +264,11 @@ unwind(MyThread* t) t->frame = next; vmJump(frameReturnAddress(frame)); } else if ((methodFlags(t, frameMethod(frame)) & ACC_NATIVE) == 0) { - uint32_t* eh = findExceptionHandler(t, frame); + NativeExceptionHandler* eh = findExceptionHandler(t, frame); if (eh) { Code* code = static_cast(methodCompiled(t, frameMethod(frame))); t->frame = frame; - vmJump(code->body + eh[EHIp]); + vmJump(code->code() + nativeExceptionHandlerIp(eh)); } } } @@ -938,8 +949,12 @@ parameterOffset(unsigned index) class Compiler: public Assembler { public: - Compiler(System* s): + Compiler(Thread* t): Assembler(s), + t(t), + threadFrameOffset(reinterpret_cast(&(t->frame)) + - reinterpret_cast(t)) + poolRegisterClobbered(true), javaIPs(s, 1024), machineIPs(s, 1024), lineNumbers(s, 256), @@ -983,7 +998,7 @@ class Compiler: public Assembler { push(poolRegister(), poolReference(target)); push(rbp, FrameThread); - callAlignedAddress(code->body); + callAlignedAddress(code->code()); add(footprint, rsp); // pop arguments @@ -991,9 +1006,6 @@ class Compiler: public Assembler { } void compileCall(void* function, object arg1) { - mov(rbp, FrameThread, rax); - mov(rbp, rax, frameOffset); // set thread frame to current - if (BytesPerWord == 4) { push(poolRegister(), poolReference(arg1)); push(rbp, FrameThread); @@ -1002,6 +1014,9 @@ class Compiler: public Assembler { mov(rbp, FrameThread, rdi); } + mov(rbp, FrameThread, rax); + mov(rbp, rax, threadFrameOffset); // set thread frame to current + callAddress(function); if (BytesPerWord == 4) { @@ -1010,9 +1025,6 @@ class Compiler: public Assembler { } void compileCall(void* function, Register arg1) { - mov(rbp, FrameThread, rax); - mov(rbp, rax, frameOffset); // set thread frame to current - if (BytesPerWord == 4) { push(arg1); push(rbp, FrameThread); @@ -1021,6 +1033,9 @@ class Compiler: public Assembler { mov(rbp, FrameThread, rdi); } + mov(rbp, FrameThread, rax); + mov(rbp, rax, threadFrameOffset); // set thread frame to current + callAddress(function); if (BytesPerWord == 4) { @@ -1029,9 +1044,6 @@ class Compiler: public Assembler { } void compileCall(void* function, object arg1, Register arg2) { - mov(rbp, FrameThread, rax); - mov(rbp, rax, frameOffset); // set thread frame to current - if (BytesPerWord == 4) { push(arg2); push(poolRegister(), poolReference(arg1)); @@ -1042,6 +1054,9 @@ class Compiler: public Assembler { mov(rbp, FrameThread, rdi); } + mov(rbp, FrameThread, rax); + mov(rbp, rax, threadFrameOffset); // set thread frame to current + callAddress(function); if (BytesPerWord == 4) { @@ -1063,6 +1078,9 @@ class Compiler: public Assembler { mov(rbp, FrameThread, rdi); } + mov(rbp, FrameThread, rax); + mov(rbp, rax, threadFrameOffset); // set thread frame to current + callAddress(function); if (BytesPerWord == 4) { @@ -1071,9 +1089,6 @@ class Compiler: public Assembler { } void compileCall(void* function, Register arg1, Register arg2) { - mov(rbp, FrameThread, rax); - mov(rbp, rax, frameOffset); // set thread frame to current - if (BytesPerWord == 4) { push(arg2); push(arg1); @@ -1084,6 +1099,9 @@ class Compiler: public Assembler { mov(rbp, FrameThread, rdi); } + mov(rbp, FrameThread, rax); + mov(rbp, rax, threadFrameOffset); // set thread frame to current + callAddress(function); if (BytesPerWord == 4) { @@ -2086,14 +2104,11 @@ class Compiler: public Assembler { } Code* compileNativeInvoker() { - unsigned frameOffset = reinterpret_cast(&(t->frame)) - - reinterpret_cast(t); - push(rbp); mov(rsp, rbp); mov(rbp, FrameThread, rax); - mov(rbp, rax, frameOffset); // set thread frame to current + mov(rbp, rax, threadFrameOffset); // set thread frame to current if (BytesPerWord == 4) { push(rbp, FrameMethod); @@ -2118,14 +2133,11 @@ class Compiler: public Assembler { } Code* compileStub() { - unsigned frameOffset = reinterpret_cast(&(t->frame)) - - reinterpret_cast(t); - push(rbp); mov(rsp, rbp); mov(rbp, FrameThread, rax); - mov(rbp, rax, frameOffset); // set thread frame to current + mov(rbp, rax, threadFrameOffset); // set thread frame to current if (BytesPerWord == 4) { push(rbp, FrameMethod); @@ -2181,6 +2193,7 @@ class Compiler: public Assembler { if (poolRegisterClobbered) { mov(rbp, FrameMethod, rdi); mov(rdi, MethodCode, rdi); + poolRegisterClobbered = false; } pool.appendAddress(o); return pool.length() + BytesPerWord; @@ -2199,6 +2212,7 @@ class Compiler: public Assembler { } MyThread* t; + unsigned threadFrameOffset; bool poolRegisterClobbered; Buffer javaIPs; Buffer machineIPs; @@ -2229,8 +2243,8 @@ compileMethod2(MyThread* t, object method) fprintf(stderr, "compiled %s.%s from %p to %p\n", &byteArrayBody(t, className(t, methodClass(t, method)), 0), &byteArrayBody(t, methodName(t, method), 0), - code->body, - code->body + code->codeLength); + code->code(), + code->code() + code->codeLength()); } set(t, methodCompiled(t, method), compiled); diff --git a/src/types.def b/src/types.def index 0b700c8fc5..2bd951b764 100644 --- a/src/types.def +++ b/src/types.def @@ -90,6 +90,16 @@ (uint16_t maxLocals) (array uint8_t body)) +(pod nativeExceptionHandler + (uint32_t start) + (uint32_t end) + (uint32_t ip) + (uint32_t catchType)) + +(pod nativeLineNumber + (uint32_t ip) + (uint32_t line)) + (type reference (object class) (object name)