Merged revisions 7940-8026 via svnmerge from
[cacao.git] / src / vm / jit / replace.h
index 8d8a06a3a94d8a70554b0c90849a6d4ef79434a5..dd3e32bc387e428857b220cd9abb492abdb046f1 100644 (file)
@@ -1,6 +1,6 @@
-/* vm/jit/replace.h - on-stack replacement of methods
+/* src/vm/jit/replace.h - on-stack replacement of methods
 
-   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:
-
    $Id$
 
 */
 #ifndef _REPLACE_H
 #define _REPLACE_H
 
+#include "config.h"
+#include "vm/types.h"
+
+#if !defined(ENABLE_REPLACEMENT)
+
+/*** macros for the codegens (disabled version) ************************/
+
+#define REPLACEMENT_POINTS_INIT(cd, jd)
+#define REPLACEMENT_POINTS_RESET(cd, jd)
+#define REPLACEMENT_POINT_BLOCK_START(cd, bptr)
+#define REPLACEMENT_POINT_INLINE_START(cd, iptr)
+#define REPLACEMENT_POINT_INLINE_BODY(cd, iptr)
+#define REPLACEMENT_POINT_RETURN(cd, iptr)
+#define REPLACEMENT_POINT_INVOKE(cd, iptr)
+#define REPLACEMENT_POINT_INVOKE_RETURN(cd, iptr)
+#define REPLACEMENT_EMIT_STUBS(jd)
+
+#else /* defined(ENABLE_REPLACEMENT) */
+
 /* forward typedefs ***********************************************************/
 
+typedef struct rplalloc rplalloc;
 typedef struct rplpoint rplpoint;
 typedef struct executionstate_t executionstate_t;
 typedef struct sourcestate_t sourcestate_t;
 typedef struct sourceframe_t sourceframe_t;
 typedef struct replace_safestack_t replace_safestack_t;
-
-#include "config.h"
-#include "vm/types.h"
+typedef union  replace_val_t replace_val_t;
 
 #include "arch.h"
 #include "md-abi.h"
 
-#include "vm/method.h"
 #include "vm/jit/reg.h"
+#include "vm/jit/stacktrace.h"
+
+#include "vmcore/method.h"
 
 
 /* alignment for the safe stack used during replacement */
@@ -66,8 +80,6 @@ typedef struct replace_safestack_t replace_safestack_t;
 
 /*** structs *********************************************************/
 
-typedef struct rplalloc rplalloc;
-
 #define RPLALLOC_STACK  -1
 #define RPLALLOC_PARAM  -2
 #define RPLALLOC_SYNC   -3
@@ -98,8 +110,9 @@ struct rplalloc {
 #define RPLPOINT_TYPE_RETURN  5
 #define RPLPOINT_TYPE_BODY    6
 
-#define RPLPOINT_FLAG_NOTRAP  0x01  /* rplpoint cannot be trapped */
-#define RPLPOINT_FLAG_ACTIVE  0x08  /* trap is active             */
+#define RPLPOINT_FLAG_NOTRAP     0x01  /* rplpoint cannot be trapped */
+#define RPLPOINT_FLAG_COUNTDOWN  0x02  /* count down hits            */
+#define RPLPOINT_FLAG_ACTIVE     0x08  /* trap is active             */
 
 
 #if !defined(NDEBUG)
@@ -126,6 +139,20 @@ struct rplpoint {
 };
 
 
+union replace_val_t {
+       s4                 i;
+       s8                 l;
+       ptrint             p;
+       struct {
+               u4 lo;
+               u4 hi;
+       }                  words;
+       float              f;
+       double             d;
+       java_objectheader *a;
+};
+
+
 /* An `executionsstate` represents the state of a thread as it reached */
 /* an replacement point or is about to enter one.                      */
 
@@ -135,8 +162,11 @@ struct executionstate_t {
        u1           *pv;                   /* procedure value. NULL means */
                                            /* search the AVL tree         */
 
-       u8            intregs[INT_REG_CNT];             /* register values */
-       u8            fltregs[FLT_REG_CNT];             /* register values */
+       ptrint        intregs[INT_REG_CNT];             /* register values */
+       double        fltregs[FLT_REG_CNT];             /* register values */
+#if defined(HAS_ADDRESS_REGISTER_FILE)
+       ptrint        adrregs[ADR_REG_CNT];             /* register values */
+#endif
 
        codeinfo     *code;            /* codeinfo corresponding to the pv */
 };
@@ -149,26 +179,40 @@ struct sourceframe_t {
        s4             id;
        s4             type;
 
-       u8             instance;
+       /* values */
+       replace_val_t  instance;
 
-       u8            *javastack;                  /* values of stack vars */
+       replace_val_t *javastack;                  /* values of stack vars */
        u1            *javastacktype;              /*  types of stack vars */
        s4             javastackdepth;             /* number of stack vars */
 
-       u8            *javalocals;                 /* values of javalocals */
+       replace_val_t *javalocals;                 /* values of javalocals */
        u1            *javalocaltype;              /*  types of javalocals */
        s4             javalocalcount;             /* number of javalocals */
 
-       u8            *syncslots;
+       replace_val_t *syncslots;
        s4             syncslotcount; /* XXX do we need more than one? */
 
+       /* mapping info */
        rplpoint      *fromrp;         /* rplpoint used to read this frame */
        codeinfo      *fromcode;              /* code this frame was using */
-
        rplpoint      *torp;          /* rplpoint this frame was mapped to */
        codeinfo      *tocode;            /* code this frame was mapped to */
+
+       /* info for native frames */
+       stackframeinfo *sfi;      /* sfi for native frames, otherwise NULL */
+       s4             nativeframesize;    /* size (bytes) of native frame */
+       u1            *nativepc;
+       ptrint         nativesavint[INT_SAV_CNT]; /* XXX temporary */
+       double         nativesavflt[FLT_REG_CNT]; /* XXX temporary */
+#if defined(HAS_ADDRESS_REGISTER_FILE)
+       ptrint         nativesavadr[ADR_SAV_CNT]; /* XXX temporary */
+#endif
 };
 
+#define REPLACE_IS_NATIVE_FRAME(frame)  ((frame)->sfi != NULL)
+#define REPLACE_IS_JAVA_FRAME(frame)    ((frame)->sfi == NULL)
+
 
 struct sourcestate_t {
        sourceframe_t *frames;    /* list of source frames, from bottom up */
@@ -204,6 +248,9 @@ struct replace_safestack_t {
         return false;                                                \
     (cd)->replacementpoint = (jd)->code->rplpoints;
 
+#define REPLACEMENT_POINTS_RESET(cd, jd)                             \
+    (cd)->replacementpoint = (jd)->code->rplpoints;
+
 #define REPLACEMENT_POINT_BLOCK_START(cd, bptr)                      \
     if ((bptr)->bitflags & BBFLAG_REPLACEMENT)                       \
         codegen_set_replacement_point((cd) RPLPOINT_CHECK_BB(bptr));
@@ -254,7 +301,10 @@ void md_patch_replacement_point(codeinfo *code, s4 index, rplpoint *rp,
                                                                u1 *savedmcode);
 #endif
 
-#endif
+#endif /* defined(ENABLE_REPLACEMENT) */
+
+#endif /* _REPLACE_H */
+
 
 /*
  * These are local overrides for various environment variables in Emacs.