1 /* vm/jit/replace.h - on-stack replacement of methods
3 Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 Contact: cacao@cacaojvm.org
27 Authors: Edwin Steiner
39 /* forward typedefs ***********************************************************/
41 typedef struct rplpoint rplpoint;
42 typedef struct executionstate_t executionstate_t;
43 typedef struct sourcestate_t sourcestate_t;
44 typedef struct sourceframe_t sourceframe_t;
52 #include "vm/method.h"
53 #include "vm/jit/reg.h"
56 /*** structs *********************************************************/
58 typedef struct rplalloc rplalloc;
60 #define RPLALLOC_STACK -1
61 #define RPLALLOC_PARAM -2
62 #define RPLALLOC_SYNC -3
64 /* `rplalloc` is a compact struct for register allocation info */
66 /* XXX optimize this for space efficiency */
68 s4 index; /* local index, -1 for stack slot */
69 s4 regoff; /* register index / stack slot offset */
70 unsigned int flags:4; /* OR of (INMEMORY,...) */
71 int type:4; /* TYPE_... constant */
75 #error value of INMEMORY is too big to fit in rplalloc.flags
79 /* XXX what to do about overlapping rplpoints? */
80 #define RPLPOINT_TYPE_STD BBTYPE_STD
81 #define RPLPOINT_TYPE_EXH BBTYPE_EXH
82 #define RPLPOINT_TYPE_SBR BBTYPE_SBR
83 #define RPLPOINT_TYPE_CALL 3
84 #define RPLPOINT_TYPE_INLINE 4
85 #define RPLPOINT_TYPE_RETURN 5
88 /* An `rplpoint` represents a replacement point in a compiled method */
91 u1 *pc; /* machine code PC of this point */
92 u1 *outcode; /* pointer to replacement-out code */ /* XXX only for trappable rps */
93 methodinfo *method; /* source method this point is in */
94 rplpoint *target; /* target of the replacement */ /* XXX remove? */
95 codeinfo *code; /* codeinfo this point belongs to */ /* XXX unify with parent */
96 rplpoint *parent; /* rplpoint of the inlined body */ /* XXX unify with code */
97 rplalloc *regalloc; /* pointer to register index table */
98 u8 mcode; /* saved maching code for patching */ /* XXX only for trappable rps */
99 s4 id; /* id of the rplpoint within method */
100 s4 callsize; /* size of call code in bytes */
101 unsigned int regalloccount:24; /* number of local allocations */
102 unsigned int type:4; /* RPLPOINT_TYPE_... constant */
103 unsigned int flags:8; /* OR of RPLPOINT_... constants */
107 /* An `executionsstate` represents the state of a thread as it reached */
108 /* an replacement point or is about to enter one. */
110 struct executionstate_t {
111 u1 *pc; /* program counter */
112 u1 *sp; /* stack pointer within method */
113 u1 *pv; /* procedure value. NULL means */
114 /* search the AVL tree */
116 u8 intregs[INT_REG_CNT]; /* register values */
117 u8 fltregs[FLT_REG_CNT]; /* register values */
119 codeinfo *code; /* codeinfo corresponding to the pv */
123 struct sourceframe_t {
124 sourceframe_t *up; /* source frame above this one */
126 methodinfo *method; /* method this frame is in */
129 u8 *javastack; /* values of stack vars */
130 u1 *javastacktype; /* types of stack vars */
131 s4 javastackdepth; /* number of stack vars */
133 u8 *javalocals; /* values of javalocals */
134 u1 *javalocaltype; /* types of javalocals */
135 s4 javalocalcount; /* number of javalocals */
138 s4 syncslotcount; /* XXX do we need more than one? */
142 struct sourcestate_t {
143 sourceframe_t *frames; /* list of source frames, from bottom up */
147 /*** prototypes ********************************************************/
149 bool replace_create_replacement_points(jitdata *jd);
150 void replace_free_replacement_points(codeinfo *code);
152 void replace_activate_replacement_point(rplpoint *rp,rplpoint *target);
153 void replace_deactivate_replacement_point(rplpoint *rp);
154 void replace_activate(codeinfo *code,codeinfo *target);
156 void replace_me(rplpoint *rp,executionstate_t *es);
159 void replace_show_replacement_points(codeinfo *code);
160 void replace_replacement_point_println(rplpoint *rp, int depth);
161 void replace_executionstate_println(executionstate_t *es);
162 void replace_sourcestate_println(sourcestate_t *ss);
163 void replace_source_frame_println(sourceframe_t *frame);
166 /* machine dependent functions (code in ARCH_DIR/md.c) */
168 #if defined(ENABLE_JIT)
169 void md_patch_replacement_point(rplpoint *rp);
175 * These are local overrides for various environment variables in Emacs.
176 * Please do not remove this and leave it at the end of the file, where
177 * Emacs will automagically detect them.
178 * ---------------------------------------------------------------------
181 * indent-tabs-mode: t
185 * vim:noexpandtab:sw=4:ts=4: