Merged revisions 8245-8298 via svnmerge from
[cacao.git] / src / vm / jit / jit.h
index de45e2d222e0dfd9bc6412fc91291e66660c45c5..a9dff9f3391bcb7769141d9f76e3ecfcdc69fa3a 100644 (file)
@@ -1,6 +1,6 @@
 /* src/vm/jit/jit.h - code generation header
 
-   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: Andreas Krall
-            Reinhard Grafl
-            Christian Thalinger
-            Edwin Steiner
-
-   $Id: jit.h 6211 2006-12-16 22:53:24Z edwin $
+   $Id: jit.h 8295 2007-08-11 17:57:24Z michi $
 
 */
 
@@ -43,7 +36,6 @@ typedef struct jitdata jitdata;
 typedef struct stackelement stackelement;
 typedef stackelement *stackptr;
 typedef struct basicblock basicblock;
-typedef struct branchref branchref;
 typedef struct instruction instruction;
 typedef struct insinfo_inline insinfo_inline;
 typedef struct exception_entry exception_entry;
@@ -53,14 +45,12 @@ typedef struct exception_entry exception_entry;
 #include "vm/types.h"
 
 #include "toolbox/chain.h"
+
 #include "vm/global.h"
-#include "vm/method.h"
-#include "vm/references.h"
 #include "vm/resolve.h"
-#include "vm/statistics.h"
+
 #include "vm/jit/codegen-common.h"
 #include "vm/jit/reg.h"
-#include "vm/jit/stacktrace.h"
 #include "vm/jit/replace.h"
 
 #if defined(ENABLE_INLINING)
@@ -79,14 +69,38 @@ typedef struct exception_entry exception_entry;
 
 #include "vm/jit/verify/typeinfo.h"
 
+#include "vmcore/method.h"
+#include "vmcore/references.h"
+
+#if defined(ENABLE_STATISTICS)
+# include "vmcore/statistics.h"
+#endif
+
+
 /* common jit/codegen macros **************************************************/
 
 #if defined(ENABLE_STATISTICS)
 # define COUNT(x)        (x)++
-# define COUNT_SPILLS    count_spills++
+# define COUNT_SPILLS             /* use COUNT_(READ|WRITE)_SPILLS instead */
+# define COUNT_READ_SPILLS(var) \
+       switch(var->type) { \
+       case TYPE_FLT: count_spills_read_flt++; break; \
+       case TYPE_DBL: count_spills_read_dbl++; break; \
+       default: count_spills_read_ila++; break; \
+       }
+
+# define COUNT_WRITE_SPILLS(var) \
+       switch(var->type) { \
+       case TYPE_FLT: count_spills_write_flt++; break; \
+       case TYPE_DBL: count_spills_write_dbl++; break; \
+       default: count_spills_write_ila++; break; \
+       }
+
 #else
-# define COUNT(x)        /* nothing */
-# define COUNT_SPILLS    /* nothing */
+# define COUNT(x)                /* nothing */
+# define COUNT_SPILLS            /* nothing */
+# define COUNT_READ_SPILLS(x)    /* nothing */
+# define COUNT_WRITE_SPILLS(x)   /* nothing */
 #endif
 
 typedef struct interface_info interface_info;
@@ -116,8 +130,6 @@ struct jitdata {
 
        instruction     *instructions;    /* ICMDs, valid between parse and stack */
        basicblock      *basicblocks;     /* start of basic block list            */
-       s4              *basicblockindex; /* block index for each JavaPC          */
-                                      /* valid between parse and stack        */
        stackelement    *stack;           /* XXX should become stack.c internal   */
        s4               instructioncount;/* XXX remove this?                     */
        s4               basicblockcount; /* number of basic blocks               */
@@ -126,13 +138,15 @@ struct jitdata {
 
        varinfo         *var;             /* array of variables                   */
        s4               vartop;          /* next free index in var array         */
-    
+
        s4               varcount;        /* number of variables in var array     */
        s4               localcount;      /* number of locals at start of var ar. */
-    s4              *local_map;  /* internal structure to rename(de-coallesc) */
-                                               /* locals and keep the coalescing info for simplereg. */
-                           /* local_map[local_index * 5 + local_type] =          */
-                           /* new_index in rd->var or UNUSED                     */
+    s4              *local_map;       /* map for renaming (de-coallescing)    */
+                                        /* locals and keeping the coalescing info for simplereg. */
+                        /* local_map[javaindex * 5 + type] =                     */
+                        /*     >= 0......index into jd->var, or                  */
+                                        /*     UNUSED....this (javaindex,type) pair is not used  */
+
        s4               maxlocals;       /* max. number of javalocals            */
 
        interface_info  *interface_map;   /* interface variables (for simplereg)  */
@@ -263,8 +277,8 @@ struct stackelement {
 /* branch_target_t: used in TABLESWITCH tables */
 
 typedef union {
-    s4                         insindex; /* used between parse and stack      */
-    basicblock                *block;    /* used from stack analysis onwards  */
+    s4                         insindex; /* used in parse                     */
+    basicblock                *block;    /* valid after parse                 */
 } branch_target_t;
 
 /* lookup_target_t: used in LOOKUPSWITCH tables */
@@ -319,7 +333,7 @@ typedef union {
     float                     f;
     double                    d;
     void                     *anyptr;
-    java_objectheader        *stringconst;       /* for ACONST with string    */
+    java_handle_t            *stringconst;       /* for ACONST with string    */
     classref_or_classinfo     c;                 /* for ACONST with class     */
 } val_operand_t;
 
@@ -327,24 +341,25 @@ typedef union {
 
 typedef union {
        s4                         varindex;
-    basicblock                *block;       /* valid after stack analysis     */
+    basicblock                *block;       /* valid after parse              */
     branch_target_t           *table;       /* for TABLESWITCH                */
     lookup_target_t           *lookup;      /* for LOOKUPSWITCH               */
-    s4                         insindex;    /* used between parse and stack   */
+    s4                         insindex;    /* used in parse                  */
 } dst_operand_t;
 
 /*** flags (32 bits) ***/
 
-#define INS_FLAG_UNRESOLVED    0x01    /* contains unresolved field/meth/class*/
-#define INS_FLAG_CLASS         0x02    /* for ACONST, PUT*CONST with class    */
-#define INS_FLAG_ARRAY         0x04    /* for CHECKCAST/INSTANCEOF with array */
-#define INS_FLAG_CHECK         0x08    /* for *ALOAD|*ASTORE: check index     */
+#define INS_FLAG_BASICBLOCK    0x01    /* marks a basic block start           */
+#define INS_FLAG_UNRESOLVED    0x02    /* contains unresolved field/meth/class*/
+#define INS_FLAG_CLASS         0x04    /* for ACONST, PUT*CONST with class    */
+#define INS_FLAG_ARRAY         0x08    /* for CHECKCAST/INSTANCEOF with array */
+#define INS_FLAG_CHECK         0x10    /* for *ALOAD|*ASTORE: check index     */
                                        /* for BUILTIN: check exception        */
-#define INS_FLAG_KILL_PREV     0x02    /* for *STORE, invalidate prev local   */
-#define INS_FLAG_KILL_NEXT     0x04    /* for *STORE, invalidate next local   */
-#define INS_FLAG_RETADDR       0x08    /* for ASTORE: op is a returnAddress   */
+#define INS_FLAG_KILL_PREV     0x04    /* for *STORE, invalidate prev local   */
+#define INS_FLAG_KILL_NEXT     0x08    /* for *STORE, invalidate next local   */
+#define INS_FLAG_RETADDR       0x10    /* for ASTORE: op is a returnAddress   */
 
-#define INS_FLAG_ID_SHIFT      4
+#define INS_FLAG_ID_SHIFT      5
 #define INS_FLAG_ID_MASK       (~0 << INS_FLAG_ID_SHIFT)
 
 typedef union {
@@ -376,6 +391,9 @@ struct instruction {
 };
 
 
+#define INSTRUCTION_STARTS_BASICBLOCK(iptr) \
+       ((iptr)->flags.bits & INS_FLAG_BASICBLOCK)
+
 #define INSTRUCTION_IS_RESOLVED(iptr) \
        (!((iptr)->flags.bits & INS_FLAG_UNRESOLVED))
 
@@ -431,7 +449,9 @@ struct insinfo_inline {
        s4         *javalocals_end;   /* javalocals after inlined body            */
 
        /* fields set by replacement point creation ------------------------------*/
+#if defined(ENABLE_REPLACEMENT)
        rplpoint   *rp;             /* replacement point at INLINE_START          */
+#endif
 
        /* fields set by the codegen ---------------------------------------------*/
        s4          startmpc;       /* machine code offset of start of inlining   */
@@ -474,7 +494,7 @@ struct basicblock {
        instruction  *iinstr;       /* pointer to intermediate code instructions  */
 
        varinfo      *inlocals;     /* copy of locals on block entry              */
-       s4           *javalocals;   /* map from java locals to cacao variables    */
+       s4           *javalocals;   /* map from java locals to cacao variables[+] */
        s4           *invars;       /* array of in-variables at begin of block    */
        s4           *outvars;      /* array of out-variables at end of block     */
        s4            indepth;      /* stack depth at begin of basic block        */
@@ -500,6 +520,25 @@ struct basicblock {
        s4            mpc;          /* machine code pc at start of block          */
 };
 
+/* [+]...the javalocals array: This array is indexed by the javaindex (the    */
+/*       local variable index ocurring in the original bytecode). An element  */
+/*       javalocals[javaindex] encodes where to find the contents of the      */
+/*       original variable at this point in the program.                      */
+/*       There are three cases for javalocals[javaindex]:                     */
+/*           >= 0.......it's an index into the jd->var array, where the       */
+/*                      CACAO variable corresponding to the original local    */
+/*                      can be found.                                         */
+/*           UNUSED.....the original variable is not live at this point       */
+/*           < UNUSED...the original variable contains a returnAddress at     */
+/*                      this point. The number of the block to return to can  */
+/*                      be calculated using RETADDR_FROM_JAVALOCAL:           */
+/*                                                                            */
+/*                      javalocals[javaindex] == JAVALOCAL_FROM_RETADDR(nr)   */
+/*                      RETADDR_FROM_JAVALOCAL(javalocals[javaindex]) == nr   */
+
+#define JAVALOCAL_FROM_RETADDR(nr)  (UNUSED - (1 + (nr)))
+#define RETADDR_FROM_JAVALOCAL(jl)  (UNUSED - (1 + (jl)))
+
 
 /* Macro for initializing newly allocated basic block's. It does not
    need to zero fields, as we zero out the whole basic block array. */
@@ -513,14 +552,6 @@ struct basicblock {
        } while (0)
                        
 
-/* branchref *****************************************************************/
-
-struct branchref {
-       s4         branchpos;       /* patching position in code segment          */
-       branchref *next;            /* next element in branchref list             */
-};
-
-
 /* data-flow constants for the ICMD table ************************************/
 
 #define DF_0_TO_0      0
@@ -1289,21 +1320,6 @@ void jit_renumber_basicblocks(jitdata *jd);
 void jit_check_basicblock_numbers(jitdata *jd);
 #endif
 
-/* machine dependent functions */
-#if defined(ENABLE_JIT)
-void md_init(void);
-
-u1  *md_get_method_patch_address(u1 *ra, stackframeinfo *sfi, u1 *mptr);
-
-void md_cacheflush(u1 *addr, s4 nbytes);
-void md_icacheflush(u1 *addr, s4 nbytes);
-void md_dcacheflush(u1 *addr, s4 nbytes);
-#endif
-
-#if defined(ENABLE_INTRP)
-void intrp_md_init(void);
-#endif
-
 #endif /* _JIT_H */