1 /* src/vm/jit/intrp/asmpart.c - Java-C interface functions for Interpreter
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
8 This file is part of CACAO.
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.
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.
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
25 Contact: cacao@cacaojvm.org
27 Authors: Christian Thalinger
30 Changes: Edwin Steiner
32 $Id: asmpart.c 5812 2006-10-20 14:22:23Z twisti $
45 #include "vm/builtin.h"
47 #include "vm/exceptions.h"
48 #include "vm/loader.h"
49 #include "vm/options.h"
50 #include "vm/jit/asmpart.h"
51 #include "vm/jit/methodheader.h"
52 #include "vm/jit/intrp/intrp.h"
53 #include "vm/jit/dseg.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 = codegen_get_pv_from_pc((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 for (i = 0; i < exceptiontablelength; i++) {
213 if (cr.any == NULL) {
218 if (IS_CLASSREF(cr)) {
219 /* The exception class reference is unresolved. */
220 /* We have to do _eager_ resolving here. While the class of */
221 /* the exception object is guaranteed to be loaded, it may */
222 /* well have been loaded by a different loader than the */
223 /* defining loader of m's class, which is the one we must */
224 /* use to resolve the catch class. Thus lazy resolving */
225 /* might fail, even if the result of the resolution would */
226 /* be an already loaded class. */
228 /* The resolving may involve Java code, so we need a usable */
229 /* global_sp. XXX is this a correct value for global_sp? */
231 global_sp = (Cell *)(((u1 *)fp) - framesize - SIZEOF_VOID_P);
233 c = resolve_classref_eager(cr.ref);
238 /* Exception resolving the exception class, argh! */
239 /* XXX how to report that error? */
243 /* Ok, we resolved it. Enter it in the table, so we don't */
244 /* have to do this again. */
245 /* XXX this write should be atomic. Is it? */
247 ex->catchtype.cls = c;
252 /* If the class is not linked, the exception object cannot */
253 /* be an instance of it. */
254 if (!(c->state & CLASS_LINKED))
259 if (ip-1 >= (Inst *) ex->startpc && ip-1 < (Inst *) ex->endpc &&
260 (c == NULL || builtin_instanceof(o, c)))
262 *new_spp = (Cell *)(((u1 *)fp) - framesize - SIZEOF_VOID_P);
264 return (Inst *) (ex->handlerpc);
268 #if defined(ENABLE_THREADS)
269 /* is this method synchronized? */
272 java_objectheader *syncobj;
274 /* get synchronization object */
276 if (m->flags & ACC_STATIC) {
277 syncobj = (java_objectheader *) m->class;
280 syncobj = (java_objectheader *) access_local_cell(-framesize + SIZEOF_VOID_P);
283 assert(syncobj != NULL);
285 lock_monitor_exit(syncobj);
287 #endif /* defined(ENABLE_THREADS) */
289 /* unwind stack frame */
291 ip = (Inst *)access_local_cell(-framesize - SIZEOF_VOID_P);
292 fp = (Cell *)access_local_cell(-framesize);
299 void intrp_asm_abstractmethoderror(void)
301 vm_abort("intrp_asm_abstractmethoderror: IMPLEMENT ME!");
305 void intrp_asm_getclassvalues_atomic(vftbl_t *super, vftbl_t *sub, castinfo *out)
309 #if defined(ENABLE_THREADS)
313 sbv = super->baseval;
314 sdv = super->diffval;
317 #if defined(ENABLE_THREADS)
321 out->super_baseval = sbv;
322 out->super_diffval = sdv;
323 out->sub_baseval = sv;
328 * These are local overrides for various environment variables in Emacs.
329 * Please do not remove this and leave it at the end of the file, where
330 * Emacs will automagically detect them.
331 * ---------------------------------------------------------------------
334 * indent-tabs-mode: t
338 * vim:noexpandtab:sw=4:ts=4: