* src/vm/jit/codegen-common.h (branchref): Removed.
authortwisti <none@none>
Wed, 15 Mar 2006 16:36:43 +0000 (16:36 +0000)
committertwisti <none@none>
Wed, 15 Mar 2006 16:36:43 +0000 (16:36 +0000)
(codegendata): Removed xboundrefs, xnullrefs, xcastrefs, xstorerefs,
xdivrefs and xexceptionrefs. Added exceptionrefs.
(codegen_addxboundrefs, codegen_addxcastrefs, codegen_addxdivrefs)
(codegen_addxstorerefs, codegen_addxnullrefs)
(codegen_addxexceptionrefs): Removed.
(codegen_add_arithmeticexception_ref)
(codegen_add_arrayindexoutofboundsexception_ref)
(codegen_add_arraystoreexception_ref)
(codegen_add_classcastexception_ref)
(codegen_add_nullpointerexception_ref)
(codegen_add_fillinstacktrace_ref): New function.
* src/vm/jit/codegen-common.c: Likewise.

* src/vm/jit/dseg.h (exceptionref): New structure.

* src/vm/jit/x86_64/codegen.c: Use new exception stubs. Don't cast
with M_MOV_IMM.
* src/vm/jit/x86_64/codegen.h (M_MOV_IMM, M_IMOV_IMM): Added cast.

* src/vm/jit/stacktrace.c (stacktrace_inline_fillInStackTrace): Moved.
* src/vm/jit/stacktrace.h (STACKTRACE_inline_arithmeticexception)
(STACKTRACE_inline_arrayindexoutofboundsexception)
(STACKTRACE_inline_arraystoreexception)
(STACKTRACE_inline_classcastexception)
(STACKTRACE_inline_nullpointerexception)
(STACKTRACE_inline_fillInStackTrace): Added functionptr defines.

* src/vm/jit/jit.h (branchref): Added.

src/vm/jit/codegen-common.c
src/vm/jit/codegen-common.h
src/vm/jit/dseg.h
src/vm/jit/jit.h
src/vm/jit/stacktrace.c
src/vm/jit/stacktrace.h
src/vm/jit/x86_64/codegen.c
src/vm/jit/x86_64/codegen.h

index 455ba82097715aeab53a68d21d3c1323e3da4bbc..63a9c8e5d69632ca4316f3d0abc9a96142baa654 100644 (file)
@@ -48,7 +48,7 @@
    memory. All functions writing values into the data area return the offset
    relative the begin of the code area (start of procedure).   
 
-   $Id: codegen-common.c 4609 2006-03-15 05:13:21Z edwin $
+   $Id: codegen-common.c 4615 2006-03-15 16:36:43Z twisti $
 
 */
 
@@ -182,13 +182,8 @@ void codegen_setup(methodinfo *m, codegendata *cd)
        cd->datareferences = NULL;
 #endif
 
-       cd->xboundrefs = NULL;
-       cd->xnullrefs = NULL;
-       cd->xcastrefs = NULL;
-       cd->xstorerefs = NULL;
-       cd->xdivrefs = NULL;
-       cd->xexceptionrefs = NULL;
-       cd->patchrefs = NULL;
+       cd->exceptionrefs  = NULL;
+       cd->patchrefs      = NULL;
 
        cd->linenumberreferences = NULL;
        cd->linenumbertablesizepos = 0;
@@ -353,136 +348,107 @@ void codegen_addreference(codegendata *cd, basicblock *target, void *branchptr)
 }
 
 
-/* codegen_addxboundrefs *******************************************************
+/* codegen_add_exception_ref ***************************************************
 
-   Adds an ArrayIndexOutOfBoundsException branch to the list.
+   Adds an exception branch to the list.
 
 *******************************************************************************/
 
-void codegen_addxboundrefs(codegendata *cd, void *branchptr, s4 reg)
+static void codegen_add_exception_ref(codegendata *cd, void *branchptr, s4 reg,
+                                                                         functionptr function)
 {
-       s4 branchpos;
-       branchref *br;
+       s4            branchpos;
+       exceptionref *eref;
 
        branchpos = (u1 *) branchptr - cd->mcodebase;
 
-       br = DNEW(branchref);
+       eref = DNEW(exceptionref);
 
-       br->branchpos = branchpos;
-       br->reg       = reg;
-       br->next      = cd->xboundrefs;
+       eref->branchpos = branchpos;
+       eref->reg       = reg;
+       eref->function  = function;
+       eref->next      = cd->exceptionrefs;
 
-       cd->xboundrefs = br;
+       cd->exceptionrefs = eref;
 }
 
 
-/* codegen_addxcastrefs ********************************************************
+/* codegen_add_arithmeticexception_ref *****************************************
 
-   Adds an ClassCastException branch to the list.
+   Adds an ArithmeticException branch to the list.
 
 *******************************************************************************/
 
-void codegen_addxcastrefs(codegendata *cd, void *branchptr)
+void codegen_add_arithmeticexception_ref(codegendata *cd, void *branchptr)
 {
-       s4         branchpos;
-       branchref *br;
-
-       branchpos = (u1 *) branchptr - cd->mcodebase;
-
-       br = DNEW(branchref);
-
-       br->branchpos = branchpos;
-       br->next      = cd->xcastrefs;
-
-       cd->xcastrefs = br;
+       codegen_add_exception_ref(cd, branchptr, -1,
+                                                         STACKTRACE_inline_arithmeticexception);
 }
 
 
-/* codegen_addxdivrefs *********************************************************
+/* codegen_add_arrayindexoutofboundsexception_ref ******************************
 
-   Adds an ArithmeticException branch to the list.
+   Adds an ArrayIndexOutOfBoundsException branch to the list.
 
 *******************************************************************************/
 
-void codegen_addxdivrefs(codegendata *cd, void *branchptr)
+void codegen_add_arrayindexoutofboundsexception_ref(codegendata *cd,
+                                                                                                       void *branchptr, s4 reg)
 {
-       s4         branchpos;
-       branchref *br;
-
-       branchpos = (u1 *) branchptr - cd->mcodebase;
-
-       br = DNEW(branchref);
-
-       br->branchpos = branchpos;
-       br->next      = cd->xdivrefs;
-
-       cd->xdivrefs = br;
+       codegen_add_exception_ref(cd, branchptr, reg,
+                                                         STACKTRACE_inline_arrayindexoutofboundsexception);
 }
 
 
-/* codegen_addxstorerefs *******************************************************
+/* codegen_add_arraystoreexception_ref *****************************************
 
    Adds an ArrayStoreException branch to the list.
 
 *******************************************************************************/
 
-void codegen_addxstorerefs(codegendata *cd, void *branchptr)
+void codegen_add_arraystoreexception_ref(codegendata *cd, void *branchptr)
 {
-       s4         branchpos;
-       branchref *br;
+       codegen_add_exception_ref(cd, branchptr, -1,
+                                                         STACKTRACE_inline_arraystoreexception);
+}
 
-       branchpos = (u1 *) branchptr - cd->mcodebase;
 
-       br = DNEW(branchref);
+/* codegen_add_classcastexception_ref ******************************************
+
+   Adds an ClassCastException branch to the list.
 
-       br->branchpos = branchpos;
-       br->next      = cd->xstorerefs;
+*******************************************************************************/
 
-       cd->xstorerefs = br;
+void codegen_add_classcastexception_ref(codegendata *cd, void *branchptr)
+{
+       codegen_add_exception_ref(cd, branchptr, -1,
+                                                         STACKTRACE_inline_classcastexception);
 }
 
 
-/* codegen_addxnullrefs ********************************************************
+/* codegen_add_nullpointerexception_ref ****************************************
 
    Adds an NullPointerException branch to the list.
 
 *******************************************************************************/
 
-void codegen_addxnullrefs(codegendata *cd, void *branchptr)
+void codegen_add_nullpointerexception_ref(codegendata *cd, void *branchptr)
 {
-       s4         branchpos;
-       branchref *br;
-
-       branchpos = (u1 *) branchptr - cd->mcodebase;
-
-       br = DNEW(branchref);
-
-       br->branchpos = branchpos;
-       br->next      = cd->xnullrefs;
-
-       cd->xnullrefs = br;
+       codegen_add_exception_ref(cd, branchptr, -1,
+                                                         STACKTRACE_inline_nullpointerexception);
 }
 
 
-/* codegen_addxexceptionsrefs **************************************************
+/* codegen_add_fillinstacktrace_ref ********************************************
 
-   Adds an common exception branch to the list.
+   Adds a fillInStackTrace branch to the list.
 
 *******************************************************************************/
 
-void codegen_addxexceptionrefs(codegendata *cd, void *branchptr)
+void codegen_add_fillinstacktrace_ref(codegendata *cd, void *branchptr)
 {
-       s4 branchpos;
-       branchref *br;
-
-       branchpos = (u1 *) branchptr - cd->mcodebase;
-
-       br = DNEW(branchref);
-
-       br->branchpos = branchpos;
-       br->next      = cd->xexceptionrefs;
-
-       cd->xexceptionrefs = br;
+       codegen_add_exception_ref(cd, branchptr, -1,
+                                                         STACKTRACE_inline_fillInStackTrace);
 }
 
 
index dd24000c9e6dbcb19ec0f17eafdf84a7af551540..1ed7700d4e4e1afa86da9a6e92d332b07405f0f5 100644 (file)
@@ -29,7 +29,7 @@
    Changes: Christian Ullrich
                        Edwin Steiner
 
-   $Id: codegen-common.h 4598 2006-03-14 22:16:47Z edwin $
+   $Id: codegen-common.h 4615 2006-03-15 16:36:43Z twisti $
 
 */
 
@@ -40,7 +40,6 @@
 /* forward typedefs ***********************************************************/
 
 typedef struct codegendata codegendata;
-typedef struct branchref branchref;
 typedef struct threadcritnodetemp threadcritnodetemp;
 
 
