1 /* src/vm/jit/intrp/engine.c - #included by engine1.c and engine2.c
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 /* #define VM_DEBUG */
36 #include "vm/jit/intrp/intrp.h"
38 #include "md-abi.h" /* required for TRACE_ARGS_NUM */
40 #include "mm/memory.h"
42 #include "threads/thread.hpp"
44 #include "vm/builtin.h"
45 #include "vm/loader.h"
46 #include "vm/options.h"
48 #include "vm/jit/methodheader.h"
49 #include "vm/jit/patcher.h"
50 #include "vm/jit/stacktrace.hpp"
53 #if defined(ENABLE_THREADS)
54 # include "threads/atomic.hpp"
57 #if !defined(STORE_ORDER_BARRIER) && !defined(ENABLE_THREADS)
58 #define STORE_ORDER_BARRIER() /* nothing */
62 /* threading macros */
63 #define GCC_PR15242_WORKAROUND
64 #ifdef GCC_PR15242_WORKAROUND
66 # define DO_GOTO goto before_goto
69 # define DO_GOTO goto *ip[-1]
74 # define SET_IP(p) do {ip=(p); NEXT_P0;} while (0)
75 # define NEXT_INST (*IP)
76 # define INC_IP(const_inc) do { ip+=(const_inc);} while (0)
78 # define NEXT_P1 (ip++)
79 # define NEXT_P2 do {NEXT_P1_5; DO_GOTO;} while(0)
81 #define NEXT ({DEF_CA NEXT_P1; NEXT_P2;})
82 #define IPTOS NEXT_INST
84 #if defined(__POWERPC__) || defined(__POWERPC64__) || defined(__SPARC__)
88 #if defined(USE_spTOS)
96 /* works with gcc-2.95.4 20011002 (Debian prerelease) without static supers */
97 #define SPREG /* __asm__("%esi") */
98 #define TOSREG /* __asm__("%ecx") */
99 #elif defined(__X86_64__)
100 /* works with gcc-4.0.2 (Debian 4.0.2-2) */
101 #define SPREG /* __asm__("%r15") */
109 /* conversion on fetch */
112 #define SUPER_END vm_count_block(IP)
115 #define vm_uncount_block(_ip) /* nothing */
119 #define THROW0 goto throw
121 #define THROW(_ball) do { \
122 __asm__(""); /* work around gcc PR 25285 */ \
123 goto *throw_##_ball; \
126 #define THROW(_ball) do { \
127 goto throw_##_ball##1; \
131 #define THROWCODE(_ball) \
134 *exceptionptr = (stacktrace_inline_##_ball(NULL, (u1 *) fp, (u1 *) IP, (u1 *) IP)); \
138 #define CHECK_NULL_PTR(ptr) \
140 if ((ptr) == NULL) { \
141 THROW(nullpointerexception); \
145 #define THROW_CLASSCASTEXCEPTION(o) \
147 classcastexception_object = o; \
148 THROW(classcastexception); \
151 #define CHECK_OUT_OF_BOUNDS(_array, _idx) \
153 if (length_array(_array) <= (u4) (_idx)) { \
154 arrayindexoutofbounds_index = (_idx); \
155 THROW(arrayindexoutofboundsexception); \
159 #define CHECK_ZERO_DIVISOR(_divisor) \
160 { if (_divisor == 0) \
161 THROW(arithmeticexception); \
165 /* !! alignment bug */
166 #define access_local_long(_offset) \
167 ( *(s8 *)(((u1 *)fp) + (_offset)) )
170 #define length_array(array) \
171 ( ((java_arrayheader*)(array))->size )
173 #define access_array_int(array, index) \
174 ((((java_intarray*)(array))->data)[index])
176 #define access_array_long(array, index) \
177 ((((java_longarray*)(array))->data)[index])
179 #define access_array_char(array, index) \
180 ((((java_chararray*)(array))->data)[index])
182 #define access_array_short(array, index) \
183 ((((java_shortarray*)(array))->data)[index])
185 #define access_array_byte(array, index) \
186 ((((java_bytearray*)(array))->data)[index])
188 #define access_array_addr(array, index) \
189 ((((java_objectarray*)(array))->data)[index])
191 #define access_array_float(array, index) \
192 ((((java_floatarray*)(array))->data)[index])
194 /* (see createcompilerstub in codegen.c) */
195 #define FRAMESIZE(stub) (((Cell *)stub)[1])
198 #define CLEARSTACK(_start, _end) \
199 do {Cell *__start=(_start); MSET(__start,0,u1,(_end)-__start); } while (0)
201 #define CLEARSTACK(_start, _end)
206 #define NAME(_x) if (vm_debug) {fprintf(vm_out, "%lx: %-20s, ", (long)(ip-1), _x); fprintf(vm_out,"fp=%p, sp=%p", fp, sp);}
211 #define LABEL2(name) J_##name: __asm__("");
212 #define LABEL3(name) K_##name: __asm__("");
216 engine(Inst *ip0, Cell * sp0, Cell * fp)
219 register Cell *sp SPREG = sp0;
220 /* Inst ca1; XXX unused? */ /* code address; this is the next dispatched instruction */
221 IF_spTOS(register Cell spTOS TOSREG;)
222 static Inst labels[] = {
223 #define INST_ADDR(_inst) (&&I_##_inst)
224 #include <java-labels.i>
227 #define INST_ADDR(_inst) (&&J_##_inst)
228 #include <java-labels.i>
230 #define INST_ADDR(_inst) (&&K_##_inst)
231 #include <java-labels.i>
234 (Label)&&before_goto,
236 #define INST_ADDR(_inst) (&&H_##_inst)
237 #include <java-labels.i>
240 /* local variables for the various throw codes; this helps make
241 potentially throwing instructions relocatable (instead of a
242 non-relocatable direct jump, they perform an indirect jump) */
243 Label throw_arithmeticexception = &&throw_arithmeticexception1;
244 Label throw_arrayindexoutofboundsexception = &&throw_arrayindexoutofboundsexception1;
245 Label throw_classcastexception = &&throw_classcastexception1;
246 Label throw_nullpointerexception = &&throw_nullpointerexception1;
247 Label throw_arraystoreexception = &&throw_arraystoreexception1;
248 java_objectheader *classcastexception_object = NULL;
249 s4 arrayindexoutofbounds_index = 0; /* pass the index to the throw code */
252 fprintf(vm_out,"entering engine(%p,%p,%p)\n",ip0,sp,fp);
254 return (java_objectheader *)labels;
261 /* ensure that gcc does not constant-propagate the contents of
262 these variables and thus undo our relocatability work */
263 throw_arithmeticexception = 0;
264 throw_arrayindexoutofboundsexception = 0;
265 throw_classcastexception = 0;
266 throw_nullpointerexception = 0;
267 throw_arraystoreexception = 0;
269 /* the actual codes jumped to through the ...exception variables */
270 THROWCODE(arithmeticexception);
271 THROWCODE(nullpointerexception);
272 THROWCODE(arraystoreexception);
274 throw_classcastexception1:
276 *exceptionptr = stacktrace_inline_classcastexception(NULL, (u1 *) fp, (u1 *) IP, (u1 *) IP, classcastexception_object);
280 throw_arrayindexoutofboundsexception1:
282 *exceptionptr = stacktrace_inline_arrayindexoutofboundsexception(NULL, (u1 *) fp, (u1 *) IP, (u1 *) IP, arrayindexoutofbounds_index);
287 /* I don't have a clue where these things come from,
288 but I've put them in macros.h for the moment */
289 IF_spTOS(spTOS = sp[0]);
294 #define INST_ADDR(_inst) (&&I_##_inst)
297 after_last: return NULL;
302 * These are local overrides for various environment variables in Emacs.
303 * Please do not remove this and leave it at the end of the file, where
304 * Emacs will automagically detect them.
305 * ---------------------------------------------------------------------
308 * indent-tabs-mode: t
312 * vim:noexpandtab:sw=4:ts=4: