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.hpp"
36 #include "vm/jit/builtin.hpp"
38 #include "vm/linker.h"
39 #include "vm/loader.hpp"
40 #include "vm/options.h"
42 #include "vm/jit/asmpart.h"
43 #include "vm/jit/methodheader.h"
44 #include "vm/jit/methodtree.h"
45 #include "vm/jit/dseg.h"
47 #include "vm/jit/intrp/intrp.h"
49 #if defined(ENABLE_VMLOG)
50 #include <vmlog_cacao.h>
54 static bool intrp_asm_vm_call_method_intern(methodinfo *m, s4 vmargscount,
57 java_objectheader *retval;
67 for (i = 0; i < vmargscount; i++) {
68 switch (vmargs[i].type) {
72 *(--sp) = (Cell) vmargs[i].data.l;
77 *((u8 *) sp) = vmargs[i].data.l;
82 entrypoint = createcalljavafunction(m);
84 retval = engine((Inst *) entrypoint, sp, NULL);
86 /* XXX remove the method from the method table */
89 (void)builtin_throw_exception(retval);
97 java_objectheader *intrp_asm_vm_call_method(methodinfo *m, s4 vmargscount,
100 java_objectheader *retval = NULL;
102 if (intrp_asm_vm_call_method_intern(m, vmargscount, vmargs)) {
103 if (m->parseddesc->returntype.type == TYPE_ADR)
104 retval = (java_objectheader *)*global_sp++;
106 assert(m->parseddesc->returntype.type == TYPE_VOID);
113 s4 intrp_asm_vm_call_method_int(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
117 if (intrp_asm_vm_call_method_intern(m, vmargscount, vmargs)) {
118 if (m->parseddesc->returntype.type == TYPE_INT)
119 retval = *global_sp++;
121 assert(m->parseddesc->returntype.type == TYPE_VOID);
128 s8 intrp_asm_vm_call_method_long(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
132 assert(m->parseddesc->returntype.type == TYPE_LNG);
134 if (intrp_asm_vm_call_method_intern(m, vmargscount, vmargs)) {
135 retval = *(s8 *)global_sp;
143 float intrp_asm_vm_call_method_float(methodinfo *m, s4 vmargscount,
148 assert(m->parseddesc->returntype.type == TYPE_FLT);
150 if (intrp_asm_vm_call_method_intern(m, vmargscount, vmargs)) {
151 retval = *(float *)global_sp;
159 double intrp_asm_vm_call_method_double(methodinfo *m, s4 vmargscount,
164 assert(m->parseddesc->returntype.type == TYPE_DBL);
166 if (intrp_asm_vm_call_method_intern(m, vmargscount, vmargs)) {
167 retval = *(double *)global_sp;
175 Inst *intrp_asm_handle_exception(Inst *ip, java_objectheader *o, Cell *fp, Cell **new_spp, Cell **new_fpp)
178 classref_or_classinfo cr;
181 dseg_exception_entry *ex;
182 s4 exceptiontablelength;
185 /* for a description of the stack see IRETURN in java.vmg */
187 for (; fp != NULL; ) {
188 u1 *f = methodtree_find((u1 *) (ip - 1));
190 /* get methodinfo pointer from method header */
192 codeinfo *code = *((codeinfo **) ((u1 *)f + CodeinfoPointer));
193 methodinfo *m = code->m;
195 framesize = *((s4 *) (((u1 *) f) + FrameSize));
196 issync = *((s4 *) (((u1 *) f) + IsSync));
197 ex = (dseg_exception_entry *)
198 (((u1 *) f) + ExTableStart);
199 exceptiontablelength = *((s4 *) (((u1 *) f) + ExTableSize));
202 if (opt_verbose || opt_verbosecall || opt_verboseexception)
203 builtin_trace_exception(o, m, ip, 1);
206 #if defined(ENABLE_VMLOG)
207 vmlog_cacao_throw(o);
210 for (i = 0; i < exceptiontablelength; i++) {
215 if (cr.any == NULL) {
220 if (IS_CLASSREF(cr)) {
221 /* The exception class reference is unresolved. */
222 /* We have to do _eager_ resolving here. While the class of */
223 /* the exception object is guaranteed to be loaded, it may */
224 /* well have been loaded by a different loader than the */
225 /* defining loader of m's class, which is the one we must */
226 /* use to resolve the catch class. Thus lazy resolving */
227 /* might fail, even if the result of the resolution would */
228 /* be an already loaded class. */
230 /* The resolving may involve Java code, so we need a usable */
231 /* global_sp. XXX is this a correct value for global_sp? */
233 global_sp = (Cell *)(((u1 *)fp) - framesize - SIZEOF_VOID_P);
235 c = resolve_classref_eager(cr.ref);
240 /* Exception resolving the exception class, argh! */
241 /* XXX how to report that error? */
245 /* Ok, we resolved it. Enter it in the table, so we don't */
246 /* have to do this again. */
247 /* XXX this write should be atomic. Is it? */
249 ex->catchtype.cls = c;
254 /* If the class is not linked, the exception object cannot */
255 /* be an instance of it. */
256 if (!(c->state & CLASS_LINKED))
261 if (ip-1 >= (Inst *) ex->startpc && ip-1 < (Inst *) ex->endpc &&
262 (c == NULL || builtin_instanceof(o, c)))
264 #if defined(ENABLE_VMLOG)
265 vmlog_cacao_catch(o);
268 *new_spp = (Cell *)(((u1 *)fp) - framesize - SIZEOF_VOID_P);
270 return (Inst *) (ex->handlerpc);
274 #if defined(ENABLE_THREADS)
275 /* is this method synchronized? */
278 java_objectheader *syncobj;
280 /* get synchronization object */
282 if (m->flags & ACC_STATIC) {
283 syncobj = (java_objectheader *) m->clazz;
286 syncobj = (java_objectheader *) access_local_cell(-framesize + SIZEOF_VOID_P);
289 assert(syncobj != NULL);
291 lock_monitor_exit(syncobj);
293 #endif /* defined(ENABLE_THREADS) */
295 /* unwind stack frame */
297 #if defined(ENABLE_VMLOG)
298 vmlog_cacao_unwnd_method(m);
301 ip = (Inst *)access_local_cell(-framesize - SIZEOF_VOID_P);
302 fp = (Cell *)access_local_cell(-framesize);
309 void intrp_asm_abstractmethoderror(void)
311 vm_abort("intrp_asm_abstractmethoderror: IMPLEMENT ME!");
316 * These are local overrides for various environment variables in Emacs.
317 * Please do not remove this and leave it at the end of the file, where
318 * Emacs will automagically detect them.
319 * ---------------------------------------------------------------------
322 * indent-tabs-mode: t
326 * vim:noexpandtab:sw=4:ts=4: