1 /* src/vm/jit/parse.c - parser for JavaVM to intermediate code translation
3 Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, 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., 51 Franklin Street, Fifth Floor, Boston, MA
25 Contact: cacao@cacaojvm.org
29 Changes: Carolyn Oates
34 $Id: parse.c 5302 2006-09-05 10:37:26Z edwin $
46 #include "mm/memory.h"
47 #include "native/native.h"
49 #if defined(ENABLE_THREADS)
50 # include "threads/native/lock.h"
53 #include "toolbox/logging.h"
54 #include "vm/builtin.h"
55 #include "vm/exceptions.h"
56 #include "vm/global.h"
57 #include "vm/linker.h"
58 #include "vm/loader.h"
59 #include "vm/resolve.h"
60 #include "vm/options.h"
61 #include "vm/statistics.h"
62 #include "vm/stringlocal.h"
64 #include "vm/jit/asmpart.h"
65 #include "vm/jit/jit.h"
66 #include "vm/jit/parse.h"
67 #include "vm/jit/patcher.h"
68 #include "vm/jit/loop/loop.h"
70 /*******************************************************************************
72 function 'parse' scans the JavaVM code and generates intermediate code
74 During parsing the block index table is used to store at bit pos 0
75 a flag which marks basic block starts and at position 1 to 31 the
76 intermediate instruction index. After parsing the block index table
77 is scanned, for marked positions a block is generated and the block
78 number is stored in the block index table.
80 *******************************************************************************/
82 static exceptiontable * new_fillextable(
85 exceptiontable *extable,
86 exceptiontable *raw_extable,
87 int exceptiontablelength,
92 if (exceptiontablelength == 0)
95 b_count = *block_count;
97 for (src = exceptiontablelength-1; src >=0; src--) {
98 /* the start of the handled region becomes a basic block start */
99 p = raw_extable[src].startpc;
100 CHECK_BYTECODE_INDEX(p);
101 extable->startpc = p;
102 NEW_MARK_BASICBLOCK(p);
104 p = raw_extable[src].endpc; /* see JVM Spec 4.7.3 */
105 CHECK_BYTECODE_INDEX_EXCLUSIVE(p);
107 #if defined(ENABLE_VERIFIER)
108 if (p <= raw_extable[src].startpc) {
109 exceptions_throw_verifyerror(m,
110 "Invalid exception handler range");
116 /* end of handled region becomes a basic block boundary */
117 /* (If it is the bytecode end, we'll use the special */
118 /* end block that is created anyway.) */
119 if (p < m->jcodelength)
120 NEW_MARK_BASICBLOCK(p);
122 /* the start of the handler becomes a basic block start */
123 p = raw_extable[src].handlerpc;
124 CHECK_BYTECODE_INDEX(p);
125 extable->handlerpc = p;
126 NEW_MARK_BASICBLOCK(p);
128 extable->catchtype = raw_extable[src].catchtype;
129 extable->next = NULL;
130 extable->down = &extable[1];
134 *block_count = b_count;
139 #if defined(ENABLE_VERIFIER)
140 throw_invalid_bytecode_index:
141 exceptions_throw_verifyerror(m,
142 "Illegal bytecode index in exception table");
147 /*** macro for checking the length of the bytecode ***/
149 #if defined(ENABLE_VERIFIER)
150 #define CHECK_END_OF_BYTECODE(neededlength) \
152 if ((neededlength) > m->jcodelength) \
153 goto throw_unexpected_end_of_bytecode; \
155 #else /* !ENABLE_VERIFIER */
156 #define CHECK_END_OF_BYTECODE(neededlength)
157 #endif /* ENABLE_VERIFIER */
159 bool new_parse(jitdata *jd)
161 methodinfo *m; /* method being parsed */
164 int p; /* java instruction counter */
165 int nextp; /* start of next java instruction */
166 int opcode; /* java opcode */
167 int i; /* temporary for different uses (ctrs) */
168 int ipc = 0; /* intermediate instruction counter */
169 int b_count = 0; /* basic block counter */
170 int s_count = 0; /* stack element counter */
171 bool blockend = false; /* true if basic block end has been reached */
172 bool iswide = false; /* true if last instruction was a wide */
173 new_instruction *iptr; /* current ptr into instruction array */
174 u1 *instructionstart; /* 1 for pcs which are valid instr. starts */
175 constant_classref *cr;
176 constant_classref *compr;
178 builtintable_entry *bte;
181 unresolved_method *um;
182 resolve_result_t result;
189 /* get required compiler data */
195 /* allocate instruction array and block index table */
197 /* 1 additional for end ipc */
198 jd->new_basicblockindex = DMNEW(s4, m->jcodelength + 1);
199 memset(jd->new_basicblockindex, 0, sizeof(s4) * (m->jcodelength + 1));
201 instructionstart = DMNEW(u1, m->jcodelength + 1);
202 memset(instructionstart, 0, sizeof(u1) * (m->jcodelength + 1));
204 /* IMPORTANT: We assume that parsing creates at most one instruction per */
205 /* byte of original bytecode! */
207 iptr = jd->new_instructions = DMNEW(new_instruction, m->jcodelength);
209 /* compute branch targets of exception table */
211 if (!new_fillextable(jd, m,
212 &(cd->exceptiontable[cd->exceptiontablelength-1]),
214 m->exceptiontablelength,
220 s_count = 1 + m->exceptiontablelength; /* initialize stack element counter */
222 #if defined(ENABLE_THREADS)
223 if (checksync && (m->flags & ACC_SYNCHRONIZED))
224 jd->isleafmethod = false;
227 /* setup line number info */
232 if (m->linenumbercount == 0) {
236 linepcchange = m->linenumbers[0].start_pc;
239 /*** LOOP OVER ALL BYTECODE INSTRUCTIONS **********************************/
241 for (p = 0; p < m->jcodelength; p = nextp) {
243 /* mark this position as a valid instruction start */
245 instructionstart[p] = 1;
247 /* change the current line number, if necessary */
249 /* XXX rewrite this using pointer arithmetic */
251 if (linepcchange == p) {
252 if (m->linenumbercount > lineindex) {
254 currentline = m->linenumbers[lineindex].line_number;
256 if (lineindex < m->linenumbercount) {
257 linepcchange = m->linenumbers[lineindex].start_pc;
258 if (linepcchange == p)
259 goto next_linenumber;
264 /* fetch next opcode */
266 opcode = SUCK_BE_U1(m->jcode + p);
268 /* store intermediate instruction count (bit 0 mark block starts) */
270 jd->new_basicblockindex[p] |= (ipc << 1);
272 /* some compilers put a JAVA_NOP after a blockend instruction */
274 if (blockend && (opcode != JAVA_NOP)) {
275 /* start new block */
277 NEW_MARK_BASICBLOCK(p);
281 /* compute next instruction start */
283 nextp = p + jcommandsize[opcode];
285 CHECK_END_OF_BYTECODE(nextp);
287 /* add stack elements produced by this instruction */
289 s_count += stackreq[opcode];
291 /* translate this bytecode instruction */
298 /* pushing constants onto the stack ***********************************/
301 NEW_OP_LOADCONST_I(SUCK_BE_S1(m->jcode + p + 1));
305 NEW_OP_LOADCONST_I(SUCK_BE_S2(m->jcode + p + 1));
309 i = SUCK_BE_U1(m->jcode + p + 1);
310 goto pushconstantitem;
314 i = SUCK_BE_U2(m->jcode + p + 1);
318 #if defined(ENABLE_VERIFIER)
319 if (i >= m->class->cpcount) {
320 exceptions_throw_verifyerror(m,
321 "Attempt to access constant outside range");
326 switch (m->class->cptags[i]) {
327 case CONSTANT_Integer:
328 NEW_OP_LOADCONST_I(((constant_integer *) (m->class->cpinfos[i]))->value);
331 NEW_OP_LOADCONST_L(((constant_long *) (m->class->cpinfos[i]))->value);
334 NEW_OP_LOADCONST_F(((constant_float *) (m->class->cpinfos[i]))->value);
336 case CONSTANT_Double:
337 NEW_OP_LOADCONST_D(((constant_double *) (m->class->cpinfos[i]))->value);
339 case CONSTANT_String:
340 NEW_OP_LOADCONST_STRING(literalstring_new((utf *) (m->class->cpinfos[i])));
343 cr = (constant_classref *) (m->class->cpinfos[i]);
345 if (!resolve_classref(m, cr, resolveLazy, true,
349 /* if not resolved, c == NULL */
351 NEW_OP_LOADCONST_CLASSINFO_OR_CLASSREF(c, cr, 0 /* no extra flags */);
355 #if defined(ENABLE_VERIFIER)
357 exceptions_throw_verifyerror(m,
358 "Invalid constant type to push");
364 case JAVA_ACONST_NULL:
365 NEW_OP_LOADCONST_NULL();
375 NEW_OP_LOADCONST_I(opcode - JAVA_ICONST_0);
380 NEW_OP_LOADCONST_L(opcode - JAVA_LCONST_0);
386 NEW_OP_LOADCONST_F(opcode - JAVA_FCONST_0);
391 NEW_OP_LOADCONST_D(opcode - JAVA_DCONST_0);
394 /* local variable access instructions *********************************/
399 if (iswide == false) {
400 i = SUCK_BE_U1(m->jcode + p + 1);
403 i = SUCK_BE_U2(m->jcode + p + 1);
407 NEW_OP_LOAD_ONEWORD(opcode, i);
412 if (iswide == false) {
413 i = SUCK_BE_U1(m->jcode + p + 1);
416 i = SUCK_BE_U2(m->jcode + p + 1);
420 NEW_OP_LOAD_TWOWORD(opcode, i);
427 NEW_OP_LOAD_ONEWORD(ICMD_ILOAD, opcode - JAVA_ILOAD_0);
434 NEW_OP_LOAD_TWOWORD(ICMD_LLOAD, opcode - JAVA_LLOAD_0);
441 NEW_OP_LOAD_ONEWORD(ICMD_FLOAD, opcode - JAVA_FLOAD_0);
448 NEW_OP_LOAD_TWOWORD(ICMD_DLOAD, opcode - JAVA_DLOAD_0);
455 NEW_OP_LOAD_ONEWORD(ICMD_ALOAD, opcode - JAVA_ALOAD_0);
461 if (iswide == false) {
462 i = SUCK_BE_U1(m->jcode + p + 1);
465 i = SUCK_BE_U2(m->jcode + p + 1);
469 NEW_OP_STORE_ONEWORD(opcode, i);
474 if (iswide == false) {
475 i = SUCK_BE_U1(m->jcode + p + 1);
478 i = SUCK_BE_U2(m->jcode + p + 1);
482 NEW_OP_STORE_TWOWORD(opcode, i);
489 NEW_OP_STORE_ONEWORD(ICMD_ISTORE, opcode - JAVA_ISTORE_0);
496 NEW_OP_STORE_TWOWORD(ICMD_LSTORE, opcode - JAVA_LSTORE_0);
503 NEW_OP_STORE_ONEWORD(ICMD_FSTORE, opcode - JAVA_FSTORE_0);
510 NEW_OP_STORE_TWOWORD(ICMD_DSTORE, opcode - JAVA_DSTORE_0);
517 NEW_OP_STORE_ONEWORD(ICMD_ASTORE, opcode - JAVA_ASTORE_0);
524 if (iswide == false) {
525 i = SUCK_BE_U1(m->jcode + p + 1);
526 v = SUCK_BE_S1(m->jcode + p + 2);
530 i = SUCK_BE_U2(m->jcode + p + 1);
531 v = SUCK_BE_S2(m->jcode + p + 3);
536 NEW_OP_LOCALINDEX_I(opcode, i, v);
540 /* wider index for loading, storing and incrementing ******************/
547 /* managing arrays ****************************************************/
550 switch (SUCK_BE_S1(m->jcode + p + 1)) {
552 bte = builtintable_get_internal(BUILTIN_newarray_boolean);
555 bte = builtintable_get_internal(BUILTIN_newarray_char);
558 bte = builtintable_get_internal(BUILTIN_newarray_float);
561 bte = builtintable_get_internal(BUILTIN_newarray_double);
564 bte = builtintable_get_internal(BUILTIN_newarray_byte);
567 bte = builtintable_get_internal(BUILTIN_newarray_short);
570 bte = builtintable_get_internal(BUILTIN_newarray_int);
573 bte = builtintable_get_internal(BUILTIN_newarray_long);
575 #if defined(ENABLE_VERIFIER)
577 exceptions_throw_verifyerror(m, "Invalid array-type to create");
581 NEW_OP_BUILTIN_CHECK_EXCEPTION(bte);
585 i = SUCK_BE_U2(m->jcode + p + 1);
586 compr = (constant_classref *) class_getconstant(m->class, i, CONSTANT_Class);
590 if (!(cr = class_get_classref_multiarray_of(1, compr)))
593 if (!resolve_classref(m, cr, resolveLazy, true, true, &c))
596 NEW_OP_LOADCONST_CLASSINFO_OR_CLASSREF(c, cr, INS_FLAG_NOCHECK);
597 bte = builtintable_get_internal(BUILTIN_newarray);
598 NEW_OP_BUILTIN_CHECK_EXCEPTION(bte);
602 case JAVA_MULTIANEWARRAY:
603 jd->isleafmethod = false;
604 i = SUCK_BE_U2(m->jcode + p + 1);
606 s4 v = SUCK_BE_U1(m->jcode + p + 3);
608 cr = (constant_classref *) class_getconstant(m->class, i, CONSTANT_Class);
612 if (!resolve_classref(m, cr, resolveLazy, true, true, &c))
615 /* if unresolved, c == NULL */
617 iptr->s1.argcount = v;
618 NEW_OP_S3_CLASSINFO_OR_CLASSREF(opcode, c, cr, 0 /* flags */);
622 /* control flow instructions ******************************************/
641 i = p + SUCK_BE_S2(m->jcode + p + 1);
642 CHECK_BYTECODE_INDEX(i);
643 NEW_MARK_BASICBLOCK(i);
645 NEW_OP_INSINDEX(opcode, i);
649 i = p + SUCK_BE_S4(m->jcode + p + 1);
650 CHECK_BYTECODE_INDEX(i);
651 NEW_MARK_BASICBLOCK(i);
653 NEW_OP_INSINDEX(opcode, i);
657 i = p + SUCK_BE_S2(m->jcode + p + 1);
659 CHECK_BYTECODE_INDEX(i);
660 NEW_MARK_BASICBLOCK(i);
662 NEW_OP_PREPARE_ZEROFLAGS(JAVA_JSR);
663 iptr->sx.s23.s3.jsrtarget.insindex = i;
668 i = p + SUCK_BE_S4(m->jcode + p + 1);
672 if (iswide == false) {
673 i = SUCK_BE_U1(m->jcode + p + 1);
676 i = SUCK_BE_U2(m->jcode + p + 1);
682 NEW_OP_LOAD_ONEWORD(opcode, i);
692 /* XXX ARETURN will need a flag in the typechecker */
698 /* XXX ATHROW will need a flag in the typechecker */
703 /* table jumps ********************************************************/
705 case JAVA_LOOKUPSWITCH:
708 lookup_target_t *lookup;
709 #if defined(ENABLE_VERIFIER)
713 nextp = ALIGN((p + 1), 4);
715 CHECK_END_OF_BYTECODE(nextp + 8);
717 NEW_OP_PREPARE_ZEROFLAGS(opcode);
721 j = p + SUCK_BE_S4(m->jcode + nextp);
722 iptr->sx.s23.s3.lookupdefault.insindex = j;
724 CHECK_BYTECODE_INDEX(j);
725 NEW_MARK_BASICBLOCK(j);
727 /* number of pairs */
729 num = SUCK_BE_U4(m->jcode + nextp);
730 iptr->sx.s23.s2.lookupcount = num;
733 /* allocate the intermediate code table */
735 lookup = DMNEW(lookup_target_t, num);
736 iptr->dst.lookup = lookup;
738 /* iterate over the lookup table */
740 CHECK_END_OF_BYTECODE(nextp + 8 * num);
742 for (i = 0; i < num; i++) {
745 j = SUCK_BE_S4(m->jcode + nextp);
750 #if defined(ENABLE_VERIFIER)
751 /* check if the lookup table is sorted correctly */
753 if (i && (j <= prevvalue)) {
754 exceptions_throw_verifyerror(m, "Unsorted lookup switch");
761 j = p + SUCK_BE_S4(m->jcode + nextp);
762 lookup->target.insindex = j;
765 CHECK_BYTECODE_INDEX(j);
766 NEW_MARK_BASICBLOCK(j);
774 case JAVA_TABLESWITCH:
778 branch_target_t *table;
781 nextp = ALIGN((p + 1), 4);
783 CHECK_END_OF_BYTECODE(nextp + 12);
785 NEW_OP_PREPARE_ZEROFLAGS(opcode);
789 deftarget = p + SUCK_BE_S4(m->jcode + nextp);
791 CHECK_BYTECODE_INDEX(deftarget);
792 NEW_MARK_BASICBLOCK(deftarget);
796 j = SUCK_BE_S4(m->jcode + nextp);
797 iptr->sx.s23.s2.tablelow = j;
802 num = SUCK_BE_S4(m->jcode + nextp);
803 iptr->sx.s23.s3.tablehigh = num;
806 /* calculate the number of table entries */
810 #if defined(ENABLE_VERIFIER)
812 exceptions_throw_verifyerror(m,
813 "invalid TABLESWITCH: upper bound < lower bound");
817 /* create the intermediate code table */
818 /* the first entry is the default target */
820 table = MNEW(branch_target_t, 1 + num);
821 iptr->dst.table = table;
822 (table++)->insindex = deftarget;
824 /* iterate over the target table */
826 CHECK_END_OF_BYTECODE(nextp + 4 * num);
828 for (i = 0; i < num; i++) {
829 j = p + SUCK_BE_S4(m->jcode + nextp);
830 (table++)->insindex = j;
832 CHECK_BYTECODE_INDEX(j);
833 NEW_MARK_BASICBLOCK(j);
841 /* load and store of object fields ************************************/
845 jd->isleafmethod = false;
854 unresolved_field *uf;
856 i = SUCK_BE_U2(m->jcode + p + 1);
857 fr = class_getconstant(m->class, i, CONSTANT_Fieldref);
861 NEW_OP_PREPARE_ZEROFLAGS(opcode);
862 iptr->sx.s23.s3.fmiref = fr;
864 /* only with -noverify, otherwise the typechecker does this */
866 #if defined(ENABLE_VERIFIER)
867 if (!JITDATA_HAS_FLAG_VERIFY(jd)) {
869 result = new_resolve_field_lazy(iptr, m);
870 if (result == resolveFailed)
873 if (result != resolveSucceeded) {
874 uf = new_create_unresolved_field(m->class, m, iptr);
879 /* store the unresolved_field pointer */
881 iptr->sx.s23.s3.uf = uf;
882 iptr->flags.bits = INS_FLAG_UNRESOLVED;
884 #if defined(ENABLE_VERIFIER)
892 /* method invocation **************************************************/
894 case JAVA_INVOKESTATIC:
895 i = SUCK_BE_U2(m->jcode + p + 1);
896 mr = class_getconstant(m->class, i, CONSTANT_Methodref);
900 md = mr->parseddesc.md;
903 if (!descriptor_params_from_paramtypes(md, ACC_STATIC))
908 case JAVA_INVOKEINTERFACE:
909 i = SUCK_BE_U2(m->jcode + p + 1);
911 mr = class_getconstant(m->class, i,
912 CONSTANT_InterfaceMethodref);
914 goto invoke_nonstatic_method;
916 case JAVA_INVOKESPECIAL:
917 case JAVA_INVOKEVIRTUAL:
918 i = SUCK_BE_U2(m->jcode + p + 1);
919 mr = class_getconstant(m->class, i, CONSTANT_Methodref);
921 invoke_nonstatic_method:
925 md = mr->parseddesc.md;
928 if (!descriptor_params_from_paramtypes(md, 0))
932 jd->isleafmethod = false;
934 NEW_OP_PREPARE_ZEROFLAGS(opcode);
935 iptr->sx.s23.s3.fmiref = mr;
937 /* only with -noverify, otherwise the typechecker does this */
939 #if defined(ENABLE_VERIFIER)
940 if (!JITDATA_HAS_FLAG_VERIFY(jd)) {
942 result = new_resolve_method_lazy(iptr, m);
943 if (result == resolveFailed)
946 if (result != resolveSucceeded) {
947 um = new_create_unresolved_method(m->class, m, iptr);
952 /* store the unresolved_method pointer */
954 iptr->sx.s23.s3.um = um;
955 iptr->flags.bits = INS_FLAG_UNRESOLVED;
957 #if defined(ENABLE_VERIFIER)
963 /* instructions taking class arguments ********************************/
966 i = SUCK_BE_U2(m->jcode + p + 1);
967 cr = (constant_classref *) class_getconstant(m->class, i, CONSTANT_Class);
971 if (!resolve_classref(m, cr, resolveLazy, true, true, &c))
974 NEW_OP_LOADCONST_CLASSINFO_OR_CLASSREF(c, cr, INS_FLAG_NOCHECK);
975 bte = builtintable_get_internal(BUILTIN_new);
976 NEW_OP_BUILTIN_CHECK_EXCEPTION(bte);
981 i = SUCK_BE_U2(m->jcode + p + 1);
982 cr = (constant_classref *) class_getconstant(m->class, i, CONSTANT_Class);
986 if (!resolve_classref(m, cr, resolveLazy, true, true, &c))
989 if (cr->name->text[0] == '[') {
990 /* array type cast-check */
991 flags = INS_FLAG_ARRAY;
992 jd->isleafmethod = false;
995 /* object type cast-check */
998 NEW_OP_S3_CLASSINFO_OR_CLASSREF(opcode, c, cr, flags);
1001 case JAVA_INSTANCEOF:
1002 i = SUCK_BE_U2(m->jcode + p + 1);
1003 cr = (constant_classref *) class_getconstant(m->class, i, CONSTANT_Class);
1007 if (!resolve_classref(m, cr, resolveLazy, true, true, &c))
1010 if (cr->name->text[0] == '[') {
1011 /* array type cast-check */
1012 NEW_OP_LOADCONST_CLASSINFO_OR_CLASSREF(c, cr, INS_FLAG_NOCHECK);
1013 bte = builtintable_get_internal(BUILTIN_arrayinstanceof);
1014 NEW_OP_BUILTIN_NO_EXCEPTION(bte);
1018 /* object type cast-check */
1019 NEW_OP_S3_CLASSINFO_OR_CLASSREF(opcode, c, cr, 0 /* flags*/);
1023 /* synchronization instructions ***************************************/
1025 case JAVA_MONITORENTER:
1026 #if defined(ENABLE_THREADS)
1028 /* XXX null check */
1029 bte = builtintable_get_internal(LOCK_monitor_enter);
1030 NEW_OP_BUILTIN_NO_EXCEPTION(bte);
1035 NEW_OP(ICMD_CHECKNULL_POP);
1039 case JAVA_MONITOREXIT:
1040 #if defined(ENABLE_THREADS)
1042 /* XXX null check */
1043 bte = builtintable_get_internal(LOCK_monitor_exit);
1044 NEW_OP_BUILTIN_CHECK_EXCEPTION(bte);
1049 NEW_OP(ICMD_CHECKNULL_POP);
1053 /* arithmetic instructions that may become builtin functions **********/
1056 #if !SUPPORT_DIVISION
1057 bte = builtintable_get_internal(BUILTIN_idiv);
1058 NEW_OP_BUILTIN_ARITHMETIC(opcode, bte);
1065 #if !SUPPORT_DIVISION
1066 bte = builtintable_get_internal(BUILTIN_irem);
1067 NEW_OP_BUILTIN_ARITHMETIC(opcode, bte);
1074 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1075 bte = builtintable_get_internal(BUILTIN_ldiv);
1076 NEW_OP_BUILTIN_ARITHMETIC(opcode, bte);
1083 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1084 bte = builtintable_get_internal(BUILTIN_lrem);
1085 NEW_OP_BUILTIN_ARITHMETIC(opcode, bte);
1092 #if defined(__I386__)
1095 bte = builtintable_get_internal(BUILTIN_frem);
1096 NEW_OP_BUILTIN_NO_EXCEPTION(bte);
1101 #if defined(__I386__)
1104 bte = builtintable_get_internal(BUILTIN_drem);
1105 NEW_OP_BUILTIN_NO_EXCEPTION(bte);
1110 #if defined(__ALPHA__)
1112 bte = builtintable_get_internal(BUILTIN_f2i);
1113 NEW_OP_BUILTIN_NO_EXCEPTION(bte);
1123 #if defined(__ALPHA__)
1125 bte = builtintable_get_internal(BUILTIN_f2l);
1126 NEW_OP_BUILTIN_NO_EXCEPTION(bte);
1136 #if defined(__ALPHA__)
1138 bte = builtintable_get_internal(BUILTIN_d2i);
1139 NEW_OP_BUILTIN_NO_EXCEPTION(bte);
1149 #if defined(__ALPHA__)
1151 bte = builtintable_get_internal(BUILTIN_d2l);
1152 NEW_OP_BUILTIN_NO_EXCEPTION(bte);
1161 /* invalid opcodes ****************************************************/
1163 /* check for invalid opcodes if the verifier is enabled */
1164 #if defined(ENABLE_VERIFIER)
1165 case JAVA_BREAKPOINT:
1166 exceptions_throw_verifyerror(m, "Quick instructions shouldn't appear, yet.");
1169 case 186: /* unused opcode */
1223 exceptions_throw_verifyerror(m, "Illegal opcode %d at instr %d\n",
1227 #endif /* defined(ENABLE_VERIFIER) */
1229 /* opcodes that don't require translation *****************************/
1232 /* straight-forward translation to ICMD */
1238 /* verifier checks ****************************************************/
1240 #if defined(ENABLE_VERIFIER)
1241 /* If WIDE was used correctly, iswide should have been reset by now. */
1243 exceptions_throw_verifyerror(m,
1244 "Illegal instruction: WIDE before incompatible opcode");
1247 #endif /* defined(ENABLE_VERIFIER) */
1251 /*** END OF LOOP **********************************************************/
1253 /* assert that we did not write more ICMDs than allocated */
1255 assert(ipc == (iptr - jd->new_instructions));
1256 assert(ipc <= m->jcodelength);
1258 /*** verifier checks ******************************************************/
1260 #if defined(ENABLE_VERIFIER)
1261 if (p != m->jcodelength) {
1262 exceptions_throw_verifyerror(m,
1263 "Command-sequence crosses code-boundary");
1268 exceptions_throw_verifyerror(m, "Falling off the end of the code");
1271 #endif /* defined(ENABLE_VERIFIER) */
1273 /*** setup the methodinfo, allocate stack and basic blocks ****************/
1275 /* adjust block count if target 0 is not first intermediate instruction */
1277 if (!jd->new_basicblockindex[0] || (jd->new_basicblockindex[0] > 1))
1280 /* copy local to method variables */
1282 jd->new_instructioncount = ipc;
1283 jd->new_basicblockcount = b_count;
1284 jd->new_stackcount = s_count + jd->new_basicblockcount * m->maxstack; /* in-stacks */
1286 /* allocate stack table */
1288 jd->new_stack = DMNEW(stackelement, jd->new_stackcount);
1290 /* build basic block list */
1292 bptr = jd->new_basicblocks = DMNEW(basicblock, b_count + 1); /* one more for end ipc */
1294 /* zero out all basic block structures */
1296 MZERO(bptr, basicblock, b_count + 1);
1299 jd->new_c_debug_nr = 0;
1301 /* additional block if target 0 is not first intermediate instruction */
1303 if (!jd->new_basicblockindex[0] || (jd->new_basicblockindex[0] > 1)) {
1304 BASICBLOCK_INIT(bptr, m);
1306 bptr->iinstr = /* XXX */ (instruction *) jd->new_instructions;
1307 /* bptr->icount is set when the next block is allocated */
1311 bptr[-1].next = bptr;
1314 /* allocate blocks */
1316 for (p = 0; p < m->jcodelength; p++) {
1317 if (jd->new_basicblockindex[p] & 1) {
1318 /* Check if this block starts at the beginning of an */
1320 #if defined(ENABLE_VERIFIER)
1321 if (!instructionstart[p]) {
1322 exceptions_throw_verifyerror(m,
1323 "Branch into middle of instruction");
1328 /* allocate the block */
1330 BASICBLOCK_INIT(bptr, m);
1332 bptr->iinstr = /* XXX */ (instruction *) (jd->new_instructions + (jd->new_basicblockindex[p] >> 1));
1334 bptr[-1].icount = /*XXX*/ (new_instruction *)bptr->iinstr - (new_instruction*) bptr[-1].iinstr;
1336 /* bptr->icount is set when the next block is allocated */
1338 jd->new_basicblockindex[p] = b_count;
1342 bptr[-1].next = bptr;
1346 /* set instruction count of last real block */
1349 bptr[-1].icount = (jd->new_instructions + jd->new_instructioncount) - /* XXX */ (new_instruction *) bptr[-1].iinstr;
1352 /* allocate additional block at end */
1354 BASICBLOCK_INIT(bptr,m);
1356 /* set basicblock pointers in exception table */
1358 if (cd->exceptiontablelength > 0) {
1359 cd->exceptiontable[cd->exceptiontablelength - 1].down = NULL;
1362 for (i = 0; i < cd->exceptiontablelength; ++i) {
1363 p = cd->exceptiontable[i].startpc;
1364 cd->exceptiontable[i].start = jd->new_basicblocks + jd->new_basicblockindex[p];
1366 p = cd->exceptiontable[i].endpc;
1367 cd->exceptiontable[i].end = (p == m->jcodelength) ? (jd->new_basicblocks + jd->new_basicblockcount /*+ 1*/) : (jd->new_basicblocks + jd->new_basicblockindex[p]);
1369 p = cd->exceptiontable[i].handlerpc;
1370 cd->exceptiontable[i].handler = jd->new_basicblocks + jd->new_basicblockindex[p];
1373 /* XXX activate this if you want to try inlining */
1375 for (i = 0; i < m->exceptiontablelength; ++i) {
1376 p = m->exceptiontable[i].startpc;
1377 m->exceptiontable[i].start = jd->new_basicblocks + jd->new_basicblockindex[p];
1379 p = m->exceptiontable[i].endpc;
1380 m->exceptiontable[i].end = (p == m->jcodelength) ? (jd->new_basicblocks + jd->new_basicblockcount /*+ 1*/) : (jd->new_basicblocks + jd->new_basicblockindex[p]);
1382 p = m->exceptiontable[i].handlerpc;
1383 m->exceptiontable[i].handler = jd->new_basicblocks + jd->new_basicblockindex[p];
1387 /* everything's ok */
1391 /*** goto labels for throwing verifier exceptions *************************/
1393 #if defined(ENABLE_VERIFIER)
1395 throw_unexpected_end_of_bytecode:
1396 exceptions_throw_verifyerror(m, "Unexpected end of bytecode");
1399 throw_invalid_bytecode_index:
1400 exceptions_throw_verifyerror(m, "Illegal target of branch instruction");
1403 throw_illegal_local_variable_number:
1404 exceptions_throw_verifyerror(m, "Illegal local variable number");
1407 #endif /* ENABLE_VERIFIER */
1412 * These are local overrides for various environment variables in Emacs.
1413 * Please do not remove this and leave it at the end of the file, where
1414 * Emacs will automagically detect them.
1415 * ---------------------------------------------------------------------
1418 * indent-tabs-mode: t
1422 * vim:noexpandtab:sw=4:ts=4: