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 1338 2004-07-21 16:02:14Z twisti $
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(methodinfo *m)
87 int opcode, i, len, loops;
88 int superblockend, repeat, deadcode;
96 argren = DMNEW(s4, m->maxlocals); /* table for argument renaming */
97 for (i = 0; i < m->maxlocals; i++)
100 m->registerdata->arguments_num = 0;
103 m->basicblocks[0].flags = BBREACHED;
104 m->basicblocks[0].instack = 0;
105 m->basicblocks[0].indepth = 0;
107 for (i = 0; i < m->exceptiontablelength; i++) {
108 bptr = &m->basicblocks[m->basicblockindex[m->exceptiontable[i].handlerpc]];
109 bptr->flags = BBREACHED;
110 bptr->type = BBTYPE_EXH;
113 bptr->pre_count = 10000;
118 #ifdef CONDITIONAL_LOADCONST
119 b_count = m->basicblockcount;
120 bptr = m->basicblocks;
121 while (--b_count >= 0) {
122 if (bptr->icount != 0) {
123 iptr = bptr->iinstr + bptr->icount - 1;
156 m->basicblocks[m->basicblockindex[iptr->op1]].pre_count++;
159 case ICMD_TABLESWITCH:
161 m->basicblocks[m->basicblockindex[*s4ptr++]].pre_count++;
162 i = *s4ptr++; /* low */
163 i = *s4ptr++ - i + 1; /* high */
165 m->basicblocks[m->basicblockindex[*s4ptr++]].pre_count++;
169 case ICMD_LOOKUPSWITCH:
171 m->basicblocks[m->basicblockindex[*s4ptr++]].pre_count++;
172 i = *s4ptr++; /* count */
174 m->basicblocks[m->basicblockindex[s4ptr[1]]].pre_count++;
190 b_count = m->basicblockcount;
191 bptr = m->basicblocks;
192 superblockend = true;
196 while (--b_count >= 0) {
197 if (bptr->flags == BBDELETED) {
200 else if (superblockend && (bptr->flags < BBREACHED))
202 else if (bptr->flags <= BBREACHED) {
204 stackdepth = bptr->indepth;
205 else if (bptr->flags < BBREACHED) {
207 bptr->instack = copy;
208 bptr->indepth = stackdepth;
210 else if (bptr->indepth != stackdepth) {
212 panic("Stack depth mismatch");
215 curstack = bptr->instack;
217 superblockend = false;
218 bptr->flags = BBFINISHED;
221 b_index = bptr - m->basicblocks;
226 /* dolog("p: %04d op: %s stack: %p", iptr - instr, icmd_names[opcode], curstack); */
228 #ifdef USEBUILTINTABLE
231 stdopdescriptor *breplace;
232 breplace = find_builtin(opcode);
234 if (breplace && opcode == breplace->opcode) {
235 iptr[0].opc = breplace->icmd;
236 iptr[0].op1 = breplace->type_d;
237 iptr[0].val.a = breplace->builtin;
238 m->isleafmethod = false;
239 switch (breplace->icmd) {
247 builtin_descriptor *breplace;
248 breplace = find_builtin(opcode);
250 if (breplace && opcode == breplace->opcode) {
251 iptr[0].opc = breplace->icmd;
252 iptr[0].op1 = breplace->type_d;
253 iptr[0].val.a = breplace->builtin;
254 m->isleafmethod = false;
255 switch (breplace->icmd) {
270 case ICMD_CHECKASIZE:
271 case ICMD_CHECKEXCEPTION:
273 case ICMD_IFEQ_ICONST:
274 case ICMD_IFNE_ICONST:
275 case ICMD_IFLT_ICONST:
276 case ICMD_IFGE_ICONST:
277 case ICMD_IFGT_ICONST:
278 case ICMD_IFLE_ICONST:
279 case ICMD_ELSE_ICONST:
284 m->registerdata->locals[iptr->op1][TYPE_ADR].type = TYPE_ADR;
286 COUNT(count_pcmd_return);
288 superblockend = true;
291 /* pop 0 push 1 const */
294 COUNT(count_pcmd_load);
296 switch (iptr[1].opc) {
298 iptr[0].opc = ICMD_IADDCONST;
300 iptr[1].opc = ICMD_NOP;
301 OP1_1(TYPE_INT,TYPE_INT);
302 COUNT(count_pcmd_op);
305 iptr[0].opc = ICMD_ISUBCONST;
306 goto icmd_iconst_tail;
308 iptr[0].opc = ICMD_IMULCONST;
309 goto icmd_iconst_tail;
311 if (iptr[0].val.i == 0x00000002)
313 else if (iptr[0].val.i == 0x00000004)
315 else if (iptr[0].val.i == 0x00000008)
317 else if (iptr[0].val.i == 0x00000010)
319 else if (iptr[0].val.i == 0x00000020)
321 else if (iptr[0].val.i == 0x00000040)
323 else if (iptr[0].val.i == 0x00000080)
325 else if (iptr[0].val.i == 0x00000100)
327 else if (iptr[0].val.i == 0x00000200)
329 else if (iptr[0].val.i == 0x00000400)
331 else if (iptr[0].val.i == 0x00000800)
333 else if (iptr[0].val.i == 0x00001000)
335 else if (iptr[0].val.i == 0x00002000)
337 else if (iptr[0].val.i == 0x00004000)
339 else if (iptr[0].val.i == 0x00008000)
341 else if (iptr[0].val.i == 0x00010000)
343 else if (iptr[0].val.i == 0x00020000)
345 else if (iptr[0].val.i == 0x00040000)
347 else if (iptr[0].val.i == 0x00080000)
349 else if (iptr[0].val.i == 0x00100000)
351 else if (iptr[0].val.i == 0x00200000)
353 else if (iptr[0].val.i == 0x00400000)
355 else if (iptr[0].val.i == 0x00800000)
357 else if (iptr[0].val.i == 0x01000000)
359 else if (iptr[0].val.i == 0x02000000)
361 else if (iptr[0].val.i == 0x04000000)
363 else if (iptr[0].val.i == 0x08000000)
365 else if (iptr[0].val.i == 0x10000000)
367 else if (iptr[0].val.i == 0x20000000)
369 else if (iptr[0].val.i == 0x40000000)
371 else if (iptr[0].val.i == 0x80000000)
377 iptr[0].opc = ICMD_IDIVPOW2;
378 goto icmd_iconst_tail;
380 if ((iptr[0].val.i == 0x00000002) ||
381 (iptr[0].val.i == 0x00000004) ||
382 (iptr[0].val.i == 0x00000008) ||
383 (iptr[0].val.i == 0x00000010) ||
384 (iptr[0].val.i == 0x00000020) ||
385 (iptr[0].val.i == 0x00000040) ||
386 (iptr[0].val.i == 0x00000080) ||
387 (iptr[0].val.i == 0x00000100) ||
388 (iptr[0].val.i == 0x00000200) ||
389 (iptr[0].val.i == 0x00000400) ||
390 (iptr[0].val.i == 0x00000800) ||
391 (iptr[0].val.i == 0x00001000) ||
392 (iptr[0].val.i == 0x00002000) ||
393 (iptr[0].val.i == 0x00004000) ||
394 (iptr[0].val.i == 0x00008000) ||
395 (iptr[0].val.i == 0x00010000) ||
396 (iptr[0].val.i == 0x00020000) ||
397 (iptr[0].val.i == 0x00040000) ||
398 (iptr[0].val.i == 0x00080000) ||
399 (iptr[0].val.i == 0x00100000) ||
400 (iptr[0].val.i == 0x00200000) ||
401 (iptr[0].val.i == 0x00400000) ||
402 (iptr[0].val.i == 0x00800000) ||
403 (iptr[0].val.i == 0x01000000) ||
404 (iptr[0].val.i == 0x02000000) ||
405 (iptr[0].val.i == 0x04000000) ||
406 (iptr[0].val.i == 0x08000000) ||
407 (iptr[0].val.i == 0x10000000) ||
408 (iptr[0].val.i == 0x20000000) ||
409 (iptr[0].val.i == 0x40000000) ||
410 (iptr[0].val.i == 0x80000000)) {
411 iptr[0].opc = ICMD_IREMPOW2;
413 #if defined(__I386__)
414 method_uses_ecx = true;
416 goto icmd_iconst_tail;
421 iptr[0].opc = ICMD_IANDCONST;
422 goto icmd_iconst_tail;
424 iptr[0].opc = ICMD_IORCONST;
425 goto icmd_iconst_tail;
427 iptr[0].opc = ICMD_IXORCONST;
428 goto icmd_iconst_tail;
430 iptr[0].opc = ICMD_ISHLCONST;
431 goto icmd_iconst_tail;
433 iptr[0].opc = ICMD_ISHRCONST;
434 goto icmd_iconst_tail;
436 iptr[0].opc = ICMD_IUSHRCONST;
437 goto icmd_iconst_tail;
438 #if SUPPORT_LONG_SHIFT
440 iptr[0].opc = ICMD_LSHLCONST;
441 #if defined(__I386__)
442 method_uses_ecx = true;
444 goto icmd_lconst_tail;
446 iptr[0].opc = ICMD_LSHRCONST;
447 #if defined(__I386__)
448 method_uses_ecx = true;
450 goto icmd_lconst_tail;
452 iptr[0].opc = ICMD_LUSHRCONST;
453 #if defined(__I386__)
454 method_uses_ecx = true;
456 goto icmd_lconst_tail;
459 iptr[0].opc = ICMD_IFEQ;
461 iptr[0].op1 = iptr[1].op1;
464 /* iptr[1].opc = ICMD_NOP; */
466 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
468 iptr[0].target = (void *) tbptr;
470 MARKREACHED(tbptr, copy);
471 COUNT(count_pcmd_bra);
474 iptr[0].opc = ICMD_IFLT;
475 goto icmd_if_icmp_tail;
477 iptr[0].opc = ICMD_IFLE;
478 goto icmd_if_icmp_tail;
480 iptr[0].opc = ICMD_IFNE;
481 goto icmd_if_icmp_tail;
483 iptr[0].opc = ICMD_IFGT;
484 goto icmd_if_icmp_tail;
486 iptr[0].opc = ICMD_IFGE;
487 goto icmd_if_icmp_tail;
489 #if SUPPORT_CONST_ASTORE
494 #if SUPPORT_ONLY_ZERO_ASTORE
495 if (iptr[0].val.i == 0) {
496 #endif /* SUPPORT_ONLY_ZERO_ASTORE */
497 switch (iptr[1].opc) {
499 iptr[0].opc = ICMD_IASTORECONST;
502 iptr[0].opc = ICMD_BASTORECONST;
505 iptr[0].opc = ICMD_CASTORECONST;
508 iptr[0].opc = ICMD_SASTORECONST;
512 iptr[1].opc = ICMD_NOP;
513 OPTT2_0(TYPE_INT, TYPE_ADR);
514 COUNT(count_pcmd_op);
515 #if SUPPORT_ONLY_ZERO_ASTORE
518 #endif /* SUPPORT_ONLY_ZERO_ASTORE */
520 #endif /* SUPPORT_CONST_ASTORE */
531 COUNT(count_pcmd_load);
533 switch (iptr[1].opc) {
536 iptr[0].opc = ICMD_LADDCONST;
538 iptr[1].opc = ICMD_NOP;
539 OP1_1(TYPE_LNG,TYPE_LNG);
540 COUNT(count_pcmd_op);
543 iptr[0].opc = ICMD_LSUBCONST;
544 goto icmd_lconst_tail;
548 iptr[0].opc = ICMD_LMULCONST;
549 #if defined(__I386__)
550 method_uses_ecx = true;
551 method_uses_edx = true;
553 goto icmd_lconst_tail;
557 if (iptr[0].val.l == 0x00000002)
559 else if (iptr[0].val.l == 0x00000004)
561 else if (iptr[0].val.l == 0x00000008)
563 else if (iptr[0].val.l == 0x00000010)
565 else if (iptr[0].val.l == 0x00000020)
567 else if (iptr[0].val.l == 0x00000040)
569 else if (iptr[0].val.l == 0x00000080)
571 else if (iptr[0].val.l == 0x00000100)
573 else if (iptr[0].val.l == 0x00000200)
575 else if (iptr[0].val.l == 0x00000400)
577 else if (iptr[0].val.l == 0x00000800)
579 else if (iptr[0].val.l == 0x00001000)
581 else if (iptr[0].val.l == 0x00002000)
583 else if (iptr[0].val.l == 0x00004000)
585 else if (iptr[0].val.l == 0x00008000)
587 else if (iptr[0].val.l == 0x00010000)
589 else if (iptr[0].val.l == 0x00020000)
591 else if (iptr[0].val.l == 0x00040000)
593 else if (iptr[0].val.l == 0x00080000)
595 else if (iptr[0].val.l == 0x00100000)
597 else if (iptr[0].val.l == 0x00200000)
599 else if (iptr[0].val.l == 0x00400000)
601 else if (iptr[0].val.l == 0x00800000)
603 else if (iptr[0].val.l == 0x01000000)
605 else if (iptr[0].val.l == 0x02000000)
607 else if (iptr[0].val.l == 0x04000000)
609 else if (iptr[0].val.l == 0x08000000)
611 else if (iptr[0].val.l == 0x10000000)
613 else if (iptr[0].val.l == 0x20000000)
615 else if (iptr[0].val.l == 0x40000000)
617 else if (iptr[0].val.l == 0x80000000)
623 iptr[0].opc = ICMD_LDIVPOW2;
624 #if defined(__I386__)
625 method_uses_ecx = true;
627 goto icmd_lconst_tail;
629 if ((iptr[0].val.l == 0x00000002) ||
630 (iptr[0].val.l == 0x00000004) ||
631 (iptr[0].val.l == 0x00000008) ||
632 (iptr[0].val.l == 0x00000010) ||
633 (iptr[0].val.l == 0x00000020) ||
634 (iptr[0].val.l == 0x00000040) ||
635 (iptr[0].val.l == 0x00000080) ||
636 (iptr[0].val.l == 0x00000100) ||
637 (iptr[0].val.l == 0x00000200) ||
638 (iptr[0].val.l == 0x00000400) ||
639 (iptr[0].val.l == 0x00000800) ||
640 (iptr[0].val.l == 0x00001000) ||
641 (iptr[0].val.l == 0x00002000) ||
642 (iptr[0].val.l == 0x00004000) ||
643 (iptr[0].val.l == 0x00008000) ||
644 (iptr[0].val.l == 0x00010000) ||
645 (iptr[0].val.l == 0x00020000) ||
646 (iptr[0].val.l == 0x00040000) ||
647 (iptr[0].val.l == 0x00080000) ||
648 (iptr[0].val.l == 0x00100000) ||
649 (iptr[0].val.l == 0x00200000) ||
650 (iptr[0].val.l == 0x00400000) ||
651 (iptr[0].val.l == 0x00800000) ||
652 (iptr[0].val.l == 0x01000000) ||
653 (iptr[0].val.l == 0x02000000) ||
654 (iptr[0].val.l == 0x04000000) ||
655 (iptr[0].val.l == 0x08000000) ||
656 (iptr[0].val.l == 0x10000000) ||
657 (iptr[0].val.l == 0x20000000) ||
658 (iptr[0].val.l == 0x40000000) ||
659 (iptr[0].val.l == 0x80000000)) {
660 iptr[0].opc = ICMD_LREMPOW2;
662 #if defined(__I386__)
663 method_uses_ecx = true;
665 goto icmd_lconst_tail;
672 iptr[0].opc = ICMD_LANDCONST;
673 goto icmd_lconst_tail;
675 iptr[0].opc = ICMD_LORCONST;
676 goto icmd_lconst_tail;
678 iptr[0].opc = ICMD_LXORCONST;
679 goto icmd_lconst_tail;
681 #if !defined(NOLONG_CONDITIONAL)
683 if ((len > 1) && (iptr[2].val.i == 0)) {
684 switch (iptr[2].opc) {
686 iptr[0].opc = ICMD_IF_LEQ;
687 #if defined(__I386__)
688 method_uses_ecx = true;
690 icmd_lconst_lcmp_tail:
691 iptr[0].op1 = iptr[2].op1;
694 /* iptr[1].opc = ICMD_NOP;
695 iptr[2].opc = ICMD_NOP; */
697 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
699 iptr[0].target = (void *) tbptr;
701 MARKREACHED(tbptr, copy);
702 COUNT(count_pcmd_bra);
703 COUNT(count_pcmd_op);
706 iptr[0].opc = ICMD_IF_LNE;
707 #if defined(__I386__)
708 method_uses_ecx = true;
710 goto icmd_lconst_lcmp_tail;
712 iptr[0].opc = ICMD_IF_LLT;
713 goto icmd_lconst_lcmp_tail;
715 iptr[0].opc = ICMD_IF_LGT;
716 goto icmd_lconst_lcmp_tail;
718 iptr[0].opc = ICMD_IF_LLE;
719 goto icmd_lconst_lcmp_tail;
721 iptr[0].opc = ICMD_IF_LGE;
722 goto icmd_lconst_lcmp_tail;
725 } /* switch (iptr[2].opc) */
726 } /* if (iptr[2].val.i == 0) */
732 #if SUPPORT_CONST_ASTORE
734 #if SUPPORT_ONLY_ZERO_ASTORE
735 if (iptr[0].val.l == 0) {
736 #endif /* SUPPORT_ONLY_ZERO_ASTORE */
737 iptr[0].opc = ICMD_LASTORECONST;
738 iptr[1].opc = ICMD_NOP;
739 OPTT2_0(TYPE_INT, TYPE_ADR);
740 COUNT(count_pcmd_op);
741 #if SUPPORT_ONLY_ZERO_ASTORE
744 #endif /* SUPPORT_ONLY_ZERO_ASTORE */
746 #endif /* SUPPORT_CONST_ASTORE */
757 COUNT(count_pcmd_load);
762 COUNT(count_pcmd_load);
767 COUNT(count_pcmd_load);
768 #if SUPPORT_CONST_ASTORE
769 if (len > 0 && iptr->val.a == 0) {
770 if (iptr[1].opc == ICMD_BUILTIN3 &&
771 iptr[1].val.a == BUILTIN_aastore) {
772 iptr[0].opc = ICMD_AASTORECONST;
773 iptr[1].opc = ICMD_NOP;
774 OPTT2_0(TYPE_INT, TYPE_ADR);
775 COUNT(count_pcmd_op);
782 #endif /* SUPPORT_CONST_ASTORE */
786 /* pop 0 push 1 load */
793 COUNT(count_load_instruction);
794 i = opcode-ICMD_ILOAD;
795 iptr->op1 = argren[iptr->op1];
796 m->registerdata->locals[iptr->op1][i].type = i;
797 LOAD(i, LOCALVAR, iptr->op1);
803 #if defined(__I386__)
804 method_uses_ecx = true;
805 method_uses_edx = true;
811 COUNT(count_check_null);
812 COUNT(count_check_bound);
813 COUNT(count_pcmd_mem);
814 OP2IAT_1(opcode-ICMD_IALOAD);
815 #if defined(__I386__)
816 method_uses_ecx = true;
823 COUNT(count_check_null);
824 COUNT(count_check_bound);
825 COUNT(count_pcmd_mem);
827 #if defined(__I386__)
828 method_uses_ecx = true;
832 /* pop 0 push 0 iinc */
838 count_store_depth[10]++;
840 count_store_depth[i]++;
845 if ((copy->varkind == LOCALVAR) &&
846 (copy->varnum == iptr->op1)) {
847 copy->varkind = TEMPVAR;
856 /* pop 1 push 0 store */
866 i = opcode - ICMD_ISTORE;
867 m->registerdata->locals[iptr->op1][i].type = i;
872 count_store_length[20]++;
874 count_store_length[i]++;
877 count_store_depth[10]++;
879 count_store_depth[i]++;
881 copy = curstack->prev;
884 if ((copy->varkind == LOCALVAR) &&
885 (copy->varnum == iptr->op1)) {
886 copy->varkind = TEMPVAR;
892 if ((new - curstack) == 1) {
893 curstack->varkind = LOCALVAR;
894 curstack->varnum = iptr->op1;
896 STORE(opcode-ICMD_ISTORE);
904 #if defined(__I386__)
905 method_uses_ecx = true;
906 method_uses_edx = true;
910 COUNT(count_check_null);
911 COUNT(count_check_bound);
912 COUNT(count_pcmd_mem);
913 OP3TIA_0(opcode-ICMD_IASTORE);
919 COUNT(count_check_null);
920 COUNT(count_check_bound);
921 COUNT(count_pcmd_mem);
923 #if defined(__I386__)
924 method_uses_ecx = true;
925 method_uses_edx = true;
932 #ifdef TYPECHECK_STACK_COMPCAT
935 if (IS_2_WORD_TYPE(curstack->type)) {
936 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
949 COUNT(count_pcmd_return);
950 OP1_0(opcode-ICMD_IRETURN);
951 superblockend = true;
955 COUNT(count_check_null);
959 superblockend = true;
963 COUNT(count_pcmd_mem);
965 #if defined(__I386__)
966 method_uses_ecx = true;
970 /* pop 1 push 0 branch */
974 COUNT(count_pcmd_bra);
976 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
978 iptr[0].target = (void *) tbptr;
980 MARKREACHED(tbptr, copy);
989 COUNT(count_pcmd_bra);
990 #ifdef CONDITIONAL_LOADCONST
992 tbptr = m->basicblocks + b_index;
993 if ((b_count >= 3) &&
994 ((b_index + 2) == m->basicblockindex[iptr[0].op1]) &&
995 (tbptr[1].pre_count == 1) &&
996 (iptr[1].opc == ICMD_ICONST) &&
997 (iptr[2].opc == ICMD_GOTO) &&
998 ((b_index + 3) == m->basicblockindex[iptr[2].op1]) &&
999 (tbptr[2].pre_count == 1) &&
1000 (iptr[3].opc == ICMD_ICONST)) {
1001 OP1_1(TYPE_INT, TYPE_INT);
1002 switch (iptr[0].opc) {
1004 iptr[0].opc = ICMD_IFNE_ICONST;
1007 iptr[0].opc = ICMD_IFEQ_ICONST;
1010 iptr[0].opc = ICMD_IFGE_ICONST;
1013 iptr[0].opc = ICMD_IFLT_ICONST;
1016 iptr[0].opc = ICMD_IFLE_ICONST;
1019 iptr[0].opc = ICMD_IFGT_ICONST;
1022 iptr[0].val.i = iptr[1].val.i;
1023 iptr[1].opc = ICMD_ELSE_ICONST;
1024 iptr[1].val.i = iptr[3].val.i;
1025 iptr[2].opc = ICMD_NOP;
1026 iptr[3].opc = ICMD_NOP;
1027 tbptr[1].flags = BBDELETED;
1028 tbptr[2].flags = BBDELETED;
1029 tbptr[1].icount = 0;
1030 tbptr[2].icount = 0;
1031 if (tbptr[3].pre_count == 2) {
1032 len += tbptr[3].icount + 3;
1033 bptr->icount += tbptr[3].icount + 3;
1034 tbptr[3].flags = BBDELETED;
1035 tbptr[3].icount = 0;
1048 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1050 iptr[0].target = (void *) tbptr;
1052 MARKREACHED(tbptr, copy);
1055 /* pop 0 push 0 branch */
1058 COUNT(count_pcmd_bra);
1059 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1061 iptr[0].target = (void *) tbptr;
1063 MARKREACHED(tbptr, copy);
1065 superblockend = true;
1068 /* pop 1 push 0 table branch */
1070 case ICMD_TABLESWITCH:
1071 COUNT(count_pcmd_table);
1073 s4ptr = iptr->val.a;
1074 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
1075 MARKREACHED(tbptr, copy);
1076 i = *s4ptr++; /* low */
1077 i = *s4ptr++ - i + 1; /* high */
1079 tptr = DMNEW(void*, i+1);
1080 iptr->target = (void *) tptr;
1082 tptr[0] = (void *) tbptr;
1086 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
1088 tptr[0] = (void *) tbptr;
1091 MARKREACHED(tbptr, copy);
1094 superblockend = true;
1095 #if defined(__I386__)
1096 method_uses_ecx = true;
1100 /* pop 1 push 0 table branch */
1102 case ICMD_LOOKUPSWITCH:
1103 COUNT(count_pcmd_table);
1105 s4ptr = iptr->val.a;
1106 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
1107 MARKREACHED(tbptr, copy);
1108 i = *s4ptr++; /* count */
1110 tptr = DMNEW(void*, i+1);
1111 iptr->target = (void *) tptr;
1113 tptr[0] = (void *) tbptr;
1117 tbptr = m->basicblocks + m->basicblockindex[s4ptr[1]];
1119 tptr[0] = (void *) tbptr;
1122 MARKREACHED(tbptr, copy);
1126 superblockend = true;
1129 case ICMD_NULLCHECKPOP:
1130 case ICMD_MONITORENTER:
1131 COUNT(count_check_null);
1132 case ICMD_MONITOREXIT:
1136 /* pop 2 push 0 branch */
1138 case ICMD_IF_ICMPEQ:
1139 case ICMD_IF_ICMPNE:
1140 case ICMD_IF_ICMPLT:
1141 case ICMD_IF_ICMPGE:
1142 case ICMD_IF_ICMPGT:
1143 case ICMD_IF_ICMPLE:
1144 COUNT(count_pcmd_bra);
1146 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1148 iptr[0].target = (void *) tbptr;
1150 MARKREACHED(tbptr, copy);
1153 case ICMD_IF_ACMPEQ:
1154 case ICMD_IF_ACMPNE:
1155 COUNT(count_pcmd_bra);
1157 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1159 iptr[0].target = (void *) tbptr;
1161 MARKREACHED(tbptr, copy);
1167 COUNT(count_check_null);
1168 COUNT(count_pcmd_mem);
1169 OPTT2_0(iptr->op1,TYPE_ADR);
1170 #if defined(__I386__)
1171 method_uses_ecx = true;
1177 if (!IS_2_WORD_TYPE(curstack->type)) {
1179 #ifdef TYPECHECK_STACK_COMPCAT
1182 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1183 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1188 OP1_0ANY; /* second pop */
1191 iptr->opc = ICMD_POP;
1195 /* pop 0 push 1 dup */
1198 #ifdef TYPECHECK_STACK_COMPCAT
1201 if (IS_2_WORD_TYPE(curstack->type)) {
1202 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1207 COUNT(count_dup_instruction);
1213 if (IS_2_WORD_TYPE(curstack->type)) {
1215 iptr->opc = ICMD_DUP;
1220 /* ..., ????, cat1 */
1221 #ifdef TYPECHECK_STACK_COMPCAT
1223 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1224 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1230 NEWSTACK(copy->prev->type, copy->prev->varkind,
1231 copy->prev->varnum);
1232 NEWSTACK(copy->type, copy->varkind,
1239 /* pop 2 push 3 dup */
1242 #ifdef TYPECHECK_STACK_COMPCAT
1245 if (IS_2_WORD_TYPE(curstack->type) ||
1246 IS_2_WORD_TYPE(curstack->prev->type)) {
1247 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1257 if (IS_2_WORD_TYPE(curstack->type)) {
1258 /* ..., ????, cat2 */
1259 #ifdef TYPECHECK_STACK_COMPCAT
1261 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1262 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1267 iptr->opc = ICMD_DUP_X1;
1271 /* ..., ????, cat1 */
1272 #ifdef TYPECHECK_STACK_COMPCAT
1275 if (IS_2_WORD_TYPE(curstack->prev->type)
1276 || IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1277 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1286 /* pop 3 push 4 dup */
1290 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1291 /* ..., cat2, ???? */
1292 #ifdef TYPECHECK_STACK_COMPCAT
1294 if (IS_2_WORD_TYPE(curstack->type)) {
1295 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1300 iptr->opc = ICMD_DUP_X1;
1304 /* ..., cat1, ???? */
1305 #ifdef TYPECHECK_STACK_COMPCAT
1308 if (IS_2_WORD_TYPE(curstack->type)
1309 || IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1310 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1321 if (IS_2_WORD_TYPE(curstack->type)) {
1322 /* ..., ????, cat2 */
1323 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1324 /* ..., cat2, cat2 */
1325 iptr->opc = ICMD_DUP_X1;
1329 /* ..., cat1, cat2 */
1330 #ifdef TYPECHECK_STACK_COMPCAT
1333 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1334 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1339 iptr->opc = ICMD_DUP_X2;
1345 /* ..., ????, ????, cat1 */
1346 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1347 /* ..., cat2, ????, cat1 */
1348 #ifdef TYPECHECK_STACK_COMPCAT
1350 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1351 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1356 iptr->opc = ICMD_DUP2_X1;
1360 /* ..., cat1, ????, cat1 */
1361 #ifdef TYPECHECK_STACK_COMPCAT
1364 if (IS_2_WORD_TYPE(curstack->prev->type)
1365 || IS_2_WORD_TYPE(curstack->prev->prev->prev->type)) {
1366 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1376 /* pop 2 push 2 swap */
1379 #ifdef TYPECHECK_STACK_COMPCAT
1382 if (IS_2_WORD_TYPE(curstack->type)
1383 || IS_2_WORD_TYPE(curstack->prev->type)) {
1384 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1395 #if !SUPPORT_DIVISION
1396 iptr[0].opc = ICMD_BUILTIN2;
1397 iptr[0].op1 = TYPE_INT;
1398 iptr[0].val.a = BUILTIN_idiv;
1399 m->isleafmethod = false;
1404 #if !SUPPORT_DIVISION
1405 iptr[0].opc = ICMD_BUILTIN2;
1406 iptr[0].op1 = TYPE_INT;
1407 iptr[0].val.a = BUILTIN_irem;
1408 m->isleafmethod = false;
1411 #if defined(__I386__)
1412 method_uses_ecx = true;
1413 method_uses_edx = true;
1419 #if defined(__I386__)
1420 method_uses_ecx = true;
1428 COUNT(count_pcmd_op);
1433 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1434 iptr[0].opc = ICMD_BUILTIN2;
1435 iptr[0].op1 = TYPE_LNG;
1436 iptr[0].val.a = BUILTIN_ldiv;
1437 m->isleafmethod = false;
1442 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1443 iptr[0].opc = ICMD_BUILTIN2;
1444 iptr[0].op1 = TYPE_LNG;
1445 iptr[0].val.a = BUILTIN_lrem;
1446 m->isleafmethod = false;
1451 #if defined(__I386__)
1452 method_uses_ecx = true;
1453 method_uses_edx = true;
1460 /* DEBUG */ /*dolog("OP2_1(TYPE_LNG)"); */
1461 COUNT(count_pcmd_op);
1468 COUNT(count_pcmd_op);
1470 #if defined(__I386__)
1471 method_uses_ecx = true;
1472 method_uses_edx = true;
1481 COUNT(count_pcmd_op);
1490 COUNT(count_pcmd_op);
1495 COUNT(count_pcmd_op);
1496 #if !defined(NOLONG_CONDITIONAL)
1497 if ((len > 0) && (iptr[1].val.i == 0)) {
1498 switch (iptr[1].opc) {
1500 iptr[0].opc = ICMD_IF_LCMPEQ;
1501 #if defined(__I386__)
1502 method_uses_ecx = true;
1505 iptr[0].op1 = iptr[1].op1;
1508 /* iptr[1].opc = ICMD_NOP; */
1510 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1512 iptr[0].target = (void *) tbptr;
1514 MARKREACHED(tbptr, copy);
1515 COUNT(count_pcmd_bra);
1518 iptr[0].opc = ICMD_IF_LCMPNE;
1519 #if defined(__I386__)
1520 method_uses_ecx = true;
1522 goto icmd_lcmp_if_tail;
1524 iptr[0].opc = ICMD_IF_LCMPLT;
1525 goto icmd_lcmp_if_tail;
1527 iptr[0].opc = ICMD_IF_LCMPGT;
1528 goto icmd_lcmp_if_tail;
1530 iptr[0].opc = ICMD_IF_LCMPLE;
1531 goto icmd_lcmp_if_tail;
1533 iptr[0].opc = ICMD_IF_LCMPGE;
1534 goto icmd_lcmp_if_tail;
1536 OPTT2_1(TYPE_LNG, TYPE_INT);
1541 OPTT2_1(TYPE_LNG, TYPE_INT);
1545 COUNT(count_pcmd_op);
1546 OPTT2_1(TYPE_FLT, TYPE_INT);
1550 COUNT(count_pcmd_op);
1551 OPTT2_1(TYPE_DBL, TYPE_INT);
1559 case ICMD_INT2SHORT:
1560 COUNT(count_pcmd_op);
1561 OP1_1(TYPE_INT, TYPE_INT);
1564 COUNT(count_pcmd_op);
1565 OP1_1(TYPE_LNG, TYPE_LNG);
1568 COUNT(count_pcmd_op);
1569 OP1_1(TYPE_FLT, TYPE_FLT);
1572 COUNT(count_pcmd_op);
1573 OP1_1(TYPE_DBL, TYPE_DBL);
1577 COUNT(count_pcmd_op);
1578 OP1_1(TYPE_INT, TYPE_LNG);
1579 #if defined(__I386__)
1580 method_uses_edx = true;
1584 COUNT(count_pcmd_op);
1585 OP1_1(TYPE_INT, TYPE_FLT);
1588 COUNT(count_pcmd_op);
1589 OP1_1(TYPE_INT, TYPE_DBL);
1592 COUNT(count_pcmd_op);
1593 OP1_1(TYPE_LNG, TYPE_INT);
1596 COUNT(count_pcmd_op);
1597 OP1_1(TYPE_LNG, TYPE_FLT);
1600 COUNT(count_pcmd_op);
1601 OP1_1(TYPE_LNG, TYPE_DBL);
1604 COUNT(count_pcmd_op);
1605 OP1_1(TYPE_FLT, TYPE_INT);
1608 COUNT(count_pcmd_op);
1609 OP1_1(TYPE_FLT, TYPE_LNG);
1610 #if defined(__I386__)
1611 method_uses_edx = true;
1615 COUNT(count_pcmd_op);
1616 OP1_1(TYPE_FLT, TYPE_DBL);
1619 COUNT(count_pcmd_op);
1620 OP1_1(TYPE_DBL, TYPE_INT);
1623 COUNT(count_pcmd_op);
1624 OP1_1(TYPE_DBL, TYPE_LNG);
1625 #if defined(__I386__)
1626 method_uses_edx = true;
1630 COUNT(count_pcmd_op);
1631 OP1_1(TYPE_DBL, TYPE_FLT);
1634 case ICMD_CHECKCAST:
1635 OP1_1(TYPE_ADR, TYPE_ADR);
1636 #if defined(__I386__)
1637 method_uses_ecx = true;
1638 method_uses_edx = true;
1642 case ICMD_INSTANCEOF:
1643 #if defined(__I386__)
1644 method_uses_ecx = true;
1645 method_uses_edx = true;
1647 case ICMD_ARRAYLENGTH:
1648 OP1_1(TYPE_ADR, TYPE_INT);
1652 case ICMD_ANEWARRAY:
1653 OP1_1(TYPE_INT, TYPE_ADR);
1657 COUNT(count_check_null);
1658 COUNT(count_pcmd_mem);
1659 OP1_1(TYPE_ADR, iptr->op1);
1660 #if defined(__I386__)
1661 method_uses_ecx = true;
1667 case ICMD_GETSTATIC:
1668 COUNT(count_pcmd_mem);
1670 #if defined(__I386__)
1671 method_uses_ecx = true;
1681 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1683 iptr[0].target = (void *) tbptr;
1685 /* This is a dirty hack. The typechecker
1686 * needs it because the OP1_0ANY below
1687 * overwrites iptr->dst.
1689 iptr->val.a = (void *) iptr->dst;
1691 tbptr->type = BBTYPE_SBR;
1693 /* We need to check for overflow right here because
1694 * the pushed value is poped after MARKREACHED. */
1696 MARKREACHED(tbptr, copy);
1700 /* pop many push any */
1702 case ICMD_INVOKEVIRTUAL:
1703 case ICMD_INVOKESPECIAL:
1704 case ICMD_INVOKEINTERFACE:
1705 case ICMD_INVOKESTATIC:
1706 COUNT(count_pcmd_met);
1707 #if defined(__I386__)
1708 method_uses_ecx = true;
1711 methodinfo *lm = iptr->val.a;
1712 if (lm->flags & ACC_STATIC)
1713 {COUNT(count_check_null);}
1715 if (i > m->registerdata->arguments_num)
1716 m->registerdata->arguments_num = i;
1718 #if defined(__X86_64__)
1726 (IS_FLT_DBL_TYPE(copy->type)) ? farg++ : iarg++;
1730 stackargs += (iarg < m->registerdata->intreg_argnum) ?
1731 0 : (iarg - m->registerdata->intreg_argnum);
1732 stackargs += (farg < m->registerdata->fltreg_argnum) ?
1733 0 : (farg - m->registerdata->fltreg_argnum);
1738 if (!(copy->flags & SAVEDVAR)) {
1739 copy->varkind = ARGVAR;
1740 if (IS_FLT_DBL_TYPE(copy->type)) {
1741 if (--farg < m->registerdata->fltreg_argnum) {
1742 copy->varnum = farg;
1744 copy->varnum = --stackargs + m->registerdata->intreg_argnum;
1747 if (--iarg < m->registerdata->intreg_argnum) {
1748 copy->varnum = iarg;
1750 copy->varnum = --stackargs + m->registerdata->intreg_argnum;
1754 (IS_FLT_DBL_TYPE(copy->type)) ? --farg : --iarg;
1762 if (! (copy->flags & SAVEDVAR)) {
1763 copy->varkind = ARGVAR;
1770 copy->flags |= SAVEDVAR;
1775 if (lm->returntype != TYPE_VOID) {
1776 OP0_1(lm->returntype);
1782 /* DEBUG */ /*dolog("builtin3");*/
1784 if (! (curstack->flags & SAVEDVAR)) {
1785 curstack->varkind = ARGVAR;
1786 curstack->varnum = 2;
1788 if (3 > m->registerdata->arguments_num) {
1789 m->registerdata->arguments_num = 3;
1796 /* DEBUG */ /*dolog("builtin2");*/
1797 if (!(curstack->flags & SAVEDVAR)) {
1798 curstack->varkind = ARGVAR;
1799 curstack->varnum = 1;
1801 if (2 > m->registerdata->arguments_num) {
1802 m->registerdata->arguments_num = 2;
1809 /* DEBUG */ /*dolog("builtin1");*/
1810 if (!(curstack->flags & SAVEDVAR)) {
1811 curstack->varkind = ARGVAR;
1812 curstack->varnum = 0;
1814 if (1 > m->registerdata->arguments_num) {
1815 m->registerdata->arguments_num = 1;
1820 copy->flags |= SAVEDVAR;
1823 if (iptr->op1 != TYPE_VOID)
1827 case ICMD_MULTIANEWARRAY:
1830 if ((i + m->registerdata->intreg_argnum) > m->registerdata->arguments_num)
1831 m->registerdata->arguments_num = i + m->registerdata->intreg_argnum;
1834 /* check INT type here? Currently typecheck does this. */
1835 if (! (copy->flags & SAVEDVAR)) {
1836 copy->varkind = ARGVAR;
1837 copy->varnum = i + m->registerdata->intreg_argnum;
1842 copy->flags |= SAVEDVAR;
1850 case ICMD_CLEAR_ARGREN:
1851 for (i = iptr->op1; i<m->maxlocals; i++)
1853 iptr->opc = opcode = ICMD_NOP;
1857 case ICMD_READONLY_ARG:
1858 case ICMD_READONLY_ARG+1:
1859 case ICMD_READONLY_ARG+2:
1860 case ICMD_READONLY_ARG+3:
1861 case ICMD_READONLY_ARG+4:
1864 if (curstack->varkind == LOCALVAR) {
1865 i = curstack->varnum;
1866 argren[iptr->op1] = i;
1869 opcode = iptr->opc = opcode - ICMD_READONLY_ARG + ICMD_ISTORE;
1876 new_exception_message(string_java_lang_InternalError,
1883 } /* while instructions */
1885 bptr->outstack = curstack;
1886 bptr->outdepth = stackdepth;
1890 superblockend = true;
1892 } /* while blocks */
1893 } while (repeat && !deadcode);
1895 #if defined(STATISTICS)
1897 if (m->basicblockcount > count_max_basic_blocks)
1898 count_max_basic_blocks = m->basicblockcount;
1899 count_basic_blocks += m->basicblockcount;
1900 if (m->instructioncount > count_max_javainstr)
1901 count_max_javainstr = m->instructioncount;
1902 count_javainstr += m->instructioncount;
1903 if (m->stackcount > count_upper_bound_new_stack)
1904 count_upper_bound_new_stack = m->stackcount;
1905 if ((new - m->stack) > count_max_new_stack)
1906 count_max_new_stack = (new - m->stack);
1908 b_count = m->basicblockcount;
1909 bptr = m->basicblocks;
1910 while (--b_count >= 0) {
1911 if (bptr->flags > BBREACHED) {
1912 if (bptr->indepth >= 10)
1913 count_block_stack[10]++;
1915 count_block_stack[bptr->indepth]++;
1918 count_block_size_distribution[len]++;
1920 count_block_size_distribution[10]++;
1922 count_block_size_distribution[11]++;
1924 count_block_size_distribution[12]++;
1926 count_block_size_distribution[13]++;
1928 count_block_size_distribution[14]++;
1930 count_block_size_distribution[15]++;
1932 count_block_size_distribution[16]++;
1934 count_block_size_distribution[17]++;
1940 count_analyse_iterations[0]++;
1941 else if (loops == 2)
1942 count_analyse_iterations[1]++;
1943 else if (loops == 3)
1944 count_analyse_iterations[2]++;
1945 else if (loops == 4)
1946 count_analyse_iterations[3]++;
1948 count_analyse_iterations[4]++;
1950 if (m->basicblockcount <= 5)
1951 count_method_bb_distribution[0]++;
1952 else if (m->basicblockcount <= 10)
1953 count_method_bb_distribution[1]++;
1954 else if (m->basicblockcount <= 15)
1955 count_method_bb_distribution[2]++;
1956 else if (m->basicblockcount <= 20)
1957 count_method_bb_distribution[3]++;
1958 else if (m->basicblockcount <= 30)
1959 count_method_bb_distribution[4]++;
1960 else if (m->basicblockcount <= 40)
1961 count_method_bb_distribution[5]++;
1962 else if (m->basicblockcount <= 50)
1963 count_method_bb_distribution[6]++;
1964 else if (m->basicblockcount <= 75)
1965 count_method_bb_distribution[7]++;
1967 count_method_bb_distribution[8]++;
1971 /* just return methodinfo* to signal everything was ok */
1977 /**********************************************************************/
1978 /* DEBUGGING HELPERS */
1979 /**********************************************************************/
1981 void icmd_print_stack(methodinfo *m, stackptr s)
1993 j = m->maxstack - i;
1998 /* DEBUG */ /*printf("(%d,%d,%d,%d)",s->varkind,s->flags,s->regoff,s->varnum); fflush(stdout);*/
1999 if (s->flags & SAVEDVAR)
2000 switch (s->varkind) {
2002 if (s->flags & INMEMORY)
2003 printf(" M%02d", s->regoff);
2004 else if ((s->type == TYPE_FLT) || (s->type == TYPE_DBL))
2005 printf(" F%02d", s->regoff);
2007 printf(" %3s", regs[s->regoff]);
2011 printf(" I%02d", s->varnum);
2014 printf(" L%02d", s->varnum);
2017 printf(" A%02d", s->varnum);
2020 printf(" !%02d", j);
2023 switch (s->varkind) {
2025 if (s->flags & INMEMORY)
2026 printf(" m%02d", s->regoff);
2027 else if ((s->type == TYPE_FLT) || (s->type == TYPE_DBL))
2028 printf(" f%02d", s->regoff);
2030 printf(" %3s", regs[s->regoff]);
2034 printf(" i%02d", s->varnum);
2037 printf(" l%02d", s->varnum);
2040 printf(" a%02d", s->varnum);
2043 printf(" ?%02d", j);
2051 static void print_reg(stackptr s) {
2053 if (s->flags & SAVEDVAR)
2054 switch (s->varkind) {
2056 if (s->flags & INMEMORY)
2057 printf(" tm%02d", s->regoff);
2059 printf(" tr%02d", s->regoff);
2062 printf(" s %02d", s->varnum);
2065 printf(" l %02d", s->varnum);
2068 printf(" a %02d", s->varnum);
2071 printf(" ! %02d", s->varnum);
2074 switch (s->varkind) {
2076 if (s->flags & INMEMORY)
2077 printf(" Tm%02d", s->regoff);
2079 printf(" Tr%02d", s->regoff);
2082 printf(" S %02d", s->varnum);
2085 printf(" L %02d", s->varnum);
2088 printf(" A %02d", s->varnum);
2091 printf(" ? %02d", s->varnum);
2101 char *icmd_builtin_name(functionptr bptr)
2103 builtin_descriptor *bdesc = builtin_desc;
2104 while ((bdesc->opcode != 0) && (bdesc->builtin != bptr))
2106 return (bdesc->opcode) ? bdesc->name : "<NOT IN TABLE>";
2110 static char *jit_type[] = {
2119 void show_icmd_method(methodinfo *m)
2126 utf_fprint_classname(stdout, m->class->name);
2128 utf_fprint(stdout, m->name);
2129 utf_fprint_classname(stdout, m->descriptor);
2130 printf ("\n\nMax locals: %d\n", (int) m->maxlocals);
2131 printf ("Max stack: %d\n", (int) m->maxstack);
2133 printf ("Line number table length: %d\n", m->linenumbercount);
2135 printf ("Exceptions (Number: %d):\n", m->exceptiontablelength);
2136 for (ex = m->exceptiontable; ex != NULL; ex = ex->down) {
2137 printf(" L%03d ... ", ex->start->debug_nr );
2138 printf("L%03d = ", ex->end->debug_nr);
2139 printf("L%03d\n", ex->handler->debug_nr);
2142 printf ("Local Table:\n");
2143 for (i = 0; i < m->maxlocals; i++) {
2144 printf(" %3d: ", i);
2145 for (j = TYPE_INT; j <= TYPE_ADR; j++)
2146 if (m->registerdata->locals[i][j].type >= 0) {
2147 printf(" (%s) ", jit_type[j]);
2148 if (m->registerdata->locals[i][j].flags & INMEMORY)
2149 printf("m%2d", m->registerdata->locals[i][j].regoff);
2150 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2151 printf("f%02d", m->registerdata->locals[i][j].regoff);
2153 printf("%3s", regs[m->registerdata->locals[i][j].regoff]);
2160 printf ("Interface Table:\n");
2161 for (i = 0; i < m->maxstack; i++) {
2162 if ((m->registerdata->interfaces[i][0].type >= 0) ||
2163 (m->registerdata->interfaces[i][1].type >= 0) ||
2164 (m->registerdata->interfaces[i][2].type >= 0) ||
2165 (m->registerdata->interfaces[i][3].type >= 0) ||
2166 (m->registerdata->interfaces[i][4].type >= 0)) {
2167 printf(" %3d: ", i);
2168 for (j = TYPE_INT; j <= TYPE_ADR; j++)
2169 if (m->registerdata->interfaces[i][j].type >= 0) {
2170 printf(" (%s) ", jit_type[j]);
2171 if (m->registerdata->interfaces[i][j].flags & SAVEDVAR) {
2172 if (m->registerdata->interfaces[i][j].flags & INMEMORY)
2173 printf("M%2d", m->registerdata->interfaces[i][j].regoff);
2174 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2175 printf("F%02d", m->registerdata->interfaces[i][j].regoff);
2177 printf("%3s", regs[m->registerdata->interfaces[i][j].regoff]);
2181 if (m->registerdata->interfaces[i][j].flags & INMEMORY)
2182 printf("m%2d", m->registerdata->interfaces[i][j].regoff);
2183 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2184 printf("f%02d", m->registerdata->interfaces[i][j].regoff);
2186 printf("%3s", regs[m->registerdata->interfaces[i][j].regoff]);
2195 if (showdisassemble) {
2196 #if defined(__I386__) || defined(__X86_64__)
2200 u1ptr = m->mcode + m->codegendata->dseglen;
2201 for (i = 0; i < m->basicblocks[0].mpc; i++, u1ptr++) {
2202 a = disassinstr(u1ptr, i);
2210 s4ptr = (s4 *) (m->mcode + m->codegendata->dseglen);
2211 for (i = 0; i < m->basicblocks[0].mpc; i += 4, s4ptr++) {
2212 disassinstr(s4ptr, i);
2218 for (bptr = m->basicblocks; bptr != NULL; bptr = bptr->next) {
2219 show_icmd_block(m, bptr);
2224 void show_icmd_block(methodinfo *m, basicblock *bptr)
2230 if (bptr->flags != BBDELETED) {
2231 deadcode = bptr->flags <= BBREACHED;
2234 for (j = m->maxstack; j > 0; j--)
2237 icmd_print_stack(m, bptr->instack);
2238 printf("] L%03d(%d - %d) flags=%d:\n", bptr->debug_nr, bptr->icount, bptr->pre_count,bptr->flags);
2239 iptr = bptr->iinstr;
2241 for (i = 0; i < bptr->icount; i++, iptr++) {
2244 for (j = m->maxstack; j > 0; j--)
2248 icmd_print_stack(m, iptr->dst);
2249 printf("] %4d ", i);
2250 show_icmd(iptr, deadcode);
2254 if (showdisassemble && (!deadcode)) {
2255 #if defined(__I386__) || defined(__X86_64__)
2261 u1ptr = m->mcode + m->codegendata->dseglen + i;
2263 if (bptr->next != NULL) {
2264 for (; i < bptr->next->mpc; i++, u1ptr++) {
2265 a = disassinstr(u1ptr, i);
2272 for (; u1ptr < (u1 *) (m->mcode + m->mcodelength); i++, u1ptr++) {
2273 a = disassinstr(u1ptr, i);
2284 s4ptr = (s4 *) (m->mcode + m->codegendata->dseglen + i);
2286 if (bptr->next != NULL) {
2287 for (; i < bptr->next->mpc; i += 4, s4ptr++) {
2288 disassinstr(s4ptr, i);
2293 for (; s4ptr < (s4 *) (m->mcode + m->mcodelength); i += 4, s4ptr++) {
2294 disassinstr(s4ptr, i);
2304 void show_icmd(instruction *iptr, bool deadcode)
2310 printf("%s", icmd_names[iptr->opc]);
2312 switch (iptr->opc) {
2313 case ICMD_IADDCONST:
2314 case ICMD_ISUBCONST:
2315 case ICMD_IMULCONST:
2318 case ICMD_IANDCONST:
2320 case ICMD_IXORCONST:
2321 case ICMD_ISHLCONST:
2322 case ICMD_ISHRCONST:
2323 case ICMD_IUSHRCONST:
2324 case ICMD_LSHLCONST:
2325 case ICMD_LSHRCONST:
2326 case ICMD_LUSHRCONST:
2328 case ICMD_ELSE_ICONST:
2329 case ICMD_IFEQ_ICONST:
2330 case ICMD_IFNE_ICONST:
2331 case ICMD_IFLT_ICONST:
2332 case ICMD_IFGE_ICONST:
2333 case ICMD_IFGT_ICONST:
2334 case ICMD_IFLE_ICONST:
2335 case ICMD_IASTORECONST:
2336 case ICMD_BASTORECONST:
2337 case ICMD_CASTORECONST:
2338 case ICMD_SASTORECONST:
2339 printf(" %d", iptr->val.i);
2342 case ICMD_LADDCONST:
2343 case ICMD_LSUBCONST:
2344 case ICMD_LMULCONST:
2347 case ICMD_LANDCONST:
2349 case ICMD_LXORCONST:
2351 case ICMD_LASTORECONST:
2352 #if defined(__I386__)
2353 printf(" %lld", iptr->val.l);
2355 printf(" %ld", iptr->val.l);
2360 printf(" %f", iptr->val.f);
2364 printf(" %f", iptr->val.d);
2368 case ICMD_AASTORECONST:
2369 printf(" %p", iptr->val.a);
2374 printf(" %d,", ((fieldinfo *) iptr->val.a)->offset);
2375 case ICMD_PUTSTATIC:
2376 case ICMD_GETSTATIC:
2378 utf_fprint(stdout, ((fieldinfo *) iptr->val.a)->class->name);
2380 utf_fprint(stdout, ((fieldinfo *) iptr->val.a)->name);
2382 utf_fprint(stdout, ((fieldinfo *) iptr->val.a)->descriptor);
2387 printf(" %d + %d", iptr->op1, iptr->val.i);
2422 printf(" %d", iptr->op1);
2428 ((classinfo *) iptr->val.a)->name);
2432 switch (iptr->op1) {
2460 case ICMD_ANEWARRAY:
2464 ((classinfo *) iptr->val.a)->name);
2468 case ICMD_MULTIANEWARRAY:
2471 printf(" %d ",iptr->op1);
2472 vft = (vftbl_t *)iptr->val.a;
2474 utf_fprint(stdout,vft->class->name);
2480 case ICMD_CHECKCAST:
2481 case ICMD_INSTANCEOF:
2483 classinfo *c = iptr->val.a;
2484 if (c->flags & ACC_INTERFACE)
2485 printf(" (INTERFACE) ");
2487 printf(" (CLASS,%3d) ", c->vftbl->diffval);
2488 utf_fprint(stdout, c->name);
2495 printf(" %s", icmd_builtin_name((functionptr) iptr->val.a));
2498 case ICMD_INVOKEVIRTUAL:
2499 case ICMD_INVOKESPECIAL:
2500 case ICMD_INVOKESTATIC:
2501 case ICMD_INVOKEINTERFACE:
2504 ((methodinfo *) iptr->val.a)->class->name);
2507 ((methodinfo *) iptr->val.a)->name);
2516 if (deadcode || !iptr->target)
2517 printf("(%d) op1=%d", iptr->val.i, iptr->op1);
2519 printf("(%d) L%03d", iptr->val.i, ((basicblock *) iptr->target)->debug_nr);
2528 if (deadcode || !iptr->target)
2529 #if defined(__I386__) || defined(__POWERPC__)
2530 printf("(%lld) op1=%d", iptr->val.l, iptr->op1);
2532 printf("(%ld) op1=%d", iptr->val.l, iptr->op1);
2535 #if defined(__I386__) || defined(__POWERPC__)
2536 printf("(%lld) L%03d", iptr->val.l, ((basicblock *) iptr->target)->debug_nr);
2538 printf("(%ld) L%03d", iptr->val.l, ((basicblock *) iptr->target)->debug_nr);
2545 case ICMD_IFNONNULL:
2546 case ICMD_IF_ICMPEQ:
2547 case ICMD_IF_ICMPNE:
2548 case ICMD_IF_ICMPLT:
2549 case ICMD_IF_ICMPGE:
2550 case ICMD_IF_ICMPGT:
2551 case ICMD_IF_ICMPLE:
2552 case ICMD_IF_LCMPEQ:
2553 case ICMD_IF_LCMPNE:
2554 case ICMD_IF_LCMPLT:
2555 case ICMD_IF_LCMPGE:
2556 case ICMD_IF_LCMPGT:
2557 case ICMD_IF_LCMPLE:
2558 case ICMD_IF_ACMPEQ:
2559 case ICMD_IF_ACMPNE:
2560 if (deadcode || !iptr->target)
2561 printf(" op1=%d", iptr->op1);
2563 printf(" L%03d", ((basicblock *) iptr->target)->debug_nr);
2566 case ICMD_TABLESWITCH:
2567 s4ptr = (s4*)iptr->val.a;
2569 if (deadcode || !iptr->target) {
2570 printf(" %d;", *s4ptr);
2573 tptr = (void **) iptr->target;
2574 printf(" L%03d;", ((basicblock *) *tptr)->debug_nr);
2578 s4ptr++; /* skip default */
2579 j = *s4ptr++; /* low */
2580 j = *s4ptr++ - j; /* high */
2582 if (deadcode || !*tptr)
2583 printf(" %d", *s4ptr++);
2585 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2592 case ICMD_LOOKUPSWITCH:
2593 s4ptr = (s4*)iptr->val.a;
2595 if (deadcode || !iptr->target) {
2596 printf(" %d;", *s4ptr);
2599 tptr = (void **) iptr->target;
2600 printf(" L%03d;", ((basicblock *) *tptr)->debug_nr);
2603 s4ptr++; /* default */
2604 j = *s4ptr++; /* count */
2607 if (deadcode || !*tptr) {
2608 s4ptr++; /* skip value */
2609 printf(" %d",*s4ptr++);
2612 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2618 /* printf(" Line number: %d, method:",iptr->line); */
2619 /* utf_display(iptr->method->class->name); */
2621 /* utf_display(iptr->method->name); */
2626 * These are local overrides for various environment variables in Emacs.
2627 * Please do not remove this and leave it at the end of the file, where
2628 * Emacs will automagically detect them.
2629 * ---------------------------------------------------------------------
2632 * indent-tabs-mode: t