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 2458 2005-05-12 23:02:07Z twisti $
43 #include "mm/memory.h"
44 #include "native/native.h"
45 #include "toolbox/logging.h"
46 #include "vm/global.h"
47 #include "vm/builtin.h"
48 #include "vm/options.h"
49 #include "vm/resolve.h"
50 #include "vm/statistics.h"
51 #include "vm/stringlocal.h"
52 #include "vm/tables.h"
53 #include "vm/jit/codegen.inc.h"
54 #include "vm/jit/jit.h"
55 #include "vm/jit/reg.h"
56 #include "vm/jit/stack.h"
57 #include "vm/jit/lsra.h"
60 /**********************************************************************/
62 /**********************************************************************/
64 /* analyse_stack uses the intermediate code created by parse.c to
65 * build a model of the JVM operand stack for the current method.
67 * The following checks are performed:
68 * - check for operand stack underflow (before each instruction)
69 * - check for operand stack overflow (after[1] each instruction)
70 * - check for matching stack depth at merging points
71 * - check for matching basic types[2] at merging points
72 * - check basic types for instruction input (except for BUILTIN*
73 * opcodes, INVOKE* opcodes and MULTIANEWARRAY)
75 * [1]) Checking this after the instruction should be ok. parse.c
76 * counts the number of required stack slots in such a way that it is
77 * only vital that we don't exceed `maxstack` at basic block
80 * [2]) 'basic types' means the distinction between INT, LONG, FLOAT,
81 * DOUBLE and ADDRESS types. Subtypes of INT and different ADDRESS
82 * types are not discerned.
85 methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
93 int opcode, i, len, loops;
94 int superblockend, repeat, deadcode;
109 argren = DMNEW(s4, cd->maxlocals); /* table for argument renaming */
110 for (i = 0; i < cd->maxlocals; i++)
113 rd->arguments_num = 0;
116 m->basicblocks[0].flags = BBREACHED;
117 m->basicblocks[0].instack = 0;
118 m->basicblocks[0].indepth = 0;
120 for (i = 0; i < cd->exceptiontablelength; i++) {
121 bptr = &m->basicblocks[m->basicblockindex[cd->exceptiontable[i].handlerpc]];
122 bptr->flags = BBREACHED;
123 bptr->type = BBTYPE_EXH;
126 bptr->pre_count = 10000;
131 #if CONDITIONAL_LOADCONST
132 b_count = m->basicblockcount;
133 bptr = m->basicblocks;
134 while (--b_count >= 0) {
135 if (bptr->icount != 0) {
136 iptr = bptr->iinstr + bptr->icount - 1;
169 m->basicblocks[m->basicblockindex[iptr->op1]].pre_count++;
172 case ICMD_TABLESWITCH:
174 m->basicblocks[m->basicblockindex[*s4ptr++]].pre_count++;
175 i = *s4ptr++; /* low */
176 i = *s4ptr++ - i + 1; /* high */
178 m->basicblocks[m->basicblockindex[*s4ptr++]].pre_count++;
182 case ICMD_LOOKUPSWITCH:
184 m->basicblocks[m->basicblockindex[*s4ptr++]].pre_count++;
185 i = *s4ptr++; /* count */
187 m->basicblocks[m->basicblockindex[s4ptr[1]]].pre_count++;
198 #endif /* CONDITIONAL_LOADCONST */
203 b_count = m->basicblockcount;
204 bptr = m->basicblocks;
205 superblockend = true;
209 /*printf("Block count :%d\n",b_count);*/
210 while (--b_count >= 0) {
211 if (bptr->flags == BBDELETED) {
213 /*log_text("BBDELETED");*/
215 else if (superblockend && (bptr->flags < BBREACHED))
217 else if (bptr->flags <= BBREACHED) {
219 stackdepth = bptr->indepth;
220 else if (bptr->flags < BBREACHED) {
222 bptr->instack = copy;
223 bptr->indepth = stackdepth;
225 else if (bptr->indepth != stackdepth) {
226 show_icmd_method(m, cd, rd);
227 printf("Block: %d, required depth: %d, current depth: %d\n", bptr->debug_nr, bptr->indepth, stackdepth);
228 panic("Stack depth mismatch");
231 curstack = bptr->instack;
233 superblockend = false;
234 bptr->flags = BBFINISHED;
237 b_index = bptr - m->basicblocks;
240 /* XXX TWISTI: why is this set to NULL here? */
241 /* iptr->target = NULL; */
243 /* dolog("p: %04d op: %s stack: %p", iptr - instr, icmd_names[opcode], curstack); */
245 #if defined(USEBUILTINTABLE)
248 stdopdescriptor *breplace;
249 breplace = find_builtin(opcode);
251 if (breplace && opcode == breplace->opcode) {
252 iptr[0].opc = breplace->icmd;
253 iptr[0].op1 = breplace->type_d;
254 iptr[0].val.fp = breplace->builtin;
255 m->isleafmethod = false;
256 switch (breplace->icmd) {
264 builtin_descriptor *breplace;
265 breplace = find_builtin(opcode);
267 if (breplace && opcode == breplace->opcode) {
268 iptr[0].opc = breplace->icmd;
269 iptr[0].op1 = breplace->type_d;
270 iptr[0].val.fp = breplace->builtin;
271 m->isleafmethod = false;
272 switch (breplace->icmd) {
280 #endif /* defined(USEBUILTINTABLE) */
287 COUNT(count_check_null);
289 case ICMD_CHECKASIZE:
290 case ICMD_CHECKEXCEPTION:
292 case ICMD_IFEQ_ICONST:
293 case ICMD_IFNE_ICONST:
294 case ICMD_IFLT_ICONST:
295 case ICMD_IFGE_ICONST:
296 case ICMD_IFGT_ICONST:
297 case ICMD_IFLE_ICONST:
298 case ICMD_ELSE_ICONST:
303 rd->locals[iptr->op1][TYPE_ADR].type = TYPE_ADR;
305 COUNT(count_pcmd_return);
307 superblockend = true;
310 /* pop 0 push 1 const */
313 COUNT(count_pcmd_load);
315 switch (iptr[1].opc) {
317 iptr[0].opc = ICMD_IADDCONST;
319 iptr[1].opc = ICMD_NOP;
320 OP1_1(TYPE_INT, TYPE_INT);
321 COUNT(count_pcmd_op);
324 iptr[0].opc = ICMD_ISUBCONST;
325 goto icmd_iconst_tail;
326 #if SUPPORT_CONST_MUL
328 iptr[0].opc = ICMD_IMULCONST;
329 goto icmd_iconst_tail;
330 #else /* SUPPORT_CONST_MUL */
332 if (iptr[0].val.i == 0x00000002)
334 else if (iptr[0].val.i == 0x00000004)
336 else if (iptr[0].val.i == 0x00000008)
338 else if (iptr[0].val.i == 0x00000010)
340 else if (iptr[0].val.i == 0x00000020)
342 else if (iptr[0].val.i == 0x00000040)
344 else if (iptr[0].val.i == 0x00000080)
346 else if (iptr[0].val.i == 0x00000100)
348 else if (iptr[0].val.i == 0x00000200)
350 else if (iptr[0].val.i == 0x00000400)
352 else if (iptr[0].val.i == 0x00000800)
354 else if (iptr[0].val.i == 0x00001000)
356 else if (iptr[0].val.i == 0x00002000)
358 else if (iptr[0].val.i == 0x00004000)
360 else if (iptr[0].val.i == 0x00008000)
362 else if (iptr[0].val.i == 0x00010000)
364 else if (iptr[0].val.i == 0x00020000)
366 else if (iptr[0].val.i == 0x00040000)
368 else if (iptr[0].val.i == 0x00080000)
370 else if (iptr[0].val.i == 0x00100000)
372 else if (iptr[0].val.i == 0x00200000)
374 else if (iptr[0].val.i == 0x00400000)
376 else if (iptr[0].val.i == 0x00800000)
378 else if (iptr[0].val.i == 0x01000000)
380 else if (iptr[0].val.i == 0x02000000)
382 else if (iptr[0].val.i == 0x04000000)
384 else if (iptr[0].val.i == 0x08000000)
386 else if (iptr[0].val.i == 0x10000000)
388 else if (iptr[0].val.i == 0x20000000)
390 else if (iptr[0].val.i == 0x40000000)
392 else if (iptr[0].val.i == 0x80000000)
398 iptr[0].opc = ICMD_IMULPOW2;
399 goto icmd_iconst_tail;
400 #endif /* SUPPORT_CONST_MUL */
402 if (iptr[0].val.i == 0x00000002)
404 else if (iptr[0].val.i == 0x00000004)
406 else if (iptr[0].val.i == 0x00000008)
408 else if (iptr[0].val.i == 0x00000010)
410 else if (iptr[0].val.i == 0x00000020)
412 else if (iptr[0].val.i == 0x00000040)
414 else if (iptr[0].val.i == 0x00000080)
416 else if (iptr[0].val.i == 0x00000100)
418 else if (iptr[0].val.i == 0x00000200)
420 else if (iptr[0].val.i == 0x00000400)
422 else if (iptr[0].val.i == 0x00000800)
424 else if (iptr[0].val.i == 0x00001000)
426 else if (iptr[0].val.i == 0x00002000)
428 else if (iptr[0].val.i == 0x00004000)
430 else if (iptr[0].val.i == 0x00008000)
432 else if (iptr[0].val.i == 0x00010000)
434 else if (iptr[0].val.i == 0x00020000)
436 else if (iptr[0].val.i == 0x00040000)
438 else if (iptr[0].val.i == 0x00080000)
440 else if (iptr[0].val.i == 0x00100000)
442 else if (iptr[0].val.i == 0x00200000)
444 else if (iptr[0].val.i == 0x00400000)
446 else if (iptr[0].val.i == 0x00800000)
448 else if (iptr[0].val.i == 0x01000000)
450 else if (iptr[0].val.i == 0x02000000)
452 else if (iptr[0].val.i == 0x04000000)
454 else if (iptr[0].val.i == 0x08000000)
456 else if (iptr[0].val.i == 0x10000000)
458 else if (iptr[0].val.i == 0x20000000)
460 else if (iptr[0].val.i == 0x40000000)
462 else if (iptr[0].val.i == 0x80000000)
468 iptr[0].opc = ICMD_IDIVPOW2;
469 goto icmd_iconst_tail;
471 /*log_text("stack.c: ICMD_ICONST/ICMD_IREM");*/
472 if ((iptr[0].val.i == 0x00000002) ||
473 (iptr[0].val.i == 0x00000004) ||
474 (iptr[0].val.i == 0x00000008) ||
475 (iptr[0].val.i == 0x00000010) ||
476 (iptr[0].val.i == 0x00000020) ||
477 (iptr[0].val.i == 0x00000040) ||
478 (iptr[0].val.i == 0x00000080) ||
479 (iptr[0].val.i == 0x00000100) ||
480 (iptr[0].val.i == 0x00000200) ||
481 (iptr[0].val.i == 0x00000400) ||
482 (iptr[0].val.i == 0x00000800) ||
483 (iptr[0].val.i == 0x00001000) ||
484 (iptr[0].val.i == 0x00002000) ||
485 (iptr[0].val.i == 0x00004000) ||
486 (iptr[0].val.i == 0x00008000) ||
487 (iptr[0].val.i == 0x00010000) ||
488 (iptr[0].val.i == 0x00020000) ||
489 (iptr[0].val.i == 0x00040000) ||
490 (iptr[0].val.i == 0x00080000) ||
491 (iptr[0].val.i == 0x00100000) ||
492 (iptr[0].val.i == 0x00200000) ||
493 (iptr[0].val.i == 0x00400000) ||
494 (iptr[0].val.i == 0x00800000) ||
495 (iptr[0].val.i == 0x01000000) ||
496 (iptr[0].val.i == 0x02000000) ||
497 (iptr[0].val.i == 0x04000000) ||
498 (iptr[0].val.i == 0x08000000) ||
499 (iptr[0].val.i == 0x10000000) ||
500 (iptr[0].val.i == 0x20000000) ||
501 (iptr[0].val.i == 0x40000000) ||
502 (iptr[0].val.i == 0x80000000)) {
503 iptr[0].opc = ICMD_IREMPOW2;
505 goto icmd_iconst_tail;
509 #if SUPPORT_CONST_LOGICAL
511 iptr[0].opc = ICMD_IANDCONST;
512 goto icmd_iconst_tail;
514 iptr[0].opc = ICMD_IORCONST;
515 goto icmd_iconst_tail;
517 iptr[0].opc = ICMD_IXORCONST;
518 goto icmd_iconst_tail;
519 #endif /* SUPPORT_CONST_LOGICAL */
521 iptr[0].opc = ICMD_ISHLCONST;
522 goto icmd_iconst_tail;
524 iptr[0].opc = ICMD_ISHRCONST;
525 goto icmd_iconst_tail;
527 iptr[0].opc = ICMD_IUSHRCONST;
528 goto icmd_iconst_tail;
529 #if SUPPORT_LONG_SHIFT
531 iptr[0].opc = ICMD_LSHLCONST;
532 goto icmd_lconst_tail;
534 iptr[0].opc = ICMD_LSHRCONST;
535 goto icmd_lconst_tail;
537 iptr[0].opc = ICMD_LUSHRCONST;
538 goto icmd_lconst_tail;
539 #endif /* SUPPORT_LONG_SHIFT */
541 iptr[0].opc = ICMD_IFEQ;
543 iptr[0].op1 = iptr[1].op1;
547 /* iptr[1].opc = ICMD_NOP; */
549 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
551 iptr[0].target = (void *) tbptr;
553 MARKREACHED(tbptr, copy);
554 COUNT(count_pcmd_bra);
560 iptr[0].opc = ICMD_IFLT;
561 goto icmd_if_icmp_tail;
563 iptr[0].opc = ICMD_IFLE;
564 goto icmd_if_icmp_tail;
566 iptr[0].opc = ICMD_IFNE;
567 goto icmd_if_icmp_tail;
569 iptr[0].opc = ICMD_IFGT;
570 goto icmd_if_icmp_tail;
572 iptr[0].opc = ICMD_IFGE;
573 goto icmd_if_icmp_tail;
575 #if SUPPORT_CONST_STORE
580 #if SUPPORT_CONST_STORE_ZERO_ONLY
581 if (iptr[0].val.i == 0) {
582 #endif /* SUPPORT_CONST_STORE_ZERO_ONLY */
583 switch (iptr[1].opc) {
585 iptr[0].opc = ICMD_IASTORECONST;
588 iptr[0].opc = ICMD_BASTORECONST;
591 iptr[0].opc = ICMD_CASTORECONST;
594 iptr[0].opc = ICMD_SASTORECONST;
598 iptr[1].opc = ICMD_NOP;
599 OPTT2_0(TYPE_INT, TYPE_ADR);
600 COUNT(count_pcmd_op);
601 #if SUPPORT_CONST_STORE_ZERO_ONLY
604 #endif /* SUPPORT_CONST_STORE_ZERO_ONLY */
609 #if SUPPORT_CONST_STORE_ZERO_ONLY
610 if (iptr[0].val.i == 0) {
611 #endif /* SUPPORT_CONST_STORE_ZERO_ONLY */
612 switch (iptr[1].opc) {
614 iptr[0].opc = ICMD_PUTSTATICCONST;
618 iptr[0].opc = ICMD_PUTFIELDCONST;
623 iptr[1].opc = ICMD_NOP;
624 iptr[0].op1 = TYPE_INT;
625 COUNT(count_pcmd_op);
626 #if SUPPORT_CONST_STORE_ZERO_ONLY
629 #endif /* SUPPORT_CONST_STORE_ZERO_ONLY */
631 #endif /* SUPPORT_CONST_STORE */
641 COUNT(count_pcmd_load);
643 switch (iptr[1].opc) {
646 iptr[0].opc = ICMD_LADDCONST;
648 iptr[1].opc = ICMD_NOP;
649 OP1_1(TYPE_LNG,TYPE_LNG);
650 COUNT(count_pcmd_op);
653 iptr[0].opc = ICMD_LSUBCONST;
654 goto icmd_lconst_tail;
655 #endif /* SUPPORT_LONG_ADD */
656 #if SUPPORT_LONG_MUL && SUPPORT_CONST_MUL
658 iptr[0].opc = ICMD_LMULCONST;
659 goto icmd_lconst_tail;
660 #else /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
661 # if SUPPORT_LONG_SHIFT
663 if (iptr[0].val.l == 0x00000002)
665 else if (iptr[0].val.l == 0x00000004)
667 else if (iptr[0].val.l == 0x00000008)
669 else if (iptr[0].val.l == 0x00000010)
671 else if (iptr[0].val.l == 0x00000020)
673 else if (iptr[0].val.l == 0x00000040)
675 else if (iptr[0].val.l == 0x00000080)
677 else if (iptr[0].val.l == 0x00000100)
679 else if (iptr[0].val.l == 0x00000200)
681 else if (iptr[0].val.l == 0x00000400)
683 else if (iptr[0].val.l == 0x00000800)
685 else if (iptr[0].val.l == 0x00001000)
687 else if (iptr[0].val.l == 0x00002000)
689 else if (iptr[0].val.l == 0x00004000)
691 else if (iptr[0].val.l == 0x00008000)
693 else if (iptr[0].val.l == 0x00010000)
695 else if (iptr[0].val.l == 0x00020000)
697 else if (iptr[0].val.l == 0x00040000)
699 else if (iptr[0].val.l == 0x00080000)
701 else if (iptr[0].val.l == 0x00100000)
703 else if (iptr[0].val.l == 0x00200000)
705 else if (iptr[0].val.l == 0x00400000)
707 else if (iptr[0].val.l == 0x00800000)
709 else if (iptr[0].val.l == 0x01000000)
711 else if (iptr[0].val.l == 0x02000000)
713 else if (iptr[0].val.l == 0x04000000)
715 else if (iptr[0].val.l == 0x08000000)
717 else if (iptr[0].val.l == 0x10000000)
719 else if (iptr[0].val.l == 0x20000000)
721 else if (iptr[0].val.l == 0x40000000)
723 else if (iptr[0].val.l == 0x80000000)
729 iptr[0].opc = ICMD_LMULPOW2;
730 goto icmd_lconst_tail;
731 # endif /* SUPPORT_LONG_SHIFT */
732 #endif /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
735 if (iptr[0].val.l == 0x00000002)
737 else if (iptr[0].val.l == 0x00000004)
739 else if (iptr[0].val.l == 0x00000008)
741 else if (iptr[0].val.l == 0x00000010)
743 else if (iptr[0].val.l == 0x00000020)
745 else if (iptr[0].val.l == 0x00000040)
747 else if (iptr[0].val.l == 0x00000080)
749 else if (iptr[0].val.l == 0x00000100)
751 else if (iptr[0].val.l == 0x00000200)
753 else if (iptr[0].val.l == 0x00000400)
755 else if (iptr[0].val.l == 0x00000800)
757 else if (iptr[0].val.l == 0x00001000)
759 else if (iptr[0].val.l == 0x00002000)
761 else if (iptr[0].val.l == 0x00004000)
763 else if (iptr[0].val.l == 0x00008000)
765 else if (iptr[0].val.l == 0x00010000)
767 else if (iptr[0].val.l == 0x00020000)
769 else if (iptr[0].val.l == 0x00040000)
771 else if (iptr[0].val.l == 0x00080000)
773 else if (iptr[0].val.l == 0x00100000)
775 else if (iptr[0].val.l == 0x00200000)
777 else if (iptr[0].val.l == 0x00400000)
779 else if (iptr[0].val.l == 0x00800000)
781 else if (iptr[0].val.l == 0x01000000)
783 else if (iptr[0].val.l == 0x02000000)
785 else if (iptr[0].val.l == 0x04000000)
787 else if (iptr[0].val.l == 0x08000000)
789 else if (iptr[0].val.l == 0x10000000)
791 else if (iptr[0].val.l == 0x20000000)
793 else if (iptr[0].val.l == 0x40000000)
795 else if (iptr[0].val.l == 0x80000000)
801 iptr[0].opc = ICMD_LDIVPOW2;
802 goto icmd_lconst_tail;
804 if ((iptr[0].val.l == 0x00000002) ||
805 (iptr[0].val.l == 0x00000004) ||
806 (iptr[0].val.l == 0x00000008) ||
807 (iptr[0].val.l == 0x00000010) ||
808 (iptr[0].val.l == 0x00000020) ||
809 (iptr[0].val.l == 0x00000040) ||
810 (iptr[0].val.l == 0x00000080) ||
811 (iptr[0].val.l == 0x00000100) ||
812 (iptr[0].val.l == 0x00000200) ||
813 (iptr[0].val.l == 0x00000400) ||
814 (iptr[0].val.l == 0x00000800) ||
815 (iptr[0].val.l == 0x00001000) ||
816 (iptr[0].val.l == 0x00002000) ||
817 (iptr[0].val.l == 0x00004000) ||
818 (iptr[0].val.l == 0x00008000) ||
819 (iptr[0].val.l == 0x00010000) ||
820 (iptr[0].val.l == 0x00020000) ||
821 (iptr[0].val.l == 0x00040000) ||
822 (iptr[0].val.l == 0x00080000) ||
823 (iptr[0].val.l == 0x00100000) ||
824 (iptr[0].val.l == 0x00200000) ||
825 (iptr[0].val.l == 0x00400000) ||
826 (iptr[0].val.l == 0x00800000) ||
827 (iptr[0].val.l == 0x01000000) ||
828 (iptr[0].val.l == 0x02000000) ||
829 (iptr[0].val.l == 0x04000000) ||
830 (iptr[0].val.l == 0x08000000) ||
831 (iptr[0].val.l == 0x10000000) ||
832 (iptr[0].val.l == 0x20000000) ||
833 (iptr[0].val.l == 0x40000000) ||
834 (iptr[0].val.l == 0x80000000)) {
835 iptr[0].opc = ICMD_LREMPOW2;
837 goto icmd_lconst_tail;
841 #endif /* SUPPORT_LONG_DIV */
842 #if SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL
845 iptr[0].opc = ICMD_LANDCONST;
846 goto icmd_lconst_tail;
848 iptr[0].opc = ICMD_LORCONST;
849 goto icmd_lconst_tail;
851 iptr[0].opc = ICMD_LXORCONST;
852 goto icmd_lconst_tail;
853 #endif /* SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL */
854 #if !defined(NOLONG_CONDITIONAL)
856 if ((len > 1) && (iptr[2].val.i == 0)) {
857 switch (iptr[2].opc) {
859 iptr[0].opc = ICMD_IF_LEQ;
860 icmd_lconst_lcmp_tail:
861 iptr[0].op1 = iptr[2].op1;
864 /* iptr[1].opc = ICMD_NOP;
865 iptr[2].opc = ICMD_NOP; */
867 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
869 iptr[0].target = (void *) tbptr;
871 MARKREACHED(tbptr, copy);
872 COUNT(count_pcmd_bra);
873 COUNT(count_pcmd_op);
876 iptr[0].opc = ICMD_IF_LNE;
877 goto icmd_lconst_lcmp_tail;
879 iptr[0].opc = ICMD_IF_LLT;
880 goto icmd_lconst_lcmp_tail;
882 iptr[0].opc = ICMD_IF_LGT;
883 goto icmd_lconst_lcmp_tail;
885 iptr[0].opc = ICMD_IF_LLE;
886 goto icmd_lconst_lcmp_tail;
888 iptr[0].opc = ICMD_IF_LGE;
889 goto icmd_lconst_lcmp_tail;
892 } /* switch (iptr[2].opc) */
893 } /* if (iptr[2].val.i == 0) */
897 #endif /* !defined(NOLONG_CONDITIONAL) */
899 #if SUPPORT_CONST_STORE
901 #if SUPPORT_CONST_STORE_ZERO_ONLY
902 if (iptr[0].val.l == 0) {
903 #endif /* SUPPORT_CONST_STORE_ZERO_ONLY */
904 iptr[0].opc = ICMD_LASTORECONST;
905 iptr[1].opc = ICMD_NOP;
906 OPTT2_0(TYPE_INT, TYPE_ADR);
907 COUNT(count_pcmd_op);
908 #if SUPPORT_CONST_STORE_ZERO_ONLY
911 #endif /* SUPPORT_CONST_STORE_ZERO_ONLY */
916 #if SUPPORT_CONST_STORE_ZERO_ONLY
917 if (iptr[0].val.l == 0) {
918 #endif /* SUPPORT_CONST_STORE_ZERO_ONLY */
919 switch (iptr[1].opc) {
921 iptr[0].opc = ICMD_PUTSTATICCONST;
925 iptr[0].opc = ICMD_PUTFIELDCONST;
930 iptr[1].opc = ICMD_NOP;
931 iptr[0].op1 = TYPE_LNG;
932 COUNT(count_pcmd_op);
933 #if SUPPORT_CONST_STORE_ZERO_ONLY
936 #endif /* SUPPORT_CONST_STORE_ZERO_ONLY */
938 #endif /* SUPPORT_CONST_STORE */
948 COUNT(count_pcmd_load);
953 COUNT(count_pcmd_load);
958 COUNT(count_pcmd_load);
959 #if SUPPORT_CONST_STORE
960 if (len > 0 && iptr->val.a == 0) {
961 switch (iptr[1].opc) {
963 if (iptr[1].val.fp != BUILTIN_aastore) {
970 switch (iptr[1].opc) {
972 iptr[0].opc = ICMD_AASTORECONST;
973 OPTT2_0(TYPE_INT, TYPE_ADR);
976 iptr[0].opc = ICMD_PUTSTATICCONST;
977 iptr[0].op1 = TYPE_ADR;
981 iptr[0].opc = ICMD_PUTFIELDCONST;
982 iptr[0].op1 = TYPE_ADR;
987 iptr[1].opc = ICMD_NOP;
988 COUNT(count_pcmd_op);
995 #endif /* SUPPORT_CONST_STORE */
999 /* pop 0 push 1 load */
1006 COUNT(count_load_instruction);
1007 i = opcode-ICMD_ILOAD;
1008 iptr->op1 = argren[iptr->op1];
1009 rd->locals[iptr->op1][i].type = i;
1010 LOAD(i, LOCALVAR, iptr->op1);
1020 COUNT(count_check_null);
1021 COUNT(count_check_bound);
1022 COUNT(count_pcmd_mem);
1023 OP2IAT_1(opcode-ICMD_IALOAD);
1029 COUNT(count_check_null);
1030 COUNT(count_check_bound);
1031 COUNT(count_pcmd_mem);
1035 /* pop 0 push 0 iinc */
1038 #if defined(STATISTICS)
1042 count_store_depth[10]++;
1044 count_store_depth[i]++;
1050 if ((copy->varkind == LOCALVAR) &&
1051 (copy->varnum == iptr->op1)) {
1052 copy->varkind = TEMPVAR;
1061 /* pop 1 push 0 store */
1071 i = opcode - ICMD_ISTORE;
1072 rd->locals[iptr->op1][i].type = i;
1073 #if defined(STATISTICS)
1078 count_store_length[20]++;
1080 count_store_length[i]++;
1083 count_store_depth[10]++;
1085 count_store_depth[i]++;
1088 copy = curstack->prev;
1091 if ((copy->varkind == LOCALVAR) &&
1092 (copy->varnum == iptr->op1)) {
1093 copy->varkind = TEMPVAR;
1099 if ((new - curstack) == 1) {
1100 curstack->varkind = LOCALVAR;
1101 curstack->varnum = iptr->op1;
1103 STORE(opcode-ICMD_ISTORE);
1113 COUNT(count_check_null);
1114 COUNT(count_check_bound);
1115 COUNT(count_pcmd_mem);
1116 OP3TIA_0(opcode-ICMD_IASTORE);
1122 COUNT(count_check_null);
1123 COUNT(count_check_bound);
1124 COUNT(count_pcmd_mem);
1131 #ifdef TYPECHECK_STACK_COMPCAT
1134 if (IS_2_WORD_TYPE(curstack->type)) {
1135 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1148 COUNT(count_pcmd_return);
1149 OP1_0(opcode-ICMD_IRETURN);
1150 superblockend = true;
1154 COUNT(count_check_null);
1158 superblockend = true;
1161 case ICMD_PUTSTATIC:
1162 COUNT(count_pcmd_mem);
1166 /* pop 1 push 0 branch */
1169 case ICMD_IFNONNULL:
1170 COUNT(count_pcmd_bra);
1172 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1174 iptr[0].target = (void *) tbptr;
1176 MARKREACHED(tbptr, copy);
1188 COUNT(count_pcmd_bra);
1189 #if CONDITIONAL_LOADCONST
1190 tbptr = m->basicblocks + b_index;
1191 if ((b_count >= 3) &&
1192 ((b_index + 2) == m->basicblockindex[iptr[0].op1]) &&
1193 (tbptr[1].pre_count == 1) &&
1194 (tbptr[1].iinstr[0].opc == ICMD_ICONST) &&
1195 (tbptr[1].iinstr[1].opc == ICMD_GOTO) &&
1196 ((b_index + 3) == m->basicblockindex[tbptr[1].iinstr[1].op1]) &&
1197 (tbptr[2].pre_count == 1) &&
1198 (tbptr[2].iinstr[0].opc == ICMD_ICONST) &&
1199 (tbptr[2].icount==1)) {
1200 /*printf("tbptr[2].icount=%d\n",tbptr[2].icount);*/
1201 OP1_1(TYPE_INT, TYPE_INT);
1202 switch (iptr[0].opc) {
1204 iptr[0].opc = ICMD_IFNE_ICONST;
1207 iptr[0].opc = ICMD_IFEQ_ICONST;
1210 iptr[0].opc = ICMD_IFGE_ICONST;
1213 iptr[0].opc = ICMD_IFLT_ICONST;
1216 iptr[0].opc = ICMD_IFLE_ICONST;
1219 iptr[0].opc = ICMD_IFGT_ICONST;
1223 iptr[0].val.i = iptr[1].val.i;
1224 iptr[1].opc = ICMD_ELSE_ICONST;
1225 iptr[1].val.i = iptr[3].val.i;
1226 iptr[2].opc = ICMD_NOP;
1227 iptr[3].opc = ICMD_NOP;
1229 /* HACK: save compare value in iptr[1].op1 */
1230 iptr[1].op1 = iptr[0].val.i;
1231 iptr[0].val.i = tbptr[1].iinstr[0].val.i;
1232 iptr[1].opc = ICMD_ELSE_ICONST;
1233 iptr[1].val.i = tbptr[2].iinstr[0].val.i;
1234 tbptr[1].iinstr[0].opc = ICMD_NOP;
1235 tbptr[1].iinstr[1].opc = ICMD_NOP;
1236 tbptr[2].iinstr[0].opc = ICMD_NOP;
1238 tbptr[1].flags = BBDELETED;
1239 tbptr[2].flags = BBDELETED;
1240 tbptr[1].icount = 0;
1241 tbptr[2].icount = 0;
1242 if (tbptr[3].pre_count == 2) {
1243 len += tbptr[3].icount + 3;
1244 bptr->icount += tbptr[3].icount + 3;
1245 tbptr[3].flags = BBDELETED;
1246 tbptr[3].icount = 0;
1256 #endif /* CONDITIONAL_LOADCONST */
1259 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1261 iptr[0].target = (void *) tbptr;
1263 MARKREACHED(tbptr, copy);
1266 /* pop 0 push 0 branch */
1269 COUNT(count_pcmd_bra);
1270 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1272 iptr[0].target = (void *) tbptr;
1274 MARKREACHED(tbptr, copy);
1276 superblockend = true;
1279 /* pop 1 push 0 table branch */
1281 case ICMD_TABLESWITCH:
1282 COUNT(count_pcmd_table);
1284 s4ptr = iptr->val.a;
1285 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
1286 MARKREACHED(tbptr, copy);
1287 i = *s4ptr++; /* low */
1288 i = *s4ptr++ - i + 1; /* high */
1290 tptr = DMNEW(void*, i+1);
1291 iptr->target = (void *) tptr;
1293 tptr[0] = (void *) tbptr;
1297 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
1299 tptr[0] = (void *) tbptr;
1302 MARKREACHED(tbptr, copy);
1305 superblockend = true;
1308 /* pop 1 push 0 table branch */
1310 case ICMD_LOOKUPSWITCH:
1311 COUNT(count_pcmd_table);
1313 s4ptr = iptr->val.a;
1314 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
1315 MARKREACHED(tbptr, copy);
1316 i = *s4ptr++; /* count */
1318 tptr = DMNEW(void*, i+1);
1319 iptr->target = (void *) tptr;
1321 tptr[0] = (void *) tbptr;
1325 tbptr = m->basicblocks + m->basicblockindex[s4ptr[1]];
1327 tptr[0] = (void *) tbptr;
1330 MARKREACHED(tbptr, copy);
1334 superblockend = true;
1337 case ICMD_MONITORENTER:
1338 COUNT(count_check_null);
1339 case ICMD_MONITOREXIT:
1343 /* pop 2 push 0 branch */
1345 case ICMD_IF_ICMPEQ:
1346 case ICMD_IF_ICMPNE:
1347 case ICMD_IF_ICMPLT:
1348 case ICMD_IF_ICMPGE:
1349 case ICMD_IF_ICMPGT:
1350 case ICMD_IF_ICMPLE:
1351 COUNT(count_pcmd_bra);
1353 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1355 iptr[0].target = (void *) tbptr;
1357 MARKREACHED(tbptr, copy);
1360 case ICMD_IF_ACMPEQ:
1361 case ICMD_IF_ACMPNE:
1362 COUNT(count_pcmd_bra);
1364 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1366 iptr[0].target = (void *) tbptr;
1368 MARKREACHED(tbptr, copy);
1374 COUNT(count_check_null);
1375 COUNT(count_pcmd_mem);
1376 OPTT2_0(iptr->op1,TYPE_ADR);
1381 if (!IS_2_WORD_TYPE(curstack->type)) {
1383 #ifdef TYPECHECK_STACK_COMPCAT
1386 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1387 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1392 OP1_0ANY; /* second pop */
1395 iptr->opc = ICMD_POP;
1399 /* pop 0 push 1 dup */
1402 #ifdef TYPECHECK_STACK_COMPCAT
1405 if (IS_2_WORD_TYPE(curstack->type)) {
1406 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1411 COUNT(count_dup_instruction);
1417 if (IS_2_WORD_TYPE(curstack->type)) {
1419 iptr->opc = ICMD_DUP;
1424 /* ..., ????, cat1 */
1425 #ifdef TYPECHECK_STACK_COMPCAT
1427 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1428 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1434 NEWSTACK(copy->prev->type, copy->prev->varkind,
1435 copy->prev->varnum);
1436 NEWSTACK(copy->type, copy->varkind,
1443 /* pop 2 push 3 dup */
1446 #ifdef TYPECHECK_STACK_COMPCAT
1449 if (IS_2_WORD_TYPE(curstack->type) ||
1450 IS_2_WORD_TYPE(curstack->prev->type)) {
1451 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1461 if (IS_2_WORD_TYPE(curstack->type)) {
1462 /* ..., ????, cat2 */
1463 #ifdef TYPECHECK_STACK_COMPCAT
1465 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1466 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1471 iptr->opc = ICMD_DUP_X1;
1475 /* ..., ????, cat1 */
1476 #ifdef TYPECHECK_STACK_COMPCAT
1479 if (IS_2_WORD_TYPE(curstack->prev->type)
1480 || IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1481 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1490 /* pop 3 push 4 dup */
1494 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1495 /* ..., cat2, ???? */
1496 #ifdef TYPECHECK_STACK_COMPCAT
1498 if (IS_2_WORD_TYPE(curstack->type)) {
1499 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1504 iptr->opc = ICMD_DUP_X1;
1508 /* ..., cat1, ???? */
1509 #ifdef TYPECHECK_STACK_COMPCAT
1512 if (IS_2_WORD_TYPE(curstack->type)
1513 || IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1514 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1525 if (IS_2_WORD_TYPE(curstack->type)) {
1526 /* ..., ????, cat2 */
1527 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1528 /* ..., cat2, cat2 */
1529 iptr->opc = ICMD_DUP_X1;
1533 /* ..., cat1, cat2 */
1534 #ifdef TYPECHECK_STACK_COMPCAT
1537 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1538 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1543 iptr->opc = ICMD_DUP_X2;
1549 /* ..., ????, ????, cat1 */
1550 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1551 /* ..., cat2, ????, cat1 */
1552 #ifdef TYPECHECK_STACK_COMPCAT
1554 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1555 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1560 iptr->opc = ICMD_DUP2_X1;
1564 /* ..., cat1, ????, cat1 */
1565 #ifdef TYPECHECK_STACK_COMPCAT
1568 if (IS_2_WORD_TYPE(curstack->prev->type)
1569 || IS_2_WORD_TYPE(curstack->prev->prev->prev->type)) {
1570 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1580 /* pop 2 push 2 swap */
1583 #ifdef TYPECHECK_STACK_COMPCAT
1586 if (IS_2_WORD_TYPE(curstack->type)
1587 || IS_2_WORD_TYPE(curstack->prev->type)) {
1588 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1599 #if !SUPPORT_DIVISION
1600 iptr[0].opc = ICMD_BUILTIN2;
1601 iptr[0].op1 = TYPE_INT;
1602 iptr[0].val.fp = BUILTIN_idiv;
1603 m->isleafmethod = false;
1608 #if !SUPPORT_DIVISION
1609 /*log_text("ICMD_IREM: !SUPPORT_DIVISION");*/
1610 iptr[0].opc = ICMD_BUILTIN2;
1611 iptr[0].op1 = TYPE_INT;
1612 iptr[0].val.fp = BUILTIN_irem;
1613 m->isleafmethod = false;
1616 /*log_text("ICMD_IREM: SUPPORT_DIVISION");*/
1627 COUNT(count_pcmd_op);
1632 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1633 iptr[0].opc = ICMD_BUILTIN2;
1634 iptr[0].op1 = TYPE_LNG;
1635 iptr[0].val.fp = BUILTIN_ldiv;
1636 m->isleafmethod = false;
1641 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1642 iptr[0].opc = ICMD_BUILTIN2;
1643 iptr[0].op1 = TYPE_LNG;
1644 iptr[0].val.fp = BUILTIN_lrem;
1645 m->isleafmethod = false;
1652 #if SUPPORT_LONG_LOGICAL
1656 #endif /* SUPPORT_LONG_LOGICAL */
1657 COUNT(count_pcmd_op);
1664 COUNT(count_pcmd_op);
1673 COUNT(count_pcmd_op);
1682 COUNT(count_pcmd_op);
1687 COUNT(count_pcmd_op);
1688 #if !defined(NOLONG_CONDITIONAL)
1689 if ((len > 0) && (iptr[1].val.i == 0)) {
1690 switch (iptr[1].opc) {
1692 iptr[0].opc = ICMD_IF_LCMPEQ;
1694 iptr[0].op1 = iptr[1].op1;
1697 /* iptr[1].opc = ICMD_NOP; */
1699 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1701 iptr[0].target = (void *) tbptr;
1703 MARKREACHED(tbptr, copy);
1704 COUNT(count_pcmd_bra);
1707 iptr[0].opc = ICMD_IF_LCMPNE;
1708 goto icmd_lcmp_if_tail;
1710 iptr[0].opc = ICMD_IF_LCMPLT;
1711 goto icmd_lcmp_if_tail;
1713 iptr[0].opc = ICMD_IF_LCMPGT;
1714 goto icmd_lcmp_if_tail;
1716 iptr[0].opc = ICMD_IF_LCMPLE;
1717 goto icmd_lcmp_if_tail;
1719 iptr[0].opc = ICMD_IF_LCMPGE;
1720 goto icmd_lcmp_if_tail;
1722 OPTT2_1(TYPE_LNG, TYPE_INT);
1727 OPTT2_1(TYPE_LNG, TYPE_INT);
1731 COUNT(count_pcmd_op);
1732 OPTT2_1(TYPE_FLT, TYPE_INT);
1736 COUNT(count_pcmd_op);
1737 OPTT2_1(TYPE_DBL, TYPE_INT);
1745 case ICMD_INT2SHORT:
1746 COUNT(count_pcmd_op);
1747 OP1_1(TYPE_INT, TYPE_INT);
1750 COUNT(count_pcmd_op);
1751 OP1_1(TYPE_LNG, TYPE_LNG);
1754 COUNT(count_pcmd_op);
1755 OP1_1(TYPE_FLT, TYPE_FLT);
1758 COUNT(count_pcmd_op);
1759 OP1_1(TYPE_DBL, TYPE_DBL);
1763 COUNT(count_pcmd_op);
1764 OP1_1(TYPE_INT, TYPE_LNG);
1767 COUNT(count_pcmd_op);
1768 OP1_1(TYPE_INT, TYPE_FLT);
1771 COUNT(count_pcmd_op);
1772 OP1_1(TYPE_INT, TYPE_DBL);
1775 COUNT(count_pcmd_op);
1776 OP1_1(TYPE_LNG, TYPE_INT);
1779 COUNT(count_pcmd_op);
1780 OP1_1(TYPE_LNG, TYPE_FLT);
1783 COUNT(count_pcmd_op);
1784 OP1_1(TYPE_LNG, TYPE_DBL);
1787 COUNT(count_pcmd_op);
1788 OP1_1(TYPE_FLT, TYPE_INT);
1791 COUNT(count_pcmd_op);
1792 OP1_1(TYPE_FLT, TYPE_LNG);
1795 COUNT(count_pcmd_op);
1796 OP1_1(TYPE_FLT, TYPE_DBL);
1799 COUNT(count_pcmd_op);
1800 OP1_1(TYPE_DBL, TYPE_INT);
1803 COUNT(count_pcmd_op);
1804 OP1_1(TYPE_DBL, TYPE_LNG);
1807 COUNT(count_pcmd_op);
1808 OP1_1(TYPE_DBL, TYPE_FLT);
1811 case ICMD_CHECKCAST:
1812 OP1_1(TYPE_ADR, TYPE_ADR);
1815 case ICMD_INSTANCEOF:
1816 case ICMD_ARRAYLENGTH:
1817 OP1_1(TYPE_ADR, TYPE_INT);
1821 case ICMD_ANEWARRAY:
1822 OP1_1(TYPE_INT, TYPE_ADR);
1826 COUNT(count_check_null);
1827 COUNT(count_pcmd_mem);
1828 OP1_1(TYPE_ADR, iptr->op1);
1833 case ICMD_GETSTATIC:
1834 COUNT(count_pcmd_mem);
1844 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1846 iptr[0].target = (void *) tbptr;
1848 /* This is a dirty hack. The typechecker
1849 * needs it because the OP1_0ANY below
1850 * overwrites iptr->dst.
1852 iptr->val.a = (void *) iptr->dst;
1854 tbptr->type = BBTYPE_SBR;
1856 /* We need to check for overflow right here because
1857 * the pushed value is poped after MARKREACHED. */
1859 MARKREACHED(tbptr, copy);
1863 /* pop many push any */
1866 call_returntype = iptr->op1;
1869 #if defined(USEBUILTINTABLE) || !SUPPORT_DIVISION
1870 /* Just prevent a compiler warning... */
1874 call_returntype = iptr->op1;
1877 #if defined(USEBUILTINTABLE)
1878 /* Just prevent a compiler warning... */
1882 call_returntype = iptr->op1;
1885 case ICMD_INVOKEVIRTUAL:
1886 case ICMD_INVOKESPECIAL:
1887 case ICMD_INVOKEINTERFACE:
1888 case ICMD_INVOKESTATIC:
1889 COUNT(count_pcmd_met);
1891 #if defined(__X86_64__) || defined(__I386__) || defined(__ALPHA__) || defined(__MIPS__)
1892 unresolved_method *um = iptr->target;
1893 /* if (lm->flags & ACC_STATIC) */
1894 /* {COUNT(count_check_null);} */
1895 call_argcount = iptr->op1;
1896 call_returntype = um->methodref->parseddesc.md->returntype.type;
1898 methodinfo *lm = iptr->val.a;
1899 if (lm->flags & ACC_STATIC)
1900 {COUNT(count_check_null);}
1901 call_argcount = iptr->op1;
1902 call_returntype = lm->returntype;
1908 if (i > rd->arguments_num)
1909 rd->arguments_num = i;
1912 /* Macro in codegen.h */
1916 copy->flags |= SAVEDVAR;
1922 if (call_returntype != TYPE_VOID)
1923 OP0_1(call_returntype);
1927 case ICMD_INLINE_START:
1928 case ICMD_INLINE_END:
1932 case ICMD_MULTIANEWARRAY:
1933 if (rd->argintreguse < 3)
1934 rd->argintreguse = 3;
1939 #ifdef SPECIALMEMUSE
1940 if (rd->ifmemuse < (i + rd->intreg_argnum + 6))
1941 rd->ifmemuse = i + rd->intreg_argnum + 6;
1943 # if defined(__I386__)
1944 if (rd->ifmemuse < i + 3)
1945 rd->ifmemuse = i + 3; /* n integer args spilled on stack */
1947 if (rd->ifmemuse < i)
1948 rd->ifmemuse = i; /* n integer args spilled on stack */
1949 # endif /* defined(__I386__) */
1951 if ((i + INT_ARG_CNT) > rd->arguments_num)
1952 rd->arguments_num = i + INT_ARG_CNT;
1955 /* check INT type here? Currently typecheck does this. */
1956 if (!(copy->flags & SAVEDVAR)) {
1957 copy->varkind = ARGVAR;
1958 copy->varnum = i + INT_ARG_CNT;
1959 copy->flags|=INMEMORY;
1960 #if defined(SPECIALMEMUSE)
1961 copy->regoff = i + rd->intreg_argnum + 6;
1963 # if defined(__I386__)
1964 copy->regoff = i + 3;
1967 # endif /* defined(__I386__) */
1968 #endif /* defined(SPECIALMEMUSE) */
1973 copy->flags |= SAVEDVAR;
1981 case ICMD_CLEAR_ARGREN:
1982 for (i = iptr->op1; i < cd->maxlocals; i++)
1984 iptr->opc = opcode = ICMD_NOP;
1988 case ICMD_READONLY_ARG:
1989 case ICMD_READONLY_ARG+1:
1990 case ICMD_READONLY_ARG+2:
1991 case ICMD_READONLY_ARG+3:
1992 case ICMD_READONLY_ARG+4:
1995 if (curstack->varkind == LOCALVAR) {
1996 i = curstack->varnum;
1997 argren[iptr->op1] = i;
2000 opcode = iptr->opc = opcode - ICMD_READONLY_ARG + ICMD_ISTORE;
2007 new_exception_message(string_java_lang_InternalError,
2014 } /* while instructions */
2016 bptr->outstack = curstack;
2017 bptr->outdepth = stackdepth;
2021 superblockend = true;
2023 } /* while blocks */
2024 } while (repeat && !deadcode);
2026 #if defined(STATISTICS)
2028 if (m->basicblockcount > count_max_basic_blocks)
2029 count_max_basic_blocks = m->basicblockcount;
2030 count_basic_blocks += m->basicblockcount;
2031 if (m->instructioncount > count_max_javainstr) count_max_javainstr = m->instructioncount;
2032 count_javainstr += m->instructioncount;
2033 if (m->stackcount > count_upper_bound_new_stack)
2034 count_upper_bound_new_stack = m->stackcount;
2035 if ((new - m->stack) > count_max_new_stack)
2036 count_max_new_stack = (new - m->stack);
2038 b_count = m->basicblockcount;
2039 bptr = m->basicblocks;
2040 while (--b_count >= 0) {
2041 if (bptr->flags > BBREACHED) {
2042 if (bptr->indepth >= 10)
2043 count_block_stack[10]++;
2045 count_block_stack[bptr->indepth]++;
2048 count_block_size_distribution[len]++;
2050 count_block_size_distribution[10]++;
2052 count_block_size_distribution[11]++;
2054 count_block_size_distribution[12]++;
2056 count_block_size_distribution[13]++;
2058 count_block_size_distribution[14]++;
2060 count_block_size_distribution[15]++;
2062 count_block_size_distribution[16]++;
2064 count_block_size_distribution[17]++;
2070 count_analyse_iterations[0]++;
2071 else if (loops == 2)
2072 count_analyse_iterations[1]++;
2073 else if (loops == 3)
2074 count_analyse_iterations[2]++;
2075 else if (loops == 4)
2076 count_analyse_iterations[3]++;
2078 count_analyse_iterations[4]++;
2080 if (m->basicblockcount <= 5)
2081 count_method_bb_distribution[0]++;
2082 else if (m->basicblockcount <= 10)
2083 count_method_bb_distribution[1]++;
2084 else if (m->basicblockcount <= 15)
2085 count_method_bb_distribution[2]++;
2086 else if (m->basicblockcount <= 20)
2087 count_method_bb_distribution[3]++;
2088 else if (m->basicblockcount <= 30)
2089 count_method_bb_distribution[4]++;
2090 else if (m->basicblockcount <= 40)
2091 count_method_bb_distribution[5]++;
2092 else if (m->basicblockcount <= 50)
2093 count_method_bb_distribution[6]++;
2094 else if (m->basicblockcount <= 75)
2095 count_method_bb_distribution[7]++;
2097 count_method_bb_distribution[8]++;
2101 /* just return methodinfo* to signal everything was ok */
2107 /**********************************************************************/
2108 /* DEBUGGING HELPERS */
2109 /**********************************************************************/
2111 void icmd_print_stack(codegendata *cd, stackptr s)
2123 j = cd->maxstack - i;
2128 /* DEBUG */ /*printf("(%d,%d,%d,%d)",s->varkind,s->flags,s->regoff,s->varnum); fflush(stdout);*/
2129 if (s->flags & SAVEDVAR)
2130 switch (s->varkind) {
2132 if (s->flags & INMEMORY)
2133 printf(" M%02d", s->regoff);
2134 #ifdef HAS_ADDRESS_REGISTER_FILE
2135 else if (s->type == TYPE_ADR)
2136 printf(" R%02d", s->regoff);
2138 else if (IS_FLT_DBL_TYPE(s->type))
2139 printf(" F%02d", s->regoff);
2141 printf(" %3s", regs[s->regoff]);
2145 printf(" I%02d", s->varnum);
2148 printf(" L%02d", s->varnum);
2151 printf(" A%02d", s->varnum);
2152 #ifdef INVOKE_NEW_DEBUG
2153 if (s->flags & INMEMORY)
2154 printf("(M%i)", s->regoff);
2156 printf("(R%i)", s->regoff);
2160 printf(" !%02d", j);
2163 switch (s->varkind) {
2165 if (s->flags & INMEMORY)
2166 printf(" m%02d", s->regoff);
2167 #ifdef HAS_ADDRESS_REGISTER_FILE
2168 else if (s->type == TYPE_ADR)
2169 printf(" r%02d", s->regoff);
2171 else if (IS_FLT_DBL_TYPE(s->type))
2172 printf(" f%02d", s->regoff);
2174 printf(" %3s", regs[s->regoff]);
2178 printf(" i%02d", s->varnum);
2181 printf(" l%02d", s->varnum);
2184 printf(" a%02d", s->varnum);
2185 #ifdef INVOKE_NEW_DEBUG
2186 if (s->flags & INMEMORY)
2187 printf("(M%i)", s->regoff);
2189 printf("(R%i)", s->regoff);
2193 printf(" ?%02d", j);
2201 static void print_reg(stackptr s) {
2203 if (s->flags & SAVEDVAR)
2204 switch (s->varkind) {
2206 if (s->flags & INMEMORY)
2207 printf(" tm%02d", s->regoff);
2209 printf(" tr%02d", s->regoff);
2212 printf(" s %02d", s->varnum);
2215 printf(" l %02d", s->varnum);
2218 printf(" a %02d", s->varnum);
2221 printf(" ! %02d", s->varnum);
2224 switch (s->varkind) {
2226 if (s->flags & INMEMORY)
2227 printf(" Tm%02d", s->regoff);
2229 printf(" Tr%02d", s->regoff);
2232 printf(" S %02d", s->varnum);
2235 printf(" L %02d", s->varnum);
2238 printf(" A %02d", s->varnum);
2241 printf(" ? %02d", s->varnum);
2251 char *icmd_builtin_name(functionptr bptr)
2253 builtin_descriptor *bdesc = builtin_desc;
2254 while ((bdesc->opcode != 0) && (bdesc->builtin != bptr))
2256 return (bdesc->opcode) ? bdesc->name : "<NOT IN TABLE>";
2260 static char *jit_type[] = {
2269 void show_icmd_method(methodinfo *m, codegendata *cd, registerdata *rd)
2276 utf_fprint_classname(stdout, m->class->name);
2278 utf_fprint(stdout, m->name);
2279 utf_fprint_classname(stdout, m->descriptor);
2280 printf("\n\nMax locals: %d\n", (int) cd->maxlocals);
2281 printf("Max stack: %d\n", (int) cd->maxstack);
2283 printf("Line number table length: %d\n", m->linenumbercount);
2285 printf("Exceptions (Number: %d):\n", cd->exceptiontablelength);
2286 for (ex = cd->exceptiontable; ex != NULL; ex = ex->down) {
2287 printf(" L%03d ... ", ex->start->debug_nr );
2288 printf("L%03d = ", ex->end->debug_nr);
2289 printf("L%03d", ex->handler->debug_nr);
2290 printf(" (catchtype: ");
2291 if (ex->catchtype.any)
2292 if (IS_CLASSREF(ex->catchtype))
2293 utf_display_classname(ex->catchtype.ref->name);
2295 utf_display_classname(ex->catchtype.cls->name);
2301 printf("Local Table:\n");
2302 for (i = 0; i < cd->maxlocals; i++) {
2303 printf(" %3d: ", i);
2304 for (j = TYPE_INT; j <= TYPE_ADR; j++)
2305 if (rd->locals[i][j].type >= 0) {
2306 printf(" (%s) ", jit_type[j]);
2307 if (rd->locals[i][j].flags & INMEMORY)
2308 printf("m%2d", rd->locals[i][j].regoff);
2309 #ifdef HAS_ADDRESS_REGISTER_FILE
2310 else if (j == TYPE_ADR)
2311 printf("r%02d", rd->locals[i][j].regoff);
2313 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2314 printf("f%02d", rd->locals[i][j].regoff);
2316 printf("%3s", regs[rd->locals[i][j].regoff]);
2325 printf("Interface Table:\n");
2326 for (i = 0; i < cd->maxstack; i++) {
2327 if ((rd->interfaces[i][0].type >= 0) ||
2328 (rd->interfaces[i][1].type >= 0) ||
2329 (rd->interfaces[i][2].type >= 0) ||
2330 (rd->interfaces[i][3].type >= 0) ||
2331 (rd->interfaces[i][4].type >= 0)) {
2332 printf(" %3d: ", i);
2333 for (j = TYPE_INT; j <= TYPE_ADR; j++)
2334 if (rd->interfaces[i][j].type >= 0) {
2335 printf(" (%s) ", jit_type[j]);
2336 if (rd->interfaces[i][j].flags & SAVEDVAR) {
2337 if (rd->interfaces[i][j].flags & INMEMORY)
2338 printf("M%2d", rd->interfaces[i][j].regoff);
2339 #ifdef HAS_ADDRESS_REGISTER_FILE
2340 else if (j == TYPE_ADR)
2341 printf("R%02d", rd->interfaces[i][j].regoff);
2343 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2344 printf("F%02d", rd->interfaces[i][j].regoff);
2346 printf("%3s", regs[rd->interfaces[i][j].regoff]);
2350 if (rd->interfaces[i][j].flags & INMEMORY)
2351 printf("m%2d", rd->interfaces[i][j].regoff);
2352 #ifdef HAS_ADDRESS_REGISTER_FILE
2353 else if (j == TYPE_ADR)
2354 printf("r%02d", rd->interfaces[i][j].regoff);
2356 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2357 printf("f%02d", rd->interfaces[i][j].regoff);
2359 printf("%3s", regs[rd->interfaces[i][j].regoff]);
2370 if (showdisassemble) {
2371 #if defined(__I386__) || defined(__X86_64__)
2375 u1ptr = (u1 *) ((ptrint) m->mcode + cd->dseglen);
2376 for (i = 0; i < m->basicblocks[0].mpc;) {
2377 a = disassinstr(u1ptr);
2382 #elif defined(__XDSPCORE__)
2386 s4ptr = (s4 *) ((ptrint) m->mcode + cd->dseglen);
2387 for (i = 0; i < m->basicblocks[0].mpc;) {
2388 a = disassinstr(stdout, s4ptr);
2397 s4ptr = (s4 *) ((ptrint) m->mcode + cd->dseglen);
2398 for (i = 0; i < m->basicblocks[0].mpc; i += 4, s4ptr++) {
2405 for (bptr = m->basicblocks; bptr != NULL; bptr = bptr->next) {
2406 show_icmd_block(m, cd, bptr);
2411 void show_icmd_block(methodinfo *m, codegendata *cd, basicblock *bptr)
2417 if (bptr->flags != BBDELETED) {
2418 deadcode = bptr->flags <= BBREACHED;
2421 for (j = cd->maxstack; j > 0; j--)
2424 icmd_print_stack(cd, bptr->instack);
2425 printf("] L%03d(%d - %d) flags=%d:\n", bptr->debug_nr, bptr->icount, bptr->pre_count,bptr->flags);
2426 iptr = bptr->iinstr;
2428 for (i = 0; i < bptr->icount; i++, iptr++) {
2431 for (j = cd->maxstack; j > 0; j--)
2435 icmd_print_stack(cd, iptr->dst);
2436 printf("] %4d ", i);
2439 if (icmd_uses_tmp[iptr->opc][0])
2443 if (icmd_uses_tmp[iptr->opc][1])
2447 if (icmd_uses_tmp[iptr->opc][2])
2453 show_icmd(iptr, deadcode);
2457 if (showdisassemble && (!deadcode)) {
2458 #if defined(__I386__) || defined(__X86_64__)
2464 u1ptr = (u1 *) ((ptrint) m->mcode + cd->dseglen + i);
2466 if (bptr->next != NULL) {
2467 for (; i < bptr->next->mpc; ) {
2468 a = disassinstr(u1ptr);
2475 for (; u1ptr < (u1 *) ((ptrint) m->mcode + m->mcodelength); ) {
2476 a = disassinstr(u1ptr);
2482 #elif defined(__XDSPCORE__)
2488 s4ptr = (s4 *) ((ptrint) m->mcode + cd->dseglen + i);
2490 if (bptr->next != NULL) {
2491 for (; i < bptr->next->mpc;) {
2492 a = disassinstr(stdout, s4ptr);
2500 for (; s4ptr < (s4 *) ((ptrint) m->mcode + m->mcodelength); ) {
2501 a = disassinstr(stdout, s4ptr);
2512 s4ptr = (s4 *) ((ptrint) m->mcode + cd->dseglen + i);
2514 if (bptr->next != NULL) {
2515 for (; i < bptr->next->mpc; i += 4, s4ptr++)
2520 for (; s4ptr < (s4 *) ((ptrint) m->mcode + m->mcodelength); i += 4, s4ptr++)
2530 void show_icmd(instruction *iptr, bool deadcode)
2536 printf("%s", icmd_names[iptr->opc]);
2538 switch (iptr->opc) {
2539 case ICMD_IADDCONST:
2540 case ICMD_ISUBCONST:
2541 case ICMD_IMULCONST:
2545 case ICMD_IANDCONST:
2547 case ICMD_IXORCONST:
2548 case ICMD_ISHLCONST:
2549 case ICMD_ISHRCONST:
2550 case ICMD_IUSHRCONST:
2551 case ICMD_LSHLCONST:
2552 case ICMD_LSHRCONST:
2553 case ICMD_LUSHRCONST:
2555 case ICMD_ELSE_ICONST:
2556 case ICMD_IASTORECONST:
2557 case ICMD_BASTORECONST:
2558 case ICMD_CASTORECONST:
2559 case ICMD_SASTORECONST:
2560 printf(" %d (0x%08x)", iptr->val.i, iptr->val.i);
2563 case ICMD_IFEQ_ICONST:
2564 case ICMD_IFNE_ICONST:
2565 case ICMD_IFLT_ICONST:
2566 case ICMD_IFGE_ICONST:
2567 case ICMD_IFGT_ICONST:
2568 case ICMD_IFLE_ICONST:
2569 printf("(%d) %d", iptr[1].op1, iptr->val.i);
2572 case ICMD_LADDCONST:
2573 case ICMD_LSUBCONST:
2574 case ICMD_LMULCONST:
2578 case ICMD_LANDCONST:
2580 case ICMD_LXORCONST:
2582 case ICMD_LASTORECONST:
2583 #if defined(__I386__) || defined(__POWERPC__)
2584 printf(" %lld (0x%016llx)", iptr->val.l, iptr->val.l);
2586 printf(" %ld (0x%016lx)", iptr->val.l, iptr->val.l);
2591 printf(" %f", iptr->val.f);
2595 printf(" %f", iptr->val.d);
2599 case ICMD_AASTORECONST:
2600 printf(" %p", iptr->val.a);
2605 #if defined(__X86_64__) || defined(__I386__) || defined(__ALPHA__) || defined(__MIPS__)
2607 printf(" %d, ", ((fieldinfo *) iptr->val.a)->offset);
2609 printf(" (NOT RESOLVED), ");
2610 utf_display_classname(((unresolved_field *) iptr->target)->fieldref->classref->name);
2612 utf_display(((unresolved_field *) iptr->target)->fieldref->name);
2614 utf_display(((unresolved_field *) iptr->target)->fieldref->descriptor);
2617 printf(" %d,", ((fieldinfo *) iptr->val.a)->offset);
2619 utf_display_classname(((fieldinfo *) iptr->val.a)->class->name);
2621 utf_display(((fieldinfo *) iptr->val.a)->name);
2623 utf_display(((fieldinfo *) iptr->val.a)->descriptor);
2628 case ICMD_PUTSTATIC:
2629 case ICMD_GETSTATIC:
2630 #if defined(__X86_64__) || defined(__I386__) || defined(__ALPHA__) || defined(__MIPS__)
2634 printf(" (NOT RESOLVED) ");
2635 utf_display_classname(((unresolved_field *) iptr->target)->fieldref->classref->name);
2637 utf_display(((unresolved_field *) iptr->target)->fieldref->name);
2639 utf_display(((unresolved_field *) iptr->target)->fieldref->descriptor);
2643 utf_display_classname(((fieldinfo *) iptr->val.a)->class->name);
2645 utf_display(((fieldinfo *) iptr->val.a)->name);
2647 utf_display(((fieldinfo *) iptr->val.a)->descriptor);
2652 case ICMD_PUTSTATICCONST:
2653 case ICMD_PUTFIELDCONST:
2654 switch (iptr[1].op1) {
2656 printf(" %d,", iptr->val.i);
2659 #if defined(__I386__) || defined(__POWERPC__)
2660 printf(" %lld,", iptr->val.l);
2662 printf(" %ld,", iptr->val.l);
2666 printf(" %p,", iptr->val.a);
2669 printf(" %g,", iptr->val.f);
2672 printf(" %g,", iptr->val.d);
2675 #if defined(__X86_64__)
2676 if (iptr->opc == ICMD_PUTFIELDCONST)
2677 printf(" NOT RESOLVED,");
2679 utf_display_classname(((unresolved_field *) iptr[1].target)->fieldref->classref->name);
2681 utf_display(((unresolved_field *) iptr[1].target)->fieldref->name);
2683 utf_display(((unresolved_field *) iptr[1].target)->fieldref->descriptor);
2686 if (iptr->opc == ICMD_PUTFIELDCONST)
2687 printf(" %d,", ((fieldinfo *) iptr[1].val.a)->offset);
2689 utf_display_classname(((fieldinfo *) iptr[1].val.a)->class->name);
2691 utf_display(((fieldinfo *) iptr[1].val.a)->name);
2693 utf_display(((fieldinfo *) iptr[1].val.a)->descriptor);
2699 printf(" %d + %d", iptr->op1, iptr->val.i);
2734 printf(" %d", iptr->op1);
2739 utf_display_classname(((classinfo *) iptr->val.a)->name);
2743 switch (iptr->op1) {
2771 case ICMD_ANEWARRAY:
2774 utf_display_classname(((classinfo *) iptr->val.a)->name);
2778 case ICMD_MULTIANEWARRAY:
2781 printf(" %d ",iptr->op1);
2782 vft = (vftbl_t *)iptr->val.a;
2784 utf_display_classname(vft->class->name);
2790 case ICMD_CHECKCAST:
2791 case ICMD_INSTANCEOF:
2792 #if defined(__X86_64__) || defined(__I386__) || defined(__ALPHA__) || defined(__MIPS__)
2794 classinfo *c = iptr->val.a;
2796 if (c->flags & ACC_INTERFACE)
2797 printf(" (INTERFACE) ");
2799 printf(" (CLASS,%3d) ", c->vftbl->diffval);
2801 printf(" (NOT RESOLVED) ");
2803 utf_display_classname(((constant_classref *) iptr->target)->name);
2808 classinfo *c = iptr->val.a;
2809 if (c->flags & ACC_INTERFACE)
2810 printf(" (INTERFACE) ");
2812 printf(" (CLASS,%3d) ", c->vftbl->diffval);
2813 utf_display_classname(c->name);
2817 case ICMD_INLINE_START:
2818 printf("\t\t\t%s.%s%s depth=%i",iptr->method->class->name->text,iptr->method->name->text,iptr->method->descriptor->text, iptr->op1);
2820 case ICMD_INLINE_END:
2826 printf(" %s", icmd_builtin_name((functionptr) iptr->val.fp));
2829 case ICMD_INVOKEVIRTUAL:
2830 case ICMD_INVOKESPECIAL:
2831 case ICMD_INVOKESTATIC:
2832 case ICMD_INVOKEINTERFACE:
2833 #if defined(__X86_64__) || defined(__I386__) || defined(__ALPHA__) || defined(__MIPS__)
2835 printf(" (NOT RESOLVED) ");
2838 utf_display_classname(((unresolved_method *) iptr->target)->methodref->classref->name);
2840 utf_display(((unresolved_method *) iptr->target)->methodref->name);
2841 utf_display(((unresolved_method *) iptr->target)->methodref->descriptor);
2844 utf_display_classname(((methodinfo *) iptr->val.a)->class->name);
2846 utf_display(((methodinfo *) iptr->val.a)->name);
2847 utf_display(((methodinfo *) iptr->val.a)->descriptor);
2857 if (deadcode || !iptr->target)
2858 printf("(%d) op1=%d", iptr->val.i, iptr->op1);
2860 printf("(%d) L%03d", iptr->val.i, ((basicblock *) iptr->target)->debug_nr);
2869 if (deadcode || !iptr->target)
2870 #if defined(__I386__) || defined(__POWERPC__)
2871 printf("(%lld) op1=%d", iptr->val.l, iptr->op1);
2873 printf("(%ld) op1=%d", iptr->val.l, iptr->op1);
2876 #if defined(__I386__) || defined(__POWERPC__)
2877 printf("(%lld) L%03d", iptr->val.l, ((basicblock *) iptr->target)->debug_nr);
2879 printf("(%ld) L%03d", iptr->val.l, ((basicblock *) iptr->target)->debug_nr);
2886 case ICMD_IFNONNULL:
2887 case ICMD_IF_ICMPEQ:
2888 case ICMD_IF_ICMPNE:
2889 case ICMD_IF_ICMPLT:
2890 case ICMD_IF_ICMPGE:
2891 case ICMD_IF_ICMPGT:
2892 case ICMD_IF_ICMPLE:
2893 case ICMD_IF_LCMPEQ:
2894 case ICMD_IF_LCMPNE:
2895 case ICMD_IF_LCMPLT:
2896 case ICMD_IF_LCMPGE:
2897 case ICMD_IF_LCMPGT:
2898 case ICMD_IF_LCMPLE:
2899 case ICMD_IF_ACMPEQ:
2900 case ICMD_IF_ACMPNE:
2901 if (deadcode || !iptr->target)
2902 printf(" op1=%d", iptr->op1);
2904 printf(" L%03d", ((basicblock *) iptr->target)->debug_nr);
2907 case ICMD_TABLESWITCH:
2908 s4ptr = (s4*)iptr->val.a;
2910 if (deadcode || !iptr->target) {
2911 printf(" %d;", *s4ptr);
2914 tptr = (void **) iptr->target;
2915 printf(" L%03d;", ((basicblock *) *tptr)->debug_nr);
2919 s4ptr++; /* skip default */
2920 j = *s4ptr++; /* low */
2921 j = *s4ptr++ - j; /* high */
2923 if (deadcode || !*tptr)
2924 printf(" %d", *s4ptr++);
2926 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2933 case ICMD_LOOKUPSWITCH:
2934 s4ptr = (s4*)iptr->val.a;
2936 if (deadcode || !iptr->target) {
2937 printf(" %d;", *s4ptr);
2940 tptr = (void **) iptr->target;
2941 printf(" L%03d;", ((basicblock *) *tptr)->debug_nr);
2944 s4ptr++; /* default */
2945 j = *s4ptr++; /* count */
2948 if (deadcode || !*tptr) {
2949 s4ptr++; /* skip value */
2950 printf(" %d",*s4ptr++);
2953 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2959 printf(" Line number: %d, method:",iptr->line);
2961 utf_display(iptr->method->class->name);
2963 utf_display(iptr->method->name); */
2968 * These are local overrides for various environment variables in Emacs.
2969 * Please do not remove this and leave it at the end of the file, where
2970 * Emacs will automagically detect them.
2971 * ---------------------------------------------------------------------
2974 * indent-tabs-mode: t