* src/vm/vm.c, src/vm/vm.h: Moved to .cpp.
[cacao.git] / src / vm / jit / mips / codegen.c
index c2e25312258f9d202a121333623f6a9bb62936e3..68ad764c25c95a1976a362173a738ccea746a9f4 100644 (file)
@@ -1,9 +1,7 @@
 /* src/vm/jit/mips/codegen.c - machine code generator for MIPS
 
-   Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
-   C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
-   E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
-   J. Wenninger, Institut f. Computersprachen - TU Wien
+   Copyright (C) 1996-2005, 2006, 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 
@@ -22,8 +20,6 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: codegen.c 8297 2007-08-12 00:02:48Z michi $
-
 */
 
 
@@ -48,7 +44,7 @@
 
 #include "vm/builtin.h"
 #include "vm/exceptions.h"
-#include "vm/vm.h"
+#include "vm/vm.hpp"
 
 #include "vm/jit/abi.h"
 #include "vm/jit/asmpart.h"
 #include "vm/jit/dseg.h"
 #include "vm/jit/emit-common.h"
 #include "vm/jit/jit.h"
-#include "vm/jit/md.h"
+#include "vm/jit/linenumbertable.h"
 #include "vm/jit/patcher-common.h"
 #include "vm/jit/reg.h"
 #include "vm/jit/replace.h"
+#include "vm/jit/trap.h"
 
 #if defined(ENABLE_LSRA)
 # include "vm/jit/allocator/lsra.h"
@@ -85,7 +82,6 @@ bool codegen_emit(jitdata *jd)
        varinfo            *var;
        basicblock         *bptr;
        instruction        *iptr;
-       exception_entry    *ex;
        u2                  currentline;
        constant_classref  *cr;
        unresolved_class   *uc;
@@ -120,7 +116,7 @@ bool codegen_emit(jitdata *jd)
        s4 i, p, t, l;
        s4 savedregs_num;
 
-       savedregs_num = (jd->isleafmethod) ? 0 : 1;       /* space to save the RA */
+       savedregs_num = code_is_leafmethod(code) ? 0 : 1; /* space to save the RA */
 
        /* space to save used callee saved registers */
 
@@ -132,7 +128,7 @@ bool codegen_emit(jitdata *jd)
 #if defined(ENABLE_THREADS)
        /* space to save argument of monitor_enter */
 
-       if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
+       if (checksync && code_is_synchronized(code)) {
 # if SIZEOF_VOID_P == 8
                cd->stackframesize++;
 # else
@@ -152,34 +148,18 @@ bool codegen_emit(jitdata *jd)
        (void) dseg_add_unique_address(cd, code);              /* CodeinfoPointer */
        (void) dseg_add_unique_s4(cd, cd->stackframesize * 8); /* FrameSize       */
 
-#if defined(ENABLE_THREADS)
-       /* IsSync contains the offset relative to the stack pointer for the
-          argument of monitor_exit used in the exception handler. Since the
-          offset could be zero and give a wrong meaning of the flag it is
-          offset by one.
-       */
-
-       if (checksync && (m->flags & ACC_SYNCHRONIZED))
-               (void) dseg_add_unique_s4(cd, (rd->memuse + 1) * 8); /* IsSync        */
+       code->synchronizedoffset = rd->memuse * 8;
+
+       /* REMOVEME: We still need it for exception handling in assembler. */
+
+       if (code_is_leafmethod(code))
+               (void) dseg_add_unique_s4(cd, 1);
        else
-#endif
-               (void) dseg_add_unique_s4(cd, 0);                  /* IsSync          */
-                                              
-       (void) dseg_add_unique_s4(cd, jd->isleafmethod);       /* IsLeaf          */
+               (void) dseg_add_unique_s4(cd, 0);
+
        (void) dseg_add_unique_s4(cd, INT_SAV_CNT - rd->savintreguse); /* IntSave */
        (void) dseg_add_unique_s4(cd, FLT_SAV_CNT - rd->savfltreguse); /* FltSave */
-       dseg_addlinenumbertablesize(cd);
-       (void) dseg_add_unique_s4(cd, jd->exceptiontablelength); /* ExTableSize   */
-
-       /* create exception table */
 
-       for (ex = jd->exceptiontable; ex != NULL; ex = ex->down) {
-               dseg_add_target(cd, ex->start);
-               dseg_add_target(cd, ex->end);
-               dseg_add_target(cd, ex->handler);
-               (void) dseg_add_unique_address(cd, ex->catchtype.any);
-       }
-       
        /* create stack frame (if necessary) */
 
        if (cd->stackframesize)
@@ -188,7 +168,7 @@ bool codegen_emit(jitdata *jd)
        /* save return address and used callee saved registers */
 
        p = cd->stackframesize;
-       if (!jd->isleafmethod) {
+       if (!code_is_leafmethod(code)) {
                p--; M_AST(REG_RA, REG_SP, p * 8);
        }
        for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--) {
@@ -285,7 +265,7 @@ bool codegen_emit(jitdata *jd)
        /* call monitorenter function */
 
 #if defined(ENABLE_THREADS)
-       if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
+       if (checksync && code_is_synchronized(code)) {
                /* stack offset for monitor argument */
 
                s1 = rd->memuse;
@@ -307,7 +287,7 @@ bool codegen_emit(jitdata *jd)
                /* get correct lock object */
 
                if (m->flags & ACC_STATIC) {
-                       disp = dseg_add_address(cd, &m->class->object.header);
+                       disp = dseg_add_address(cd, &m->clazz->object.header);
                        M_ALD(REG_A0, REG_PV, disp);
                        disp = dseg_add_functionptr(cd, LOCK_monitor_enter);
                        M_ALD(REG_ITMP3, REG_PV, disp);
@@ -317,7 +297,7 @@ bool codegen_emit(jitdata *jd)
                        M_BNEZ(REG_A0, 2);
                        disp = dseg_add_functionptr(cd, LOCK_monitor_enter);
                        M_ALD(REG_ITMP3, REG_PV, disp);                   /* branch delay */
-                       M_ALD_INTERN(REG_ZERO, REG_ZERO, EXCEPTION_HARDWARE_NULLPOINTER);
+                       M_ALD_INTERN(REG_ZERO, REG_ZERO, TRAP_NullPointerException);
                }
 
                M_JSR(REG_RA, REG_ITMP3);
@@ -410,7 +390,7 @@ bool codegen_emit(jitdata *jd)
 
                for (iptr = bptr->iinstr; len > 0; len--, iptr++) {
                        if (iptr->line != currentline) {
-                               dseg_addlinenumber(cd, iptr->line);
+                               linenumbertable_list_entry_add(cd, iptr->line);
                                currentline = iptr->line;
                        }
 
@@ -431,14 +411,14 @@ bool codegen_emit(jitdata *jd)
                case ICMD_INLINE_BODY:
 
                        REPLACEMENT_POINT_INLINE_BODY(cd, iptr);
-                       dseg_addlinenumber_inline_start(cd, iptr);
-                       dseg_addlinenumber(cd, iptr->line);
+                       linenumbertable_list_entry_add_inline_start(cd, iptr);
+                       linenumbertable_list_entry_add(cd, iptr->line);
                        break;
 
                case ICMD_INLINE_END:
 
-                       dseg_addlinenumber_inline_end(cd, iptr);
-                       dseg_addlinenumber(cd, iptr->line);
+                       linenumbertable_list_entry_add_inline_end(cd, iptr);
+                       linenumbertable_list_entry_add(cd, iptr->line);
                        break;
 
                case ICMD_CHECKNULL:  /* ..., objectref  ==> ..., objectref           */
@@ -1708,7 +1688,7 @@ bool codegen_emit(jitdata *jd)
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
                        /* implicit null-pointer check */
-                       M_ILD(d, s1, OFFSET(java_arrayheader, size));
+                       M_ILD(d, s1, OFFSET(java_array_t, size));
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -1720,7 +1700,7 @@ bool codegen_emit(jitdata *jd)
                        emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_AADD(s2, s1, REG_ITMP3);
                        /* implicit null-pointer check */
-                       M_BLDS(d, REG_ITMP3, OFFSET(java_bytearray, data[0]));
+                       M_BLDS(d, REG_ITMP3, OFFSET(java_bytearray_t, data[0]));
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -1733,7 +1713,7 @@ bool codegen_emit(jitdata *jd)
                        M_AADD(s2, s1, REG_ITMP3);
                        M_AADD(s2, REG_ITMP3, REG_ITMP3);
                        /* implicit null-pointer check */
-                       M_SLDU(d, REG_ITMP3, OFFSET(java_chararray, data[0]));
+                       M_SLDU(d, REG_ITMP3, OFFSET(java_chararray_t, data[0]));
                        emit_store_dst(jd, iptr, d);
                        break;                  
 
@@ -1746,7 +1726,7 @@ bool codegen_emit(jitdata *jd)
                        M_AADD(s2, s1, REG_ITMP3);
                        M_AADD(s2, REG_ITMP3, REG_ITMP3);
                        /* implicit null-pointer check */
-                       M_SLDS(d, REG_ITMP3, OFFSET(java_shortarray, data[0]));
+                       M_SLDS(d, REG_ITMP3, OFFSET(java_shortarray_t, data[0]));
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -1759,7 +1739,7 @@ bool codegen_emit(jitdata *jd)
                        M_ASLL_IMM(s2, 2, REG_ITMP3);
                        M_AADD(REG_ITMP3, s1, REG_ITMP3);
                        /* implicit null-pointer check */
-                       M_ILD_INTERN(d, REG_ITMP3, OFFSET(java_intarray, data[0]));
+                       M_ILD_INTERN(d, REG_ITMP3, OFFSET(java_intarray_t, data[0]));
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -1776,7 +1756,7 @@ bool codegen_emit(jitdata *jd)
                        M_ASLL_IMM(s2, 3, REG_ITMP3);
                        M_AADD(REG_ITMP3, s1, REG_ITMP3);
                        /* implicit null-pointer check */
-                       M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_longarray, data[0]));
+                       M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_longarray_t, data[0]));
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -1789,7 +1769,7 @@ bool codegen_emit(jitdata *jd)
                        M_ASLL_IMM(s2, 2, REG_ITMP3);
                        M_AADD(REG_ITMP3, s1, REG_ITMP3);
                        /* implicit null-pointer check */
-                       M_FLD_INTERN(d, REG_ITMP3, OFFSET(java_floatarray, data[0]));
+                       M_FLD_INTERN(d, REG_ITMP3, OFFSET(java_floatarray_t, data[0]));
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -1802,7 +1782,7 @@ bool codegen_emit(jitdata *jd)
                        M_ASLL_IMM(s2, 3, REG_ITMP3);
                        M_AADD(REG_ITMP3, s1, REG_ITMP3);
                        /* implicit null-pointer check */
-                       M_DLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray, data[0]));
+                       M_DLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray_t, data[0]));
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -1815,7 +1795,7 @@ bool codegen_emit(jitdata *jd)
                        M_ASLL_IMM(s2, POINTERSHIFT, REG_ITMP3);
                        M_AADD(REG_ITMP3, s1, REG_ITMP3);
                        /* implicit null-pointer check */
-                       M_ALD_INTERN(d, REG_ITMP3, OFFSET(java_objectarray, data[0]));
+                       M_ALD_INTERN(d, REG_ITMP3, OFFSET(java_objectarray_t, data[0]));
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -1828,7 +1808,7 @@ bool codegen_emit(jitdata *jd)
                        M_AADD(s2, s1, REG_ITMP1);
                        s3 = emit_load_s3(jd, iptr, REG_ITMP3);
                        /* implicit null-pointer check */
-                       M_BST(s3, REG_ITMP1, OFFSET(java_bytearray, data[0]));
+                       M_BST(s3, REG_ITMP1, OFFSET(java_bytearray_t, data[0]));
                        break;
 
                case ICMD_CASTORE:    /* ..., arrayref, index, value  ==> ...         */
@@ -1841,7 +1821,7 @@ bool codegen_emit(jitdata *jd)
                        M_AADD(s2, REG_ITMP1, REG_ITMP1);
                        s3 = emit_load_s3(jd, iptr, REG_ITMP3);
                        /* implicit null-pointer check */
-                       M_SST(s3, REG_ITMP1, OFFSET(java_chararray, data[0]));
+                       M_SST(s3, REG_ITMP1, OFFSET(java_chararray_t, data[0]));
                        break;
 
                case ICMD_IASTORE:    /* ..., arrayref, index, value  ==> ...         */
@@ -1853,7 +1833,7 @@ bool codegen_emit(jitdata *jd)
                        M_AADD(REG_ITMP2, s1, REG_ITMP1);
                        s3 = emit_load_s3(jd, iptr, REG_ITMP3);
                        /* implicit null-pointer check */
-                       M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_intarray, data[0]));
+                       M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_intarray_t, data[0]));
                        break;
 
                case ICMD_LASTORE:    /* ..., arrayref, index, value  ==> ...         */
@@ -1869,7 +1849,7 @@ bool codegen_emit(jitdata *jd)
                        s3 = emit_load_s3(jd, iptr, REG_ITMP23_PACKED);
 #endif
                        /* implicit null-pointer check */
-                       M_LST_INTERN(s3, REG_ITMP1, OFFSET(java_longarray, data[0]));
+                       M_LST_INTERN(s3, REG_ITMP1, OFFSET(java_longarray_t, data[0]));
                        break;
 
                case ICMD_FASTORE:    /* ..., arrayref, index, value  ==> ...         */
@@ -1881,7 +1861,7 @@ bool codegen_emit(jitdata *jd)
                        M_AADD(REG_ITMP2, s1, REG_ITMP1);
                        s3 = emit_load_s3(jd, iptr, REG_FTMP1);
                        /* implicit null-pointer check */
-                       M_FST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray, data[0]));
+                       M_FST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
                        break;
 
                case ICMD_DASTORE:    /* ..., arrayref, index, value  ==> ...         */
@@ -1893,7 +1873,7 @@ bool codegen_emit(jitdata *jd)
                        M_AADD(REG_ITMP2, s1, REG_ITMP1);
                        s3 = emit_load_s3(jd, iptr, REG_FTMP1);
                        /* implicit null-pointer check */
-                       M_DST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray, data[0]));
+                       M_DST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray_t, data[0]));
                        break;
 
 
@@ -1906,11 +1886,11 @@ bool codegen_emit(jitdata *jd)
 
                        M_INTMOVE(s1, REG_A0);
                        M_INTMOVE(s3, REG_A1);
-                       disp = dseg_add_functionptr(cd, BUILTIN_canstore);
+                       disp = dseg_add_functionptr(cd, BUILTIN_FAST_canstore);
                        M_ALD(REG_ITMP3, REG_PV, disp);
                        M_JSR(REG_RA, REG_ITMP3);
                        M_NOP;
-                       emit_exception_check(cd, iptr);
+                       emit_arraystore_check(cd, iptr);
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
@@ -1918,7 +1898,7 @@ bool codegen_emit(jitdata *jd)
                        M_AADD(REG_ITMP2, s1, REG_ITMP1);
                        s3 = emit_load_s3(jd, iptr, REG_ITMP3);
                        /* implicit null-pointer check */
-                       M_AST_INTERN(s3, REG_ITMP1, OFFSET(java_objectarray, data[0]));
+                       M_AST_INTERN(s3, REG_ITMP1, OFFSET(java_objectarray_t, data[0]));
                        break;
 
 
@@ -1929,7 +1909,7 @@ bool codegen_emit(jitdata *jd)
                        emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_AADD(s2, s1, REG_ITMP1);
                        /* implicit null-pointer check */
-                       M_BST(REG_ZERO, REG_ITMP1, OFFSET(java_bytearray, data[0]));
+                       M_BST(REG_ZERO, REG_ITMP1, OFFSET(java_bytearray_t, data[0]));
                        break;
 
                case ICMD_CASTORECONST:   /* ..., arrayref, index  ==> ...            */
@@ -1941,7 +1921,7 @@ bool codegen_emit(jitdata *jd)
                        M_AADD(s2, s1, REG_ITMP1);
                        M_AADD(s2, REG_ITMP1, REG_ITMP1);
                        /* implicit null-pointer check */
-                       M_SST(REG_ZERO, REG_ITMP1, OFFSET(java_chararray, data[0]));
+                       M_SST(REG_ZERO, REG_ITMP1, OFFSET(java_chararray_t, data[0]));
                        break;
 
                case ICMD_IASTORECONST:   /* ..., arrayref, index  ==> ...            */
@@ -1952,7 +1932,7 @@ bool codegen_emit(jitdata *jd)
                        M_ASLL_IMM(s2, 2, REG_ITMP2);
                        M_AADD(REG_ITMP2, s1, REG_ITMP1);
                        /* implicit null-pointer check */
-                       M_IST_INTERN(REG_ZERO, REG_ITMP1, OFFSET(java_intarray, data[0]));
+                       M_IST_INTERN(REG_ZERO, REG_ITMP1, OFFSET(java_intarray_t, data[0]));
                        break;
 
                case ICMD_LASTORECONST:   /* ..., arrayref, index  ==> ...            */
@@ -1964,9 +1944,9 @@ bool codegen_emit(jitdata *jd)
                        M_AADD(REG_ITMP2, s1, REG_ITMP1);
                        /* implicit null-pointer check */
 #if SIZEOF_VOID_P == 8
-                       M_LST_INTERN(REG_ZERO, REG_ITMP1, OFFSET(java_longarray, data[0]));
+                       M_LST_INTERN(REG_ZERO, REG_ITMP1, OFFSET(java_longarray_t, data[0]));
 #else
-                       M_LST_INTERN(PACK_REGS(REG_ZERO, REG_ZERO), REG_ITMP1, OFFSET(java_longarray, data[0]));
+                       M_LST_INTERN(PACK_REGS(REG_ZERO, REG_ZERO), REG_ITMP1, OFFSET(java_longarray_t, data[0]));
 #endif
                        break;
 
@@ -1978,7 +1958,7 @@ bool codegen_emit(jitdata *jd)
                        M_ASLL_IMM(s2, POINTERSHIFT, REG_ITMP2);
                        M_AADD(REG_ITMP2, s1, REG_ITMP1);
                        /* implicit null-pointer check */
-                       M_AST_INTERN(REG_ZERO, REG_ITMP1, OFFSET(java_objectarray, data[0]));
+                       M_AST_INTERN(REG_ZERO, REG_ITMP1, OFFSET(java_objectarray_t, data[0]));
                        break;
 
 
@@ -1996,9 +1976,9 @@ bool codegen_emit(jitdata *jd)
                                fieldtype = fi->type;
                                disp      = dseg_add_address(cd, fi->value);
 
-                               if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class))
+                               if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->clazz))
                                        patcher_add_patch_ref(jd, PATCHER_initialize_class,
-                                                                                 fi->class, disp);
+                                                                                 fi->clazz, disp);
                        }
 
                        M_ALD(REG_ITMP1, REG_PV, disp);
@@ -2046,9 +2026,9 @@ bool codegen_emit(jitdata *jd)
                                fieldtype = fi->type;
                                disp      = dseg_add_address(cd, fi->value);
 
-                               if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class))
+                               if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->clazz))
                                        patcher_add_patch_ref(jd, PATCHER_initialize_class,
-                                                                                 fi->class, disp);
+                                                                                 fi->clazz, disp);
                        }
 
                        M_ALD(REG_ITMP1, REG_PV, disp);
@@ -2095,9 +2075,9 @@ bool codegen_emit(jitdata *jd)
                                fieldtype = fi->type;
                                disp      = dseg_add_address(cd, fi->value);
 
-                               if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class))
+                               if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->clazz))
                                        patcher_add_patch_ref(jd, PATCHER_initialize_class,
-                                                                                 fi->class, disp);
+                                                                                 fi->clazz, disp);
                        }
 
                        M_ALD(REG_ITMP1, REG_PV, disp);
@@ -2834,7 +2814,7 @@ nowperformreturn:
 #endif
 
 #if defined(ENABLE_THREADS)
-                       if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
+                       if (checksync && code_is_synchronized(code)) {
                                disp = dseg_add_functionptr(cd, LOCK_monitor_exit);
                                M_ALD(REG_ITMP3, REG_PV, disp);
 
@@ -2895,7 +2875,7 @@ nowperformreturn:
 
                        /* restore return address                                         */
 
-                       if (!jd->isleafmethod) {
+                       if (!code_is_leafmethod(code)) {
                                p--; M_ALD(REG_RA, REG_SP, p * 8);
                        }
 
@@ -3101,22 +3081,31 @@ gen_method:
 
                        switch (iptr->opc) {
                        case ICMD_BUILTIN:
-                               disp = dseg_add_functionptr(cd, bte->fp);
+                               if (bte->stub == NULL) {
+                                       disp = dseg_add_functionptr(cd, bte->fp);
+                                       M_ALD(REG_ITMP3, REG_PV, disp);  /* built-in-function pointer */
 
-                               M_ALD(REG_ITMP3, REG_PV, disp);  /* built-in-function pointer */
+                                       /* generate the actual call */
 
-                               /* generate the actual call */
+                                       /* TWISTI: i actually don't know the reason for using
+                                          REG_ITMP3 here instead of REG_PV. */
 
-                               /* TWISTI: i actually don't know the reason for using
-                                  REG_ITMP3 here instead of REG_PV. */
+                                       M_JSR(REG_RA, REG_ITMP3);
+                                       M_NOP;
+                               }
+                               else {
+                                       disp = dseg_add_functionptr(cd, bte->stub);
+                                       M_ALD(REG_PV, REG_PV, disp);          /* method pointer in pv */
+
+                                       /* generate the actual call */
+
+                                       M_JSR(REG_RA, REG_PV);
+                                       M_NOP;
+                               }
 
-                               M_JSR(REG_RA, REG_ITMP3);
-                               M_NOP;
                                REPLACEMENT_POINT_INVOKE_RETURN(cd, iptr);
                                disp = (s4) (cd->mcodeptr - cd->mcodebase);
                                M_LDA(REG_PV, REG_RA, -disp);
-
-                               emit_exception_check(cd, iptr);
                                break;
 
                        case ICMD_INVOKESPECIAL:
@@ -3180,9 +3169,9 @@ gen_method:
                                }
                                else {
                                        s1 = OFFSET(vftbl_t, interfacetable[0]) -
-                                               sizeof(methodptr*) * lm->class->index;
+                                               sizeof(methodptr*) * lm->clazz->index;
 
-                                       s2 = sizeof(methodptr) * (lm - lm->class->methods);
+                                       s2 = sizeof(methodptr) * (lm - lm->clazz->methods);
                                }
 
                                /* implicit null-pointer check */
@@ -3247,9 +3236,6 @@ gen_method:
                                        superindex = super->index;
                                }
                        
-                               if ((super == NULL) || !(super->flags & ACC_INTERFACE))
-                                       CODEGEN_CRITICAL_SECTION_NEW;
-
                                s1 = emit_load_s1(jd, iptr, REG_ITMP1);
 
                                /* if class is not resolved, check which code to call */
@@ -3320,8 +3306,6 @@ gen_method:
                                        M_ALD(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
                                        M_ALD(REG_ITMP3, REG_PV, disp);
 
-                                       CODEGEN_CRITICAL_SECTION_START;
-
                                        M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval));
                                        /*                              if (s1 != REG_ITMP1) { */
                                        /*                                      M_ILD(REG_ITMP1, REG_ITMP3, OFFSET(vftbl_t, baseval)); */
@@ -3336,8 +3320,6 @@ gen_method:
                                        M_ALD(REG_ITMP3, REG_PV, disp);
                                        M_ILD(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval));
 
-                                       CODEGEN_CRITICAL_SECTION_END;
-
                                        /*                              } */
                                        M_CMPULT(REG_ITMP3, REG_ITMP2, REG_ITMP3);
                                        emit_classcast_check(cd, iptr, ICMD_IFNE, REG_ITMP3, s1);
@@ -3402,9 +3384,6 @@ gen_method:
                                superindex = super->index;
                        }
                        
-                       if ((super == NULL) || !(super->flags & ACC_INTERFACE))
-                               CODEGEN_CRITICAL_SECTION_NEW;
-
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
 
@@ -3482,14 +3461,10 @@ gen_method:
                                M_ALD(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
                                M_ALD(REG_ITMP2, REG_PV, disp);
 
-                               CODEGEN_CRITICAL_SECTION_START;
-
                                M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
                                M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
                                M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
 
-                               CODEGEN_CRITICAL_SECTION_END;
-
                                M_ISUB(REG_ITMP1, REG_ITMP3, REG_ITMP1); 
                                M_CMPULT(REG_ITMP2, REG_ITMP1, d);
                                M_XOR_IMM(d, 1, d);
@@ -3595,8 +3570,6 @@ gen_method:
        } /* if (bptr -> flags >= BBREACHED) */
        } /* for basic block */
 
-       dseg_createlinenumbertable(cd);
-
        /* generate traps */
 
        emit_patcher_traps(jd);
@@ -3607,48 +3580,22 @@ gen_method:
 }
 
 
-/* codegen_emit_stub_compiler **************************************************
-
-   Emits 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_ALD_INTERN(REG_ITMP1, REG_PV, -2 * SIZEOF_VOID_P);  /* codeinfo pointer */
-       M_ALD_INTERN(REG_PV, REG_PV, -3 * SIZEOF_VOID_P);  /* pointer to compiler */
-       M_JMP(REG_PV);
-       M_NOP;
-}
-
-
 /* codegen_emit_stub_native ****************************************************
 
    Emits a stub routine which calls a native method.
 
 *******************************************************************************/
 
-void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
+void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int skipparams)
 {
        methodinfo  *m;
        codeinfo    *code;
        codegendata *cd;
        methoddesc  *md;
-       s4           nativeparams;
        s4           i, j;
        s4           t;
-       s4           s1, s2, disp;
-       s4           funcdisp;              /* displacement of the function       */
+       int          s1, s2;
+       int          disp;
 
        /* get required compiler data */
 
@@ -3659,13 +3606,12 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
        /* initialize variables */
 
        md = m->parseddesc;
-       nativeparams = (m->flags & ACC_STATIC) ? 2 : 1;
 
        /* calculate stack frame size */
 
        cd->stackframesize =
                1 +                             /* return address                     */
-               sizeof(stackframeinfo) / SIZEOF_VOID_P +
+               sizeof(stackframeinfo_t) / SIZEOF_VOID_P +
                sizeof(localref_table) / SIZEOF_VOID_P +
                md->paramcount +                /* for saving arguments over calls    */
 #if SIZEOF_VOID_P == 4
@@ -3683,12 +3629,9 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
 
        (void) dseg_add_unique_address(cd, code);              /* CodeinfoPointer */
        (void) dseg_add_unique_s4(cd, cd->stackframesize * 8); /* FrameSize       */
-       (void) dseg_add_unique_s4(cd, 0);                      /* IsSync          */
        (void) dseg_add_unique_s4(cd, 0);                      /* IsLeaf          */
        (void) dseg_add_unique_s4(cd, 0);                      /* IntSave         */
        (void) dseg_add_unique_s4(cd, 0);                      /* FltSave         */
-       (void) dseg_addlinenumbertablesize(cd);
-       (void) dseg_add_unique_s4(cd, 0);                      /* ExTableSize     */
 
        /* generate stub code */
 
@@ -3700,15 +3643,6 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
                emit_verbosecall_enter(jd);
 #endif
 
-       /* get function address (this must happen before the stackframeinfo) */
-
-       funcdisp = dseg_add_functionptr(cd, f);
-
-#if !defined(WITH_STATIC_CLASSPATH)
-       if (f == NULL)
-               patcher_add_patch_ref(jd, PATCHER_resolve_native_function, m, funcdisp);
-#endif
-
        /* save integer and float argument registers */
 
 #if SIZEOF_VOID_P == 8
@@ -3751,15 +3685,18 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
 
        /* prepare data structures for native function call */
 
-       M_AADD_IMM(REG_SP, (cd->stackframesize - 1) * 8, REG_A0);
+       M_MOV(REG_SP, REG_A0);
        M_MOV(REG_PV, REG_A1);
-       M_AADD_IMM(REG_SP, cd->stackframesize * 8, REG_A2);
-       M_ALD(REG_A3, REG_SP, (cd->stackframesize - 1) * 8);
        disp = dseg_add_functionptr(cd, codegen_start_native_call);
        M_ALD(REG_ITMP3, REG_PV, disp);
        M_JSR(REG_RA, REG_ITMP3);
        M_NOP; /* XXX fill me! */
 
+       /* remember class argument */
+
+       if (m->flags & ACC_STATIC)
+               M_MOV(REG_RESULT, REG_ITMP3);
+
        /* restore integer and float argument registers */
 
 #if SIZEOF_VOID_P == 8
@@ -3802,7 +3739,7 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
 
        /* copy or spill arguments to new locations */
 
-       for (i = md->paramcount - 1, j = i + nativeparams; i >= 0; i--, j--) {
+       for (i = md->paramcount - 1, j = i + skipparams; i >= 0; i--, j--) {
                t = md->params[i].type;
 
                if (IS_INT_LNG_TYPE(t)) {
@@ -3924,21 +3861,24 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
                }
        }
 
-       /* put class into second argument register */
+       /* Handle native Java methods. */
 
-       if (m->flags & ACC_STATIC) {
-               disp = dseg_add_address(cd, m->class);
-               M_ALD(REG_A1, REG_PV, disp);
-       }
+       if (m->flags & ACC_NATIVE) {
+               /* put class into second argument register */
 
-       /* put env into first argument register */
+               if (m->flags & ACC_STATIC)
+                       M_MOV(REG_ITMP3, REG_A1);
 
-       disp = dseg_add_address(cd, _Jv_env);
-       M_ALD(REG_A0, REG_PV, disp);
+               /* put env into first argument register */
 
-       /* do the native function call */
+               disp = dseg_add_address(cd, _Jv_env);
+               M_ALD(REG_A0, REG_PV, disp);
+       }
+
+       /* Call the native function. */
 
-       M_ALD(REG_ITMP3, REG_PV, funcdisp); /* load adress of native method       */
+       disp = dseg_add_functionptr(cd, f);
+       M_ALD(REG_ITMP3, REG_PV, disp);     /* load adress of native method       */
        M_JSR(REG_RA, REG_ITMP3);           /* call native method                 */
        M_NOP;                              /* delay slot                         */
 
@@ -3958,14 +3898,14 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
 #else
        case TYPE_INT:
        case TYPE_ADR:
-               M_IST(REG_RESULT, REG_SP, 1*4 + 0 * 8);
+               M_IST(REG_RESULT, REG_SP, 2*4 + 0 * 8);
                break;
        case TYPE_LNG:
-               M_LST(REG_RESULT_PACKED, REG_SP, 1*4 + 0 * 8);
+               M_LST(REG_RESULT_PACKED, REG_SP, 2*4 + 0 * 8);
                break;
        case TYPE_FLT:
        case TYPE_DBL:
-               M_DST(REG_FRESULT, REG_SP, 1*4 + 0 * 8);
+               M_DST(REG_FRESULT, REG_SP, 2*4 + 0 * 8);
                break;
 #endif
        case TYPE_VOID:
@@ -3979,7 +3919,8 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
 
        /* remove native stackframe info */
 
-       M_AADD_IMM(REG_SP, (cd->stackframesize - 1) * 8, REG_A0);
+       M_MOV(REG_SP, REG_A0);
+       M_MOV(REG_PV, REG_A1);
        disp = dseg_add_functionptr(cd, codegen_finish_native_call);
        M_ALD(REG_ITMP3, REG_PV, disp);
        M_JSR(REG_RA, REG_ITMP3);
@@ -4002,14 +3943,14 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
 #else
        case TYPE_INT:
        case TYPE_ADR:
-               M_ILD(REG_RESULT, REG_SP, 1*4 + 0 * 8);
+               M_ILD(REG_RESULT, REG_SP, 2*4 + 0 * 8);
                break;
        case TYPE_LNG:
-               M_LLD(REG_RESULT_PACKED, REG_SP, 1*4 + 0 * 8);
+               M_LLD(REG_RESULT_PACKED, REG_SP, 2*4 + 0 * 8);
                break;
        case TYPE_FLT:
        case TYPE_DBL:
-               M_DLD(REG_FRESULT, REG_SP, 1*4 + 0 * 8);
+               M_DLD(REG_FRESULT, REG_SP, 2*4 + 0 * 8);
                break;
 #endif
        case TYPE_VOID: