1 /* jit/stack.c - stack analysis
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4 R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
5 M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
6 P. Tomsich, J. Wenninger
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
31 $Id: stack.c 1415 2004-10-11 20:12:08Z jowenn $
45 #include "statistics.h"
46 #include "jit/codegen.inc.h"
48 #include "jit/stack.h"
50 #include "toolbox/logging.h"
51 #include "toolbox/memory.h"
54 /**********************************************************************/
56 /**********************************************************************/
58 /* analyse_stack uses the intermediate code created by parse.c to
59 * build a model of the JVM operand stack for the current method.
61 * The following checks are performed:
62 * - check for operand stack underflow (before each instruction)
63 * - check for operand stack overflow (after[1] each instruction)
64 * - check for matching stack depth at merging points
65 * - check for matching basic types[2] at merging points
66 * - check basic types for instruction input (except for BUILTIN*
67 * opcodes, INVOKE* opcodes and MULTIANEWARRAY)
69 * [1]) Checking this after the instruction should be ok. parse.c
70 * counts the number of required stack slots in such a way that it is
71 * only vital that we don't exceed `maxstack` at basic block
74 * [2]) 'basic types' means the distinction between INT, LONG, FLOAT,
75 * DOUBLE and ADDRESS types. Subtypes of INT and different ADDRESS
76 * types are not discerned.
79 methodinfo *analyse_stack(codegendata *codegendata)
87 int opcode, i, len, loops;
88 int superblockend, repeat, deadcode;
95 methodinfo *m=codegendata->method;
97 argren = DMNEW(s4, m->maxlocals); /* table for argument renaming */
98 for (i = 0; i < m->maxlocals; i++)
101 m->registerdata->arguments_num = 0;
104 m->basicblocks[0].flags = BBREACHED;
105 m->basicblocks[0].instack = 0;
106 m->basicblocks[0].indepth = 0;
108 for (i = 0; i < m->codegendata->exceptiontablelength; i++) {
109 bptr = &m->basicblocks[m->basicblockindex[m->codegendata->exceptiontable[i].handlerpc]];
110 bptr->flags = BBREACHED;
111 bptr->type = BBTYPE_EXH;
114 bptr->pre_count = 10000;
119 #ifdef CONDITIONAL_LOADCONST
120 b_count = m->basicblockcount;
121 bptr = m->basicblocks;
122 while (--b_count >= 0) {
123 if (bptr->icount != 0) {
124 iptr = bptr->iinstr + bptr->icount - 1;
157 m->basicblocks[m->basicblockindex[iptr->op1]].pre_count++;
160 case ICMD_TABLESWITCH:
162 m->basicblocks[m->basicblockindex[*s4ptr++]].pre_count++;
163 i = *s4ptr++; /* low */
164 i = *s4ptr++ - i + 1; /* high */
166 m->basicblocks[m->basicblockindex[*s4ptr++]].pre_count++;
170 case ICMD_LOOKUPSWITCH:
172 m->basicblocks[m->basicblockindex[*s4ptr++]].pre_count++;
173 i = *s4ptr++; /* count */
175 m->basicblocks[m->basicblockindex[s4ptr[1]]].pre_count++;
191 b_count = m->basicblockcount;
192 bptr = m->basicblocks;
193 superblockend = true;
197 while (--b_count >= 0) {
198 if (bptr->flags == BBDELETED) {
201 else if (superblockend && (bptr->flags < BBREACHED))
203 else if (bptr->flags <= BBREACHED) {
205 stackdepth = bptr->indepth;
206 else if (bptr->flags < BBREACHED) {
208 bptr->instack = copy;
209 bptr->indepth = stackdepth;
211 else if (bptr->indepth != stackdepth) {
213 panic("Stack depth mismatch");
216 curstack = bptr->instack;
218 superblockend = false;
219 bptr->flags = BBFINISHED;
222 b_index = bptr - m->basicblocks;
227 /* dolog("p: %04d op: %s stack: %p", iptr - instr, icmd_names[opcode], curstack); */
229 #ifdef USEBUILTINTABLE
232 stdopdescriptor *breplace;
233 breplace = find_builtin(opcode);
235 if (breplace && opcode == breplace->opcode) {
236 iptr[0].opc = breplace->icmd;
237 iptr[0].op1 = breplace->type_d;
238 iptr[0].val.a = breplace->builtin;
239 m->isleafmethod = false;
240 switch (breplace->icmd) {
248 builtin_descriptor *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.a = breplace->builtin;
255 m->isleafmethod = false;
256 switch (breplace->icmd) {
271 case ICMD_CHECKASIZE:
272 case ICMD_CHECKEXCEPTION:
274 case ICMD_IFEQ_ICONST:
275 case ICMD_IFNE_ICONST:
276 case ICMD_IFLT_ICONST:
277 case ICMD_IFGE_ICONST:
278 case ICMD_IFGT_ICONST:
279 case ICMD_IFLE_ICONST:
280 case ICMD_ELSE_ICONST:
285 m->registerdata->locals[iptr->op1][TYPE_ADR].type = TYPE_ADR;
287 COUNT(count_pcmd_return);
289 superblockend = true;
292 /* pop 0 push 1 const */
295 COUNT(count_pcmd_load);
297 switch (iptr[1].opc) {
299 iptr[0].opc = ICMD_IADDCONST;
301 iptr[1].opc = ICMD_NOP;
302 OP1_1(TYPE_INT,TYPE_INT);
303 COUNT(count_pcmd_op);
306 iptr[0].opc = ICMD_ISUBCONST;
307 goto icmd_iconst_tail;
309 iptr[0].opc = ICMD_IMULCONST;
310 goto icmd_iconst_tail;
312 if (iptr[0].val.i == 0x00000002)
314 else if (iptr[0].val.i == 0x00000004)
316 else if (iptr[0].val.i == 0x00000008)
318 else if (iptr[0].val.i == 0x00000010)
320 else if (iptr[0].val.i == 0x00000020)
322 else if (iptr[0].val.i == 0x00000040)
324 else if (iptr[0].val.i == 0x00000080)
326 else if (iptr[0].val.i == 0x00000100)
328 else if (iptr[0].val.i == 0x00000200)
330 else if (iptr[0].val.i == 0x00000400)
332 else if (iptr[0].val.i == 0x00000800)
334 else if (iptr[0].val.i == 0x00001000)
336 else if (iptr[0].val.i == 0x00002000)
338 else if (iptr[0].val.i == 0x00004000)
340 else if (iptr[0].val.i == 0x00008000)
342 else if (iptr[0].val.i == 0x00010000)
344 else if (iptr[0].val.i == 0x00020000)
346 else if (iptr[0].val.i == 0x00040000)
348 else if (iptr[0].val.i == 0x00080000)
350 else if (iptr[0].val.i == 0x00100000)
352 else if (iptr[0].val.i == 0x00200000)
354 else if (iptr[0].val.i == 0x00400000)
356 else if (iptr[0].val.i == 0x00800000)
358 else if (iptr[0].val.i == 0x01000000)
360 else if (iptr[0].val.i == 0x02000000)
362 else if (iptr[0].val.i == 0x04000000)
364 else if (iptr[0].val.i == 0x08000000)
366 else if (iptr[0].val.i == 0x10000000)
368 else if (iptr[0].val.i == 0x20000000)
370 else if (iptr[0].val.i == 0x40000000)
372 else if (iptr[0].val.i == 0x80000000)
378 iptr[0].opc = ICMD_IDIVPOW2;
379 goto icmd_iconst_tail;
381 if ((iptr[0].val.i == 0x00000002) ||
382 (iptr[0].val.i == 0x00000004) ||
383 (iptr[0].val.i == 0x00000008) ||
384 (iptr[0].val.i == 0x00000010) ||
385 (iptr[0].val.i == 0x00000020) ||
386 (iptr[0].val.i == 0x00000040) ||
387 (iptr[0].val.i == 0x00000080) ||
388 (iptr[0].val.i == 0x00000100) ||
389 (iptr[0].val.i == 0x00000200) ||
390 (iptr[0].val.i == 0x00000400) ||
391 (iptr[0].val.i == 0x00000800) ||
392 (iptr[0].val.i == 0x00001000) ||
393 (iptr[0].val.i == 0x00002000) ||
394 (iptr[0].val.i == 0x00004000) ||
395 (iptr[0].val.i == 0x00008000) ||
396 (iptr[0].val.i == 0x00010000) ||
397 (iptr[0].val.i == 0x00020000) ||
398 (iptr[0].val.i == 0x00040000) ||
399 (iptr[0].val.i == 0x00080000) ||
400 (iptr[0].val.i == 0x00100000) ||
401 (iptr[0].val.i == 0x00200000) ||
402 (iptr[0].val.i == 0x00400000) ||
403 (iptr[0].val.i == 0x00800000) ||
404 (iptr[0].val.i == 0x01000000) ||
405 (iptr[0].val.i == 0x02000000) ||
406 (iptr[0].val.i == 0x04000000) ||
407 (iptr[0].val.i == 0x08000000) ||
408 (iptr[0].val.i == 0x10000000) ||
409 (iptr[0].val.i == 0x20000000) ||
410 (iptr[0].val.i == 0x40000000) ||
411 (iptr[0].val.i == 0x80000000)) {
412 iptr[0].opc = ICMD_IREMPOW2;
414 #if defined(__I386__)
415 method_uses_ecx = true;
417 goto icmd_iconst_tail;
422 iptr[0].opc = ICMD_IANDCONST;
423 goto icmd_iconst_tail;
425 iptr[0].opc = ICMD_IORCONST;
426 goto icmd_iconst_tail;
428 iptr[0].opc = ICMD_IXORCONST;
429 goto icmd_iconst_tail;
431 iptr[0].opc = ICMD_ISHLCONST;
432 goto icmd_iconst_tail;
434 iptr[0].opc = ICMD_ISHRCONST;
435 goto icmd_iconst_tail;
437 iptr[0].opc = ICMD_IUSHRCONST;
438 goto icmd_iconst_tail;
439 #if SUPPORT_LONG_SHIFT
441 iptr[0].opc = ICMD_LSHLCONST;
442 #if defined(__I386__)
443 method_uses_ecx = true;
445 goto icmd_lconst_tail;
447 iptr[0].opc = ICMD_LSHRCONST;
448 #if defined(__I386__)
449 method_uses_ecx = true;
451 goto icmd_lconst_tail;
453 iptr[0].opc = ICMD_LUSHRCONST;
454 #if defined(__I386__)
455 method_uses_ecx = true;
457 goto icmd_lconst_tail;
460 iptr[0].opc = ICMD_IFEQ;
462 iptr[0].op1 = iptr[1].op1;
465 /* iptr[1].opc = ICMD_NOP; */
467 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
469 iptr[0].target = (void *) tbptr;
471 MARKREACHED(tbptr, copy);
472 COUNT(count_pcmd_bra);
475 iptr[0].opc = ICMD_IFLT;
476 goto icmd_if_icmp_tail;
478 iptr[0].opc = ICMD_IFLE;
479 goto icmd_if_icmp_tail;
481 iptr[0].opc = ICMD_IFNE;
482 goto icmd_if_icmp_tail;
484 iptr[0].opc = ICMD_IFGT;
485 goto icmd_if_icmp_tail;
487 iptr[0].opc = ICMD_IFGE;
488 goto icmd_if_icmp_tail;
490 #if SUPPORT_CONST_ASTORE
495 #if SUPPORT_ONLY_ZERO_ASTORE
496 if (iptr[0].val.i == 0) {
497 #endif /* SUPPORT_ONLY_ZERO_ASTORE */
498 switch (iptr[1].opc) {
500 iptr[0].opc = ICMD_IASTORECONST;
503 iptr[0].opc = ICMD_BASTORECONST;
506 iptr[0].opc = ICMD_CASTORECONST;
509 iptr[0].opc = ICMD_SASTORECONST;
513 iptr[1].opc = ICMD_NOP;
514 OPTT2_0(TYPE_INT, TYPE_ADR);
515 COUNT(count_pcmd_op);
516 #if SUPPORT_ONLY_ZERO_ASTORE
519 #endif /* SUPPORT_ONLY_ZERO_ASTORE */
521 #endif /* SUPPORT_CONST_ASTORE */
532 COUNT(count_pcmd_load);
534 switch (iptr[1].opc) {
537 iptr[0].opc = ICMD_LADDCONST;
539 iptr[1].opc = ICMD_NOP;
540 OP1_1(TYPE_LNG,TYPE_LNG);
541 COUNT(count_pcmd_op);
544 iptr[0].opc = ICMD_LSUBCONST;
545 goto icmd_lconst_tail;
549 iptr[0].opc = ICMD_LMULCONST;
550 #if defined(__I386__)
551 method_uses_ecx = true;
552 method_uses_edx = true;
554 goto icmd_lconst_tail;
558 if (iptr[0].val.l == 0x00000002)
560 else if (iptr[0].val.l == 0x00000004)
562 else if (iptr[0].val.l == 0x00000008)
564 else if (iptr[0].val.l == 0x00000010)
566 else if (iptr[0].val.l == 0x00000020)
568 else if (iptr[0].val.l == 0x00000040)
570 else if (iptr[0].val.l == 0x00000080)
572 else if (iptr[0].val.l == 0x00000100)
574 else if (iptr[0].val.l == 0x00000200)
576 else if (iptr[0].val.l == 0x00000400)
578 else if (iptr[0].val.l == 0x00000800)
580 else if (iptr[0].val.l == 0x00001000)
582 else if (iptr[0].val.l == 0x00002000)
584 else if (iptr[0].val.l == 0x00004000)
586 else if (iptr[0].val.l == 0x00008000)
588 else if (iptr[0].val.l == 0x00010000)
590 else if (iptr[0].val.l == 0x00020000)
592 else if (iptr[0].val.l == 0x00040000)
594 else if (iptr[0].val.l == 0x00080000)
596 else if (iptr[0].val.l == 0x00100000)
598 else if (iptr[0].val.l == 0x00200000)
600 else if (iptr[0].val.l == 0x00400000)
602 else if (iptr[0].val.l == 0x00800000)
604 else if (iptr[0].val.l == 0x01000000)
606 else if (iptr[0].val.l == 0x02000000)
608 else if (iptr[0].val.l == 0x04000000)
610 else if (iptr[0].val.l == 0x08000000)
612 else if (iptr[0].val.l == 0x10000000)
614 else if (iptr[0].val.l == 0x20000000)
616 else if (iptr[0].val.l == 0x40000000)
618 else if (iptr[0].val.l == 0x80000000)
624 iptr[0].opc = ICMD_LDIVPOW2;
625 #if defined(__I386__)
626 method_uses_ecx = true;
628 goto icmd_lconst_tail;
630 if ((iptr[0].val.l == 0x00000002) ||
631 (iptr[0].val.l == 0x00000004) ||
632 (iptr[0].val.l == 0x00000008) ||
633 (iptr[0].val.l == 0x00000010) ||
634 (iptr[0].val.l == 0x00000020) ||
635 (iptr[0].val.l == 0x00000040) ||
636 (iptr[0].val.l == 0x00000080) ||
637 (iptr[0].val.l == 0x00000100) ||
638 (iptr[0].val.l == 0x00000200) ||
639 (iptr[0].val.l == 0x00000400) ||
640 (iptr[0].val.l == 0x00000800) ||
641 (iptr[0].val.l == 0x00001000) ||
642 (iptr[0].val.l == 0x00002000) ||
643 (iptr[0].val.l == 0x00004000) ||
644 (iptr[0].val.l == 0x00008000) ||
645 (iptr[0].val.l == 0x00010000) ||
646 (iptr[0].val.l == 0x00020000) ||
647 (iptr[0].val.l == 0x00040000) ||
648 (iptr[0].val.l == 0x00080000) ||
649 (iptr[0].val.l == 0x00100000) ||
650 (iptr[0].val.l == 0x00200000) ||
651 (iptr[0].val.l == 0x00400000) ||
652 (iptr[0].val.l == 0x00800000) ||
653 (iptr[0].val.l == 0x01000000) ||
654 (iptr[0].val.l == 0x02000000) ||
655 (iptr[0].val.l == 0x04000000) ||
656 (iptr[0].val.l == 0x08000000) ||
657 (iptr[0].val.l == 0x10000000) ||
658 (iptr[0].val.l == 0x20000000) ||
659 (iptr[0].val.l == 0x40000000) ||
660 (iptr[0].val.l == 0x80000000)) {
661 iptr[0].opc = ICMD_LREMPOW2;
663 #if defined(__I386__)
664 method_uses_ecx = true;
666 goto icmd_lconst_tail;
673 iptr[0].opc = ICMD_LANDCONST;
674 goto icmd_lconst_tail;
676 iptr[0].opc = ICMD_LORCONST;
677 goto icmd_lconst_tail;
679 iptr[0].opc = ICMD_LXORCONST;
680 goto icmd_lconst_tail;
682 #if !defined(NOLONG_CONDITIONAL)
684 if ((len > 1) && (iptr[2].val.i == 0)) {
685 switch (iptr[2].opc) {
687 iptr[0].opc = ICMD_IF_LEQ;
688 #if defined(__I386__)
689 method_uses_ecx = true;
691 icmd_lconst_lcmp_tail:
692 iptr[0].op1 = iptr[2].op1;
695 /* iptr[1].opc = ICMD_NOP;
696 iptr[2].opc = ICMD_NOP; */
698 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
700 iptr[0].target = (void *) tbptr;
702 MARKREACHED(tbptr, copy);
703 COUNT(count_pcmd_bra);
704 COUNT(count_pcmd_op);
707 iptr[0].opc = ICMD_IF_LNE;
708 #if defined(__I386__)
709 method_uses_ecx = true;
711 goto icmd_lconst_lcmp_tail;
713 iptr[0].opc = ICMD_IF_LLT;
714 goto icmd_lconst_lcmp_tail;
716 iptr[0].opc = ICMD_IF_LGT;
717 goto icmd_lconst_lcmp_tail;
719 iptr[0].opc = ICMD_IF_LLE;
720 goto icmd_lconst_lcmp_tail;
722 iptr[0].opc = ICMD_IF_LGE;
723 goto icmd_lconst_lcmp_tail;
726 } /* switch (iptr[2].opc) */
727 } /* if (iptr[2].val.i == 0) */
733 #if SUPPORT_CONST_ASTORE
735 #if SUPPORT_ONLY_ZERO_ASTORE
736 if (iptr[0].val.l == 0) {
737 #endif /* SUPPORT_ONLY_ZERO_ASTORE */
738 iptr[0].opc = ICMD_LASTORECONST;
739 iptr[1].opc = ICMD_NOP;
740 OPTT2_0(TYPE_INT, TYPE_ADR);
741 COUNT(count_pcmd_op);
742 #if SUPPORT_ONLY_ZERO_ASTORE
745 #endif /* SUPPORT_ONLY_ZERO_ASTORE */
747 #endif /* SUPPORT_CONST_ASTORE */
758 COUNT(count_pcmd_load);
763 COUNT(count_pcmd_load);
768 COUNT(count_pcmd_load);
769 #if SUPPORT_CONST_ASTORE
770 if (len > 0 && iptr->val.a == 0) {
771 if (iptr[1].opc == ICMD_BUILTIN3 &&
772 iptr[1].val.a == BUILTIN_aastore) {
773 iptr[0].opc = ICMD_AASTORECONST;
774 iptr[1].opc = ICMD_NOP;
775 OPTT2_0(TYPE_INT, TYPE_ADR);
776 COUNT(count_pcmd_op);
783 #endif /* SUPPORT_CONST_ASTORE */
787 /* pop 0 push 1 load */
794 COUNT(count_load_instruction);
795 i = opcode-ICMD_ILOAD;
796 iptr->op1 = argren[iptr->op1];
797 m->registerdata->locals[iptr->op1][i].type = i;
798 LOAD(i, LOCALVAR, iptr->op1);
804 #if defined(__I386__)
805 method_uses_ecx = true;
806 method_uses_edx = true;
812 COUNT(count_check_null);
813 COUNT(count_check_bound);
814 COUNT(count_pcmd_mem);
815 OP2IAT_1(opcode-ICMD_IALOAD);
816 #if defined(__I386__)
817 method_uses_ecx = true;
824 COUNT(count_check_null);
825 COUNT(count_check_bound);
826 COUNT(count_pcmd_mem);
828 #if defined(__I386__)
829 method_uses_ecx = true;
833 /* pop 0 push 0 iinc */
839 count_store_depth[10]++;
841 count_store_depth[i]++;
846 if ((copy->varkind == LOCALVAR) &&
847 (copy->varnum == iptr->op1)) {
848 copy->varkind = TEMPVAR;
857 /* pop 1 push 0 store */
867 i = opcode - ICMD_ISTORE;
868 m->registerdata->locals[iptr->op1][i].type = i;
873 count_store_length[20]++;
875 count_store_length[i]++;
878 count_store_depth[10]++;
880 count_store_depth[i]++;
882 copy = curstack->prev;
885 if ((copy->varkind == LOCALVAR) &&
886 (copy->varnum == iptr->op1)) {
887 copy->varkind = TEMPVAR;
893 if ((new - curstack) == 1) {
894 curstack->varkind = LOCALVAR;
895 curstack->varnum = iptr->op1;
897 STORE(opcode-ICMD_ISTORE);
905 #if defined(__I386__)
906 method_uses_ecx = true;
907 method_uses_edx = true;
911 COUNT(count_check_null);
912 COUNT(count_check_bound);
913 COUNT(count_pcmd_mem);
914 OP3TIA_0(opcode-ICMD_IASTORE);
920 COUNT(count_check_null);
921 COUNT(count_check_bound);
922 COUNT(count_pcmd_mem);
924 #if defined(__I386__)
925 method_uses_ecx = true;
926 method_uses_edx = true;
933 #ifdef TYPECHECK_STACK_COMPCAT
936 if (IS_2_WORD_TYPE(curstack->type)) {
937 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
950 COUNT(count_pcmd_return);
951 OP1_0(opcode-ICMD_IRETURN);
952 superblockend = true;
956 COUNT(count_check_null);
960 superblockend = true;
964 COUNT(count_pcmd_mem);
966 #if defined(__I386__)
967 method_uses_ecx = true;
971 /* pop 1 push 0 branch */
975 COUNT(count_pcmd_bra);
977 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
979 iptr[0].target = (void *) tbptr;
981 MARKREACHED(tbptr, copy);
990 COUNT(count_pcmd_bra);
991 #ifdef CONDITIONAL_LOADCONST
993 tbptr = m->basicblocks + b_index;
994 if ((b_count >= 3) &&
995 ((b_index + 2) == m->basicblockindex[iptr[0].op1]) &&
996 (tbptr[1].pre_count == 1) &&
997 (iptr[1].opc == ICMD_ICONST) &&
998 (iptr[2].opc == ICMD_GOTO) &&
999 ((b_index + 3) == m->basicblockindex[iptr[2].op1]) &&
1000 (tbptr[2].pre_count == 1) &&
1001 (iptr[3].opc == ICMD_ICONST)) {
1002 OP1_1(TYPE_INT, TYPE_INT);
1003 switch (iptr[0].opc) {
1005 iptr[0].opc = ICMD_IFNE_ICONST;
1008 iptr[0].opc = ICMD_IFEQ_ICONST;
1011 iptr[0].opc = ICMD_IFGE_ICONST;
1014 iptr[0].opc = ICMD_IFLT_ICONST;
1017 iptr[0].opc = ICMD_IFLE_ICONST;
1020 iptr[0].opc = ICMD_IFGT_ICONST;
1023 iptr[0].val.i = iptr[1].val.i;
1024 iptr[1].opc = ICMD_ELSE_ICONST;
1025 iptr[1].val.i = iptr[3].val.i;
1026 iptr[2].opc = ICMD_NOP;
1027 iptr[3].opc = ICMD_NOP;
1028 tbptr[1].flags = BBDELETED;
1029 tbptr[2].flags = BBDELETED;
1030 tbptr[1].icount = 0;
1031 tbptr[2].icount = 0;
1032 if (tbptr[3].pre_count == 2) {
1033 len += tbptr[3].icount + 3;
1034 bptr->icount += tbptr[3].icount + 3;
1035 tbptr[3].flags = BBDELETED;
1036 tbptr[3].icount = 0;
1049 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1051 iptr[0].target = (void *) tbptr;
1053 MARKREACHED(tbptr, copy);
1056 /* pop 0 push 0 branch */
1059 COUNT(count_pcmd_bra);
1060 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1062 iptr[0].target = (void *) tbptr;
1064 MARKREACHED(tbptr, copy);
1066 superblockend = true;
1069 /* pop 1 push 0 table branch */
1071 case ICMD_TABLESWITCH:
1072 COUNT(count_pcmd_table);
1074 s4ptr = iptr->val.a;
1075 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
1076 MARKREACHED(tbptr, copy);
1077 i = *s4ptr++; /* low */
1078 i = *s4ptr++ - i + 1; /* high */
1080 tptr = DMNEW(void*, i+1);
1081 iptr->target = (void *) tptr;
1083 tptr[0] = (void *) tbptr;
1087 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
1089 tptr[0] = (void *) tbptr;
1092 MARKREACHED(tbptr, copy);
1095 superblockend = true;
1096 #if defined(__I386__)
1097 method_uses_ecx = true;
1101 /* pop 1 push 0 table branch */
1103 case ICMD_LOOKUPSWITCH:
1104 COUNT(count_pcmd_table);
1106 s4ptr = iptr->val.a;
1107 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
1108 MARKREACHED(tbptr, copy);
1109 i = *s4ptr++; /* count */
1111 tptr = DMNEW(void*, i+1);
1112 iptr->target = (void *) tptr;
1114 tptr[0] = (void *) tbptr;
1118 tbptr = m->basicblocks + m->basicblockindex[s4ptr[1]];
1120 tptr[0] = (void *) tbptr;
1123 MARKREACHED(tbptr, copy);
1127 superblockend = true;
1130 case ICMD_NULLCHECKPOP:
1131 case ICMD_MONITORENTER:
1132 COUNT(count_check_null);
1133 case ICMD_MONITOREXIT:
1137 /* pop 2 push 0 branch */
1139 case ICMD_IF_ICMPEQ:
1140 case ICMD_IF_ICMPNE:
1141 case ICMD_IF_ICMPLT:
1142 case ICMD_IF_ICMPGE:
1143 case ICMD_IF_ICMPGT:
1144 case ICMD_IF_ICMPLE:
1145 COUNT(count_pcmd_bra);
1147 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1149 iptr[0].target = (void *) tbptr;
1151 MARKREACHED(tbptr, copy);
1154 case ICMD_IF_ACMPEQ:
1155 case ICMD_IF_ACMPNE:
1156 COUNT(count_pcmd_bra);
1158 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1160 iptr[0].target = (void *) tbptr;
1162 MARKREACHED(tbptr, copy);
1168 COUNT(count_check_null);
1169 COUNT(count_pcmd_mem);
1170 OPTT2_0(iptr->op1,TYPE_ADR);
1171 #if defined(__I386__)
1172 method_uses_ecx = true;
1178 if (!IS_2_WORD_TYPE(curstack->type)) {
1180 #ifdef TYPECHECK_STACK_COMPCAT
1183 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1184 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1189 OP1_0ANY; /* second pop */
1192 iptr->opc = ICMD_POP;
1196 /* pop 0 push 1 dup */
1199 #ifdef TYPECHECK_STACK_COMPCAT
1202 if (IS_2_WORD_TYPE(curstack->type)) {
1203 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1208 COUNT(count_dup_instruction);
1214 if (IS_2_WORD_TYPE(curstack->type)) {
1216 iptr->opc = ICMD_DUP;
1221 /* ..., ????, cat1 */
1222 #ifdef TYPECHECK_STACK_COMPCAT
1224 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1225 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1231 NEWSTACK(copy->prev->type, copy->prev->varkind,
1232 copy->prev->varnum);
1233 NEWSTACK(copy->type, copy->varkind,
1240 /* pop 2 push 3 dup */
1243 #ifdef TYPECHECK_STACK_COMPCAT
1246 if (IS_2_WORD_TYPE(curstack->type) ||
1247 IS_2_WORD_TYPE(curstack->prev->type)) {
1248 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1258 if (IS_2_WORD_TYPE(curstack->type)) {
1259 /* ..., ????, cat2 */
1260 #ifdef TYPECHECK_STACK_COMPCAT
1262 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1263 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1268 iptr->opc = ICMD_DUP_X1;
1272 /* ..., ????, cat1 */
1273 #ifdef TYPECHECK_STACK_COMPCAT
1276 if (IS_2_WORD_TYPE(curstack->prev->type)
1277 || IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1278 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1287 /* pop 3 push 4 dup */
1291 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1292 /* ..., cat2, ???? */
1293 #ifdef TYPECHECK_STACK_COMPCAT
1295 if (IS_2_WORD_TYPE(curstack->type)) {
1296 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1301 iptr->opc = ICMD_DUP_X1;
1305 /* ..., cat1, ???? */
1306 #ifdef TYPECHECK_STACK_COMPCAT
1309 if (IS_2_WORD_TYPE(curstack->type)
1310 || IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1311 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1322 if (IS_2_WORD_TYPE(curstack->type)) {
1323 /* ..., ????, cat2 */
1324 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1325 /* ..., cat2, cat2 */
1326 iptr->opc = ICMD_DUP_X1;
1330 /* ..., cat1, cat2 */
1331 #ifdef TYPECHECK_STACK_COMPCAT
1334 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1335 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1340 iptr->opc = ICMD_DUP_X2;
1346 /* ..., ????, ????, cat1 */
1347 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1348 /* ..., cat2, ????, cat1 */
1349 #ifdef TYPECHECK_STACK_COMPCAT
1351 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1352 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1357 iptr->opc = ICMD_DUP2_X1;
1361 /* ..., cat1, ????, cat1 */
1362 #ifdef TYPECHECK_STACK_COMPCAT
1365 if (IS_2_WORD_TYPE(curstack->prev->type)
1366 || IS_2_WORD_TYPE(curstack->prev->prev->prev->type)) {
1367 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1377 /* pop 2 push 2 swap */
1380 #ifdef TYPECHECK_STACK_COMPCAT
1383 if (IS_2_WORD_TYPE(curstack->type)
1384 || IS_2_WORD_TYPE(curstack->prev->type)) {
1385 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1396 #if !SUPPORT_DIVISION
1397 iptr[0].opc = ICMD_BUILTIN2;
1398 iptr[0].op1 = TYPE_INT;
1399 iptr[0].val.a = BUILTIN_idiv;
1400 m->isleafmethod = false;
1405 #if !SUPPORT_DIVISION
1406 iptr[0].opc = ICMD_BUILTIN2;
1407 iptr[0].op1 = TYPE_INT;
1408 iptr[0].val.a = BUILTIN_irem;
1409 m->isleafmethod = false;
1412 #if defined(__I386__)
1413 method_uses_ecx = true;
1414 method_uses_edx = true;
1420 #if defined(__I386__)
1421 method_uses_ecx = true;
1429 COUNT(count_pcmd_op);
1434 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1435 iptr[0].opc = ICMD_BUILTIN2;
1436 iptr[0].op1 = TYPE_LNG;
1437 iptr[0].val.a = BUILTIN_ldiv;
1438 m->isleafmethod = false;
1443 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1444 iptr[0].opc = ICMD_BUILTIN2;
1445 iptr[0].op1 = TYPE_LNG;
1446 iptr[0].val.a = BUILTIN_lrem;
1447 m->isleafmethod = false;
1452 #if defined(__I386__)
1453 method_uses_ecx = true;
1454 method_uses_edx = true;
1461 /* DEBUG */ /*dolog("OP2_1(TYPE_LNG)"); */
1462 COUNT(count_pcmd_op);
1469 COUNT(count_pcmd_op);
1471 #if defined(__I386__)
1472 method_uses_ecx = true;
1473 method_uses_edx = true;
1482 COUNT(count_pcmd_op);
1491 COUNT(count_pcmd_op);
1496 COUNT(count_pcmd_op);
1497 #if !defined(NOLONG_CONDITIONAL)
1498 if ((len > 0) && (iptr[1].val.i == 0)) {
1499 switch (iptr[1].opc) {
1501 iptr[0].opc = ICMD_IF_LCMPEQ;
1502 #if defined(__I386__)
1503 method_uses_ecx = true;
1506 iptr[0].op1 = iptr[1].op1;
1509 /* iptr[1].opc = ICMD_NOP; */
1511 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1513 iptr[0].target = (void *) tbptr;
1515 MARKREACHED(tbptr, copy);
1516 COUNT(count_pcmd_bra);
1519 iptr[0].opc = ICMD_IF_LCMPNE;
1520 #if defined(__I386__)
1521 method_uses_ecx = true;
1523 goto icmd_lcmp_if_tail;
1525 iptr[0].opc = ICMD_IF_LCMPLT;
1526 goto icmd_lcmp_if_tail;
1528 iptr[0].opc = ICMD_IF_LCMPGT;
1529 goto icmd_lcmp_if_tail;
1531 iptr[0].opc = ICMD_IF_LCMPLE;
1532 goto icmd_lcmp_if_tail;
1534 iptr[0].opc = ICMD_IF_LCMPGE;
1535 goto icmd_lcmp_if_tail;
1537 OPTT2_1(TYPE_LNG, TYPE_INT);
1542 OPTT2_1(TYPE_LNG, TYPE_INT);
1546 COUNT(count_pcmd_op);
1547 OPTT2_1(TYPE_FLT, TYPE_INT);
1551 COUNT(count_pcmd_op);
1552 OPTT2_1(TYPE_DBL, TYPE_INT);
1560 case ICMD_INT2SHORT:
1561 COUNT(count_pcmd_op);
1562 OP1_1(TYPE_INT, TYPE_INT);
1565 COUNT(count_pcmd_op);
1566 OP1_1(TYPE_LNG, TYPE_LNG);
1569 COUNT(count_pcmd_op);
1570 OP1_1(TYPE_FLT, TYPE_FLT);
1573 COUNT(count_pcmd_op);
1574 OP1_1(TYPE_DBL, TYPE_DBL);
1578 COUNT(count_pcmd_op);
1579 OP1_1(TYPE_INT, TYPE_LNG);
1580 #if defined(__I386__)
1581 method_uses_edx = true;
1585 COUNT(count_pcmd_op);
1586 OP1_1(TYPE_INT, TYPE_FLT);
1589 COUNT(count_pcmd_op);
1590 OP1_1(TYPE_INT, TYPE_DBL);
1593 COUNT(count_pcmd_op);
1594 OP1_1(TYPE_LNG, TYPE_INT);
1597 COUNT(count_pcmd_op);
1598 OP1_1(TYPE_LNG, TYPE_FLT);
1601 COUNT(count_pcmd_op);
1602 OP1_1(TYPE_LNG, TYPE_DBL);
1605 COUNT(count_pcmd_op);
1606 OP1_1(TYPE_FLT, TYPE_INT);
1609 COUNT(count_pcmd_op);
1610 OP1_1(TYPE_FLT, TYPE_LNG);
1611 #if defined(__I386__)
1612 method_uses_edx = true;
1616 COUNT(count_pcmd_op);
1617 OP1_1(TYPE_FLT, TYPE_DBL);
1620 COUNT(count_pcmd_op);
1621 OP1_1(TYPE_DBL, TYPE_INT);
1624 COUNT(count_pcmd_op);
1625 OP1_1(TYPE_DBL, TYPE_LNG);
1626 #if defined(__I386__)
1627 method_uses_edx = true;
1631 COUNT(count_pcmd_op);
1632 OP1_1(TYPE_DBL, TYPE_FLT);
1635 case ICMD_CHECKCAST:
1636 OP1_1(TYPE_ADR, TYPE_ADR);
1637 #if defined(__I386__)
1638 method_uses_ecx = true;
1639 method_uses_edx = true;
1643 case ICMD_INSTANCEOF:
1644 #if defined(__I386__)
1645 method_uses_ecx = true;
1646 method_uses_edx = true;
1648 case ICMD_ARRAYLENGTH:
1649 OP1_1(TYPE_ADR, TYPE_INT);
1653 case ICMD_ANEWARRAY:
1654 OP1_1(TYPE_INT, TYPE_ADR);
1658 COUNT(count_check_null);
1659 COUNT(count_pcmd_mem);
1660 OP1_1(TYPE_ADR, iptr->op1);
1661 #if defined(__I386__)
1662 method_uses_ecx = true;
1668 case ICMD_GETSTATIC:
1669 COUNT(count_pcmd_mem);
1671 #if defined(__I386__)
1672 method_uses_ecx = true;
1682 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1684 iptr[0].target = (void *) tbptr;
1686 /* This is a dirty hack. The typechecker
1687 * needs it because the OP1_0ANY below
1688 * overwrites iptr->dst.
1690 iptr->val.a = (void *) iptr->dst;
1692 tbptr->type = BBTYPE_SBR;
1694 /* We need to check for overflow right here because
1695 * the pushed value is poped after MARKREACHED. */
1697 MARKREACHED(tbptr, copy);
1701 /* pop many push any */
1703 case ICMD_INVOKEVIRTUAL:
1704 case ICMD_INVOKESPECIAL:
1705 case ICMD_INVOKEINTERFACE:
1706 case ICMD_INVOKESTATIC:
1707 COUNT(count_pcmd_met);
1708 #if defined(__I386__)
1709 method_uses_ecx = true;
1712 methodinfo *lm = iptr->val.a;
1713 if (lm->flags & ACC_STATIC)
1714 {COUNT(count_check_null);}
1716 if (i > m->registerdata->arguments_num)
1717 m->registerdata->arguments_num = i;
1719 #if defined(__X86_64__)
1727 (IS_FLT_DBL_TYPE(copy->type)) ? farg++ : iarg++;
1731 stackargs += (iarg < m->registerdata->intreg_argnum) ?
1732 0 : (iarg - m->registerdata->intreg_argnum);
1733 stackargs += (farg < m->registerdata->fltreg_argnum) ?
1734 0 : (farg - m->registerdata->fltreg_argnum);
1739 if (!(copy->flags & SAVEDVAR)) {
1740 copy->varkind = ARGVAR;
1741 if (IS_FLT_DBL_TYPE(copy->type)) {
1742 if (--farg < m->registerdata->fltreg_argnum) {
1743 copy->varnum = farg;
1745 copy->varnum = --stackargs + m->registerdata->intreg_argnum;
1748 if (--iarg < m->registerdata->intreg_argnum) {
1749 copy->varnum = iarg;
1751 copy->varnum = --stackargs + m->registerdata->intreg_argnum;
1755 (IS_FLT_DBL_TYPE(copy->type)) ? --farg : --iarg;
1763 if (! (copy->flags & SAVEDVAR)) {
1764 copy->varkind = ARGVAR;
1771 copy->flags |= SAVEDVAR;
1776 if (lm->returntype != TYPE_VOID) {
1777 OP0_1(lm->returntype);
1783 /* DEBUG */ /*dolog("builtin3");*/
1785 if (! (curstack->flags & SAVEDVAR)) {
1786 curstack->varkind = ARGVAR;
1787 curstack->varnum = 2;
1789 if (3 > m->registerdata->arguments_num) {
1790 m->registerdata->arguments_num = 3;
1797 /* DEBUG */ /*dolog("builtin2");*/
1798 if (!(curstack->flags & SAVEDVAR)) {
1799 curstack->varkind = ARGVAR;
1800 curstack->varnum = 1;
1802 if (2 > m->registerdata->arguments_num) {
1803 m->registerdata->arguments_num = 2;
1810 /* DEBUG */ /*dolog("builtin1");*/
1811 if (!(curstack->flags & SAVEDVAR)) {
1812 curstack->varkind = ARGVAR;
1813 curstack->varnum = 0;
1815 if (1 > m->registerdata->arguments_num) {
1816 m->registerdata->arguments_num = 1;
1821 copy->flags |= SAVEDVAR;
1824 if (iptr->op1 != TYPE_VOID)
1828 case ICMD_MULTIANEWARRAY:
1831 if ((i + m->registerdata->intreg_argnum) > m->registerdata->arguments_num)
1832 m->registerdata->arguments_num = i + m->registerdata->intreg_argnum;
1835 /* check INT type here? Currently typecheck does this. */
1836 if (! (copy->flags & SAVEDVAR)) {
1837 copy->varkind = ARGVAR;
1838 copy->varnum = i + m->registerdata->intreg_argnum;
1843 copy->flags |= SAVEDVAR;
1851 case ICMD_CLEAR_ARGREN:
1852 for (i = iptr->op1; i<m->maxlocals; i++)
1854 iptr->opc = opcode = ICMD_NOP;
1858 case ICMD_READONLY_ARG:
1859 case ICMD_READONLY_ARG+1:
1860 case ICMD_READONLY_ARG+2:
1861 case ICMD_READONLY_ARG+3:
1862 case ICMD_READONLY_ARG+4:
1865 if (curstack->varkind == LOCALVAR) {
1866 i = curstack->varnum;
1867 argren[iptr->op1] = i;
1870 opcode = iptr->opc = opcode - ICMD_READONLY_ARG + ICMD_ISTORE;
1877 new_exception_message(string_java_lang_InternalError,
1884 } /* while instructions */
1886 bptr->outstack = curstack;
1887 bptr->outdepth = stackdepth;
1891 superblockend = true;
1893 } /* while blocks */
1894 } while (repeat && !deadcode);
1896 #if defined(STATISTICS)
1898 if (m->basicblockcount > count_max_basic_blocks)
1899 count_max_basic_blocks = m->basicblockcount;
1900 count_basic_blocks += m->basicblockcount;
1901 if (m->instructioncount > count_max_javainstr)
1902 count_max_javainstr = m->instructioncount;
1903 count_javainstr += m->instructioncount;
1904 if (m->stackcount > count_upper_bound_new_stack)
1905 count_upper_bound_new_stack = m->stackcount;
1906 if ((new - m->stack) > count_max_new_stack)
1907 count_max_new_stack = (new - m->stack);
1909 b_count = m->basicblockcount;
1910 bptr = m->basicblocks;
1911 while (--b_count >= 0) {
1912 if (bptr->flags > BBREACHED) {
1913 if (bptr->indepth >= 10)
1914 count_block_stack[10]++;
1916 count_block_stack[bptr->indepth]++;
1919 count_block_size_distribution[len]++;
1921 count_block_size_distribution[10]++;
1923 count_block_size_distribution[11]++;
1925 count_block_size_distribution[12]++;
1927 count_block_size_distribution[13]++;
1929 count_block_size_distribution[14]++;
1931 count_block_size_distribution[15]++;
1933 count_block_size_distribution[16]++;
1935 count_block_size_distribution[17]++;
1941 count_analyse_iterations[0]++;
1942 else if (loops == 2)
1943 count_analyse_iterations[1]++;
1944 else if (loops == 3)
1945 count_analyse_iterations[2]++;
1946 else if (loops == 4)
1947 count_analyse_iterations[3]++;
1949 count_analyse_iterations[4]++;
1951 if (m->basicblockcount <= 5)
1952 count_method_bb_distribution[0]++;
1953 else if (m->basicblockcount <= 10)
1954 count_method_bb_distribution[1]++;
1955 else if (m->basicblockcount <= 15)
1956 count_method_bb_distribution[2]++;
1957 else if (m->basicblockcount <= 20)
1958 count_method_bb_distribution[3]++;
1959 else if (m->basicblockcount <= 30)
1960 count_method_bb_distribution[4]++;
1961 else if (m->basicblockcount <= 40)
1962 count_method_bb_distribution[5]++;
1963 else if (m->basicblockcount <= 50)
1964 count_method_bb_distribution[6]++;
1965 else if (m->basicblockcount <= 75)
1966 count_method_bb_distribution[7]++;
1968 count_method_bb_distribution[8]++;
1972 /* just return methodinfo* to signal everything was ok */
1978 /**********************************************************************/
1979 /* DEBUGGING HELPERS */
1980 /**********************************************************************/
1982 void icmd_print_stack(methodinfo *m, stackptr s)
1994 j = m->maxstack - i;
1999 /* DEBUG */ /*printf("(%d,%d,%d,%d)",s->varkind,s->flags,s->regoff,s->varnum); fflush(stdout);*/
2000 if (s->flags & SAVEDVAR)
2001 switch (s->varkind) {
2003 if (s->flags & INMEMORY)
2004 printf(" M%02d", s->regoff);
2005 else if ((s->type == TYPE_FLT) || (s->type == TYPE_DBL))
2006 printf(" F%02d", s->regoff);
2008 printf(" %3s", regs[s->regoff]);
2012 printf(" I%02d", s->varnum);
2015 printf(" L%02d", s->varnum);
2018 printf(" A%02d", s->varnum);
2021 printf(" !%02d", j);
2024 switch (s->varkind) {
2026 if (s->flags & INMEMORY)
2027 printf(" m%02d", s->regoff);
2028 else if ((s->type == TYPE_FLT) || (s->type == TYPE_DBL))
2029 printf(" f%02d", s->regoff);
2031 printf(" %3s", regs[s->regoff]);
2035 printf(" i%02d", s->varnum);
2038 printf(" l%02d", s->varnum);
2041 printf(" a%02d", s->varnum);
2044 printf(" ?%02d", j);
2052 static void print_reg(stackptr s) {
2054 if (s->flags & SAVEDVAR)
2055 switch (s->varkind) {
2057 if (s->flags & INMEMORY)
2058 printf(" tm%02d", s->regoff);
2060 printf(" tr%02d", s->regoff);
2063 printf(" s %02d", s->varnum);
2066 printf(" l %02d", s->varnum);
2069 printf(" a %02d", s->varnum);
2072 printf(" ! %02d", s->varnum);
2075 switch (s->varkind) {
2077 if (s->flags & INMEMORY)
2078 printf(" Tm%02d", s->regoff);
2080 printf(" Tr%02d", s->regoff);
2083 printf(" S %02d", s->varnum);
2086 printf(" L %02d", s->varnum);
2089 printf(" A %02d", s->varnum);
2092 printf(" ? %02d", s->varnum);
2102 char *icmd_builtin_name(functionptr bptr)
2104 builtin_descriptor *bdesc = builtin_desc;
2105 while ((bdesc->opcode != 0) && (bdesc->builtin != bptr))
2107 return (bdesc->opcode) ? bdesc->name : "<NOT IN TABLE>";
2111 static char *jit_type[] = {
2120 void show_icmd_method(methodinfo *m)
2127 utf_fprint_classname(stdout, m->class->name);
2129 utf_fprint(stdout, m->name);
2130 utf_fprint_classname(stdout, m->descriptor);
2131 printf ("\n\nMax locals: %d\n", (int) m->maxlocals);
2132 printf ("Max stack: %d\n", (int) m->maxstack);
2134 printf ("Line number table length: %d\n", m->linenumbercount);
2136 printf ("Exceptions (Number: %d):\n", m->codegendata->exceptiontablelength);
2137 for (ex = m->codegendata->exceptiontable; ex != NULL; ex = ex->down) {
2138 printf(" L%03d ... ", ex->start->debug_nr );
2139 printf("L%03d = ", ex->end->debug_nr);
2140 printf("L%03d\n", ex->handler->debug_nr);
2143 printf ("Local Table:\n");
2144 for (i = 0; i < m->maxlocals; i++) {
2145 printf(" %3d: ", i);
2146 for (j = TYPE_INT; j <= TYPE_ADR; j++)
2147 if (m->registerdata->locals[i][j].type >= 0) {
2148 printf(" (%s) ", jit_type[j]);
2149 if (m->registerdata->locals[i][j].flags & INMEMORY)
2150 printf("m%2d", m->registerdata->locals[i][j].regoff);
2151 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2152 printf("f%02d", m->registerdata->locals[i][j].regoff);
2154 printf("%3s", regs[m->registerdata->locals[i][j].regoff]);
2161 printf ("Interface Table:\n");
2162 for (i = 0; i < m->maxstack; i++) {
2163 if ((m->registerdata->interfaces[i][0].type >= 0) ||
2164 (m->registerdata->interfaces[i][1].type >= 0) ||
2165 (m->registerdata->interfaces[i][2].type >= 0) ||
2166 (m->registerdata->interfaces[i][3].type >= 0) ||
2167 (m->registerdata->interfaces[i][4].type >= 0)) {
2168 printf(" %3d: ", i);
2169 for (j = TYPE_INT; j <= TYPE_ADR; j++)
2170 if (m->registerdata->interfaces[i][j].type >= 0) {
2171 printf(" (%s) ", jit_type[j]);
2172 if (m->registerdata->interfaces[i][j].flags & SAVEDVAR) {
2173 if (m->registerdata->interfaces[i][j].flags & INMEMORY)
2174 printf("M%2d", m->registerdata->interfaces[i][j].regoff);
2175 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2176 printf("F%02d", m->registerdata->interfaces[i][j].regoff);
2178 printf("%3s", regs[m->registerdata->interfaces[i][j].regoff]);
2182 if (m->registerdata->interfaces[i][j].flags & INMEMORY)
2183 printf("m%2d", m->registerdata->interfaces[i][j].regoff);
2184 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2185 printf("f%02d", m->registerdata->interfaces[i][j].regoff);
2187 printf("%3s", regs[m->registerdata->interfaces[i][j].regoff]);
2196 if (showdisassemble) {
2197 #if defined(__I386__) || defined(__X86_64__)
2201 u1ptr = m->mcode + m->codegendata->dseglen;
2202 for (i = 0; i < m->basicblocks[0].mpc; i++, u1ptr++) {
2203 a = disassinstr(u1ptr, i);
2211 s4ptr = (s4 *) (m->mcode + m->codegendata->dseglen);
2212 for (i = 0; i < m->basicblocks[0].mpc; i += 4, s4ptr++) {
2213 disassinstr(s4ptr, i);
2219 for (bptr = m->basicblocks; bptr != NULL; bptr = bptr->next) {
2220 show_icmd_block(m, bptr);
2225 void show_icmd_block(methodinfo *m, basicblock *bptr)
2231 if (bptr->flags != BBDELETED) {
2232 deadcode = bptr->flags <= BBREACHED;
2235 for (j = m->maxstack; j > 0; j--)
2238 icmd_print_stack(m, bptr->instack);
2239 printf("] L%03d(%d - %d) flags=%d:\n", bptr->debug_nr, bptr->icount, bptr->pre_count,bptr->flags);
2240 iptr = bptr->iinstr;
2242 for (i = 0; i < bptr->icount; i++, iptr++) {
2245 for (j = m->maxstack; j > 0; j--)
2249 icmd_print_stack(m, iptr->dst);
2250 printf("] %4d ", i);
2251 show_icmd(iptr, deadcode);
2255 if (showdisassemble && (!deadcode)) {
2256 #if defined(__I386__) || defined(__X86_64__)
2262 u1ptr = m->mcode + m->codegendata->dseglen + i;
2264 if (bptr->next != NULL) {
2265 for (; i < bptr->next->mpc; i++, u1ptr++) {
2266 a = disassinstr(u1ptr, i);
2273 for (; u1ptr < (u1 *) (m->mcode + m->mcodelength); i++, u1ptr++) {
2274 a = disassinstr(u1ptr, i);
2285 s4ptr = (s4 *) (m->mcode + m->codegendata->dseglen + i);
2287 if (bptr->next != NULL) {
2288 for (; i < bptr->next->mpc; i += 4, s4ptr++) {
2289 disassinstr(s4ptr, i);
2294 for (; s4ptr < (s4 *) (m->mcode + m->mcodelength); i += 4, s4ptr++) {
2295 disassinstr(s4ptr, i);
2305 void show_icmd(instruction *iptr, bool deadcode)
2311 printf("%s", icmd_names[iptr->opc]);
2313 switch (iptr->opc) {
2314 case ICMD_IADDCONST:
2315 case ICMD_ISUBCONST:
2316 case ICMD_IMULCONST:
2319 case ICMD_IANDCONST:
2321 case ICMD_IXORCONST:
2322 case ICMD_ISHLCONST:
2323 case ICMD_ISHRCONST:
2324 case ICMD_IUSHRCONST:
2325 case ICMD_LSHLCONST:
2326 case ICMD_LSHRCONST:
2327 case ICMD_LUSHRCONST:
2329 case ICMD_ELSE_ICONST:
2330 case ICMD_IFEQ_ICONST:
2331 case ICMD_IFNE_ICONST:
2332 case ICMD_IFLT_ICONST:
2333 case ICMD_IFGE_ICONST:
2334 case ICMD_IFGT_ICONST:
2335 case ICMD_IFLE_ICONST:
2336 case ICMD_IASTORECONST:
2337 case ICMD_BASTORECONST:
2338 case ICMD_CASTORECONST:
2339 case ICMD_SASTORECONST:
2340 printf(" %d", iptr->val.i);
2343 case ICMD_LADDCONST:
2344 case ICMD_LSUBCONST:
2345 case ICMD_LMULCONST:
2348 case ICMD_LANDCONST:
2350 case ICMD_LXORCONST:
2352 case ICMD_LASTORECONST:
2353 #if defined(__I386__)
2354 printf(" %lld", iptr->val.l);
2356 printf(" %ld", iptr->val.l);
2361 printf(" %f", iptr->val.f);
2365 printf(" %f", iptr->val.d);
2369 case ICMD_AASTORECONST:
2370 printf(" %p", iptr->val.a);
2375 printf(" %d,", ((fieldinfo *) iptr->val.a)->offset);
2376 case ICMD_PUTSTATIC:
2377 case ICMD_GETSTATIC:
2379 utf_fprint(stdout, ((fieldinfo *) iptr->val.a)->class->name);
2381 utf_fprint(stdout, ((fieldinfo *) iptr->val.a)->name);
2383 utf_fprint(stdout, ((fieldinfo *) iptr->val.a)->descriptor);
2388 printf(" %d + %d", iptr->op1, iptr->val.i);
2423 printf(" %d", iptr->op1);
2429 ((classinfo *) iptr->val.a)->name);
2433 switch (iptr->op1) {
2461 case ICMD_ANEWARRAY:
2465 ((classinfo *) iptr->val.a)->name);
2469 case ICMD_MULTIANEWARRAY:
2472 printf(" %d ",iptr->op1);
2473 vft = (vftbl_t *)iptr->val.a;
2475 utf_fprint(stdout,vft->class->name);
2481 case ICMD_CHECKCAST:
2482 case ICMD_INSTANCEOF:
2484 classinfo *c = iptr->val.a;
2485 if (c->flags & ACC_INTERFACE)
2486 printf(" (INTERFACE) ");
2488 printf(" (CLASS,%3d) ", c->vftbl->diffval);
2489 utf_fprint(stdout, c->name);
2496 printf(" %s", icmd_builtin_name((functionptr) iptr->val.a));
2499 case ICMD_INVOKEVIRTUAL:
2500 case ICMD_INVOKESPECIAL:
2501 case ICMD_INVOKESTATIC:
2502 case ICMD_INVOKEINTERFACE:
2505 ((methodinfo *) iptr->val.a)->class->name);
2508 ((methodinfo *) iptr->val.a)->name);
2517 if (deadcode || !iptr->target)
2518 printf("(%d) op1=%d", iptr->val.i, iptr->op1);
2520 printf("(%d) L%03d", iptr->val.i, ((basicblock *) iptr->target)->debug_nr);
2529 if (deadcode || !iptr->target)
2530 #if defined(__I386__) || defined(__POWERPC__)
2531 printf("(%lld) op1=%d", iptr->val.l, iptr->op1);
2533 printf("(%ld) op1=%d", iptr->val.l, iptr->op1);
2536 #if defined(__I386__) || defined(__POWERPC__)
2537 printf("(%lld) L%03d", iptr->val.l, ((basicblock *) iptr->target)->debug_nr);
2539 printf("(%ld) L%03d", iptr->val.l, ((basicblock *) iptr->target)->debug_nr);
2546 case ICMD_IFNONNULL:
2547 case ICMD_IF_ICMPEQ:
2548 case ICMD_IF_ICMPNE:
2549 case ICMD_IF_ICMPLT:
2550 case ICMD_IF_ICMPGE:
2551 case ICMD_IF_ICMPGT:
2552 case ICMD_IF_ICMPLE:
2553 case ICMD_IF_LCMPEQ:
2554 case ICMD_IF_LCMPNE:
2555 case ICMD_IF_LCMPLT:
2556 case ICMD_IF_LCMPGE:
2557 case ICMD_IF_LCMPGT:
2558 case ICMD_IF_LCMPLE:
2559 case ICMD_IF_ACMPEQ:
2560 case ICMD_IF_ACMPNE:
2561 if (deadcode || !iptr->target)
2562 printf(" op1=%d", iptr->op1);
2564 printf(" L%03d", ((basicblock *) iptr->target)->debug_nr);
2567 case ICMD_TABLESWITCH:
2568 s4ptr = (s4*)iptr->val.a;
2570 if (deadcode || !iptr->target) {
2571 printf(" %d;", *s4ptr);
2574 tptr = (void **) iptr->target;
2575 printf(" L%03d;", ((basicblock *) *tptr)->debug_nr);
2579 s4ptr++; /* skip default */
2580 j = *s4ptr++; /* low */
2581 j = *s4ptr++ - j; /* high */
2583 if (deadcode || !*tptr)
2584 printf(" %d", *s4ptr++);
2586 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2593 case ICMD_LOOKUPSWITCH:
2594 s4ptr = (s4*)iptr->val.a;
2596 if (deadcode || !iptr->target) {
2597 printf(" %d;", *s4ptr);
2600 tptr = (void **) iptr->target;
2601 printf(" L%03d;", ((basicblock *) *tptr)->debug_nr);
2604 s4ptr++; /* default */
2605 j = *s4ptr++; /* count */
2608 if (deadcode || !*tptr) {
2609 s4ptr++; /* skip value */
2610 printf(" %d",*s4ptr++);
2613 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2619 /* printf(" Line number: %d, method:",iptr->line); */
2620 /* utf_display(iptr->method->class->name); */
2622 /* utf_display(iptr->method->name); */
2627 * These are local overrides for various environment variables in Emacs.
2628 * Please do not remove this and leave it at the end of the file, where
2629 * Emacs will automagically detect them.
2630 * ---------------------------------------------------------------------
2633 * indent-tabs-mode: t