@@ -118,12 +117,7 @@ struct codegendata {
        dataref        *datareferences; /* list of data segment references        */
 #endif
 
-       branchref      *xboundrefs;     /* list of bound check branches           */
-       branchref      *xnullrefs;      /* list of null check branches            */
-       branchref      *xcastrefs;      /* list of cast check branches            */
-       branchref      *xstorerefs;     /* list of array store check branches     */
-       branchref      *xdivrefs;       /* list of divide by zero branches        */
-       branchref      *xexceptionrefs; /* list of exception branches             */
+       exceptionref   *exceptionrefs;  /* list of exception branches             */
        patchref       *patchrefs;
 
        linenumberref  *linenumberreferences; /* list of line numbers and the     */
@@ -147,15 +141,6 @@ struct codegendata {
 };
 
 
-/***************** forward references in branch instructions ******************/
-
-struct branchref {
-       s4         branchpos;       /* patching position in code segment          */
-       s4         reg;             /* used for ArrayIndexOutOfBounds index reg   */
-       branchref *next;            /* next element in branchref list             */
-};
-
-
 #if defined(__I386__) || defined(__X86_64__) || defined(ENABLE_INTRP) || defined(DISABLE_GC)
 typedef struct _methodtree_element methodtree_element;
 
@@ -182,12 +167,14 @@ u1 *codegen_ncode_increase(codegendata *cd, u1 *ncodeptr);
 
 void codegen_addreference(codegendata *cd, basicblock *target, void *branchptr);
 
-void codegen_addxboundrefs(codegendata *cd, void *branchptr, s4 reg);
-void codegen_addxcastrefs(codegendata *cd, void *branchptr);
-void codegen_addxdivrefs(codegendata *cd, void *branchptr);
-void codegen_addxstorerefs(codegendata *cd, void *branchptr);
-void codegen_addxnullrefs(codegendata *cd, void *branchptr);
-void codegen_addxexceptionrefs(codegendata *cd, void *branchptr);
+void codegen_add_arithmeticexception_ref(codegendata *cd, void *branchptr);
+void codegen_add_arrayindexoutofboundsexception_ref(codegendata *cd,
+                                                                                                       void *branchptr, s4 reg);
+void codegen_add_arraystoreexception_ref(codegendata *cd, void *branchptr);
+void codegen_add_classcastexception_ref(codegendata *cd, void *branchptr);
+void codegen_add_nullpointerexception_ref(codegendata *cd, void *branchptr);
+void codegen_add_fillinstacktrace_ref(codegendata *cd, void *branchptr);
+
 
 void codegen_addpatchref(codegendata *cd, voidptr branchptr,
                                                 functionptr patcher, voidptr ref, s4 disp);
index 0b567704118b3ae9b9ace1911ea6e8a8186fb447..f9994721f48b62e0a40291f77d84a3d0a0089685 100644 (file)
@@ -30,7 +30,7 @@
    Changes: Christian Thalinger
             Joseph Wenninger
 
-   $Id: dseg.h 4445 2006-02-05 15:26:34Z edwin $
+   $Id: dseg.h 4615 2006-03-15 16:36:43Z twisti $
 
 */
 
@@ -42,6 +42,7 @@
 
 typedef struct jumpref jumpref;
 typedef struct dataref dataref;
+typedef struct exceptionref exceptionref;
 typedef struct patchref patchref;
 typedef struct linenumberref linenumberref;
 
@@ -80,6 +81,16 @@ struct dataref {
 };
 
 
+/* exceptionref ***************************************************************/
+
+struct exceptionref {
+       s4            branchpos;    /* patching position in code segment          */
+       s4            reg;          /* used for ArrayIndexOutOfBounds index reg   */
+       functionptr   function;     /* function pointer to generate exception     */
+       exceptionref *next;         /* next element in exceptionref list          */
+};
+
+
 /* patchref *******************************************************************/
 
 struct patchref {
index 92cae1f5c31051171aab9943b201e5ea9e0b89ee..06bea1c25990ff962663bbb8b03f4ca69caeaf68 100644 (file)
@@ -30,7 +30,7 @@
    Changes: Christian Thalinger
                        Edwin Steiner
 
-   $Id: jit.h 4602 2006-03-14 23:49:34Z edwin $
+   $Id: jit.h 4615 2006-03-15 16:36:43Z twisti $
 
 */
 
@@ -43,6 +43,7 @@
 typedef struct stackelement stackelement;
 typedef stackelement *stackptr;
 typedef struct basicblock basicblock;
+typedef struct branchref branchref;
 typedef struct instruction instruction;
 typedef struct subroutineinfo subroutineinfo;
 
@@ -215,6 +216,15 @@ struct basicblock {
                        bptr->debug_nr = m->c_debug_nr++;              \
                } while (0)
                        
+
+/* branchref *****************************************************************/
+
+struct branchref {
+       s4         branchpos;       /* patching position in code segment          */
+       branchref *next;            /* next element in branchref list             */
+};
+
+
 /********** op1 values for ACONST instructions ********************************/
 
 #define ACONST_LOAD     0  /* ACONST_NULL or LDC instruction                  */
index 2132e571b682318dd3b93459ab313d73d83ce089..c7be309d4ddff2ad6d9f7b473e7fecf47e13d288 100644 (file)
@@ -29,7 +29,7 @@
    Changes: Christian Thalinger
             Edwin Steiner
 
-   $Id: stacktrace.c 4598 2006-03-14 22:16:47Z edwin $
+   $Id: stacktrace.c 4615 2006-03-15 16:36:43Z twisti $
 
 */
 
@@ -472,25 +472,41 @@ java_objectheader *stacktrace_inline_nullpointerexception(u1 *pv, u1 *sp,
 }
 
 
-/* stacktrace_hardware_arithmeticexception *************************************
+/* stacktrace_inline_fillInStackTrace ******************************************
 
-   Creates an ArithemticException for inline stub.
+   Fills in the correct stacktrace into an existing exception object
+   (this one is for inline exception stubs).
 
 *******************************************************************************/
 
-java_objectheader *stacktrace_hardware_arithmeticexception(u1 *pv, u1 *sp,
-                                                                                                                  u1 *ra, u1 *xpc)
+java_objectheader *stacktrace_inline_fillInStackTrace(u1 *pv, u1 *sp, u1 *ra,
+                                                                                                         u1 *xpc)
 {
        stackframeinfo     sfi;
        java_objectheader *o;
+       methodinfo        *m;
 
        /* create stackframeinfo */
 
-       stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc);
+       stacktrace_create_inline_stackframeinfo(&sfi, pv, sp, ra, xpc);
 
-       /* create exception */
+       /* get exception */
 
-       o = new_arithmeticexception();
+       o = *exceptionptr;
+
+       /* clear exception */
+
+       *exceptionptr = NULL;
+
+       /* resolve methodinfo pointer from exception object */
+
+       m = class_resolvemethod(o->vftbl->class,
+                                                       utf_fillInStackTrace,
+                                                       utf_void__java_lang_Throwable);
+
+       /* call function */
+
+       (void) vm_call_method(m, o);
 
        /* remove stackframeinfo */
 
@@ -500,14 +516,14 @@ java_objectheader *stacktrace_hardware_arithmeticexception(u1 *pv, u1 *sp,
 }
 
 
-/* stacktrace_hardware_nullpointerexception ************************************
+/* stacktrace_hardware_arithmeticexception *************************************
 
-   Creates an NullPointerException for the SIGSEGV signal handler.
+   Creates an ArithemticException for inline stub.
 
 *******************************************************************************/
 
-java_objectheader *stacktrace_hardware_nullpointerexception(u1 *pv, u1 *sp,
-                                                                                                                       u1 *ra, u1 *xpc)
+java_objectheader *stacktrace_hardware_arithmeticexception(u1 *pv, u1 *sp,
+                                                                                                                  u1 *ra, u1 *xpc)
 {
        stackframeinfo     sfi;
        java_objectheader *o;
@@ -518,7 +534,7 @@ java_objectheader *stacktrace_hardware_nullpointerexception(u1 *pv, u1 *sp,
 
        /* create exception */
 
-       o = new_nullpointerexception();
+       o = new_arithmeticexception();
 
        /* remove stackframeinfo */
 
@@ -528,41 +544,25 @@ java_objectheader *stacktrace_hardware_nullpointerexception(u1 *pv, u1 *sp,
 }
 
 
-/* stacktrace_inline_fillInStackTrace ******************************************
+/* stacktrace_hardware_nullpointerexception ************************************
 
-   Fills in the correct stacktrace into an existing exception object
-   (this one is for inline exception stubs).
+   Creates an NullPointerException for the SIGSEGV signal handler.
 
 *******************************************************************************/
 
-java_objectheader *stacktrace_inline_fillInStackTrace(u1 *pv, u1 *sp, u1 *ra,
-                                                                                                         u1 *xpc)
+java_objectheader *stacktrace_hardware_nullpointerexception(u1 *pv, u1 *sp,
+                                                                                                                       u1 *ra, u1 *xpc)
 {
        stackframeinfo     sfi;
        java_objectheader *o;
-       methodinfo        *m;
 
        /* create stackframeinfo */
 
-       stacktrace_create_inline_stackframeinfo(&sfi, pv, sp, ra, xpc);
-
-       /* get exception */
-
-       o = *exceptionptr;
-
-       /* clear exception */
-
-       *exceptionptr = NULL;
-
-       /* resolve methodinfo pointer from exception object */
-
-       m = class_resolvemethod(o->vftbl->class,
-                                                       utf_fillInStackTrace,
-                                                       utf_void__java_lang_Throwable);
+       stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc);
 
-       /* call function */
+       /* create exception */
 
-       (void) vm_call_method(m, o);
+       o = new_nullpointerexception();
 
        /* remove stackframeinfo */
 
index b009acf16b04a7ec2fe193355c11001643c389c8..073c5ccefec58bca51a2ea28e120990ffaf2b60f 100644 (file)
@@ -28,7 +28,7 @@
 
    Changes:
 
-   $Id: stacktrace.h 4533 2006-02-21 09:25:16Z twisti $
+   $Id: stacktrace.h 4615 2006-03-15 16:36:43Z twisti $
 
 */
 
@@ -118,21 +118,38 @@ void stacktrace_remove_stackframeinfo(stackframeinfo *sfi);
 /* inline exception creating functions */
 java_objectheader *stacktrace_inline_arithmeticexception(u1 *pv, u1 *sp, u1 *ra,
                                                                                                                 u1 *xpc);
+#define STACKTRACE_inline_arithmeticexception \
+    (functionptr) stacktrace_inline_arithmeticexception
+                                                                                               
 
 java_objectheader *stacktrace_inline_arrayindexoutofboundsexception(u1 *pv,
                                                                                                                                        u1 *sp,
                                                                                                                                        u1 *ra,
                                                                                                                                        u1 *xpc,
                                                                                                                                        s4 index);
+#define STACKTRACE_inline_arrayindexoutofboundsexception \
+    (functionptr) stacktrace_inline_arrayindexoutofboundsexception
 
 java_objectheader *stacktrace_inline_arraystoreexception(u1 *pv, u1 *sp, u1 *ra,
                                                                                                                 u1 *xpc);
+#define STACKTRACE_inline_arraystoreexception \
+    (functionptr) stacktrace_inline_arraystoreexception
 
 java_objectheader *stacktrace_inline_classcastexception(u1 *pv, u1 *sp, u1 *ra,
                                                                                                                u1 *xpc);
+#define STACKTRACE_inline_classcastexception \
+    (functionptr) stacktrace_inline_classcastexception
 
 java_objectheader *stacktrace_inline_nullpointerexception(u1 *pv, u1 *sp,
                                                                                                                  u1 *ra, u1 *xpc);
+#define STACKTRACE_inline_nullpointerexception \
+    (functionptr) stacktrace_inline_nullpointerexception
+
+/* refill the stacktrace of an existing exception */
+java_objectheader *stacktrace_inline_fillInStackTrace(u1 *pv, u1 *sp, u1 *ra,
+                                                                                                         u1 *xpc);
+#define STACKTRACE_inline_fillInStackTrace \
+    (functionptr) stacktrace_inline_fillInStackTrace
 
 
 /* hardware exception creating functions */
@@ -142,9 +159,6 @@ java_objectheader *stacktrace_hardware_arithmeticexception(u1 *pv, u1 *sp,
 java_objectheader *stacktrace_hardware_nullpointerexception(u1 *pv, u1 *sp,
                                                                                                                        u1 *ra, u1 *xpc);
 
-/* refill the stacktrace of an existing exception */
-java_objectheader *stacktrace_inline_fillInStackTrace(u1 *pv, u1 *sp, u1 *ra,
-                                                                                                         u1 *xpc);
 
 stacktracebuffer  *stacktrace_fillInStackTrace(void);
 java_objectarray  *stacktrace_getClassContext(void);
index 6ec62805e8c78b34796cb08fb5abbc7d96f0521d..aa84bf42c5c3981fa334d72e0d1c600996bbed81 100644 (file)
@@ -30,7 +30,7 @@
    Changes: Christian Ullrich
             Edwin Steiner
 
-   $Id: codegen.c 4598 2006-03-14 22:16:47Z edwin $
+   $Id: codegen.c 4615 2006-03-15 16:36:43Z twisti $
 
 */
 
@@ -175,7 +175,7 @@ bool codegen(methodinfo *m, codegendata *cd, registerdata *rd)
        if (opt_prof) {
                /* count frequency */
 
-               M_MOV_IMM((ptrint) m, REG_ITMP3);
+               M_MOV_IMM(m, REG_ITMP3);
                M_IINC_MEMBASE(REG_ITMP3, OFFSET(methodinfo, frequency));
 
                PROFILE_CYCLE_START;
@@ -273,18 +273,18 @@ bool codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                /* decide which monitor enter function to call */
 
                if (m->flags & ACC_STATIC) {
-                       M_MOV_IMM((ptrint) m->class, REG_ITMP1);
+                       M_MOV_IMM(m->class, REG_ITMP1);
                        M_AST(REG_ITMP1, REG_SP, s1 * 8);
                        M_INTMOVE(REG_ITMP1, rd->argintregs[0]);
-                       M_MOV_IMM((ptrint) BUILTIN_staticmonitorenter, REG_ITMP1);
+                       M_MOV_IMM(BUILTIN_staticmonitorenter, REG_ITMP1);
                        M_CALL(REG_ITMP1);
 
                } else {
                        M_TEST(rd->argintregs[0]);
-                       x86_64_jcc(cd, X86_64_CC_Z, 0);
-                       codegen_addxnullrefs(cd, cd->mcodeptr);
+                       M_BEQ(0);
+                       codegen_add_nullpointerexception_ref(cd, cd->mcodeptr);
                        M_AST(rd->argintregs[0], REG_SP, s1 * 8);
-                       M_MOV_IMM((ptrint) BUILTIN_monitorenter, REG_ITMP1);
+                       M_MOV_IMM(BUILTIN_monitorenter, REG_ITMP1);
                        M_CALL(REG_ITMP1);
                }
 
@@ -342,9 +342,9 @@ bool codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        }
                }
 
-               M_MOV_IMM((ptrint) m, REG_ITMP2);
+               M_MOV_IMM(m, REG_ITMP2);
                M_AST(REG_ITMP2, REG_SP, 0 * 8);
-               M_MOV_IMM((ptrint) builtin_trace_args, REG_ITMP1);
+               M_MOV_IMM(builtin_trace_args, REG_ITMP1);
                M_CALL(REG_ITMP1);
 
                /* restore integer argument registers */
@@ -402,7 +402,7 @@ bool codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                if (opt_prof_bb) {
                        /* count frequency */
 
-                       M_MOV_IMM((ptrint) m->bbfrequency, REG_ITMP2);
+                       M_MOV_IMM(m->bbfrequency, REG_ITMP2);
                        M_IINC_MEMBASE(REG_ITMP2, bptr->debug_nr * 4);
 
                        /* if this is an exception handler, start profiling again */
@@ -515,7 +515,7 @@ bool codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                else
                                        M_TEST(src->regoff);
                                M_BEQ(0);
-                               codegen_addxnullrefs(cd, cd->mcodeptr);
+                               codegen_add_nullpointerexception_ref(cd, cd->mcodeptr);
                                break;
 
                /* constant operations ************************************************/
@@ -578,13 +578,13 @@ bool codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
 /*                             PROFILE_CYCLE_START; */
 
-                               M_MOV_IMM((ptrint) iptr->val.a, d);
+                               M_MOV_IMM(iptr->val.a, d);
 
                        } else {
                                if (iptr->val.a == 0)
                                        M_CLR(d);
                                else
-                                       M_MOV_IMM((ptrint) iptr->val.a, d);
+                                       M_MOV_IMM(iptr->val.a, d);
                        }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -2201,11 +2201,11 @@ bool codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        M_MOV(s1, rd->argintregs[0]);
                        M_MOV(s3, rd->argintregs[1]);
-                       M_MOV_IMM((ptrint) BUILTIN_canstore, REG_ITMP1);
+                       M_MOV_IMM(BUILTIN_canstore, REG_ITMP1);
                        M_CALL(REG_ITMP1);
                        M_TEST(REG_RESULT);
                        M_BEQ(0);
-                       codegen_addxstorerefs(cd, cd->mcodeptr);
+                       codegen_add_arraystoreexception_ref(cd, cd->mcodeptr);
 
                        var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
                        var_to_reg_int(s2, src->prev, REG_ITMP2);
@@ -2672,7 +2672,7 @@ bool codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        M_CALL_IMM(0);                            /* passing exception pc */
                        M_POP(REG_ITMP2_XPC);
 
-                       M_MOV_IMM((ptrint) asm_handle_exception, REG_ITMP3);
+                       M_MOV_IMM(asm_handle_exception, REG_ITMP3);
                        M_JMP(REG_ITMP3);
                        break;
 
@@ -3001,7 +3001,7 @@ nowperformreturn:
                                        break;
                                }
 
-                               M_MOV_IMM((ptrint) builtin_monitorexit, REG_ITMP1);
+                               M_MOV_IMM(builtin_monitorexit, REG_ITMP1);
                                M_CALL(REG_ITMP1);
 
                                /* and now restore the proper return value */
@@ -3190,14 +3190,14 @@ gen_method:
                                if (iptr->op1 == true) {
                                        M_TEST(REG_RESULT);
                                        M_BEQ(0);
-                                       codegen_addxexceptionrefs(cd, cd->mcodeptr);
+                                       codegen_add_fillinstacktrace_ref(cd, cd->mcodeptr);
                                }
                                break;
 
                        case ICMD_INVOKESPECIAL:
                                M_TEST(rd->argintregs[0]);
                                M_BEQ(0);
-                               codegen_addxnullrefs(cd, cd->mcodeptr);
+                               codegen_add_nullpointerexception_ref(cd, cd->mcodeptr);
 
                                /* first argument contains pointer */
 /*                             gen_nullptr_check(rd->argintregs[0]); */
@@ -3439,14 +3439,14 @@ gen_method:
                                        M_LSUB_IMM32(superindex, REG_ITMP3);
                                        M_TEST(REG_ITMP3);
                                        M_BLE(0);
-                                       codegen_addxcastrefs(cd, cd->mcodeptr);
+                                       codegen_add_classcastexception_ref(cd, cd->mcodeptr);
                                        x86_64_mov_membase32_reg(cd, REG_ITMP2,
                                                                                         OFFSET(vftbl_t, interfacetable[0]) -
                                                                                         superindex * sizeof(methodptr*),
                                                                                         REG_ITMP3);
                                        M_TEST(REG_ITMP3);
                                        M_BEQ(0);
-                                       codegen_addxcastrefs(cd, cd->mcodeptr);
+                                       codegen_add_classcastexception_ref(cd, cd->mcodeptr);
 
                                        if (!super)
                                                M_JMP_IMM(s3);
@@ -3473,7 +3473,7 @@ gen_method:
                                                }
                                        }
 
-                                       M_MOV_IMM((ptrint) supervftbl, REG_ITMP3);
+                                       M_MOV_IMM(supervftbl, REG_ITMP3);
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
                                        codegen_threadcritstart(cd, cd->mcodeptr - cd->mcodebase);
 #endif
@@ -3497,7 +3497,7 @@ gen_method:
                                                                                          OFFSET(vftbl_t, baseval),
                                                                                          REG_ITMP3);
                                        M_LSUB(REG_ITMP3, REG_ITMP2);
-                                       M_MOV_IMM((ptrint) supervftbl, REG_ITMP3);
+                                       M_MOV_IMM(supervftbl, REG_ITMP3);
                                        M_ILD(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval));
                                        /*                                      } */
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
@@ -3505,7 +3505,7 @@ gen_method:
 #endif
                                        M_CMP(REG_ITMP3, REG_ITMP2);
                                        M_BA(0);         /* (u) REG_ITMP1 > (u) REG_ITMP2 -> jump */
-                                       codegen_addxcastrefs(cd, cd->mcodeptr);
+                                       codegen_add_classcastexception_ref(cd, cd->mcodeptr);
                                }
                                d = reg_of_var(rd, iptr->dst, REG_ITMP3);
 
@@ -3525,12 +3525,12 @@ gen_method:
                                        }
                                }
 
-                               M_MOV_IMM((ptrint) iptr->val.a, rd->argintregs[1]);
-                               M_MOV_IMM((ptrint) BUILTIN_arraycheckcast, REG_ITMP1);
+                               M_MOV_IMM(iptr->val.a, rd->argintregs[1]);
+                               M_MOV_IMM(BUILTIN_arraycheckcast, REG_ITMP1);
                                M_CALL(REG_ITMP1);
                                M_TEST(REG_RESULT);
                                M_BEQ(0);
-                               codegen_addxcastrefs(cd, cd->mcodeptr);
+                               codegen_add_classcastexception_ref(cd, cd->mcodeptr);
 
                                var_to_reg_int(s1, src, REG_ITMP1);
                                d = reg_of_var(rd, iptr->dst, REG_ITMP1);
@@ -3760,20 +3760,20 @@ gen_method:
 
                        /* a1 = arrayvftbl */
 
-                       M_MOV_IMM((ptrint) iptr->val.a, rd->argintregs[1]);
+                       M_MOV_IMM(iptr->val.a, rd->argintregs[1]);
 
                        /* a2 = pointer to dimensions = stack pointer */
 
                        M_MOV(REG_SP, rd->argintregs[2]);
 
-                       M_MOV_IMM((ptrint) BUILTIN_multianewarray, REG_ITMP1);
+                       M_MOV_IMM(BUILTIN_multianewarray, REG_ITMP1);
                        M_CALL(REG_ITMP1);
 
                        /* check for exception before result assignment */
 
                        M_TEST(REG_RESULT);
                        M_BEQ(0);
-                       codegen_addxexceptionrefs(cd, cd->mcodeptr);
+                       codegen_add_fillinstacktrace_ref(cd, cd->mcodeptr);
 
                        s1 = reg_of_var(rd, iptr->dst, REG_RESULT);
                        M_INTMOVE(REG_RESULT, s1);
@@ -3837,284 +3837,91 @@ gen_method:
 
        dseg_createlinenumbertable(cd);
 
-       {
-
-       u1        *xcodeptr;
-       branchref *bref;
-
-       /* generate ArithmeticException stubs */
-
-       xcodeptr = NULL;
-       
-       for (bref = cd->xdivrefs; bref != NULL; bref = bref->next) {
-               gen_resolvebranch(cd->mcodebase + bref->branchpos, 
-                                 bref->branchpos,
-                                                 cd->mcodeptr - cd->mcodebase);
-
-               MCODECHECK(512);
-
-               M_MOV_IMM(0, REG_ITMP2_XPC);                              /* 10 bytes */
-               dseg_adddata(cd, cd->mcodeptr);
-               M_AADD_IMM32(bref->branchpos - 6, REG_ITMP2_XPC);         /* 7 bytes  */
-
-               if (xcodeptr != NULL) {
-                       M_JMP_IMM(xcodeptr - cd->mcodeptr - 5);
-               
-               } else {
-                       xcodeptr = cd->mcodeptr;
-
-                       x86_64_lea_membase_reg(cd, RIP, -(((ptrint) cd->mcodeptr + 7) - (ptrint) cd->mcodebase), rd->argintregs[0]);
-                       M_MOV(REG_SP, rd->argintregs[1]);
-                       M_ALD(rd->argintregs[2], REG_SP, parentargs_base * 8);
-                       M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
-
-                       M_ASUB_IMM(2 * 8, REG_SP);
-                       M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
-
-                       M_MOV_IMM((ptrint) stacktrace_inline_arithmeticexception,
-                                         REG_ITMP3);
-                       M_CALL(REG_ITMP3);
-
-                       M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
-                       M_AADD_IMM(2 * 8, REG_SP);
-
-                       M_MOV_IMM((ptrint) asm_handle_exception, REG_ITMP3);
-                       M_JMP(REG_ITMP3);
-               }
-       }
-
-       /* generate ArrayIndexOutOfBoundsException stubs */
-
-       xcodeptr = NULL;
-
-       for (bref = cd->xboundrefs; bref != NULL; bref = bref->next) {
-               gen_resolvebranch(cd->mcodebase + bref->branchpos, 
-                                 bref->branchpos,
-                                                 cd->mcodeptr - cd->mcodebase);
-
-               MCODECHECK(512);
-
-               /* move index register into REG_ITMP1 */
-
-               M_MOV(bref->reg, REG_ITMP1);                              /* 3 bytes  */
-
-               M_MOV_IMM(0, REG_ITMP2_XPC);                              /* 10 bytes */
-               dseg_adddata(cd, cd->mcodeptr);
-               M_AADD_IMM32(bref->branchpos - 6, REG_ITMP2_XPC);         /* 7 bytes  */
-
-               if (xcodeptr != NULL) {
-                       M_JMP_IMM(xcodeptr - cd->mcodeptr - 5);
-
-               } else {
-                       xcodeptr = cd->mcodeptr;
-
-                       x86_64_lea_membase_reg(cd, RIP, -(((ptrint) cd->mcodeptr + 7) - (ptrint) cd->mcodebase), rd->argintregs[0]);
-                       M_MOV(REG_SP, rd->argintregs[1]);
-                       M_ALD(rd->argintregs[2], REG_SP, parentargs_base * 8);
-                       M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
-                       M_MOV(REG_ITMP1, rd->argintregs[4]);
-
-                       M_ASUB_IMM(2 * 8, REG_SP);
-                       M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
-
-                       M_MOV_IMM((ptrint) stacktrace_inline_arrayindexoutofboundsexception,
-                                         REG_ITMP3);
-                       M_CALL(REG_ITMP3);
-
-                       M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
-                       M_AADD_IMM(2 * 8, REG_SP);
-
-                       M_MOV_IMM((ptrint) asm_handle_exception, REG_ITMP3);
-                       M_JMP(REG_ITMP3);
-               }
-       }
-
-       /* generate ArrayStoreException stubs */
-
-       xcodeptr = NULL;
-       
-       for (bref = cd->xstorerefs; bref != NULL; bref = bref->next) {
-               gen_resolvebranch(cd->mcodebase + bref->branchpos, 
-                                 bref->branchpos,
-                                                 cd->mcodeptr - cd->mcodebase);
-
-               MCODECHECK(512);
-
-               M_MOV_IMM(0, REG_ITMP2_XPC);                              /* 10 bytes */
-               dseg_adddata(cd, cd->mcodeptr);
-               M_AADD_IMM32(bref->branchpos - 6, REG_ITMP2_XPC);         /* 7 bytes  */
-
-               if (xcodeptr != NULL) {
-                       M_JMP_IMM(xcodeptr - cd->mcodeptr - 5);
-
-               } else {
-                       xcodeptr = cd->mcodeptr;
-
-                       x86_64_lea_membase_reg(cd, RIP, -(((ptrint) cd->mcodeptr + 7) - (ptrint) cd->mcodebase), rd->argintregs[0]);
-                       M_MOV(REG_SP, rd->argintregs[1]);
-                       M_ALD(rd->argintregs[2], REG_SP, parentargs_base * 8);
-                       M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
-
-                       M_ASUB_IMM(2 * 8, REG_SP);
-                       M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
 
-                       M_MOV_IMM((ptrint) stacktrace_inline_arraystoreexception,
-                                         REG_ITMP3);
-                       M_CALL(REG_ITMP3);
+       /* generate exception and patcher stubs */
 
-                       M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
-                       M_AADD_IMM(2 * 8, REG_SP);
-
-                       M_MOV_IMM((ptrint) asm_handle_exception, REG_ITMP3);
-                       M_JMP(REG_ITMP3);
-               }
-       }
-
-       /* generate ClassCastException stubs */
-
-       xcodeptr = NULL;
-       
-       for (bref = cd->xcastrefs; bref != NULL; bref = bref->next) {
-               gen_resolvebranch(cd->mcodebase + bref->branchpos, 
-                                 bref->branchpos,
-                                                 cd->mcodeptr - cd->mcodebase);
-
-               MCODECHECK(512);
-
-               M_MOV_IMM(0, REG_ITMP2_XPC);                              /* 10 bytes */
-               dseg_adddata(cd, cd->mcodeptr);
-               M_AADD_IMM32(bref->branchpos - 6, REG_ITMP2_XPC);         /* 7 bytes  */
-
-               if (xcodeptr != NULL) {
-                       M_JMP_IMM(xcodeptr - cd->mcodeptr - 5);
-               
-               } else {
-                       xcodeptr = cd->mcodeptr;
-
-                       x86_64_lea_membase_reg(cd, RIP, -(((ptrint) cd->mcodeptr + 7) - (ptrint) cd->mcodebase), rd->argintregs[0]);
-                       M_MOV(REG_SP, rd->argintregs[1]);
-                       M_ALD(rd->argintregs[2], REG_SP, parentargs_base * 8);
-                       M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
-
-                       M_ASUB_IMM(2 * 8, REG_SP);
-                       M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
-
-                       M_MOV_IMM((ptrint) stacktrace_inline_classcastexception, REG_ITMP3);
-                       M_CALL(REG_ITMP3);
-
-                       M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
-                       M_AADD_IMM(2 * 8, REG_SP);
-
-                       M_MOV_IMM((ptrint) asm_handle_exception, REG_ITMP3);
-                       M_JMP(REG_ITMP3);
-               }
-       }
+       {
+               exceptionref *eref;
+               patchref     *pref;
+               ptrint        mcode;
+               u1           *savedmcodeptr;
+               u1           *tmpmcodeptr;
 
-       /* generate NullpointerException stubs */
+               savedmcodeptr = NULL;
 
-       xcodeptr = NULL;
+               /* generate exception stubs */
        
-       for (bref = cd->xnullrefs; bref != NULL; bref = bref->next) {
-               gen_resolvebranch(cd->mcodebase + bref->branchpos, 
-                                 bref->branchpos,
-                                                 cd->mcodeptr - cd->mcodebase);
-
-               MCODECHECK(512);
-
-               M_MOV_IMM(0, REG_ITMP2_XPC);                              /* 10 bytes */
-               dseg_adddata(cd, cd->mcodeptr);
-               M_AADD_IMM32(bref->branchpos - 6, REG_ITMP2_XPC);         /* 7 bytes  */
+               for (eref = cd->exceptionrefs; eref != NULL; eref = eref->next) {
+                       gen_resolvebranch(cd->mcodebase + eref->branchpos, 
+                                                         eref->branchpos,
+                                                         cd->mcodeptr - cd->mcodebase);
 
-               if (xcodeptr != NULL) {
-                       M_JMP_IMM(xcodeptr - cd->mcodeptr - 5);
-               
-               } else {
-                       xcodeptr = cd->mcodeptr;
+                       MCODECHECK(512);
 
-                       x86_64_lea_membase_reg(cd, RIP, -(((ptrint) cd->mcodeptr + 7) - (ptrint) cd->mcodebase), rd->argintregs[0]);
-                       M_MOV(REG_SP, rd->argintregs[1]);
-                       M_ALD(rd->argintregs[2], REG_SP, parentargs_base * 8);
-                       M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
+                       /* Check if the exception is an
+                          ArrayIndexOutOfBoundsException.  If so, move index register
+                          into REG_ITMP1. */
 
-                       M_ASUB_IMM(2 * 8, REG_SP);
-                       M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
+                       if (eref->reg != -1)
+                               M_MOV(eref->reg, REG_ITMP1);
 
-                       M_MOV_IMM((ptrint) stacktrace_inline_nullpointerexception,
-                                         REG_ITMP3);
-                       M_CALL(REG_ITMP3);
+                       /* calcuate exception address */
 
-                       M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
-                       M_AADD_IMM(2 * 8, REG_SP);
+                       M_MOV_IMM(0, REG_ITMP2_XPC);
+                       dseg_adddata(cd, cd->mcodeptr);
+                       M_AADD_IMM32(eref->branchpos - 6, REG_ITMP2_XPC);
 
-                       M_MOV_IMM((ptrint) asm_handle_exception, REG_ITMP3);
-                       M_JMP(REG_ITMP3);
-               }
-       }
+                       /* move function to call into REG_ITMP3 */
 
-       /* generate exception check stubs */
+                       M_MOV_IMM(eref->function, REG_ITMP3);
 
-       xcodeptr = NULL;
-       
-       for (bref = cd->xexceptionrefs; bref != NULL; bref = bref->next) {
-               gen_resolvebranch(cd->mcodebase + bref->branchpos, 
-                                 bref->branchpos,
-                                                 cd->mcodeptr - cd->mcodebase);
-
-               MCODECHECK(512);
-
-               M_MOV_IMM(0, REG_ITMP2_XPC);                              /* 10 bytes */
-               dseg_adddata(cd, cd->mcodeptr);
-               M_AADD_IMM32(bref->branchpos - 6, REG_ITMP2_XPC);         /* 7 bytes  */
-
-               if (xcodeptr != NULL) {
-                       M_JMP_IMM(xcodeptr - cd->mcodeptr - 5);
+                       if (savedmcodeptr != NULL) {
+                               M_JMP_IMM(savedmcodeptr - cd->mcodeptr - 5);
                
-               } else {
-                       xcodeptr = cd->mcodeptr;
+                       } else {
+                               savedmcodeptr = cd->mcodeptr;
 
-                       x86_64_lea_membase_reg(cd, RIP, -(((ptrint) cd->mcodeptr + 7) - (ptrint) cd->mcodebase), rd->argintregs[0]);
-                       M_MOV(REG_SP, rd->argintregs[1]);
-                       M_ALD(rd->argintregs[2], REG_SP, parentargs_base * 8);
-                       M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
+                               x86_64_lea_membase_reg(cd, RIP, -(((ptrint) cd->mcodeptr + 7) - (ptrint) cd->mcodebase), rd->argintregs[0]);
+                               M_MOV(REG_SP, rd->argintregs[1]);
+                               M_ALD(rd->argintregs[2], REG_SP, parentargs_base * 8);
+                               M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
+                               M_MOV(REG_ITMP1, rd->argintregs[4]);            /* for AIOOBE */
 
-                       M_ASUB_IMM(2 * 8, REG_SP);
-                       M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
+                               M_ASUB_IMM(2 * 8, REG_SP);
+                               M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
 
-                       M_MOV_IMM((ptrint) stacktrace_inline_fillInStackTrace, REG_ITMP3);
-                       M_CALL(REG_ITMP3);
+                               M_CALL(REG_ITMP3);
 
-                       M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
-                       M_AADD_IMM(2 * 8, REG_SP);
+                               M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
+                               M_AADD_IMM(2 * 8, REG_SP);
 
-                       M_MOV_IMM((ptrint) asm_handle_exception, REG_ITMP3);
-                       M_JMP(REG_ITMP3);
+                               M_MOV_IMM(asm_handle_exception, REG_ITMP3);
+                               M_JMP(REG_ITMP3);
+                       }
                }
-       }
 
-       /* generate code patching stub call code */
 
-       {
-               patchref    *pref;
-               codegendata *tmpcd;
-               ptrint       mcode;
-
-               tmpcd = DNEW(codegendata);
+               /* generate code patching stub call code */
 
                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).               */
+                       /* Get machine code which is patched back in later. A
+                          `call rel32' is 5 bytes long (but read 8 bytes). */
 
-                       xcodeptr = cd->mcodebase + pref->branchpos;
-                       mcode = *((ptrint *) xcodeptr);
+                       savedmcodeptr = cd->mcodebase + pref->branchpos;
+                       mcode = *((ptrint *) savedmcodeptr);
 
-                       /* patch in `call rel32' to call the following code               */
+                       /* patch in `call rel32' to call the following code */
 
-                       tmpcd->mcodeptr = xcodeptr;     /* set dummy mcode pointer        */
-                       x86_64_call_imm(tmpcd, cd->mcodeptr - (xcodeptr + 5));
+                       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 */
 
@@ -4132,21 +3939,20 @@ gen_method:
 
                        /* move machine code bytes and classinfo pointer into registers */
 
-                       M_MOV_IMM((ptrint) mcode, REG_ITMP3);
+                       M_MOV_IMM(mcode, REG_ITMP3);
                        M_PUSH(REG_ITMP3);
-                       M_MOV_IMM((ptrint) pref->ref, REG_ITMP3);
+                       M_MOV_IMM(pref->ref, REG_ITMP3);
                        M_PUSH(REG_ITMP3);
-                       M_MOV_IMM((ptrint) pref->disp, REG_ITMP3);
+                       M_MOV_IMM(pref->disp, REG_ITMP3);
                        M_PUSH(REG_ITMP3);
 
-                       M_MOV_IMM((ptrint) pref->patcher, REG_ITMP3);
+                       M_MOV_IMM(pref->patcher, REG_ITMP3);
                        M_PUSH(REG_ITMP3);
 
-                       M_MOV_IMM((ptrint) asm_wrapper_patcher, REG_ITMP3);
+                       M_MOV_IMM(asm_wrapper_patcher, REG_ITMP3);
                        M_JMP(REG_ITMP3);
                }
        }
-       }
 
        codegen_finish(m, cd, (s4) ((u1 *) cd->mcodeptr - cd->mcodebase));
 
@@ -4267,7 +4073,7 @@ u1 *createnativestub(functionptr f, methodinfo *m, codegendata *cd,
        if (opt_prof) {
                /* count frequency */
 
-               M_MOV_IMM((ptrint) m, REG_ITMP2);
+               M_MOV_IMM(m, REG_ITMP2);
                M_IINC_MEMBASE(REG_ITMP2, OFFSET(methodinfo, frequency));
        }
 
@@ -4301,9 +4107,9 @@ u1 *createnativestub(functionptr f, methodinfo *m, codegendata *cd,
                        }
                }
 
-               M_MOV_IMM((ptrint) m, REG_ITMP1);
+               M_MOV_IMM(m, REG_ITMP1);
                M_AST(REG_ITMP1, REG_SP, 0 * 8);
-               M_MOV_IMM((ptrint) builtin_trace_args, REG_ITMP1);
+               M_MOV_IMM(builtin_trace_args, REG_ITMP1);
                M_CALL(REG_ITMP1);
 
                /* restore integer and float argument registers */
@@ -4330,7 +4136,7 @@ u1 *createnativestub(functionptr f, methodinfo *m, codegendata *cd,
        }
 #endif
 
-       M_MOV_IMM((ptrint) f, REG_ITMP3);
+       M_MOV_IMM(f, REG_ITMP3);
 
 
        /* save integer and float argument registers */
@@ -4351,7 +4157,7 @@ u1 *createnativestub(functionptr f, methodinfo *m, codegendata *cd,
        x86_64_lea_membase_reg(cd, RIP, -(((ptrint) cd->mcodeptr + 7) - (ptrint) cd->mcodebase), rd->argintregs[1]);
        M_ALEA(REG_SP, stackframesize * 8 + SIZEOF_VOID_P, rd->argintregs[2]);
        M_ALD(rd->argintregs[3], REG_SP, stackframesize * 8);
-       M_MOV_IMM((ptrint) codegen_start_native_call, REG_ITMP1);
+       M_MOV_IMM(codegen_start_native_call, REG_ITMP1);
        M_CALL(REG_ITMP1);
 
        /* restore integer and float argument registers */
@@ -4408,11 +4214,11 @@ u1 *createnativestub(functionptr f, methodinfo *m, codegendata *cd,
        /* put class into second argument register */
 
        if (m->flags & ACC_STATIC)
-               M_MOV_IMM((ptrint) m->class, rd->argintregs[1]);
+               M_MOV_IMM(m->class, rd->argintregs[1]);
 
        /* put env into first argument register */
 
-       M_MOV_IMM((ptrint) _Jv_env, rd->argintregs[0]);
+       M_MOV_IMM(_Jv_env, rd->argintregs[0]);
 
        /* do the native function call */
 
@@ -4430,7 +4236,7 @@ u1 *createnativestub(functionptr f, methodinfo *m, codegendata *cd,
        /* remove native stackframe info */
 
        M_ALEA(REG_SP, stackframesize * 8, rd->argintregs[0]);
-       M_MOV_IMM((ptrint) codegen_finish_native_call, REG_ITMP1);
+       M_MOV_IMM(codegen_finish_native_call, REG_ITMP1);
        M_CALL(REG_ITMP1);
 
        /* generate call trace */
@@ -4445,22 +4251,22 @@ u1 *createnativestub(functionptr f, methodinfo *m, codegendata *cd,
                                M_DLD(REG_FRESULT, REG_SP, 0 * 8);
                }
 
-               M_MOV_IMM((ptrint) m, rd->argintregs[0]);
+               M_MOV_IMM(m, rd->argintregs[0]);
                M_MOV(REG_RESULT, rd->argintregs[1]);
                M_FLTMOVE(REG_FRESULT, rd->argfltregs[0]);
                M_FLTMOVE(REG_FRESULT, rd->argfltregs[1]);
 
-               M_MOV_IMM((ptrint) builtin_displaymethodstop, REG_ITMP1);
+               M_MOV_IMM(builtin_displaymethodstop, REG_ITMP1);
                M_CALL(REG_ITMP1);
        }
 
        /* check for exception */
 
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
-       M_MOV_IMM((ptrint) builtin_get_exceptionptrptr, REG_ITMP3);
+       M_MOV_IMM(builtin_get_exceptionptrptr, REG_ITMP3);
        M_CALL(REG_ITMP3);
 #else
-       M_MOV_IMM((ptrint) &_no_threads_exceptionptr, REG_RESULT);
+       M_MOV_IMM(&_no_threads_exceptionptr, REG_RESULT);
 #endif
        M_ALD(REG_ITMP2, REG_RESULT, 0);
 
@@ -4488,13 +4294,13 @@ u1 *createnativestub(functionptr f, methodinfo *m, codegendata *cd,
 
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
        M_LST(REG_ITMP2, REG_SP, 0 * 8);
-       M_MOV_IMM((ptrint) builtin_get_exceptionptrptr, REG_ITMP3);
+       M_MOV_IMM(builtin_get_exceptionptrptr, REG_ITMP3);
        M_CALL(REG_ITMP3);
        M_AST_IMM32(0, REG_RESULT, 0);                 /* clear exception pointer */
        M_LLD(REG_ITMP1_XPTR, REG_SP, 0 * 8);
 #else
        M_MOV(REG_ITMP3, REG_ITMP1_XPTR);
-       M_MOV_IMM((ptrint) &_no_threads_exceptionptr, REG_ITMP3);
+       M_MOV_IMM(&_no_threads_exceptionptr, REG_ITMP3);
        M_AST_IMM32(0, REG_ITMP3, 0);                  /* clear exception pointer */
 #endif
 
@@ -4505,34 +4311,36 @@ u1 *createnativestub(functionptr f, methodinfo *m, codegendata *cd,
        M_LLD(REG_ITMP2_XPC, REG_SP, 0 * 8);     /* get return address from stack */
        M_ASUB_IMM(3, REG_ITMP2_XPC);                                    /* callq */
 
-       M_MOV_IMM((ptrint) asm_handle_nat_exception, REG_ITMP3);
+       M_MOV_IMM(asm_handle_nat_exception, REG_ITMP3);
        M_JMP(REG_ITMP3);
 
 
        /* process patcher calls **************************************************/
 
        {
-               u1          *xcodeptr;
-               patchref    *pref;
-               codegendata *tmpcd;
-               ptrint       mcode;
+               patchref *pref;
+               ptrint    mcode;
+               u1       *savedmcodeptr;
+               u1       *tmpmcodeptr;
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
-               s4           disp;
+               s4        disp;
 #endif
 
-               tmpcd = DNEW(codegendata);
-
                for (pref = cd->patchrefs; pref != NULL; pref = pref->next) {
-                       /* Get machine code which is patched back in later. A             */
-                       /* `call rel32' is 5 bytes long (but read 8 bytes).               */
+                       /* Get machine code which is patched back in later. A
+                          `call rel32' is 5 bytes long (but read 8 bytes). */
 
-                       xcodeptr = cd->mcodebase + pref->branchpos;
-                       mcode = *((ptrint *) xcodeptr);
+                       savedmcodeptr = cd->mcodebase + pref->branchpos;
+                       mcode = *((ptrint *) savedmcodeptr);
 
                        /* patch in `call rel32' to call the following code               */
 
-                       tmpcd->mcodeptr = xcodeptr;     /* set dummy mcode pointer        */
-                       x86_64_call_imm(tmpcd, cd->mcodeptr - (xcodeptr + 5));
+                       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 */
 
@@ -4550,17 +4358,17 @@ u1 *createnativestub(functionptr f, methodinfo *m, codegendata *cd,
 
                        /* move machine code bytes and classinfo pointer into registers */
 
-                       M_MOV_IMM((ptrint) mcode, REG_ITMP3);
+                       M_MOV_IMM(mcode, REG_ITMP3);
                        M_PUSH(REG_ITMP3);
-                       M_MOV_IMM((ptrint) pref->ref, REG_ITMP3);
+                       M_MOV_IMM(pref->ref, REG_ITMP3);
                        M_PUSH(REG_ITMP3);
-                       M_MOV_IMM((ptrint) pref->disp, REG_ITMP3);
+                       M_MOV_IMM(pref->disp, REG_ITMP3);
                        M_PUSH(REG_ITMP3);
 
-                       M_MOV_IMM((ptrint) pref->patcher, REG_ITMP3);
+                       M_MOV_IMM(pref->patcher, REG_ITMP3);
                        M_PUSH(REG_ITMP3);
 
-                       M_MOV_IMM((ptrint) asm_wrapper_patcher, REG_ITMP3);
+                       M_MOV_IMM(asm_wrapper_patcher, REG_ITMP3);
                        M_JMP(REG_ITMP3);
                }
        }
index 630c1efd3bc6d9a801e6df5333189534eda58599..a1c1a2f8496ea10ebb358f77dae697d85a387e8c 100644 (file)
@@ -29,7 +29,7 @@
 
    Changes:
 
-   $Id: codegen.h 4398 2006-01-31 23:43:08Z twisti $
+   $Id: codegen.h 4615 2006-03-15 16:36:43Z twisti $
 
 */
 
@@ -279,29 +279,29 @@ typedef enum {
 
 #define gen_nullptr_check(objreg) \
        if (checknull) { \
-        x86_64_test_reg_reg(cd, (objreg), (objreg)); \
-        x86_64_jcc(cd, X86_64_CC_E, 0); \
-           codegen_addxnullrefs(cd, cd->mcodeptr); \
+        M_TEST(objreg); \
+        M_BEQ(0); \
+           codegen_add_nullpointerexception_ref(cd, cd->mcodeptr); \
        }
 
 
 #define gen_bound_check \
     if (checkbounds) { \
-        x86_64_alul_membase_reg(cd, X86_64_CMP, s1, OFFSET(java_arrayheader, size), s2); \
-        x86_64_jcc(cd, X86_64_CC_AE, 0); \
-        codegen_addxboundrefs(cd, cd->mcodeptr, s2); \
+        M_CMP_MEMBASE(s1, OFFSET(java_arrayheader, size), s2); \
+        M_BAE(0); \
+        codegen_add_arrayindexoutofboundsexception_ref(cd, cd->mcodeptr, s2); \
     }
 
 
 #define gen_div_check(v) \
     if (checknull) { \
         if ((v)->flags & INMEMORY) { \
-            x86_64_alu_imm_membase(cd, X86_64_CMP, 0, REG_SP, src->regoff * 8); \
+            M_CMP_IMM_MEMBASE(0, REG_SP, src->regoff * 8); \
         } else { \
-            x86_64_test_reg_reg(cd, src->regoff, src->regoff); \
+            M_TEST(src->regoff); \
         } \
-        x86_64_jcc(cd, X86_64_CC_E, 0); \
-        codegen_addxdivrefs(cd, cd->mcodeptr); \
+        M_BEQ(0); \
+        codegen_add_arithmeticexception_ref(cd, cd->mcodeptr); \
     }
 
 
@@ -426,11 +426,11 @@ typedef enum {
 /* macros to create code ******************************************************/
 
 #define M_MOV(a,b)              x86_64_mov_reg_reg(cd, (a), (b))
-#define M_MOV_IMM(a,b)          x86_64_mov_imm_reg(cd, (a), (b))
+#define M_MOV_IMM(a,b)          x86_64_mov_imm_reg(cd, (u8) (a), (b))
 
 #define M_FMOV(a,b)             x86_64_movq_reg_reg(cd, (a), (b))
 
-#define M_IMOV_IMM(a,b)         x86_64_movl_imm_reg(cd, (a), (b))
+#define M_IMOV_IMM(a,b)         x86_64_movl_imm_reg(cd, (u4) (a), (b))
 
 #define M_ILD(a,b,disp)         x86_64_movl_membase_reg(cd, (b), (disp), (a))
 #define M_LLD(a,b,disp)         x86_64_mov_membase_reg(cd, (b), (disp), (a))
@@ -501,6 +501,7 @@ typedef enum {
 #define M_BEQ(disp)             x86_64_jcc(cd, X86_64_CC_E, (disp))
 #define M_BNE(disp)             x86_64_jcc(cd, X86_64_CC_NE, (disp))
 #define M_BLE(disp)             x86_64_jcc(cd, X86_64_CC_LE, (disp))
+#define M_BAE(disp)             x86_64_jcc(cd, X86_64_CC_AE, (disp))
 #define M_BA(disp)              x86_64_jcc(cd, X86_64_CC_A, (disp))
 
 #define M_CMOVEQ(a,b)           x86_64_cmovcc_reg_reg(cd, X86_64_CC_E, (a), (b))