* src/vm/jit/parse.cpp,
[cacao.git] / src / vm / jit / m68k / codegen.c
index 2bf473d9ea8009440a62f33da59aa458db9fd3b4..a6ad45abeef0244cfe0ed521ba3f4dd8acdce5fb 100644 (file)
@@ -1,9 +1,7 @@
 /* src/vm/jit/m68k/codegen.c
 
-   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.
 
 #include <stdint.h>
 
 #include "md-abi.h"
-#include "md-os.h"
 
 #include "vm/types.h"
 #include "vm/jit/m68k/codegen.h"
 #include "vm/jit/m68k/emit.h"
 
 #include "mm/memory.h"
-#include "native/jni.h"
-#include "native/localref.h"
-#include "native/native.h"
 
-#include "threads/lock-common.h"
+#include "native/localref.hpp"
+#include "native/native.hpp"
 
-#include "vm/builtin.h"
-#include "vm/exceptions.h"
+#include "threads/lock.hpp"
+
+#include "vm/jit/builtin.hpp"
+#include "vm/exceptions.hpp"
 #include "vm/global.h"
-#include "vm/stringlocal.h"
-#include "vm/vm.h"
+#include "vm/loader.hpp"
+#include "vm/options.h"
+#include "vm/utf8.h"
+#include "vm/vm.hpp"
 
 #include "vm/jit/asmpart.h"
-#include "vm/jit/codegen-common.h"
-#include "vm/jit/patcher-common.h"
+#include "vm/jit/codegen-common.hpp"
+#include "vm/jit/patcher-common.hpp"
 #include "vm/jit/dseg.h"
-#include "vm/jit/linenumbertable.h"
-#include "vm/jit/emit-common.h"
-#include "vm/jit/jit.h"
+#include "vm/jit/linenumbertable.hpp"
+#include "vm/jit/emit-common.hpp"
+#include "vm/jit/jit.hpp"
 #include "vm/jit/abi.h"
-#include "vm/jit/parse.h"
+#include "vm/jit/parse.hpp"
 #include "vm/jit/reg.h"
-#include "vm/jit/replace.h"
-#include "vm/jit/stacktrace.h"
-
-#include "vmcore/loader.h"
-#include "vmcore/options.h"
-#include "vmcore/utf8.h"
+#include "vm/jit/replace.hpp"
+#include "vm/jit/stacktrace.hpp"
+#include "vm/jit/trap.h"
 
 
 bool codegen_emit(jitdata *jd) 
@@ -254,13 +250,13 @@ bool codegen_emit(jitdata *jd)
        /* call lock_monitor_enter function */
        if (checksync && code_is_synchronized(code))    {
                if (m->flags & ACC_STATIC)      {
-                       M_AMOV_IMM((&m->class->object.header), REG_ATMP1);
+                       M_AMOV_IMM((&m->clazz->object.header), REG_ATMP1);
                } else  {
                        /* for non-static case the first arg is the object */
                        M_ALD(REG_ATMP1, REG_SP, cd->stackframesize + 4);
                        M_ATST(REG_ATMP1);
                        M_BNE(2);
-                       M_TRAP(M68K_EXCEPTION_HARDWARE_NULLPOINTER);
+                       M_TRAP(TRAP_NullPointerException);
                }
 
                M_AST(REG_ATMP1, REG_SP, rd->memuse * 8);
@@ -1119,8 +1115,8 @@ bool codegen_emit(jitdata *jd)
                                fieldtype = fi->type;
                                disp      = (intptr_t) fi->value;
 
-                               if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
-                                       patcher_add_patch_ref(jd, PATCHER_initialize_class, fi->class,
+                               if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->clazz)) {
+                                       patcher_add_patch_ref(jd, PATCHER_initialize_class, fi->clazz,
                                                                                0);
                                }
                        }
@@ -1173,8 +1169,8 @@ bool codegen_emit(jitdata *jd)
                                fieldtype = fi->type;
                                disp      = (intptr_t) fi->value;
 
-                               if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class))
-                                       patcher_add_patch_ref(jd, PATCHER_initialize_class, fi->class,
+                               if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->clazz))
+                                       patcher_add_patch_ref(jd, PATCHER_initialize_class, fi->clazz,
                                                                                0);
                        }
                
@@ -1734,8 +1730,8 @@ bool codegen_emit(jitdata *jd)
                                                s1 = 0;
                                                s2 = 0;
                                        } else {
-                                               s1 = OFFSET(vftbl_t, interfacetable[0]) - sizeof(methodptr*) * lm->class->index;
-                                               s2 = sizeof(methodptr) * (lm - lm->class->methods);
+                                               s1 = OFFSET(vftbl_t, interfacetable[0]) - sizeof(methodptr*) * lm->clazz->index;
+                                               s2 = sizeof(methodptr) * (lm - lm->clazz->methods);
                                        }
                                        /* load object pointer (==argument 0) */
                                        M_ALD(REG_ATMP1, REG_SP, 0);
@@ -1996,9 +1992,6 @@ nowperformreturn:
                                superindex = super->index;
                        }
                        
-                       if ((super == NULL) || !(super->flags & ACC_INTERFACE))
-                               CODEGEN_CRITICAL_SECTION_NEW;
-
                        s1 = emit_load_s1(jd, iptr, REG_ATMP1);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
 
@@ -2062,14 +2055,10 @@ nowperformreturn:
 
                                M_ALD(REG_ATMP1, s1, OFFSET(java_object_t, vftbl));
 
-                               CODEGEN_CRITICAL_SECTION_START;
-
                                M_ILD(REG_ITMP1, REG_ATMP1, OFFSET(vftbl_t, baseval));
                                M_ILD(REG_ITMP3, REG_ATMP2, OFFSET(vftbl_t, baseval));
                                M_ILD(REG_ITMP2, REG_ATMP2, OFFSET(vftbl_t, diffval));
 
-                               CODEGEN_CRITICAL_SECTION_END;
-
                                M_ISUB(REG_ITMP3, REG_ITMP1);
                                M_ICMP(REG_ITMP2, REG_ITMP1);
                                M_BHI(4);
@@ -2121,9 +2110,6 @@ nowperformreturn:
                                        superindex = super->index;
                                }
 
-                               if ((super == NULL) || !(super->flags & ACC_INTERFACE))
-                                       CODEGEN_CRITICAL_SECTION_NEW;
-
                                s1 = emit_load_s1(jd, iptr, REG_ATMP1);
                                assert(VAROP(iptr->s1)->type == TYPE_ADR);
 
@@ -2183,14 +2169,10 @@ nowperformreturn:
 
                                        M_ALD(REG_ATMP2, s1, OFFSET(java_object_t, vftbl));
 
-                                       CODEGEN_CRITICAL_SECTION_START;
-
                                        M_ILD(REG_ITMP3, REG_ATMP2, OFFSET(vftbl_t, baseval));  /* REG_ITMP3 == sub->vftbl->baseval */
                                        M_ILD(REG_ITMP1, REG_ATMP3, OFFSET(vftbl_t, baseval));
                                        M_ILD(REG_ITMP2, REG_ATMP3, OFFSET(vftbl_t, diffval));
 
-                                       CODEGEN_CRITICAL_SECTION_END;
-
                                        M_ISUB(REG_ITMP1, REG_ITMP3);
                                        M_ICMP(REG_ITMP2, REG_ITMP3);   /* XXX was CMPU */
 
@@ -2412,27 +2394,9 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int s
        (void) dseg_add_unique_s4(cd, 0);                              /* IntSave         */
        (void) dseg_add_unique_s4(cd, 0);                              /* FltSave         */
 
-       /* print call trace */
-#if 0
-#if !defined(NDEBUG)
-       if (JITDATA_HAS_FLAG_VERBOSECALL(jd)) {
-               emit_verbosecall_enter(jd);
-       }
-#endif
-#endif
-
        /* generate code */
        M_AADD_IMM(-(cd->stackframesize*8), REG_SP);
 
-       /* get function address (this must happen before the stackframeinfo) */
-       if (f == NULL)  {
-               patcher_add_patch_ref(jd, PATCHER_resolve_native_function, m, 0);
-       }
-
-       M_AMOV_IMM(f, REG_ATMP2); /* do not move this line, the patcher is needed */
-
-       M_AST(REG_ATMP2, REG_SP, 4 * 4);
-
        /* put arguments for codegen_start_native_call onto stack */
        /* void codegen_start_native_call(u1 *datasp, u1 *pv, u1 *sp, u1 *ra) */
        
@@ -2450,9 +2414,6 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int s
        if (m->flags & ACC_STATIC)
                M_INT2ADRMOVE(REG_RESULT, REG_ATMP3);
 
-       /* load function pointer */
-       M_ALD(REG_ATMP2, REG_SP, 4 * 4);
-
        /* copy arguments into stackframe */
        for (i = md->paramcount -1, j = i + skipparams; i >= 0; --i, --j)       {
                t = md->paramtypes[i].type;
@@ -2478,11 +2439,12 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int s
                        M_AST(REG_ATMP3, REG_SP, 1 * 4);
 
                /* env ist first argument */
-               M_AMOV_IMM(_Jv_env, REG_ATMP1);
+               M_AMOV_IMM(VM_get_jnienv(), REG_ATMP1);
                M_AST(REG_ATMP1, REG_SP, 0 * 4);
        }
 
        /* call the native function */
+       M_AMOV_IMM(f, REG_ATMP2);
        M_JSR(REG_ATMP2);
 
        /* save return value */
@@ -2503,14 +2465,7 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int s
 
                default: assert(0);
        }
-#if 0  
-       /* print call trace */
-#if ! defined(NDEBUG)
-       if (JITDATA_HAS_FLAG_VERBOSECALL(jd)) {
-               emit_verbosecall_exit(jd);
-       }
-#endif
-#endif
+
        /* remove native stackframe info */
        /* therefore we call: java_objectheader *codegen_finish_native_call(u1 *datasp) */
 
@@ -2568,9 +2523,6 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int s
 
        /* should never be reached from within jit code*/
        M_JSR_IMM(0);
-
-       /* generate patcher stub call code */
-       emit_patcher_traps(jd);
 }