1 /* src/vm/jit/intrp/asmpart.c - Java-C interface functions for Interpreter
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
34 #include "threads/thread.h"
36 #include "vm/builtin.h"
37 #include "vm/exceptions.h"
39 #include "vm/jit/asmpart.h"
40 #include "vm/jit/methodheader.h"
41 #include "vm/jit/methodtree.h"
42 #include "vm/jit/dseg.h"
44 #include "vm/jit/intrp/intrp.h"
46 #include "vmcore/class.h"
47 #include "vmcore/linker.h"
48 #include "vmcore/loader.h"
49 #include "vmcore/options.h"
51 #if defined(ENABLE_VMLOG)
52 #include <vmlog_cacao.h>
56 static bool intrp_asm_vm_call_method_intern(methodinfo *m, s4 vmargscount,
59 java_objectheader *retval;
69 for (i = 0; i < vmargscount; i++) {
70 switch (vmargs[i].type) {
74 *(--sp) = (Cell) vmargs[i].data.l;
79 *((u8 *) sp) = vmargs[i].data.l;
84 entrypoint = createcalljavafunction(m);
86 retval = engine((Inst *) entrypoint, sp, NULL);
88 /* XXX remove the method from the method table */
91 (void)builtin_throw_exception(retval);
99 java_objectheader *intrp_asm_vm_call_method(methodinfo *m, s4 vmargscount,
102 java_objectheader *retval = NULL;
104 if (intrp_asm_vm_call_method_intern(m, vmargscount, vmargs)) {
105 if (m->parseddesc->returntype.type == TYPE_ADR)
106 retval = (java_objectheader *)*global_sp++;
108 assert(m->parseddesc->returntype.type == TYPE_VOID);
115 s4 intrp_asm_vm_call_method_int(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
119 if (intrp_asm_vm_call_method_intern(m, vmargscount, vmargs)) {
120 if (m->parseddesc->returntype.type == TYPE_INT)
121 retval = *global_sp++;
123 assert(m->parseddesc->returntype.type == TYPE_VOID);
130 s8 intrp_asm_vm_call_method_long(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
134 assert(m->parseddesc->returntype.type == TYPE_LNG);
136 if (intrp_asm_vm_call_method_intern(m, vmargscount, vmargs)) {
137 retval = *(s8 *)global_sp;
145 float intrp_asm_vm_call_method_float(methodinfo *m, s4 vmargscount,
150 assert(m->parseddesc->returntype.type == TYPE_FLT);
152 if (intrp_asm_vm_call_method_intern(m, vmargscount, vmargs)) {
153 retval = *(float *)global_sp;
161 double intrp_asm_vm_call_method_double(methodinfo *m, s4 vmargscount,
166 assert(m->parseddesc->returntype.type == TYPE_DBL);
168 if (intrp_asm_vm_call_method_intern(m, vmargscount, vmargs)) {
169 retval = *(double *)global_sp;
177 Inst *intrp_asm_handle_exception(Inst *ip, java_objectheader *o, Cell *fp, Cell **new_spp, Cell **new_fpp)
180 classref_or_classinfo cr;
183 dseg_exception_entry *ex;
184 s4 exceptiontablelength;
187 /* for a description of the stack see IRETURN in java.vmg */
189 for (; fp != NULL; ) {
190 u1 *f = methodtree_find((u1 *) (ip - 1));
192 /* get methodinfo pointer from method header */
194 codeinfo *code = *((codeinfo **) ((u1 *)f + CodeinfoPointer));
195 methodinfo *m = code->m;
197 framesize = *((s4 *) (((u1 *) f) + FrameSize));
198 issync = *((s4 *) (((u1 *) f) + IsSync));
199 ex = (dseg_exception_entry *)
200 (((u1 *) f) + ExTableStart);
201 exceptiontablelength = *((s4 *) (((u1 *) f) + ExTableSize));
204 if (opt_verbose || opt_verbosecall || opt_verboseexception)
205 builtin_trace_exception(o, m, ip, 1);
208 #if defined(ENABLE_VMLOG)
209 vmlog_cacao_throw(o);
212 for (i = 0; i < exceptiontablelength; i++) {
217 if (cr.any == NULL) {
222 if (IS_CLASSREF(cr)) {
223 /* The exception class reference is unresolved. */
224 /* We have to do _eager_ resolving here. While the class of */
225 /* the exception object is guaranteed to be loaded, it may */
226 /* well have been loaded by a different loader than the */
227 /* defining loader of m's class, which is the one we must */
228 /* use to resolve the catch class. Thus lazy resolving */
229 /* might fail, even if the result of the resolution would */
230 /* be an already loaded class. */
232 /* The resolving may involve Java code, so we need a usable */
233 /* global_sp. XXX is this a correct value for global_sp? */
235 global_sp = (Cell *)(((u1 *)fp) - framesize - SIZEOF_VOID_P);
237 c = resolve_classref_eager(cr.ref);
242 /* Exception resolving the exception class, argh! */
243 /* XXX how to report that error? */
247 /* Ok, we resolved it. Enter it in the table, so we don't */
248 /* have to do this again. */
249 /* XXX this write should be atomic. Is it? */
251 ex->catchtype.cls = c;
256 /* If the class is not linked, the exception object cannot */
257 /* be an instance of it. */
258 if (!(c->state & CLASS_LINKED))
263 if (ip-1 >= (Inst *) ex->startpc && ip-1 < (Inst *) ex->endpc &&
264 (c == NULL || builtin_instanceof(o, c)))
266 #if defined(ENABLE_VMLOG)
267 vmlog_cacao_catch(o);
270 *new_spp = (Cell *)(((u1 *)fp) - framesize - SIZEOF_VOID_P);
272 return (Inst *) (ex->handlerpc);
276 #if defined(ENABLE_THREADS)
277 /* is this method synchronized? */
280 java_objectheader *syncobj;
282 /* get synchronization object */
284 if (m->flags & ACC_STATIC) {
285 syncobj = (java_objectheader *) m->clazz;
288 syncobj = (java_objectheader *) access_local_cell(-framesize + SIZEOF_VOID_P);
291 assert(syncobj != NULL);
293 lock_monitor_exit(syncobj);
295 #endif /* defined(ENABLE_THREADS) */
297 /* unwind stack frame */
299 #if defined(ENABLE_VMLOG)
300 vmlog_cacao_unwnd_method(m);
303 ip = (Inst *)access_local_cell(-framesize - SIZEOF_VOID_P);
304 fp = (Cell *)access_local_cell(-framesize);
311 void intrp_asm_abstractmethoderror(void)
313 vm_abort("intrp_asm_abstractmethoderror: IMPLEMENT ME!");
317 void intrp_asm_getclassvalues_atomic(vftbl_t *super, vftbl_t *sub, castinfo *out)
321 LOCK_MONITOR_ENTER(linker_classrenumber_lock);
323 sbv = super->baseval;
324 sdv = super->diffval;
327 LOCK_MONITOR_EXIT(linker_classrenumber_lock);
329 out->super_baseval = sbv;
330 out->super_diffval = sdv;
331 out->sub_baseval = sv;
336 * These are local overrides for various environment variables in Emacs.
337 * Please do not remove this and leave it at the end of the file, where
338 * Emacs will automagically detect them.
339 * ---------------------------------------------------------------------
342 * indent-tabs-mode: t
346 * vim:noexpandtab:sw=4:ts=4: