1 /* src/vm/jit/stack.c - stack analysis
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
29 Changes: Edwin Steiner
32 $Id: stack.c 2496 2005-05-23 08:06:06Z twisti $
44 #include "mm/memory.h"
45 #include "native/native.h"
46 #include "toolbox/logging.h"
47 #include "vm/global.h"
48 #include "vm/builtin.h"
49 #include "vm/options.h"
50 #include "vm/resolve.h"
51 #include "vm/statistics.h"
52 #include "vm/stringlocal.h"
53 #include "vm/tables.h"
54 #include "vm/jit/codegen.inc.h"
55 #include "vm/jit/jit.h"
56 #include "vm/jit/reg.h"
57 #include "vm/jit/stack.h"
58 #include "vm/jit/lsra.h"
61 /**********************************************************************/
63 /**********************************************************************/
65 /* analyse_stack uses the intermediate code created by parse.c to
66 * build a model of the JVM operand stack for the current method.
68 * The following checks are performed:
69 * - check for operand stack underflow (before each instruction)
70 * - check for operand stack overflow (after[1] each instruction)
71 * - check for matching stack depth at merging points
72 * - check for matching basic types[2] at merging points
73 * - check basic types for instruction input (except for BUILTIN*
74 * opcodes, INVOKE* opcodes and MULTIANEWARRAY)
76 * [1]) Checking this after the instruction should be ok. parse.c
77 * counts the number of required stack slots in such a way that it is
78 * only vital that we don't exceed `maxstack` at basic block
81 * [2]) 'basic types' means the distinction between INT, LONG, FLOAT,
82 * DOUBLE and ADDRESS types. Subtypes of INT and different ADDRESS
83 * types are not discerned.
86 methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
94 int opcode, i, len, loops;
95 int superblockend, repeat, deadcode;
110 argren = DMNEW(s4, cd->maxlocals); /* table for argument renaming */
111 for (i = 0; i < cd->maxlocals; i++)
114 rd->arguments_num = 0;
117 m->basicblocks[0].flags = BBREACHED;
118 m->basicblocks[0].instack = 0;
119 m->basicblocks[0].indepth = 0;
121 for (i = 0; i < cd->exceptiontablelength; i++) {
122 bptr = &m->basicblocks[m->basicblockindex[cd->exceptiontable[i].handlerpc]];
123 bptr->flags = BBREACHED;
124 bptr->type = BBTYPE_EXH;
127 bptr->pre_count = 10000;
132 #if CONDITIONAL_LOADCONST
133 b_count = m->basicblockcount;
134 bptr = m->basicblocks;
135 while (--b_count >= 0) {
136 if (bptr->icount != 0) {
137 iptr = bptr->iinstr + bptr->icount - 1;
170 m->basicblocks[m->basicblockindex[iptr->op1]].pre_count++;
173 case ICMD_TABLESWITCH:
175 m->basicblocks[m->basicblockindex[*s4ptr++]].pre_count++;
176 i = *s4ptr++; /* low */
177 i = *s4ptr++ - i + 1; /* high */
179 m->basicblocks[m->basicblockindex[*s4ptr++]].pre_count++;
183 case ICMD_LOOKUPSWITCH:
185 m->basicblocks[m->basicblockindex[*s4ptr++]].pre_count++;
186 i = *s4ptr++; /* count */
188 m->basicblocks[m->basicblockindex[s4ptr[1]]].pre_count++;
199 #endif /* CONDITIONAL_LOADCONST */
204 b_count = m->basicblockcount;
205 bptr = m->basicblocks;
206 superblockend = true;
210 /*printf("Block count :%d\n",b_count);*/
212 while (--b_count >= 0) {
213 if (bptr->flags == BBDELETED) {
215 /*log_text("BBDELETED");*/
217 } else if (superblockend && (bptr->flags < BBREACHED)) {
220 } else if (bptr->flags <= BBREACHED) {
222 stackdepth = bptr->indepth;
224 } else if (bptr->flags < BBREACHED) {
226 bptr->instack = copy;
227 bptr->indepth = stackdepth;
229 } else if (bptr->indepth != stackdepth) {
230 show_icmd_method(m, cd, rd);
231 printf("Block: %d, required depth: %d, current depth: %d\n", bptr->debug_nr, bptr->indepth, stackdepth);
232 log_text("Stack depth mismatch");
236 curstack = bptr->instack;
238 superblockend = false;
239 bptr->flags = BBFINISHED;
242 b_index = bptr - m->basicblocks;
246 /* XXX TWISTI: why is this set to NULL here? */
247 /* iptr->target = NULL; */
249 /* dolog("p: %04d op: %s stack: %p", iptr - instr, icmd_names[opcode], curstack); */
251 #if defined(USEBUILTINTABLE)
254 stdopdescriptor *breplace;
255 breplace = find_builtin(opcode);
257 if (breplace && opcode == breplace->opcode) {
258 iptr[0].opc = breplace->icmd;
259 iptr[0].op1 = breplace->type_d;
260 iptr[0].val.fp = breplace->builtin;
261 m->isleafmethod = false;
262 switch (breplace->icmd) {
270 builtin_descriptor *breplace;
271 breplace = find_builtin(opcode);
273 if (breplace && opcode == breplace->opcode) {
274 iptr[0].opc = breplace->icmd;
275 iptr[0].op1 = breplace->type_d;
276 iptr[0].val.fp = breplace->builtin;
277 m->isleafmethod = false;
278 switch (breplace->icmd) {
286 #endif /* defined(USEBUILTINTABLE) */
293 COUNT(count_check_null);
295 case ICMD_CHECKASIZE:
296 case ICMD_CHECKEXCEPTION:
298 case ICMD_IFEQ_ICONST:
299 case ICMD_IFNE_ICONST:
300 case ICMD_IFLT_ICONST:
301 case ICMD_IFGE_ICONST:
302 case ICMD_IFGT_ICONST:
303 case ICMD_IFLE_ICONST:
304 case ICMD_ELSE_ICONST:
309 rd->locals[iptr->op1][TYPE_ADR].type = TYPE_ADR;
311 COUNT(count_pcmd_return);
313 superblockend = true;
316 /* pop 0 push 1 const */
319 COUNT(count_pcmd_load);
321 switch (iptr[1].opc) {
323 iptr[0].opc = ICMD_IADDCONST;
325 iptr[1].opc = ICMD_NOP;
326 OP1_1(TYPE_INT, TYPE_INT);
327 COUNT(count_pcmd_op);
330 iptr[0].opc = ICMD_ISUBCONST;
331 goto icmd_iconst_tail;
332 #if SUPPORT_CONST_MUL
334 iptr[0].opc = ICMD_IMULCONST;
335 goto icmd_iconst_tail;
336 #else /* SUPPORT_CONST_MUL */
338 if (iptr[0].val.i == 0x00000002)
340 else if (iptr[0].val.i == 0x00000004)
342 else if (iptr[0].val.i == 0x00000008)
344 else if (iptr[0].val.i == 0x00000010)
346 else if (iptr[0].val.i == 0x00000020)
348 else if (iptr[0].val.i == 0x00000040)
350 else if (iptr[0].val.i == 0x00000080)
352 else if (iptr[0].val.i == 0x00000100)
354 else if (iptr[0].val.i == 0x00000200)
356 else if (iptr[0].val.i == 0x00000400)
358 else if (iptr[0].val.i == 0x00000800)
360 else if (iptr[0].val.i == 0x00001000)
362 else if (iptr[0].val.i == 0x00002000)
364 else if (iptr[0].val.i == 0x00004000)
366 else if (iptr[0].val.i == 0x00008000)
368 else if (iptr[0].val.i == 0x00010000)
370 else if (iptr[0].val.i == 0x00020000)
372 else if (iptr[0].val.i == 0x00040000)
374 else if (iptr[0].val.i == 0x00080000)
376 else if (iptr[0].val.i == 0x00100000)
378 else if (iptr[0].val.i == 0x00200000)
380 else if (iptr[0].val.i == 0x00400000)
382 else if (iptr[0].val.i == 0x00800000)
384 else if (iptr[0].val.i == 0x01000000)
386 else if (iptr[0].val.i == 0x02000000)
388 else if (iptr[0].val.i == 0x04000000)
390 else if (iptr[0].val.i == 0x08000000)
392 else if (iptr[0].val.i == 0x10000000)
394 else if (iptr[0].val.i == 0x20000000)
396 else if (iptr[0].val.i == 0x40000000)
398 else if (iptr[0].val.i == 0x80000000)
404 iptr[0].opc = ICMD_IMULPOW2;
405 goto icmd_iconst_tail;
406 #endif /* SUPPORT_CONST_MUL */
408 if (iptr[0].val.i == 0x00000002)
410 else if (iptr[0].val.i == 0x00000004)
412 else if (iptr[0].val.i == 0x00000008)
414 else if (iptr[0].val.i == 0x00000010)
416 else if (iptr[0].val.i == 0x00000020)
418 else if (iptr[0].val.i == 0x00000040)
420 else if (iptr[0].val.i == 0x00000080)
422 else if (iptr[0].val.i == 0x00000100)
424 else if (iptr[0].val.i == 0x00000200)
426 else if (iptr[0].val.i == 0x00000400)
428 else if (iptr[0].val.i == 0x00000800)
430 else if (iptr[0].val.i == 0x00001000)
432 else if (iptr[0].val.i == 0x00002000)
434 else if (iptr[0].val.i == 0x00004000)
436 else if (iptr[0].val.i == 0x00008000)
438 else if (iptr[0].val.i == 0x00010000)
440 else if (iptr[0].val.i == 0x00020000)
442 else if (iptr[0].val.i == 0x00040000)
444 else if (iptr[0].val.i == 0x00080000)
446 else if (iptr[0].val.i == 0x00100000)
448 else if (iptr[0].val.i == 0x00200000)
450 else if (iptr[0].val.i == 0x00400000)
452 else if (iptr[0].val.i == 0x00800000)
454 else if (iptr[0].val.i == 0x01000000)
456 else if (iptr[0].val.i == 0x02000000)
458 else if (iptr[0].val.i == 0x04000000)
460 else if (iptr[0].val.i == 0x08000000)
462 else if (iptr[0].val.i == 0x10000000)
464 else if (iptr[0].val.i == 0x20000000)
466 else if (iptr[0].val.i == 0x40000000)
468 else if (iptr[0].val.i == 0x80000000)
474 iptr[0].opc = ICMD_IDIVPOW2;
475 goto icmd_iconst_tail;
477 /*log_text("stack.c: ICMD_ICONST/ICMD_IREM");*/
478 if ((iptr[0].val.i == 0x00000002) ||
479 (iptr[0].val.i == 0x00000004) ||
480 (iptr[0].val.i == 0x00000008) ||
481 (iptr[0].val.i == 0x00000010) ||
482 (iptr[0].val.i == 0x00000020) ||
483 (iptr[0].val.i == 0x00000040) ||
484 (iptr[0].val.i == 0x00000080) ||
485 (iptr[0].val.i == 0x00000100) ||
486 (iptr[0].val.i == 0x00000200) ||
487 (iptr[0].val.i == 0x00000400) ||
488 (iptr[0].val.i == 0x00000800) ||
489 (iptr[0].val.i == 0x00001000) ||
490 (iptr[0].val.i == 0x00002000) ||
491 (iptr[0].val.i == 0x00004000) ||
492 (iptr[0].val.i == 0x00008000) ||
493 (iptr[0].val.i == 0x00010000) ||
494 (iptr[0].val.i == 0x00020000) ||
495 (iptr[0].val.i == 0x00040000) ||
496 (iptr[0].val.i == 0x00080000) ||
497 (iptr[0].val.i == 0x00100000) ||
498 (iptr[0].val.i == 0x00200000) ||
499 (iptr[0].val.i == 0x00400000) ||
500 (iptr[0].val.i == 0x00800000) ||
501 (iptr[0].val.i == 0x01000000) ||
502 (iptr[0].val.i == 0x02000000) ||
503 (iptr[0].val.i == 0x04000000) ||
504 (iptr[0].val.i == 0x08000000) ||
505 (iptr[0].val.i == 0x10000000) ||
506 (iptr[0].val.i == 0x20000000) ||
507 (iptr[0].val.i == 0x40000000) ||
508 (iptr[0].val.i == 0x80000000)) {
509 iptr[0].opc = ICMD_IREMPOW2;
511 goto icmd_iconst_tail;
515 #if SUPPORT_CONST_LOGICAL
517 iptr[0].opc = ICMD_IANDCONST;
518 goto icmd_iconst_tail;
520 iptr[0].opc = ICMD_IORCONST;
521 goto icmd_iconst_tail;
523 iptr[0].opc = ICMD_IXORCONST;
524 goto icmd_iconst_tail;
525 #endif /* SUPPORT_CONST_LOGICAL */
527 iptr[0].opc = ICMD_ISHLCONST;
528 goto icmd_iconst_tail;
530 iptr[0].opc = ICMD_ISHRCONST;
531 goto icmd_iconst_tail;
533 iptr[0].opc = ICMD_IUSHRCONST;
534 goto icmd_iconst_tail;
535 #if SUPPORT_LONG_SHIFT
537 iptr[0].opc = ICMD_LSHLCONST;
538 goto icmd_lconst_tail;
540 iptr[0].opc = ICMD_LSHRCONST;
541 goto icmd_lconst_tail;
543 iptr[0].opc = ICMD_LUSHRCONST;
544 goto icmd_lconst_tail;
545 #endif /* SUPPORT_LONG_SHIFT */
547 iptr[0].opc = ICMD_IFEQ;
549 iptr[0].op1 = iptr[1].op1;
553 /* iptr[1].opc = ICMD_NOP; */
555 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
557 iptr[0].target = (void *) tbptr;
559 MARKREACHED(tbptr, copy);
560 COUNT(count_pcmd_bra);
566 iptr[0].opc = ICMD_IFLT;
567 goto icmd_if_icmp_tail;
569 iptr[0].opc = ICMD_IFLE;
570 goto icmd_if_icmp_tail;
572 iptr[0].opc = ICMD_IFNE;
573 goto icmd_if_icmp_tail;
575 iptr[0].opc = ICMD_IFGT;
576 goto icmd_if_icmp_tail;
578 iptr[0].opc = ICMD_IFGE;
579 goto icmd_if_icmp_tail;
581 #if SUPPORT_CONST_STORE
586 #if SUPPORT_CONST_STORE_ZERO_ONLY
587 if (iptr[0].val.i == 0) {
588 #endif /* SUPPORT_CONST_STORE_ZERO_ONLY */
589 switch (iptr[1].opc) {
591 iptr[0].opc = ICMD_IASTORECONST;
594 iptr[0].opc = ICMD_BASTORECONST;
597 iptr[0].opc = ICMD_CASTORECONST;
600 iptr[0].opc = ICMD_SASTORECONST;
604 iptr[1].opc = ICMD_NOP;
605 OPTT2_0(TYPE_INT, TYPE_ADR);
606 COUNT(count_pcmd_op);
607 #if SUPPORT_CONST_STORE_ZERO_ONLY
610 #endif /* SUPPORT_CONST_STORE_ZERO_ONLY */
615 #if SUPPORT_CONST_STORE_ZERO_ONLY
616 if (iptr[0].val.i == 0) {
617 #endif /* SUPPORT_CONST_STORE_ZERO_ONLY */
618 switch (iptr[1].opc) {
620 iptr[0].opc = ICMD_PUTSTATICCONST;
624 iptr[0].opc = ICMD_PUTFIELDCONST;
629 iptr[1].opc = ICMD_NOP;
630 iptr[0].op1 = TYPE_INT;
631 COUNT(count_pcmd_op);
632 #if SUPPORT_CONST_STORE_ZERO_ONLY
635 #endif /* SUPPORT_CONST_STORE_ZERO_ONLY */
637 #endif /* SUPPORT_CONST_STORE */
647 COUNT(count_pcmd_load);
649 switch (iptr[1].opc) {
652 iptr[0].opc = ICMD_LADDCONST;
654 iptr[1].opc = ICMD_NOP;
655 OP1_1(TYPE_LNG,TYPE_LNG);
656 COUNT(count_pcmd_op);
659 iptr[0].opc = ICMD_LSUBCONST;
660 goto icmd_lconst_tail;
661 #endif /* SUPPORT_LONG_ADD */
662 #if SUPPORT_LONG_MUL && SUPPORT_CONST_MUL
664 iptr[0].opc = ICMD_LMULCONST;
665 goto icmd_lconst_tail;
666 #else /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
667 # if SUPPORT_LONG_SHIFT
669 if (iptr[0].val.l == 0x00000002)
671 else if (iptr[0].val.l == 0x00000004)
673 else if (iptr[0].val.l == 0x00000008)
675 else if (iptr[0].val.l == 0x00000010)
677 else if (iptr[0].val.l == 0x00000020)
679 else if (iptr[0].val.l == 0x00000040)
681 else if (iptr[0].val.l == 0x00000080)
683 else if (iptr[0].val.l == 0x00000100)
685 else if (iptr[0].val.l == 0x00000200)
687 else if (iptr[0].val.l == 0x00000400)
689 else if (iptr[0].val.l == 0x00000800)
691 else if (iptr[0].val.l == 0x00001000)
693 else if (iptr[0].val.l == 0x00002000)
695 else if (iptr[0].val.l == 0x00004000)
697 else if (iptr[0].val.l == 0x00008000)
699 else if (iptr[0].val.l == 0x00010000)
701 else if (iptr[0].val.l == 0x00020000)
703 else if (iptr[0].val.l == 0x00040000)
705 else if (iptr[0].val.l == 0x00080000)
707 else if (iptr[0].val.l == 0x00100000)
709 else if (iptr[0].val.l == 0x00200000)
711 else if (iptr[0].val.l == 0x00400000)
713 else if (iptr[0].val.l == 0x00800000)
715 else if (iptr[0].val.l == 0x01000000)
717 else if (iptr[0].val.l == 0x02000000)
719 else if (iptr[0].val.l == 0x04000000)
721 else if (iptr[0].val.l == 0x08000000)
723 else if (iptr[0].val.l == 0x10000000)
725 else if (iptr[0].val.l == 0x20000000)
727 else if (iptr[0].val.l == 0x40000000)
729 else if (iptr[0].val.l == 0x80000000)
735 iptr[0].opc = ICMD_LMULPOW2;
736 goto icmd_lconst_tail;
737 # endif /* SUPPORT_LONG_SHIFT */
738 #endif /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
741 if (iptr[0].val.l == 0x00000002)
743 else if (iptr[0].val.l == 0x00000004)
745 else if (iptr[0].val.l == 0x00000008)
747 else if (iptr[0].val.l == 0x00000010)
749 else if (iptr[0].val.l == 0x00000020)
751 else if (iptr[0].val.l == 0x00000040)
753 else if (iptr[0].val.l == 0x00000080)
755 else if (iptr[0].val.l == 0x00000100)
757 else if (iptr[0].val.l == 0x00000200)
759 else if (iptr[0].val.l == 0x00000400)
761 else if (iptr[0].val.l == 0x00000800)
763 else if (iptr[0].val.l == 0x00001000)
765 else if (iptr[0].val.l == 0x00002000)
767 else if (iptr[0].val.l == 0x00004000)
769 else if (iptr[0].val.l == 0x00008000)
771 else if (iptr[0].val.l == 0x00010000)
773 else if (iptr[0].val.l == 0x00020000)
775 else if (iptr[0].val.l == 0x00040000)
777 else if (iptr[0].val.l == 0x00080000)
779 else if (iptr[0].val.l == 0x00100000)
781 else if (iptr[0].val.l == 0x00200000)
783 else if (iptr[0].val.l == 0x00400000)
785 else if (iptr[0].val.l == 0x00800000)
787 else if (iptr[0].val.l == 0x01000000)
789 else if (iptr[0].val.l == 0x02000000)
791 else if (iptr[0].val.l == 0x04000000)
793 else if (iptr[0].val.l == 0x08000000)
795 else if (iptr[0].val.l == 0x10000000)
797 else if (iptr[0].val.l == 0x20000000)
799 else if (iptr[0].val.l == 0x40000000)
801 else if (iptr[0].val.l == 0x80000000)
807 iptr[0].opc = ICMD_LDIVPOW2;
808 goto icmd_lconst_tail;
810 if ((iptr[0].val.l == 0x00000002) ||
811 (iptr[0].val.l == 0x00000004) ||
812 (iptr[0].val.l == 0x00000008) ||
813 (iptr[0].val.l == 0x00000010) ||
814 (iptr[0].val.l == 0x00000020) ||
815 (iptr[0].val.l == 0x00000040) ||
816 (iptr[0].val.l == 0x00000080) ||
817 (iptr[0].val.l == 0x00000100) ||
818 (iptr[0].val.l == 0x00000200) ||
819 (iptr[0].val.l == 0x00000400) ||
820 (iptr[0].val.l == 0x00000800) ||
821 (iptr[0].val.l == 0x00001000) ||
822 (iptr[0].val.l == 0x00002000) ||
823 (iptr[0].val.l == 0x00004000) ||
824 (iptr[0].val.l == 0x00008000) ||
825 (iptr[0].val.l == 0x00010000) ||
826 (iptr[0].val.l == 0x00020000) ||
827 (iptr[0].val.l == 0x00040000) ||
828 (iptr[0].val.l == 0x00080000) ||
829 (iptr[0].val.l == 0x00100000) ||
830 (iptr[0].val.l == 0x00200000) ||
831 (iptr[0].val.l == 0x00400000) ||
832 (iptr[0].val.l == 0x00800000) ||
833 (iptr[0].val.l == 0x01000000) ||
834 (iptr[0].val.l == 0x02000000) ||
835 (iptr[0].val.l == 0x04000000) ||
836 (iptr[0].val.l == 0x08000000) ||
837 (iptr[0].val.l == 0x10000000) ||
838 (iptr[0].val.l == 0x20000000) ||
839 (iptr[0].val.l == 0x40000000) ||
840 (iptr[0].val.l == 0x80000000)) {
841 iptr[0].opc = ICMD_LREMPOW2;
843 goto icmd_lconst_tail;
847 #endif /* SUPPORT_LONG_DIV */
848 #if SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL
851 iptr[0].opc = ICMD_LANDCONST;
852 goto icmd_lconst_tail;
854 iptr[0].opc = ICMD_LORCONST;
855 goto icmd_lconst_tail;
857 iptr[0].opc = ICMD_LXORCONST;
858 goto icmd_lconst_tail;
859 #endif /* SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL */
860 #if !defined(NOLONG_CONDITIONAL)
862 if ((len > 1) && (iptr[2].val.i == 0)) {
863 switch (iptr[2].opc) {
865 iptr[0].opc = ICMD_IF_LEQ;
866 icmd_lconst_lcmp_tail:
867 iptr[0].op1 = iptr[2].op1;
870 /* iptr[1].opc = ICMD_NOP;
871 iptr[2].opc = ICMD_NOP; */
873 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
875 iptr[0].target = (void *) tbptr;
877 MARKREACHED(tbptr, copy);
878 COUNT(count_pcmd_bra);
879 COUNT(count_pcmd_op);
882 iptr[0].opc = ICMD_IF_LNE;
883 goto icmd_lconst_lcmp_tail;
885 iptr[0].opc = ICMD_IF_LLT;
886 goto icmd_lconst_lcmp_tail;
888 iptr[0].opc = ICMD_IF_LGT;
889 goto icmd_lconst_lcmp_tail;
891 iptr[0].opc = ICMD_IF_LLE;
892 goto icmd_lconst_lcmp_tail;
894 iptr[0].opc = ICMD_IF_LGE;
895 goto icmd_lconst_lcmp_tail;
898 } /* switch (iptr[2].opc) */
899 } /* if (iptr[2].val.i == 0) */
903 #endif /* !defined(NOLONG_CONDITIONAL) */
905 #if SUPPORT_CONST_STORE
907 #if SUPPORT_CONST_STORE_ZERO_ONLY
908 if (iptr[0].val.l == 0) {
909 #endif /* SUPPORT_CONST_STORE_ZERO_ONLY */
910 iptr[0].opc = ICMD_LASTORECONST;
911 iptr[1].opc = ICMD_NOP;
912 OPTT2_0(TYPE_INT, TYPE_ADR);
913 COUNT(count_pcmd_op);
914 #if SUPPORT_CONST_STORE_ZERO_ONLY
917 #endif /* SUPPORT_CONST_STORE_ZERO_ONLY */
922 #if SUPPORT_CONST_STORE_ZERO_ONLY
923 if (iptr[0].val.l == 0) {
924 #endif /* SUPPORT_CONST_STORE_ZERO_ONLY */
925 switch (iptr[1].opc) {
927 iptr[0].opc = ICMD_PUTSTATICCONST;
931 iptr[0].opc = ICMD_PUTFIELDCONST;
936 iptr[1].opc = ICMD_NOP;
937 iptr[0].op1 = TYPE_LNG;
938 COUNT(count_pcmd_op);
939 #if SUPPORT_CONST_STORE_ZERO_ONLY
942 #endif /* SUPPORT_CONST_STORE_ZERO_ONLY */
944 #endif /* SUPPORT_CONST_STORE */
954 COUNT(count_pcmd_load);
959 COUNT(count_pcmd_load);
964 COUNT(count_pcmd_load);
965 #if SUPPORT_CONST_STORE
966 if (len > 0 && iptr->val.a == 0) {
967 switch (iptr[1].opc) {
969 if (iptr[1].val.fp != BUILTIN_aastore) {
976 switch (iptr[1].opc) {
978 iptr[0].opc = ICMD_AASTORECONST;
979 OPTT2_0(TYPE_INT, TYPE_ADR);
982 iptr[0].opc = ICMD_PUTSTATICCONST;
983 iptr[0].op1 = TYPE_ADR;
987 iptr[0].opc = ICMD_PUTFIELDCONST;
988 iptr[0].op1 = TYPE_ADR;
993 iptr[1].opc = ICMD_NOP;
994 COUNT(count_pcmd_op);
1001 #endif /* SUPPORT_CONST_STORE */
1002 PUSHCONST(TYPE_ADR);
1005 /* pop 0 push 1 load */
1012 COUNT(count_load_instruction);
1013 i = opcode-ICMD_ILOAD;
1014 iptr->op1 = argren[iptr->op1];
1015 rd->locals[iptr->op1][i].type = i;
1016 LOAD(i, LOCALVAR, iptr->op1);
1026 COUNT(count_check_null);
1027 COUNT(count_check_bound);
1028 COUNT(count_pcmd_mem);
1029 OP2IAT_1(opcode-ICMD_IALOAD);
1035 COUNT(count_check_null);
1036 COUNT(count_check_bound);
1037 COUNT(count_pcmd_mem);
1041 /* pop 0 push 0 iinc */
1044 #if defined(STATISTICS)
1048 count_store_depth[10]++;
1050 count_store_depth[i]++;
1056 if ((copy->varkind == LOCALVAR) &&
1057 (copy->varnum == iptr->op1)) {
1058 copy->varkind = TEMPVAR;
1067 /* pop 1 push 0 store */
1077 i = opcode - ICMD_ISTORE;
1078 rd->locals[iptr->op1][i].type = i;
1079 #if defined(STATISTICS)
1084 count_store_length[20]++;
1086 count_store_length[i]++;
1089 count_store_depth[10]++;
1091 count_store_depth[i]++;
1094 copy = curstack->prev;
1097 if ((copy->varkind == LOCALVAR) &&
1098 (copy->varnum == iptr->op1)) {
1099 copy->varkind = TEMPVAR;
1105 if ((new - curstack) == 1) {
1106 curstack->varkind = LOCALVAR;
1107 curstack->varnum = iptr->op1;
1109 STORE(opcode-ICMD_ISTORE);
1119 COUNT(count_check_null);
1120 COUNT(count_check_bound);
1121 COUNT(count_pcmd_mem);
1122 OP3TIA_0(opcode-ICMD_IASTORE);
1128 COUNT(count_check_null);
1129 COUNT(count_check_bound);
1130 COUNT(count_pcmd_mem);
1137 #ifdef TYPECHECK_STACK_COMPCAT
1140 if (IS_2_WORD_TYPE(curstack->type)) {
1141 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1154 COUNT(count_pcmd_return);
1155 OP1_0(opcode-ICMD_IRETURN);
1156 superblockend = true;
1160 COUNT(count_check_null);
1164 superblockend = true;
1167 case ICMD_PUTSTATIC:
1168 COUNT(count_pcmd_mem);
1172 /* pop 1 push 0 branch */
1175 case ICMD_IFNONNULL:
1176 COUNT(count_pcmd_bra);
1178 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1180 iptr[0].target = (void *) tbptr;
1182 MARKREACHED(tbptr, copy);
1194 COUNT(count_pcmd_bra);
1195 #if CONDITIONAL_LOADCONST
1196 tbptr = m->basicblocks + b_index;
1197 if ((b_count >= 3) &&
1198 ((b_index + 2) == m->basicblockindex[iptr[0].op1]) &&
1199 (tbptr[1].pre_count == 1) &&
1200 (tbptr[1].iinstr[0].opc == ICMD_ICONST) &&
1201 (tbptr[1].iinstr[1].opc == ICMD_GOTO) &&
1202 ((b_index + 3) == m->basicblockindex[tbptr[1].iinstr[1].op1]) &&
1203 (tbptr[2].pre_count == 1) &&
1204 (tbptr[2].iinstr[0].opc == ICMD_ICONST) &&
1205 (tbptr[2].icount==1)) {
1206 /*printf("tbptr[2].icount=%d\n",tbptr[2].icount);*/
1207 OP1_1(TYPE_INT, TYPE_INT);
1208 switch (iptr[0].opc) {
1210 iptr[0].opc = ICMD_IFNE_ICONST;
1213 iptr[0].opc = ICMD_IFEQ_ICONST;
1216 iptr[0].opc = ICMD_IFGE_ICONST;
1219 iptr[0].opc = ICMD_IFLT_ICONST;
1222 iptr[0].opc = ICMD_IFLE_ICONST;
1225 iptr[0].opc = ICMD_IFGT_ICONST;
1229 iptr[0].val.i = iptr[1].val.i;
1230 iptr[1].opc = ICMD_ELSE_ICONST;
1231 iptr[1].val.i = iptr[3].val.i;
1232 iptr[2].opc = ICMD_NOP;
1233 iptr[3].opc = ICMD_NOP;
1235 /* HACK: save compare value in iptr[1].op1 */
1236 iptr[1].op1 = iptr[0].val.i;
1237 iptr[0].val.i = tbptr[1].iinstr[0].val.i;
1238 iptr[1].opc = ICMD_ELSE_ICONST;
1239 iptr[1].val.i = tbptr[2].iinstr[0].val.i;
1240 tbptr[1].iinstr[0].opc = ICMD_NOP;
1241 tbptr[1].iinstr[1].opc = ICMD_NOP;
1242 tbptr[2].iinstr[0].opc = ICMD_NOP;
1244 tbptr[1].flags = BBDELETED;
1245 tbptr[2].flags = BBDELETED;
1246 tbptr[1].icount = 0;
1247 tbptr[2].icount = 0;
1248 if (tbptr[3].pre_count == 2) {
1249 len += tbptr[3].icount + 3;
1250 bptr->icount += tbptr[3].icount + 3;
1251 tbptr[3].flags = BBDELETED;
1252 tbptr[3].icount = 0;
1262 #endif /* CONDITIONAL_LOADCONST */
1265 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1267 iptr[0].target = (void *) tbptr;
1269 MARKREACHED(tbptr, copy);
1272 /* pop 0 push 0 branch */
1275 COUNT(count_pcmd_bra);
1276 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1278 iptr[0].target = (void *) tbptr;
1280 MARKREACHED(tbptr, copy);
1282 superblockend = true;
1285 /* pop 1 push 0 table branch */
1287 case ICMD_TABLESWITCH:
1288 COUNT(count_pcmd_table);
1290 s4ptr = iptr->val.a;
1291 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
1292 MARKREACHED(tbptr, copy);
1293 i = *s4ptr++; /* low */
1294 i = *s4ptr++ - i + 1; /* high */
1296 tptr = DMNEW(void*, i+1);
1297 iptr->target = (void *) tptr;
1299 tptr[0] = (void *) tbptr;
1303 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
1305 tptr[0] = (void *) tbptr;
1308 MARKREACHED(tbptr, copy);
1311 superblockend = true;
1314 /* pop 1 push 0 table branch */
1316 case ICMD_LOOKUPSWITCH:
1317 COUNT(count_pcmd_table);
1319 s4ptr = iptr->val.a;
1320 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
1321 MARKREACHED(tbptr, copy);
1322 i = *s4ptr++; /* count */
1324 tptr = DMNEW(void*, i+1);
1325 iptr->target = (void *) tptr;
1327 tptr[0] = (void *) tbptr;
1331 tbptr = m->basicblocks + m->basicblockindex[s4ptr[1]];
1333 tptr[0] = (void *) tbptr;
1336 MARKREACHED(tbptr, copy);
1340 superblockend = true;
1343 case ICMD_MONITORENTER:
1344 COUNT(count_check_null);
1345 case ICMD_MONITOREXIT:
1349 /* pop 2 push 0 branch */
1351 case ICMD_IF_ICMPEQ:
1352 case ICMD_IF_ICMPNE:
1353 case ICMD_IF_ICMPLT:
1354 case ICMD_IF_ICMPGE:
1355 case ICMD_IF_ICMPGT:
1356 case ICMD_IF_ICMPLE:
1357 COUNT(count_pcmd_bra);
1359 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1361 iptr[0].target = (void *) tbptr;
1363 MARKREACHED(tbptr, copy);
1366 case ICMD_IF_ACMPEQ:
1367 case ICMD_IF_ACMPNE:
1368 COUNT(count_pcmd_bra);
1370 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1372 iptr[0].target = (void *) tbptr;
1374 MARKREACHED(tbptr, copy);
1380 COUNT(count_check_null);
1381 COUNT(count_pcmd_mem);
1382 OPTT2_0(iptr->op1,TYPE_ADR);
1387 if (!IS_2_WORD_TYPE(curstack->type)) {
1389 #ifdef TYPECHECK_STACK_COMPCAT
1392 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1393 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1398 OP1_0ANY; /* second pop */
1401 iptr->opc = ICMD_POP;
1405 /* pop 0 push 1 dup */
1408 #ifdef TYPECHECK_STACK_COMPCAT
1411 if (IS_2_WORD_TYPE(curstack->type)) {
1412 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1417 COUNT(count_dup_instruction);
1423 if (IS_2_WORD_TYPE(curstack->type)) {
1425 iptr->opc = ICMD_DUP;
1430 /* ..., ????, cat1 */
1431 #ifdef TYPECHECK_STACK_COMPCAT
1433 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1434 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1440 NEWSTACK(copy->prev->type, copy->prev->varkind,
1441 copy->prev->varnum);
1442 NEWSTACK(copy->type, copy->varkind,
1449 /* pop 2 push 3 dup */
1452 #ifdef TYPECHECK_STACK_COMPCAT
1455 if (IS_2_WORD_TYPE(curstack->type) ||
1456 IS_2_WORD_TYPE(curstack->prev->type)) {
1457 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1467 if (IS_2_WORD_TYPE(curstack->type)) {
1468 /* ..., ????, cat2 */
1469 #ifdef TYPECHECK_STACK_COMPCAT
1471 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1472 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1477 iptr->opc = ICMD_DUP_X1;
1481 /* ..., ????, cat1 */
1482 #ifdef TYPECHECK_STACK_COMPCAT
1485 if (IS_2_WORD_TYPE(curstack->prev->type)
1486 || IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1487 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1496 /* pop 3 push 4 dup */
1500 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1501 /* ..., cat2, ???? */
1502 #ifdef TYPECHECK_STACK_COMPCAT
1504 if (IS_2_WORD_TYPE(curstack->type)) {
1505 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1510 iptr->opc = ICMD_DUP_X1;
1514 /* ..., cat1, ???? */
1515 #ifdef TYPECHECK_STACK_COMPCAT
1518 if (IS_2_WORD_TYPE(curstack->type)
1519 || IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1520 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1531 if (IS_2_WORD_TYPE(curstack->type)) {
1532 /* ..., ????, cat2 */
1533 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1534 /* ..., cat2, cat2 */
1535 iptr->opc = ICMD_DUP_X1;
1539 /* ..., cat1, cat2 */
1540 #ifdef TYPECHECK_STACK_COMPCAT
1543 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1544 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1549 iptr->opc = ICMD_DUP_X2;
1555 /* ..., ????, ????, cat1 */
1556 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1557 /* ..., cat2, ????, cat1 */
1558 #ifdef TYPECHECK_STACK_COMPCAT
1560 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1561 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1566 iptr->opc = ICMD_DUP2_X1;
1570 /* ..., cat1, ????, cat1 */
1571 #ifdef TYPECHECK_STACK_COMPCAT
1574 if (IS_2_WORD_TYPE(curstack->prev->type)
1575 || IS_2_WORD_TYPE(curstack->prev->prev->prev->type)) {
1576 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1586 /* pop 2 push 2 swap */
1589 #ifdef TYPECHECK_STACK_COMPCAT
1592 if (IS_2_WORD_TYPE(curstack->type)
1593 || IS_2_WORD_TYPE(curstack->prev->type)) {
1594 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1605 #if !SUPPORT_DIVISION
1606 iptr[0].opc = ICMD_BUILTIN2;
1607 iptr[0].op1 = TYPE_INT;
1608 iptr[0].val.fp = BUILTIN_idiv;
1609 m->isleafmethod = false;
1614 #if !SUPPORT_DIVISION
1615 /*log_text("ICMD_IREM: !SUPPORT_DIVISION");*/
1616 iptr[0].opc = ICMD_BUILTIN2;
1617 iptr[0].op1 = TYPE_INT;
1618 iptr[0].val.fp = BUILTIN_irem;
1619 m->isleafmethod = false;
1622 /*log_text("ICMD_IREM: SUPPORT_DIVISION");*/
1633 COUNT(count_pcmd_op);
1638 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1639 iptr[0].opc = ICMD_BUILTIN2;
1640 iptr[0].op1 = TYPE_LNG;
1641 iptr[0].val.fp = BUILTIN_ldiv;
1642 m->isleafmethod = false;
1647 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1648 iptr[0].opc = ICMD_BUILTIN2;
1649 iptr[0].op1 = TYPE_LNG;
1650 iptr[0].val.fp = BUILTIN_lrem;
1651 m->isleafmethod = false;
1658 #if SUPPORT_LONG_LOGICAL
1662 #endif /* SUPPORT_LONG_LOGICAL */
1663 COUNT(count_pcmd_op);
1670 COUNT(count_pcmd_op);
1679 COUNT(count_pcmd_op);
1688 COUNT(count_pcmd_op);
1693 COUNT(count_pcmd_op);
1694 #if !defined(NOLONG_CONDITIONAL)
1695 if ((len > 0) && (iptr[1].val.i == 0)) {
1696 switch (iptr[1].opc) {
1698 iptr[0].opc = ICMD_IF_LCMPEQ;
1700 iptr[0].op1 = iptr[1].op1;
1703 /* iptr[1].opc = ICMD_NOP; */
1705 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1707 iptr[0].target = (void *) tbptr;
1709 MARKREACHED(tbptr, copy);
1710 COUNT(count_pcmd_bra);
1713 iptr[0].opc = ICMD_IF_LCMPNE;
1714 goto icmd_lcmp_if_tail;
1716 iptr[0].opc = ICMD_IF_LCMPLT;
1717 goto icmd_lcmp_if_tail;
1719 iptr[0].opc = ICMD_IF_LCMPGT;
1720 goto icmd_lcmp_if_tail;
1722 iptr[0].opc = ICMD_IF_LCMPLE;
1723 goto icmd_lcmp_if_tail;
1725 iptr[0].opc = ICMD_IF_LCMPGE;
1726 goto icmd_lcmp_if_tail;
1728 OPTT2_1(TYPE_LNG, TYPE_INT);
1733 OPTT2_1(TYPE_LNG, TYPE_INT);
1737 COUNT(count_pcmd_op);
1738 OPTT2_1(TYPE_FLT, TYPE_INT);
1742 COUNT(count_pcmd_op);
1743 OPTT2_1(TYPE_DBL, TYPE_INT);
1751 case ICMD_INT2SHORT:
1752 COUNT(count_pcmd_op);
1753 OP1_1(TYPE_INT, TYPE_INT);
1756 COUNT(count_pcmd_op);
1757 OP1_1(TYPE_LNG, TYPE_LNG);
1760 COUNT(count_pcmd_op);
1761 OP1_1(TYPE_FLT, TYPE_FLT);
1764 COUNT(count_pcmd_op);
1765 OP1_1(TYPE_DBL, TYPE_DBL);
1769 COUNT(count_pcmd_op);
1770 OP1_1(TYPE_INT, TYPE_LNG);
1773 COUNT(count_pcmd_op);
1774 OP1_1(TYPE_INT, TYPE_FLT);
1777 COUNT(count_pcmd_op);
1778 OP1_1(TYPE_INT, TYPE_DBL);
1781 COUNT(count_pcmd_op);
1782 OP1_1(TYPE_LNG, TYPE_INT);
1785 COUNT(count_pcmd_op);
1786 OP1_1(TYPE_LNG, TYPE_FLT);
1789 COUNT(count_pcmd_op);
1790 OP1_1(TYPE_LNG, TYPE_DBL);
1793 COUNT(count_pcmd_op);
1794 OP1_1(TYPE_FLT, TYPE_INT);
1797 COUNT(count_pcmd_op);
1798 OP1_1(TYPE_FLT, TYPE_LNG);
1801 COUNT(count_pcmd_op);
1802 OP1_1(TYPE_FLT, TYPE_DBL);
1805 COUNT(count_pcmd_op);
1806 OP1_1(TYPE_DBL, TYPE_INT);
1809 COUNT(count_pcmd_op);
1810 OP1_1(TYPE_DBL, TYPE_LNG);
1813 COUNT(count_pcmd_op);
1814 OP1_1(TYPE_DBL, TYPE_FLT);
1817 case ICMD_CHECKCAST:
1818 OP1_1(TYPE_ADR, TYPE_ADR);
1821 case ICMD_INSTANCEOF:
1822 case ICMD_ARRAYLENGTH:
1823 OP1_1(TYPE_ADR, TYPE_INT);
1827 case ICMD_ANEWARRAY:
1828 OP1_1(TYPE_INT, TYPE_ADR);
1832 COUNT(count_check_null);
1833 COUNT(count_pcmd_mem);
1834 OP1_1(TYPE_ADR, iptr->op1);
1839 case ICMD_GETSTATIC:
1840 COUNT(count_pcmd_mem);
1850 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1852 iptr[0].target = (void *) tbptr;
1854 /* This is a dirty hack. The typechecker
1855 * needs it because the OP1_0ANY below
1856 * overwrites iptr->dst.
1858 iptr->val.a = (void *) iptr->dst;
1860 tbptr->type = BBTYPE_SBR;
1862 /* We need to check for overflow right here because
1863 * the pushed value is poped after MARKREACHED. */
1865 MARKREACHED(tbptr, copy);
1869 /* pop many push any */
1872 call_returntype = iptr->op1;
1875 #if defined(USEBUILTINTABLE) || !SUPPORT_DIVISION
1876 /* Just prevent a compiler warning... */
1880 call_returntype = iptr->op1;
1883 #if defined(USEBUILTINTABLE)
1884 /* Just prevent a compiler warning... */
1888 call_returntype = iptr->op1;
1891 case ICMD_INVOKEVIRTUAL:
1892 case ICMD_INVOKESPECIAL:
1893 case ICMD_INVOKEINTERFACE:
1894 case ICMD_INVOKESTATIC:
1895 COUNT(count_pcmd_met);
1897 #if defined(__X86_64__) || defined(__I386__) || defined(__ALPHA__) || defined(__MIPS__)
1898 unresolved_method *um = iptr->target;
1899 /* if (lm->flags & ACC_STATIC) */
1900 /* {COUNT(count_check_null);} */
1901 call_argcount = iptr->op1;
1902 call_returntype = um->methodref->parseddesc.md->returntype.type;
1904 methodinfo *lm = iptr->val.a;
1905 if (lm->flags & ACC_STATIC)
1906 {COUNT(count_check_null);}
1907 call_argcount = iptr->op1;
1908 call_returntype = lm->returntype;
1914 if (i > rd->arguments_num)
1915 rd->arguments_num = i;
1918 /* Macro in codegen.h */
1922 copy->flags |= SAVEDVAR;
1928 if (call_returntype != TYPE_VOID)
1929 OP0_1(call_returntype);
1933 case ICMD_INLINE_START:
1934 case ICMD_INLINE_END:
1938 case ICMD_MULTIANEWARRAY:
1939 if (rd->argintreguse < 3)
1940 rd->argintreguse = 3;
1945 #ifdef SPECIALMEMUSE
1946 if (rd->ifmemuse < (i + rd->intreg_argnum + 6))
1947 rd->ifmemuse = i + rd->intreg_argnum + 6;
1949 # if defined(__I386__)
1950 if (rd->ifmemuse < i + 3)
1951 rd->ifmemuse = i + 3; /* n integer args spilled on stack */
1953 if (rd->ifmemuse < i)
1954 rd->ifmemuse = i; /* n integer args spilled on stack */
1955 # endif /* defined(__I386__) */
1957 if ((i + INT_ARG_CNT) > rd->arguments_num)
1958 rd->arguments_num = i + INT_ARG_CNT;
1961 /* check INT type here? Currently typecheck does this. */
1962 if (!(copy->flags & SAVEDVAR)) {
1963 copy->varkind = ARGVAR;
1964 copy->varnum = i + INT_ARG_CNT;
1965 copy->flags|=INMEMORY;
1966 #if defined(SPECIALMEMUSE)
1967 copy->regoff = i + rd->intreg_argnum + 6;
1969 # if defined(__I386__)
1970 copy->regoff = i + 3;
1973 # endif /* defined(__I386__) */
1974 #endif /* defined(SPECIALMEMUSE) */
1979 copy->flags |= SAVEDVAR;
1987 case ICMD_CLEAR_ARGREN:
1988 for (i = iptr->op1; i < cd->maxlocals; i++)
1990 iptr->opc = opcode = ICMD_NOP;
1994 case ICMD_READONLY_ARG:
1995 case ICMD_READONLY_ARG+1:
1996 case ICMD_READONLY_ARG+2:
1997 case ICMD_READONLY_ARG+3:
1998 case ICMD_READONLY_ARG+4:
2001 if (curstack->varkind == LOCALVAR) {
2002 i = curstack->varnum;
2003 argren[iptr->op1] = i;
2006 opcode = iptr->opc = opcode - ICMD_READONLY_ARG + ICMD_ISTORE;
2013 new_exception_message(string_java_lang_InternalError,
2020 } /* while instructions */
2022 bptr->outstack = curstack;
2023 bptr->outdepth = stackdepth;
2027 superblockend = true;
2029 } /* while blocks */
2030 } while (repeat && !deadcode);
2032 #if defined(STATISTICS)
2034 if (m->basicblockcount > count_max_basic_blocks)
2035 count_max_basic_blocks = m->basicblockcount;
2036 count_basic_blocks += m->basicblockcount;
2037 if (m->instructioncount > count_max_javainstr) count_max_javainstr = m->instructioncount;
2038 count_javainstr += m->instructioncount;
2039 if (m->stackcount > count_upper_bound_new_stack)
2040 count_upper_bound_new_stack = m->stackcount;
2041 if ((new - m->stack) > count_max_new_stack)
2042 count_max_new_stack = (new - m->stack);
2044 b_count = m->basicblockcount;
2045 bptr = m->basicblocks;
2046 while (--b_count >= 0) {
2047 if (bptr->flags > BBREACHED) {
2048 if (bptr->indepth >= 10)
2049 count_block_stack[10]++;
2051 count_block_stack[bptr->indepth]++;
2054 count_block_size_distribution[len]++;
2056 count_block_size_distribution[10]++;
2058 count_block_size_distribution[11]++;
2060 count_block_size_distribution[12]++;
2062 count_block_size_distribution[13]++;
2064 count_block_size_distribution[14]++;
2066 count_block_size_distribution[15]++;
2068 count_block_size_distribution[16]++;
2070 count_block_size_distribution[17]++;
2076 count_analyse_iterations[0]++;
2077 else if (loops == 2)
2078 count_analyse_iterations[1]++;
2079 else if (loops == 3)
2080 count_analyse_iterations[2]++;
2081 else if (loops == 4)
2082 count_analyse_iterations[3]++;
2084 count_analyse_iterations[4]++;
2086 if (m->basicblockcount <= 5)
2087 count_method_bb_distribution[0]++;
2088 else if (m->basicblockcount <= 10)
2089 count_method_bb_distribution[1]++;
2090 else if (m->basicblockcount <= 15)
2091 count_method_bb_distribution[2]++;
2092 else if (m->basicblockcount <= 20)
2093 count_method_bb_distribution[3]++;
2094 else if (m->basicblockcount <= 30)
2095 count_method_bb_distribution[4]++;
2096 else if (m->basicblockcount <= 40)
2097 count_method_bb_distribution[5]++;
2098 else if (m->basicblockcount <= 50)
2099 count_method_bb_distribution[6]++;
2100 else if (m->basicblockcount <= 75)
2101 count_method_bb_distribution[7]++;
2103 count_method_bb_distribution[8]++;
2107 /* just return methodinfo* to signal everything was ok */
2113 /**********************************************************************/
2114 /* DEBUGGING HELPERS */
2115 /**********************************************************************/
2117 void icmd_print_stack(codegendata *cd, stackptr s)
2129 j = cd->maxstack - i;
2134 /* DEBUG */ /*printf("(%d,%d,%d,%d)",s->varkind,s->flags,s->regoff,s->varnum); fflush(stdout);*/
2135 if (s->flags & SAVEDVAR)
2136 switch (s->varkind) {
2138 if (s->flags & INMEMORY)
2139 printf(" M%02d", s->regoff);
2140 #ifdef HAS_ADDRESS_REGISTER_FILE
2141 else if (s->type == TYPE_ADR)
2142 printf(" R%02d", s->regoff);
2144 else if (IS_FLT_DBL_TYPE(s->type))
2145 printf(" F%02d", s->regoff);
2147 printf(" %3s", regs[s->regoff]);
2151 printf(" I%02d", s->varnum);
2154 printf(" L%02d", s->varnum);
2157 printf(" A%02d", s->varnum);
2158 #ifdef INVOKE_NEW_DEBUG
2159 if (s->flags & INMEMORY)
2160 printf("(M%i)", s->regoff);
2162 printf("(R%i)", s->regoff);
2166 printf(" !%02d", j);
2169 switch (s->varkind) {
2171 if (s->flags & INMEMORY)
2172 printf(" m%02d", s->regoff);
2173 #ifdef HAS_ADDRESS_REGISTER_FILE
2174 else if (s->type == TYPE_ADR)
2175 printf(" r%02d", s->regoff);
2177 else if (IS_FLT_DBL_TYPE(s->type))
2178 printf(" f%02d", s->regoff);
2180 printf(" %3s", regs[s->regoff]);
2184 printf(" i%02d", s->varnum);
2187 printf(" l%02d", s->varnum);
2190 printf(" a%02d", s->varnum);
2191 #ifdef INVOKE_NEW_DEBUG
2192 if (s->flags & INMEMORY)
2193 printf("(M%i)", s->regoff);
2195 printf("(R%i)", s->regoff);
2199 printf(" ?%02d", j);
2207 static void print_reg(stackptr s) {
2209 if (s->flags & SAVEDVAR)
2210 switch (s->varkind) {
2212 if (s->flags & INMEMORY)
2213 printf(" tm%02d", s->regoff);
2215 printf(" tr%02d", s->regoff);
2218 printf(" s %02d", s->varnum);
2221 printf(" l %02d", s->varnum);
2224 printf(" a %02d", s->varnum);
2227 printf(" ! %02d", s->varnum);
2230 switch (s->varkind) {
2232 if (s->flags & INMEMORY)
2233 printf(" Tm%02d", s->regoff);
2235 printf(" Tr%02d", s->regoff);
2238 printf(" S %02d", s->varnum);
2241 printf(" L %02d", s->varnum);
2244 printf(" A %02d", s->varnum);
2247 printf(" ? %02d", s->varnum);
2257 char *icmd_builtin_name(functionptr bptr)
2259 builtin_descriptor *bdesc = builtin_desc;
2260 while ((bdesc->opcode != 0) && (bdesc->builtin != bptr))
2262 return (bdesc->opcode) ? bdesc->name : "<NOT IN TABLE>";
2266 static char *jit_type[] = {
2275 void show_icmd_method(methodinfo *m, codegendata *cd, registerdata *rd)
2282 utf_fprint_classname(stdout, m->class->name);
2284 utf_fprint(stdout, m->name);
2285 utf_fprint_classname(stdout, m->descriptor);
2286 printf("\n\nMax locals: %d\n", (int) cd->maxlocals);
2287 printf("Max stack: %d\n", (int) cd->maxstack);
2289 printf("Line number table length: %d\n", m->linenumbercount);
2291 printf("Exceptions (Number: %d):\n", cd->exceptiontablelength);
2292 for (ex = cd->exceptiontable; ex != NULL; ex = ex->down) {
2293 printf(" L%03d ... ", ex->start->debug_nr );
2294 printf("L%03d = ", ex->end->debug_nr);
2295 printf("L%03d", ex->handler->debug_nr);
2296 printf(" (catchtype: ");
2297 if (ex->catchtype.any)
2298 if (IS_CLASSREF(ex->catchtype))
2299 utf_display_classname(ex->catchtype.ref->name);
2301 utf_display_classname(ex->catchtype.cls->name);
2307 printf("Local Table:\n");
2308 for (i = 0; i < cd->maxlocals; i++) {
2309 printf(" %3d: ", i);
2310 for (j = TYPE_INT; j <= TYPE_ADR; j++)
2311 if (rd->locals[i][j].type >= 0) {
2312 printf(" (%s) ", jit_type[j]);
2313 if (rd->locals[i][j].flags & INMEMORY)
2314 printf("m%2d", rd->locals[i][j].regoff);
2315 #ifdef HAS_ADDRESS_REGISTER_FILE
2316 else if (j == TYPE_ADR)
2317 printf("r%02d", rd->locals[i][j].regoff);
2319 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2320 printf("f%02d", rd->locals[i][j].regoff);
2322 printf("%3s", regs[rd->locals[i][j].regoff]);
2331 printf("Interface Table:\n");
2332 for (i = 0; i < cd->maxstack; i++) {
2333 if ((rd->interfaces[i][0].type >= 0) ||
2334 (rd->interfaces[i][1].type >= 0) ||
2335 (rd->interfaces[i][2].type >= 0) ||
2336 (rd->interfaces[i][3].type >= 0) ||
2337 (rd->interfaces[i][4].type >= 0)) {
2338 printf(" %3d: ", i);
2339 for (j = TYPE_INT; j <= TYPE_ADR; j++)
2340 if (rd->interfaces[i][j].type >= 0) {
2341 printf(" (%s) ", jit_type[j]);
2342 if (rd->interfaces[i][j].flags & SAVEDVAR) {
2343 if (rd->interfaces[i][j].flags & INMEMORY)
2344 printf("M%2d", rd->interfaces[i][j].regoff);
2345 #ifdef HAS_ADDRESS_REGISTER_FILE
2346 else if (j == TYPE_ADR)
2347 printf("R%02d", rd->interfaces[i][j].regoff);
2349 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2350 printf("F%02d", rd->interfaces[i][j].regoff);
2352 printf("%3s", regs[rd->interfaces[i][j].regoff]);
2356 if (rd->interfaces[i][j].flags & INMEMORY)
2357 printf("m%2d", rd->interfaces[i][j].regoff);
2358 #ifdef HAS_ADDRESS_REGISTER_FILE
2359 else if (j == TYPE_ADR)
2360 printf("r%02d", rd->interfaces[i][j].regoff);
2362 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2363 printf("f%02d", rd->interfaces[i][j].regoff);
2365 printf("%3s", regs[rd->interfaces[i][j].regoff]);
2376 if (showdisassemble) {
2377 #if defined(__I386__) || defined(__X86_64__)
2381 u1ptr = (u1 *) ((ptrint) m->mcode + cd->dseglen);
2382 for (i = 0; i < m->basicblocks[0].mpc;) {
2383 a = disassinstr(u1ptr);
2388 #elif defined(__XDSPCORE__)
2392 s4ptr = (s4 *) ((ptrint) m->mcode + cd->dseglen);
2393 for (i = 0; i < m->basicblocks[0].mpc;) {
2394 a = disassinstr(stdout, s4ptr);
2403 s4ptr = (s4 *) ((ptrint) m->mcode + cd->dseglen);
2404 for (i = 0; i < m->basicblocks[0].mpc; i += 4, s4ptr++) {
2411 for (bptr = m->basicblocks; bptr != NULL; bptr = bptr->next) {
2412 show_icmd_block(m, cd, bptr);
2417 void show_icmd_block(methodinfo *m, codegendata *cd, basicblock *bptr)
2423 if (bptr->flags != BBDELETED) {
2424 deadcode = bptr->flags <= BBREACHED;
2427 for (j = cd->maxstack; j > 0; j--)
2430 icmd_print_stack(cd, bptr->instack);
2431 printf("] L%03d(%d - %d) flags=%d:\n", bptr->debug_nr, bptr->icount, bptr->pre_count,bptr->flags);
2432 iptr = bptr->iinstr;
2434 for (i = 0; i < bptr->icount; i++, iptr++) {
2437 for (j = cd->maxstack; j > 0; j--)
2441 icmd_print_stack(cd, iptr->dst);
2442 printf("] %4d ", i);
2445 if (icmd_uses_tmp[iptr->opc][0])
2449 if (icmd_uses_tmp[iptr->opc][1])
2453 if (icmd_uses_tmp[iptr->opc][2])
2459 show_icmd(iptr, deadcode);
2463 if (showdisassemble && (!deadcode)) {
2464 #if defined(__I386__) || defined(__X86_64__)
2470 u1ptr = (u1 *) ((ptrint) m->mcode + cd->dseglen + i);
2472 if (bptr->next != NULL) {
2473 for (; i < bptr->next->mpc; ) {
2474 a = disassinstr(u1ptr);
2481 for (; u1ptr < (u1 *) ((ptrint) m->mcode + m->mcodelength); ) {
2482 a = disassinstr(u1ptr);
2488 #elif defined(__XDSPCORE__)
2494 s4ptr = (s4 *) ((ptrint) m->mcode + cd->dseglen + i);
2496 if (bptr->next != NULL) {
2497 for (; i < bptr->next->mpc;) {
2498 a = disassinstr(stdout, s4ptr);
2506 for (; s4ptr < (s4 *) ((ptrint) m->mcode + m->mcodelength); ) {
2507 a = disassinstr(stdout, s4ptr);
2518 s4ptr = (s4 *) ((ptrint) m->mcode + cd->dseglen + i);
2520 if (bptr->next != NULL) {
2521 for (; i < bptr->next->mpc; i += 4, s4ptr++)
2526 for (; s4ptr < (s4 *) ((ptrint) m->mcode + m->mcodelength); i += 4, s4ptr++)
2536 void show_icmd(instruction *iptr, bool deadcode)
2542 printf("%s", icmd_names[iptr->opc]);
2544 switch (iptr->opc) {
2545 case ICMD_IADDCONST:
2546 case ICMD_ISUBCONST:
2547 case ICMD_IMULCONST:
2551 case ICMD_IANDCONST:
2553 case ICMD_IXORCONST:
2554 case ICMD_ISHLCONST:
2555 case ICMD_ISHRCONST:
2556 case ICMD_IUSHRCONST:
2557 case ICMD_LSHLCONST:
2558 case ICMD_LSHRCONST:
2559 case ICMD_LUSHRCONST:
2561 case ICMD_ELSE_ICONST:
2562 case ICMD_IASTORECONST:
2563 case ICMD_BASTORECONST:
2564 case ICMD_CASTORECONST:
2565 case ICMD_SASTORECONST:
2566 printf(" %d (0x%08x)", iptr->val.i, iptr->val.i);
2569 case ICMD_IFEQ_ICONST:
2570 case ICMD_IFNE_ICONST:
2571 case ICMD_IFLT_ICONST:
2572 case ICMD_IFGE_ICONST:
2573 case ICMD_IFGT_ICONST:
2574 case ICMD_IFLE_ICONST:
2575 printf("(%d) %d", iptr[1].op1, iptr->val.i);
2578 case ICMD_LADDCONST:
2579 case ICMD_LSUBCONST:
2580 case ICMD_LMULCONST:
2584 case ICMD_LANDCONST:
2586 case ICMD_LXORCONST:
2588 case ICMD_LASTORECONST:
2589 #if defined(__I386__) || defined(__POWERPC__)
2590 printf(" %lld (0x%016llx)", iptr->val.l, iptr->val.l);
2592 printf(" %ld (0x%016lx)", iptr->val.l, iptr->val.l);
2597 printf(" %f", iptr->val.f);
2601 printf(" %f", iptr->val.d);
2605 case ICMD_AASTORECONST:
2606 printf(" %p", iptr->val.a);
2611 #if defined(__X86_64__) || defined(__I386__) || defined(__ALPHA__) || defined(__MIPS__)
2613 printf(" %d, ", ((fieldinfo *) iptr->val.a)->offset);
2615 printf(" (NOT RESOLVED), ");
2616 utf_display_classname(((unresolved_field *) iptr->target)->fieldref->classref->name);
2618 utf_display(((unresolved_field *) iptr->target)->fieldref->name);
2620 utf_display(((unresolved_field *) iptr->target)->fieldref->descriptor);
2623 printf(" %d,", ((fieldinfo *) iptr->val.a)->offset);
2625 utf_display_classname(((fieldinfo *) iptr->val.a)->class->name);
2627 utf_display(((fieldinfo *) iptr->val.a)->name);
2629 utf_display(((fieldinfo *) iptr->val.a)->descriptor);
2634 case ICMD_PUTSTATIC:
2635 case ICMD_GETSTATIC:
2636 #if defined(__X86_64__) || defined(__I386__) || defined(__ALPHA__) || defined(__MIPS__)
2640 printf(" (NOT RESOLVED) ");
2641 utf_display_classname(((unresolved_field *) iptr->target)->fieldref->classref->name);
2643 utf_display(((unresolved_field *) iptr->target)->fieldref->name);
2645 utf_display(((unresolved_field *) iptr->target)->fieldref->descriptor);
2649 utf_display_classname(((fieldinfo *) iptr->val.a)->class->name);
2651 utf_display(((fieldinfo *) iptr->val.a)->name);
2653 utf_display(((fieldinfo *) iptr->val.a)->descriptor);
2658 case ICMD_PUTSTATICCONST:
2659 case ICMD_PUTFIELDCONST:
2660 switch (iptr[1].op1) {
2662 printf(" %d,", iptr->val.i);
2665 #if defined(__I386__) || defined(__POWERPC__)
2666 printf(" %lld,", iptr->val.l);
2668 printf(" %ld,", iptr->val.l);
2672 printf(" %p,", iptr->val.a);
2675 printf(" %g,", iptr->val.f);
2678 printf(" %g,", iptr->val.d);
2681 #if defined(__X86_64__) || defined(__I386__) || defined(__ALPHA__) || defined(__MIPS__)
2682 if (iptr->opc == ICMD_PUTFIELDCONST)
2683 printf(" NOT RESOLVED,");
2685 utf_display_classname(((unresolved_field *) iptr[1].target)->fieldref->classref->name);
2687 utf_display(((unresolved_field *) iptr[1].target)->fieldref->name);
2689 utf_display(((unresolved_field *) iptr[1].target)->fieldref->descriptor);
2692 if (iptr->opc == ICMD_PUTFIELDCONST)
2693 printf(" %d,", ((fieldinfo *) iptr[1].val.a)->offset);
2695 utf_display_classname(((fieldinfo *) iptr[1].val.a)->class->name);
2697 utf_display(((fieldinfo *) iptr[1].val.a)->name);
2699 utf_display(((fieldinfo *) iptr[1].val.a)->descriptor);
2705 printf(" %d + %d", iptr->op1, iptr->val.i);
2740 printf(" %d", iptr->op1);
2745 utf_display_classname(((classinfo *) iptr->val.a)->name);
2749 switch (iptr->op1) {
2777 case ICMD_ANEWARRAY:
2780 utf_display_classname(((classinfo *) iptr->val.a)->name);
2784 case ICMD_MULTIANEWARRAY:
2787 printf(" %d ",iptr->op1);
2788 vft = (vftbl_t *)iptr->val.a;
2790 utf_display_classname(vft->class->name);
2796 case ICMD_CHECKCAST:
2797 case ICMD_INSTANCEOF:
2798 #if defined(__X86_64__) || defined(__I386__) || defined(__ALPHA__) || defined(__MIPS__)
2800 classinfo *c = iptr->val.a;
2802 if (c->flags & ACC_INTERFACE)
2803 printf(" (INTERFACE) ");
2805 printf(" (CLASS,%3d) ", c->vftbl->diffval);
2807 printf(" (NOT RESOLVED) ");
2809 utf_display_classname(((constant_classref *) iptr->target)->name);
2814 classinfo *c = iptr->val.a;
2815 if (c->flags & ACC_INTERFACE)
2816 printf(" (INTERFACE) ");
2818 printf(" (CLASS,%3d) ", c->vftbl->diffval);
2819 utf_display_classname(c->name);
2823 case ICMD_INLINE_START:
2824 printf("\t\t\t%s.%s%s depth=%i",iptr->method->class->name->text,iptr->method->name->text,iptr->method->descriptor->text, iptr->op1);
2826 case ICMD_INLINE_END:
2832 printf(" %s", icmd_builtin_name((functionptr) iptr->val.fp));
2835 case ICMD_INVOKEVIRTUAL:
2836 case ICMD_INVOKESPECIAL:
2837 case ICMD_INVOKESTATIC:
2838 case ICMD_INVOKEINTERFACE:
2839 #if defined(__X86_64__) || defined(__I386__) || defined(__ALPHA__) || defined(__MIPS__)
2841 printf(" (NOT RESOLVED) ");
2844 utf_display_classname(((unresolved_method *) iptr->target)->methodref->classref->name);
2846 utf_display(((unresolved_method *) iptr->target)->methodref->name);
2847 utf_display(((unresolved_method *) iptr->target)->methodref->descriptor);
2850 utf_display_classname(((methodinfo *) iptr->val.a)->class->name);
2852 utf_display(((methodinfo *) iptr->val.a)->name);
2853 utf_display(((methodinfo *) iptr->val.a)->descriptor);
2863 if (deadcode || !iptr->target)
2864 printf("(%d) op1=%d", iptr->val.i, iptr->op1);
2866 printf("(%d) L%03d", iptr->val.i, ((basicblock *) iptr->target)->debug_nr);
2875 if (deadcode || !iptr->target)
2876 #if defined(__I386__) || defined(__POWERPC__)
2877 printf("(%lld) op1=%d", iptr->val.l, iptr->op1);
2879 printf("(%ld) op1=%d", iptr->val.l, iptr->op1);
2882 #if defined(__I386__) || defined(__POWERPC__)
2883 printf("(%lld) L%03d", iptr->val.l, ((basicblock *) iptr->target)->debug_nr);
2885 printf("(%ld) L%03d", iptr->val.l, ((basicblock *) iptr->target)->debug_nr);
2892 case ICMD_IFNONNULL:
2893 case ICMD_IF_ICMPEQ:
2894 case ICMD_IF_ICMPNE:
2895 case ICMD_IF_ICMPLT:
2896 case ICMD_IF_ICMPGE:
2897 case ICMD_IF_ICMPGT:
2898 case ICMD_IF_ICMPLE:
2899 case ICMD_IF_LCMPEQ:
2900 case ICMD_IF_LCMPNE:
2901 case ICMD_IF_LCMPLT:
2902 case ICMD_IF_LCMPGE:
2903 case ICMD_IF_LCMPGT:
2904 case ICMD_IF_LCMPLE:
2905 case ICMD_IF_ACMPEQ:
2906 case ICMD_IF_ACMPNE:
2907 if (deadcode || !iptr->target)
2908 printf(" op1=%d", iptr->op1);
2910 printf(" L%03d", ((basicblock *) iptr->target)->debug_nr);
2913 case ICMD_TABLESWITCH:
2914 s4ptr = (s4*)iptr->val.a;
2916 if (deadcode || !iptr->target) {
2917 printf(" %d;", *s4ptr);
2920 tptr = (void **) iptr->target;
2921 printf(" L%03d;", ((basicblock *) *tptr)->debug_nr);
2925 s4ptr++; /* skip default */
2926 j = *s4ptr++; /* low */
2927 j = *s4ptr++ - j; /* high */
2929 if (deadcode || !*tptr)
2930 printf(" %d", *s4ptr++);
2932 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2939 case ICMD_LOOKUPSWITCH:
2940 s4ptr = (s4*)iptr->val.a;
2942 if (deadcode || !iptr->target) {
2943 printf(" %d;", *s4ptr);
2946 tptr = (void **) iptr->target;
2947 printf(" L%03d;", ((basicblock *) *tptr)->debug_nr);
2950 s4ptr++; /* default */
2951 j = *s4ptr++; /* count */
2954 if (deadcode || !*tptr) {
2955 s4ptr++; /* skip value */
2956 printf(" %d",*s4ptr++);
2959 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2965 printf(" Line number: %d, method:",iptr->line);
2967 utf_display(iptr->method->class->name);
2969 utf_display(iptr->method->name); */
2974 * These are local overrides for various environment variables in Emacs.
2975 * Please do not remove this and leave it at the end of the file, where
2976 * Emacs will automagically detect them.
2977 * ---------------------------------------------------------------------
2980 * indent-tabs-mode: t