* src/vm/jit/i386/arch.h (JIT_COMPILER_VIA_SIGNAL): Temporarily added.
authorChristian Thalinger <twisti@complang.tuwien.ac.at>
Mon, 1 Oct 2007 14:05:01 +0000 (16:05 +0200)
committerChristian Thalinger <twisti@complang.tuwien.ac.at>
Mon, 1 Oct 2007 14:05:01 +0000 (16:05 +0200)
* src/vm/jit/i386/asmpart.S (asm_call_jit_compiler): Removed.

* src/vm/jit/i386/codegen.c (codegen_emit_stub_compiler): Likewise.

* src/vm/jit/i386/codegen.h (COMPILERSTUB_CODESIZE): Adapted size.
(M_BYTE1, M_BYTE2): New macros.
(M_CLTD, M_RET, M_NOP): Use M_BYTE1.
(M_UD2): Use M_BYTE2.

* src/vm/jit/i386/emit.c (emit_trap_compiler): New function.
(emit_trap): Use macros.
(emit_cltd, emit_ret, emit_nop): Removed.
* src/vm/jit/i386/emit.h (emit_cltd, emit_ret, emit_nop): Likewise.

* src/vm/jit/i386/linux/md-os.c (md_signal_handler_sigsegv): Added JIT
compiler code.

src/vm/jit/i386/arch.h
src/vm/jit/i386/asmpart.S
src/vm/jit/i386/codegen.c
src/vm/jit/i386/codegen.h
src/vm/jit/i386/emit.c
src/vm/jit/i386/emit.h
src/vm/jit/i386/linux/md-os.c

index 9763bdedf071adb5395331f029fe20cadf2a79ff..9d68a824cb9dc77a6d3424bc04354d1ae37cc107 100644 (file)
@@ -28,6 +28,8 @@
 #ifndef _ARCH_H
 #define _ARCH_H
 
+#define JIT_COMPILER_VIA_SIGNAL
+
 #include "config.h"
 
 
index 18183537337280675e752a7764a40de40c1e1634..112c9592c711a3f3a0bc82ce2efea93672aed175 100644 (file)
@@ -51,7 +51,6 @@
        .globl asm_vm_call_method_exception_handler
        .globl asm_vm_call_method_end
 
-       .globl asm_call_jit_compiler
        .globl asm_handle_nat_exception
        .globl asm_handle_exception
 
@@ -193,61 +192,6 @@ asm_vm_call_method_end:
        jmp     L_asm_vm_call_method_return
 
 
-/* asm_call_jit_compiler *******************************************************
-
-   Invokes the compiler for untranslated JavaVM methods.
-
-   Register R0 contains a pointer to the method info structure (prepared
-   by createcompilerstub). Using the return address in R26 and the
-   offset in the LDA instruction or using the value in methodptr R28 the
-   patching address for storing the method address can be computed:
-
-   Method address was either loaded using
-
-   i386_mov_imm_reg(a, REG_ITMP2)                ; invokestatic/special
-   i386_call_reg(REG_ITMP2)
-
-   or
-
-   i386_mov_membase_reg(REG_SP, 0, REG_ITMP1)    ; invokevirtual/interface
-   i386_mov_membase_reg(REG_ITMP1, OFFSET(, vftbl), REG_ITMP2)
-   i386_mov_membase_reg(REG_ITMP2, OFFSET(vftbl, table[0]) + \
-       sizeof(methodptr) * m->vftblindex, REG_ITMP1)
-   i386_call_reg(REG_ITMP1)
-
-   In the static case the method pointer can be computed using the
-   return address and the lda function following the jmp instruction.
-
-*******************************************************************************/
-
-asm_call_jit_compiler:
-L_asm_call_jit_compiler:                /* required for PIC code              */
-       sub     $(4*4),sp                   /* keep stack 16-byte aligned         */
-
-       mov     itmp1,0*4(sp)               /* pass methodinfo pointer            */
-       mov     mptr,1*4(sp)                /* pass method pointer                */
-       mov     sp,itmp2                    /* pass java sp                       */
-       add     $((1+4)*4),itmp2
-       mov     itmp2,2*4(sp)
-       mov     4*4(sp),itmp3               /* pass java ra                       */
-       mov     itmp3,3*4(sp)
-       call    jit_asm_compile
-
-       add     $(4*4),sp                   /* remove stack frame                 */
-
-       test    v0,v0                       /* check for exception                */
-       je      L_asm_call_jit_compiler_exception
-
-       jmp             *v0                         /* ...and now call the new method     */
-
-L_asm_call_jit_compiler_exception:
-       call    exceptions_get_and_clear_exception
-                                           /* v0 == xptr                         */
-       pop     xpc                         /* get return address                 */
-       sub     $2,xpc                      /* faulting address is ra - 2         */
-       jmp     L_asm_handle_exception
-
-
 /* asm_handle_exception ********************************************************
 *                                                                              *
 *   This function handles an exception. It does not use the usual calling      *
index d90b981ae2040d57f3bf05e6fc5812826663262e..b8701b93552b88f420dd5b6a95f882af67579a9e 100644 (file)
@@ -2814,7 +2814,7 @@ nowperformreturn:
                        if (cd->stackframesize)
                                M_AADD_IMM(cd->stackframesize * 8, REG_SP);
 
-                       emit_ret(cd);
+                       M_RET;
                        }
                        break;
 
@@ -3476,30 +3476,6 @@ gen_method:
 }
 
 
-/* codegen_emit_stub_compiler **************************************************
-
-   Emit a stub routine which calls the compiler.
-       
-*******************************************************************************/
-
-void codegen_emit_stub_compiler(jitdata *jd)
-{
-       methodinfo  *m;
-       codegendata *cd;
-
-       /* get required compiler data */
-
-       m  = jd->m;
-       cd = jd->cd;
-
-       /* code for the stub */
-
-       M_MOV_IMM(m, REG_ITMP1);
-       M_MOV_IMM(asm_call_jit_compiler, REG_ITMP3);
-       M_JMP(REG_ITMP3);
-}
-
-
 /* codegen_emit_stub_native ****************************************************
 
    Emits a stub routine which calls a native method.
index 506afc59629bd324fa5546c3bec1039bfbdbc382..9d3b3051797189d5559538f323f381455f33da3c 100644 (file)
 
 /* stub defines ***************************************************************/
 
