1 /* src/vm/jit/replace.h - on-stack replacement of methods
3 Copyright (C) 1996-2005, 2006, 2007 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
34 #if !defined(ENABLE_REPLACEMENT)
36 /*** macros for the codegens (disabled version) ************************/
38 #define REPLACEMENT_POINTS_INIT(cd, jd)
39 #define REPLACEMENT_POINTS_RESET(cd, jd)
40 #define REPLACEMENT_POINT_BLOCK_START(cd, bptr)
41 #define REPLACEMENT_POINT_INLINE_START(cd, iptr)
42 #define REPLACEMENT_POINT_INLINE_BODY(cd, iptr)
43 #define REPLACEMENT_POINT_RETURN(cd, iptr)
44 #define REPLACEMENT_POINT_INVOKE(cd, iptr)
45 #define REPLACEMENT_POINT_INVOKE_RETURN(cd, iptr)
46 #define REPLACEMENT_POINT_FORGC_BUILTIN(cd, iptr)
47 #define REPLACEMENT_POINT_FORGC_BUILTIN_RETURN(cd, iptr)
49 #else /* defined(ENABLE_REPLACEMENT) */
51 /* forward typedefs ***********************************************************/
53 typedef struct rplalloc rplalloc;
54 typedef struct rplpoint rplpoint;
55 typedef struct sourcestate_t sourcestate_t;
56 typedef struct sourceframe_t sourceframe_t;
57 typedef union replace_val_t replace_val_t;
62 #include "vm/jit/reg.h"
63 #include "vm/jit/stacktrace.h"
65 #include "vmcore/method.h"
68 /*** structs *********************************************************/
70 #define RPLALLOC_STACK -1
71 #define RPLALLOC_PARAM -2
72 #define RPLALLOC_SYNC -3
74 /* `rplalloc` is a compact struct for register allocation info */
76 /* XXX optimize this for space efficiency */
78 s4 index; /* local index, -1 for stack slot */
79 s4 regoff; /* register index / stack slot offset */
80 unsigned int flags:4; /* OR of (INMEMORY,...) */
81 unsigned int type:4; /* TYPE_... constant */
85 #error value of INMEMORY is too big to fit in rplalloc.flags
89 /* XXX what to do about overlapping rplpoints? */
90 /* CAUTION: Do not change the numerical values. These are used as */
91 /* indices into replace_normalize_type_map. */
92 #define RPLPOINT_TYPE_STD BBTYPE_STD
93 #define RPLPOINT_TYPE_EXH BBTYPE_EXH
94 #define RPLPOINT_TYPE_SBR BBTYPE_SBR
95 #define RPLPOINT_TYPE_CALL 3
96 #define RPLPOINT_TYPE_INLINE 4
97 #define RPLPOINT_TYPE_RETURN 5
98 #define RPLPOINT_TYPE_BODY 6
100 #define RPLPOINT_FLAG_NOTRAP 0x01 /* rplpoint cannot be trapped */
101 #define RPLPOINT_FLAG_COUNTDOWN 0x02 /* count down hits */
102 #define RPLPOINT_FLAG_ACTIVE 0x08 /* trap is active */
106 #define RPLPOINT_CHECK(type) , RPLPOINT_TYPE_##type
107 #define RPLPOINT_CHECK_BB(bptr) , (bptr)->type
109 #define RPLPOINT_CHECK(type)
110 #define RPLPOINT_CHECK_BB(bptr)
114 /* An `rplpoint` represents a replacement point in a compiled method */
117 u1 *pc; /* machine code PC of this point */
118 methodinfo *method; /* source method this point is in */
119 rplpoint *parent; /* rplpoint of the inlined body */ /* XXX unify with code */
120 rplalloc *regalloc; /* pointer to register index table */
121 s4 id; /* id of the rplpoint within method */
122 s4 callsize; /* size of call code in bytes */
123 unsigned int regalloccount:20; /* number of local allocations */
124 unsigned int type:4; /* RPLPOINT_TYPE_... constant */
125 unsigned int flags:8; /* OR of RPLPOINT_... constants */
129 union replace_val_t {
143 u1 *ra; /* return address / link register */
144 struct sourceframe_t {
145 sourceframe_t *down; /* source frame down the call chain */
147 methodinfo *method; /* method this frame is in */
152 replace_val_t instance;
154 replace_val_t *javastack; /* values of stack vars */
155 u1 *javastacktype; /* types of stack vars */
156 s4 javastackdepth; /* number of stack vars */
158 replace_val_t *javalocals; /* values of javalocals */
159 u1 *javalocaltype; /* types of javalocals */
160 s4 javalocalcount; /* number of javalocals */
162 replace_val_t *syncslots;
163 s4 syncslotcount; /* XXX do we need more than one? */
166 rplpoint *fromrp; /* rplpoint used to read this frame */
167 codeinfo *fromcode; /* code this frame was using */
168 rplpoint *torp; /* rplpoint this frame was mapped to */
169 codeinfo *tocode; /* code this frame was mapped to */
171 /* info for native frames */
172 stackframeinfo_t *sfi; /* sfi for native frames, otherwise NULL */
173 s4 nativeframesize; /* size (bytes) of native frame */
175 ptrint nativesavint[INT_SAV_CNT]; /* XXX temporary */
176 double nativesavflt[FLT_REG_CNT]; /* XXX temporary */
177 #if defined(HAS_ADDRESS_REGISTER_FILE)
178 ptrint nativesavadr[ADR_SAV_CNT]; /* XXX temporary */
182 #define REPLACE_IS_NATIVE_FRAME(frame) ((frame)->sfi != NULL)
183 #define REPLACE_IS_JAVA_FRAME(frame) ((frame)->sfi == NULL)
186 struct sourcestate_t {
187 sourceframe_t *frames; /* list of source frames, from bottom up */
191 /*** macros for the codegens *******************************************/
193 #define REPLACEMENT_POINTS_INIT(cd, jd) \
194 if (!replace_create_replacement_points(jd)) \
196 (cd)->replacementpoint = (jd)->code->rplpoints;
198 #define REPLACEMENT_POINTS_RESET(cd, jd) \
199 (cd)->replacementpoint = (jd)->code->rplpoints;
201 #define REPLACEMENT_POINT_BLOCK_START(cd, bptr) \
202 if ((bptr)->bitflags & BBFLAG_REPLACEMENT) \
203 codegen_set_replacement_point((cd) RPLPOINT_CHECK_BB(bptr));
205 #define REPLACEMENT_POINT_INLINE_START(cd, iptr) \
206 codegen_set_replacement_point(cd RPLPOINT_CHECK(INLINE));
208 #define REPLACEMENT_POINT_INLINE_BODY(cd, iptr) \
209 codegen_set_replacement_point_notrap(cd RPLPOINT_CHECK(BODY));
211 #define REPLACEMENT_POINT_RETURN(cd, iptr) \
212 codegen_set_replacement_point(cd RPLPOINT_CHECK(RETURN));
214 #define REPLACEMENT_POINT_INVOKE(cd, iptr) \
215 codegen_set_replacement_point(cd RPLPOINT_CHECK(CALL));
217 #define REPLACEMENT_POINT_INVOKE_RETURN(cd, iptr) \
218 if (iptr->opc != ICMD_BUILTIN) \
219 cd->replacementpoint[-1].callsize = (cd->mcodeptr - cd->mcodebase)\
220 - (ptrint) cd->replacementpoint[-1].pc;
223 /*** macros for the codegens (for GC) **********************************/
225 #if defined(ENABLE_GC_CACAO)
227 #define REPLACEMENT_POINT_FORGC_BUILTIN(cd, iptr) \
228 codegen_set_replacement_point(cd RPLPOINT_CHECK(CALL));
230 #define REPLACEMENT_POINT_FORGC_BUILTIN_RETURN(cd, iptr) \
231 if (iptr->opc == ICMD_BUILTIN) \
232 cd->replacementpoint[-1].callsize = (cd->mcodeptr - cd->mcodebase)\
233 - (ptrint) cd->replacementpoint[-1].pc;
235 #else /* defined(ENABLE_GC_CACAO) */
237 #define REPLACEMENT_POINT_FORGC_BUILTIN(cd, iptr)
238 #define REPLACEMENT_POINT_FORGC_BUILTIN_RETURN(cd, iptr)
240 #endif /* defined(ENABLE_GC_CACAO) */
243 /*** prototypes ********************************************************/
245 bool replace_create_replacement_points(jitdata *jd);
246 void replace_free_replacement_points(codeinfo *code);
248 void replace_activate_replacement_points(codeinfo *code, bool mappable);
249 void replace_deactivate_replacement_points(codeinfo *code);
251 bool replace_me_wrapper(u1 *pc, void *context);
254 void replace_show_replacement_points(codeinfo *code);
255 void replace_replacement_point_println(rplpoint *rp, int depth);
256 void replace_sourcestate_println(sourcestate_t *ss);
257 void replace_sourcestate_println_short(sourcestate_t *ss);
258 void replace_source_frame_println(sourceframe_t *frame);
261 /* machine dependent functions (code in ARCH_DIR/md.c) */
263 #if defined(ENABLE_JIT)
264 void md_patch_replacement_point(u1 *pc, u1 *savedmcode, bool revert);
267 #endif /* defined(ENABLE_REPLACEMENT) */
269 #endif /* _REPLACE_H */
273 * These are local overrides for various environment variables in Emacs.
274 * Please do not remove this and leave it at the end of the file, where
275 * Emacs will automagically detect them.
276 * ---------------------------------------------------------------------
279 * indent-tabs-mode: t
283 * vim:noexpandtab:sw=4:ts=4: