Merged with tip.
[cacao.git] / src / vm / jit / code.h
index aab97eaf7ea9a8f28a47eea2b915bb574380557f..375379725984bfcec636ae7f6c9d29591a1a7de4 100644 (file)
@@ -1,9 +1,7 @@
 /* src/vm/jit/code.h - codeinfo struct for representing compiled code
 
-   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.
 
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id$
-
 */
 
 
 #ifndef _CODE_H
 #define _CODE_H
 
-/* forward typedefs ***********************************************************/
+#include "config.h"
 
-typedef struct codeinfo codeinfo;
+#include <assert.h>
+#include <stdint.h>
 
-#include "config.h"
 #include "vm/types.h"
 
+#include "toolbox/list.h"
+
 #include "vm/global.h"
 
+#include "vm/jit/exceptiontable.h"
+#include "vm/jit/linenumbertable.h"
+#include "vm/jit/methodheader.h"
 #include "vm/jit/replace.h"
 
 #include "vmcore/method.h"
@@ -46,8 +47,10 @@ typedef struct codeinfo codeinfo;
 
 /* constants ******************************************************************/
 
-#define CODE_FLAG_INVALID     0x0001
-#define CODE_FLAG_LEAFMETHOD  0x0002
+#define CODE_FLAG_INVALID         0x0001
+#define CODE_FLAG_LEAFMETHOD      0x0002
+#define CODE_FLAG_SYNCHRONIZED    0x0004
+#define CODE_FLAG_TLH             0x0008
 
 
 /* codeinfo *******************************************************************
@@ -65,61 +68,156 @@ struct codeinfo {
        methodinfo   *m;                    /* method this is a realization of    */
        codeinfo     *prev;                 /* previous codeinfo of this method   */
 
-       u4            codeflags;            /* or of CODE_FLAG_ constants         */
+       uint32_t      flags;                /* OR of CODE_FLAG_ constants         */
 
        u1            optlevel;             /* optimization level of this code    */
        s4            basicblockcount;      /* number of basic blocks             */
 
+       int32_t       synchronizedoffset;   /* stack offset of synchronized obj.  */
+
        /* machine code */
        u1           *mcode;                /* pointer to machine code            */
        u1           *entrypoint;           /* machine code entry point           */
        s4            mcodelength;          /* length of generated machine code   */
 
+       exceptiontable_t  *exceptiontable;
+       linenumbertable_t *linenumbertable;
+
+       /* patcher list */
+       list_t       *patchers;
+
        /* replacement */                                   
+       s4            stackframesize;       /* size of the stackframe in slots    */
+
 #if defined(ENABLE_REPLACEMENT)
        rplpoint     *rplpoints;            /* replacement points                 */
        rplalloc     *regalloc;             /* register allocation info           */
-       u1           *replacementstubs;     /* beginning of replacement stubs     */
        s4            rplpointcount;        /* number of replacement points       */
        s4            globalcount;          /* number of global allocations       */
        s4            regalloccount;        /* number of total allocations        */
        s4            memuse;               /* number of arg + local slots        */
-       s4            stackframesize;       /* size of the stackframe in slots    */
        u1            savedintcount;        /* number of callee saved int regs    */
        u1            savedfltcount;        /* number of callee saved flt regs    */
+# if defined(HAS_ADDRESS_REGISTER_FILE)
+       u1            savedadrcount;        /* number of callee saved adr regs    */
+# endif
        u1           *savedmcode;           /* saved code under patches           */
-#endif /* defined(ENABLE_REPLACEMENT) */
+#endif
 
+#if defined(ENABLE_PROFILING)
        u4            frequency;            /* number of method invocations       */
        u4           *bbfrequency;                  
        s8            cycles;               /* number of cpu cycles               */
+#endif
 };
 
 
-/* macros *********************************************************************/
+/* inline functions ***********************************************************/
+
+/* code_xxx_invalid ************************************************************
+
+   Functions for CODE_FLAG_INVALID.
+
+*******************************************************************************/
+
+inline static int code_is_invalid(codeinfo *code)
+{
+       return (code->flags & CODE_FLAG_INVALID);
+}
+
+inline static void code_flag_invalid(codeinfo *code)
+{
+       code->flags |= CODE_FLAG_INVALID;
+}
+
+inline static void code_unflag_invalid(codeinfo *code)
+{
+       code->flags &= ~CODE_FLAG_INVALID;
+}
+
+
+/* code_xxx_leafmethod *********************************************************
+
+   Functions for CODE_FLAG_LEAFMETHOD.
+
+*******************************************************************************/
+
+inline static int code_is_leafmethod(codeinfo *code)
+{
+       return (code->flags & CODE_FLAG_LEAFMETHOD);
+}
+
+inline static void code_flag_leafmethod(codeinfo *code)
+{
+       code->flags |= CODE_FLAG_LEAFMETHOD;
+}
+
+inline static void code_unflag_leafmethod(codeinfo *code)
+{
+       code->flags &= ~CODE_FLAG_LEAFMETHOD;
+}
+
+
+/* code_xxx_synchronized *******************************************************
+
+   Functions for CODE_FLAG_SYNCHRONIZED.
+
+*******************************************************************************/
+
+inline static int code_is_synchronized(codeinfo *code)
+{
+       return (code->flags & CODE_FLAG_SYNCHRONIZED);
+}
+
+inline static void code_flag_synchronized(codeinfo *code)
+{
+       code->flags |= CODE_FLAG_SYNCHRONIZED;
+}
 
-#define CODE_IS_VALID(code)       (!((code)->codeflags & CODE_FLAG_INVALID))
-#define CODE_IS_INVALID(code)     ((code)->codeflags & CODE_FLAG_INVALID)
-#define CODE_IS_LEAFMETHOD(code)  ((code)->codeflags & CODE_FLAG_LEAFMETHOD)
+inline static void code_unflag_synchronized(codeinfo *code)
+{
+       code->flags &= ~CODE_FLAG_SYNCHRONIZED;
+}
 
-#define CODE_SETFLAG_INVALID(code)                                   \
-            ((code)->codeflags |= CODE_FLAG_INVALID)
-#define CODE_SETFLAG_LEAFMETHOD(code)                                \
-            ((code)->codeflags |= CODE_FLAG_LEAFMETHOD)
+
+/* code_get_codeinfo_for_pv ****************************************************
+
+   Return the codeinfo for the given PV.
+
+   IN:
+       pv...............PV
+
+   RETURN VALUE:
+       the codeinfo *
+
+*******************************************************************************/
+
+inline static codeinfo *code_get_codeinfo_for_pv(void *pv)
+{
+       codeinfo *code;
+
+       assert(pv != NULL);
+
+       code = *((codeinfo **) (((uintptr_t) pv) + CodeinfoPointer));
+
+       return code;
+}
 
 
 /* function prototypes ********************************************************/
 
-bool code_init(void);
+void code_init(void);
 
 codeinfo *code_codeinfo_new(methodinfo *m);
 void code_codeinfo_free(codeinfo *code);
 
-codeinfo *code_find_codeinfo_for_pc(u1 *pc);
+codeinfo *code_find_codeinfo_for_pc(void *pc);
+codeinfo *code_find_codeinfo_for_pc_nocheck(void *pc);
+
+methodinfo *code_get_methodinfo_for_pv(void *pv);
 
 #if defined(ENABLE_REPLACEMENT)
 int code_get_sync_slot_count(codeinfo *code);
-int code_get_stack_frame_size(codeinfo *code);
 #endif /* defined(ENABLE_REPLACEMENT) */
 
 void code_free_code_of_method(methodinfo *m);