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 2240 2005-04-06 13:04:28Z 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 */
1250 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1252 iptr[0].target = (void *) tbptr;
1254 MARKREACHED(tbptr, copy);
1257 /* pop 0 push 0 branch */
1260 COUNT(count_pcmd_bra);
1261 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1263 iptr[0].target = (void *) tbptr;
1265 MARKREACHED(tbptr, copy);
1267 superblockend = true;
1270 /* pop 1 push 0 table branch */
1272 case ICMD_TABLESWITCH:
1273 COUNT(count_pcmd_table);
1275 s4ptr = iptr->val.a;
1276 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
1277 MARKREACHED(tbptr, copy);
1278 i = *s4ptr++; /* low */
1279 i = *s4ptr++ - i + 1; /* high */
1281 tptr = DMNEW(void*, i+1);
1282 iptr->target = (void *) tptr;
1284 tptr[0] = (void *) tbptr;
1288 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
1290 tptr[0] = (void *) tbptr;
1293 MARKREACHED(tbptr, copy);
1296 superblockend = true;
1299 /* pop 1 push 0 table branch */
1301 case ICMD_LOOKUPSWITCH:
1302 COUNT(count_pcmd_table);
1304 s4ptr = iptr->val.a;
1305 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
1306 MARKREACHED(tbptr, copy);
1307 i = *s4ptr++; /* count */
1309 tptr = DMNEW(void*, i+1);
1310 iptr->target = (void *) tptr;
1312 tptr[0] = (void *) tbptr;
1316 tbptr = m->basicblocks + m->basicblockindex[s4ptr[1]];
1318 tptr[0] = (void *) tbptr;
1321 MARKREACHED(tbptr, copy);
1325 superblockend = true;
1328 case ICMD_NULLCHECKPOP:
1329 case ICMD_MONITORENTER:
1330 COUNT(count_check_null);
1331 case ICMD_MONITOREXIT:
1335 /* pop 2 push 0 branch */
1337 case ICMD_IF_ICMPEQ:
1338 case ICMD_IF_ICMPNE:
1339 case ICMD_IF_ICMPLT:
1340 case ICMD_IF_ICMPGE:
1341 case ICMD_IF_ICMPGT:
1342 case ICMD_IF_ICMPLE:
1343 COUNT(count_pcmd_bra);
1345 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1347 iptr[0].target = (void *) tbptr;
1349 MARKREACHED(tbptr, copy);
1352 case ICMD_IF_ACMPEQ:
1353 case ICMD_IF_ACMPNE:
1354 COUNT(count_pcmd_bra);
1356 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1358 iptr[0].target = (void *) tbptr;
1360 MARKREACHED(tbptr, copy);
1366 COUNT(count_check_null);
1367 COUNT(count_pcmd_mem);
1368 OPTT2_0(iptr->op1,TYPE_ADR);
1373 if (!IS_2_WORD_TYPE(curstack->type)) {
1375 #ifdef TYPECHECK_STACK_COMPCAT
1378 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1379 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1384 OP1_0ANY; /* second pop */
1387 iptr->opc = ICMD_POP;
1391 /* pop 0 push 1 dup */
1394 #ifdef TYPECHECK_STACK_COMPCAT
1397 if (IS_2_WORD_TYPE(curstack->type)) {
1398 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1403 COUNT(count_dup_instruction);
1409 if (IS_2_WORD_TYPE(curstack->type)) {
1411 iptr->opc = ICMD_DUP;
1416 /* ..., ????, cat1 */
1417 #ifdef TYPECHECK_STACK_COMPCAT
1419 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1420 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1426 NEWSTACK(copy->prev->type, copy->prev->varkind,
1427 copy->prev->varnum);
1428 NEWSTACK(copy->type, copy->varkind,
1435 /* pop 2 push 3 dup */
1438 #ifdef TYPECHECK_STACK_COMPCAT
1441 if (IS_2_WORD_TYPE(curstack->type) ||
1442 IS_2_WORD_TYPE(curstack->prev->type)) {
1443 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1453 if (IS_2_WORD_TYPE(curstack->type)) {
1454 /* ..., ????, cat2 */
1455 #ifdef TYPECHECK_STACK_COMPCAT
1457 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1458 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1463 iptr->opc = ICMD_DUP_X1;
1467 /* ..., ????, cat1 */
1468 #ifdef TYPECHECK_STACK_COMPCAT
1471 if (IS_2_WORD_TYPE(curstack->prev->type)
1472 || IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1473 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1482 /* pop 3 push 4 dup */
1486 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1487 /* ..., cat2, ???? */
1488 #ifdef TYPECHECK_STACK_COMPCAT
1490 if (IS_2_WORD_TYPE(curstack->type)) {
1491 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1496 iptr->opc = ICMD_DUP_X1;
1500 /* ..., cat1, ???? */
1501 #ifdef TYPECHECK_STACK_COMPCAT
1504 if (IS_2_WORD_TYPE(curstack->type)
1505 || IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1506 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1517 if (IS_2_WORD_TYPE(curstack->type)) {
1518 /* ..., ????, cat2 */
1519 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1520 /* ..., cat2, cat2 */
1521 iptr->opc = ICMD_DUP_X1;
1525 /* ..., cat1, cat2 */
1526 #ifdef TYPECHECK_STACK_COMPCAT
1529 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1530 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1535 iptr->opc = ICMD_DUP_X2;
1541 /* ..., ????, ????, cat1 */
1542 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1543 /* ..., cat2, ????, cat1 */
1544 #ifdef TYPECHECK_STACK_COMPCAT
1546 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1547 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1552 iptr->opc = ICMD_DUP2_X1;
1556 /* ..., cat1, ????, cat1 */
1557 #ifdef TYPECHECK_STACK_COMPCAT
1560 if (IS_2_WORD_TYPE(curstack->prev->type)
1561 || IS_2_WORD_TYPE(curstack->prev->prev->prev->type)) {
1562 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1572 /* pop 2 push 2 swap */
1575 #ifdef TYPECHECK_STACK_COMPCAT
1578 if (IS_2_WORD_TYPE(curstack->type)
1579 || IS_2_WORD_TYPE(curstack->prev->type)) {
1580 *exceptionptr = new_verifyerror(m, "Attempt to split long or double on the stack");
1591 #if !SUPPORT_DIVISION
1592 iptr[0].opc = ICMD_BUILTIN2;
1593 iptr[0].op1 = TYPE_INT;
1594 iptr[0].val.fp = BUILTIN_idiv;
1595 m->isleafmethod = false;
1600 #if !SUPPORT_DIVISION
1601 iptr[0].opc = ICMD_BUILTIN2;
1602 iptr[0].op1 = TYPE_INT;
1603 iptr[0].val.fp = BUILTIN_irem;
1604 m->isleafmethod = false;
1617 COUNT(count_pcmd_op);
1622 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1623 iptr[0].opc = ICMD_BUILTIN2;
1624 iptr[0].op1 = TYPE_LNG;
1625 iptr[0].val.fp = BUILTIN_ldiv;
1626 m->isleafmethod = false;
1631 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1632 iptr[0].opc = ICMD_BUILTIN2;
1633 iptr[0].op1 = TYPE_LNG;
1634 iptr[0].val.fp = BUILTIN_lrem;
1635 m->isleafmethod = false;
1642 #if SUPPORT_LONG_LOGICAL
1646 #endif /* SUPPORT_LONG_LOGICAL */
1647 COUNT(count_pcmd_op);
1654 COUNT(count_pcmd_op);
1663 COUNT(count_pcmd_op);
1672 COUNT(count_pcmd_op);
1677 COUNT(count_pcmd_op);
1678 #if !defined(NOLONG_CONDITIONAL)
1679 if ((len > 0) && (iptr[1].val.i == 0)) {
1680 switch (iptr[1].opc) {
1682 iptr[0].opc = ICMD_IF_LCMPEQ;
1684 iptr[0].op1 = iptr[1].op1;
1687 /* iptr[1].opc = ICMD_NOP; */
1689 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1691 iptr[0].target = (void *) tbptr;
1693 MARKREACHED(tbptr, copy);
1694 COUNT(count_pcmd_bra);
1697 iptr[0].opc = ICMD_IF_LCMPNE;
1698 goto icmd_lcmp_if_tail;
1700 iptr[0].opc = ICMD_IF_LCMPLT;
1701 goto icmd_lcmp_if_tail;
1703 iptr[0].opc = ICMD_IF_LCMPGT;
1704 goto icmd_lcmp_if_tail;
1706 iptr[0].opc = ICMD_IF_LCMPLE;
1707 goto icmd_lcmp_if_tail;
1709 iptr[0].opc = ICMD_IF_LCMPGE;
1710 goto icmd_lcmp_if_tail;
1712 OPTT2_1(TYPE_LNG, TYPE_INT);
1717 OPTT2_1(TYPE_LNG, TYPE_INT);
1721 COUNT(count_pcmd_op);
1722 OPTT2_1(TYPE_FLT, TYPE_INT);
1726 COUNT(count_pcmd_op);
1727 OPTT2_1(TYPE_DBL, TYPE_INT);
1735 case ICMD_INT2SHORT:
1736 COUNT(count_pcmd_op);
1737 OP1_1(TYPE_INT, TYPE_INT);
1740 COUNT(count_pcmd_op);
1741 OP1_1(TYPE_LNG, TYPE_LNG);
1744 COUNT(count_pcmd_op);
1745 OP1_1(TYPE_FLT, TYPE_FLT);
1748 COUNT(count_pcmd_op);
1749 OP1_1(TYPE_DBL, TYPE_DBL);
1753 COUNT(count_pcmd_op);
1754 OP1_1(TYPE_INT, TYPE_LNG);
1757 COUNT(count_pcmd_op);
1758 OP1_1(TYPE_INT, TYPE_FLT);
1761 COUNT(count_pcmd_op);
1762 OP1_1(TYPE_INT, TYPE_DBL);
1765 COUNT(count_pcmd_op);
1766 OP1_1(TYPE_LNG, TYPE_INT);
1769 COUNT(count_pcmd_op);
1770 OP1_1(TYPE_LNG, TYPE_FLT);
1773 COUNT(count_pcmd_op);
1774 OP1_1(TYPE_LNG, TYPE_DBL);
1777 COUNT(count_pcmd_op);
1778 OP1_1(TYPE_FLT, TYPE_INT);
1781 COUNT(count_pcmd_op);
1782 OP1_1(TYPE_FLT, TYPE_LNG);
1785 COUNT(count_pcmd_op);
1786 OP1_1(TYPE_FLT, TYPE_DBL);
1789 COUNT(count_pcmd_op);
1790 OP1_1(TYPE_DBL, TYPE_INT);
1793 COUNT(count_pcmd_op);
1794 OP1_1(TYPE_DBL, TYPE_LNG);
1797 COUNT(count_pcmd_op);
1798 OP1_1(TYPE_DBL, TYPE_FLT);
1801 case ICMD_CHECKCAST:
1802 OP1_1(TYPE_ADR, TYPE_ADR);
1805 case ICMD_INSTANCEOF:
1806 case ICMD_ARRAYLENGTH:
1807 OP1_1(TYPE_ADR, TYPE_INT);
1811 case ICMD_ANEWARRAY:
1812 OP1_1(TYPE_INT, TYPE_ADR);
1816 COUNT(count_check_null);
1817 COUNT(count_pcmd_mem);
1818 OP1_1(TYPE_ADR, iptr->op1);
1823 case ICMD_GETSTATIC:
1824 COUNT(count_pcmd_mem);
1834 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1836 iptr[0].target = (void *) tbptr;
1838 /* This is a dirty hack. The typechecker
1839 * needs it because the OP1_0ANY below
1840 * overwrites iptr->dst.
1842 iptr->val.a = (void *) iptr->dst;
1844 tbptr->type = BBTYPE_SBR;
1846 /* We need to check for overflow right here because
1847 * the pushed value is poped after MARKREACHED. */
1849 MARKREACHED(tbptr, copy);
1853 /* pop many push any */
1856 call_returntype = iptr->op1;
1859 #if defined(USEBUILTINTABLE) || !SUPPORT_DIVISION
1860 /* Just prevent a compiler warning... */
1864 call_returntype = iptr->op1;
1867 #if defined(USEBUILTINTABLE)
1868 /* Just prevent a compiler warning... */
1872 call_returntype = iptr->op1;
1875 case ICMD_INVOKESPECIAL:
1876 COUNT(count_pcmd_met);
1878 #if defined(__X86_64__)
1879 unresolved_method *um = iptr->target;
1880 /* if (lm->flags & ACC_STATIC) */
1881 /* {COUNT(count_check_null);} */
1882 call_argcount = iptr->op1;
1884 um->methodref->parseddesc.md->returntype.type;
1886 methodinfo *lm = iptr->val.a;
1887 if (lm->flags & ACC_STATIC)
1888 {COUNT(count_check_null);}
1889 call_argcount = iptr->op1;
1890 call_returntype = lm->returntype;
1893 /* _callhandling: */
1896 if (i > rd->arguments_num)
1897 rd->arguments_num = i;
1900 /* Macro in codegen.h */
1904 copy->flags |= SAVEDVAR;
1910 if (call_returntype != TYPE_VOID)
1911 OP0_1(call_returntype);
1915 case ICMD_INVOKEVIRTUAL:
1916 /* case ICMD_INVOKESPECIAL: */
1917 case ICMD_INVOKEINTERFACE:
1918 case ICMD_INVOKESTATIC:
1919 COUNT(count_pcmd_met);
1921 methodinfo *lm = iptr->val.a;
1922 if (lm->flags & ACC_STATIC)
1923 {COUNT(count_check_null);}
1924 call_argcount = iptr->op1;
1925 call_returntype = lm->returntype;
1930 if (i > rd->arguments_num)
1931 rd->arguments_num = i;
1934 /* Macro in codegen.h */
1938 copy->flags |= SAVEDVAR;
1944 if (call_returntype != TYPE_VOID)
1945 OP0_1(call_returntype);
1949 case ICMD_INLINE_START:
1950 case ICMD_INLINE_END:
1954 case ICMD_MULTIANEWARRAY:
1957 #ifdef SPECIALMEMUSE
1958 if (rd->ifmemuse < (i + rd->intreg_argnum + 6))
1959 rd->ifmemuse = i + rd->intreg_argnum + 6;
1961 if (rd->ifmemuse < i)
1962 rd->ifmemuse = i; /* n integer args spilled on stack */
1964 if ((i + INT_ARG_CNT) > rd->arguments_num)
1965 rd->arguments_num = i + INT_ARG_CNT;
1968 /* check INT type here? Currently typecheck does this. */
1969 if (!(copy->flags & SAVEDVAR)) {
1970 copy->varkind = ARGVAR;
1971 copy->varnum = i + INT_ARG_CNT;
1972 copy->flags|=INMEMORY;
1973 #ifdef SPECIALMEMUSE
1974 copy->regoff = i + rd->intreg_argnum + 6;
1982 copy->flags |= SAVEDVAR;
1990 case ICMD_CLEAR_ARGREN:
1991 for (i = iptr->op1; i < cd->maxlocals; i++)
1993 iptr->opc = opcode = ICMD_NOP;
1997 case ICMD_READONLY_ARG:
1998 case ICMD_READONLY_ARG+1:
1999 case ICMD_READONLY_ARG+2:
2000 case ICMD_READONLY_ARG+3:
2001 case ICMD_READONLY_ARG+4:
2004 if (curstack->varkind == LOCALVAR) {
2005 i = curstack->varnum;
2006 argren[iptr->op1] = i;
2009 opcode = iptr->opc = opcode - ICMD_READONLY_ARG + ICMD_ISTORE;
2016 new_exception_message(string_java_lang_InternalError,
2023 } /* while instructions */
2025 bptr->outstack = curstack;
2026 bptr->outdepth = stackdepth;
2030 superblockend = true;
2032 } /* while blocks */
2033 } while (repeat && !deadcode);
2035 #if defined(STATISTICS)
2037 if (m->basicblockcount > count_max_basic_blocks)
2038 count_max_basic_blocks = m->basicblockcount;
2039 count_basic_blocks += m->basicblockcount;
2040 if (m->instructioncount > count_max_javainstr) count_max_javainstr = m->instructioncount;
2041 count_javainstr += m->instructioncount;
2042 if (m->stackcount > count_upper_bound_new_stack)
2043 count_upper_bound_new_stack = m->stackcount;
2044 if ((new - m->stack) > count_max_new_stack)
2045 count_max_new_stack = (new - m->stack);
2047 b_count = m->basicblockcount;
2048 bptr = m->basicblocks;
2049 while (--b_count >= 0) {
2050 if (bptr->flags > BBREACHED) {
2051 if (bptr->indepth >= 10)
2052 count_block_stack[10]++;
2054 count_block_stack[bptr->indepth]++;
2057 count_block_size_distribution[len]++;
2059 count_block_size_distribution[10]++;
2061 count_block_size_distribution[11]++;
2063 count_block_size_distribution[12]++;
2065 count_block_size_distribution[13]++;
2067 count_block_size_distribution[14]++;
2069 count_block_size_distribution[15]++;
2071 count_block_size_distribution[16]++;
2073 count_block_size_distribution[17]++;
2079 count_analyse_iterations[0]++;
2080 else if (loops == 2)
2081 count_analyse_iterations[1]++;
2082 else if (loops == 3)
2083 count_analyse_iterations[2]++;
2084 else if (loops == 4)
2085 count_analyse_iterations[3]++;
2087 count_analyse_iterations[4]++;
2089 if (m->basicblockcount <= 5)
2090 count_method_bb_distribution[0]++;
2091 else if (m->basicblockcount <= 10)
2092 count_method_bb_distribution[1]++;
2093 else if (m->basicblockcount <= 15)
2094 count_method_bb_distribution[2]++;
2095 else if (m->basicblockcount <= 20)
2096 count_method_bb_distribution[3]++;
2097 else if (m->basicblockcount <= 30)
2098 count_method_bb_distribution[4]++;
2099 else if (m->basicblockcount <= 40)
2100 count_method_bb_distribution[5]++;
2101 else if (m->basicblockcount <= 50)
2102 count_method_bb_distribution[6]++;
2103 else if (m->basicblockcount <= 75)
2104 count_method_bb_distribution[7]++;
2106 count_method_bb_distribution[8]++;
2110 /* just return methodinfo* to signal everything was ok */
2116 /**********************************************************************/
2117 /* DEBUGGING HELPERS */
2118 /**********************************************************************/
2120 void icmd_print_stack(codegendata *cd, stackptr s)
2132 j = cd->maxstack - i;
2137 /* DEBUG */ /*printf("(%d,%d,%d,%d)",s->varkind,s->flags,s->regoff,s->varnum); fflush(stdout);*/
2138 if (s->flags & SAVEDVAR)
2139 switch (s->varkind) {
2141 if (s->flags & INMEMORY)
2142 printf(" M%02d", s->regoff);
2143 #ifdef HAS_ADDRESS_REGISTER_FILE
2144 else if (s->type == TYPE_ADR)
2145 printf(" R%02d", s->regoff);
2147 else if (IS_FLT_DBL_TYPE(s->type))
2148 printf(" F%02d", s->regoff);
2150 printf(" %3s", regs[s->regoff]);
2154 printf(" I%02d", s->varnum);
2157 printf(" L%02d", s->varnum);
2160 printf(" A%02d", s->varnum);
2161 #ifdef INVOKE_NEW_DEBUG
2162 if (s->flags & INMEMORY)
2163 printf("(M%i)", s->regoff);
2165 printf("(R%i)", s->regoff);
2169 printf(" !%02d", j);
2172 switch (s->varkind) {
2174 if (s->flags & INMEMORY)
2175 printf(" m%02d", s->regoff);
2176 #ifdef HAS_ADDRESS_REGISTER_FILE
2177 else if (s->type == TYPE_ADR)
2178 printf(" r%02d", s->regoff);
2180 else if (IS_FLT_DBL_TYPE(s->type))
2181 printf(" f%02d", s->regoff);
2183 printf(" %3s", regs[s->regoff]);
2187 printf(" i%02d", s->varnum);
2190 printf(" l%02d", s->varnum);
2193 printf(" a%02d", s->varnum);
2194 #ifdef INVOKE_NEW_DEBUG
2195 if (s->flags & INMEMORY)
2196 printf("(M%i)", s->regoff);
2198 printf("(R%i)", s->regoff);
2202 printf(" ?%02d", j);
2210 static void print_reg(stackptr s) {
2212 if (s->flags & SAVEDVAR)
2213 switch (s->varkind) {
2215 if (s->flags & INMEMORY)
2216 printf(" tm%02d", s->regoff);
2218 printf(" tr%02d", s->regoff);
2221 printf(" s %02d", s->varnum);
2224 printf(" l %02d", s->varnum);
2227 printf(" a %02d", s->varnum);
2230 printf(" ! %02d", s->varnum);
2233 switch (s->varkind) {
2235 if (s->flags & INMEMORY)
2236 printf(" Tm%02d", s->regoff);
2238 printf(" Tr%02d", s->regoff);
2241 printf(" S %02d", s->varnum);
2244 printf(" L %02d", s->varnum);
2247 printf(" A %02d", s->varnum);
2250 printf(" ? %02d", s->varnum);
2260 char *icmd_builtin_name(functionptr bptr)
2262 builtin_descriptor *bdesc = builtin_desc;
2263 while ((bdesc->opcode != 0) && (bdesc->builtin != bptr))
2265 return (bdesc->opcode) ? bdesc->name : "<NOT IN TABLE>";
2269 static char *jit_type[] = {
2278 void show_icmd_method(methodinfo *m, codegendata *cd, registerdata *rd)
2285 utf_fprint_classname(stdout, m->class->name);
2287 utf_fprint(stdout, m->name);
2288 utf_fprint_classname(stdout, m->descriptor);
2289 printf("\n\nMax locals: %d\n", (int) cd->maxlocals);
2290 printf("Max stack: %d\n", (int) cd->maxstack);
2292 printf("Line number table length: %d\n", m->linenumbercount);
2294 printf("Exceptions (Number: %d):\n", cd->exceptiontablelength);
2295 for (ex = cd->exceptiontable; ex != NULL; ex = ex->down) {
2296 printf(" L%03d ... ", ex->start->debug_nr );
2297 printf("L%03d = ", ex->end->debug_nr);
2298 printf("L%03d\n", ex->handler->debug_nr);
2301 printf("Local Table:\n");
2302 for (i = 0; i < cd->maxlocals; i++) {
2303 printf(" %3d: ", i);
2304 for (j = TYPE_INT; j <= TYPE_ADR; j++)
2305 if (rd->locals[i][j].type >= 0) {
2306 printf(" (%s) ", jit_type[j]);
2307 if (rd->locals[i][j].flags & INMEMORY)
2308 printf("m%2d", rd->locals[i][j].regoff);
2309 #ifdef HAS_ADDRESS_REGISTER_FILE
2310 else if (j == TYPE_ADR)
2311 printf("r%02d", rd->locals[i][j].regoff);
2313 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2314 printf("f%02d", rd->locals[i][j].regoff);
2316 printf("%3s", regs[rd->locals[i][j].regoff]);
2325 printf("Interface Table:\n");
2326 for (i = 0; i < cd->maxstack; i++) {
2327 if ((rd->interfaces[i][0].type >= 0) ||
2328 (rd->interfaces[i][1].type >= 0) ||
2329 (rd->interfaces[i][2].type >= 0) ||
2330 (rd->interfaces[i][3].type >= 0) ||
2331 (rd->interfaces[i][4].type >= 0)) {
2332 printf(" %3d: ", i);
2333 for (j = TYPE_INT; j <= TYPE_ADR; j++)
2334 if (rd->interfaces[i][j].type >= 0) {
2335 printf(" (%s) ", jit_type[j]);
2336 if (rd->interfaces[i][j].flags & SAVEDVAR) {
2337 if (rd->interfaces[i][j].flags & INMEMORY)
2338 printf("M%2d", rd->interfaces[i][j].regoff);
2339 #ifdef HAS_ADDRESS_REGISTER_FILE
2340 else if (j == TYPE_ADR)
2341 printf("R%02d", rd->interfaces[i][j].regoff);
2343 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2344 printf("F%02d", rd->interfaces[i][j].regoff);
2346 printf("%3s", regs[rd->interfaces[i][j].regoff]);
2350 if (rd->interfaces[i][j].flags & INMEMORY)
2351 printf("m%2d", rd->interfaces[i][j].regoff);
2352 #ifdef HAS_ADDRESS_REGISTER_FILE
2353 else if (j == TYPE_ADR)
2354 printf("r%02d", rd->interfaces[i][j].regoff);
2356 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2357 printf("f%02d", rd->interfaces[i][j].regoff);
2359 printf("%3s", regs[rd->interfaces[i][j].regoff]);
2370 if (showdisassemble) {
2371 #if defined(__I386__) || defined(__X86_64__)
2375 u1ptr = (u1 *) ((ptrint) m->mcode + cd->dseglen);
2376 for (i = 0; i < m->basicblocks[0].mpc;) {
2377 a = disassinstr(u1ptr);
2382 #elif defined(__XDSPCORE__)
2386 s4ptr = (s4 *) ((ptrint) m->mcode + cd->dseglen);
2387 for (i = 0; i < m->basicblocks[0].mpc;) {
2388 a = disassinstr(stdout, s4ptr);
2397 s4ptr = (s4 *) ((ptrint) m->mcode + cd->dseglen);
2398 for (i = 0; i < m->basicblocks[0].mpc; i += 4, s4ptr++) {
2405 for (bptr = m->basicblocks; bptr != NULL; bptr = bptr->next) {
2406 show_icmd_block(m, cd, bptr);
2411 void show_icmd_block(methodinfo *m, codegendata *cd, basicblock *bptr)
2417 if (bptr->flags != BBDELETED) {
2418 deadcode = bptr->flags <= BBREACHED;
2421 for (j = cd->maxstack; j > 0; j--)
2424 icmd_print_stack(cd, bptr->instack);
2425 printf("] L%03d(%d - %d) flags=%d:\n", bptr->debug_nr, bptr->icount, bptr->pre_count,bptr->flags);
2426 iptr = bptr->iinstr;
2428 for (i = 0; i < bptr->icount; i++, iptr++) {
2431 for (j = cd->maxstack; j > 0; j--)
2435 icmd_print_stack(cd, iptr->dst);
2436 printf("] %4d ", i);
2439 if (icmd_uses_tmp[iptr->opc][0])
2443 if (icmd_uses_tmp[iptr->opc][1])
2447 if (icmd_uses_tmp[iptr->opc][2])
2453 show_icmd(iptr, deadcode);
2457 if (showdisassemble && (!deadcode)) {
2458 #if defined(__I386__) || defined(__X86_64__)
2464 u1ptr = (u1 *) ((ptrint) m->mcode + cd->dseglen + i);
2466 if (bptr->next != NULL) {
2467 for (; i < bptr->next->mpc; ) {
2468 a = disassinstr(u1ptr);
2475 for (; u1ptr < (u1 *) ((ptrint) m->mcode + m->mcodelength); ) {
2476 a = disassinstr(u1ptr);
2482 #elif defined(__XDSPCORE__)
2488 s4ptr = (s4 *) ((ptrint) m->mcode + cd->dseglen + i);
2490 if (bptr->next != NULL) {
2491 for (; i < bptr->next->mpc;) {
2492 a = disassinstr(stdout, s4ptr);
2500 for (; s4ptr < (s4 *) ((ptrint) m->mcode + m->mcodelength); ) {
2501 a = disassinstr(stdout, s4ptr);
2512 s4ptr = (s4 *) ((ptrint) m->mcode + cd->dseglen + i);
2514 if (bptr->next != NULL) {
2515 for (; i < bptr->next->mpc; i += 4, s4ptr++)
2520 for (; s4ptr < (s4 *) ((ptrint) m->mcode + m->mcodelength); i += 4, s4ptr++)
2530 void show_icmd(instruction *iptr, bool deadcode)
2536 printf("%s", icmd_names[iptr->opc]);
2538 switch (iptr->opc) {
2539 case ICMD_IADDCONST:
2540 case ICMD_ISUBCONST:
2541 case ICMD_IMULCONST:
2545 case ICMD_IANDCONST:
2547 case ICMD_IXORCONST:
2548 case ICMD_ISHLCONST:
2549 case ICMD_ISHRCONST:
2550 case ICMD_IUSHRCONST:
2551 case ICMD_LSHLCONST:
2552 case ICMD_LSHRCONST:
2553 case ICMD_LUSHRCONST:
2555 case ICMD_ELSE_ICONST:
2556 case ICMD_IASTORECONST:
2557 case ICMD_BASTORECONST:
2558 case ICMD_CASTORECONST:
2559 case ICMD_SASTORECONST:
2560 printf(" %d", iptr->val.i);
2563 case ICMD_IFEQ_ICONST:
2564 case ICMD_IFNE_ICONST:
2565 case ICMD_IFLT_ICONST:
2566 case ICMD_IFGE_ICONST:
2567 case ICMD_IFGT_ICONST:
2568 case ICMD_IFLE_ICONST:
2569 printf("(%d) %d", iptr[1].op1, iptr->val.i);
2572 case ICMD_LADDCONST:
2573 case ICMD_LSUBCONST:
2574 case ICMD_LMULCONST:
2578 case ICMD_LANDCONST:
2580 case ICMD_LXORCONST:
2582 case ICMD_LASTORECONST:
2583 #if defined(__I386__) || defined(__POWERPC__)
2584 printf(" %lld", iptr->val.l);
2586 printf(" %ld", iptr->val.l);
2591 printf(" %f", iptr->val.f);
2595 printf(" %f", iptr->val.d);
2599 case ICMD_AASTORECONST:
2600 printf(" %p", iptr->val.a);
2605 printf(" %d,", ((fieldinfo *) iptr->val.a)->offset);
2606 case ICMD_PUTSTATIC:
2607 case ICMD_GETSTATIC:
2609 utf_fprint(stdout, ((fieldinfo *) iptr->val.a)->class->name);
2611 utf_fprint(stdout, ((fieldinfo *) iptr->val.a)->name);
2613 utf_fprint(stdout, ((fieldinfo *) iptr->val.a)->descriptor);
2617 case ICMD_PUTSTATICCONST:
2618 case ICMD_PUTFIELDCONST:
2619 switch (iptr[1].op1) {
2621 printf(" %d,", iptr->val.i);
2624 #if defined(__I386__) || defined(__POWERPC__)
2625 printf(" %lld,", iptr->val.l);
2627 printf(" %ld,", iptr->val.l);
2631 printf(" %p,", iptr->val.a);
2634 printf(" %g,", iptr->val.f);
2637 printf(" %g,", iptr->val.d);
2640 if (iptr->opc == ICMD_PUTFIELDCONST)
2641 printf(" %d,", ((fieldinfo *) iptr[1].val.a)->offset);
2643 utf_fprint(stdout, ((fieldinfo *) iptr[1].val.a)->class->name);
2645 utf_fprint(stdout, ((fieldinfo *) iptr[1].val.a)->name);
2647 utf_fprint(stdout, ((fieldinfo *) iptr[1].val.a)->descriptor);
2652 printf(" %d + %d", iptr->op1, iptr->val.i);
2687 printf(" %d", iptr->op1);
2693 ((classinfo *) iptr->val.a)->name);
2697 switch (iptr->op1) {
2725 case ICMD_ANEWARRAY:
2729 ((classinfo *) iptr->val.a)->name);
2733 case ICMD_MULTIANEWARRAY:
2736 printf(" %d ",iptr->op1);
2737 vft = (vftbl_t *)iptr->val.a;
2739 utf_fprint(stdout,vft->class->name);
2745 case ICMD_CHECKCAST:
2746 case ICMD_INSTANCEOF:
2748 classinfo *c = iptr->val.a;
2749 if (c->flags & ACC_INTERFACE)
2750 printf(" (INTERFACE) ");
2752 printf(" (CLASS,%3d) ", c->vftbl->diffval);
2753 utf_fprint(stdout, c->name);
2757 case ICMD_INLINE_START:
2758 printf("\t\t\t%s.%s%s depth=%i",iptr->method->class->name->text,iptr->method->name->text,iptr->method->descriptor->text, iptr->op1);
2760 case ICMD_INLINE_END:
2766 printf(" %s", icmd_builtin_name((functionptr) iptr->val.fp));
2769 case ICMD_INVOKESPECIAL:
2770 #if defined(__X86_64__)
2773 ((unresolved_method *) iptr->target)->methodref->classref->name);
2776 ((unresolved_method *) iptr->target)->methodref->name);
2780 ((methodinfo *) iptr->val.a)->class->name);
2783 ((methodinfo *) iptr->val.a)->name);
2787 case ICMD_INVOKEVIRTUAL:
2788 /* case ICMD_INVOKESPECIAL: */
2789 case ICMD_INVOKESTATIC:
2790 case ICMD_INVOKEINTERFACE:
2793 ((methodinfo *) iptr->val.a)->class->name);
2796 ((methodinfo *) iptr->val.a)->name);
2805 if (deadcode || !iptr->target)
2806 printf("(%d) op1=%d", iptr->val.i, iptr->op1);
2808 printf("(%d) L%03d", iptr->val.i, ((basicblock *) iptr->target)->debug_nr);
2817 if (deadcode || !iptr->target)
2818 #if defined(__I386__) || defined(__POWERPC__)
2819 printf("(%lld) op1=%d", iptr->val.l, iptr->op1);
2821 printf("(%ld) op1=%d", iptr->val.l, iptr->op1);
2824 #if defined(__I386__) || defined(__POWERPC__)
2825 printf("(%lld) L%03d", iptr->val.l, ((basicblock *) iptr->target)->debug_nr);
2827 printf("(%ld) L%03d", iptr->val.l, ((basicblock *) iptr->target)->debug_nr);
2834 case ICMD_IFNONNULL:
2835 case ICMD_IF_ICMPEQ:
2836 case ICMD_IF_ICMPNE:
2837 case ICMD_IF_ICMPLT:
2838 case ICMD_IF_ICMPGE:
2839 case ICMD_IF_ICMPGT:
2840 case ICMD_IF_ICMPLE:
2841 case ICMD_IF_LCMPEQ:
2842 case ICMD_IF_LCMPNE:
2843 case ICMD_IF_LCMPLT:
2844 case ICMD_IF_LCMPGE:
2845 case ICMD_IF_LCMPGT:
2846 case ICMD_IF_LCMPLE:
2847 case ICMD_IF_ACMPEQ:
2848 case ICMD_IF_ACMPNE:
2849 if (deadcode || !iptr->target)
2850 printf(" op1=%d", iptr->op1);
2852 printf(" L%03d", ((basicblock *) iptr->target)->debug_nr);
2855 case ICMD_TABLESWITCH:
2856 s4ptr = (s4*)iptr->val.a;
2858 if (deadcode || !iptr->target) {
2859 printf(" %d;", *s4ptr);
2862 tptr = (void **) iptr->target;
2863 printf(" L%03d;", ((basicblock *) *tptr)->debug_nr);
2867 s4ptr++; /* skip default */
2868 j = *s4ptr++; /* low */
2869 j = *s4ptr++ - j; /* high */
2871 if (deadcode || !*tptr)
2872 printf(" %d", *s4ptr++);
2874 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2881 case ICMD_LOOKUPSWITCH:
2882 s4ptr = (s4*)iptr->val.a;
2884 if (deadcode || !iptr->target) {
2885 printf(" %d;", *s4ptr);
2888 tptr = (void **) iptr->target;
2889 printf(" L%03d;", ((basicblock *) *tptr)->debug_nr);
2892 s4ptr++; /* default */
2893 j = *s4ptr++; /* count */
2896 if (deadcode || !*tptr) {
2897 s4ptr++; /* skip value */
2898 printf(" %d",*s4ptr++);
2901 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2907 printf(" Line number: %d, method:",iptr->line);
2909 utf_display(iptr->method->class->name);
2911 utf_display(iptr->method->name); */
2916 * These are local overrides for various environment variables in Emacs.
2917 * Please do not remove this and leave it at the end of the file, where
2918 * Emacs will automagically detect them.
2919 * ---------------------------------------------------------------------
2922 * indent-tabs-mode: t