1 /* vm/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 1621 2004-11-30 13:06:55Z twisti $
41 #include "mm/memory.h"
42 #include "native/native.h"
43 #include "toolbox/logging.h"
44 #include "vm/global.h"
45 #include "vm/builtin.h"
46 #include "vm/options.h"
47 #include "vm/statistics.h"
48 #include "vm/tables.h"
49 #include "vm/jit/codegen.inc.h"
50 #include "vm/jit/jit.h"
51 #include "vm/jit/reg.h"
52 #include "vm/jit/stack.h"
55 /**********************************************************************/
57 /**********************************************************************/
59 /* analyse_stack uses the intermediate code created by parse.c to
60 * build a model of the JVM operand stack for the current method.
62 * The following checks are performed:
63 * - check for operand stack underflow (before each instruction)
64 * - check for operand stack overflow (after[1] each instruction)
65 * - check for matching stack depth at merging points
66 * - check for matching basic types[2] at merging points
67 * - check basic types for instruction input (except for BUILTIN*
68 * opcodes, INVOKE* opcodes and MULTIANEWARRAY)
70 * [1]) Checking this after the instruction should be ok. parse.c
71 * counts the number of required stack slots in such a way that it is
72 * only vital that we don't exceed `maxstack` at basic block
75 * [2]) 'basic types' means the distinction between INT, LONG, FLOAT,
76 * DOUBLE and ADDRESS types. Subtypes of INT and different ADDRESS
77 * types are not discerned.
80 methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
88 int opcode, i, len, loops;
89 int superblockend, repeat, deadcode;
97 argren = DMNEW(s4, cd->maxlocals); /* table for argument renaming */
98 for (i = 0; i < cd->maxlocals; i++)
101 rd->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 < cd->exceptiontablelength; i++) {
109 bptr = &m->basicblocks[m->basicblockindex[cd->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) {
212 show_icmd_method(m, cd, rd);
213 printf("Block: %d, required depth: %d, current depth: %d\n", bptr->debug_nr, bptr->indepth, stackdepth);
214 panic("Stack depth mismatch");
217 curstack = bptr->instack;
219 superblockend = false;
220 bptr->flags = BBFINISHED;
223 b_index = bptr - m->basicblocks;
228 /* dolog("p: %04d op: %s stack: %p", iptr - instr, icmd_names[opcode], curstack); */
230 #ifdef USEBUILTINTABLE
233 stdopdescriptor *breplace;
234 breplace = find_builtin(opcode);
236 if (breplace && opcode == breplace->opcode) {
237 iptr[0].opc = breplace->icmd;
238 iptr[0].op1 = breplace->type_d;
239 iptr[0].val.fp = breplace->builtin;
240 m->isleafmethod = false;
241 switch (breplace->icmd) {
249 builtin_descriptor *breplace;
250 breplace = find_builtin(opcode);
252 if (breplace && opcode == breplace->opcode) {
253 iptr[0].opc = breplace->icmd;
254 iptr[0].op1 = breplace->type_d;
255 iptr[0].val.fp = breplace->builtin;
256 m->isleafmethod = false;
257 switch (breplace->icmd) {
272 case ICMD_CHECKASIZE:
273 case ICMD_CHECKEXCEPTION:
275 case ICMD_IFEQ_ICONST:
276 case ICMD_IFNE_ICONST:
277 case ICMD_IFLT_ICONST:
278 case ICMD_IFGE_ICONST:
279 case ICMD_IFGT_ICONST:
280 case ICMD_IFLE_ICONST:
281 case ICMD_ELSE_ICONST:
286 rd->locals[iptr->op1][TYPE_ADR].type = TYPE_ADR;
288 COUNT(count_pcmd_return);
290 superblockend = true;
293 /* pop 0 push 1 const */
296 COUNT(count_pcmd_load);
298 switch (iptr[1].opc) {
300 iptr[0].opc = ICMD_IADDCONST;
302 iptr[1].opc = ICMD_NOP;
303 OP1_1(TYPE_INT,TYPE_INT);
304 COUNT(count_pcmd_op);
307 iptr[0].opc = ICMD_ISUBCONST;
308 goto icmd_iconst_tail;
310 iptr[0].opc = ICMD_IMULCONST;
311 goto icmd_iconst_tail;
313 if (iptr[0].val.i == 0x00000002)
315 else if (iptr[0].val.i == 0x00000004)
317 else if (iptr[0].val.i == 0x00000008)
319 else if (iptr[0].val.i == 0x00000010)
321 else if (iptr[0].val.i == 0x00000020)
323 else if (iptr[0].val.i == 0x00000040)
325 else if (iptr[0].val.i == 0x00000080)
327 else if (iptr[0].val.i == 0x00000100)
329 else if (iptr[0].val.i == 0x00000200)
331 else if (iptr[0].val.i == 0x00000400)
333 else if (iptr[0].val.i == 0x00000800)
335 else if (iptr[0].val.i == 0x00001000)
337 else if (iptr[0].val.i == 0x00002000)
339 else if (iptr[0].val.i == 0x00004000)
341 else if (iptr[0].val.i == 0x00008000)
343 else if (iptr[0].val.i == 0x00010000)
345 else if (iptr[0].val.i == 0x00020000)
347 else if (iptr[0].val.i == 0x00040000)
349 else if (iptr[0].val.i == 0x00080000)
351 else if (iptr[0].val.i == 0x00100000)
353 else if (iptr[0].val.i == 0x00200000)
355 else if (iptr[0].val.i == 0x00400000)
357 else if (iptr[0].val.i == 0x00800000)
359 else if (iptr[0].val.i == 0x01000000)
361 else if (iptr[0].val.i == 0x02000000)
363 else if (iptr[0].val.i == 0x04000000)
365 else if (iptr[0].val.i == 0x08000000)
367 else if (iptr[0].val.i == 0x10000000)
369 else if (iptr[0].val.i == 0x20000000)
371 else if (iptr[0].val.i == 0x40000000)
373 else if (iptr[0].val.i == 0x80000000)
379 iptr[0].opc = ICMD_IDIVPOW2;
380 goto icmd_iconst_tail;
382 if ((iptr[0].val.i == 0x00000002) ||
383 (iptr[0].val.i == 0x00000004) ||
384 (iptr[0].val.i == 0x00000008) ||
385 (iptr[0].val.i == 0x00000010) ||
386 (iptr[0].val.i == 0x00000020) ||
387 (iptr[0].val.i == 0x00000040) ||
388 (iptr[0].val.i == 0x00000080) ||
389 (iptr[0].val.i == 0x00000100) ||
390 (iptr[0].val.i == 0x00000200) ||
391 (iptr[0].val.i == 0x00000400) ||
392 (iptr[0].val.i == 0x00000800) ||
393 (iptr[0].val.i == 0x00001000) ||
394 (iptr[0].val.i == 0x00002000) ||
395 (iptr[0].val.i == 0x00004000) ||
396 (iptr[0].val.i == 0x00008000) ||
397 (iptr[0].val.i == 0x00010000) ||
398 (iptr[0].val.i == 0x00020000) ||
399 (iptr[0].val.i == 0x00040000) ||
400 (iptr[0].val.i == 0x00080000) ||
401 (iptr[0].val.i == 0x00100000) ||
402 (iptr[0].val.i == 0x00200000) ||
403 (iptr[0].val.i == 0x00400000) ||
404 (iptr[0].val.i == 0x00800000) ||
405 (iptr[0].val.i == 0x01000000) ||
406 (iptr[0].val.i == 0x02000000) ||
407 (iptr[0].val.i == 0x04000000) ||
408 (iptr[0].val.i == 0x08000000) ||
409 (iptr[0].val.i == 0x10000000) ||
410 (iptr[0].val.i == 0x20000000) ||
411 (iptr[0].val.i == 0x40000000) ||
412 (iptr[0].val.i == 0x80000000)) {
413 iptr[0].opc = ICMD_IREMPOW2;
415 #if defined(__I386__)
416 method_uses_ecx = true;
418 goto icmd_iconst_tail;
423 iptr[0].opc = ICMD_IANDCONST;
424 goto icmd_iconst_tail;
426 iptr[0].opc = ICMD_IORCONST;
427 goto icmd_iconst_tail;
429 iptr[0].opc = ICMD_IXORCONST;
430 goto icmd_iconst_tail;
432 iptr[0].opc = ICMD_ISHLCONST;
433 goto icmd_iconst_tail;
435 iptr[0].opc = ICMD_ISHRCONST;
436 goto icmd_iconst_tail;
438 iptr[0].opc = ICMD_IUSHRCONST;
439 goto icmd_iconst_tail;
440 #if SUPPORT_LONG_SHIFT
442 iptr[0].opc = ICMD_LSHLCONST;
443 #if defined(__I386__)
444 method_uses_ecx = true;
446 goto icmd_lconst_tail;
448 iptr[0].opc = ICMD_LSHRCONST;
449 #if defined(__I386__)
450 method_uses_ecx = true;
452 goto icmd_lconst_tail;
454 iptr[0].opc = ICMD_LUSHRCONST;
455 #if defined(__I386__)
456 method_uses_ecx = true;
458 goto icmd_lconst_tail;
461 iptr[0].opc = ICMD_IFEQ;
463 iptr[0].op1 = iptr[1].op1;
466 /* iptr[1].opc = ICMD_NOP; */
468 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
470 iptr[0].target = (void *) tbptr;
472 MARKREACHED(tbptr, copy);
473 COUNT(count_pcmd_bra);
476 iptr[0].opc = ICMD_IFLT;
477 goto icmd_if_icmp_tail;
479 iptr[0].opc = ICMD_IFLE;
480 goto icmd_if_icmp_tail;
482 iptr[0].opc = ICMD_IFNE;
483 goto icmd_if_icmp_tail;
485 iptr[0].opc = ICMD_IFGT;
486 goto icmd_if_icmp_tail;
488 iptr[0].opc = ICMD_IFGE;
489 goto icmd_if_icmp_tail;
491 #if SUPPORT_CONST_ASTORE
496 #if SUPPORT_ONLY_ZERO_ASTORE
497 if (iptr[0].val.i == 0) {
498 #endif /* SUPPORT_ONLY_ZERO_ASTORE */
499 switch (iptr[1].opc) {
501 iptr[0].opc = ICMD_IASTORECONST;
504 iptr[0].opc = ICMD_BASTORECONST;
507 iptr[0].opc = ICMD_CASTORECONST;
510 iptr[0].opc = ICMD_SASTORECONST;
514 iptr[1].opc = ICMD_NOP;
515 OPTT2_0(TYPE_INT, TYPE_ADR);
516 COUNT(count_pcmd_op);
517 #if SUPPORT_ONLY_ZERO_ASTORE
520 #endif /* SUPPORT_ONLY_ZERO_ASTORE */
522 #endif /* SUPPORT_CONST_ASTORE */
533 COUNT(count_pcmd_load);
535 switch (iptr[1].opc) {
538 iptr[0].opc = ICMD_LADDCONST;
540 iptr[1].opc = ICMD_NOP;
541 OP1_1(TYPE_LNG,TYPE_LNG);
542 COUNT(count_pcmd_op);
545 iptr[0].opc = ICMD_LSUBCONST;
546 goto icmd_lconst_tail;
550 iptr[0].opc = ICMD_LMULCONST;
551 #if defined(__I386__)
552 method_uses_ecx = true;
553 method_uses_edx = true;
555 goto icmd_lconst_tail;
559 if (iptr[0].val.l == 0x00000002)
561 else if (iptr[0].val.l == 0x00000004)
563 else if (iptr[0].val.l == 0x00000008)
565 else if (iptr[0].val.l == 0x00000010)
567 else if (iptr[0].val.l == 0x00000020)
569 else if (iptr[0].val.l == 0x00000040)
571 else if (iptr[0].val.l == 0x00000080)
573 else if (iptr[0].val.l == 0x00000100)
575 else if (iptr[0].val.l == 0x00000200)
577 else if (iptr[0].val.l == 0x00000400)
579 else if (iptr[0].val.l == 0x00000800)
581 else if (iptr[0].val.l == 0x00001000)
583 else if (iptr[0].val.l == 0x00002000)
585 else if (iptr[0].val.l == 0x00004000)
587 else if (iptr[0].val.l == 0x00008000)
589 else if (iptr[0].val.l == 0x00010000)
591 else if (iptr[0].val.l == 0x00020000)
593 else if (iptr[0].val.l == 0x00040000)
595 else if (iptr[0].val.l == 0x00080000)
597 else if (iptr[0].val.l == 0x00100000)
599 else if (iptr[0].val.l == 0x00200000)
601 else if (iptr[0].val.l == 0x00400000)
603 else if (iptr[0].val.l == 0x00800000)
605 else if (iptr[0].val.l == 0x01000000)
607 else if (iptr[0].val.l == 0x02000000)
609 else if (iptr[0].val.l == 0x04000000)
611 else if (iptr[0].val.l == 0x08000000)
613 else if (iptr[0].val.l == 0x10000000)
615 else if (iptr[0].val.l == 0x20000000)
617 else if (iptr[0].val.l == 0x40000000)
619 else if (iptr[0].val.l == 0x80000000)
625 iptr[0].opc = ICMD_LDIVPOW2;
626 #if defined(__I386__)
627 method_uses_ecx = true;
629 goto icmd_lconst_tail;
631 if ((iptr[0].val.l == 0x00000002) ||
632 (iptr[0].val.l == 0x00000004) ||
633 (iptr[0].val.l == 0x00000008) ||
634 (iptr[0].val.l == 0x00000010) ||
635 (iptr[0].val.l == 0x00000020) ||
636 (iptr[0].val.l == 0x00000040) ||
637 (iptr[0].val.l == 0x00000080) ||
638 (iptr[0].val.l == 0x00000100) ||
639 (iptr[0].val.l == 0x00000200) ||
640 (iptr[0].val.l == 0x00000400) ||
641 (iptr[0].val.l == 0x00000800) ||
642 (iptr[0].val.l == 0x00001000) ||
643 (iptr[0].val.l == 0x00002000) ||
644 (iptr[0].val.l == 0x00004000) ||
645 (iptr[0].val.l == 0x00008000) ||
646 (iptr[0].val.l == 0x00010000) ||
647 (iptr[0].val.l == 0x00020000) ||
648 (iptr[0].val.l == 0x00040000) ||
649 (iptr[0].val.l == 0x00080000) ||
650 (iptr[0].val.l == 0x00100000) ||
651 (iptr[0].val.l == 0x00200000) ||
652 (iptr[0].val.l == 0x00400000) ||
653 (iptr[0].val.l == 0x00800000) ||
654 (iptr[0].val.l == 0x01000000) ||
655 (iptr[0].val.l == 0x02000000) ||
656 (iptr[0].val.l == 0x04000000) ||
657 (iptr[0].val.l == 0x08000000) ||
658 (iptr[0].val.l == 0x10000000) ||
659 (iptr[0].val.l == 0x20000000) ||
660 (iptr[0].val.l == 0x40000000) ||
661 (iptr[0].val.l == 0x80000000)) {
662 iptr[0].opc = ICMD_LREMPOW2;
664 #if defined(__I386__)
665 method_uses_ecx = true;
667 goto icmd_lconst_tail;
674 iptr[0].opc = ICMD_LANDCONST;
675 goto icmd_lconst_tail;
677 iptr[0].opc = ICMD_LORCONST;
678 goto icmd_lconst_tail;
680 iptr[0].opc = ICMD_LXORCONST;
681 goto icmd_lconst_tail;
683 #if !defined(NOLONG_CONDITIONAL)
685 if ((len > 1) && (iptr[2].val.i == 0)) {
686 switch (iptr[2].opc) {
688 iptr[0].opc = ICMD_IF_LEQ;
689 #if defined(__I386__)
690 method_uses_ecx = true;
692 icmd_lconst_lcmp_tail:
693 iptr[0].op1 = iptr[2].op1;
696 /* iptr[1].opc = ICMD_NOP;
697 iptr[2].opc = ICMD_NOP; */
699 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
701 iptr[0].target = (void *) tbptr;
703 MARKREACHED(tbptr, copy);
704 COUNT(count_pcmd_bra);
705 COUNT(count_pcmd_op);
708 iptr[0].opc = ICMD_IF_LNE;
709 #if defined(__I386__)
710 method_uses_ecx = true;
712 goto icmd_lconst_lcmp_tail;
714 iptr[0].opc = ICMD_IF_LLT;
715 goto icmd_lconst_lcmp_tail;
717 iptr[0].opc = ICMD_IF_LGT;
718 goto icmd_lconst_lcmp_tail;
720 iptr[0].opc = ICMD_IF_LLE;
721 goto icmd_lconst_lcmp_tail;
723 iptr[0].opc = ICMD_IF_LGE;
724 goto icmd_lconst_lcmp_tail;
727 } /* switch (iptr[2].opc) */
728 } /* if (iptr[2].val.i == 0) */
734 #if SUPPORT_CONST_ASTORE
736 #if SUPPORT_ONLY_ZERO_ASTORE
737 if (iptr[0].val.l == 0) {
738 #endif /* SUPPORT_ONLY_ZERO_ASTORE */
739 iptr[0].opc = ICMD_LASTORECONST;
740 iptr[1].opc = ICMD_NOP;
741 OPTT2_0(TYPE_INT, TYPE_ADR);
742 COUNT(count_pcmd_op);
743 #if SUPPORT_ONLY_ZERO_ASTORE
746 #endif /* SUPPORT_ONLY_ZERO_ASTORE */
748 #endif /* SUPPORT_CONST_ASTORE */
759 COUNT(count_pcmd_load);
764 COUNT(count_pcmd_load);
769 COUNT(count_pcmd_load);
770 #if SUPPORT_CONST_ASTORE
771 if (len > 0 && iptr->val.a == 0) {
772 if (iptr[1].opc == ICMD_BUILTIN3 &&
773 iptr[1].val.fp == BUILTIN_aastore) {
774 iptr[0].opc = ICMD_AASTORECONST;
775 iptr[1].opc = ICMD_NOP;
776 OPTT2_0(TYPE_INT, TYPE_ADR);
777 COUNT(count_pcmd_op);
784 #endif /* SUPPORT_CONST_ASTORE */
788 /* pop 0 push 1 load */
795 COUNT(count_load_instruction);
796 i = opcode-ICMD_ILOAD;
797 iptr->op1 = argren[iptr->op1];
798 rd->locals[iptr->op1][i].type = i;
799 LOAD(i, LOCALVAR, iptr->op1);
805 #if defined(__I386__)
806 method_uses_ecx = true;
807 method_uses_edx = true;
813 COUNT(count_check_null);
814 COUNT(count_check_bound);
815 COUNT(count_pcmd_mem);
816 OP2IAT_1(opcode-ICMD_IALOAD);
817 #if defined(__I386__)
818 method_uses_ecx = true;
825 COUNT(count_check_null);
826 COUNT(count_check_bound);
827 COUNT(count_pcmd_mem);
829 #if defined(__I386__)
830 method_uses_ecx = true;
834 /* pop 0 push 0 iinc */
840 count_store_depth[10]++;
842 count_store_depth[i]++;
847 if ((copy->varkind == LOCALVAR) &&
848 (copy->varnum == iptr->op1)) {
849 copy->varkind = TEMPVAR;
858 /* pop 1 push 0 store */
868 i = opcode - ICMD_ISTORE;
869 rd->locals[iptr->op1][i].type = i;
874 count_store_length[20]++;
876 count_store_length[i]++;
879 count_store_depth[10]++;
881 count_store_depth[i]++;
883 copy = curstack->prev;
886 if ((copy->varkind == LOCALVAR) &&
887 (copy->varnum == iptr->op1)) {
888 copy->varkind = TEMPVAR;
894 if ((new - curstack) == 1) {
895 curstack->varkind = LOCALVAR;
896 curstack->varnum = iptr->op1;
898 STORE(opcode-ICMD_ISTORE);
906 #if defined(__I386__)
907 method_uses_ecx = true;
908 method_uses_edx = true;
912 COUNT(count_check_null);
913 COUNT(count_check_bound);
914 COUNT(count_pcmd_mem);
915 OP3TIA_0(opcode-ICMD_IASTORE);
921 COUNT(count_check_null);
922 COUNT(count_check_bound);
923 COUNT(count_pcmd_mem);
925 #if defined(__I386__)
926 method_uses_ecx = true;
927 method_uses_edx = true;
934 #ifdef TYPECHECK_STACK_COMPCAT
937 if (IS_2_WORD_TYPE(curstack->type)) {
938 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
951 COUNT(count_pcmd_return);
952 OP1_0(opcode-ICMD_IRETURN);
953 superblockend = true;
957 COUNT(count_check_null);
961 superblockend = true;
965 COUNT(count_pcmd_mem);
967 #if defined(__I386__)
968 method_uses_ecx = true;
972 /* pop 1 push 0 branch */
976 COUNT(count_pcmd_bra);
978 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
980 iptr[0].target = (void *) tbptr;
982 MARKREACHED(tbptr, copy);
991 COUNT(count_pcmd_bra);
992 #ifdef CONDITIONAL_LOADCONST
994 tbptr = m->basicblocks + b_index;
995 if ((b_count >= 3) &&
996 ((b_index + 2) == m->basicblockindex[iptr[0].op1]) &&
997 (tbptr[1].pre_count == 1) &&
998 (iptr[1].opc == ICMD_ICONST) &&
999 (iptr[2].opc == ICMD_GOTO) &&
1000 ((b_index + 3) == m->basicblockindex[iptr[2].op1]) &&
1001 (tbptr[2].pre_count == 1) &&
1002 (iptr[3].opc == ICMD_ICONST)) {
1003 OP1_1(TYPE_INT, TYPE_INT);
1004 switch (iptr[0].opc) {
1006 iptr[0].opc = ICMD_IFNE_ICONST;
1009 iptr[0].opc = ICMD_IFEQ_ICONST;
1012 iptr[0].opc = ICMD_IFGE_ICONST;
1015 iptr[0].opc = ICMD_IFLT_ICONST;
1018 iptr[0].opc = ICMD_IFLE_ICONST;
1021 iptr[0].opc = ICMD_IFGT_ICONST;
1024 iptr[0].val.i = iptr[1].val.i;
1025 iptr[1].opc = ICMD_ELSE_ICONST;
1026 iptr[1].val.i = iptr[3].val.i;
1027 iptr[2].opc = ICMD_NOP;
1028 iptr[3].opc = ICMD_NOP;
1029 tbptr[1].flags = BBDELETED;
1030 tbptr[2].flags = BBDELETED;
1031 tbptr[1].icount = 0;
1032 tbptr[2].icount = 0;
1033 if (tbptr[3].pre_count == 2) {
1034 len += tbptr[3].icount + 3;
1035 bptr->icount += tbptr[3].icount + 3;
1036 tbptr[3].flags = BBDELETED;
1037 tbptr[3].icount = 0;
1050 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1052 iptr[0].target = (void *) tbptr;
1054 MARKREACHED(tbptr, copy);
1057 /* pop 0 push 0 branch */
1060 COUNT(count_pcmd_bra);
1061 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1063 iptr[0].target = (void *) tbptr;
1065 MARKREACHED(tbptr, copy);
1067 superblockend = true;
1070 /* pop 1 push 0 table branch */
1072 case ICMD_TABLESWITCH:
1073 COUNT(count_pcmd_table);
1075 s4ptr = iptr->val.a;
1076 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
1077 MARKREACHED(tbptr, copy);
1078 i = *s4ptr++; /* low */
1079 i = *s4ptr++ - i + 1; /* high */
1081 tptr = DMNEW(void*, i+1);
1082 iptr->target = (void *) tptr;
1084 tptr[0] = (void *) tbptr;
1088 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
1090 tptr[0] = (void *) tbptr;
1093 MARKREACHED(tbptr, copy);
1096 superblockend = true;
1097 #if defined(__I386__)
1098 method_uses_ecx = true;
1102 /* pop 1 push 0 table branch */
1104 case ICMD_LOOKUPSWITCH:
1105 COUNT(count_pcmd_table);
1107 s4ptr = iptr->val.a;
1108 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
1109 MARKREACHED(tbptr, copy);
1110 i = *s4ptr++; /* count */
1112 tptr = DMNEW(void*, i+1);
1113 iptr->target = (void *) tptr;
1115 tptr[0] = (void *) tbptr;
1119 tbptr = m->basicblocks + m->basicblockindex[s4ptr[1]];
1121 tptr[0] = (void *) tbptr;
1124 MARKREACHED(tbptr, copy);
1128 superblockend = true;
1131 case ICMD_NULLCHECKPOP:
1132 case ICMD_MONITORENTER:
1133 COUNT(count_check_null);
1134 case ICMD_MONITOREXIT:
1138 /* pop 2 push 0 branch */
1140 case ICMD_IF_ICMPEQ:
1141 case ICMD_IF_ICMPNE:
1142 case ICMD_IF_ICMPLT:
1143 case ICMD_IF_ICMPGE:
1144 case ICMD_IF_ICMPGT:
1145 case ICMD_IF_ICMPLE:
1146 COUNT(count_pcmd_bra);
1148 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1150 iptr[0].target = (void *) tbptr;
1152 MARKREACHED(tbptr, copy);
1155 case ICMD_IF_ACMPEQ:
1156 case ICMD_IF_ACMPNE:
1157 COUNT(count_pcmd_bra);
1159 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1161 iptr[0].target = (void *) tbptr;
1163 MARKREACHED(tbptr, copy);
1169 COUNT(count_check_null);
1170 COUNT(count_pcmd_mem);
1171 OPTT2_0(iptr->op1,TYPE_ADR);
1172 #if defined(__I386__)
1173 method_uses_ecx = true;
1179 if (!IS_2_WORD_TYPE(curstack->type)) {
1181 #ifdef TYPECHECK_STACK_COMPCAT
1184 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1185 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1190 OP1_0ANY; /* second pop */
1193 iptr->opc = ICMD_POP;
1197 /* pop 0 push 1 dup */
1200 #ifdef TYPECHECK_STACK_COMPCAT
1203 if (IS_2_WORD_TYPE(curstack->type)) {
1204 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1209 COUNT(count_dup_instruction);
1215 if (IS_2_WORD_TYPE(curstack->type)) {
1217 iptr->opc = ICMD_DUP;
1222 /* ..., ????, cat1 */
1223 #ifdef TYPECHECK_STACK_COMPCAT
1225 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1226 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1232 NEWSTACK(copy->prev->type, copy->prev->varkind,
1233 copy->prev->varnum);
1234 NEWSTACK(copy->type, copy->varkind,
1241 /* pop 2 push 3 dup */
1244 #ifdef TYPECHECK_STACK_COMPCAT
1247 if (IS_2_WORD_TYPE(curstack->type) ||
1248 IS_2_WORD_TYPE(curstack->prev->type)) {
1249 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1259 if (IS_2_WORD_TYPE(curstack->type)) {
1260 /* ..., ????, cat2 */
1261 #ifdef TYPECHECK_STACK_COMPCAT
1263 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1264 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1269 iptr->opc = ICMD_DUP_X1;
1273 /* ..., ????, cat1 */
1274 #ifdef TYPECHECK_STACK_COMPCAT
1277 if (IS_2_WORD_TYPE(curstack->prev->type)
1278 || IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1279 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1288 /* pop 3 push 4 dup */
1292 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1293 /* ..., cat2, ???? */
1294 #ifdef TYPECHECK_STACK_COMPCAT
1296 if (IS_2_WORD_TYPE(curstack->type)) {
1297 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1302 iptr->opc = ICMD_DUP_X1;
1306 /* ..., cat1, ???? */
1307 #ifdef TYPECHECK_STACK_COMPCAT
1310 if (IS_2_WORD_TYPE(curstack->type)
1311 || IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1312 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1323 if (IS_2_WORD_TYPE(curstack->type)) {
1324 /* ..., ????, cat2 */
1325 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1326 /* ..., cat2, cat2 */
1327 iptr->opc = ICMD_DUP_X1;
1331 /* ..., cat1, cat2 */
1332 #ifdef TYPECHECK_STACK_COMPCAT
1335 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1336 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1341 iptr->opc = ICMD_DUP_X2;
1347 /* ..., ????, ????, cat1 */
1348 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1349 /* ..., cat2, ????, cat1 */
1350 #ifdef TYPECHECK_STACK_COMPCAT
1352 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1353 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1358 iptr->opc = ICMD_DUP2_X1;
1362 /* ..., cat1, ????, cat1 */
1363 #ifdef TYPECHECK_STACK_COMPCAT
1366 if (IS_2_WORD_TYPE(curstack->prev->type)
1367 || IS_2_WORD_TYPE(curstack->prev->prev->prev->type)) {
1368 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1378 /* pop 2 push 2 swap */
1381 #ifdef TYPECHECK_STACK_COMPCAT
1384 if (IS_2_WORD_TYPE(curstack->type)
1385 || IS_2_WORD_TYPE(curstack->prev->type)) {
1386 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1397 #if !SUPPORT_DIVISION
1398 iptr[0].opc = ICMD_BUILTIN2;
1399 iptr[0].op1 = TYPE_INT;
1400 iptr[0].val.fp = BUILTIN_idiv;
1401 m->isleafmethod = false;
1406 #if !SUPPORT_DIVISION
1407 iptr[0].opc = ICMD_BUILTIN2;
1408 iptr[0].op1 = TYPE_INT;
1409 iptr[0].val.fp = BUILTIN_irem;
1410 m->isleafmethod = false;
1413 #if defined(__I386__)
1414 method_uses_ecx = true;
1415 method_uses_edx = true;
1421 #if defined(__I386__)
1422 method_uses_ecx = true;
1430 COUNT(count_pcmd_op);
1435 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1436 iptr[0].opc = ICMD_BUILTIN2;
1437 iptr[0].op1 = TYPE_LNG;
1438 iptr[0].val.fp = BUILTIN_ldiv;
1439 m->isleafmethod = false;
1444 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1445 iptr[0].opc = ICMD_BUILTIN2;
1446 iptr[0].op1 = TYPE_LNG;
1447 iptr[0].val.fp = BUILTIN_lrem;
1448 m->isleafmethod = false;
1453 #if defined(__I386__)
1454 method_uses_ecx = true;
1455 method_uses_edx = true;
1462 /* DEBUG */ /*dolog("OP2_1(TYPE_LNG)"); */
1463 COUNT(count_pcmd_op);
1470 COUNT(count_pcmd_op);
1472 #if defined(__I386__)
1473 method_uses_ecx = true;
1474 method_uses_edx = true;
1483 COUNT(count_pcmd_op);
1492 COUNT(count_pcmd_op);
1497 COUNT(count_pcmd_op);
1498 #if !defined(NOLONG_CONDITIONAL)
1499 if ((len > 0) && (iptr[1].val.i == 0)) {
1500 switch (iptr[1].opc) {
1502 iptr[0].opc = ICMD_IF_LCMPEQ;
1503 #if defined(__I386__)
1504 method_uses_ecx = true;
1507 iptr[0].op1 = iptr[1].op1;
1510 /* iptr[1].opc = ICMD_NOP; */
1512 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1514 iptr[0].target = (void *) tbptr;
1516 MARKREACHED(tbptr, copy);
1517 COUNT(count_pcmd_bra);
1520 iptr[0].opc = ICMD_IF_LCMPNE;
1521 #if defined(__I386__)
1522 method_uses_ecx = true;
1524 goto icmd_lcmp_if_tail;
1526 iptr[0].opc = ICMD_IF_LCMPLT;
1527 goto icmd_lcmp_if_tail;
1529 iptr[0].opc = ICMD_IF_LCMPGT;
1530 goto icmd_lcmp_if_tail;
1532 iptr[0].opc = ICMD_IF_LCMPLE;
1533 goto icmd_lcmp_if_tail;
1535 iptr[0].opc = ICMD_IF_LCMPGE;
1536 goto icmd_lcmp_if_tail;
1538 OPTT2_1(TYPE_LNG, TYPE_INT);
1543 OPTT2_1(TYPE_LNG, TYPE_INT);
1547 COUNT(count_pcmd_op);
1548 OPTT2_1(TYPE_FLT, TYPE_INT);
1552 COUNT(count_pcmd_op);
1553 OPTT2_1(TYPE_DBL, TYPE_INT);
1561 case ICMD_INT2SHORT:
1562 COUNT(count_pcmd_op);
1563 OP1_1(TYPE_INT, TYPE_INT);
1566 COUNT(count_pcmd_op);
1567 OP1_1(TYPE_LNG, TYPE_LNG);
1570 COUNT(count_pcmd_op);
1571 OP1_1(TYPE_FLT, TYPE_FLT);
1574 COUNT(count_pcmd_op);
1575 OP1_1(TYPE_DBL, TYPE_DBL);
1579 COUNT(count_pcmd_op);
1580 OP1_1(TYPE_INT, TYPE_LNG);
1581 #if defined(__I386__)
1582 method_uses_edx = true;
1586 COUNT(count_pcmd_op);
1587 OP1_1(TYPE_INT, TYPE_FLT);
1590 COUNT(count_pcmd_op);
1591 OP1_1(TYPE_INT, TYPE_DBL);
1594 COUNT(count_pcmd_op);
1595 OP1_1(TYPE_LNG, TYPE_INT);
1598 COUNT(count_pcmd_op);
1599 OP1_1(TYPE_LNG, TYPE_FLT);
1602 COUNT(count_pcmd_op);
1603 OP1_1(TYPE_LNG, TYPE_DBL);
1606 COUNT(count_pcmd_op);
1607 OP1_1(TYPE_FLT, TYPE_INT);
1610 COUNT(count_pcmd_op);
1611 OP1_1(TYPE_FLT, TYPE_LNG);
1612 #if defined(__I386__)
1613 method_uses_edx = true;
1617 COUNT(count_pcmd_op);
1618 OP1_1(TYPE_FLT, TYPE_DBL);
1621 COUNT(count_pcmd_op);
1622 OP1_1(TYPE_DBL, TYPE_INT);
1625 COUNT(count_pcmd_op);
1626 OP1_1(TYPE_DBL, TYPE_LNG);
1627 #if defined(__I386__)
1628 method_uses_edx = true;
1632 COUNT(count_pcmd_op);
1633 OP1_1(TYPE_DBL, TYPE_FLT);
1636 case ICMD_CHECKCAST:
1637 OP1_1(TYPE_ADR, TYPE_ADR);
1638 #if defined(__I386__)
1639 method_uses_ecx = true;
1640 method_uses_edx = true;
1644 case ICMD_INSTANCEOF:
1645 #if defined(__I386__)
1646 method_uses_ecx = true;
1647 method_uses_edx = true;
1649 case ICMD_ARRAYLENGTH:
1650 OP1_1(TYPE_ADR, TYPE_INT);
1654 case ICMD_ANEWARRAY:
1655 OP1_1(TYPE_INT, TYPE_ADR);
1659 COUNT(count_check_null);
1660 COUNT(count_pcmd_mem);
1661 OP1_1(TYPE_ADR, iptr->op1);
1662 #if defined(__I386__)
1663 method_uses_ecx = true;
1669 case ICMD_GETSTATIC:
1670 COUNT(count_pcmd_mem);
1672 #if defined(__I386__)
1673 method_uses_ecx = true;
1683 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1685 iptr[0].target = (void *) tbptr;
1687 /* This is a dirty hack. The typechecker
1688 * needs it because the OP1_0ANY below
1689 * overwrites iptr->dst.
1691 iptr->val.a = (void *) iptr->dst;
1693 tbptr->type = BBTYPE_SBR;
1695 /* We need to check for overflow right here because
1696 * the pushed value is poped after MARKREACHED. */
1698 MARKREACHED(tbptr, copy);
1702 /* pop many push any */
1704 case ICMD_INVOKEVIRTUAL:
1705 case ICMD_INVOKESPECIAL:
1706 case ICMD_INVOKEINTERFACE:
1707 case ICMD_INVOKESTATIC:
1708 COUNT(count_pcmd_met);
1709 #if defined(__I386__)
1710 method_uses_ecx = true;
1713 methodinfo *lm = iptr->val.a;
1714 if (lm->flags & ACC_STATIC)
1715 {COUNT(count_check_null);}
1717 if (i > rd->arguments_num)
1718 rd->arguments_num = i;
1720 #if defined(__X86_64__)
1728 (IS_FLT_DBL_TYPE(copy->type)) ? farg++ : iarg++;
1732 stackargs += (iarg < rd->intreg_argnum) ?
1733 0 : (iarg - rd->intreg_argnum);
1734 stackargs += (farg < rd->fltreg_argnum) ?
1735 0 : (farg - rd->fltreg_argnum);
1740 if (!(copy->flags & SAVEDVAR)) {
1741 copy->varkind = ARGVAR;
1742 if (IS_FLT_DBL_TYPE(copy->type)) {
1743 if (--farg < rd->fltreg_argnum) {
1744 copy->varnum = farg;
1746 copy->varnum = --stackargs + rd->intreg_argnum;
1749 if (--iarg < rd->intreg_argnum) {
1750 copy->varnum = iarg;
1752 copy->varnum = --stackargs + rd->intreg_argnum;
1756 (IS_FLT_DBL_TYPE(copy->type)) ? --farg : --iarg;
1764 if (! (copy->flags & SAVEDVAR)) {
1765 copy->varkind = ARGVAR;
1772 copy->flags |= SAVEDVAR;
1777 if (lm->returntype != TYPE_VOID) {
1778 OP0_1(lm->returntype);
1782 case ICMD_INLINE_START:
1783 case ICMD_INLINE_END:
1788 /* DEBUG */ /*dolog("builtin3");*/
1790 if (! (curstack->flags & SAVEDVAR)) {
1791 curstack->varkind = ARGVAR;
1792 curstack->varnum = 2;
1794 if (3 > rd->arguments_num) {
1795 rd->arguments_num = 3;
1802 /* DEBUG */ /*dolog("builtin2");*/
1803 if (!(curstack->flags & SAVEDVAR)) {
1804 curstack->varkind = ARGVAR;
1805 curstack->varnum = 1;
1807 if (2 > rd->arguments_num) {
1808 rd->arguments_num = 2;
1815 /* DEBUG */ /*dolog("builtin1");*/
1816 if (!(curstack->flags & SAVEDVAR)) {
1817 curstack->varkind = ARGVAR;
1818 curstack->varnum = 0;
1820 if (1 > rd->arguments_num) {
1821 rd->arguments_num = 1;
1826 copy->flags |= SAVEDVAR;
1829 if (iptr->op1 != TYPE_VOID)
1833 case ICMD_MULTIANEWARRAY:
1836 if ((i + rd->intreg_argnum) > rd->arguments_num)
1837 rd->arguments_num = i + rd->intreg_argnum;
1840 /* check INT type here? Currently typecheck does this. */
1841 if (! (copy->flags & SAVEDVAR)) {
1842 copy->varkind = ARGVAR;
1843 copy->varnum = i + rd->intreg_argnum;
1848 copy->flags |= SAVEDVAR;
1856 case ICMD_CLEAR_ARGREN:
1857 for (i = iptr->op1; i < cd->maxlocals; i++)
1859 iptr->opc = opcode = ICMD_NOP;
1863 case ICMD_READONLY_ARG:
1864 case ICMD_READONLY_ARG+1:
1865 case ICMD_READONLY_ARG+2:
1866 case ICMD_READONLY_ARG+3:
1867 case ICMD_READONLY_ARG+4:
1870 if (curstack->varkind == LOCALVAR) {
1871 i = curstack->varnum;
1872 argren[iptr->op1] = i;
1875 opcode = iptr->opc = opcode - ICMD_READONLY_ARG + ICMD_ISTORE;
1882 new_exception_message(string_java_lang_InternalError,
1889 } /* while instructions */
1891 bptr->outstack = curstack;
1892 bptr->outdepth = stackdepth;
1896 superblockend = true;
1898 } /* while blocks */
1899 } while (repeat && !deadcode);
1901 #if defined(STATISTICS)
1903 if (m->basicblockcount > count_max_basic_blocks)
1904 count_max_basic_blocks = m->basicblockcount;
1905 count_basic_blocks += m->basicblockcount;
1906 if (m->instructioncount > count_max_javainstr) count_max_javainstr = m->instructioncount;
1907 count_javainstr += m->instructioncount;
1908 if (m->stackcount > count_upper_bound_new_stack)
1909 count_upper_bound_new_stack = m->stackcount;
1910 if ((new - m->stack) > count_max_new_stack)
1911 count_max_new_stack = (new - m->stack);
1913 b_count = m->basicblockcount;
1914 bptr = m->basicblocks;
1915 while (--b_count >= 0) {
1916 if (bptr->flags > BBREACHED) {
1917 if (bptr->indepth >= 10)
1918 count_block_stack[10]++;
1920 count_block_stack[bptr->indepth]++;
1923 count_block_size_distribution[len]++;
1925 count_block_size_distribution[10]++;
1927 count_block_size_distribution[11]++;
1929 count_block_size_distribution[12]++;
1931 count_block_size_distribution[13]++;
1933 count_block_size_distribution[14]++;
1935 count_block_size_distribution[15]++;
1937 count_block_size_distribution[16]++;
1939 count_block_size_distribution[17]++;
1945 count_analyse_iterations[0]++;
1946 else if (loops == 2)
1947 count_analyse_iterations[1]++;
1948 else if (loops == 3)
1949 count_analyse_iterations[2]++;
1950 else if (loops == 4)
1951 count_analyse_iterations[3]++;
1953 count_analyse_iterations[4]++;
1955 if (m->basicblockcount <= 5)
1956 count_method_bb_distribution[0]++;
1957 else if (m->basicblockcount <= 10)
1958 count_method_bb_distribution[1]++;
1959 else if (m->basicblockcount <= 15)
1960 count_method_bb_distribution[2]++;
1961 else if (m->basicblockcount <= 20)
1962 count_method_bb_distribution[3]++;
1963 else if (m->basicblockcount <= 30)
1964 count_method_bb_distribution[4]++;
1965 else if (m->basicblockcount <= 40)
1966 count_method_bb_distribution[5]++;
1967 else if (m->basicblockcount <= 50)
1968 count_method_bb_distribution[6]++;
1969 else if (m->basicblockcount <= 75)
1970 count_method_bb_distribution[7]++;
1972 count_method_bb_distribution[8]++;
1976 /* just return methodinfo* to signal everything was ok */
1982 /**********************************************************************/
1983 /* DEBUGGING HELPERS */
1984 /**********************************************************************/
1986 void icmd_print_stack(codegendata *cd, stackptr s)
1998 j = cd->maxstack - i;
2003 /* DEBUG */ /*printf("(%d,%d,%d,%d)",s->varkind,s->flags,s->regoff,s->varnum); fflush(stdout);*/
2004 if (s->flags & SAVEDVAR)
2005 switch (s->varkind) {
2007 if (s->flags & INMEMORY)
2008 printf(" M%02d", s->regoff);
2009 else if ((s->type == TYPE_FLT) || (s->type == TYPE_DBL))
2010 printf(" F%02d", s->regoff);
2012 printf(" %3s", regs[s->regoff]);
2016 printf(" I%02d", s->varnum);
2019 printf(" L%02d", s->varnum);
2022 printf(" A%02d", s->varnum);
2025 printf(" !%02d", j);
2028 switch (s->varkind) {
2030 if (s->flags & INMEMORY)
2031 printf(" m%02d", s->regoff);
2032 else if ((s->type == TYPE_FLT) || (s->type == TYPE_DBL))
2033 printf(" f%02d", s->regoff);
2035 printf(" %3s", regs[s->regoff]);
2039 printf(" i%02d", s->varnum);
2042 printf(" l%02d", s->varnum);
2045 printf(" a%02d", s->varnum);
2048 printf(" ?%02d", j);
2056 static void print_reg(stackptr s) {
2058 if (s->flags & SAVEDVAR)
2059 switch (s->varkind) {
2061 if (s->flags & INMEMORY)
2062 printf(" tm%02d", s->regoff);
2064 printf(" tr%02d", s->regoff);
2067 printf(" s %02d", s->varnum);
2070 printf(" l %02d", s->varnum);
2073 printf(" a %02d", s->varnum);
2076 printf(" ! %02d", s->varnum);
2079 switch (s->varkind) {
2081 if (s->flags & INMEMORY)
2082 printf(" Tm%02d", s->regoff);
2084 printf(" Tr%02d", s->regoff);
2087 printf(" S %02d", s->varnum);
2090 printf(" L %02d", s->varnum);
2093 printf(" A %02d", s->varnum);
2096 printf(" ? %02d", s->varnum);
2106 char *icmd_builtin_name(functionptr bptr)
2108 builtin_descriptor *bdesc = builtin_desc;
2109 while ((bdesc->opcode != 0) && (bdesc->builtin != bptr))
2111 return (bdesc->opcode) ? bdesc->name : "<NOT IN TABLE>";
2115 static char *jit_type[] = {
2124 void show_icmd_method(methodinfo *m, codegendata *cd, registerdata *rd)
2131 utf_fprint_classname(stdout, m->class->name);
2133 utf_fprint(stdout, m->name);
2134 utf_fprint_classname(stdout, m->descriptor);
2135 printf("\n\nMax locals: %d\n", (int) cd->maxlocals);
2136 printf("Max stack: %d\n", (int) cd->maxstack);
2138 printf("Line number table length: %d\n", m->linenumbercount);
2140 printf("Exceptions (Number: %d):\n", cd->exceptiontablelength);
2141 for (ex = cd->exceptiontable; ex != NULL; ex = ex->down) {
2142 printf(" L%03d ... ", ex->start->debug_nr );
2143 printf("L%03d = ", ex->end->debug_nr);
2144 printf("L%03d\n", ex->handler->debug_nr);
2147 printf("Local Table:\n");
2148 for (i = 0; i < cd->maxlocals; i++) {
2149 printf(" %3d: ", i);
2150 for (j = TYPE_INT; j <= TYPE_ADR; j++)
2151 if (rd->locals[i][j].type >= 0) {
2152 printf(" (%s) ", jit_type[j]);
2153 if (rd->locals[i][j].flags & INMEMORY)
2154 printf("m%2d", rd->locals[i][j].regoff);
2155 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2156 printf("f%02d", rd->locals[i][j].regoff);
2158 printf("%3s", regs[rd->locals[i][j].regoff]);
2165 printf("Interface Table:\n");
2166 for (i = 0; i < cd->maxstack; i++) {
2167 if ((rd->interfaces[i][0].type >= 0) ||
2168 (rd->interfaces[i][1].type >= 0) ||
2169 (rd->interfaces[i][2].type >= 0) ||
2170 (rd->interfaces[i][3].type >= 0) ||
2171 (rd->interfaces[i][4].type >= 0)) {
2172 printf(" %3d: ", i);
2173 for (j = TYPE_INT; j <= TYPE_ADR; j++)
2174 if (rd->interfaces[i][j].type >= 0) {
2175 printf(" (%s) ", jit_type[j]);
2176 if (rd->interfaces[i][j].flags & SAVEDVAR) {
2177 if (rd->interfaces[i][j].flags & INMEMORY)
2178 printf("M%2d", rd->interfaces[i][j].regoff);
2179 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2180 printf("F%02d", rd->interfaces[i][j].regoff);
2182 printf("%3s", regs[rd->interfaces[i][j].regoff]);
2186 if (rd->interfaces[i][j].flags & INMEMORY)
2187 printf("m%2d", rd->interfaces[i][j].regoff);
2188 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2189 printf("f%02d", rd->interfaces[i][j].regoff);
2191 printf("%3s", regs[rd->interfaces[i][j].regoff]);
2200 if (showdisassemble) {
2201 #if defined(__I386__) || defined(__X86_64__)
2205 u1ptr = (u1 *) ((ptrint) m->mcode + cd->dseglen);
2206 for (i = 0; i < m->basicblocks[0].mpc; i++, u1ptr++) {
2207 a = disassinstr(u1ptr, i);
2215 s4ptr = (s4 *) ((ptrint) m->mcode + cd->dseglen);
2216 for (i = 0; i < m->basicblocks[0].mpc; i += 4, s4ptr++) {
2217 disassinstr(s4ptr, i);
2223 for (bptr = m->basicblocks; bptr != NULL; bptr = bptr->next) {
2224 show_icmd_block(m, cd, bptr);
2229 void show_icmd_block(methodinfo *m, codegendata *cd, basicblock *bptr)
2235 if (bptr->flags != BBDELETED) {
2236 deadcode = bptr->flags <= BBREACHED;
2239 for (j = cd->maxstack; j > 0; j--)
2242 icmd_print_stack(cd, bptr->instack);
2243 printf("] L%03d(%d - %d) flags=%d:\n", bptr->debug_nr, bptr->icount, bptr->pre_count,bptr->flags);
2244 iptr = bptr->iinstr;
2246 for (i = 0; i < bptr->icount; i++, iptr++) {
2249 for (j = cd->maxstack; j > 0; j--)
2253 icmd_print_stack(cd, iptr->dst);
2254 printf("] %4d ", i);
2255 show_icmd(iptr, deadcode);
2259 if (showdisassemble && (!deadcode)) {
2260 #if defined(__I386__) || defined(__X86_64__)
2266 u1ptr = (u1 *) ((ptrint) m->mcode + cd->dseglen + i);
2268 if (bptr->next != NULL) {
2269 for (; i < bptr->next->mpc; i++, u1ptr++) {
2270 a = disassinstr(u1ptr, i);
2277 for (; u1ptr < (u1 *) ((ptrint) m->mcode + m->mcodelength); i++, u1ptr++) {
2278 a = disassinstr(u1ptr, i);
2289 s4ptr = (s4 *) ((ptrint) m->mcode + cd->dseglen + i);
2291 if (bptr->next != NULL) {
2292 for (; i < bptr->next->mpc; i += 4, s4ptr++) {
2293 disassinstr(s4ptr, i);
2298 for (; s4ptr < (s4 *) ((ptrint) m->mcode + m->mcodelength); i += 4, s4ptr++) {
2299 disassinstr(s4ptr, i);
2309 void show_icmd(instruction *iptr, bool deadcode)
2315 printf("%s", icmd_names[iptr->opc]);
2317 switch (iptr->opc) {
2318 case ICMD_IADDCONST:
2319 case ICMD_ISUBCONST:
2320 case ICMD_IMULCONST:
2323 case ICMD_IANDCONST:
2325 case ICMD_IXORCONST:
2326 case ICMD_ISHLCONST:
2327 case ICMD_ISHRCONST:
2328 case ICMD_IUSHRCONST:
2329 case ICMD_LSHLCONST:
2330 case ICMD_LSHRCONST:
2331 case ICMD_LUSHRCONST:
2333 case ICMD_ELSE_ICONST:
2334 case ICMD_IFEQ_ICONST:
2335 case ICMD_IFNE_ICONST:
2336 case ICMD_IFLT_ICONST:
2337 case ICMD_IFGE_ICONST:
2338 case ICMD_IFGT_ICONST:
2339 case ICMD_IFLE_ICONST:
2340 case ICMD_IASTORECONST:
2341 case ICMD_BASTORECONST:
2342 case ICMD_CASTORECONST:
2343 case ICMD_SASTORECONST:
2344 printf(" %d", iptr->val.i);
2347 case ICMD_LADDCONST:
2348 case ICMD_LSUBCONST:
2349 case ICMD_LMULCONST:
2352 case ICMD_LANDCONST:
2354 case ICMD_LXORCONST:
2356 case ICMD_LASTORECONST:
2357 #if defined(__I386__)
2358 printf(" %lld", iptr->val.l);
2360 printf(" %ld", iptr->val.l);
2365 printf(" %f", iptr->val.f);
2369 printf(" %f", iptr->val.d);
2373 case ICMD_AASTORECONST:
2374 printf(" %p", iptr->val.a);
2379 printf(" %d,", ((fieldinfo *) iptr->val.a)->offset);
2380 case ICMD_PUTSTATIC:
2381 case ICMD_GETSTATIC:
2383 utf_fprint(stdout, ((fieldinfo *) iptr->val.a)->class->name);
2385 utf_fprint(stdout, ((fieldinfo *) iptr->val.a)->name);
2387 utf_fprint(stdout, ((fieldinfo *) iptr->val.a)->descriptor);
2392 printf(" %d + %d", iptr->op1, iptr->val.i);
2427 printf(" %d", iptr->op1);
2433 ((classinfo *) iptr->val.a)->name);
2437 switch (iptr->op1) {
2465 case ICMD_ANEWARRAY:
2469 ((classinfo *) iptr->val.a)->name);
2473 case ICMD_MULTIANEWARRAY:
2476 printf(" %d ",iptr->op1);
2477 vft = (vftbl_t *)iptr->val.a;
2479 utf_fprint(stdout,vft->class->name);
2485 case ICMD_CHECKCAST:
2486 case ICMD_INSTANCEOF:
2488 classinfo *c = iptr->val.a;
2489 if (c->flags & ACC_INTERFACE)
2490 printf(" (INTERFACE) ");
2492 printf(" (CLASS,%3d) ", c->vftbl->diffval);
2493 utf_fprint(stdout, c->name);
2497 case ICMD_INLINE_START:
2498 printf("\t\t\t%s.%s%s",iptr->method->class->name->text,iptr->method->name->text,iptr->method->descriptor->text);
2500 case ICMD_INLINE_END:
2506 printf(" %s", icmd_builtin_name((functionptr) iptr->val.fp));
2509 case ICMD_INVOKEVIRTUAL:
2510 case ICMD_INVOKESPECIAL:
2511 case ICMD_INVOKESTATIC:
2512 case ICMD_INVOKEINTERFACE:
2515 ((methodinfo *) iptr->val.a)->class->name);
2518 ((methodinfo *) iptr->val.a)->name);
2527 if (deadcode || !iptr->target)
2528 printf("(%d) op1=%d", iptr->val.i, iptr->op1);
2530 printf("(%d) L%03d", iptr->val.i, ((basicblock *) iptr->target)->debug_nr);
2539 if (deadcode || !iptr->target)
2540 #if defined(__I386__) || defined(__POWERPC__)
2541 printf("(%lld) op1=%d", iptr->val.l, iptr->op1);
2543 printf("(%ld) op1=%d", iptr->val.l, iptr->op1);
2546 #if defined(__I386__) || defined(__POWERPC__)
2547 printf("(%lld) L%03d", iptr->val.l, ((basicblock *) iptr->target)->debug_nr);
2549 printf("(%ld) L%03d", iptr->val.l, ((basicblock *) iptr->target)->debug_nr);
2556 case ICMD_IFNONNULL:
2557 case ICMD_IF_ICMPEQ:
2558 case ICMD_IF_ICMPNE:
2559 case ICMD_IF_ICMPLT:
2560 case ICMD_IF_ICMPGE:
2561 case ICMD_IF_ICMPGT:
2562 case ICMD_IF_ICMPLE:
2563 case ICMD_IF_LCMPEQ:
2564 case ICMD_IF_LCMPNE:
2565 case ICMD_IF_LCMPLT:
2566 case ICMD_IF_LCMPGE:
2567 case ICMD_IF_LCMPGT:
2568 case ICMD_IF_LCMPLE:
2569 case ICMD_IF_ACMPEQ:
2570 case ICMD_IF_ACMPNE:
2571 if (deadcode || !iptr->target)
2572 printf(" op1=%d", iptr->op1);
2574 printf(" L%03d", ((basicblock *) iptr->target)->debug_nr);
2577 case ICMD_TABLESWITCH:
2578 s4ptr = (s4*)iptr->val.a;
2580 if (deadcode || !iptr->target) {
2581 printf(" %d;", *s4ptr);
2584 tptr = (void **) iptr->target;
2585 printf(" L%03d;", ((basicblock *) *tptr)->debug_nr);
2589 s4ptr++; /* skip default */
2590 j = *s4ptr++; /* low */
2591 j = *s4ptr++ - j; /* high */
2593 if (deadcode || !*tptr)
2594 printf(" %d", *s4ptr++);
2596 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2603 case ICMD_LOOKUPSWITCH:
2604 s4ptr = (s4*)iptr->val.a;
2606 if (deadcode || !iptr->target) {
2607 printf(" %d;", *s4ptr);
2610 tptr = (void **) iptr->target;
2611 printf(" L%03d;", ((basicblock *) *tptr)->debug_nr);
2614 s4ptr++; /* default */
2615 j = *s4ptr++; /* count */
2618 if (deadcode || !*tptr) {
2619 s4ptr++; /* skip value */
2620 printf(" %d",*s4ptr++);
2623 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2629 /* printf(" Line number: %d, method:",iptr->line); */
2631 utf_display(iptr->method->class->name);
2633 utf_display(iptr->method->name); */
2638 * These are local overrides for various environment variables in Emacs.
2639 * Please do not remove this and leave it at the end of the file, where
2640 * Emacs will automagically detect them.
2641 * ---------------------------------------------------------------------
2644 * indent-tabs-mode: t