1 /* src/vm/jit/codegen-common.h - architecture independent code generator stuff
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: Christian Thalinger
31 $Id: codegen-common.h 6091 2006-11-29 20:44:10Z twisti $
36 #ifndef _CODEGEN_COMMON_H
37 #define _CODEGEN_COMMON_H
39 /* forward typedefs ***********************************************************/
41 typedef struct codegen_critical_section_t codegen_critical_section_t;
42 typedef struct codegendata codegendata;
43 typedef struct jumpref jumpref;
44 typedef struct dataref dataref;
45 typedef struct exceptionref exceptionref;
46 typedef struct patchref patchref;
47 typedef struct linenumberref linenumberref;
53 #include "vm/global.h"
54 #include "vm/references.h"
55 #include "vm/method.h"
56 #include "vm/jit/dseg.h"
57 #include "vm/jit/jit.h"
58 #include "vm/jit/reg.h"
59 #include "vm/jit/code.h"
60 #include "vm/jit/replace.h"
63 #define MCODEINITSIZE (1<<15) /* 32 Kbyte code area initialization size */
64 #define DSEGINITSIZE (1<<12) /* 4 Kbyte data area initialization size */
66 #define NCODEINITSIZE (1<<15) /* 32 Kbyte code area initialization size */
69 /* Register Pack/Unpack Macros ************************************************/
71 /* ATTENTION: Don't change the order where low and high bits are
72 stored! At least mips32 relies in one case on that order. */
74 #define PACK_REGS(low,high) \
75 ( (((high) & 0x0000ffff) << 16) | ((low) & 0x0000ffff) )
77 #define GET_LOW_REG(a) ((a) & 0x0000ffff)
78 #define GET_HIGH_REG(a) (((a) & 0xffff0000) >> 16)
81 /* branch conditions **********************************************************/
83 #define BRANCH_UNCONDITIONAL -1
85 #define BRANCH_EQ (ICMD_IFEQ - ICMD_IFEQ)
86 #define BRANCH_NE (ICMD_IFNE - ICMD_IFEQ)
87 #define BRANCH_LT (ICMD_IFLT - ICMD_IFEQ)
88 #define BRANCH_GE (ICMD_IFGE - ICMD_IFEQ)
89 #define BRANCH_GT (ICMD_IFGT - ICMD_IFEQ)
90 #define BRANCH_LE (ICMD_IFLE - ICMD_IFEQ)
92 #define BRANCH_NAN 256
95 /************************* critical sections *********************************/
97 struct codegen_critical_section_t {
98 codegen_critical_section_t *next;
106 u1 *mcodebase; /* base pointer of code area */
107 u1 *mcodeend; /* pointer to end of code area */
108 s4 mcodesize; /* complete size of code area (bytes) */
109 u1 *mcodeptr; /* code generation pointer */
110 u1 *lastmcodeptr; /* last patcher position of basic block */
112 #if defined(ENABLE_INTRP)
113 u1 *ncodebase; /* base pointer of native code area */
114 s4 ncodesize; /* complete size of native code area */
115 u1 *ncodeptr; /* native code generation pointer */
117 u4 lastinstwithoutdispatch; /* ~0 if there was a dispatch */
119 s4 lastpatcheroffset; /* -1 if current super has no patcher */
120 s4 dynsuperm; /* offsets of start of current dynamic ...*/
121 s4 dynsupern; /* ... superinstruction starts */
122 struct superstart *superstarts; /* list of supers without patchers */
125 dsegentry *dseg; /* chain of data segment entries */
126 s4 dseglen; /* used size of data area (bytes) */
127 /* data area grows from top to bottom */
129 jumpref *jumpreferences; /* list of jumptable target addresses */
131 #if defined(__I386__) || defined(__X86_64__) || defined(__XDSPCORE__) || defined(ENABLE_INTRP)
132 dataref *datareferences; /* list of data segment references */
135 exceptionref *exceptionrefs; /* list of exception branches */
136 /* list *patchrefs; */
139 linenumberref *linenumberreferences; /* list of line numbers and the */
140 /* program counters of their first */
142 s4 linenumbertablesizepos;
143 s4 linenumbertablestartpos;
148 codegen_critical_section_t *threadcrit; /* List of critical code regions */
149 codegen_critical_section_t threadcritcurrent;
150 s4 threadcritcount; /* Number of critical regions */
153 s4 stackframesize; /* stackframe size of this method */
155 rplpoint *replacementpoint; /* current replacement point */
159 /* jumpref ********************************************************************/
162 s4 tablepos; /* patching position in data segment */
163 basicblock *target; /* target basic block */
164 jumpref *next; /* next element in jumpref list */
168 /* dataref ********************************************************************/
171 s4 datapos; /* patching position in generated code */
172 dataref *next; /* next element in dataref list */
176 /* exceptionref ***************************************************************/
178 struct exceptionref {
179 s4 branchpos; /* patching position in code segment */
180 s4 reg; /* used for ArrayIndexOutOfBounds index reg */
181 functionptr function; /* function pointer to generate exception */
182 exceptionref *next; /* next element in exceptionref list */
186 /* patchref *******************************************************************/
189 s4 branchpos; /* relative offset to method entrypoint */
190 s4 disp; /* displacement of ref in the data segment */
191 functionptr patcher; /* patcher function to call */
192 voidptr ref; /* reference passed */
193 /* listnode linkage; */
198 /* linenumberref **************************************************************/
200 struct linenumberref {
201 s4 tablepos; /* patching position in data segment */
202 s4 linenumber; /* line number, used for inserting into the */
203 /* table and for validity checking */
204 /* -1......start of inlined body */
205 /* -2......end of inlined body */
206 /* <= -3...special entry with methodinfo * */
207 /* (see doc/inlining_stacktrace.txt) */
208 ptrint targetmpc; /* machine code program counter of first */
209 /* instruction for given line */
210 /* NOTE: for linenumber <= -3 this is a the */
211 /* (methodinfo *) of the inlined method */
212 linenumberref *next; /* next element in linenumberref list */
216 /* methodtree_element *********************************************************/
218 typedef struct methodtree_element methodtree_element;
220 struct methodtree_element {
226 /* function prototypes ********************************************************/
228 void codegen_init(void);
229 void codegen_setup(jitdata *jd);
231 void codegen_close(void);
233 void codegen_increase(codegendata *cd);
235 #if defined(ENABLE_INTRP)
236 u1 *codegen_ncode_increase(codegendata *cd, u1 *ncodeptr);
239 void codegen_add_branch_ref(codegendata *cd, basicblock *target);
240 /* XXX REMOVE ME: don't-break-trunk macro */
241 #define codegen_addreference codegen_add_branch_ref
242 void codegen_resolve_branchrefs(codegendata *cd, basicblock *bptr);
244 void codegen_add_arithmeticexception_ref(codegendata *cd);
245 void codegen_add_arrayindexoutofboundsexception_ref(codegendata *cd, s4 reg);
246 void codegen_add_arraystoreexception_ref(codegendata *cd);
247 void codegen_add_classcastexception_ref(codegendata *cd, s4 reg);
248 void codegen_add_nullpointerexception_ref(codegendata *cd);
249 void codegen_add_fillinstacktrace_ref(codegendata *cd);
252 void codegen_add_patch_ref(codegendata *cd, functionptr patcher, voidptr ref,
254 /* XXX REMOVE ME: don't-break-trunk macro */
255 #define codegen_addpatchref codegen_add_patch_ref
257 void codegen_insertmethod(u1 *startpc, u1 *endpc);
258 u1 *codegen_get_pv_from_pc(u1 *pc);
259 u1 *codegen_get_pv_from_pc_nocheck(u1 *pc);
262 void codegen_set_replacement_point_notrap(codegendata *cd, s4 type);
263 void codegen_set_replacement_point(codegendata *cd, s4 type);
265 void codegen_set_replacement_point_notrap(codegendata *cd);
266 void codegen_set_replacement_point(codegendata *cd);
269 void codegen_finish(jitdata *jd);
271 codeinfo *codegen_createnativestub(functionptr f, methodinfo *m);
272 #if defined(ENABLE_DISASSEMBLER)
273 void codegen_disassemble_nativestub(methodinfo *m, u1 *start, u1 *end);
276 void codegen_start_native_call(u1 *datasp, u1 *pv, u1 *sp, u1 *ra);
277 java_objectheader *codegen_finish_native_call(u1 *datasp);
279 u1 *createcompilerstub(methodinfo *m);
280 u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd);
282 #if defined(ENABLE_INTRP)
283 u1 *intrp_createcompilerstub(methodinfo *m);
284 u1 *intrp_createnativestub(functionptr f, jitdata *jd, methoddesc *md);
287 void removecompilerstub(u1 *stub);
288 void removenativestub(u1 *stub);
290 s4 codegen_reg_of_var(u2 opcode, varinfo *v, s4 tempregnum);
291 s4 codegen_reg_of_dst(jitdata *jd, instruction *iptr, s4 tempregnum);
293 #if defined(ENABLE_THREADS)
294 void codegen_threadcritrestart(codegendata *cd, int offset);
295 void codegen_threadcritstart(codegendata *cd, int offset);
296 void codegen_threadcritstop(codegendata *cd, int offset);
299 /* machine dependent functions */
300 void md_codegen_patch_branch(codegendata *cd, s4 branchmpc, s4 targetmpc);
301 u1 *md_codegen_get_pv_from_pc(u1 *ra);
303 bool codegen(jitdata *jd);
305 #if defined(ENABLE_INTRP)
306 bool intrp_codegen(jitdata *jd);
309 #endif /* _CODEGEN_COMMON_H */
313 * These are local overrides for various environment variables in Emacs.
314 * Please do not remove this and leave it at the end of the file, where
315 * Emacs will automagically detect them.
316 * ---------------------------------------------------------------------
319 * indent-tabs-mode: t
323 * vim:noexpandtab:sw=4:ts=4: