* src/vm/jit/x86_64/emit.c (emit_trap_compiler): Fixed comment.
[cacao.git] / src / vm / jit / x86_64 / emit.c
index 44f3742a704166127f9e5f0a97401c5cfbe85e59..d0f940a16124e8a2f4ba84ae2474f1ab1dd7e8ea 100644 (file)
@@ -48,6 +48,7 @@
 #include "vm/jit/codegen-common.h"
 #include "vm/jit/emit-common.h"
 #include "vm/jit/jit.h"
+#include "vm/jit/patcher-common.h"
 #include "vm/jit/replace.h"
 
 #include "vmcore/options.h"
@@ -359,6 +360,22 @@ void emit_arrayindexoutofbounds_check(codegendata *cd, instruction *iptr, s4 s1,
 }
 
 
+/* emit_arraystore_check *******************************************************
+
+   Emit an ArrayStoreException check.
+
+*******************************************************************************/
+
+void emit_arraystore_check(codegendata *cd, instruction *iptr)
+{
+       if (INSTRUCTION_MUST_CHECK(iptr)) {
+               M_TEST(REG_RESULT);
+               M_BNE(8);
+               M_ALD_MEM(REG_RESULT, EXCEPTION_HARDWARE_ARRAYSTORE);
+       }
+}
+
+
 /* emit_classcast_check ********************************************************
 
    Emit a ClassCastException check.
@@ -418,90 +435,15 @@ void emit_exception_check(codegendata *cd, instruction *iptr)
 }
 
 
-/* emit_patcher_stubs **********************************************************
+/* emit_trap_compiler **********************************************************
 
-   Generates the code for the patcher stubs.
+   Emit a trap instruction which calls the JIT compiler.
 
 *******************************************************************************/
 
-void emit_patcher_stubs(jitdata *jd)
+void emit_trap_compiler(codegendata *cd)
 {
-       codegendata *cd;
-       patchref    *pref;
-       u8           mcode;
-       u1          *savedmcodeptr;
-       u1          *tmpmcodeptr;
-       s4           targetdisp;
-       s4           disp;
-
-       /* get required compiler data */
-
-       cd = jd->cd;
-
-       /* generate code patching stub call code */
-
-       targetdisp = 0;
-
-       for (pref = cd->patchrefs; pref != NULL; pref = pref->next) {
-               /* check size of code segment */
-
-               MCODECHECK(512);
-
-               /* Get machine code which is patched back in later. A
-                  `call rel32' is 5 bytes long (but read 8 bytes). */
-
-               savedmcodeptr = cd->mcodebase + pref->branchpos;
-               mcode = *((u8 *) savedmcodeptr);
-
-               /* patch in `call rel32' to call the following code */
-
-               tmpmcodeptr  = cd->mcodeptr;    /* save current mcodeptr              */
-               cd->mcodeptr = savedmcodeptr;   /* set mcodeptr to patch position     */
-
-               M_CALL_IMM(tmpmcodeptr - (savedmcodeptr + PATCHER_CALL_SIZE));
-
-               cd->mcodeptr = tmpmcodeptr;     /* restore the current mcodeptr       */
-
-               /* move pointer to java_objectheader onto stack */
-
-#if defined(ENABLE_THREADS)
-               /* create a virtual java_objectheader */
-
-               (void) dseg_add_unique_address(cd, NULL);                  /* flcword */
-               (void) dseg_add_unique_address(cd, lock_get_initial_lock_word());
-               disp = dseg_add_unique_address(cd, NULL);                  /* vftbl   */
-
-               emit_lea_membase_reg(cd, RIP, -((cd->mcodeptr + 7) - cd->mcodebase) + disp, REG_ITMP3);
-               M_PUSH(REG_ITMP3);
-#else
-               M_PUSH_IMM(0);
-#endif
-
-               /* move machine code bytes and classinfo pointer into registers */
-
-               M_MOV_IMM(mcode, REG_ITMP3);
-               M_PUSH(REG_ITMP3);
-
-               M_MOV_IMM(pref->ref, REG_ITMP3);
-               M_PUSH(REG_ITMP3);
-
-               M_MOV_IMM(pref->disp, REG_ITMP3);
-               M_PUSH(REG_ITMP3);
-
-               M_MOV_IMM(pref->patcher, REG_ITMP3);
-               M_PUSH(REG_ITMP3);
-
-               if (targetdisp == 0) {
-                       targetdisp = cd->mcodeptr - cd->mcodebase;
-
-                       M_MOV_IMM(asm_patcher_wrapper, REG_ITMP3);
-                       M_JMP(REG_ITMP3);
-               }
-               else {
-                       M_JMP_IMM((cd->mcodebase + targetdisp) -
-                                         (cd->mcodeptr + PATCHER_CALL_SIZE));
-               }
-       }
+       M_ALD_MEM(REG_METHODPTR, EXCEPTION_HARDWARE_COMPILER);
 }
 
 
@@ -513,14 +455,17 @@ void emit_patcher_stubs(jitdata *jd)
 
 uint32_t emit_trap(codegendata *cd)
 {
-       uint32_t mcode;
+       uint16_t mcode;
 
-       /* Get machine code which is patched back in later. The
-          trap is 1 instruction word long. */
+       /* Get machine code which is patched back in later. The trap is 2
+          bytes long. */
 
-       mcode = *((uint32_t *) cd->mcodeptr);
+       mcode = *((uint16_t *) cd->mcodeptr);
 
-       M_NOP;
+       /* XXX This needs to be change to INT3 when the debugging problems
+          with gdb are resolved. */
+
+       M_UD2;
 
        return mcode;
 }
@@ -1612,12 +1557,6 @@ void emit_idivl_reg(codegendata *cd, s8 reg) {
 
 
 
-void emit_ret(codegendata *cd) {
-    *(cd->mcodeptr++) = 0xc3;
-}
-
-
-
 /*
  * shift ops
  */
@@ -1813,11 +1752,6 @@ void emit_xchg_reg_reg(codegendata *cd, s8 reg, s8 dreg) {
 }
 
 
-void emit_nop(codegendata *cd) {
-    *(cd->mcodeptr++) = 0x90;
-}
-
-
 
 /*
  * call instructions