* Removed all Id tags.
[cacao.git] / src / vm / jit / intrp / intrp.h
1 /* src/vm/jit/intrp/intrp.h - definitions for Interpreter
2
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
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 */
26
27
28 #ifndef _INTRP_H
29 #define _INTRP_H
30
31 /* #define VM_PROFILING */
32
33 #include "config.h"
34
35 #include <stdio.h>
36
37 #include "vm/types.h"
38
39 #include "arch.h"
40
41 /* we need Cell in some headers below */
42
43 #if SIZEOF_VOID_P == 8
44 typedef s8 Cell;
45 #else
46 typedef s4 Cell;
47 #endif
48
49 #include "vm/global.h"
50
51 #include "vm/jit/codegen-common.h"
52
53 #include "vmcore/class.h"
54 #include "vmcore/method.h"
55 #include "vmcore/references.h"
56 #include "vm/resolve.h"
57 #include "vmcore/linker.h"
58
59
60 typedef void *Label;
61 typedef void *Inst;
62
63 #if 1
64 #define MAYBE_UNUSED __attribute__((unused))
65 #else
66 #define MAYBE_UNUSED
67 #endif
68
69 #if SIZEOF_VOID_P == 4
70
71 typedef union {
72     struct {
73                 u4 low;
74                 s4 high;
75     } cells;
76     s8 l;
77     double d;
78 } Double_Store;
79
80 #define FETCH_DCELL_T(d_,lo,hi,t_)      ({ \
81                                      Double_Store _d; \
82                                      _d.cells.low = (lo); \
83                                      _d.cells.high = (hi); \
84                                      (d_) = _d.t_; \
85                                  })
86
87 #define STORE_DCELL_T(d_,lo,hi,t_)      ({ \
88                                      Double_Store _d; \
89                                      _d.t_ = (d_); \
90                                      (lo) = _d.cells.low; \
91                                      (hi) = _d.cells.high; \
92                                  })
93
94 #else /* SIZEOF_VOID_P == 4 */
95
96 typedef union {
97         s8 low;
98         s8 l;
99         double d;
100 } Double_Store;
101
102
103 #define FETCH_DCELL_T(d_,lo,hi,t_)      ({ (d_) = ((Double_Store)(lo)).t_; })
104 #define STORE_DCELL_T(d_,lo,hi,t_)      ({ (lo) = ((Double_Store)(d_)).low; })
105
106 #endif /* SIZEOF_VOID_P == 4 */
107
108
109 #if defined(ENABLE_THREADS)
110
111 #define global_sp    (THREADOBJECT->_global_sp)
112
113 #else /* defined(ENABLE_THREADS) */
114
115 #define MAX_STACK_SIZE 128*1024
116 static char stack[MAX_STACK_SIZE];
117
118 static Cell *_global_sp = (Cell *)(stack+MAX_STACK_SIZE);
119 #define global_sp    _global_sp
120
121 #endif /* defined(ENABLE_THREADS) */
122
123 #define CLEAR_global_sp (global_sp=NULL)
124
125
126 #define vm_twoCell2l(hi,lo,d_)  FETCH_DCELL_T(d_,lo,hi,l);
127 #define vm_twoCell2d(hi,lo,d_)  FETCH_DCELL_T(d_,lo,hi,d);
128                                                                                                  
129 #define vm_l2twoCell(d_,hi,lo)  STORE_DCELL_T(d_,lo,hi,l);
130 #define vm_d2twoCell(d_,hi,lo)  STORE_DCELL_T(d_,lo,hi,d);
131
132 #define vm_Cell2v(cell, v) ((v)=(Cell)(cell))
133 #define vm_Cell2b(cell, b) ((b)=(u1)(Cell)(cell))
134 #define vm_Cell2i(cell, i) ((i)=(s4)(Cell)(cell))
135
136 #define vm_Cell2aRef(x1,x2)       ((x2) = (java_objectheader *)(x1))
137 #define vm_Cell2aArray(x1,x2)     ((x2) = (java_arrayheader * )(x1))
138 #define vm_Cell2aaTarget(x1,x2)   ((x2) = (Inst **            )(x1))
139 #define vm_Cell2aClass(x1,x2)     ((x2) = (classinfo *        )(x1))
140 #define vm_Cell2acr(x1,x2)        ((x2) = (constant_classref *)(x1))
141 #define vm_Cell2addr(x1,x2)       ((x2) = (u1 *               )(x1))
142 #define vm_Cell2af(x1,x2)         ((x2) = (functionptr        )(x1))
143 #define vm_Cell2afi(x1,x2)        ((x2) = (fieldinfo *        )(x1))
144 #define vm_Cell2am(x1,x2)         ((x2) = (methodinfo *       )(x1))
145 #define vm_Cell2acell(x1,x2)      ((x2) = (Cell *             )(x1))
146 #define vm_Cell2ainst(x1,x2)      ((x2) = (Inst *             )(x1))
147 #define vm_Cell2auf(x1,x2)        ((x2) = (unresolved_field * )(x1))
148 #define vm_Cell2aum(x1,x2)        ((x2) = (unresolved_method *)(x1))
149 #define vm_Cell2avftbl(x1,x2)     ((x2) = (vftbl_t *          )(x1))
150
151 #define vm_ui2Cell(x1,x2) ((x2) = (Cell)(x1))
152 #define vm_v2Cell(x1,x2) ((x2) = (Cell)(x1))
153 #define vm_b2Cell(x1,x2) ((x2) = (Cell)(x1))
154 #define vm_s2Cell(x1,x2) ((x2) = (Cell)(x1))
155 #define vm_i2Cell(x1,x2) ((x2) = (Cell)(x1))
156 #define vm_aRef2Cell(x1,x2) ((x2) = (Cell)(x1))
157 #define vm_aArray2Cell(x1,x2) ((x2) = (Cell)(x1))
158 #define vm_aaTarget2Cell(x1,x2) ((x2) = (Cell)(x1))
159 #define vm_aClass2Cell(x1,x2) ((x2) = (Cell)(x1))
160 #define vm_acr2Cell(x1,x2) ((x2) = (Cell)(x1))
161 #define vm_addr2Cell(x1,x2) ((x2) = (Cell)(x1))
162 #define vm_af2Cell(x1,x2) ((x2) = (Cell)(x1))
163 #define vm_afi2Cell(x1,x2) ((x2) = (Cell)(x1))
164 #define vm_am2Cell(x1,x2) ((x2) = (Cell)(x1))
165 #define vm_acell2Cell(x1,x2) ((x2) = (Cell)(x1))
166 #define vm_ainst2Cell(x1,x2) ((x2) = (Cell)(x1))
167 #define vm_auf2Cell(x1,x2) ((x2) = (Cell)(x1))
168 #define vm_aum2Cell(x1,x2) ((x2) = (Cell)(x1))
169 #define vm_avftbl2Cell(x1,x2) ((x2) = (Cell)(x1))
170
171 #define vm_Cell2Cell(x1,x2) ((x2)=(Cell)(x1))
172
173 #define IMM_ARG(access,value)           (access)
174
175 /* for disassembler and tracer */
176 #define VM_IS_INST(inst, n) ((inst) == vm_prim[n])
177
178
179 #define gen_BBSTART (cd->lastmcodeptr = NULL, append_dispatch(cd))
180 #define gen_BBEND (finish_ss(cd))
181
182
183 union Cell_float {
184     Cell cell;
185     float f;
186 };
187
188
189 #define access_local_int(_offset) \
190         ( *(Cell*)(((u1 *)fp) + (_offset)) )
191
192 #define access_local_ref(_offset) \
193         ( *(void **)(((u1 *)fp) + (_offset)) )
194
195 #define access_local_cell(_offset) \
196         ( *(Cell *)(((u1 *)fp) + (_offset)) )
197
198
199 typedef struct block_count block_count;
200
201 #define vm_f2Cell(x1,x2)        ((x2) =(((union Cell_float)(x1)).cell))
202 #define vm_Cell2f(x1,x2)        ((x2) =(((union Cell_float)(x1)).f))
203
204 extern Inst *vm_prim;
205 extern Cell peeptable;
206 extern FILE *vm_out;
207
208 /* defined in peephole.c: */
209 void init_peeptable(void);
210 ptrint peephole_opt(ptrint inst1, ptrint inst2, Cell peeptable);
211
212 /* defined in engine.c: */
213 java_objectheader *engine(Inst *ip0, Cell * sp, Cell * fp);
214
215 /* defined in disass.c: */
216 void vm_disassemble(Inst *ip, Inst *endp, Inst vm_prim[]);
217 Inst *vm_disassemble_inst(Inst *ip, Inst vm_prim[]);
218
219 /* print types for disassembler and tracer */
220 void printarg_ui      (u4                 ui      );
221 void printarg_v       (Cell               v       );
222 void printarg_b       (s4                 b       );
223 void printarg_s       (s4                 s       );
224 void printarg_i       (s4                 i       );
225 void printarg_l       (s8                 l       );
226 void printarg_f       (float              f       );
227 void printarg_d       (double             d       );
228 void printarg_aRef    (java_objectheader *aRef    );
229 void printarg_aArray  (java_arrayheader * aArray  );
230 void printarg_aaTarget(Inst **            aaTarget);
231 void printarg_aClass  (classinfo *        aClass  );
232 void printarg_acr     (constant_classref *acr     );
233 void printarg_addr    (u1 *               addr    );
234 void printarg_af      (functionptr        af      );
235 void printarg_afi     (fieldinfo *        afi     );
236 void printarg_am      (methodinfo *       am      );
237 void printarg_acell   (Cell *             acell   );
238 void printarg_ainst   (Inst *             ainst   );
239 void printarg_auf     (unresolved_field * auf     );
240 void printarg_aum     (unresolved_method *aum     );
241 void printarg_avftbl  (vftbl_t *          avftbl  );
242 void printarg_Cell    (Cell               x       );
243
244 /* defined in profile.c: */
245 void vm_uncount_block(Inst *ip);
246 block_count *vm_block_insert(Inst *ip);
247
248 /* defined in codegen.c: */
249 Cell *nativecall(functionptr f, methodinfo *m, Cell *sp, Inst *ra, Cell *fp, u1 *addrcif);
250 u1 *createcalljavafunction(methodinfo *m);
251
252 /* defined in asmpart.c: */
253 Inst *intrp_asm_handle_exception(Inst *ip, java_objectheader *o, Cell *fp, Cell **new_spp, Cell **new_fpp);
254
255 /* defined in dynamic-super.c: */
256 void gen_inst(codegendata *cd, ptrint instr);
257 void append_dispatch(codegendata *cd);
258 void finish_ss(codegendata *cd);
259 void patchersuper_rewrite(Inst *p);
260 void dynamic_super_init(void);
261 void dynamic_super_rewrite(codegendata *cd);
262
263 #endif /* _INTRP_H */
264
265
266 /*
267  * These are local overrides for various environment variables in Emacs.
268  * Please do not remove this and leave it at the end of the file, where
269  * Emacs will automagically detect them.
270  * ---------------------------------------------------------------------
271  * Local variables:
272  * mode: c
273  * indent-tabs-mode: t
274  * c-basic-offset: 4
275  * tab-width: 4
276  * End:
277  * vim:noexpandtab:sw=4:ts=4:
278  */