* src/vm/jit/i386/emit.c (emit_verbosecall_enter): Check for
[cacao.git] / src / vm / jit / codegen-common.h
1 /* src/vm/jit/codegen-common.h - architecture independent code generator stuff
2
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
7
8    This file is part of CACAO.
9
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.
14
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.
19
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
23    02110-1301, USA.
24
25    Contact: cacao@cacaojvm.org
26
27    Authors: Christian Thalinger
28             Christian Ullrich
29             Edwin Steiner
30
31    $Id: codegen-common.h 6091 2006-11-29 20:44:10Z twisti $
32
33 */
34
35
36 #ifndef _CODEGEN_COMMON_H
37 #define _CODEGEN_COMMON_H
38
39 /* forward typedefs ***********************************************************/
40
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;
48
49
50 #include "config.h"
51 #include "vm/types.h"
52
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"
61
62
63 #define MCODEINITSIZE (1<<15)       /* 32 Kbyte code area initialization size */
64 #define DSEGINITSIZE  (1<<12)       /*  4 Kbyte data area initialization size */
65
66 #define NCODEINITSIZE (1<<15)       /* 32 Kbyte code area initialization size */
67
68
69 /* Register Pack/Unpack Macros ************************************************/
70
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. */
73
74 #define PACK_REGS(low,high) \
75     ( (((high) & 0x0000ffff) << 16) | ((low) & 0x0000ffff) )
76
77 #define GET_LOW_REG(a)      ((a) & 0x0000ffff)
78 #define GET_HIGH_REG(a)    (((a) & 0xffff0000) >> 16)
79
80
81 /* branch conditions **********************************************************/
82
83 #define BRANCH_UNCONDITIONAL    -1
84
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)
91
92 #define BRANCH_NAN              256
93
94
95 /************************* critical sections  *********************************/
96
97 struct codegen_critical_section_t {
98         codegen_critical_section_t *next;
99         s4                  mcodebegin;
100         s4                  mcodeend;
101         s4                  mcoderestart;
102 };
103
104
105 struct codegendata {
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   */
111
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         */
116
117         u4              lastinstwithoutdispatch; /* ~0 if there was a dispatch    */
118
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        */
123 #endif
124
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     */
128
129         jumpref        *jumpreferences; /* list of jumptable target addresses     */
130
131 #if defined(__I386__) || defined(__X86_64__) || defined(__XDSPCORE__) || defined(ENABLE_INTRP)
132         dataref        *datareferences; /* list of data segment references        */
133 #endif
134
135         exceptionref   *exceptionrefs;  /* list of exception branches             */
136 /*      list           *patchrefs; */
137         patchref       *patchrefs;
138
139         linenumberref  *linenumberreferences; /* list of line numbers and the     */
140                                         /* program counters of their first        */
141                                         /* instruction                            */
142         s4              linenumbertablesizepos;
143         s4              linenumbertablestartpos;
144         s4              linenumbertab;
145
146         methodinfo     *method;
147
148         codegen_critical_section_t *threadcrit; /* List of critical code regions          */
149         codegen_critical_section_t threadcritcurrent;
150         s4                 threadcritcount; /* Number of critical regions         */
151
152         s4              maxstack;
153         s4              stackframesize;    /* stackframe size of this method      */
154
155         rplpoint       *replacementpoint;  /* current replacement point           */
156 };
157
158
159 /* jumpref ********************************************************************/
160
161 struct jumpref {
162         s4          tablepos;       /* patching position in data segment          */
163         basicblock *target;         /* target basic block                         */
164         jumpref    *next;           /* next element in jumpref list               */
165 };
166
167
168 /* dataref ********************************************************************/
169
170 struct dataref {
171         s4       datapos;           /* patching position in generated code        */
172         dataref *next;              /* next element in dataref list               */
173 };
174
175
176 /* exceptionref ***************************************************************/
177
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          */
183 };
184
185
186 /* patchref *******************************************************************/
187
188 struct 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; */
194         patchref    *next;
195 };
196
197
198 /* linenumberref **************************************************************/
199
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         */
213 };
214
215
216 /* methodtree_element *********************************************************/
217
218 typedef struct methodtree_element methodtree_element;
219
220 struct methodtree_element {
221         u1 *startpc;
222         u1 *endpc;
223 };
224
225
226 /* function prototypes ********************************************************/
227
228 void codegen_init(void);
229 void codegen_setup(jitdata *jd);
230
231 void codegen_close(void);
232
233 void codegen_increase(codegendata *cd);
234
235 #if defined(ENABLE_INTRP)
236 u1 *codegen_ncode_increase(codegendata *cd, u1 *ncodeptr);
237 #endif
238
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);
243
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);
250
251
252 void codegen_add_patch_ref(codegendata *cd, functionptr patcher, voidptr ref,
253                                                    s4 disp);
254 /* XXX REMOVE ME: don't-break-trunk macro */
255 #define codegen_addpatchref codegen_add_patch_ref
256
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);
260
261 #if !defined(NDEBUG)
262 void codegen_set_replacement_point_notrap(codegendata *cd, s4 type);
263 void codegen_set_replacement_point(codegendata *cd, s4 type);
264 #else
265 void codegen_set_replacement_point_notrap(codegendata *cd);
266 void codegen_set_replacement_point(codegendata *cd);
267 #endif
268
269 void codegen_finish(jitdata *jd);
270
271 codeinfo *codegen_createnativestub(functionptr f, methodinfo *m);
272 #if defined(ENABLE_DISASSEMBLER)
273 void codegen_disassemble_nativestub(methodinfo *m, u1 *start, u1 *end);
274 #endif
275
276 void codegen_start_native_call(u1 *datasp, u1 *pv, u1 *sp, u1 *ra);
277 java_objectheader *codegen_finish_native_call(u1 *datasp);
278
279 u1 *createcompilerstub(methodinfo *m);
280 u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd);
281
282 #if defined(ENABLE_INTRP)
283 u1 *intrp_createcompilerstub(methodinfo *m);
284 u1 *intrp_createnativestub(functionptr f, jitdata *jd, methoddesc *md);
285 #endif
286
287 void removecompilerstub(u1 *stub);
288 void removenativestub(u1 *stub);
289
290 s4 codegen_reg_of_var(u2 opcode, varinfo *v, s4 tempregnum);
291 s4 codegen_reg_of_dst(jitdata *jd, instruction *iptr, s4 tempregnum);
292
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);
297 #endif
298
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);
302
303 bool codegen(jitdata *jd);
304
305 #if defined(ENABLE_INTRP)
306 bool intrp_codegen(jitdata *jd);
307 #endif
308
309 #endif /* _CODEGEN_COMMON_H */
310
311
312 /*
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  * ---------------------------------------------------------------------
317  * Local variables:
318  * mode: c
319  * indent-tabs-mode: t
320  * c-basic-offset: 4
321  * tab-width: 4
322  * End:
323  * vim:noexpandtab:sw=4:ts=4:
324  */