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
32 $Id: asmpart.c 4550 2006-03-01 17:00:33Z 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"
55 /* true on success, false on exception */
57 static bool intrp_asm_calljavafunction_intern(methodinfo *m,
58 void *arg1, void *arg2,
59 void *arg3, void *arg4)
61 java_objectheader *retval;
72 /* XXX ugly hack: thread's run() needs 5 arguments */
73 assert(md->paramcount < 6);
75 if (md->paramcount > 0)
77 if (md->paramcount > 1)
79 if (md->paramcount > 2)
81 if (md->paramcount > 3)
83 if (md->paramcount > 4)
86 entrypoint = createcalljavafunction(m);
88 retval = engine((Inst *) entrypoint, sp, NULL);
90 /* XXX remove the method from the method table */
93 (void) builtin_throw_exception(retval);
101 java_objectheader *intrp_asm_calljavafunction(methodinfo *m,
102 void *arg1, void *arg2,
103 void *arg3, void *arg4)
105 if (intrp_asm_calljavafunction_intern(m, arg1, arg2, arg3, arg4)) {
106 if (m->parseddesc->returntype.type == TYPE_ADR)
107 return (java_objectheader *)(*global_sp++);
109 assert(m->parseddesc->returntype.type == TYPE_VOID);
117 s4 intrp_asm_calljavafunction_int(methodinfo *m, void *arg1, void *arg2,
118 void *arg3, void *arg4)
120 assert(m->parseddesc->returntype.type == TYPE_INT);
122 if (intrp_asm_calljavafunction_intern(m, arg1, arg2, arg3, arg4))
123 return (s4) (*global_sp++);
129 /* true on success, false on exception */
130 static bool jni_invoke_java_intern(methodinfo *m, u4 count, u4 size,
131 jni_callblock *callblock)
133 java_objectheader *retval;
143 for (i = 0; i < count; i++) {
144 switch (callblock[i].itemtype) {
148 *(--sp) = callblock[i].item;
153 *((u8 *) sp) = callblock[i].item;
158 entrypoint = createcalljavafunction(m);
160 retval = engine((Inst *) entrypoint, sp, NULL);
162 /* XXX remove the method from the method table */
164 if (retval != NULL) {
165 (void)builtin_throw_exception(retval);
173 java_objectheader *intrp_asm_calljavafunction2(methodinfo *m, u4 count, u4 size,
174 jni_callblock *callblock)
176 java_objectheader *retval = NULL;
178 if (jni_invoke_java_intern(m, count, size, callblock)) {
179 if (m->parseddesc->returntype.type == TYPE_ADR)
180 retval = (java_objectheader *)*global_sp++;
182 assert(m->parseddesc->returntype.type == TYPE_VOID);
189 s4 intrp_asm_calljavafunction2int(methodinfo *m, u4 count, u4 size,
190 jni_callblock *callblock)
194 if (jni_invoke_java_intern(m, count, size, callblock)) {
195 if (m->parseddesc->returntype.type == TYPE_INT)
196 retval = *global_sp++;
198 assert(m->parseddesc->returntype.type == TYPE_VOID);
205 s8 intrp_asm_calljavafunction2long(methodinfo *m, u4 count, u4 size,
206 jni_callblock *callblock)
210 assert(m->parseddesc->returntype.type == TYPE_LNG);
212 if (jni_invoke_java_intern(m, count, size, callblock)) {
213 retval = *(s8 *)global_sp;
221 float intrp_asm_calljavafunction2float(methodinfo *m, u4 count, u4 size,
222 jni_callblock *callblock)
226 assert(m->parseddesc->returntype.type == TYPE_FLT);
228 if (jni_invoke_java_intern(m, count, size, callblock)) {
229 retval = *(float *)global_sp;
237 double intrp_asm_calljavafunction2double(methodinfo *m, u4 count, u4 size,
238 jni_callblock *callblock)
242 assert(m->parseddesc->returntype.type == TYPE_DBL);
244 if (jni_invoke_java_intern(m, count, size, callblock)) {
245 retval = *(double *)global_sp;
253 Inst *intrp_asm_handle_exception(Inst *ip, java_objectheader *o, Cell *fp, Cell **new_spp, Cell **new_fpp)
258 s4 exceptiontablelength;
261 /* for a description of the stack see IRETURN in java.vmg */
263 for (; fp != NULL; ) {
264 u1 *f = codegen_findmethod((u1 *) (ip - 1));
266 /* get methodinfo pointer from method header */
268 methodinfo *m = *(methodinfo **) (((u1 *) f) + MethodPointer);
270 framesize = (*((s4 *) (((u1 *) f) + FrameSize)));
271 ex = (exceptionentry *) (((u1 *) f) + ExTableStart);
272 exceptiontablelength = *((s4 *) (((u1 *) f) + ExTableSize));
274 if (opt_verbose || opt_verbosecall || opt_verboseexception)
275 builtin_trace_exception(o, m, ip, 1);
277 for (i = 0; i < exceptiontablelength; i++) {
279 c = ex->catchtype.cls;
282 if (!(c->state & CLASS_LOADED))
284 if (!load_class_bootstrap(c->name))
287 if (!(c->state & CLASS_LINKED))
292 if (ip-1 >= (Inst *) ex->startpc && ip-1 < (Inst *) ex->endpc &&
293 (c == NULL || builtin_instanceof(o, c))) {
294 *new_spp = (Cell *)(((u1 *)fp) - framesize - SIZEOF_VOID_P);
296 return (Inst *) (ex->handlerpc);
300 ip = (Inst *)access_local_cell(-framesize - SIZEOF_VOID_P);
301 fp = (Cell *)access_local_cell(-framesize);
308 void intrp_asm_getclassvalues_atomic(vftbl_t *super, vftbl_t *sub, castinfo *out)
312 #if defined(USE_THREADS)
313 #if defined(NATIVE_THREADS)
320 sbv = super->baseval;
321 sdv = super->diffval;
324 #if defined(USE_THREADS)
325 #if defined(NATIVE_THREADS)
332 out->super_baseval = sbv;
333 out->super_diffval = sdv;
334 out->sub_baseval = sv;
339 * These are local overrides for various environment variables in Emacs.
340 * Please do not remove this and leave it at the end of the file, where
341 * Emacs will automagically detect them.
342 * ---------------------------------------------------------------------
345 * indent-tabs-mode: t