* src/vm/jit/parse.cpp,
[cacao.git] / src / vm / jit / powerpc64 / codegen.c
index b20cceaebf152fbe710c755f737ac9865de297d8..6de89aaf0b6c5c16d65127a5f882d02e4e68a968 100644 (file)
@@ -1,9 +1,7 @@
 /* src/vm/jit/powerpc64/codegen.c - machine code generator for 64-bit PowerPC
 
-   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 "mm/memory.h"
 
-#include "native/localref.h"
-#include "native/native.h"
+#include "native/localref.hpp"
+#include "native/native.hpp"
 
-#include "threads/lock-common.h"
+#include "threads/lock.hpp"
 
-#include "vm/builtin.h"
-#include "vm/exceptions.h"
+#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/vm.hpp"
 
 #include "vm/jit/abi.h"
 #include "vm/jit/abi-asm.h"
-#include "vm/jit/md.h"
 #include "vm/jit/asmpart.h"
-#include "vm/jit/codegen-common.h"
+#include "vm/jit/codegen-common.hpp"
 #include "vm/jit/dseg.h"
-#include "vm/jit/emit-common.h"
-#include "vm/jit/jit.h"
-#include "vm/jit/parse.h"
-#include "vm/jit/patcher-common.h"
+#include "vm/jit/emit-common.hpp"
+#include "vm/jit/jit.hpp"
+#include "vm/jit/linenumbertable.hpp"
+#include "vm/jit/parse.hpp"
+#include "vm/jit/patcher-common.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 "vm/jit/replace.hpp"
+#include "vm/jit/stacktrace.hpp"
+#include "vm/jit/trap.h"
 
 #if defined(ENABLE_LSRA)
 # include "vm/jit/allocator/lsra.h"
@@ -91,7 +88,6 @@ bool codegen_emit(jitdata *jd)
        varinfo            *var;
        basicblock         *bptr;
        instruction        *iptr;
-       exception_entry    *ex;
        u2                  currentline;
        methodinfo         *lm;             /* local methodinfo for ICMD_INVOKE*  */
        unresolved_method  *um;
@@ -156,14 +152,7 @@ bool codegen_emit(jitdata *jd)
        (void) dseg_add_unique_address(cd, code);                      /* CodeinfoPointer */
        (void) dseg_add_unique_s4(cd, cd->stackframesize * 8);             /* FrameSize       */
 
-       /* 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.
-       */
-       /* XXX Remove this "offset by one". */
-
-       code->synchronizedoffset = (rd->memuse + 1) * 8;
+       code->synchronizedoffset = rd->memuse * 8;
 
        /* REMOVEME: We still need it for exception handling in assembler. */
 
@@ -175,19 +164,6 @@ bool codegen_emit(jitdata *jd)
        (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 (!code_is_leafmethod(code)) {
@@ -290,13 +266,13 @@ bool codegen_emit(jitdata *jd)
                /* get or test the lock object */
 
                if (m->flags & ACC_STATIC) {
-                       p = dseg_add_address(cd, &m->class->object.header);
+                       p = dseg_add_address(cd, &m->clazz->object.header);
                        M_ALD(REG_A0, REG_PV, p);
                }
                else {
                        M_TST(REG_A0);
                        M_BNE(1);
-                       M_ALD_INTERN(REG_ZERO, REG_ZERO, EXCEPTION_HARDWARE_NULLPOINTER);
+                       M_ALD_INTERN(REG_ZERO, REG_ZERO, TRAP_NullPointerException);
                }
 
                M_AST(REG_A0, REG_SP, s1 * 8);                      /* rd->memuse * 8 */
@@ -390,7 +366,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;
                        }
 
@@ -410,14 +386,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           */
@@ -1476,8 +1452,8 @@ bool codegen_emit(jitdata *jd)
                                fieldtype = fi->type;
                                disp      = dseg_add_address(cd, fi->value);
 
-                               if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
-                                       patcher_add_patch_ref(jd, PATCHER_initialize_class, fi->class, disp);
+                               if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->clazz)) {
+                                       patcher_add_patch_ref(jd, PATCHER_initialize_class, fi->clazz, disp);
                                }
                        }
 
@@ -1523,8 +1499,8 @@ bool codegen_emit(jitdata *jd)
                                fieldtype = fi->type;
                                disp      = dseg_add_address(cd, fi->value);
 
-                               if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
-                                       patcher_add_patch_ref(jd, PATCHER_initialize_class, fi->class, disp);
+                               if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->clazz)) {
+                                       patcher_add_patch_ref(jd, PATCHER_initialize_class, fi->clazz, disp);
                                }
                        }
 
@@ -2157,9 +2133,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 */
@@ -2226,10 +2202,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 */
@@ -2298,16 +2270,12 @@ gen_method:
 
                                        M_ALD(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
 
-                                       CODEGEN_CRITICAL_SECTION_START;
-
                                        M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
                                        M_ALD(REG_ITMP2, REG_PV, disp);
                                        if (s1 != REG_ITMP1) {
                                                M_ILD(REG_ITMP1, REG_ITMP2, OFFSET(vftbl_t, baseval));
                                                M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
 
-                                               CODEGEN_CRITICAL_SECTION_END;
-
                                                M_SUB(REG_ITMP3, REG_ITMP1, REG_ITMP3);
                                                M_EXTSW(REG_ITMP3, REG_ITMP3);
                                        } else {
@@ -2316,9 +2284,6 @@ gen_method:
                                                M_EXTSW(REG_ITMP3, REG_ITMP3);
                                                M_ALD(REG_ITMP2, REG_PV, disp);
                                                M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
-
-                                               CODEGEN_CRITICAL_SECTION_END;
-
                                        }
                                        M_CMPU(REG_ITMP3, REG_ITMP2);
                                        emit_classcast_check(cd, iptr, BRANCH_GT, REG_ITMP3, s1);
@@ -2395,10 +2360,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);
                        if (s1 == d) {
@@ -2475,14 +2436,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_SUB(REG_ITMP1, REG_ITMP3, REG_ITMP1);
                                M_EXTSW(REG_ITMP1, REG_ITMP1);
                                M_CMPU(REG_ITMP1, REG_ITMP2);
@@ -2577,8 +2534,6 @@ gen_method:
        } /* if (bptr -> flags >= BBREACHED) */
        } /* for basic block */
 
-       dseg_createlinenumbertable(cd);
-
        /* generate traps */
 
        emit_patcher_traps(jd);
@@ -2612,6 +2567,10 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int s
        code = jd->code;
        cd   = jd->cd;
 
+       /* Sanity check. */
+
+       assert(!code_is_leafmethod(code));
+
        /* set some variables */
 
        md = m->parseddesc;
@@ -2631,12 +2590,9 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int s
 
        (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 code */
 
@@ -2750,7 +2706,7 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int s
 
                /* put env into first argument register */
 
-               disp = dseg_add_unique_address(cd, _Jv_env);
+               disp = dseg_add_unique_address(cd, VM_get_jnienv());
                M_ALD(REG_A0, REG_PV, disp);
        }
 
@@ -2821,8 +2777,6 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int s
 }
 
 
-
-
 /*
  * These are local overrides for various environment variables in Emacs.
  * Please do not remove this and leave it at the end of the file, where