1 /* src/vm/jit/intrp/codegen.c - code generator 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: Andreas Krall
30 Changes: Christian Thalinger
33 $Id: codegen.c 4351 2006-01-22 21:42:16Z twisti $
47 #include "vm/jit/intrp/codegen.h"
48 #include "vm/jit/intrp/intrp.h"
50 #include "cacao/cacao.h"
51 #include "native/native.h"
52 #include "vm/builtin.h"
54 #include "vm/exceptions.h"
55 #include "vm/global.h"
56 #include "vm/options.h"
57 #include "vm/stringlocal.h"
58 #include "vm/jit/asmpart.h"
59 #include "vm/jit/codegen-common.h"
60 #include "vm/jit/dseg.h"
61 #include "vm/jit/jit.h"
62 #include "vm/jit/parse.h"
63 #include "vm/jit/patcher.h"
67 #elif defined(WITH_FFCALL)
70 # error neither WITH_FFI nor WITH_FFCALL defined
74 #define gen_branch(_inst) { \
76 codegen_addreference(cd, (basicblock *) (iptr->target), cd->mcodeptr); \
79 #define index2offset(_i) (-(_i) * SIZEOF_VOID_P)
81 /* functions used by cacao-gen.i */
83 void genarg_v(codegendata *cd1, Cell v)
85 Inst **mcodepp = (Inst **) &(cd1->mcodeptr);
86 *((Cell *) *mcodepp) = v;
90 void genarg_i(codegendata *cd1, s4 i)
92 Inst **mcodepp = (Inst **) &(cd1->mcodeptr);
93 *((Cell *) *mcodepp) = i;
97 void genarg_b(codegendata *cd1, s4 i)
102 void genarg_f(codegendata *cd1, float f)
110 void genarg_l(codegendata *cd1, s8 l)
112 Inst **mcodepp = (Inst **) &(cd1->mcodeptr);
113 vm_l2twoCell(l, ((Cell *) *mcodepp)[1], ((Cell *) *mcodepp)[0]);
117 void genarg_aRef(codegendata *cd1, java_objectheader *a)
119 Inst **mcodepp = (Inst **) &(cd1->mcodeptr);
120 *((java_objectheader **) *mcodepp) = a;
124 void genarg_aArray(codegendata *cd1, java_arrayheader *a)
126 Inst **mcodepp = (Inst **) &(cd1->mcodeptr);
127 *((java_arrayheader **) *mcodepp) = a;
131 void genarg_aaTarget(codegendata *cd1, Inst **a)
133 Inst **mcodepp = (Inst **) &(cd1->mcodeptr);
134 *((Inst ***) *mcodepp) = a;
138 void genarg_aClass(codegendata *cd1, classinfo *a)
140 Inst **mcodepp = (Inst **) &(cd1->mcodeptr);
141 *((classinfo **) *mcodepp) = a;
145 void genarg_acr(codegendata *cd1, constant_classref *a)
147 Inst **mcodepp = (Inst **) &(cd1->mcodeptr);
148 *((constant_classref **) *mcodepp) = a;
152 void genarg_addr(codegendata *cd1, u1 *a)
154 Inst **mcodepp = (Inst **) &(cd1->mcodeptr);
155 *((u1 **) *mcodepp) = a;
159 void genarg_af(codegendata *cd1, functionptr a)
161 Inst **mcodepp = (Inst **) &(cd1->mcodeptr);
162 *((functionptr *) *mcodepp) = a;
166 void genarg_am(codegendata *cd1, methodinfo *a)
168 Inst **mcodepp = (Inst **) &(cd1->mcodeptr);
169 *((methodinfo **) *mcodepp) = a;
173 void genarg_acell(codegendata *cd1, Cell *a)
175 Inst **mcodepp = (Inst **) &(cd1->mcodeptr);
176 *((Cell **) *mcodepp) = a;
180 void genarg_ainst(codegendata *cd1, Inst *a)
182 Inst **mcodepp = (Inst **) &(cd1->mcodeptr);
183 *((Inst **) *mcodepp) = a;
187 void genarg_auf(codegendata *cd1, unresolved_field *a)
189 Inst **mcodepp = (Inst **) &(cd1->mcodeptr);
190 *((unresolved_field **) *mcodepp) = a;
194 void genarg_aum(codegendata *cd1, unresolved_method *a)
196 Inst **mcodepp = (Inst **) &(cd1->mcodeptr);
197 *((unresolved_method **) *mcodepp) = a;
201 void genarg_avftbl(codegendata *cd1, vftbl_t *a)
203 Inst **mcodepp = (Inst **) &(cd1->mcodeptr);
204 *((vftbl_t **) *mcodepp) = a;
209 /* include the interpreter generation functions *******************************/
211 #include "vm/jit/intrp/java-gen.i"
214 typedef void (*genfunctionptr) (codegendata *);
216 typedef struct builtin_gen builtin_gen;
223 struct builtin_gen builtin_gen_table[] = {
224 {BUILTIN_new, gen_NEW, },
225 {BUILTIN_newarray, gen_NEWARRAY, },
226 {BUILTIN_newarray_boolean, gen_NEWARRAY_BOOLEAN,},
227 {BUILTIN_newarray_byte, gen_NEWARRAY_BYTE, },
228 {BUILTIN_newarray_char, gen_NEWARRAY_CHAR, },
229 {BUILTIN_newarray_short, gen_NEWARRAY_SHORT, },
230 {BUILTIN_newarray_int, gen_NEWARRAY_INT, },
231 {BUILTIN_newarray_long, gen_NEWARRAY_LONG, },
232 {BUILTIN_newarray_float, gen_NEWARRAY_FLOAT, },
233 {BUILTIN_newarray_double, gen_NEWARRAY_DOUBLE, },
234 {BUILTIN_arrayinstanceof, gen_ARRAYINSTANCEOF, },
236 #if defined(USE_THREADS)
237 {BUILTIN_monitorenter, gen_MONITORENTER, },
238 {BUILTIN_monitorexit, gen_MONITOREXIT, },
241 #if !(SUPPORT_FLOAT && SUPPORT_LONG && SUPPORT_F2L)
242 {BUILTIN_f2l, gen_F2L, },
245 #if !(SUPPORT_DOUBLE && SUPPORT_LONG && SUPPORT_D2L)
246 {BUILTIN_d2l, gen_D2L, },
249 #if !(SUPPORT_FLOAT && SUPPORT_F2I)
250 {BUILTIN_f2i, gen_F2I, },
253 #if !(SUPPORT_DOUBLE && SUPPORT_D2I)
254 {BUILTIN_d2i, gen_D2I, },
257 #if !SUPPORT_DIVISION
258 {BUILTIN_idiv, gen_IDIV, },
259 {BUILTIN_irem, gen_IREM, },
262 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
263 {BUILTIN_ldiv, gen_LDIV, },
264 {BUILTIN_lrem, gen_LREM, },
267 {BUILTIN_frem, gen_FREM, },
268 {BUILTIN_drem, gen_DREM, },
272 /* codegen *********************************************************************
274 Generates machine code.
276 *******************************************************************************/
278 bool intrp_codegen(methodinfo *m, codegendata *cd, registerdata *rd)
280 s4 i, len, s1, s2, d;
286 methodinfo *lm; /* local methodinfo for ICMD_INVOKE* */
287 unresolved_method *um;
288 builtintable_entry *bte;
291 /* prevent compiler warnings */
298 /* create method header */
300 (void) dseg_addaddress(cd, m); /* MethodPointer */
301 (void) dseg_adds4(cd, m->maxlocals * SIZEOF_VOID_P); /* FrameSize */
303 #if defined(USE_THREADS)
304 if (checksync && (m->flags & ACC_SYNCHRONIZED))
305 (void) dseg_adds4(cd, 1); /* IsSync */
308 (void) dseg_adds4(cd, 0); /* IsSync */
310 (void) dseg_adds4(cd, 0); /* IsLeaf */
311 (void) dseg_adds4(cd, 0); /* IntSave */
312 (void) dseg_adds4(cd, 0); /* FltSave */
314 dseg_addlinenumbertablesize(cd);
316 (void) dseg_adds4(cd, cd->exceptiontablelength); /* ExTableSize */
318 /* create exception table */
320 for (ex = cd->exceptiontable; ex != NULL; ex = ex->down) {
321 dseg_addtarget(cd, ex->start);
322 dseg_addtarget(cd, ex->end);
323 dseg_addtarget(cd, ex->handler);
324 (void) dseg_addaddress(cd, ex->catchtype.cls);
328 /* initialize mcode variables */
330 cd->mcodeptr = cd->mcodebase;
331 cd->mcodeend = (s4 *) (cd->mcodebase + cd->mcodesize);
336 #if defined(USE_THREADS)
337 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
338 if (m->flags & ACC_STATIC)
339 gen_ACONST(cd, (java_objectheader *) m->class);
343 gen_MONITORENTER(cd);
348 gen_TRACECALL(cd, m);
352 /* walk through all basic blocks */
354 for (bptr = m->basicblocks; bptr != NULL; bptr = bptr->next) {
356 bptr->mpc = (s4) (cd->mcodeptr - cd->mcodebase);
358 if (bptr->flags >= BBREACHED) {
360 /* walk through all instructions */
367 for (iptr = bptr->iinstr; len > 0; src = iptr->dst, len--, iptr++) {
368 if (iptr->line != currentline) {
369 dseg_addlinenumber(cd, iptr->line, cd->mcodeptr);
370 currentline = iptr->line;
373 MCODECHECK(64); /* an instruction usually needs < 64 words */
377 case ICMD_INLINE_START:
378 case ICMD_INLINE_END:
381 case ICMD_NOP: /* ... ==> ... */
384 case ICMD_CHECKNULL: /* ..., objectref ==> ..., objectref */
389 /* constant operations ************************************************/
391 case ICMD_ICONST: /* ... ==> ..., constant */
392 /* op1 = 0, val.i = constant */
394 gen_ICONST(cd, iptr->val.i);
397 case ICMD_LCONST: /* ... ==> ..., constant */
398 /* op1 = 0, val.l = constant */
400 gen_LCONST(cd, iptr->val.l);
403 case ICMD_FCONST: /* ... ==> ..., constant */
404 /* op1 = 0, val.f = constant */
408 vm_f2Cell(iptr->val.f, fi);
413 case ICMD_DCONST: /* ... ==> ..., constant */
414 /* op1 = 0, val.d = constant */
416 gen_LCONST(cd, *(s8 *)&(iptr->val.d));
419 case ICMD_ACONST: /* ... ==> ..., constant */
420 /* op1 = 0, val.a = constant */
422 if ((iptr->target != NULL) && (iptr->val.a == NULL))
423 gen_PATCHER_ACONST(cd, NULL, iptr->target);
425 gen_ACONST(cd, iptr->val.a);
429 /* load/store operations **********************************************/
431 case ICMD_ILOAD: /* ... ==> ..., content of local variable */
432 /* op1 = local variable */
434 gen_ILOAD(cd, index2offset(iptr->op1));
437 case ICMD_LLOAD: /* ... ==> ..., content of local variable */
438 /* op1 = local variable */
440 gen_LLOAD(cd, index2offset(iptr->op1));
443 case ICMD_ALOAD: /* ... ==> ..., content of local variable */
444 /* op1 = local variable */
446 gen_ALOAD(cd, index2offset(iptr->op1));
449 case ICMD_FLOAD: /* ... ==> ..., content of local variable */
450 /* op1 = local variable */
452 gen_ILOAD(cd, index2offset(iptr->op1));
455 case ICMD_DLOAD: /* ... ==> ..., content of local variable */
456 /* op1 = local variable */
458 gen_LLOAD(cd, index2offset(iptr->op1));
462 case ICMD_ISTORE: /* ..., value ==> ... */
463 /* op1 = local variable */
465 gen_ISTORE(cd, index2offset(iptr->op1));
468 case ICMD_LSTORE: /* ..., value ==> ... */
469 /* op1 = local variable */
471 gen_LSTORE(cd, index2offset(iptr->op1));
474 case ICMD_ASTORE: /* ..., value ==> ... */
475 /* op1 = local variable */
477 gen_ASTORE(cd, index2offset(iptr->op1));
481 case ICMD_FSTORE: /* ..., value ==> ... */
482 /* op1 = local variable */
484 gen_ISTORE(cd, index2offset(iptr->op1));
487 case ICMD_DSTORE: /* ..., value ==> ... */
488 /* op1 = local variable */
490 gen_LSTORE(cd, index2offset(iptr->op1));
494 /* pop/dup/swap operations ********************************************/
496 /* attention: double and longs are only one entry in CACAO ICMDs */
498 /* stack.c changes stack manipulation operations to treat
499 longs/doubles as occupying a single slot. Here we are
500 undoing that (and only those things that stack.c did). */
502 case ICMD_POP: /* ..., value ==> ... */
504 if (IS_2_WORD_TYPE(src->type))
510 case ICMD_POP2: /* ..., value, value ==> ... */
515 case ICMD_DUP: /* ..., a ==> ..., a, a */
517 if (IS_2_WORD_TYPE(src->type))
523 case ICMD_DUP_X1: /* ..., a, b ==> ..., b, a, b */
525 if (IS_2_WORD_TYPE(src->type)) {
526 if (IS_2_WORD_TYPE(src->prev->type)) {
532 if (IS_2_WORD_TYPE(src->prev->type)) {
540 case ICMD_DUP_X2: /* ..., a, b, c ==> ..., c, a, b, c */
542 if (IS_2_WORD_TYPE(src->type)) {
548 case ICMD_DUP2: /* ..., a, b ==> ..., a, b, a, b */
553 case ICMD_DUP2_X1: /* ..., a, b, c ==> ..., b, c, a, b, c */
555 if (IS_2_WORD_TYPE(src->prev->prev->type))
561 case ICMD_DUP2_X2: /* ..., a, b, c, d ==> ..., c, d, a, b, c, d */
566 case ICMD_SWAP: /* ..., a, b ==> ..., b, a */
572 /* integer operations *************************************************/
574 case ICMD_INEG: /* ..., value ==> ..., - value */
579 case ICMD_LNEG: /* ..., value ==> ..., - value */
584 case ICMD_I2L: /* ..., value ==> ..., value */
589 case ICMD_L2I: /* ..., value ==> ..., value */
594 case ICMD_INT2BYTE: /* ..., value ==> ..., value */
599 case ICMD_INT2CHAR: /* ..., value ==> ..., value */
604 case ICMD_INT2SHORT: /* ..., value ==> ..., value */
610 case ICMD_IADD: /* ..., val1, val2 ==> ..., val1 + val2 */
615 case ICMD_IADDCONST: /* ..., value ==> ..., value + constant */
616 /* val.i = constant */
618 gen_ICONST(cd, iptr->val.i);
622 case ICMD_LADD: /* ..., val1, val2 ==> ..., val1 + val2 */
627 case ICMD_LADDCONST: /* ..., value ==> ..., value + constant */
628 /* val.l = constant */
630 gen_LCONST(cd, iptr->val.l);
634 case ICMD_ISUB: /* ..., val1, val2 ==> ..., val1 - val2 */
639 case ICMD_ISUBCONST: /* ..., value ==> ..., value + constant */
640 /* val.i = constant */
642 gen_ICONST(cd, iptr->val.i);
646 case ICMD_LSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
651 case ICMD_LSUBCONST: /* ..., value ==> ..., value - constant */
652 /* val.l = constant */
654 gen_LCONST(cd, iptr->val.l);
658 case ICMD_IMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
663 case ICMD_IMULCONST: /* ..., val1, val2 ==> ..., val1 * val2 */
665 gen_ICONST(cd, iptr->val.i);
669 case ICMD_LMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
674 case ICMD_LMULCONST: /* ..., val1, val2 ==> ..., val1 * val2 */
676 gen_LCONST(cd, iptr->val.l);
680 case ICMD_IDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
685 case ICMD_IREM: /* ..., val1, val2 ==> ..., val1 % val2 */
690 case ICMD_LDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
695 case ICMD_LREM: /* ..., val1, val2 ==> ..., val1 % val2 */
700 case ICMD_IDIVPOW2: /* ..., value ==> ..., value << constant */
701 /* val.i = constant */
703 gen_IDIVPOW2(cd, iptr->val.i);
706 case ICMD_IREMPOW2: /* ..., value ==> ..., value % constant */
707 /* val.i = constant */
709 gen_IREMPOW2(cd, iptr->val.i);
712 case ICMD_LDIVPOW2: /* ..., value ==> ..., value << constant */
713 /* val.i = constant */
715 gen_LDIVPOW2(cd, iptr->val.i);
718 case ICMD_LREMPOW2: /* ..., value ==> ..., value % constant */
719 /* val.l = constant */
721 gen_LREMPOW2(cd, iptr->val.i);
724 case ICMD_ISHL: /* ..., val1, val2 ==> ..., val1 << val2 */
729 case ICMD_ISHLCONST: /* ..., value ==> ..., value << constant */
730 /* val.i = constant */
732 gen_ICONST(cd, iptr->val.i);
736 case ICMD_ISHR: /* ..., val1, val2 ==> ..., val1 >> val2 */
741 case ICMD_ISHRCONST: /* ..., value ==> ..., value >> constant */
742 /* val.i = constant */
744 gen_ICONST(cd, iptr->val.i);
748 case ICMD_IUSHR: /* ..., val1, val2 ==> ..., val1 >>> val2 */
753 case ICMD_IUSHRCONST: /* ..., value ==> ..., value >>> constant */
754 /* val.i = constant */
756 gen_ICONST(cd, iptr->val.i);
760 case ICMD_LSHL: /* ..., val1, val2 ==> ..., val1 << val2 */
765 case ICMD_LSHLCONST: /* ..., value ==> ..., value << constant */
766 /* val.i = constant */
768 gen_ICONST(cd, iptr->val.i);
772 case ICMD_LSHR: /* ..., val1, val2 ==> ..., val1 >> val2 */
777 case ICMD_LSHRCONST: /* ..., value ==> ..., value >> constant */
778 /* val.i = constant */
780 gen_ICONST(cd, iptr->val.i);
784 case ICMD_LUSHR: /* ..., val1, val2 ==> ..., val1 >>> val2 */
789 case ICMD_LUSHRCONST: /* ..., value ==> ..., value >>> constant */
790 /* val.i = constant */
792 gen_ICONST(cd, iptr->val.i);
796 case ICMD_IAND: /* ..., val1, val2 ==> ..., val1 & val2 */
801 case ICMD_IANDCONST: /* ..., value ==> ..., value & constant */
802 /* val.i = constant */
804 gen_ICONST(cd, iptr->val.i);
808 case ICMD_LAND: /* ..., val1, val2 ==> ..., val1 & val2 */
813 case ICMD_LANDCONST: /* ..., value ==> ..., value & constant */
814 /* val.l = constant */
816 gen_LCONST(cd, iptr->val.l);
820 case ICMD_IOR: /* ..., val1, val2 ==> ..., val1 | val2 */
825 case ICMD_IORCONST: /* ..., value ==> ..., value | constant */
826 /* val.i = constant */
828 gen_ICONST(cd, iptr->val.i);
832 case ICMD_LOR: /* ..., val1, val2 ==> ..., val1 | val2 */
837 case ICMD_LORCONST: /* ..., value ==> ..., value | constant */
838 /* val.l = constant */
840 gen_LCONST(cd, iptr->val.l);
844 case ICMD_IXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
849 case ICMD_IXORCONST: /* ..., value ==> ..., value ^ constant */
850 /* val.i = constant */
852 gen_ICONST(cd, iptr->val.i);
856 case ICMD_LXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
861 case ICMD_LXORCONST: /* ..., value ==> ..., value ^ constant */
862 /* val.l = constant */
864 gen_LCONST(cd, iptr->val.l);
869 case ICMD_LCMP: /* ..., val1, val2 ==> ..., val1 cmp val2 */
875 case ICMD_IINC: /* ..., value ==> ..., value + constant */
876 /* op1 = variable, val.i = constant */
878 gen_IINC(cd, index2offset(iptr->op1), iptr->val.i);
882 /* floating operations ************************************************/
884 case ICMD_FNEG: /* ..., value ==> ..., - value */
889 case ICMD_DNEG: /* ..., value ==> ..., - value */
894 case ICMD_FADD: /* ..., val1, val2 ==> ..., val1 + val2 */
899 case ICMD_DADD: /* ..., val1, val2 ==> ..., val1 + val2 */
904 case ICMD_FSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
909 case ICMD_DSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
914 case ICMD_FMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
919 case ICMD_DMUL: /* ..., val1, val2 ==> ..., val1 *** val2 */
924 case ICMD_FDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
929 case ICMD_DDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
934 case ICMD_FREM: /* ..., val1, val2 ==> ..., val1 % val2 */
939 case ICMD_DREM: /* ..., val1, val2 ==> ..., val1 % val2 */
944 case ICMD_I2F: /* ..., value ==> ..., (float) value */
949 case ICMD_L2F: /* ..., value ==> ..., (float) value */
954 case ICMD_I2D: /* ..., value ==> ..., (double) value */
959 case ICMD_L2D: /* ..., value ==> ..., (double) value */
964 case ICMD_F2I: /* ..., value ==> ..., (int) value */
969 case ICMD_D2I: /* ..., value ==> ..., (int) value */
974 case ICMD_F2L: /* ..., value ==> ..., (long) value */
979 case ICMD_D2L: /* ..., value ==> ..., (long) value */
984 case ICMD_F2D: /* ..., value ==> ..., (double) value */
989 case ICMD_D2F: /* ..., value ==> ..., (float) value */
994 case ICMD_FCMPL: /* ..., val1, val2 ==> ..., val1 fcmpl val2 */
999 case ICMD_DCMPL: /* ..., val1, val2 ==> ..., val1 fcmpl val2 */
1004 case ICMD_FCMPG: /* ..., val1, val2 ==> ..., val1 fcmpg val2 */
1009 case ICMD_DCMPG: /* ..., val1, val2 ==> ..., val1 fcmpg val2 */
1015 /* memory operations **************************************************/
1017 case ICMD_ARRAYLENGTH: /* ..., arrayref ==> ..., length */
1019 gen_ARRAYLENGTH(cd);
1022 case ICMD_BALOAD: /* ..., arrayref, index ==> ..., value */
1027 case ICMD_CALOAD: /* ..., arrayref, index ==> ..., value */
1032 case ICMD_SALOAD: /* ..., arrayref, index ==> ..., value */
1037 case ICMD_IALOAD: /* ..., arrayref, index ==> ..., value */
1042 case ICMD_FALOAD: /* ..., arrayref, index ==> ..., value */
1047 case ICMD_LALOAD: /* ..., arrayref, index ==> ..., value */
1048 case ICMD_DALOAD: /* ..., arrayref, index ==> ..., value */
1053 case ICMD_AALOAD: /* ..., arrayref, index ==> ..., value */
1059 case ICMD_BASTORE: /* ..., arrayref, index, value ==> ... */
1064 case ICMD_CASTORE: /* ..., arrayref, index, value ==> ... */
1065 case ICMD_SASTORE: /* ..., arrayref, index, value ==> ... */
1070 case ICMD_IASTORE: /* ..., arrayref, index, value ==> ... */
1075 case ICMD_FASTORE: /* ..., arrayref, index, value ==> ... */
1080 case ICMD_LASTORE: /* ..., arrayref, index, value ==> ... */
1081 case ICMD_DASTORE: /* ..., arrayref, index, value ==> ... */
1086 case ICMD_AASTORE: /* ..., arrayref, index, value ==> ... */
1092 case ICMD_GETSTATIC: /* ... ==> ..., value */
1093 /* op1 = type, val.a = field address */
1096 fieldinfo *fi = iptr->val.a;
1097 unresolved_field *uf = iptr->target;
1099 switch (iptr->op1) {
1101 if ((fi == NULL) || !CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1102 gen_PATCHER_GETSTATIC_INT(cd, 0, uf);
1104 gen_GETSTATIC_INT(cd, (u1 *)&(fi->value.i), uf);
1108 if ((fi == NULL) || !CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1109 gen_PATCHER_GETSTATIC_FLOAT(cd, 0, uf);
1111 gen_GETSTATIC_FLOAT(cd, (u1 *)&(fi->value.i), uf);
1116 if ((fi == NULL) || !CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1117 gen_PATCHER_GETSTATIC_LONG(cd, 0, uf);
1119 gen_GETSTATIC_LONG(cd, (u1 *)&(fi->value.l), uf);
1123 if ((fi == NULL) || !CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1124 gen_PATCHER_GETSTATIC_CELL(cd, 0, uf);
1126 gen_GETSTATIC_CELL(cd, (u1 *)&(fi->value.a), uf);
1133 case ICMD_PUTSTATIC: /* ..., value ==> ... */
1134 /* op1 = type, val.a = field address */
1137 fieldinfo *fi = iptr->val.a;
1138 unresolved_field *uf = iptr->target;
1140 switch (iptr->op1) {
1142 if ((fi == NULL) || !CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1143 gen_PATCHER_PUTSTATIC_INT(cd, 0, uf);
1145 gen_PUTSTATIC_INT(cd, (u1 *)&(fi->value.i), uf);
1149 if ((fi == NULL) || !CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1150 gen_PATCHER_PUTSTATIC_FLOAT(cd, 0, uf);
1152 gen_PUTSTATIC_FLOAT(cd, (u1 *)&(fi->value.i), uf);
1157 if ((fi == NULL) || !CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1158 gen_PATCHER_PUTSTATIC_LONG(cd, 0, uf);
1160 gen_PUTSTATIC_LONG(cd, (u1 *)&(fi->value.l), uf);
1164 if ((fi == NULL) || !CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1165 gen_PATCHER_PUTSTATIC_CELL(cd, 0, uf);
1167 gen_PUTSTATIC_CELL(cd, (u1 *)&(fi->value.a), uf);
1175 case ICMD_GETFIELD: /* ... ==> ..., value */
1176 /* op1 = type, val.a = field address */
1179 fieldinfo *fi = iptr->val.a;
1180 unresolved_field *uf = iptr->target;
1182 switch (iptr->op1) {
1185 gen_PATCHER_GETFIELD_INT(cd, 0, uf);
1187 gen_GETFIELD_INT(cd, fi->offset, uf);
1192 gen_PATCHER_GETFIELD_FLOAT(cd, 0, uf);
1194 gen_GETFIELD_FLOAT(cd, fi->offset, uf);
1200 gen_PATCHER_GETFIELD_LONG(cd, 0, uf);
1202 gen_GETFIELD_LONG(cd, fi->offset, uf);
1207 gen_PATCHER_GETFIELD_CELL(cd, 0, uf);
1209 gen_GETFIELD_CELL(cd, fi->offset, uf);
1216 case ICMD_PUTFIELD: /* ..., objectref, value ==> ... */
1217 /* op1 = type, val.a = field address */
1220 fieldinfo *fi = iptr->val.a;
1221 unresolved_field *uf = iptr->target;
1223 switch (iptr->op1) {
1226 gen_PATCHER_PUTFIELD_INT(cd, 0, uf);
1228 gen_PUTFIELD_INT(cd, fi->offset, uf);
1233 gen_PATCHER_PUTFIELD_FLOAT(cd, 0, uf);
1235 gen_PUTFIELD_FLOAT(cd, fi->offset, uf);
1241 gen_PATCHER_PUTFIELD_LONG(cd, 0, uf);
1243 gen_PUTFIELD_LONG(cd, fi->offset, uf);
1248 gen_PATCHER_PUTFIELD_CELL(cd, 0, uf);
1250 gen_PUTFIELD_CELL(cd, fi->offset, uf);
1258 /* branch operations **************************************************/
1260 case ICMD_ATHROW: /* ..., objectref ==> ... (, objectref) */
1265 case ICMD_GOTO: /* ... ==> ... */
1266 /* op1 = target JavaVM pc */
1270 case ICMD_JSR: /* ... ==> ... */
1271 /* op1 = target JavaVM pc */
1275 case ICMD_RET: /* ... ==> ... */
1276 /* op1 = local variable */
1278 gen_RET(cd, index2offset(iptr->op1));
1281 case ICMD_IFNULL: /* ..., value ==> ... */
1282 /* op1 = target JavaVM pc */
1287 case ICMD_IFNONNULL: /* ..., value ==> ... */
1288 /* op1 = target JavaVM pc */
1290 gen_branch(IFNONNULL);
1293 case ICMD_IFEQ: /* ..., value ==> ... */
1294 /* op1 = target JavaVM pc, val.i = constant */
1296 if (iptr->val.i == 0) {
1299 gen_ICONST(cd, iptr->val.i);
1300 gen_branch(IF_ICMPEQ);
1304 case ICMD_IFLT: /* ..., value ==> ... */
1305 /* op1 = target JavaVM pc, val.i = constant */
1307 if (iptr->val.i == 0) {
1310 gen_ICONST(cd, iptr->val.i);
1311 gen_branch(IF_ICMPLT);
1315 case ICMD_IFLE: /* ..., value ==> ... */
1316 /* op1 = target JavaVM pc, val.i = constant */
1318 if (iptr->val.i == 0) {
1321 gen_ICONST(cd, iptr->val.i);
1322 gen_branch(IF_ICMPLE);
1326 case ICMD_IFNE: /* ..., value ==> ... */
1327 /* op1 = target JavaVM pc, val.i = constant */
1329 if (iptr->val.i == 0) {
1332 gen_ICONST(cd, iptr->val.i);
1333 gen_branch(IF_ICMPNE);
1337 case ICMD_IFGT: /* ..., value ==> ... */
1338 /* op1 = target JavaVM pc, val.i = constant */
1340 if (iptr->val.i == 0) {
1343 gen_ICONST(cd, iptr->val.i);
1344 gen_branch(IF_ICMPGT);
1348 case ICMD_IFGE: /* ..., value ==> ... */
1349 /* op1 = target JavaVM pc, val.i = constant */
1351 if (iptr->val.i == 0) {
1354 gen_ICONST(cd, iptr->val.i);
1355 gen_branch(IF_ICMPGE);
1359 case ICMD_IF_LEQ: /* ..., value ==> ... */
1360 /* op1 = target JavaVM pc, val.l = constant */
1362 gen_LCONST(cd, iptr->val.l);
1363 gen_branch(IF_LCMPEQ);
1366 case ICMD_IF_LLT: /* ..., value ==> ... */
1367 /* op1 = target JavaVM pc, val.l = constant */
1369 gen_LCONST(cd, iptr->val.l);
1370 gen_branch(IF_LCMPLT);
1373 case ICMD_IF_LLE: /* ..., value ==> ... */
1374 /* op1 = target JavaVM pc, val.l = constant */
1376 gen_LCONST(cd, iptr->val.l);
1377 gen_branch(IF_LCMPLE);
1380 case ICMD_IF_LNE: /* ..., value ==> ... */
1381 /* op1 = target JavaVM pc, val.l = constant */
1383 gen_LCONST(cd, iptr->val.l);
1384 gen_branch(IF_LCMPNE);
1387 case ICMD_IF_LGT: /* ..., value ==> ... */
1388 /* op1 = target JavaVM pc, val.l = constant */
1390 gen_LCONST(cd, iptr->val.l);
1391 gen_branch(IF_LCMPGT);
1394 case ICMD_IF_LGE: /* ..., value ==> ... */
1395 /* op1 = target JavaVM pc, val.l = constant */
1397 gen_LCONST(cd, iptr->val.l);
1398 gen_branch(IF_LCMPGE);
1401 case ICMD_IF_ICMPEQ: /* ..., value, value ==> ... */
1402 /* op1 = target JavaVM pc */
1404 gen_branch(IF_ICMPEQ);
1407 case ICMD_IF_LCMPEQ: /* ..., value, value ==> ... */
1408 /* op1 = target JavaVM pc */
1410 gen_branch(IF_LCMPEQ);
1413 case ICMD_IF_ACMPEQ: /* ..., value, value ==> ... */
1414 /* op1 = target JavaVM pc */
1416 gen_branch(IF_ACMPEQ);
1419 case ICMD_IF_ICMPNE: /* ..., value, value ==> ... */
1420 /* op1 = target JavaVM pc */
1422 gen_branch(IF_ICMPNE);
1425 case ICMD_IF_LCMPNE: /* ..., value, value ==> ... */
1426 /* op1 = target JavaVM pc */
1428 gen_branch(IF_LCMPNE);
1431 case ICMD_IF_ACMPNE: /* ..., value, value ==> ... */
1432 /* op1 = target JavaVM pc */
1434 gen_branch(IF_ACMPNE);
1437 case ICMD_IF_ICMPLT: /* ..., value, value ==> ... */
1438 /* op1 = target JavaVM pc */
1440 gen_branch(IF_ICMPLT);
1443 case ICMD_IF_LCMPLT: /* ..., value, value ==> ... */
1444 /* op1 = target JavaVM pc */
1446 gen_branch(IF_LCMPLT);
1449 case ICMD_IF_ICMPGT: /* ..., value, value ==> ... */
1450 /* op1 = target JavaVM pc */
1452 gen_branch(IF_ICMPGT);
1455 case ICMD_IF_LCMPGT: /* ..., value, value ==> ... */
1456 /* op1 = target JavaVM pc */
1458 gen_branch(IF_LCMPGT);
1461 case ICMD_IF_ICMPLE: /* ..., value, value ==> ... */
1462 /* op1 = target JavaVM pc */
1464 gen_branch(IF_ICMPLE);
1467 case ICMD_IF_LCMPLE: /* ..., value, value ==> ... */
1468 /* op1 = target JavaVM pc */
1470 gen_branch(IF_LCMPLE);
1473 case ICMD_IF_ICMPGE: /* ..., value, value ==> ... */
1474 /* op1 = target JavaVM pc */
1476 gen_branch(IF_ICMPGE);
1479 case ICMD_IF_LCMPGE: /* ..., value, value ==> ... */
1480 /* op1 = target JavaVM pc */
1482 gen_branch(IF_LCMPGE);
1486 case ICMD_ARETURN: /* ..., retvalue ==> ... */
1487 case ICMD_IRETURN: /* ..., retvalue ==> ... */
1488 case ICMD_FRETURN: /* ..., retvalue ==> ... */
1490 #if defined(USE_THREADS)
1491 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
1492 if (m->flags & ACC_STATIC) {
1493 gen_ACONST(cd, (java_objectheader *) m->class);
1497 gen_MONITOREXIT(cd);
1501 gen_TRACERETURN(cd, m);
1503 gen_IRETURN(cd, index2offset(cd->maxlocals));
1506 case ICMD_LRETURN: /* ..., retvalue ==> ... */
1507 case ICMD_DRETURN: /* ..., retvalue ==> ... */
1509 #if defined(USE_THREADS)
1510 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
1511 if (m->flags & ACC_STATIC) {
1512 gen_ACONST(cd, (java_objectheader *) m->class);
1516 gen_MONITOREXIT(cd);
1520 gen_TRACELRETURN(cd, m);
1522 gen_LRETURN(cd, index2offset(cd->maxlocals));
1525 case ICMD_RETURN: /* ... ==> ... */
1527 #if defined(USE_THREADS)
1528 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
1529 if (m->flags & ACC_STATIC) {
1530 gen_ACONST(cd, (java_objectheader *) m->class);
1534 gen_MONITOREXIT(cd);
1538 gen_TRACERETURN(cd, m);
1540 gen_RETURN(cd, index2offset(cd->maxlocals));
1544 case ICMD_TABLESWITCH: /* ..., index ==> ... */
1549 tptr = (void **) iptr->target;
1551 s4ptr = iptr->val.a;
1552 l = s4ptr[1]; /* low */
1553 i = s4ptr[2]; /* high */
1557 /* arguments: low, range, datasegment address, table
1558 offset in datasegment, default target */
1560 gen_TABLESWITCH(cd, l, i, NULL, 0, NULL);
1562 /* actually -3 cells offset */
1564 dseg_adddata(cd, (cd->mcodeptr - 2 * sizeof(Inst)));
1565 codegen_addreference(cd, (basicblock *) tptr[0], cd->mcodeptr);
1567 /* build jump table top down and use address of lowest entry */
1572 dseg_addtarget(cd, (basicblock *) tptr[0]);
1577 /* length of dataseg after last dseg_addtarget is used by load */
1578 ((ptrint *)(cd->mcodeptr))[-2] = (ptrint) -(cd->dseglen);
1582 case ICMD_LOOKUPSWITCH: /* ..., key ==> ... */
1587 tptr = (void **) iptr->target;
1589 s4ptr = iptr->val.a;
1591 /* s4ptr[0] is equal to tptr[0] */
1592 i = s4ptr[1]; /* count */
1594 /* arguments: count, datasegment address, table offset in */
1595 /* datasegment, default target */
1596 gen_LOOKUPSWITCH(cd, i, NULL, 0, NULL);
1597 dseg_adddata(cd, (cd->mcodeptr - 2*sizeof(Inst))); /* actually -3 cells offset*/
1598 codegen_addreference(cd, (basicblock *) tptr[0], cd->mcodeptr);
1600 /* build jump table top down and use address of lowest entry */
1606 dseg_addtarget(cd, (basicblock *) tptr[0]);
1607 dseg_addaddress(cd, s4ptr[0]);
1613 /* length of dataseg after last dseg_addtarget is used by load */
1614 ((ptrint *)(cd->mcodeptr))[-2] = (ptrint) -(cd->dseglen);
1618 case ICMD_BUILTIN: /* ..., arg1, arg2, arg3 ==> ... */
1619 /* op1 = arg count val.a = builtintable entry */
1622 for (i = 0; i < sizeof(builtin_gen_table)/sizeof(builtin_gen); i++) {
1623 builtin_gen *bg = &builtin_gen_table[i];
1624 if (bg->builtin == bte->fp) {
1626 goto gen_builtin_end;
1633 case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ... */
1634 /* op1 = arg count, val.a = method pointer */
1640 md = um->methodref->parseddesc.md;
1641 gen_PATCHER_INVOKESTATIC(cd, 0, md->paramslots, um);
1644 md = lm->parseddesc;
1645 gen_INVOKESTATIC(cd, (Inst **)lm->stubroutine, md->paramslots, um);
1649 case ICMD_INVOKESPECIAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
1655 md = um->methodref->parseddesc.md;
1656 gen_PATCHER_INVOKESPECIAL(cd, 0, md->paramslots, um);
1659 md = lm->parseddesc;
1660 gen_INVOKESPECIAL(cd, (Inst **)lm->stubroutine, md->paramslots, um);
1664 case ICMD_INVOKEVIRTUAL:/* op1 = arg count, val.a = method pointer */
1670 md = um->methodref->parseddesc.md;
1671 gen_PATCHER_INVOKEVIRTUAL(cd, 0, md->paramslots, um);
1674 md = lm->parseddesc;
1676 s1 = OFFSET(vftbl_t, table[0]) +
1677 sizeof(methodptr) * lm->vftblindex;
1679 gen_INVOKEVIRTUAL(cd, s1, md->paramslots, um);
1683 case ICMD_INVOKEINTERFACE:/* op1 = arg count, val.a = method pointer */
1689 md = um->methodref->parseddesc.md;
1690 gen_PATCHER_INVOKEINTERFACE(cd, 0, 0, md->paramslots, um);
1693 md = lm->parseddesc;
1695 s1 = OFFSET(vftbl_t, interfacetable[0]) -
1696 sizeof(methodptr*) * lm->class->index;
1698 s2 = sizeof(methodptr) * (lm - lm->class->methods);
1700 gen_INVOKEINTERFACE(cd, s1, s2, md->paramslots, um);
1705 case ICMD_CHECKCAST: /* ..., objectref ==> ..., objectref */
1706 /* op1: 0 == array, 1 == class */
1707 /* val.a: (classinfo *) superclass */
1709 if (iptr->op1 == 1) {
1710 if (iptr->val.a == NULL)
1711 gen_PATCHER_CHECKCAST(cd, NULL, iptr->target);
1713 gen_CHECKCAST(cd, iptr->val.a, NULL);
1715 if (iptr->val.a == NULL)
1716 gen_PATCHER_ARRAYCHECKCAST(cd, NULL, iptr->target);
1718 gen_ARRAYCHECKCAST(cd, iptr->val.a, NULL);
1722 case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult */
1723 /* op1: 0 == array, 1 == class */
1724 /* val.a: (classinfo *) superclass */
1726 if (iptr->val.a == NULL)
1727 gen_PATCHER_INSTANCEOF(cd, NULL, iptr->target);
1729 gen_INSTANCEOF(cd, iptr->val.a, iptr->target);
1732 case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref */
1733 /* op1 = dimension, val.a = class */
1735 if (iptr->val.a == NULL) {
1736 gen_PATCHER_MULTIANEWARRAY(cd, NULL, iptr->op1, iptr->target);
1738 gen_MULTIANEWARRAY(cd, iptr->val.a, iptr->op1, NULL);
1743 *exceptionptr = new_internalerror("Unknown ICMD %d", iptr->opc);
1747 } /* for instruction */
1751 } /* if (bptr->flags >= BBREACHED) */
1752 } /* for basic block */
1754 dseg_createlinenumbertable(cd);
1756 codegen_finish(m, cd, (s4) (cd->mcodeptr - cd->mcodebase));
1759 vm_block_insert(m->mcode + m->mcodelength);
1762 /* branch resolving (walk through all basic blocks) */
1764 for (bptr = m->basicblocks; bptr != NULL; bptr = bptr->next) {
1767 for (brefs = bptr->branchrefs; brefs != NULL; brefs = brefs->next) {
1768 gen_resolveanybranch(((u1*) m->entrypoint) + brefs->branchpos,
1769 ((u1 *)m->entrypoint) + bptr->mpc);
1773 /* everything's ok */
1779 /* a stub consists of
1791 codeptr points either to TRANSLATE or to the translated threaded code
1793 all methods are called indirectly through methodptr
1796 #define COMPILERSTUB_SIZE 4
1798 u1 *intrp_createcompilerstub(methodinfo *m)
1804 s = CNEW(Inst, COMPILERSTUB_SIZE);
1806 /* mark start of dump memory area */
1808 dumpsize = dump_size();
1810 cd = DNEW(codegendata);
1811 cd->mcodeptr = (u1 *) s;
1812 cd->lastinstwithoutdispatch = ~0;
1813 cd->superstarts = NULL;
1815 genarg_ainst(cd, s + 2);
1817 if (m->flags & ACC_NATIVE) {
1818 genarg_i(cd, m->parseddesc->paramslots);
1820 genarg_i(cd, m->maxlocals);
1824 gen_TRANSLATE(cd, m);
1828 vm_block_insert(cd->mcodeptr);
1831 #if defined(ENABLE_STATISTICS)
1833 count_cstub_len += COMPILERSTUB_SIZE;
1836 /* release dump area */
1838 dump_release(dumpsize);
1844 #if defined(WITH_FFI)
1845 static ffi_type *cacaotype2ffitype(s4 cacaotype)
1847 switch (cacaotype) {
1849 #if SIZEOF_VOID_P == 8
1850 return &ffi_type_sint64;
1852 return &ffi_type_sint32;
1855 return &ffi_type_sint64;
1857 return &ffi_type_float;
1859 return &ffi_type_double;
1861 return &ffi_type_pointer;
1863 return &ffi_type_void;
1883 #if defined(WITH_FFI)
1884 static ffi_cif *createnativecif(methodinfo *m, methoddesc *nmd)
1886 methoddesc *md = m->parseddesc;
1887 ffi_cif *pcif = NEW(ffi_cif);
1888 ffi_type **types = MNEW(ffi_type *, nmd->paramcount);
1889 ffi_type **ptypes = types;
1892 /* pass env pointer */
1894 *ptypes++ = &ffi_type_pointer;
1896 /* for static methods, pass class pointer */
1898 if (m->flags & ACC_STATIC)
1899 *ptypes++ = &ffi_type_pointer;
1901 /* pass parameter to native function */
1903 for (i = 0; i < md->paramcount; i++)
1904 *ptypes++ = cacaotype2ffitype(md->paramtypes[i].type);
1906 assert(ptypes - types == nmd->paramcount);
1908 if (ffi_prep_cif(pcif, FFI_DEFAULT_ABI, nmd->paramcount, cacaotype2ffitype(md->returntype.type), types) != FFI_OK)
1916 u1 *intrp_createnativestub(functionptr f, methodinfo *m, codegendata *cd,
1917 registerdata *rd, methoddesc *nmd)
1919 #if defined(WITH_FFI)
1925 /* create method header */
1927 (void) dseg_addaddress(cd, m); /* MethodPointer */
1928 (void) dseg_adds4(cd, nmd->paramslots * SIZEOF_VOID_P); /* FrameSize */
1929 (void) dseg_adds4(cd, 0); /* IsSync */
1930 (void) dseg_adds4(cd, 0); /* IsLeaf */
1931 (void) dseg_adds4(cd, 0); /* IntSave */
1932 (void) dseg_adds4(cd, 0); /* FltSave */
1933 dseg_addlinenumbertablesize(cd);
1934 (void) dseg_adds4(cd, 0); /* ExTableSize */
1936 #if defined(WITH_FFI)
1937 /* prepare ffi cif structure */
1939 cif = createnativecif(m, nmd);
1947 gen_TRACECALL(cd, m);
1950 gen_PATCHER_NATIVECALL(cd, m, f, (u1 *)cif);
1953 gen_TRACENATIVECALL(cd, m, f, (u1 *)cif);
1955 gen_NATIVECALL(cd, m, f, (u1 *)cif);
1960 codegen_finish(m, cd, (s4) (cd->mcodeptr - cd->mcodebase));
1963 vm_block_insert(m->mcode + m->mcodelength);
1966 return m->entrypoint;
1970 /* call jni function */
1971 Cell *nativecall(functionptr f, methodinfo *m, Cell *sp, Inst *ra, Cell *fp, u1 *addrcif)
1973 #if defined(WITH_FFCALL)
1987 switch (md->returntype.type) {
1989 endsp = sp - 1 + md->paramslots;
1990 av_start_long(alist, f, endsp);
1993 endsp = sp - 2 + md->paramslots;
1994 av_start_longlong(alist, f, endsp);
1997 endsp = sp - 1 + md->paramslots;
1998 av_start_float(alist, f, endsp);
2001 endsp = sp - 2 + md->paramslots;
2002 av_start_double(alist, f, endsp);
2005 endsp = sp - 1 + md->paramslots;
2006 av_start_ptr(alist, f, void *, endsp);
2009 endsp = sp + md->paramslots;
2010 av_start_void(alist, f);
2016 av_ptr(alist, JNIEnv *, &env);
2018 if (m->flags & ACC_STATIC)
2019 av_ptr(alist, classinfo *, m->class);
2021 for (i = 0, p = sp + md->paramslots; i < md->paramcount; i++) {
2022 switch (md->paramtypes[i].type) {
2029 av_longlong(alist, *(s8 *)p);
2033 av_float(alist, *((float *) p));
2037 av_double(alist, *(double *) p);
2041 av_ptr(alist, void *, *(void **) p);
2050 /* create stackframe info structure */
2052 codegen_start_native_call(((u1 *) &s) + sizeof(s), m->entrypoint,
2053 (u1 *) fp, (u1 *) ra);
2057 codegen_finish_native_call(((u1 *) &s) + sizeof(s));
2062 #elif defined(WITH_FFI)
2063 methoddesc *md = m->parseddesc;
2065 void *values[md->paramcount + 2];
2066 void **pvalues = values;
2077 pcif = (ffi_cif *) addrcif;
2079 /* pass env pointer */
2081 penv = (JNIEnv *) &env;
2084 /* for static methods, pass class pointer */
2086 if (m->flags & ACC_STATIC)
2087 *pvalues++ = &m->class;
2089 /* pass parameter to native function */
2091 for (i = 0, p = sp + md->paramslots; i < md->paramcount; i++) {
2092 if (IS_2_WORD_TYPE(md->paramtypes[i].type))
2100 /* calculate position of return value */
2102 if (md->returntype.type == TYPE_VOID)
2103 endsp = sp + md->paramslots;
2105 endsp = sp - (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1) + md->paramslots;
2109 /* create stackframe info structure */
2111 codegen_start_native_call(((u1 *) &s) + sizeof(s), m->entrypoint,
2112 (u1 *) fp, (u1 *) ra);
2114 ffi_call(pcif, FFI_FN(f), endsp, values);
2116 codegen_finish_native_call(((u1 *) &s) + sizeof(s));
2125 u1 *createcalljavafunction(methodinfo *m)
2131 t_inlining_globals *id;
2135 /* mark dump memory */
2137 dumpsize = dump_size();
2139 tmpm = DNEW(methodinfo);
2140 cd = DNEW(codegendata);
2141 rd = DNEW(registerdata);
2142 id = DNEW(t_inlining_globals);
2144 /* setup code generation stuff */
2146 MSET(tmpm, 0, u1, sizeof(methodinfo));
2148 inlining_setup(tmpm, id);
2149 codegen_setup(tmpm, cd, id);
2153 /* create method header */
2155 (void) dseg_addaddress(cd, NULL); /* MethodPointer */
2156 (void) dseg_adds4(cd, md->paramslots * SIZEOF_VOID_P); /* FrameSize */
2157 (void) dseg_adds4(cd, 0); /* IsSync */
2158 (void) dseg_adds4(cd, 0); /* IsLeaf */
2159 (void) dseg_adds4(cd, 0); /* IntSave */
2160 (void) dseg_adds4(cd, 0); /* FltSave */
2161 dseg_addlinenumbertablesize(cd);
2162 (void) dseg_adds4(cd, 0); /* ExTableSize */
2168 gen_INVOKESTATIC(cd, (Inst **)m->stubroutine, md->paramslots, 0);
2173 codegen_finish(tmpm, cd, (s4) (cd->mcodeptr - cd->mcodebase));
2176 vm_block_insert(tmpm->mcode + tmpm->mcodelength);
2178 entrypoint = tmpm->entrypoint;
2180 /* release memory */
2182 dump_release(dumpsize);
2189 * These are local overrides for various environment variables in Emacs.
2190 * Please do not remove this and leave it at the end of the file, where
2191 * Emacs will automagically detect them.
2192 * ---------------------------------------------------------------------
2195 * indent-tabs-mode: t