* Removed all Id tags.
[cacao.git] / src / vm / jit / code.c
index f5b296a40163b8520b69bb634e576f6c139d313b..e02bdcadf1f796e5a805e2bcfe13fd3f19500660 100644 (file)
@@ -1,6 +1,6 @@
 /* src/vm/jit/code.c - codeinfo struct for representing compiled code
 
-   Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+   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
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Contact: cacao@cacaojvm.org
+*/
 
-   Authors: Edwin Steiner
 
-   Changes: Christian Thalinger
+#include "config.h"
 
-   $Id$
+#include <assert.h>
 
-*/
+#include "vm/types.h"
 
+#include "arch.h"
 
-#include "config.h"
-#include "vm/types.h"
+#include "mm/memory.h"
 
-#include <assert.h>
+#if defined(ENABLE_THREADS)
+# include "threads/native/lock.h"
+#endif
 
 #include "vm/jit/code.h"
-#include "mm/memory.h"
-#include "vm/options.h"
-#include "arch.h"
+#include "vm/jit/codegen-common.h"
+#include "vm/jit/methodheader.h"
+#include "vm/jit/patcher-common.h"
+
+#include "vmcore/options.h"
+
+
+/* code_init *******************************************************************
+
+   Initialize the code-subsystem.
+
+*******************************************************************************/
+
+bool code_init(void)
+{
+       /* check for offset of code->m == 0 (see comment in code.h) */
+
+       assert(OFFSET(codeinfo, m) == 0);
+
+       /* everything's ok */
+
+       return true;
+}
 
 
 /* code_codeinfo_new ***********************************************************
@@ -53,8 +74,7 @@
 
    The following fields are set in codeinfo:
        m
-          isleafmethod
-   all other fields are zeroed
+       patchers
 
    RETURN VALUE:
        a new, initialized codeinfo, or
@@ -70,6 +90,8 @@ codeinfo *code_codeinfo_new(methodinfo *m)
 
        code->m = m;
 
+       patcher_list_create(code);
+
 #if defined(ENABLE_STATISTICS)
        if (opt_stat)
                size_codeinfo += sizeof(codeinfo);
@@ -79,6 +101,52 @@ codeinfo *code_codeinfo_new(methodinfo *m)
 }
 
 
+/* code_find_codeinfo_for_pc ***************************************************
+
+   Return the codeinfo for the compilation unit that contains the
+   given PC.
+
+   IN:
+       pc...............machine code position
+
+   RETURN VALUE:
+       the codeinfo * for the given PC
+
+*******************************************************************************/
+
+codeinfo *code_find_codeinfo_for_pc(u1 *pc)
+{
+       u1 *pv;
+
+       pv = codegen_get_pv_from_pc(pc);
+       assert(pv);
+
+       return *(codeinfo **)(pv + CodeinfoPointer);
+}
+
+
+/* code_get_methodinfo_for_pv **************************************************
+
+   Return the methodinfo for the given PV.
+
+   IN:
+       pv...............PV
+
+   RETURN VALUE:
+       the methodinfo *
+
+*******************************************************************************/
+
+methodinfo *code_get_methodinfo_for_pv(u1 *pv)
+{
+       codeinfo *code;
+
+       code = *((codeinfo **) (pv + CodeinfoPointer));
+
+       return code->m;
+}
+
+
 /* code_get_sync_slot_count ****************************************************
 
    Return the number of stack slots used for storing the synchronized object
@@ -93,6 +161,7 @@ codeinfo *code_codeinfo_new(methodinfo *m)
   
 *******************************************************************************/
 
+#if defined(ENABLE_REPLACEMENT)
 int code_get_sync_slot_count(codeinfo *code)
 {
 #ifdef ENABLE_THREADS
@@ -127,70 +196,7 @@ int code_get_sync_slot_count(codeinfo *code)
 
 #endif /* ENABLE_THREADS */
 }
-
-
-/* code_get_stack_frame_size ***************************************************
-
-   Return the number of stack slots that the stack frame of the given code
-   comprises.
-
-   IMPORTANT: The return value does *not* include the saved return address 
-              slot, although it is part of non-leaf stack frames on RISC
-                         architectures. The rationale behind this is that the saved
-                         return address is never moved or changed by replacement, and
-                         this way CISC and RISC architectures can be treated the same.
-                         (See also doc/stack_frames.txt.)
-   
-   IN:
-       code.............the codeinfo of the code in question
-                           (must be != NULL)
-
-   RETURN VALUE:
-       the number of stack slots
-  
-*******************************************************************************/
-
-int code_get_stack_frame_size(codeinfo *code)
-{
-       int count;
-       
-       assert(code);
-
-       /* slots allocated by register allocator plus saved registers */
-
-#ifdef HAS_4BYTE_STACKSLOT
-       count = code->memuse + code->savedintcount + 2*code->savedfltcount;
-#else
-       count = code->memuse + code->savedintcount + code->savedfltcount;
-#endif
-
-       /* add slots needed in synchronized methods */
-
-       count += code_get_sync_slot_count(code);
-
-       /* keep stack aligned */
-
-#if defined(__X86_64__)
-       /* the x86_64 codegen only aligns the stack in non-leaf methods */
-       if (!code->isleafmethod || opt_verbosecall)
-               count |= 1; /* even when return address is added */
-#endif
-
-       /* XXX align stack on alpha */
-#if defined(__MIPS__)
-       if (code->isleafmethod)
-               count = (count + 1) & ~1;
-       else
-               count |= 1; /* even when return address is added */
-#endif
-
-#if defined(__POWERPC__)
-       /* keep stack 16-byte aligned */
-       count = (count + 3) & ~3;
-#endif
-
-       return count;
-}
+#endif /* defined(ENABLE_REPLACEMENT) */
 
 
 /* code_codeinfo_free **********************************************************
@@ -210,7 +216,11 @@ void code_codeinfo_free(codeinfo *code)
        if (code->mcode != NULL)
                CFREE((void *) (ptrint) code->mcode, code->mcodelength);
 
+       patcher_list_free(code);
+
+#if defined(ENABLE_REPLACEMENT)
        replace_free_replacement_points(code);
+#endif
 
        FREE(code, codeinfo);