-#define COMPILERSTUB_CODESIZE    12
+#define COMPILERSTUB_CODESIZE    6
 
 
 /* macros to create code ******************************************************/
 
+#define M_BYTE1(a) \
+    do { \
+        *(cd->mcodeptr) = (a); \
+        cd->mcodeptr++; \
+    } while (0)
+
+
+#define M_BYTE2(a, b) \
+    do { \
+        M_BYTE1(a); \
+        M_BYTE1(b); \
+    } while (0)
+
+
 #define M_ILD(a,b,disp)         emit_mov_membase_reg(cd, (b), (disp), (a))
 #define M_ILD32(a,b,disp)       emit_mov_membase32_reg(cd, (b), (disp), (a))
 
 
 #define M_CZEXT(a,b)            emit_movzwl_reg_reg(cd, (a), (b))
 
-#define M_CLTD                  emit_cltd(cd)
+#define M_CLTD                  M_BYTE1(0x99)
 
 #define M_SLL(a)                emit_shift_reg(cd, SHIFT_SHL, (a))
 #define M_SRA(a)                emit_shift_reg(cd, SHIFT_SAR, (a))
 
 #define M_CALL(a)               emit_call_reg(cd, (a))
 #define M_CALL_IMM(a)           emit_call_imm(cd, (a))
-#define M_RET                   emit_ret(cd)
+#define M_RET                   M_BYTE1(0xc3)
 
 #define M_BEQ(a)                emit_jcc(cd, CC_E, (a))
 #define M_BNE(a)                emit_jcc(cd, CC_NE, (a))
 #define M_JMP(a)                emit_jmp_reg(cd, (a))
 #define M_JMP_IMM(a)            emit_jmp_imm(cd, (a))
 
-#define M_NOP                   emit_nop(cd)
+#define M_NOP                   M_BYTE1(0x90)
+#define M_UD2                   M_BYTE2(0x0f, 0x0b)
 
 
 #define M_FLD(a,b,disp)         emit_flds_membase(cd, (b), (disp))
index 7836b193c8681078683c8be645178620a21e5f9e..6f46ebcc236ab1dcc36a4ec4159e3deceed2a4fd 100644 (file)
@@ -507,6 +507,18 @@ void emit_exception_check(codegendata *cd, instruction *iptr)
 }
 
 
+/* emit_trap_compiler **********************************************************
+
+   Emit a trap instruction which calls the JIT compiler.
+
+*******************************************************************************/
+
+void emit_trap_compiler(codegendata *cd)
+{
+       M_ALD_MEM(REG_METHODPTR, EXCEPTION_HARDWARE_COMPILER);
+}
+
+
 /* emit_trap *******************************************************************
 
    Emit a trap instruction and return the original machine code.
@@ -525,9 +537,9 @@ uint32_t emit_trap(codegendata *cd)
 #if 0
        /* XXX this breaks GDB, so we disable it for now */
        *(cd->mcodeptr++) = 0xcc;
+       M_INT3;
 #else
-       *(cd->mcodeptr++) = 0x0f;
-       *(cd->mcodeptr++) = 0x0b;
+       M_UD2;
 #endif
 
        return (uint32_t) mcode;
@@ -1063,12 +1075,6 @@ void emit_dec_mem(codegendata *cd, s4 mem)
 }
 
 
-void emit_cltd(codegendata *cd)
-{
-       *(cd->mcodeptr++) = 0x99;
-}
-
-
 void emit_imul_reg_reg(codegendata *cd, s4 reg, s4 dreg)
 {
        *(cd->mcodeptr++) = 0x0f;
@@ -1148,12 +1154,6 @@ void emit_idiv_reg(codegendata *cd, s4 reg)
 }
 
 
-void emit_ret(codegendata *cd)
-{
-       *(cd->mcodeptr++) = 0xc3;
-}
-
-
 
 /*
  * shift ops
@@ -1309,12 +1309,6 @@ void emit_push_reg(codegendata *cd, s4 reg)
 }
 
 
-void emit_nop(codegendata *cd)
-{
-       *(cd->mcodeptr++) = 0x90;
-}
-
-
 void emit_lock(codegendata *cd)
 {
        *(cd->mcodeptr++) = 0xf0;
index 4e333cd2075e5941bad50d982da19106a2265982..22b116ff567a890bafda6e719248b76684de167c 100644 (file)
@@ -188,7 +188,6 @@ void emit_alu_imm_memabs(codegendata *cd, s4 opc, s4 imm, s4 disp);
 void emit_test_reg_reg(codegendata *cd, s4 reg, s4 dreg);
 void emit_test_imm_reg(codegendata *cd, s4 imm, s4 dreg);
 void emit_dec_mem(codegendata *cd, s4 mem);
-void emit_cltd(codegendata *cd);
 void emit_imul_reg_reg(codegendata *cd, s4 reg, s4 dreg);
 void emit_imul_membase_reg(codegendata *cd, s4 basereg, s4 disp, s4 dreg);
 void emit_imul_imm_reg(codegendata *cd, s4 imm, s4 reg);
@@ -196,7 +195,6 @@ void emit_imul_imm_reg_reg(codegendata *cd, s4 imm, s4 reg, s4 dreg);
 void emit_imul_imm_membase_reg(codegendata *cd, s4 imm, s4 basereg, s4 disp, s4 dreg);
 void emit_mul_reg(codegendata *cd, s4 reg);
 void emit_idiv_reg(codegendata *cd, s4 reg);
-void emit_ret(codegendata *cd);
 void emit_shift_reg(codegendata *cd, s4 opc, s4 reg);
 void emit_shift_imm_reg(codegendata *cd, s4 opc, s4 imm, s4 reg);
 void emit_shld_reg_reg(codegendata *cd, s4 reg, s4 dreg);
@@ -215,7 +213,6 @@ void emit_neg_reg(codegendata *cd, s4 reg);
 void emit_push_imm(codegendata *cd, s4 imm);
 void emit_pop_reg(codegendata *cd, s4 reg);
 void emit_push_reg(codegendata *cd, s4 reg);
-void emit_nop(codegendata *cd);
 void emit_lock(codegendata *cd);
 void emit_call_reg(codegendata *cd, s4 reg);
 void emit_call_imm(codegendata *cd, s4 imm);
index 49d215e3cf272031f954bcd179935bd1937cf129..731fad10e47c5207fc25ce1300e13937012644ef 100644 (file)
@@ -68,6 +68,7 @@ void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
        ptrint          val;
        s4              type;
        void           *p;
+       java_object_t  *o;
 
        _uc = (ucontext_t *) _p;
        _mc = &_uc->uc_mcontext;
@@ -101,6 +102,17 @@ void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
                   here. */
 
                val = _mc->gregs[REG_EAX - d];
+
+               if (type == EXCEPTION_HARDWARE_COMPILER) {
+                       /* We use a framesize of zero here because the call pushed
+                          the return addres onto the stack. */
+
+                       ra = md_stacktrace_get_returnaddress(sp, 0);
+
+                       /* And remove the RA from the stack. */
+
+                       sp = sp + 1 * SIZEOF_VOID_P;
+               }
        }
        else {
                /* this was a normal NPE */
@@ -113,11 +125,29 @@ void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
 
        p = signal_handle(type, val, pv, sp, ra, xpc, _p);
 
-       /* set registers */
+       /* Set registers. */
 
-       _mc->gregs[REG_EAX] = (intptr_t) p;
-       _mc->gregs[REG_ECX] = (intptr_t) xpc;                    /* REG_ITMP2_XPC */
-       _mc->gregs[REG_EIP] = (intptr_t) asm_handle_exception;
+       if (type == EXCEPTION_HARDWARE_COMPILER) {
+               if (p == NULL) {
+                       o = exceptions_get_and_clear_exception();
+
+                       ra = ra - 2;                     /* XPC is before the actual call */
+
+                       _mc->gregs[REG_ESP] = (uintptr_t) sp;    /* Remove RA from stack. */
+
+                       _mc->gregs[REG_EAX] = (uintptr_t) o;
+                       _mc->gregs[REG_ECX] = (uintptr_t) ra;            /* REG_ITMP2_XPC */
+                       _mc->gregs[REG_EIP] = (uintptr_t) asm_handle_exception;
+               }
+               else {
+                       _mc->gregs[REG_EIP] = (uintptr_t) p;
+               }
+       }
+       else {
+               _mc->gregs[REG_EAX] = (intptr_t) p;
+               _mc->gregs[REG_ECX] = (intptr_t) xpc;                /* REG_ITMP2_XPC */
+               _mc->gregs[REG_EIP] = (intptr_t) asm_handle_exception;
+       }
 }