1 /* src/vm/jit/intrp/asmpart.c - Java-C interface functions for Interpreter
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 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., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Christian Thalinger
32 $Id: asmpart.c 4164 2006-01-12 21:38:11Z twisti $
45 #include "vm/builtin.h"
47 #include "vm/exceptions.h"
48 #include "vm/options.h"
49 #include "vm/jit/asmpart.h"
50 #include "vm/jit/methodheader.h"
51 #include "vm/jit/intrp/intrp.h"
54 /* true on success, false on exception */
56 static bool asm_calljavafunction_intern(methodinfo *m, void *arg1, void *arg2,
57 void *arg3, void *arg4)
59 java_objectheader *retval;
62 functionptr entrypoint;
69 /* XXX ugly hack: thread's run() needs 5 arguments */
70 assert(md->paramcount < 6);
72 if (md->paramcount > 0)
74 if (md->paramcount > 1)
76 if (md->paramcount > 2)
78 if (md->paramcount > 3)
80 if (md->paramcount > 4)
83 entrypoint = createcalljavafunction(m);
85 retval = engine((Inst *) entrypoint, sp, NULL);
87 /* XXX remove the method from the method table */
90 (void) builtin_throw_exception(retval);
98 java_objectheader *intrp_asm_calljavafunction(methodinfo *m,
99 void *arg1, void *arg2,
100 void *arg3, void *arg4)
102 if (asm_calljavafunction_intern(m, arg1, arg2, arg3, arg4)) {
103 if (m->parseddesc->returntype.type == TYPE_ADR)
104 return (java_objectheader *)(*global_sp++);
106 assert(m->parseddesc->returntype.type == TYPE_VOID);
114 s4 intrp_asm_calljavafunction_int(methodinfo *m, void *arg1, void *arg2,
115 void *arg3, void *arg4)
117 assert(m->parseddesc->returntype.type == TYPE_INT);
119 if (asm_calljavafunction_intern(m, arg1, arg2, arg3, arg4))
120 return (s4) (*global_sp++);
126 /* true on success, false on exception */
127 static bool jni_invoke_java_intern(methodinfo *m, u4 count, u4 size,
128 jni_callblock *callblock)
130 java_objectheader *retval;
131 Cell *sp = global_sp;
133 functionptr entrypoint;
138 for (i = 0; i < count; i++) {
139 switch (callblock[i].itemtype) {
143 *(--sp) = callblock[i].item;
148 *((u8 *) sp) = callblock[i].item;
153 entrypoint = createcalljavafunction(m);
155 retval = engine((Inst *) entrypoint, sp, NULL);
157 /* XXX remove the method from the method table */
159 if (retval != NULL) {
160 (void)builtin_throw_exception(retval);
168 java_objectheader *intrp_asm_calljavafunction2(methodinfo *m, u4 count, u4 size,
169 jni_callblock *callblock)
171 java_objectheader *retval = NULL;
173 if (jni_invoke_java_intern(m, count, size, callblock)) {
174 if (m->parseddesc->returntype.type == TYPE_ADR)
175 retval = (java_objectheader *)*global_sp++;
177 assert(m->parseddesc->returntype.type == TYPE_VOID);
184 s4 intrp_asm_calljavafunction2int(methodinfo *m, u4 count, u4 size,
185 jni_callblock *callblock)
189 if (jni_invoke_java_intern(m, count, size, callblock)) {
190 if (m->parseddesc->returntype.type == TYPE_INT)
191 retval = *global_sp++;
193 assert(m->parseddesc->returntype.type == TYPE_VOID);
200 s8 intrp_asm_calljavafunction2long(methodinfo *m, u4 count, u4 size,
201 jni_callblock *callblock)
205 assert(m->parseddesc->returntype.type == TYPE_LNG);
207 if (jni_invoke_java_intern(m, count, size, callblock)) {
208 retval = *(s8 *)global_sp;
216 float intrp_asm_calljavafunction2float(methodinfo *m, u4 count, u4 size,
217 jni_callblock *callblock)
221 assert(m->parseddesc->returntype.type == TYPE_FLT);
223 if (jni_invoke_java_intern(m, count, size, callblock)) {
224 retval = *(float *)global_sp;
232 double intrp_asm_calljavafunction2double(methodinfo *m, u4 count, u4 size,
233 jni_callblock *callblock)
237 assert(m->parseddesc->returntype.type == TYPE_DBL);
239 if (jni_invoke_java_intern(m, count, size, callblock)) {
240 retval = *(double *)global_sp;
248 Inst *intrp_asm_handle_exception(Inst *ip, java_objectheader *o, Cell *fp, Cell **new_spp, Cell **new_fpp)
253 s4 exceptiontablelength;
256 /* for a description of the stack see IRETURN in java.vmg */
258 for (; fp != NULL; ) {
259 u1 *f = codegen_findmethod((u1 *) (ip - 1));
261 /* get methodinfo pointer from method header */
263 methodinfo *m = *(methodinfo **) (((u1 *) f) + MethodPointer);
265 framesize = (*((s4 *) (((u1 *) f) + FrameSize)));
266 ex = (exceptionentry *) (((u1 *) f) + ExTableStart);
267 exceptiontablelength = *((s4 *) (((u1 *) f) + ExTableSize));
269 if (opt_verbose || runverbose || opt_verboseexception)
270 builtin_trace_exception(o, m, ip, 1);
272 for (i = 0; i < exceptiontablelength; i++) {
274 c = ex->catchtype.cls;
277 if (!(c->state & CLASS_LOADED))
279 if (!load_class_bootstrap(c->name))
282 if (!(c->state & CLASS_LINKED))
287 if (ip-1 >= (Inst *) ex->startpc && ip-1 < (Inst *) ex->endpc &&
288 (c == NULL || builtin_instanceof(o, c))) {
289 *new_spp = (Cell *)(((u1 *)fp) - framesize - SIZEOF_VOID_P);
291 return (Inst *) (ex->handlerpc);
295 ip = (Inst *)access_local_cell(-framesize - SIZEOF_VOID_P);
296 fp = (Cell *)access_local_cell(-framesize);
303 void intrp_asm_getclassvalues_atomic(vftbl_t *super, vftbl_t *sub, castinfo *out)
307 #if defined(USE_THREADS)
308 #if defined(NATIVE_THREADS)
315 sbv = super->baseval;
316 sdv = super->diffval;
319 #if defined(USE_THREADS)
320 #if defined(NATIVE_THREADS)
327 out->super_baseval = sbv;
328 out->super_diffval = sdv;
329 out->sub_baseval = sv;
334 * These are local overrides for various environment variables in Emacs.
335 * Please do not remove this and leave it at the end of the file, where
336 * Emacs will automagically detect them.
337 * ---------------------------------------------------------------------
340 * indent-tabs-mode: t