1 /* src/vm/jit/stack.c - stack analysis
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Andreas Krall
29 Changes: Edwin Steiner
32 $Id: stack.c 2333 2005-04-22 13:26:36Z twisti $
43 #include "mm/memory.h"
44 #include "native/native.h"
45 #include "toolbox/logging.h"
46 #include "vm/global.h"
47 #include "vm/builtin.h"
48 #include "vm/options.h"
49 #include "vm/resolve.h"
50 #include "vm/statistics.h"
51 #include "vm/tables.h"
52 #include "vm/jit/codegen.inc.h"
53 #include "vm/jit/jit.h"
54 #include "vm/jit/reg.h"
55 #include "vm/jit/stack.h"
56 #include "vm/jit/lsra.h"
59 /**********************************************************************/
61 /**********************************************************************/
63 /* analyse_stack uses the intermediate code created by parse.c to
64 * build a model of the JVM operand stack for the current method.
66 * The following checks are performed:
67 * - check for operand stack underflow (before each instruction)
68 * - check for operand stack overflow (after[1] each instruction)
69 * - check for matching stack depth at merging points
70 * - check for matching basic types[2] at merging points
71 * - check basic types for instruction input (except for BUILTIN*
72 * opcodes, INVOKE* opcodes and MULTIANEWARRAY)
74 * [1]) Checking this after the instruction should be ok. parse.c
75 * counts the number of required stack slots in such a way that it is
76 * only vital that we don't exceed `maxstack` at basic block
79 * [2]) 'basic types' means the distinction between INT, LONG, FLOAT,
80 * DOUBLE and ADDRESS types. Subtypes of INT and different ADDRESS
81 * types are not discerned.
84 methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
92 int opcode, i, len, loops;
93 int superblockend, repeat, deadcode;
108 argren = DMNEW(s4, cd->maxlocals); /* table for argument renaming */
109 for (i = 0; i < cd->maxlocals; i++)
112 rd->arguments_num = 0;
115 m->basicblocks[0].flags = BBREACHED;
116 m->basicblocks[0].instack = 0;
117 m->basicblocks[0].indepth = 0;
119 for (i = 0; i < cd->exceptiontablelength; i++) {
120 bptr = &m->basicblocks[m->basicblockindex[cd->exceptiontable[i].handlerpc]];
121 bptr->flags = BBREACHED;
122 bptr->type = BBTYPE_EXH;
125 bptr->pre_count = 10000;
130 #if CONDITIONAL_LOADCONST
131 b_count = m->basicblockcount;
132 bptr = m->basicblocks;
133 while (--b_count >= 0) {
134 if (bptr->icount != 0) {
135 iptr = bptr->iinstr + bptr->icount - 1;
168 m->basicblocks[m->basicblockindex[iptr->op1]].pre_count++;
171 case ICMD_TABLESWITCH:
173 m->basicblocks[m->basicblockindex[*s4ptr++]].pre_count++;
174 i = *s4ptr++; /* low */
175 i = *s4ptr++ - i + 1; /* high */
177 m->basicblocks[m->basicblockindex[*s4ptr++]].pre_count++;
181 case ICMD_LOOKUPSWITCH:
183 m->basicblocks[m->basicblockindex[*s4ptr++]].pre_count++;
184 i = *s4ptr++; /* count */
186 m->basicblocks[m->basicblockindex[s4ptr[1]]].pre_count++;
197 #endif /* CONDITIONAL_LOADCONST */
202 b_count = m->basicblockcount;
203 bptr = m->basicblocks;
204 superblockend = true;
208 while (--b_count >= 0) {
209 if (bptr->flags == BBDELETED) {
212 else if (superblockend && (bptr->flags < BBREACHED))
214 else if (bptr->flags <= BBREACHED) {
216 stackdepth = bptr->indepth;
217 else if (bptr->flags < BBREACHED) {
219 bptr->instack = copy;
220 bptr->indepth = stackdepth;
222 else if (bptr->indepth != stackdepth) {
223 show_icmd_method(m, cd, rd);
224 printf("Block: %d, required depth: %d, current depth: %d\n", bptr->debug_nr, bptr->indepth, stackdepth);
225 panic("Stack depth mismatch");
228 curstack = bptr->instack;
230 superblockend = false;
231 bptr->flags = BBFINISHED;
234 b_index = bptr - m->basicblocks;
237 /* XXX TWISTI: why is this set to NULL here? */
238 /* iptr->target = NULL; */
240 /* dolog("p: %04d op: %s stack: %p", iptr - instr, icmd_names[opcode], curstack); */
242 #if defined(USEBUILTINTABLE)
245 stdopdescriptor *breplace;
246 breplace = find_builtin(opcode);
248 if (breplace && opcode == breplace->opcode) {
249 iptr[0].opc = breplace->icmd;
250 iptr[0].op1 = breplace->type_d;
251 iptr[0].val.fp = breplace->builtin;
252 m->isleafmethod = false;
253 switch (breplace->icmd) {
261 builtin_descriptor *breplace;
262 breplace = find_builtin(opcode);
264 if (breplace && opcode == breplace->opcode) {
265 iptr[0].opc = breplace->icmd;
266 iptr[0].op1 = breplace->type_d;
267 iptr[0].val.fp = breplace->builtin;
268 m->isleafmethod = false;
269 switch (breplace->icmd) {
277 #endif /* defined(USEBUILTINTABLE) */
284 case ICMD_CHECKASIZE:
285 case ICMD_CHECKEXCEPTION:
287 case ICMD_IFEQ_ICONST:
288 case ICMD_IFNE_ICONST:
289 case ICMD_IFLT_ICONST:
290 case ICMD_IFGE_ICONST:
291 case ICMD_IFGT_ICONST:
292 case ICMD_IFLE_ICONST:
293 case ICMD_ELSE_ICONST:
298 rd->locals[iptr->op1][TYPE_ADR].type = TYPE_ADR;
300 COUNT(count_pcmd_return);
302 superblockend = true;
305 /* pop 0 push 1 const */
308 COUNT(count_pcmd_load);
310 switch (iptr[1].opc) {
312 iptr[0].opc = ICMD_IADDCONST;
314 iptr[1].opc = ICMD_NOP;
315 OP1_1(TYPE_INT, TYPE_INT);
316 COUNT(count_pcmd_op);
319 iptr[0].opc = ICMD_ISUBCONST;
320 goto icmd_iconst_tail;
321 #if SUPPORT_CONST_MUL
323 iptr[0].opc = ICMD_IMULCONST;
324 goto icmd_iconst_tail;
325 #else /* SUPPORT_CONST_MUL */
327 if (iptr[0].val.i == 0x00000002)
329 else if (iptr[0].val.i == 0x00000004)
331 else if (iptr[0].val.i == 0x00000008)
333 else if (iptr[0].val.i == 0x00000010)
335 else if (iptr[0].val.i == 0x00000020)
337 else if (iptr[0].val.i == 0x00000040)
339 else if (iptr[0].val.i == 0x00000080)
341 else if (iptr[0].val.i == 0x00000100)
343 else if (iptr[0].val.i == 0x00000200)
345 else if (iptr[0].val.i == 0x00000400)
347 else if (iptr[0].val.i == 0x00000800)
349 else if (iptr[0].val.i == 0x00001000)
351 else if (iptr[0].val.i == 0x00002000)
353 else if (iptr[0].val.i == 0x00004000)
355 else if (iptr[0].val.i == 0x00008000)
357 else if (iptr[0].val.i == 0x00010000)
359 else if (iptr[0].val.i == 0x00020000)
361 else if (iptr[0].val.i == 0x00040000)
363 else if (iptr[0].val.i == 0x00080000)
365 else if (iptr[0].val.i == 0x00100000)
367 else if (iptr[0].val.i == 0x00200000)
369 else if (iptr[0].val.i == 0x00400000)
371 else if (iptr[0].val.i == 0x00800000)
373 else if (iptr[0].val.i == 0x01000000)
375 else if (iptr[0].val.i == 0x02000000)
377 else if (iptr[0].val.i == 0x04000000)
379 else if (iptr[0].val.i == 0x08000000)
381 else if (iptr[0].val.i == 0x10000000)
383 else if (iptr[0].val.i == 0x20000000)
385 else if (iptr[0].val.i == 0x40000000)
387 else if (iptr[0].val.i == 0x80000000)
393 iptr[0].opc = ICMD_IMULPOW2;
394 goto icmd_iconst_tail;
395 #endif /* SUPPORT_CONST_MUL */
397 if (iptr[0].val.i == 0x00000002)
399 else if (iptr[0].val.i == 0x00000004)
401 else if (iptr[0].val.i == 0x00000008)
403 else if (iptr[0].val.i == 0x00000010)
405 else if (iptr[0].val.i == 0x00000020)
407 else if (iptr[0].val.i == 0x00000040)
409 else if (iptr[0].val.i == 0x00000080)
411 else if (iptr[0].val.i == 0x00000100)
413 else if (iptr[0].val.i == 0x00000200)
415 else if (iptr[0].val.i == 0x00000400)
417 else if (iptr[0].val.i == 0x00000800)
419 else if (iptr[0].val.i == 0x00001000)
421 else if (iptr[0].val.i == 0x00002000)
423 else if (iptr[0].val.i == 0x00004000)
425 else if (iptr[0].val.i == 0x00008000)
427 else if (iptr[0].val.i == 0x00010000)
429 else if (iptr[0].val.i == 0x00020000)
431 else if (iptr[0].val.i == 0x00040000)
433 else if (iptr[0].val.i == 0x00080000)
435 else if (iptr[0].val.i == 0x00100000)
437 else if (iptr[0].val.i == 0x00200000)
439 else if (iptr[0].val.i == 0x00400000)
441 else if (iptr[0].val.i == 0x00800000)
443 else if (iptr[0].val.i == 0x01000000)
445 else if (iptr[0].val.i == 0x02000000)
447 else if (iptr[0].val.i == 0x04000000)
449 else if (iptr[0].val.i == 0x08000000)
451 else if (iptr[0].val.i == 0x10000000)
453 else if (iptr[0].val.i == 0x20000000)
455 else if (iptr[0].val.i == 0x40000000)
457 else if (iptr[0].val.i == 0x80000000)
463 iptr[0].opc = ICMD_IDIVPOW2;
464 goto icmd_iconst_tail;
466 if ((iptr[0].val.i == 0x00000002) ||
467 (iptr[0].val.i == 0x00000004) ||
468 (iptr[0].val.i == 0x00000008) ||
469 (iptr[0].val.i == 0x00000010) ||
470 (iptr[0].val.i == 0x00000020) ||
471 (iptr[0].val.i == 0x00000040) ||
472 (iptr[0].val.i == 0x00000080) ||
473 (iptr[0].val.i == 0x00000100) ||
474 (iptr[0].val.i == 0x00000200) ||
475 (iptr[0].val.i == 0x00000400) ||
476 (iptr[0].val.i == 0x00000800) ||
477 (iptr[0].val.i == 0x00001000) ||
478 (iptr[0].val.i == 0x00002000) ||
479 (iptr[0].val.i == 0x00004000) ||
480 (iptr[0].val.i == 0x00008000) ||
481 (iptr[0].val.i == 0x00010000) ||
482 (iptr[0].val.i == 0x00020000) ||
483 (iptr[0].val.i == 0x00040000) ||
484 (iptr[0].val.i == 0x00080000) ||
485 (iptr[0].val.i == 0x00100000) ||
486 (iptr[0].val.i == 0x00200000) ||
487 (iptr[0].val.i == 0x00400000) ||
488 (iptr[0].val.i == 0x00800000) ||
489 (iptr[0].val.i == 0x01000000) ||
490 (iptr[0].val.i == 0x02000000) ||
491 (iptr[0].val.i == 0x04000000) ||
492 (iptr[0].val.i == 0x08000000) ||
493 (iptr[0].val.i == 0x10000000) ||
494 (iptr[0].val.i == 0x20000000) ||
495 (iptr[0].val.i == 0x40000000) ||
496 (iptr[0].val.i == 0x80000000)) {
497 iptr[0].opc = ICMD_IREMPOW2;
499 goto icmd_iconst_tail;
503 #if SUPPORT_CONST_LOGICAL
505 iptr[0].opc = ICMD_IANDCONST;
506 goto icmd_iconst_tail;
508 iptr[0].opc = ICMD_IORCONST;
509 goto icmd_iconst_tail;
511 iptr[0].opc = ICMD_IXORCONST;
512 goto icmd_iconst_tail;
513 #endif /* SUPPORT_CONST_LOGICAL */
515 iptr[0].opc = ICMD_ISHLCONST;
516 goto icmd_iconst_tail;
518 iptr[0].opc = ICMD_ISHRCONST;
519 goto icmd_iconst_tail;
521 iptr[0].opc = ICMD_IUSHRCONST;
522 goto icmd_iconst_tail;
523 #if SUPPORT_LONG_SHIFT
525 iptr[0].opc = ICMD_LSHLCONST;
526 goto icmd_lconst_tail;
528 iptr[0].opc = ICMD_LSHRCONST;
529 goto icmd_lconst_tail;
531 iptr[0].opc = ICMD_LUSHRCONST;
532 goto icmd_lconst_tail;
533 #endif /* SUPPORT_LONG_SHIFT */
535 iptr[0].opc = ICMD_IFEQ;
537 iptr[0].op1 = iptr[1].op1;
541 /* iptr[1].opc = ICMD_NOP; */
543 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
545 iptr[0].target = (void *) tbptr;
547 MARKREACHED(tbptr, copy);
548 COUNT(count_pcmd_bra);
554 iptr[0].opc = ICMD_IFLT;
555 goto icmd_if_icmp_tail;
557 iptr[0].opc = ICMD_IFLE;
558 goto icmd_if_icmp_tail;
560 iptr[0].opc = ICMD_IFNE;
561 goto icmd_if_icmp_tail;
563 iptr[0].opc = ICMD_IFGT;
564 goto icmd_if_icmp_tail;
566 iptr[0].opc = ICMD_IFGE;
567 goto icmd_if_icmp_tail;
569 #if SUPPORT_CONST_STORE
574 #if SUPPORT_CONST_STORE_ZERO_ONLY
575 if (iptr[0].val.i == 0) {
576 #endif /* SUPPORT_CONST_STORE_ZERO_ONLY */
577 switch (iptr[1].opc) {
579 iptr[0].opc = ICMD_IASTORECONST;
582 iptr[0].opc = ICMD_BASTORECONST;
585 iptr[0].opc = ICMD_CASTORECONST;
588 iptr[0].opc = ICMD_SASTORECONST;
592 iptr[1].opc = ICMD_NOP;
593 OPTT2_0(TYPE_INT, TYPE_ADR);
594 COUNT(count_pcmd_op);
595 #if SUPPORT_CONST_STORE_ZERO_ONLY
598 #endif /* SUPPORT_CONST_STORE_ZERO_ONLY */
603 #if SUPPORT_CONST_STORE_ZERO_ONLY
604 if (iptr[0].val.i == 0) {
605 #endif /* SUPPORT_CONST_STORE_ZERO_ONLY */
606 switch (iptr[1].opc) {
608 iptr[0].opc = ICMD_PUTSTATICCONST;
612 iptr[0].opc = ICMD_PUTFIELDCONST;
617 iptr[1].opc = ICMD_NOP;
618 iptr[0].op1 = TYPE_INT;
619 COUNT(count_pcmd_op);
620 #if SUPPORT_CONST_STORE_ZERO_ONLY
623 #endif /* SUPPORT_CONST_STORE_ZERO_ONLY */
625 #endif /* SUPPORT_CONST_STORE */
635 COUNT(count_pcmd_load);
637 switch (iptr[1].opc) {
640 iptr[0].opc = ICMD_LADDCONST;
642 iptr[1].opc = ICMD_NOP;
643 OP1_1(TYPE_LNG,TYPE_LNG);
644 COUNT(count_pcmd_op);
647 iptr[0].opc = ICMD_LSUBCONST;
648 goto icmd_lconst_tail;
649 #endif /* SUPPORT_LONG_ADD */
650 #if SUPPORT_LONG_MUL && SUPPORT_CONST_MUL
652 iptr[0].opc = ICMD_LMULCONST;
653 goto icmd_lconst_tail;
654 #else /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
655 # if SUPPORT_LONG_SHIFT
657 if (iptr[0].val.l == 0x00000002)
659 else if (iptr[0].val.l == 0x00000004)
661 else if (iptr[0].val.l == 0x00000008)
663 else if (iptr[0].val.l == 0x00000010)
665 else if (iptr[0].val.l == 0x00000020)
667 else if (iptr[0].val.l == 0x00000040)
669 else if (iptr[0].val.l == 0x00000080)
671 else if (iptr[0].val.l == 0x00000100)
673 else if (iptr[0].val.l == 0x00000200)
675 else if (iptr[0].val.l == 0x00000400)
677 else if (iptr[0].val.l == 0x00000800)
679 else if (iptr[0].val.l == 0x00001000)
681 else if (iptr[0].val.l == 0x00002000)
683 else if (iptr[0].val.l == 0x00004000)
685 else if (iptr[0].val.l == 0x00008000)
687 else if (iptr[0].val.l == 0x00010000)
689 else if (iptr[0].val.l == 0x00020000)
691 else if (iptr[0].val.l == 0x00040000)
693 else if (iptr[0].val.l == 0x00080000)
695 else if (iptr[0].val.l == 0x00100000)
697 else if (iptr[0].val.l == 0x00200000)
699 else if (iptr[0].val.l == 0x00400000)
701 else if (iptr[0].val.l == 0x00800000)
703 else if (iptr[0].val.l == 0x01000000)
705 else if (iptr[0].val.l == 0x02000000)
707 else if (iptr[0].val.l == 0x04000000)
709 else if (iptr[0].val.l == 0x08000000)
711 else if (iptr[0].val.l == 0x10000000)
713 else if (iptr[0].val.l == 0x20000000)
715 else if (iptr[0].val.l == 0x40000000)
717 else if (iptr[0].val.l == 0x80000000)
723 iptr[0].opc = ICMD_LMULPOW2;
724 goto icmd_lconst_tail;
725 # endif /* SUPPORT_LONG_SHIFT */
726 #endif /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
729 if (iptr[0].val.l == 0x00000002)
731 else if (iptr[0].val.l == 0x00000004)
733 else if (iptr[0].val.l == 0x00000008)
735 else if (iptr[0].val.l == 0x00000010)
737 else if (iptr[0].val.l == 0x00000020)
739 else if (iptr[0].val.l == 0x00000040)
741 else if (iptr[0].val.l == 0x00000080)
743 else if (iptr[0].val.l == 0x00000100)
745 else if (iptr[0].val.l == 0x00000200)
747 else if (iptr[0].val.l == 0x00000400)
749 else if (iptr[0].val.l == 0x00000800)
751 else if (iptr[0].val.l == 0x00001000)
753 else if (iptr[0].val.l == 0x00002000)
755 else if (iptr[0].val.l == 0x00004000)
757 else if (iptr[0].val.l == 0x00008000)
759 else if (iptr[0].val.l == 0x00010000)
761 else if (iptr[0].val.l == 0x00020000)
763 else if (iptr[0].val.l == 0x00040000)
765 else if (iptr[0].val.l == 0x00080000)
767 else if (iptr[0].val.l == 0x00100000)
769 else if (iptr[0].val.l == 0x00200000)
771 else if (iptr[0].val.l == 0x00400000)
773 else if (iptr[0].val.l == 0x00800000)
775 else if (iptr[0].val.l == 0x01000000)
777 else if (iptr[0].val.l == 0x02000000)
779 else if (iptr[0].val.l == 0x04000000)
781 else if (iptr[0].val.l == 0x08000000)
783 else if (iptr[0].val.l == 0x10000000)
785 else if (iptr[0].val.l == 0x20000000)
787 else if (iptr[0].val.l == 0x40000000)
789 else if (iptr[0].val.l == 0x80000000)
795 iptr[0].opc = ICMD_LDIVPOW2;
796 goto icmd_lconst_tail;
798 if ((iptr[0].val.l == 0x00000002) ||
799 (iptr[0].val.l == 0x00000004) ||
800 (iptr[0].val.l == 0x00000008) ||
801 (iptr[0].val.l == 0x00000010) ||
802 (iptr[0].val.l == 0x00000020) ||
803 (iptr[0].val.l == 0x00000040) ||
804 (iptr[0].val.l == 0x00000080) ||
805 (iptr[0].val.l == 0x00000100) ||
806 (iptr[0].val.l == 0x00000200) ||
807 (iptr[0].val.l == 0x00000400) ||
808 (iptr[0].val.l == 0x00000800) ||
809 (iptr[0].val.l == 0x00001000) ||
810 (iptr[0].val.l == 0x00002000) ||
811 (iptr[0].val.l == 0x00004000) ||
812 (iptr[0].val.l == 0x00008000) ||
813 (iptr[0].val.l == 0x00010000) ||
814 (iptr[0].val.l == 0x00020000) ||
815 (iptr[0].val.l == 0x00040000) ||
816 (iptr[0].val.l == 0x00080000) ||
817 (iptr[0].val.l == 0x00100000) ||
818 (iptr[0].val.l == 0x00200000) ||
819 (iptr[0].val.l == 0x00400000) ||
820 (iptr[0].val.l == 0x00800000) ||
821 (iptr[0].val.l == 0x01000000) ||
822 (iptr[0].val.l == 0x02000000) ||
823 (iptr[0].val.l == 0x04000000) ||
824 (iptr[0].val.l == 0x08000000) ||
825 (iptr[0].val.l == 0x10000000) ||
826 (iptr[0].val.l == 0x20000000) ||
827 (iptr[0].val.l == 0x40000000) ||
828 (iptr[0].val.l == 0x80000000)) {
829 iptr[0].opc = ICMD_LREMPOW2;
831 goto icmd_lconst_tail;
835 #endif /* SUPPORT_LONG_DIV */
836 #if SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL
839 iptr[0].opc = ICMD_LANDCONST;
840 goto icmd_lconst_tail;
842 iptr[0].opc = ICMD_LORCONST;
843 goto icmd_lconst_tail;
845 iptr[0].opc = ICMD_LXORCONST;
846 goto icmd_lconst_tail;
847 #endif /* SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL */
848 #if !defined(NOLONG_CONDITIONAL)
850 if ((len > 1) && (iptr[2].val.i == 0)) {
851 switch (iptr[2].opc) {
853 iptr[0].opc = ICMD_IF_LEQ;
854 icmd_lconst_lcmp_tail:
855 iptr[0].op1 = iptr[2].op1;
858 /* iptr[1].opc = ICMD_NOP;
859 iptr[2].opc = ICMD_NOP; */
861 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
863 iptr[0].target = (void *) tbptr;
865 MARKREACHED(tbptr, copy);
866 COUNT(count_pcmd_bra);
867 COUNT(count_pcmd_op);
870 iptr[0].opc = ICMD_IF_LNE;
871 goto icmd_lconst_lcmp_tail;
873 iptr[0].opc = ICMD_IF_LLT;
874 goto icmd_lconst_lcmp_tail;
876 iptr[0].opc = ICMD_IF_LGT;
877 goto icmd_lconst_lcmp_tail;
879 iptr[0].opc = ICMD_IF_LLE;
880 goto icmd_lconst_lcmp_tail;
882 iptr[0].opc = ICMD_IF_LGE;
883 goto icmd_lconst_lcmp_tail;
886 } /* switch (iptr[2].opc) */
887 } /* if (iptr[2].val.i == 0) */
891 #endif /* !defined(NOLONG_CONDITIONAL) */
893 #if SUPPORT_CONST_STORE
895 #if SUPPORT_CONST_STORE_ZERO_ONLY
896 if (iptr[0].val.l == 0) {
897 #endif /* SUPPORT_CONST_STORE_ZERO_ONLY */
898 iptr[0].opc = ICMD_LASTORECONST;
899 iptr[1].opc = ICMD_NOP;
900 OPTT2_0(TYPE_INT, TYPE_ADR);
901 COUNT(count_pcmd_op);
902 #if SUPPORT_CONST_STORE_ZERO_ONLY
905 #endif /* SUPPORT_CONST_STORE_ZERO_ONLY */
910 #if SUPPORT_CONST_STORE_ZERO_ONLY
911 if (iptr[0].val.l == 0) {
912 #endif /* SUPPORT_CONST_STORE_ZERO_ONLY */
913 switch (iptr[1].opc) {
915 iptr[0].opc = ICMD_PUTSTATICCONST;
919 iptr[0].opc = ICMD_PUTFIELDCONST;
924 iptr[1].opc = ICMD_NOP;
925 iptr[0].op1 = TYPE_LNG;
926 COUNT(count_pcmd_op);
927 #if SUPPORT_CONST_STORE_ZERO_ONLY
930 #endif /* SUPPORT_CONST_STORE_ZERO_ONLY */
932 #endif /* SUPPORT_CONST_STORE */
942 COUNT(count_pcmd_load);
947 COUNT(count_pcmd_load);
952 COUNT(count_pcmd_load);
953 #if SUPPORT_CONST_STORE
954 if (len > 0 && iptr->val.a == 0) {
955 switch (iptr[1].opc) {
957 if (iptr[1].val.fp != BUILTIN_aastore) {
964 switch (iptr[1].opc) {
966 iptr[0].opc = ICMD_AASTORECONST;
967 OPTT2_0(TYPE_INT, TYPE_ADR);
970 iptr[0].opc = ICMD_PUTSTATICCONST;
971 iptr[0].op1 = TYPE_ADR;
975 iptr[0].opc = ICMD_PUTFIELDCONST;
976 iptr[0].op1 = TYPE_ADR;
981 iptr[1].opc = ICMD_NOP;
982 COUNT(count_pcmd_op);
989 #endif /* SUPPORT_CONST_STORE */
993 /* pop 0 push 1 load */
1000 COUNT(count_load_instruction);
1001 i = opcode-ICMD_ILOAD;
1002 iptr->op1 = argren[iptr->op1];
1003 rd->locals[iptr->op1][i].type = i;
1004 LOAD(i, LOCALVAR, iptr->op1);
1014 COUNT(count_check_null);
1015 COUNT(count_check_bound);
1016 COUNT(count_pcmd_mem);
1017 OP2IAT_1(opcode-ICMD_IALOAD);
1023 COUNT(count_check_null);
1024 COUNT(count_check_bound);
1025 COUNT(count_pcmd_mem);
1029 /* pop 0 push 0 iinc */
1032 #if defined(STATISTICS)
1036 count_store_depth[10]++;
1038 count_store_depth[i]++;
1044 if ((copy->varkind == LOCALVAR) &&
1045 (copy->varnum == iptr->op1)) {
1046 copy->varkind = TEMPVAR;
1055 /* pop 1 push 0 store */
1065 i = opcode - ICMD_ISTORE;
1066 rd->locals[iptr->op1][i].type = i;
1067 #if defined(STATISTICS)
1072 count_store_length[20]++;
1074 count_store_length[i]++;
1077 count_store_depth[10]++;
1079 count_store_depth[i]++;
1082 copy = curstack->prev;
1085 if ((copy->varkind == LOCALVAR) &&
1086 (copy->varnum == iptr->op1)) {
1087 copy->varkind = TEMPVAR;
1093 if ((new - curstack) == 1) {
1094 curstack->varkind = LOCALVAR;
1095 curstack->varnum = iptr->op1;
1097 STORE(opcode-ICMD_ISTORE);
1107 COUNT(count_check_null);
1108 COUNT(count_check_bound);
1109 COUNT(count_pcmd_mem);
1110 OP3TIA_0(opcode-ICMD_IASTORE);
1116 COUNT(count_check_null);
1117 COUNT(count_check_bound);
1118 COUNT(count_pcmd_mem);
1125 #ifdef TYPECHECK_STACK_COMPCAT
1128 if (IS_2_WORD_TYPE(curstack->type)) {
1129 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1142 COUNT(count_pcmd_return);
1143 OP1_0(opcode-ICMD_IRETURN);
1144 superblockend = true;
1148 COUNT(count_check_null);
1152 superblockend = true;
1155 case ICMD_PUTSTATIC:
1156 COUNT(count_pcmd_mem);
1160 /* pop 1 push 0 branch */
1163 case ICMD_IFNONNULL:
1164 COUNT(count_pcmd_bra);
1166 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1168 iptr[0].target = (void *) tbptr;
1170 MARKREACHED(tbptr, copy);
1182 COUNT(count_pcmd_bra);
1183 #if CONDITIONAL_LOADCONST
1184 tbptr = m->basicblocks + b_index;
1185 if ((b_count >= 3) &&
1186 ((b_index + 2) == m->basicblockindex[iptr[0].op1]) &&
1187 (tbptr[1].pre_count == 1) &&
1188 (tbptr[1].iinstr[0].opc == ICMD_ICONST) &&
1189 (tbptr[1].iinstr[1].opc == ICMD_GOTO) &&
1190 ((b_index + 3) == m->basicblockindex[tbptr[1].iinstr[1].op1]) &&
1191 (tbptr[2].pre_count == 1) &&
1192 (tbptr[2].iinstr[0].opc == ICMD_ICONST)) {
1193 OP1_1(TYPE_INT, TYPE_INT);
1194 switch (iptr[0].opc) {
1196 iptr[0].opc = ICMD_IFNE_ICONST;
1199 iptr[0].opc = ICMD_IFEQ_ICONST;
1202 iptr[0].opc = ICMD_IFGE_ICONST;
1205 iptr[0].opc = ICMD_IFLT_ICONST;
1208 iptr[0].opc = ICMD_IFLE_ICONST;
1211 iptr[0].opc = ICMD_IFGT_ICONST;
1215 iptr[0].val.i = iptr[1].val.i;
1216 iptr[1].opc = ICMD_ELSE_ICONST;
1217 iptr[1].val.i = iptr[3].val.i;
1218 iptr[2].opc = ICMD_NOP;
1219 iptr[3].opc = ICMD_NOP;
1221 /* HACK: save compare value in iptr[1].op1 */
1222 iptr[1].op1 = iptr[0].val.i;
1223 iptr[0].val.i = tbptr[1].iinstr[0].val.i;
1224 iptr[1].opc = ICMD_ELSE_ICONST;
1225 iptr[1].val.i = tbptr[2].iinstr[0].val.i;
1226 tbptr[1].iinstr[0].opc = ICMD_NOP;
1227 tbptr[1].iinstr[1].opc = ICMD_NOP;
1228 tbptr[2].iinstr[0].opc = ICMD_NOP;
1230 tbptr[1].flags = BBDELETED;
1231 tbptr[2].flags = BBDELETED;
1232 tbptr[1].icount = 0;
1233 tbptr[2].icount = 0;
1234 if (tbptr[3].pre_count == 2) {
1235 len += tbptr[3].icount + 3;
1236 bptr->icount += tbptr[3].icount + 3;
1237 tbptr[3].flags = BBDELETED;
1238 tbptr[3].icount = 0;
1248 #endif /* CONDITIONAL_LOADCONST */
1251 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1253 iptr[0].target = (void *) tbptr;
1255 MARKREACHED(tbptr, copy);
1258 /* pop 0 push 0 branch */
1261 COUNT(count_pcmd_bra);
1262 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1264 iptr[0].target = (void *) tbptr;
1266 MARKREACHED(tbptr, copy);
1268 superblockend = true;
1271 /* pop 1 push 0 table branch */
1273 case ICMD_TABLESWITCH:
1274 COUNT(count_pcmd_table);
1276 s4ptr = iptr->val.a;
1277 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
1278 MARKREACHED(tbptr, copy);
1279 i = *s4ptr++; /* low */
1280 i = *s4ptr++ - i + 1; /* high */
1282 tptr = DMNEW(void*, i+1);
1283 iptr->target = (void *) tptr;
1285 tptr[0] = (void *) tbptr;
1289 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
1291 tptr[0] = (void *) tbptr;
1294 MARKREACHED(tbptr, copy);
1297 superblockend = true;
1300 /* pop 1 push 0 table branch */
1302 case ICMD_LOOKUPSWITCH:
1303 COUNT(count_pcmd_table);
1305 s4ptr = iptr->val.a;
1306 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
1307 MARKREACHED(tbptr, copy);
1308 i = *s4ptr++; /* count */
1310 tptr = DMNEW(void*, i+1);
1311 iptr->target = (void *) tptr;
1313 tptr[0] = (void *) tbptr;
1317 tbptr = m->basicblocks + m->basicblockindex[s4ptr[1]];
1319 tptr[0] = (void *) tbptr;
1322 MARKREACHED(tbptr, copy);
1326 superblockend = true;
1329 case ICMD_NULLCHECKPOP:
1330 case ICMD_MONITORENTER:
1331 COUNT(count_check_null);
1332 case ICMD_MONITOREXIT:
1336 /* pop 2 push 0 branch */
1338 case ICMD_IF_ICMPEQ:
1339 case ICMD_IF_ICMPNE:
1340 case ICMD_IF_ICMPLT:
1341 case ICMD_IF_ICMPGE:
1342 case ICMD_IF_ICMPGT:
1343 case ICMD_IF_ICMPLE:
1344 COUNT(count_pcmd_bra);
1346 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1348 iptr[0].target = (void *) tbptr;
1350 MARKREACHED(tbptr, copy);
1353 case ICMD_IF_ACMPEQ:
1354 case ICMD_IF_ACMPNE:
1355 COUNT(count_pcmd_bra);
1357 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1359 iptr[0].target = (void *) tbptr;
1361 MARKREACHED(tbptr, copy);
1367 COUNT(count_check_null);
1368 COUNT(count_pcmd_mem);
1369 OPTT2_0(iptr->op1,TYPE_ADR);
1374 if (!IS_2_WORD_TYPE(curstack->type)) {
1376 #ifdef TYPECHECK_STACK_COMPCAT
1379 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1380 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1385 OP1_0ANY; /* second pop */
1388 iptr->opc = ICMD_POP;
1392 /* pop 0 push 1 dup */
1395 #ifdef TYPECHECK_STACK_COMPCAT
1398 if (IS_2_WORD_TYPE(curstack->type)) {
1399 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1404 COUNT(count_dup_instruction);
1410 if (IS_2_WORD_TYPE(curstack->type)) {
1412 iptr->opc = ICMD_DUP;
1417 /* ..., ????, cat1 */
1418 #ifdef TYPECHECK_STACK_COMPCAT
1420 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1421 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1427 NEWSTACK(copy->prev->type, copy->prev->varkind,
1428 copy->prev->varnum);
1429 NEWSTACK(copy->type, copy->varkind,
1436 /* pop 2 push 3 dup */
1439 #ifdef TYPECHECK_STACK_COMPCAT
1442 if (IS_2_WORD_TYPE(curstack->type) ||
1443 IS_2_WORD_TYPE(curstack->prev->type)) {
1444 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1454 if (IS_2_WORD_TYPE(curstack->type)) {
1455 /* ..., ????, cat2 */
1456 #ifdef TYPECHECK_STACK_COMPCAT
1458 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1459 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1464 iptr->opc = ICMD_DUP_X1;
1468 /* ..., ????, cat1 */
1469 #ifdef TYPECHECK_STACK_COMPCAT
1472 if (IS_2_WORD_TYPE(curstack->prev->type)
1473 || IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1474 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1483 /* pop 3 push 4 dup */
1487 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1488 /* ..., cat2, ???? */
1489 #ifdef TYPECHECK_STACK_COMPCAT
1491 if (IS_2_WORD_TYPE(curstack->type)) {
1492 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1497 iptr->opc = ICMD_DUP_X1;
1501 /* ..., cat1, ???? */
1502 #ifdef TYPECHECK_STACK_COMPCAT
1505 if (IS_2_WORD_TYPE(curstack->type)
1506 || IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1507 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1518 if (IS_2_WORD_TYPE(curstack->type)) {
1519 /* ..., ????, cat2 */
1520 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1521 /* ..., cat2, cat2 */
1522 iptr->opc = ICMD_DUP_X1;
1526 /* ..., cat1, cat2 */
1527 #ifdef TYPECHECK_STACK_COMPCAT
1530 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1531 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1536 iptr->opc = ICMD_DUP_X2;
1542 /* ..., ????, ????, cat1 */
1543 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1544 /* ..., cat2, ????, cat1 */
1545 #ifdef TYPECHECK_STACK_COMPCAT
1547 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1548 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1553 iptr->opc = ICMD_DUP2_X1;
1557 /* ..., cat1, ????, cat1 */
1558 #ifdef TYPECHECK_STACK_COMPCAT
1561 if (IS_2_WORD_TYPE(curstack->prev->type)
1562 || IS_2_WORD_TYPE(curstack->prev->prev->prev->type)) {
1563 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1573 /* pop 2 push 2 swap */
1576 #ifdef TYPECHECK_STACK_COMPCAT
1579 if (IS_2_WORD_TYPE(curstack->type)
1580 || IS_2_WORD_TYPE(curstack->prev->type)) {
1581 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1592 #if !SUPPORT_DIVISION
1593 iptr[0].opc = ICMD_BUILTIN2;
1594 iptr[0].op1 = TYPE_INT;
1595 iptr[0].val.fp = BUILTIN_idiv;
1596 m->isleafmethod = false;
1601 #if !SUPPORT_DIVISION
1602 iptr[0].opc = ICMD_BUILTIN2;
1603 iptr[0].op1 = TYPE_INT;
1604 iptr[0].val.fp = BUILTIN_irem;
1605 m->isleafmethod = false;
1618 COUNT(count_pcmd_op);
1623 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1624 iptr[0].opc = ICMD_BUILTIN2;
1625 iptr[0].op1 = TYPE_LNG;
1626 iptr[0].val.fp = BUILTIN_ldiv;
1627 m->isleafmethod = false;
1632 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1633 iptr[0].opc = ICMD_BUILTIN2;
1634 iptr[0].op1 = TYPE_LNG;
1635 iptr[0].val.fp = BUILTIN_lrem;
1636 m->isleafmethod = false;
1643 #if SUPPORT_LONG_LOGICAL
1647 #endif /* SUPPORT_LONG_LOGICAL */
1648 COUNT(count_pcmd_op);
1655 COUNT(count_pcmd_op);
1664 COUNT(count_pcmd_op);
1673 COUNT(count_pcmd_op);
1678 COUNT(count_pcmd_op);
1679 #if !defined(NOLONG_CONDITIONAL)
1680 if ((len > 0) && (iptr[1].val.i == 0)) {
1681 switch (iptr[1].opc) {
1683 iptr[0].opc = ICMD_IF_LCMPEQ;
1685 iptr[0].op1 = iptr[1].op1;
1688 /* iptr[1].opc = ICMD_NOP; */
1690 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1692 iptr[0].target = (void *) tbptr;
1694 MARKREACHED(tbptr, copy);
1695 COUNT(count_pcmd_bra);
1698 iptr[0].opc = ICMD_IF_LCMPNE;
1699 goto icmd_lcmp_if_tail;
1701 iptr[0].opc = ICMD_IF_LCMPLT;
1702 goto icmd_lcmp_if_tail;
1704 iptr[0].opc = ICMD_IF_LCMPGT;
1705 goto icmd_lcmp_if_tail;
1707 iptr[0].opc = ICMD_IF_LCMPLE;
1708 goto icmd_lcmp_if_tail;
1710 iptr[0].opc = ICMD_IF_LCMPGE;
1711 goto icmd_lcmp_if_tail;
1713 OPTT2_1(TYPE_LNG, TYPE_INT);
1718 OPTT2_1(TYPE_LNG, TYPE_INT);
1722 COUNT(count_pcmd_op);
1723 OPTT2_1(TYPE_FLT, TYPE_INT);
1727 COUNT(count_pcmd_op);
1728 OPTT2_1(TYPE_DBL, TYPE_INT);
1736 case ICMD_INT2SHORT:
1737 COUNT(count_pcmd_op);
1738 OP1_1(TYPE_INT, TYPE_INT);
1741 COUNT(count_pcmd_op);
1742 OP1_1(TYPE_LNG, TYPE_LNG);
1745 COUNT(count_pcmd_op);
1746 OP1_1(TYPE_FLT, TYPE_FLT);
1749 COUNT(count_pcmd_op);
1750 OP1_1(TYPE_DBL, TYPE_DBL);
1754 COUNT(count_pcmd_op);
1755 OP1_1(TYPE_INT, TYPE_LNG);
1758 COUNT(count_pcmd_op);
1759 OP1_1(TYPE_INT, TYPE_FLT);
1762 COUNT(count_pcmd_op);
1763 OP1_1(TYPE_INT, TYPE_DBL);
1766 COUNT(count_pcmd_op);
1767 OP1_1(TYPE_LNG, TYPE_INT);
1770 COUNT(count_pcmd_op);
1771 OP1_1(TYPE_LNG, TYPE_FLT);
1774 COUNT(count_pcmd_op);
1775 OP1_1(TYPE_LNG, TYPE_DBL);
1778 COUNT(count_pcmd_op);
1779 OP1_1(TYPE_FLT, TYPE_INT);
1782 COUNT(count_pcmd_op);
1783 OP1_1(TYPE_FLT, TYPE_LNG);
1786 COUNT(count_pcmd_op);
1787 OP1_1(TYPE_FLT, TYPE_DBL);
1790 COUNT(count_pcmd_op);
1791 OP1_1(TYPE_DBL, TYPE_INT);
1794 COUNT(count_pcmd_op);
1795 OP1_1(TYPE_DBL, TYPE_LNG);
1798 COUNT(count_pcmd_op);
1799 OP1_1(TYPE_DBL, TYPE_FLT);
1802 case ICMD_CHECKCAST:
1803 OP1_1(TYPE_ADR, TYPE_ADR);
1806 case ICMD_INSTANCEOF:
1807 case ICMD_ARRAYLENGTH:
1808 OP1_1(TYPE_ADR, TYPE_INT);
1812 case ICMD_ANEWARRAY:
1813 OP1_1(TYPE_INT, TYPE_ADR);
1817 COUNT(count_check_null);
1818 COUNT(count_pcmd_mem);
1819 OP1_1(TYPE_ADR, iptr->op1);
1824 case ICMD_GETSTATIC:
1825 COUNT(count_pcmd_mem);
1835 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1837 iptr[0].target = (void *) tbptr;
1839 /* This is a dirty hack. The typechecker
1840 * needs it because the OP1_0ANY below
1841 * overwrites iptr->dst.
1843 iptr->val.a = (void *) iptr->dst;
1845 tbptr->type = BBTYPE_SBR;
1847 /* We need to check for overflow right here because
1848 * the pushed value is poped after MARKREACHED. */
1850 MARKREACHED(tbptr, copy);
1854 /* pop many push any */
1857 call_returntype = iptr->op1;
1860 #if defined(USEBUILTINTABLE) || !SUPPORT_DIVISION
1861 /* Just prevent a compiler warning... */
1865 call_returntype = iptr->op1;
1868 #if defined(USEBUILTINTABLE)
1869 /* Just prevent a compiler warning... */
1873 call_returntype = iptr->op1;
1876 case ICMD_INVOKEVIRTUAL:
1877 case ICMD_INVOKESPECIAL:
1878 case ICMD_INVOKEINTERFACE:
1879 case ICMD_INVOKESTATIC:
1880 COUNT(count_pcmd_met);
1882 #if defined(__X86_64__) || defined(__I386__)
1883 unresolved_method *um = iptr->target;
1884 /* if (lm->flags & ACC_STATIC) */
1885 /* {COUNT(count_check_null);} */
1886 call_argcount = iptr->op1;
1887 call_returntype = um->methodref->parseddesc.md->returntype.type;
1889 methodinfo *lm = iptr->val.a;
1890 if (lm->flags & ACC_STATIC)
1891 {COUNT(count_check_null);}
1892 call_argcount = iptr->op1;
1893 call_returntype = lm->returntype;
1899 if (i > rd->arguments_num)
1900 rd->arguments_num = i;
1903 /* Macro in codegen.h */
1907 copy->flags |= SAVEDVAR;
1913 if (call_returntype != TYPE_VOID)
1914 OP0_1(call_returntype);
1918 case ICMD_INLINE_START:
1919 case ICMD_INLINE_END:
1923 case ICMD_MULTIANEWARRAY:
1924 if (rd->argintreguse < 3)
1925 rd->argintreguse = 3;
1929 #ifdef SPECIALMEMUSE
1930 if (rd->ifmemuse < (i + rd->intreg_argnum + 6))
1931 rd->ifmemuse = i + rd->intreg_argnum + 6;
1933 if (rd->ifmemuse < i)
1934 rd->ifmemuse = i; /* n integer args spilled on stack */
1936 if ((i + INT_ARG_CNT) > rd->arguments_num)
1937 rd->arguments_num = i + INT_ARG_CNT;
1940 /* check INT type here? Currently typecheck does this. */
1941 if (!(copy->flags & SAVEDVAR)) {
1942 copy->varkind = ARGVAR;
1943 copy->varnum = i + INT_ARG_CNT;
1944 copy->flags|=INMEMORY;
1945 #ifdef SPECIALMEMUSE
1946 copy->regoff = i + rd->intreg_argnum + 6;
1954 copy->flags |= SAVEDVAR;
1962 case ICMD_CLEAR_ARGREN:
1963 for (i = iptr->op1; i < cd->maxlocals; i++)
1965 iptr->opc = opcode = ICMD_NOP;
1969 case ICMD_READONLY_ARG:
1970 case ICMD_READONLY_ARG+1:
1971 case ICMD_READONLY_ARG+2:
1972 case ICMD_READONLY_ARG+3:
1973 case ICMD_READONLY_ARG+4:
1976 if (curstack->varkind == LOCALVAR) {
1977 i = curstack->varnum;
1978 argren[iptr->op1] = i;
1981 opcode = iptr->opc = opcode - ICMD_READONLY_ARG + ICMD_ISTORE;
1988 new_exception_message(string_java_lang_InternalError,
1995 } /* while instructions */
1997 bptr->outstack = curstack;
1998 bptr->outdepth = stackdepth;
2002 superblockend = true;
2004 } /* while blocks */
2005 } while (repeat && !deadcode);
2007 #if defined(STATISTICS)
2009 if (m->basicblockcount > count_max_basic_blocks)
2010 count_max_basic_blocks = m->basicblockcount;
2011 count_basic_blocks += m->basicblockcount;
2012 if (m->instructioncount > count_max_javainstr) count_max_javainstr = m->instructioncount;
2013 count_javainstr += m->instructioncount;
2014 if (m->stackcount > count_upper_bound_new_stack)
2015 count_upper_bound_new_stack = m->stackcount;
2016 if ((new - m->stack) > count_max_new_stack)
2017 count_max_new_stack = (new - m->stack);
2019 b_count = m->basicblockcount;
2020 bptr = m->basicblocks;
2021 while (--b_count >= 0) {
2022 if (bptr->flags > BBREACHED) {
2023 if (bptr->indepth >= 10)
2024 count_block_stack[10]++;
2026 count_block_stack[bptr->indepth]++;
2029 count_block_size_distribution[len]++;
2031 count_block_size_distribution[10]++;
2033 count_block_size_distribution[11]++;
2035 count_block_size_distribution[12]++;
2037 count_block_size_distribution[13]++;
2039 count_block_size_distribution[14]++;
2041 count_block_size_distribution[15]++;
2043 count_block_size_distribution[16]++;
2045 count_block_size_distribution[17]++;
2051 count_analyse_iterations[0]++;
2052 else if (loops == 2)
2053 count_analyse_iterations[1]++;
2054 else if (loops == 3)
2055 count_analyse_iterations[2]++;
2056 else if (loops == 4)
2057 count_analyse_iterations[3]++;
2059 count_analyse_iterations[4]++;
2061 if (m->basicblockcount <= 5)
2062 count_method_bb_distribution[0]++;
2063 else if (m->basicblockcount <= 10)
2064 count_method_bb_distribution[1]++;
2065 else if (m->basicblockcount <= 15)
2066 count_method_bb_distribution[2]++;
2067 else if (m->basicblockcount <= 20)
2068 count_method_bb_distribution[3]++;
2069 else if (m->basicblockcount <= 30)
2070 count_method_bb_distribution[4]++;
2071 else if (m->basicblockcount <= 40)
2072 count_method_bb_distribution[5]++;
2073 else if (m->basicblockcount <= 50)
2074 count_method_bb_distribution[6]++;
2075 else if (m->basicblockcount <= 75)
2076 count_method_bb_distribution[7]++;
2078 count_method_bb_distribution[8]++;
2082 /* just return methodinfo* to signal everything was ok */
2088 /**********************************************************************/
2089 /* DEBUGGING HELPERS */
2090 /**********************************************************************/
2092 void icmd_print_stack(codegendata *cd, stackptr s)
2104 j = cd->maxstack - i;
2109 /* DEBUG */ /*printf("(%d,%d,%d,%d)",s->varkind,s->flags,s->regoff,s->varnum); fflush(stdout);*/
2110 if (s->flags & SAVEDVAR)
2111 switch (s->varkind) {
2113 if (s->flags & INMEMORY)
2114 printf(" M%02d", s->regoff);
2115 #ifdef HAS_ADDRESS_REGISTER_FILE
2116 else if (s->type == TYPE_ADR)
2117 printf(" R%02d", s->regoff);
2119 else if (IS_FLT_DBL_TYPE(s->type))
2120 printf(" F%02d", s->regoff);
2122 printf(" %3s", regs[s->regoff]);
2126 printf(" I%02d", s->varnum);
2129 printf(" L%02d", s->varnum);
2132 printf(" A%02d", s->varnum);
2133 #ifdef INVOKE_NEW_DEBUG
2134 if (s->flags & INMEMORY)
2135 printf("(M%i)", s->regoff);
2137 printf("(R%i)", s->regoff);
2141 printf(" !%02d", j);
2144 switch (s->varkind) {
2146 if (s->flags & INMEMORY)
2147 printf(" m%02d", s->regoff);
2148 #ifdef HAS_ADDRESS_REGISTER_FILE
2149 else if (s->type == TYPE_ADR)
2150 printf(" r%02d", s->regoff);
2152 else if (IS_FLT_DBL_TYPE(s->type))
2153 printf(" f%02d", s->regoff);
2155 printf(" %3s", regs[s->regoff]);
2159 printf(" i%02d", s->varnum);
2162 printf(" l%02d", s->varnum);
2165 printf(" a%02d", s->varnum);
2166 #ifdef INVOKE_NEW_DEBUG
2167 if (s->flags & INMEMORY)
2168 printf("(M%i)", s->regoff);
2170 printf("(R%i)", s->regoff);
2174 printf(" ?%02d", j);
2182 static void print_reg(stackptr s) {
2184 if (s->flags & SAVEDVAR)
2185 switch (s->varkind) {
2187 if (s->flags & INMEMORY)
2188 printf(" tm%02d", s->regoff);
2190 printf(" tr%02d", s->regoff);
2193 printf(" s %02d", s->varnum);
2196 printf(" l %02d", s->varnum);
2199 printf(" a %02d", s->varnum);
2202 printf(" ! %02d", s->varnum);
2205 switch (s->varkind) {
2207 if (s->flags & INMEMORY)
2208 printf(" Tm%02d", s->regoff);
2210 printf(" Tr%02d", s->regoff);
2213 printf(" S %02d", s->varnum);
2216 printf(" L %02d", s->varnum);
2219 printf(" A %02d", s->varnum);
2222 printf(" ? %02d", s->varnum);
2232 char *icmd_builtin_name(functionptr bptr)
2234 builtin_descriptor *bdesc = builtin_desc;
2235 while ((bdesc->opcode != 0) && (bdesc->builtin != bptr))
2237 return (bdesc->opcode) ? bdesc->name : "<NOT IN TABLE>";
2241 static char *jit_type[] = {
2250 void show_icmd_method(methodinfo *m, codegendata *cd, registerdata *rd)
2257 utf_fprint_classname(stdout, m->class->name);
2259 utf_fprint(stdout, m->name);
2260 utf_fprint_classname(stdout, m->descriptor);
2261 printf("\n\nMax locals: %d\n", (int) cd->maxlocals);
2262 printf("Max stack: %d\n", (int) cd->maxstack);
2264 printf("Line number table length: %d\n", m->linenumbercount);
2266 printf("Exceptions (Number: %d):\n", cd->exceptiontablelength);
2267 for (ex = cd->exceptiontable; ex != NULL; ex = ex->down) {
2268 printf(" L%03d ... ", ex->start->debug_nr );
2269 printf("L%03d = ", ex->end->debug_nr);
2270 printf("L%03d\n", ex->handler->debug_nr);
2273 printf("Local Table:\n");
2274 for (i = 0; i < cd->maxlocals; i++) {
2275 printf(" %3d: ", i);
2276 for (j = TYPE_INT; j <= TYPE_ADR; j++)
2277 if (rd->locals[i][j].type >= 0) {
2278 printf(" (%s) ", jit_type[j]);
2279 if (rd->locals[i][j].flags & INMEMORY)
2280 printf("m%2d", rd->locals[i][j].regoff);
2281 #ifdef HAS_ADDRESS_REGISTER_FILE
2282 else if (j == TYPE_ADR)
2283 printf("r%02d", rd->locals[i][j].regoff);
2285 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2286 printf("f%02d", rd->locals[i][j].regoff);
2288 printf("%3s", regs[rd->locals[i][j].regoff]);
2297 printf("Interface Table:\n");
2298 for (i = 0; i < cd->maxstack; i++) {
2299 if ((rd->interfaces[i][0].type >= 0) ||
2300 (rd->interfaces[i][1].type >= 0) ||
2301 (rd->interfaces[i][2].type >= 0) ||
2302 (rd->interfaces[i][3].type >= 0) ||
2303 (rd->interfaces[i][4].type >= 0)) {
2304 printf(" %3d: ", i);
2305 for (j = TYPE_INT; j <= TYPE_ADR; j++)
2306 if (rd->interfaces[i][j].type >= 0) {
2307 printf(" (%s) ", jit_type[j]);
2308 if (rd->interfaces[i][j].flags & SAVEDVAR) {
2309 if (rd->interfaces[i][j].flags & INMEMORY)
2310 printf("M%2d", rd->interfaces[i][j].regoff);
2311 #ifdef HAS_ADDRESS_REGISTER_FILE
2312 else if (j == TYPE_ADR)
2313 printf("R%02d", rd->interfaces[i][j].regoff);
2315 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2316 printf("F%02d", rd->interfaces[i][j].regoff);
2318 printf("%3s", regs[rd->interfaces[i][j].regoff]);
2322 if (rd->interfaces[i][j].flags & INMEMORY)
2323 printf("m%2d", rd->interfaces[i][j].regoff);
2324 #ifdef HAS_ADDRESS_REGISTER_FILE
2325 else if (j == TYPE_ADR)
2326 printf("r%02d", rd->interfaces[i][j].regoff);
2328 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2329 printf("f%02d", rd->interfaces[i][j].regoff);
2331 printf("%3s", regs[rd->interfaces[i][j].regoff]);
2342 if (showdisassemble) {
2343 #if defined(__I386__) || defined(__X86_64__)
2347 u1ptr = (u1 *) ((ptrint) m->mcode + cd->dseglen);
2348 for (i = 0; i < m->basicblocks[0].mpc;) {
2349 a = disassinstr(u1ptr);
2354 #elif defined(__XDSPCORE__)
2358 s4ptr = (s4 *) ((ptrint) m->mcode + cd->dseglen);
2359 for (i = 0; i < m->basicblocks[0].mpc;) {
2360 a = disassinstr(stdout, s4ptr);
2369 s4ptr = (s4 *) ((ptrint) m->mcode + cd->dseglen);
2370 for (i = 0; i < m->basicblocks[0].mpc; i += 4, s4ptr++) {
2377 for (bptr = m->basicblocks; bptr != NULL; bptr = bptr->next) {
2378 show_icmd_block(m, cd, bptr);
2383 void show_icmd_block(methodinfo *m, codegendata *cd, basicblock *bptr)
2389 if (bptr->flags != BBDELETED) {
2390 deadcode = bptr->flags <= BBREACHED;
2393 for (j = cd->maxstack; j > 0; j--)
2396 icmd_print_stack(cd, bptr->instack);
2397 printf("] L%03d(%d - %d) flags=%d:\n", bptr->debug_nr, bptr->icount, bptr->pre_count,bptr->flags);
2398 iptr = bptr->iinstr;
2400 for (i = 0; i < bptr->icount; i++, iptr++) {
2403 for (j = cd->maxstack; j > 0; j--)
2407 icmd_print_stack(cd, iptr->dst);
2408 printf("] %4d ", i);
2411 if (icmd_uses_tmp[iptr->opc][0])
2415 if (icmd_uses_tmp[iptr->opc][1])
2419 if (icmd_uses_tmp[iptr->opc][2])
2425 show_icmd(iptr, deadcode);
2429 if (showdisassemble && (!deadcode)) {
2430 #if defined(__I386__) || defined(__X86_64__)
2436 u1ptr = (u1 *) ((ptrint) m->mcode + cd->dseglen + i);
2438 if (bptr->next != NULL) {
2439 for (; i < bptr->next->mpc; ) {
2440 a = disassinstr(u1ptr);
2447 for (; u1ptr < (u1 *) ((ptrint) m->mcode + m->mcodelength); ) {
2448 a = disassinstr(u1ptr);
2454 #elif defined(__XDSPCORE__)
2460 s4ptr = (s4 *) ((ptrint) m->mcode + cd->dseglen + i);
2462 if (bptr->next != NULL) {
2463 for (; i < bptr->next->mpc;) {
2464 a = disassinstr(stdout, s4ptr);
2472 for (; s4ptr < (s4 *) ((ptrint) m->mcode + m->mcodelength); ) {
2473 a = disassinstr(stdout, s4ptr);
2484 s4ptr = (s4 *) ((ptrint) m->mcode + cd->dseglen + i);
2486 if (bptr->next != NULL) {
2487 for (; i < bptr->next->mpc; i += 4, s4ptr++)
2492 for (; s4ptr < (s4 *) ((ptrint) m->mcode + m->mcodelength); i += 4, s4ptr++)
2502 void show_icmd(instruction *iptr, bool deadcode)
2508 printf("%s", icmd_names[iptr->opc]);
2510 switch (iptr->opc) {
2511 case ICMD_IADDCONST:
2512 case ICMD_ISUBCONST:
2513 case ICMD_IMULCONST:
2517 case ICMD_IANDCONST:
2519 case ICMD_IXORCONST:
2520 case ICMD_ISHLCONST:
2521 case ICMD_ISHRCONST:
2522 case ICMD_IUSHRCONST:
2523 case ICMD_LSHLCONST:
2524 case ICMD_LSHRCONST:
2525 case ICMD_LUSHRCONST:
2527 case ICMD_ELSE_ICONST:
2528 case ICMD_IASTORECONST:
2529 case ICMD_BASTORECONST:
2530 case ICMD_CASTORECONST:
2531 case ICMD_SASTORECONST:
2532 printf(" %d (0x%08x)", iptr->val.i, iptr->val.i);
2535 case ICMD_IFEQ_ICONST:
2536 case ICMD_IFNE_ICONST:
2537 case ICMD_IFLT_ICONST:
2538 case ICMD_IFGE_ICONST:
2539 case ICMD_IFGT_ICONST:
2540 case ICMD_IFLE_ICONST:
2541 printf("(%d) %d", iptr[1].op1, iptr->val.i);
2544 case ICMD_LADDCONST:
2545 case ICMD_LSUBCONST:
2546 case ICMD_LMULCONST:
2550 case ICMD_LANDCONST:
2552 case ICMD_LXORCONST:
2554 case ICMD_LASTORECONST:
2555 #if defined(__I386__) || defined(__POWERPC__)
2556 printf(" %lld (0x%016llx)", iptr->val.l, iptr->val.l);
2558 printf(" %ld (0x%016lx)", iptr->val.l, iptr->val.l);
2563 printf(" %f", iptr->val.f);
2567 printf(" %f", iptr->val.d);
2571 case ICMD_AASTORECONST:
2572 printf(" %p", iptr->val.a);
2577 #if defined(__X86_64__) || defined(__I386__)
2579 printf(" %d,", ((fieldinfo *) iptr->val.a)->offset);
2581 printf(" NOT RESOLVED,");
2583 printf(" %d,", ((fieldinfo *) iptr->val.a)->offset);
2585 utf_display_classname(((fieldinfo *) iptr->val.a)->class->name);
2587 utf_display(((fieldinfo *) iptr->val.a)->name);
2589 utf_display(((fieldinfo *) iptr->val.a)->descriptor);
2593 case ICMD_PUTSTATIC:
2594 case ICMD_GETSTATIC:
2595 #if defined(__X86_64__) || defined(__I386__)
2597 utf_display_classname(((unresolved_field *) iptr->target)->fieldref->classref->name);
2599 utf_display(((unresolved_field *) iptr->target)->fieldref->name);
2601 utf_display(((unresolved_field *) iptr->target)->fieldref->descriptor);
2605 utf_display_classname(((fieldinfo *) iptr->val.a)->class->name);
2607 utf_display(((fieldinfo *) iptr->val.a)->name);
2609 utf_display(((fieldinfo *) iptr->val.a)->descriptor);
2614 case ICMD_PUTSTATICCONST:
2615 case ICMD_PUTFIELDCONST:
2616 switch (iptr[1].op1) {
2618 printf(" %d,", iptr->val.i);
2621 #if defined(__I386__) || defined(__POWERPC__)
2622 printf(" %lld,", iptr->val.l);
2624 printf(" %ld,", iptr->val.l);
2628 printf(" %p,", iptr->val.a);
2631 printf(" %g,", iptr->val.f);
2634 printf(" %g,", iptr->val.d);
2637 #if defined(__X86_64__)
2638 if (iptr->opc == ICMD_PUTFIELDCONST)
2639 printf(" NOT RESOLVED,");
2641 utf_display_classname(((unresolved_field *) iptr[1].target)->fieldref->classref->name);
2643 utf_display(((unresolved_field *) iptr[1].target)->fieldref->name);
2645 utf_display(((unresolved_field *) iptr[1].target)->fieldref->descriptor);
2648 if (iptr->opc == ICMD_PUTFIELDCONST)
2649 printf(" %d,", ((fieldinfo *) iptr[1].val.a)->offset);
2651 utf_display_classname(((fieldinfo *) iptr[1].val.a)->class->name);
2653 utf_display(((fieldinfo *) iptr[1].val.a)->name);
2655 utf_display(((fieldinfo *) iptr[1].val.a)->descriptor);
2661 printf(" %d + %d", iptr->op1, iptr->val.i);
2696 printf(" %d", iptr->op1);
2701 utf_display_classname(((classinfo *) iptr->val.a)->name);
2705 switch (iptr->op1) {
2733 case ICMD_ANEWARRAY:
2736 utf_display_classname(((classinfo *) iptr->val.a)->name);
2740 case ICMD_MULTIANEWARRAY:
2743 printf(" %d ",iptr->op1);
2744 vft = (vftbl_t *)iptr->val.a;
2746 utf_display_classname(vft->class->name);
2752 case ICMD_CHECKCAST:
2753 case ICMD_INSTANCEOF:
2754 #if defined(__X86_64__) || defined(__I386__)
2756 classinfo *c = iptr->val.a;
2758 if (c->flags & ACC_INTERFACE)
2759 printf(" (INTERFACE) ");
2761 printf(" (CLASS,%3d) ", c->vftbl->diffval);
2763 printf(" (NOT RESOLVED) ");
2765 utf_display_classname(((constant_classref *) iptr->target)->name);
2770 classinfo *c = iptr->val.a;
2771 if (c->flags & ACC_INTERFACE)
2772 printf(" (INTERFACE) ");
2774 printf(" (CLASS,%3d) ", c->vftbl->diffval);
2775 utf_display_classname(c->name);
2779 case ICMD_INLINE_START:
2780 printf("\t\t\t%s.%s%s depth=%i",iptr->method->class->name->text,iptr->method->name->text,iptr->method->descriptor->text, iptr->op1);
2782 case ICMD_INLINE_END:
2788 printf(" %s", icmd_builtin_name((functionptr) iptr->val.fp));
2791 case ICMD_INVOKEVIRTUAL:
2792 case ICMD_INVOKESPECIAL:
2793 case ICMD_INVOKESTATIC:
2794 case ICMD_INVOKEINTERFACE:
2795 #if defined(__X86_64__) || defined(__I386__)
2797 utf_display_classname(((unresolved_method *) iptr->target)->methodref->classref->name);
2799 utf_display(((unresolved_method *) iptr->target)->methodref->name);
2800 utf_display(((unresolved_method *) iptr->target)->methodref->descriptor);
2803 utf_display_classname(((methodinfo *) iptr->val.a)->class->name);
2805 utf_display(((methodinfo *) iptr->val.a)->name);
2806 utf_display(((methodinfo *) iptr->val.a)->descriptor);
2816 if (deadcode || !iptr->target)
2817 printf("(%d) op1=%d", iptr->val.i, iptr->op1);
2819 printf("(%d) L%03d", iptr->val.i, ((basicblock *) iptr->target)->debug_nr);
2828 if (deadcode || !iptr->target)
2829 #if defined(__I386__) || defined(__POWERPC__)
2830 printf("(%lld) op1=%d", iptr->val.l, iptr->op1);
2832 printf("(%ld) op1=%d", iptr->val.l, iptr->op1);
2835 #if defined(__I386__) || defined(__POWERPC__)
2836 printf("(%lld) L%03d", iptr->val.l, ((basicblock *) iptr->target)->debug_nr);
2838 printf("(%ld) L%03d", iptr->val.l, ((basicblock *) iptr->target)->debug_nr);
2845 case ICMD_IFNONNULL:
2846 case ICMD_IF_ICMPEQ:
2847 case ICMD_IF_ICMPNE:
2848 case ICMD_IF_ICMPLT:
2849 case ICMD_IF_ICMPGE:
2850 case ICMD_IF_ICMPGT:
2851 case ICMD_IF_ICMPLE:
2852 case ICMD_IF_LCMPEQ:
2853 case ICMD_IF_LCMPNE:
2854 case ICMD_IF_LCMPLT:
2855 case ICMD_IF_LCMPGE:
2856 case ICMD_IF_LCMPGT:
2857 case ICMD_IF_LCMPLE:
2858 case ICMD_IF_ACMPEQ:
2859 case ICMD_IF_ACMPNE:
2860 if (deadcode || !iptr->target)
2861 printf(" op1=%d", iptr->op1);
2863 printf(" L%03d", ((basicblock *) iptr->target)->debug_nr);
2866 case ICMD_TABLESWITCH:
2867 s4ptr = (s4*)iptr->val.a;
2869 if (deadcode || !iptr->target) {
2870 printf(" %d;", *s4ptr);
2873 tptr = (void **) iptr->target;
2874 printf(" L%03d;", ((basicblock *) *tptr)->debug_nr);
2878 s4ptr++; /* skip default */
2879 j = *s4ptr++; /* low */
2880 j = *s4ptr++ - j; /* high */
2882 if (deadcode || !*tptr)
2883 printf(" %d", *s4ptr++);
2885 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2892 case ICMD_LOOKUPSWITCH:
2893 s4ptr = (s4*)iptr->val.a;
2895 if (deadcode || !iptr->target) {
2896 printf(" %d;", *s4ptr);
2899 tptr = (void **) iptr->target;
2900 printf(" L%03d;", ((basicblock *) *tptr)->debug_nr);
2903 s4ptr++; /* default */
2904 j = *s4ptr++; /* count */
2907 if (deadcode || !*tptr) {
2908 s4ptr++; /* skip value */
2909 printf(" %d",*s4ptr++);
2912 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2918 printf(" Line number: %d, method:",iptr->line);
2920 utf_display(iptr->method->class->name);
2922 utf_display(iptr->method->name); */
2927 * These are local overrides for various environment variables in Emacs.
2928 * Please do not remove this and leave it at the end of the file, where
2929 * Emacs will automagically detect them.
2930 * ---------------------------------------------------------------------
2933 * indent-tabs-mode: t