first part of stacktraces on x86_64
[cacao.git] / src / vm / jit / parse.c
1 /* src/vm/jit/parse.c - parser for JavaVM to intermediate code translation
2
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
7
8    This file is part of CACAO.
9
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.
14
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.
19
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
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Author: Andreas Krall
28
29    Changes: Carolyn Oates
30             Edwin Steiner
31             Joseph Wenninger
32             Christian Thalinger
33
34    $Id: parse.c 2358 2005-04-22 22:01:51Z jowenn $
35
36 */
37
38
39 #include <string.h>
40
41 #include "config.h"
42 #include "types.h"
43 #include "mm/memory.h"
44 #include "native/native.h"
45 #include "toolbox/logging.h"
46 #include "vm/builtin.h"
47 #include "vm/exceptions.h"
48 #include "vm/global.h"
49 #include "vm/linker.h"
50 #include "vm/loader.h"
51 #include "vm/resolve.h"
52 #include "vm/options.h"
53 #include "vm/statistics.h"
54 #include "vm/stringlocal.h"
55 #include "vm/tables.h"
56 #include "vm/jit/asmpart.h"
57 #include "vm/jit/jit.h"
58 #include "vm/jit/parse.h"
59 #include "vm/jit/inline/parseRT.h"
60 #include "vm/jit/inline/parseXTA.h"
61 #include "vm/jit/inline/inline.h"
62 #include "vm/jit/loop/loop.h"
63 #include "vm/jit/inline/parseRTprint.h"
64
65 bool DEBUG = false;
66 bool DEBUG2 = false;
67 bool DEBUG3 = false;
68 bool DEBUG4 = false;  /*opcodes for parse.c*/
69
70
71 /*INLINING*/
72 #define debug_writebranch if (DEBUG2==true) printf("op:: %s i: %d label_index[i]: %d label_index=0x%p\n",opcode_names[opcode], i, label_index[i], (void *)label_index);
73 #define debug_writebranch1
74
75 /*******************************************************************************
76
77         function 'parse' scans the JavaVM code and generates intermediate code
78
79         During parsing the block index table is used to store at bit pos 0
80         a flag which marks basic block starts and at position 1 to 31 the
81         intermediate instruction index. After parsing the block index table
82         is scanned, for marked positions a block is generated and the block
83         number is stored in the block index table.
84
85 *******************************************************************************/
86
87 static exceptiontable* fillextable(methodinfo *m, 
88                 exceptiontable* extable, exceptiontable *raw_extable, 
89                 int exceptiontablelength, 
90                 int *label_index, int *block_count, 
91                 t_inlining_globals *inline_env)
92 {
93         int b_count, p, src, insertBlock;
94         
95         if (exceptiontablelength == 0) 
96                 return extable;
97
98         /*if (m->exceptiontablelength > 0) {
99           METHINFOx(m);
100           printf("m->exceptiontablelength=%i\n",m->exceptiontablelength);
101           panic("exceptiontablelength > 0");
102           }*/
103
104         b_count = *block_count;
105
106         for (src = exceptiontablelength-1; src >=0; src--) {
107                 /* printf("Excepiont table index: %d\n",i); */
108                 p = raw_extable[src].startpc;
109                 if (label_index != NULL) p = label_index[p];
110                 extable->startpc = p;
111                 bound_check(p);
112                 block_insert(p);
113                 
114 /*** if (DEBUG==true){printf("---------------------block_inserted:b_count=%i m->basicblockindex[(p=%i)]=%i=%p\n",b_count,p,m->basicblockindex[(p)],m->basicblockindex[(p)]); 
115   fflush(stdout); } ***/   
116                 p = raw_extable[src].endpc; /* see JVM Spec 4.7.3 */
117                 if (p <= raw_extable[src].startpc)
118                         panic("Invalid exception handler range");
119
120                 if (p >inline_env->method->jcodelength) {
121                         panic("Invalid exception handler end is after code end");
122                 }
123                 if (p<inline_env->method->jcodelength) insertBlock=1; else insertBlock=0;
124                 /*if (label_index !=NULL) printf("%s:translating endpc:%ld to %ld, label_index:%p\n",m->name->text,p,label_index[p],label_index); else
125                         printf("%s:fillextab: endpc:%ld\n",m->name->text,p);*/
126                 if (label_index != NULL) p = label_index[p];
127                 extable->endpc = p;
128                 bound_check1(p);
129                 /*if (p < inline_env->method->jcodelength) {
130                         block_insert(p); }*/
131                 if (insertBlock) block_insert(p);
132
133                 p = raw_extable[src].handlerpc;
134                 if (label_index != NULL) p = label_index[p];
135                 extable->handlerpc = p;
136                 bound_check(p);
137                 block_insert(p);
138
139                 extable->catchtype  = raw_extable[src].catchtype;
140                 extable->next = NULL;
141                 extable->down = &extable[1];
142                 extable--;
143         }
144
145         *block_count = b_count;
146         return extable; /*&extable[i];*/  /* return the next free xtable* */
147 }
148
149
150
151 methodinfo *parse(methodinfo *m, codegendata *cd, t_inlining_globals *inline_env)
152 {
153         int  p;                     /* java instruction counter           */
154         int  nextp;                 /* start of next java instruction     */
155         int  opcode;                /* java opcode                        */
156         int  i;                     /* temporary for different uses (ctrs)*/
157         int  ipc = 0;               /* intermediate instruction counter   */
158         int  b_count = 0;           /* basic block counter                */
159         int  s_count = 0;           /* stack element counter              */
160         bool blockend = false;      /* true if basic block end has been reached   */
161         bool iswide = false;        /* true if last instruction was a wide*/
162         instruction *iptr;          /* current ptr into instruction array */
163         int gp;                     /* global java instruction counter    */
164                                     /* inlining info for current method   */
165
166         inlining_methodinfo *inlinfo = inline_env->inlining_rootinfo;
167         inlining_methodinfo *tmpinlinf;
168         int nextgp = -1;            /* start of next method to be inlined */
169         int *label_index = NULL;    /* label redirection table            */
170         int firstlocal = 0;         /* first local variable of method     */
171         exceptiontable* nextex;     /* points next free entry in extable  */
172         u1 *instructionstart;       /* 1 for pcs which are valid instr. starts    */
173
174         u2 lineindex = 0;
175         u2 currentline = 0;
176         u2 linepcchange = 0;
177
178         u2 skipBasicBlockChange;
179
180 METHINFOt(m,"\nPARSING: ",DEBUG4);
181 if ((opt_rt) || (opt_xta)) {
182   FILE *Missed;
183
184   if (opt_rt)  Missed =  rtMissed;  
185   if (opt_xta) Missed = xtaMissed;  
186
187   if (m->methodUsed != USED) {
188     if (opt_verbose) {
189       printf(" rta/xta missed: "); fflush(stdout);
190       METHINFO(m,opt_verbose);
191       }
192     if ( (Missed = fopen("Missed", "a")) == NULL) {
193       printf("CACAO - rt/xtaMissed file: cant open file to write append \n");
194       }
195     else {
196       utf_fprint(Missed,m->class->name); 
197        fprintf(Missed," "); fflush(Missed);
198       utf_fprint(Missed,m->name);
199        fprintf(Missed," "); fflush(Missed);
200       utf_fprint(Missed,m->descriptor); 
201        fprintf(Missed,"\n"); fflush(Missed);
202       fclose(Missed);
203       }
204    } 
205 }
206         /* INLINING */
207
208         if (useinlining) {
209                 label_index = inlinfo->label_index;
210                 m->maxstack = inline_env->cummaxstack;
211                 /*JOWENN m->exceptiontablelength = inline_env->cumextablelength;*/
212                 tmpinlinf = (inlining_methodinfo*) 
213                                 list_first(inlinfo->inlinedmethods);
214                 if (tmpinlinf != NULL) nextgp = tmpinlinf->startgp;
215         }
216
217 /**** static analysis has to be called before inlining
218         which has to be called before reg_set
219         which has to be called before parse (or ???)
220         will check if method being parsed was analysed here
221         if (opt_xta && opt_verbose) { 
222                 **RT_jit_parse(m);**
223                 printf("XTA requested, not available\n");
224                 }
225         if (opt_vta && opt_verbose)  
226                     printf("VTA requested, not yet implemented\n");
227         ****/ 
228
229         /* allocate instruction array and block index table */
230         
231         /* 1 additional for end ipc * # cum inline methods*/
232         
233         m->basicblockindex = DMNEW(s4, inline_env->cumjcodelength + inline_env->cummethods);
234         memset(m->basicblockindex, 0, sizeof(s4) * (inline_env->cumjcodelength + inline_env->cummethods));
235
236         instructionstart = DMNEW(u1, inline_env->cumjcodelength + inline_env->cummethods);
237         memset(instructionstart, 0, sizeof(u1) * (inline_env->cumjcodelength + inline_env->cummethods));
238
239         /* 1 additional for TRACEBUILTIN and 4 for MONITORENTER/EXIT */
240         /* additional MONITOREXITS are reached by branches which are 3 bytes */
241         
242         iptr = m->instructions = DMNEW(instruction, inline_env->cumjcodelength + 5);
243
244         /* Zero the intermediate instructions array so we don't have any
245          * invalid pointers in it if we cannot finish analyse_stack(). */
246
247         memset(iptr, 0, sizeof(instruction) * (inline_env->cumjcodelength + 5));
248         
249         /* compute branch targets of exception table */
250         /*
251 if (m->exceptiontable == NULL) {
252   printf("m->exceptiontable=NULL\n");fflush(stdout);
253   }
254 else {
255   printf("m->exceptiontable != NULL\n");fflush(stdout);
256   }
257 printf("m->exceptiontablelength=%i, inline_env->method->exceptiontablelength=%i,inline_env->cumextablelength=%i\n",
258 m->exceptiontablelength, inline_env->method->exceptiontablelength,inline_env->cumextablelength);
259         */
260         /*
261 if (m->exceptiontablelength > 0)
262         m->exceptiontable = DMNEW(exceptiontable, m->exceptiontablelength + 1); 
263         */
264
265         nextex = fillextable(m, 
266           &(cd->exceptiontable[cd->exceptiontablelength-1]), m->exceptiontable, m->exceptiontablelength, 
267           label_index, &b_count, inline_env);
268         s_count = 1 + m->exceptiontablelength; /* initialize stack element counter   */
269
270 #if defined(USE_THREADS)
271         if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
272                 m->isleafmethod = false;
273                 inline_env->method->isleafmethod = false;
274         }                       
275 #endif
276
277         /* scan all java instructions */
278         currentline = 0;
279         linepcchange = 0;
280
281         if (m->linenumbercount == 0) {
282                 lineindex = 0;
283                 /*printf("linenumber count == 0\n");*/
284         } else {
285                 linepcchange = m->linenumbers[0].start_pc;
286         }
287
288         skipBasicBlockChange=0;
289         for (p = 0, gp = 0; p < inline_env->method->jcodelength; gp += (nextp - p), p = nextp) {
290           
291                 /* DEBUG */      if (DEBUG==true) printf("----- p:%d gp:%d\n",p,gp);
292
293                 /* mark this position as a valid instruction start */
294                 if (!iswide) {
295                         instructionstart[gp] = 1;
296                         /*log_text("new start of instruction");*/
297                         /*printf ("%s, linepcchange %d,p %d\n",inline_env->method->name->text,linepcchange,p);*/
298                         if (linepcchange==p) {
299                                 if (inline_env->method->linenumbercount > lineindex) {
300                                         currentline = inline_env->method->linenumbers[lineindex].line_number;
301                                         lineindex++;
302                                         if (lineindex < inline_env->method->linenumbercount)
303                                                 linepcchange = inline_env->method->linenumbers[lineindex].start_pc;
304                                         /*printf("Line number changed to: %ld\n",currentline);*/
305                                 }
306                         }
307                 }
308
309                 /*INLINING*/
310                 if ((useinlining) && (gp == nextgp)) {
311                         u1 *tptr;
312                         bool *readonly = NULL;
313                         int argBlockIdx=0;
314
315                         block_insert(gp);               /* JJJJJJJJJJ */
316                         blockend=false;
317                         instructionstart[gp] = 1;
318                         m->basicblockindex[gp] |= (ipc << 1);  /*FIXME: necessary ? */
319
320                         opcode = code_get_u1(p,inline_env->method);
321                         nextp = p += jcommandsize[opcode];
322                         if (nextp > inline_env->method->jcodelength)
323                                 panic("Unexpected end of bytecode");
324                         tmpinlinf = list_first(inlinfo->inlinedmethods);
325                         firstlocal = tmpinlinf->firstlocal;
326                         label_index = tmpinlinf->label_index;
327                         readonly = tmpinlinf->readonly;
328
329                         for (i=0,tptr=tmpinlinf->method->paramtypes;i<tmpinlinf->method->paramcount;i++,tptr++) {
330                                 if ( ((*tptr)==TYPE_LNG) ||
331                                   ((*tptr)==TYPE_DBL) )
332                                         argBlockIdx+=2;
333                                 else
334                                         argBlockIdx++;
335                         }
336
337                         for (i = 0, tptr = tmpinlinf->method->paramtypes + tmpinlinf->method->paramcount - 1; i < tmpinlinf->method->paramcount; i++, tptr--) {
338                                 int op;
339
340                                 if ((i == 0) && inlineparamopt) {
341                                         OP1(ICMD_CLEAR_ARGREN, firstlocal);
342                                 }
343
344                                 if (!inlineparamopt || !readonly[i]) {
345                                         op = ICMD_ISTORE;
346
347                                 } else {
348                                         op = ICMD_READONLY_ARG;
349                                 }
350
351                                 op += *tptr;
352                                 if ( ((*tptr)==TYPE_LNG) ||
353                                   ((*tptr)==TYPE_DBL) )
354                                         argBlockIdx-=2;
355                                 else
356                                         argBlockIdx--;
357
358                                 OP1(op, firstlocal + argBlockIdx);
359                                 /* OP1(op, firstlocal + tmpinlinf->method->paramcount - 1 - i); */
360                                 /* printf("inline argument load operation for local: %ld\n",firstlocal + tmpinlinf->method->paramcount - 1 - i); */
361                         }
362                         skipBasicBlockChange=1;
363 METHINFOt(inline_env->method,"BEFORE SAVE: ",DEBUG);
364                         inlining_save_compiler_variables();
365 METHINFOt(inline_env->method,"AFTER SAVE: ",DEBUG);
366                         inlining_set_compiler_variables(tmpinlinf);
367 METHINFOt(inline_env->method,"AFTER SET :: ",DEBUG);
368 METHINFOt(m,"\n.......Parsing (inlined): ",DEBUG);
369 METHINFO(inline_env->method,DEBUG);
370
371                         OP1(ICMD_INLINE_START,tmpinlinf->level);
372
373                         if (inlinfo->inlinedmethods == NULL) {
374                                 gp = -1;
375                         } else {
376                                 tmpinlinf = list_first(inlinfo->inlinedmethods);
377                                 nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
378                         }
379                         if (inline_env->method->exceptiontablelength > 0) 
380                           nextex = fillextable(m, nextex, 
381                             inline_env->method->exceptiontable, inline_env->method->exceptiontablelength, 
382                             label_index, &b_count, inline_env);
383                         continue;
384                 }
385           
386                 opcode = code_get_u1(p,inline_env->method);            /* fetch op code  */
387          if (DEBUG==true) 
388                 {
389                         printf("Parse p=%i<%i<%i<   opcode=<%i> %s\n",
390                            p, gp, inline_env->jcodelength, opcode, opcode_names[opcode]);
391                         if (label_index)
392                                 printf("label_index[%d]=%d\n",p,label_index[p]);
393                 }
394          /*
395 printf("basicblockindex[gp=%i]=%i=%p ipc=%i=%p shifted ipc=%i=%p\n",
396 gp,m->basicblockindex[gp],m->basicblockindex[gp],ipc,ipc,(ipc<<1),(ipc<<1));
397 fflush(stdout);
398          */
399                 if (!skipBasicBlockChange) {
400                         m->basicblockindex[gp] |= (ipc << 1); /*store intermed cnt*/
401                 } else skipBasicBlockChange=0;
402                 /*
403 printf("basicblockindex[gp=%i]=%i=%p \n",
404 gp,m->basicblockindex[gp],m->basicblockindex[gp]);
405 fflush(stdout);
406                 */
407
408                 if (blockend) {
409                         block_insert(gp);               /* start new block                */
410                         blockend = false;
411                         /*printf("blockend was set: new blockcount: %ld at:%ld\n",b_count,gp);*/
412                 }
413
414                 nextp = p + jcommandsize[opcode];   /* compute next instruction start */
415                 if (nextp > inline_env->method->jcodelength)
416                         panic("Unexpected end of bytecode");
417                 s_count += stackreq[opcode];            /* compute stack element count    */
418 SHOWOPCODE(DEBUG4)
419                 switch (opcode) {
420                 case JAVA_NOP:
421                         break;
422
423                         /* pushing constants onto the stack p */
424
425                 case JAVA_BIPUSH:
426                         LOADCONST_I(code_get_s1(p+1,inline_env->method));
427                         break;
428
429                 case JAVA_SIPUSH:
430                         LOADCONST_I(code_get_s2(p+1,inline_env->method));
431                         break;
432
433                 case JAVA_LDC1:
434                         i = code_get_u1(p+1,inline_env->method);
435
436                         goto pushconstantitem;
437                 case JAVA_LDC2:
438                 case JAVA_LDC2W:
439                         i = code_get_u2(p + 1,inline_env->method);
440
441                 pushconstantitem:
442
443                         if (i >= inline_env->method->class->cpcount) 
444                                 error("Attempt to access constant outside range: %d >= %d", i, inline_env->method->class->cpcount);
445
446                         switch (inline_env->method->class->cptags[i]) {
447                         case CONSTANT_Integer:
448                                 LOADCONST_I(((constant_integer *) (inline_env->method->class->cpinfos[i]))->value);
449                                 break;
450                         case CONSTANT_Long:
451                                 LOADCONST_L(((constant_long *) (inline_env->method->class->cpinfos[i]))->value);
452                                 break;
453                         case CONSTANT_Float:
454                                 LOADCONST_F(((constant_float *) (inline_env->method->class->cpinfos[i]))->value);
455                                 break;
456                         case CONSTANT_Double:
457                                 LOADCONST_D(((constant_double *) (inline_env->method->class->cpinfos[i]))->value);
458                                 break;
459                         case CONSTANT_String:
460                                 LOADCONST_A(literalstring_new((utf *) (inline_env->method->class->cpinfos[i])));
461                                 break;
462                         default: panic("Invalid constant type to push");
463                         }
464                         break;
465
466                 case JAVA_ACONST_NULL:
467                         LOADCONST_A(NULL);
468                         break;
469
470                 case JAVA_ICONST_M1:
471                 case JAVA_ICONST_0:
472                 case JAVA_ICONST_1:
473                 case JAVA_ICONST_2:
474                 case JAVA_ICONST_3:
475                 case JAVA_ICONST_4:
476                 case JAVA_ICONST_5:
477                         LOADCONST_I(opcode - JAVA_ICONST_0);
478                         break;
479
480                 case JAVA_LCONST_0:
481                 case JAVA_LCONST_1:
482                         LOADCONST_L(opcode - JAVA_LCONST_0);
483                         break;
484
485                 case JAVA_FCONST_0:
486                 case JAVA_FCONST_1:
487                 case JAVA_FCONST_2:
488                         LOADCONST_F(opcode - JAVA_FCONST_0);
489                         break;
490
491                 case JAVA_DCONST_0:
492                 case JAVA_DCONST_1:
493                         LOADCONST_D(opcode - JAVA_DCONST_0);
494                         break;
495
496                         /* loading variables onto the stack */
497
498                 case JAVA_ILOAD:
499                 case JAVA_LLOAD:
500                 case JAVA_FLOAD:
501                 case JAVA_DLOAD:
502                 case JAVA_ALOAD:
503                         if (!iswide) {
504                                 i = code_get_u1(p + 1,inline_env->method);
505                         } else {
506                                 i = code_get_u2(p + 1,inline_env->method);
507                                 nextp = p + 3;
508                                 iswide = false;
509                         }
510                         OP1LOAD(opcode, i + firstlocal);
511                         break;
512
513                 case JAVA_ILOAD_0:
514                 case JAVA_ILOAD_1:
515                 case JAVA_ILOAD_2:
516                 case JAVA_ILOAD_3:
517                         OP1LOAD(ICMD_ILOAD, opcode - JAVA_ILOAD_0 + firstlocal);
518                         break;
519
520                 case JAVA_LLOAD_0:
521                 case JAVA_LLOAD_1:
522                 case JAVA_LLOAD_2:
523                 case JAVA_LLOAD_3:
524                         OP1LOAD(ICMD_LLOAD, opcode - JAVA_LLOAD_0 + firstlocal);
525                         break;
526
527                 case JAVA_FLOAD_0:
528                 case JAVA_FLOAD_1:
529                 case JAVA_FLOAD_2:
530                 case JAVA_FLOAD_3:
531                         OP1LOAD(ICMD_FLOAD, opcode - JAVA_FLOAD_0 + firstlocal);
532                         break;
533
534                 case JAVA_DLOAD_0:
535                 case JAVA_DLOAD_1:
536                 case JAVA_DLOAD_2:
537                 case JAVA_DLOAD_3:
538                         OP1LOAD(ICMD_DLOAD, opcode - JAVA_DLOAD_0 + firstlocal);
539                         break;
540
541                 case JAVA_ALOAD_0:
542                 case JAVA_ALOAD_1:
543                 case JAVA_ALOAD_2:
544                 case JAVA_ALOAD_3:
545                         OP1LOAD(ICMD_ALOAD, opcode - JAVA_ALOAD_0 + firstlocal);
546                         break;
547
548                         /* storing stack values into local variables */
549
550                 case JAVA_ISTORE:
551                 case JAVA_LSTORE:
552                 case JAVA_FSTORE:
553                 case JAVA_DSTORE:
554                 case JAVA_ASTORE:
555                         if (!iswide) {
556                                 i = code_get_u1(p + 1,inline_env->method);
557                         } else {
558                                 i = code_get_u2(p + 1,inline_env->method);
559                                 iswide = false;
560                                 nextp = p + 3;
561                         }
562                         OP1STORE(opcode, i + firstlocal);
563                         break;
564
565                 case JAVA_ISTORE_0:
566                 case JAVA_ISTORE_1:
567                 case JAVA_ISTORE_2:
568                 case JAVA_ISTORE_3:
569                         OP1STORE(ICMD_ISTORE, opcode - JAVA_ISTORE_0 + firstlocal);
570                         break;
571
572                 case JAVA_LSTORE_0:
573                 case JAVA_LSTORE_1:
574                 case JAVA_LSTORE_2:
575                 case JAVA_LSTORE_3:
576                         OP1STORE(ICMD_LSTORE, opcode - JAVA_LSTORE_0 + firstlocal);
577                         break;
578
579                 case JAVA_FSTORE_0:
580                 case JAVA_FSTORE_1:
581                 case JAVA_FSTORE_2:
582                 case JAVA_FSTORE_3:
583                         OP1STORE(ICMD_FSTORE, opcode - JAVA_FSTORE_0 + firstlocal);
584                         break;
585
586                 case JAVA_DSTORE_0:
587                 case JAVA_DSTORE_1:
588                 case JAVA_DSTORE_2:
589                 case JAVA_DSTORE_3:
590                         OP1STORE(ICMD_DSTORE, opcode - JAVA_DSTORE_0 + firstlocal);
591                         break;
592
593                 case JAVA_ASTORE_0:
594                 case JAVA_ASTORE_1:
595                 case JAVA_ASTORE_2:
596                 case JAVA_ASTORE_3:
597                         OP1STORE(ICMD_ASTORE, opcode - JAVA_ASTORE_0 + firstlocal);
598                         break;
599
600                 case JAVA_IINC:
601                         {
602                                 int v;
603                                 
604                                 if (!iswide) {
605                                         i = code_get_u1(p + 1,inline_env->method);
606                                         v = code_get_s1(p + 2,inline_env->method);
607
608                                 } else {
609                                         i = code_get_u2(p + 1,inline_env->method);
610                                         v = code_get_s2(p + 3,inline_env->method);
611                                         iswide = false;
612                                         nextp = p + 5;
613                                 }
614                                 INDEX_ONEWORD(i + firstlocal);
615                                 OP2I(opcode, i + firstlocal, v);
616                         }
617                         break;
618
619                         /* wider index for loading, storing and incrementing */
620
621                 case JAVA_WIDE:
622                         iswide = true;
623                         nextp = p + 1;
624                         break;
625
626                         /* managing arrays ************************************************/
627
628                 case JAVA_NEWARRAY:
629                         OP(ICMD_CHECKASIZE);
630                         switch (code_get_s1(p + 1,inline_env->method)) {
631                         case 4:
632                                 BUILTIN1(BUILTIN_newarray_boolean, TYPE_ADR,currentline);
633                                 break;
634                         case 5:
635                                 BUILTIN1(BUILTIN_newarray_char, TYPE_ADR,currentline);
636                                 break;
637                         case 6:
638                                 BUILTIN1(BUILTIN_newarray_float, TYPE_ADR,currentline);
639                                 break;
640                         case 7:
641                                 BUILTIN1(BUILTIN_newarray_double, TYPE_ADR,currentline);
642                                 break;
643                         case 8:
644                                 BUILTIN1(BUILTIN_newarray_byte, TYPE_ADR,currentline);
645                                 break;
646                         case 9:
647                                 BUILTIN1(BUILTIN_newarray_short, TYPE_ADR,currentline);
648                                 break;
649                         case 10:
650                                 BUILTIN1(BUILTIN_newarray_int, TYPE_ADR,currentline);
651                                 break;
652                         case 11:
653                                 BUILTIN1(BUILTIN_newarray_long, TYPE_ADR,currentline);
654                                 break;
655                         default: panic("Invalid array-type to create");
656                         }
657                         OP(ICMD_CHECKEXCEPTION);
658                         break;
659
660                 case JAVA_ANEWARRAY:
661                         OP(ICMD_CHECKASIZE);
662                         i = code_get_u2(p + 1,inline_env->method);
663                         {
664                                 classinfo *component;
665                                 constant_classref *compr;
666                                 constant_classref *cr;
667                                 classinfo         *c;
668
669 #if defined(__X86_64__) || defined(__I386__)
670                                 compr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
671
672                                 if (!(cr = class_get_classref_multiarray_of(1, compr)))
673                                         return NULL;
674
675                                 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, &c))
676                                         return NULL;
677
678                                 if (c) {
679                                         LOADCONST_A_BUILTIN(c->vftbl);
680                                         BUILTIN2(BUILTIN_newarray, TYPE_ADR, currentline);
681
682                                 } else {
683                                         LOADCONST_A_BUILTIN(cr);
684                                         BUILTIN2(asm_wrapper_patcher_BUILTIN_newarray, TYPE_ADR, currentline);
685                                 }
686                                 s_count++;
687 #else
688                                 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
689
690                                 if (!resolve_classref(inline_env->method,
691                                                         cr,resolveEager,true,&component))
692                                         return NULL;
693
694                                 c = class_array_of(component,true);
695                                 if (!c)
696                                         return NULL;
697                                 LOADCONST_A_BUILTIN(c->vftbl);
698                                 s_count++;
699                                 BUILTIN2(BUILTIN_anewarray, TYPE_ADR, currentline);
700 #endif
701                         }
702                         OP(ICMD_CHECKEXCEPTION);
703                         break;
704
705                 case JAVA_MULTIANEWARRAY:
706                         inline_env->method->isleafmethod = false;
707                         i = code_get_u2(p + 1, inline_env->method);
708                         {
709                                 classinfo *component;
710                                 classinfo *c;
711                             constant_classref *cr;
712                                 vftbl_t *arrayvftbl;
713                                 s4 v = code_get_u1(p + 3, inline_env->method);
714
715 #if defined(__X86_64__) || defined(__I386__)
716                                 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
717
718                                 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, &c))
719                                         return NULL;
720
721                                 if (c) {
722                                         OP2AT(opcode, v, c->vftbl, BUILTIN_multianewarray, currentline);
723
724                                 } else {
725                                         OP2AT(opcode, v, cr, asm_wrapper_patcher_BUILTIN_multianewarray, currentline);
726                                 }
727 #else
728 /*                              vftbl *arrayvftbl = */
729 /*                                      ((classinfo *) class_getconstant(class, i, CONSTANT_Class))->vftbl; */
730 /*                              OP2A(opcode, v, arrayvftbl,currentline); */
731
732                                 
733                                 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
734
735                                 if (!resolve_classref_or_classinfo(inline_env->method,
736                                                         CLASSREF_OR_CLASSINFO(cr),resolveEager,true,&component))
737                                         return NULL;
738
739                                 arrayvftbl = component->vftbl;
740                                 OP2A(opcode, v, arrayvftbl, currentline);
741
742 /*                              classinfo *arrayclass = */
743 /*                                      (classinfo *) class_getconstant(class, i, CONSTANT_Class); */
744 /*                              OP2A(opcode, v, arrayclass, currentline); */
745 #endif
746                         }
747                         break;
748
749                 case JAVA_IFEQ:
750                 case JAVA_IFLT:
751                 case JAVA_IFLE:
752                 case JAVA_IFNE:
753                 case JAVA_IFGT:
754                 case JAVA_IFGE:
755                 case JAVA_IFNULL:
756                 case JAVA_IFNONNULL:
757                 case JAVA_IF_ICMPEQ:
758                 case JAVA_IF_ICMPNE:
759                 case JAVA_IF_ICMPLT:
760                 case JAVA_IF_ICMPGT:
761                 case JAVA_IF_ICMPLE:
762                 case JAVA_IF_ICMPGE:
763                 case JAVA_IF_ACMPEQ:
764                 case JAVA_IF_ACMPNE:
765                 case JAVA_GOTO:
766                 case JAVA_JSR:
767                         i = p + code_get_s2(p + 1,inline_env->method);
768                         if (useinlining) { 
769                                 debug_writebranch;
770                                 i = label_index[i];
771                         }
772                         bound_check(i);
773                         block_insert(i);
774                         blockend = true;
775                         OP1(opcode, i);
776                         break;
777                 case JAVA_GOTO_W:
778                 case JAVA_JSR_W:
779                         i = p + code_get_s4(p + 1,inline_env->method);
780                         if (useinlining) { 
781                                 debug_writebranch;
782                                 i = label_index[i];
783                         }
784                         bound_check(i);
785                         /*printf("B6 JSR_W\t"); fflush(stdout);*/
786                         block_insert(i);
787                         blockend = true;
788                         OP1(opcode, i);
789                         break;
790
791                 case JAVA_RET:
792                         if (!iswide) {
793                                 i = code_get_u1(p + 1,inline_env->method);
794                         } else {
795                                 i = code_get_u2(p + 1,inline_env->method);
796                                 nextp = p + 3;
797                                 iswide = false;
798                         }
799                         blockend = true;
800                                 
801                         /*
802                           if (inline_env->isinlinedmethod) {
803                           OP1(ICMD_GOTO, inlinfo->stopgp);
804                           break;
805                           }*/
806
807                         OP1LOAD(opcode, i + firstlocal);
808                         break;
809
810                 case JAVA_IRETURN:
811                 case JAVA_LRETURN:
812                 case JAVA_FRETURN:
813                 case JAVA_DRETURN:
814                 case JAVA_ARETURN:
815                 case JAVA_RETURN:
816                         if (inline_env->isinlinedmethod) {
817                                 /*                                      if (p==m->jcodelength-1) {*/ /* return is at end of inlined method */
818                                 /*                                              OP(ICMD_NOP); */
819                                 /*                                              break; */
820                                 /*                                      } */
821                                 if (nextp>inline_env->method->jcodelength-1) {
822                                         /* OP1(ICMD_GOTO, inlinfo->stopgp);
823                                            OP(ICMD_NOP);
824                                            OP(ICMD_NOP);
825                                         */
826                                         blockend=true;
827                                         break;
828                                 } /* JJJJJJJ */
829                                 blockend = true;
830                                 OP1(ICMD_GOTO, inlinfo->stopgp);
831                                 break;
832                         }
833
834                         blockend = true;
835                         OP(opcode);
836                         break;
837
838                 case JAVA_ATHROW:
839                         blockend = true;
840                         OP(opcode);
841                         break;
842                                 
843
844                         /* table jumps ********************************/
845
846                 case JAVA_LOOKUPSWITCH:
847                         {
848                                 s4 num, j;
849                                 s4 *tablep;
850                                 s4 prevvalue=0;
851
852                                 blockend = true;
853                                 nextp = ALIGN((p + 1), 4);
854                                 if (nextp + 8 > inline_env->method->jcodelength)
855                                         panic("Unexpected end of bytecode");
856                                 if (!useinlining) {
857                                         tablep = (s4 *) (inline_env->method->jcode + nextp);
858
859                                 } else {
860                                         num = code_get_u4(nextp + 4,inline_env->method);
861                                         tablep = DMNEW(s4, num * 2 + 2);
862                                 }
863
864                                 OP2A(opcode, 0, tablep,currentline);
865
866                                 /* default target */
867
868                                 j =  p + code_get_s4(nextp,inline_env->method);
869                                 if (useinlining) 
870                                         j = label_index[j];
871                                 *tablep = j;     /* restore for little endian */
872                                 tablep++;
873                                 nextp += 4;
874                                 bound_check(j);
875                                 block_insert(j);
876
877                                 /* number of pairs */
878
879                                 num = code_get_u4(nextp,inline_env->method);
880                                 *tablep = num;
881                                 tablep++;
882                                 nextp += 4;
883
884                                 if (nextp + 8*(num) > inline_env->method->jcodelength)
885                                         panic("Unexpected end of bytecode");
886
887                                 for (i = 0; i < num; i++) {
888                                         /* value */
889
890                                         j = code_get_s4(nextp,inline_env->method);
891                                         *tablep = j; /* restore for little endian */
892                                         tablep++;
893                                         nextp += 4;
894
895                                         /* check if the lookup table is sorted correctly */
896                                         
897                                         if (i && (j <= prevvalue)) {
898                                                 *exceptionptr = new_verifyerror(m, "Unsorted lookup switch");
899                                                 return NULL;
900                                         }
901                                         prevvalue = j;
902
903                                         /* target */
904
905                                         j = p + code_get_s4(nextp,inline_env->method);
906                                         if (useinlining)
907                                                 j = label_index[j];
908                                         *tablep = j; /* restore for little endian */
909                                         tablep++;
910                                         nextp += 4;
911                                         bound_check(j);
912                                         block_insert(j);
913                                 }
914
915                                 break;
916                         }
917
918
919                 case JAVA_TABLESWITCH:
920                         {
921                                 s4 num, j;
922                                 s4 *tablep;
923
924                                 blockend = true;
925                                 nextp = ALIGN((p + 1), 4);
926                                 if (nextp + 12 > inline_env->method->jcodelength)
927                                         panic("Unexpected end of bytecode");
928                                 if (!useinlining) {
929                                         tablep = (s4 *) (inline_env->method->jcode + nextp);
930
931                                 } else {
932                                         num = code_get_u4(nextp + 8,inline_env->method) - code_get_u4(nextp + 4,inline_env->method);
933                                         tablep = DMNEW(s4, num + 1 + 3);
934                                 }
935
936                                 OP2A(opcode, 0, tablep,currentline);
937
938                                 /* default target */
939
940                                 j = p + code_get_s4(nextp,inline_env->method);
941                                 if (useinlining)
942                                         j = label_index[j];
943                                 *tablep = j;     /* restore for little endian */
944                                 tablep++;
945                                 nextp += 4;
946                                 bound_check(j);
947                                 block_insert(j);
948
949                                 /* lower bound */
950
951                                 j = code_get_s4(nextp,inline_env->method);
952                                 *tablep = j;     /* restore for little endian */
953                                 tablep++;
954                                 nextp += 4;
955
956                                 /* upper bound */
957
958                                 num = code_get_s4(nextp,inline_env->method);
959                                 *tablep = num;   /* restore for little endian */
960                                 tablep++;
961                                 nextp += 4;
962
963                                 num -= j;  /* difference of upper - lower */
964                                 if (num < 0)
965                                         panic("invalid TABLESWITCH: upper bound < lower bound");
966
967                                 if (nextp + 4*(num+1) > inline_env->method->jcodelength)
968                                         panic("Unexpected end of bytecode");
969
970                                 for (i = 0; i <= num; i++) {
971                                         j = p + code_get_s4(nextp,inline_env->method);
972                                         if (useinlining) {
973                                                 /*printf("TABLESWITCH: j before mapping=%ld\n",j);*/
974                                                 j = label_index[j];
975                                         }
976                                         *tablep = j; /* restore for little endian */
977                                         tablep++;
978                                         nextp += 4;
979                                         bound_check(j);
980                                         block_insert(j);
981                                         /*printf("TABLESWITCH: block_insert(%ld)\n",j);*/
982                                 }
983
984                                 break;
985                         }
986
987
988                         /* load and store of object fields *******************/
989
990                 case JAVA_AASTORE:
991                         BUILTIN3(BUILTIN_aastore, TYPE_VOID, currentline);
992                         break;
993
994                 case JAVA_GETSTATIC:
995                 case JAVA_PUTSTATIC:
996 #if defined(__X86_64__) || defined(__I386__)
997                 case JAVA_GETFIELD:
998                 case JAVA_PUTFIELD:
999 #endif
1000                         i = code_get_u2(p + 1, inline_env->method);
1001                         {
1002                                 constant_FMIref  *fr;
1003                                 unresolved_field *uf;
1004                                 fieldinfo        *fi;
1005                                 classinfo        *c;
1006
1007                                 fr = class_getconstant(inline_env->method->class, i, CONSTANT_Fieldref);
1008 #if defined(__X86_64__) || defined(__I386__)
1009                                 OP2A_NOINC(opcode, fr->parseddesc.fd->type, fr, currentline);
1010
1011                                 if (!(uf = create_unresolved_field(inline_env->method->class,
1012                                                                                                    inline_env->method,
1013                                                                                                    iptr,
1014                                                                                                    NULL)))
1015                                         return NULL;
1016
1017                                 /* store unresolved_field pointer */
1018
1019                                 iptr->target = uf;
1020
1021                                 /* only with -noverify, otherwise the typechecker does this */
1022
1023                                 if (!opt_verify) {
1024                                         if (!resolve_field(uf, resolveLazy, &fi))
1025                                                 return NULL;
1026
1027                                         iptr->val.a = fi;
1028                                 }
1029                                 PINC;
1030 #else
1031                                 {
1032                                 classinfo *frclass;
1033                                 if (!resolve_classref(inline_env->method,fr->classref,resolveEager,true,&frclass))
1034                                         return NULL;
1035
1036                                 fi = class_resolvefield(frclass,
1037                                                                                 fr->name,
1038                                                                                 fr->descriptor,
1039                                                                                 inline_env->method->class,
1040                                                                                 true);
1041
1042                                 if (!fi)
1043                                         return NULL;
1044
1045                                 OP2A(opcode, fi->type, fi, currentline);
1046                                 if (!fi->class->initialized) {
1047                                         inline_env->method->isleafmethod = false;
1048                                 }
1049                                 }
1050 #endif
1051                         }
1052                         break;
1053
1054 #if !defined(__X86_64__) && !defined(__I386__)
1055                 case JAVA_PUTFIELD:
1056                 case JAVA_GETFIELD:
1057                         i = code_get_u2(p + 1,inline_env->method);
1058                         {
1059                                 constant_FMIref *fr;
1060                                 fieldinfo *fi;
1061                                 classinfo *frclass;
1062
1063                                 fr = class_getconstant(inline_env->method->class, i, CONSTANT_Fieldref);
1064                                 if (!resolve_classref(inline_env->method,fr->classref,resolveEager,true,&frclass))
1065                                         return NULL;
1066
1067                                 fi = class_resolvefield(frclass,
1068                                                                                 fr->name,
1069                                                                                 fr->descriptor,
1070                                                                                 inline_env->method->class,
1071                                                                                 true);
1072
1073                                 if (!fi)
1074                                         return NULL;
1075
1076                                 OP2A(opcode, fi->type, fi, currentline);
1077                         }
1078                         break;
1079 #endif
1080
1081
1082                         /* method invocation *****/
1083
1084                 case JAVA_INVOKESTATIC:
1085                         i = code_get_u2(p + 1, inline_env->method);
1086                         {
1087                                 constant_FMIref *mr;
1088                                 methodinfo *mi;
1089                                 unresolved_method *um;
1090                                 classinfo *mrclass;
1091
1092                                 inline_env->method->isleafmethod = false;
1093
1094                                 mr = class_getconstant(inline_env->method->class, i, CONSTANT_Methodref);
1095 #if defined(__X86_64__) || defined(__I386__)
1096                                 OP2A_NOINC(opcode, mr->parseddesc.md->paramcount, mr, currentline);
1097
1098                                 um = create_unresolved_method(inline_env->method->class,
1099                                                                                           inline_env->method,
1100                                                                                           iptr,
1101                                                                                           NULL);
1102
1103                                 if (!um)
1104                                         return NULL;
1105
1106                                 /* store the unresolved_method pointer */
1107
1108                                 iptr->target = um;
1109
1110                                 /* only with -noverify, otherwise the typechecker does this */
1111
1112                                 if (!opt_verify) {
1113                                         if (!resolve_method(um, resolveLazy, &mi))
1114                                                 return NULL;
1115
1116                                         iptr->val.a = mi;
1117                                 }
1118                                 PINC;
1119 #else
1120                                 if (!resolve_classref(inline_env->method,mr->classref,resolveEager,true,&mrclass))
1121                                         return NULL;
1122
1123                                 mi = class_resolveclassmethod(mrclass,
1124                                                                                           mr->name,
1125                                                                                           mr->descriptor,
1126                                                                                           inline_env->method->class,
1127                                                                                           true);
1128
1129                                 if (!mi)
1130                                         return NULL;
1131
1132 if (DEBUG4==true) { 
1133         method_display_w_class(mi); 
1134         printf("\tINVOKE STAT\n");
1135         fflush(stdout);}
1136
1137                                 if (!(mi->flags & ACC_STATIC)) {
1138                                         *exceptionptr =
1139                                                 new_exception(string_java_lang_IncompatibleClassChangeError);
1140                                         return NULL;
1141                                 }
1142
1143                                 method_descriptor2types(mi);
1144                                 OP2A(opcode, mi->paramcount, mi, currentline);
1145 #endif
1146                         }
1147                         break;
1148
1149                 case JAVA_INVOKESPECIAL:
1150                 case JAVA_INVOKEVIRTUAL:
1151                         i = code_get_u2(p + 1, inline_env->method);
1152                         {
1153                                 constant_FMIref *mr;
1154                                 methodinfo *mi;
1155                                 unresolved_method *um;
1156                                 classinfo *mrclass;
1157
1158                                 inline_env->method->isleafmethod = false;
1159
1160                                 mr = class_getconstant(inline_env->method->class, i, CONSTANT_Methodref);
1161 #if defined(__X86_64__) || defined(__I386__)
1162                                 OP2A_NOINC(opcode, mr->parseddesc.md->paramcount + 1, mr, currentline);
1163
1164                                 um = create_unresolved_method(inline_env->method->class,
1165                                                                                           inline_env->method,
1166                                                                                           iptr,
1167                                                                                           NULL);
1168
1169                                 if (!um)
1170                                         return NULL;
1171
1172                                 /* store the unresolved_method* */
1173
1174                                 iptr->target = um;
1175
1176                                 /* only with -noverify, otherwise the typechecker does this */
1177
1178                                 if (!opt_verify) {
1179                                         if (!resolve_method(um, resolveLazy, &mi))
1180                                                 return NULL;
1181
1182                                         iptr->val.a = mi;
1183                                 }
1184                                 PINC;
1185 #else
1186                                 if (!resolve_classref(inline_env->method,mr->classref,resolveEager,true,&mrclass))
1187                                         return NULL;
1188
1189                                 mi = class_resolveclassmethod(mrclass,
1190                                                                                           mr->name,
1191                                                                                           mr->descriptor,
1192                                                                                           inline_env->method->class,
1193                                                                                           true);
1194
1195                                 if (!mi)
1196                                         return NULL;
1197
1198 if (DEBUG4==true) { 
1199         method_display_w_class(mi); 
1200         printf("\tINVOKE SPEC/VIRT\n");
1201         fflush(stdout);}
1202
1203                                 if (mi->flags & ACC_STATIC) {
1204                                         *exceptionptr =
1205                                                 new_exception(string_java_lang_IncompatibleClassChangeError);
1206                                         return NULL;
1207                                 }
1208
1209                                 method_descriptor2types(mi);
1210                                 OP2A(opcode, mi->paramcount, mi, currentline);
1211 #endif
1212                         }
1213                         break;
1214
1215                 case JAVA_INVOKEINTERFACE:
1216                         i = code_get_u2(p + 1,inline_env->method);
1217                         {
1218                                 constant_FMIref *mr;
1219                                 methodinfo *mi;
1220                                 classinfo *mrclass;
1221                                 unresolved_method *um;
1222                                 
1223                                 inline_env->method->isleafmethod = false;
1224
1225                                 mr = class_getconstant(inline_env->method->class, i, CONSTANT_InterfaceMethodref);
1226 #if defined(__X86_64__) || defined(__I386__)
1227                                 OP2A_NOINC(opcode, mr->parseddesc.md->paramcount + 1, mr, currentline);
1228
1229                                 um = create_unresolved_method(inline_env->method->class,
1230                                                                                           inline_env->method,
1231                                                                                           iptr,
1232                                                                                           NULL);
1233
1234                                 if (!um)
1235                                         return NULL;
1236
1237                                 /* store the unresolved_method* */
1238
1239                                 iptr->target = um;
1240
1241                                 /* only with -noverify, otherwise the typechecker does this */
1242
1243                                 if (!opt_verify) {
1244                                         if (!resolve_method(um, resolveLazy, &mi))
1245                                                 return NULL;
1246
1247                                         iptr->val.a = mi;
1248                                 }
1249                                 PINC;
1250 #else
1251                                 if (!resolve_classref(inline_env->method,mr->classref,resolveEager,true,&mrclass))
1252                                         return NULL;
1253
1254                                 mi = class_resolveinterfacemethod(mrclass,
1255                                                                                                   mr->name,
1256                                                                                                   mr->descriptor,
1257                                                                                                   inline_env->method->class,
1258                                                                                                   true);
1259                                 if (!mi)
1260                                         return NULL;
1261
1262                                 if (mi->flags & ACC_STATIC) {
1263                                         *exceptionptr =
1264                                                 new_exception(string_java_lang_IncompatibleClassChangeError);
1265                                         return NULL;
1266                                 }
1267
1268 if (DEBUG4==true) { 
1269         method_display_w_class(mi); 
1270         printf("\tINVOKE INTERFACE\n");
1271         fflush(stdout);}
1272
1273                                 method_descriptor2types(mi);
1274                                 OP2A(opcode, mi->paramcount, mi, currentline);
1275 #endif
1276                         }
1277                         break;
1278
1279                         /* miscellaneous object operations *******/
1280
1281                 case JAVA_NEW:
1282                         {
1283                                 constant_classref *cr;
1284                                 classinfo         *cls;
1285                                 
1286 #if defined(__X86_64__) || defined(__I386__)
1287                                 i = code_get_u2(p + 1, inline_env->method);
1288                                 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1289
1290                                 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, &cls))
1291                                         return NULL;
1292
1293                                 /* <clinit> can throw an exception over native code */
1294
1295                                 if (cls && cls->initialized) {
1296                                         LOADCONST_A_BUILTIN(cls);
1297                                         BUILTIN1(BUILTIN_new, TYPE_ADR, currentline);
1298
1299                                 } else {
1300                                         LOADCONST_A_BUILTIN(cr);
1301                                         BUILTIN1(asm_wrapper_patcher_BUILTIN_new, TYPE_ADR, currentline);
1302                                 }
1303
1304                                 s_count++;
1305                                 OP(ICMD_CHECKEXCEPTION);
1306 #else
1307                                 i = code_get_u2(p + 1,inline_env->method);
1308                                 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1309                                 if (!resolve_classref(inline_env->method,cr,resolveEager,true,&cls))
1310                                         return NULL;
1311                                 LOADCONST_A_BUILTIN(cls);
1312                                 s_count++;
1313                                 BUILTIN1(BUILTIN_new, TYPE_ADR, currentline);
1314                                 OP(ICMD_CHECKEXCEPTION);
1315 #endif
1316                         }
1317                         break;
1318
1319                 case JAVA_CHECKCAST:
1320                         i = code_get_u2(p + 1, inline_env->method);
1321                         {
1322                                 constant_classref *cr;
1323                                 classinfo *cls;
1324                                 
1325                                 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1326
1327 #if defined(__X86_64__) || defined(__I386__)
1328                                 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, &cls))
1329                                         return NULL;
1330
1331                                 if (cr->name->text[0] == '[') {
1332                                         /* array type cast-check */
1333                                         if (cls) {
1334                                                 LOADCONST_A_BUILTIN(cls->vftbl);
1335                                                 BUILTIN2(BUILTIN_checkarraycast, TYPE_ADR, currentline);
1336
1337                                         } else {
1338                                                 LOADCONST_A_BUILTIN(cr);
1339                                                 BUILTIN2(asm_wrapper_patcher_BUILTIN_checkarraycast, TYPE_ADR, currentline);
1340                                         }
1341                                         s_count++;
1342
1343                                 } else {
1344                                         /* object type cast-check */
1345                                         OP2AT(opcode, 1, cls, cr, currentline);
1346                                 }
1347 #else
1348                                 if (!resolve_classref(inline_env->method,
1349                                                         cr,resolveEager,true,&cls))
1350                                         return NULL;
1351
1352                                 if (cls->vftbl->arraydesc) {
1353                                         /* array type cast-check */
1354                                         LOADCONST_A_BUILTIN(cls->vftbl);
1355                                         s_count++;
1356                                         BUILTIN2(BUILTIN_checkarraycast, TYPE_ADR,currentline);
1357
1358                                 } else { /* object type cast-check */
1359                                         /*
1360                                           +                                               LOADCONST_A_BUILTIN(class_getconstant(class, i, CONSTANT_Class));
1361                                           +                                               s_count++;
1362                                           +                                               BUILTIN2(BUILTIN_checkcast, TYPE_ADR,currentline);
1363                                           +                                             */
1364                                         OP2A(opcode, 1, cls, currentline);
1365                                 }
1366 #endif
1367                         }
1368                         break;
1369
1370                 case JAVA_INSTANCEOF:
1371                         i = code_get_u2(p + 1,inline_env->method);
1372                         {
1373                                 constant_classref *cr;
1374                                 classinfo *cls;
1375                                 
1376                                 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1377
1378 #if defined(__X86_64__) || defined(__I386__)
1379                                 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, &cls))
1380                                         return NULL;
1381
1382                                 if (cr->name->text[0] == '[') {
1383                                         /* array type cast-check */
1384                                         if (cls) {
1385                                                 LOADCONST_A_BUILTIN(cls->vftbl);
1386                                                 BUILTIN2(BUILTIN_arrayinstanceof, TYPE_INT, currentline);
1387
1388                                         } else {
1389                                                 LOADCONST_A_BUILTIN(cr);
1390                                                 BUILTIN2(asm_wrapper_patcher_BUILTIN_arrayinstanceof, TYPE_INT, currentline);
1391                                         }
1392                                         s_count++;
1393
1394                                 } else {
1395                                         /* object type cast-check */
1396                                         OP2AT(opcode, 1, cls, cr, currentline);
1397                                 }
1398 #else
1399                                 if (!resolve_classref(inline_env->method,
1400                                                         cr,resolveEager,true,&cls))
1401                                         return NULL;
1402
1403                                 if (cls->vftbl->arraydesc) {
1404                                         /* array type cast-check */
1405                                         LOADCONST_A_BUILTIN(cls->vftbl);
1406                                         s_count++;
1407                                         BUILTIN2(BUILTIN_arrayinstanceof, TYPE_INT, currentline);
1408                                 }
1409                                 else { /* object type cast-check */
1410                                         /*
1411                                           LOADCONST_A_BUILTIN(class_getconstant(class, i, CONSTANT_Class));
1412                                           s_count++;
1413                                           BUILTIN2(BUILTIN_instanceof, TYPE_INT,currentline);
1414                                           +                                             */
1415                                         OP2A(opcode, 1, cls, currentline);
1416                                 }
1417 #endif
1418                         }
1419                         break;
1420
1421                 case JAVA_MONITORENTER:
1422 #if defined(USE_THREADS)
1423                         if (checksync) {
1424                                 BUILTIN1(BUILTIN_monitorenter, TYPE_VOID,currentline);
1425                         } else
1426 #endif
1427                                 {
1428                                         OP(ICMD_NULLCHECKPOP);
1429                                 }
1430                         break;
1431
1432                 case JAVA_MONITOREXIT:
1433 #if defined(USE_THREADS)
1434                         if (checksync) {
1435                                 BUILTIN1(BUILTIN_monitorexit, TYPE_VOID,currentline);
1436                                 OP(ICMD_CHECKEXCEPTION);
1437                         } else
1438 #endif
1439                                 {
1440                                         OP(ICMD_POP);
1441                                 }
1442                         break;
1443
1444                         /* any other basic operation **************************************/
1445
1446                 case JAVA_IDIV:
1447                         OP(opcode);
1448                         break;
1449
1450                 case JAVA_IREM:
1451                         OP(opcode);
1452                         break;
1453
1454                 case JAVA_LDIV:
1455                         OP(opcode);
1456                         break;
1457
1458                 case JAVA_LREM:
1459                         OP(opcode);
1460                         break;
1461
1462                 case JAVA_FREM:
1463 #if defined(__I386__)
1464                         OP(opcode);
1465 #else
1466                         BUILTIN2(BUILTIN_frem, TYPE_FLOAT,currentline);
1467 #endif
1468                         break;
1469
1470                 case JAVA_DREM:
1471 #if defined(__I386__)
1472                         OP(opcode);
1473 #else
1474                         BUILTIN2(BUILTIN_drem, TYPE_DOUBLE,currentline);
1475 #endif
1476                         break;
1477
1478                 case JAVA_F2I:
1479 #if defined(__ALPHA__)
1480                         if (!opt_noieee) {
1481                                 BUILTIN1(BUILTIN_f2i, TYPE_INT,currentline);
1482                         } else
1483 #endif
1484                                 {
1485                                         OP(opcode);
1486                                 }
1487                         break;
1488
1489                 case JAVA_F2L:
1490 #if defined(__ALPHA__)
1491                         if (!opt_noieee) {
1492                                 BUILTIN1(BUILTIN_f2l, TYPE_LONG,currentline);
1493                         } else 
1494 #endif
1495                                 {
1496                                         OP(opcode);
1497                                 }
1498                         break;
1499
1500                 case JAVA_D2I:
1501 #if defined(__ALPHA__)
1502                         if (!opt_noieee) {
1503                                 BUILTIN1(BUILTIN_d2i, TYPE_INT,currentline);
1504                         } else
1505 #endif
1506                                 {
1507                                         OP(opcode);
1508                                 }
1509                         break;
1510
1511                 case JAVA_D2L:
1512 #if defined(__ALPHA__)
1513                         if (!opt_noieee) {
1514                                 BUILTIN1(BUILTIN_d2l, TYPE_LONG,currentline);
1515                         } else
1516 #endif
1517                                 {
1518                                         OP(opcode);
1519                                 }
1520                         break;
1521
1522                 case JAVA_BREAKPOINT:
1523                         *exceptionptr =
1524                                 new_verifyerror(m, "Quick instructions shouldn't appear yet.");
1525                         return NULL;
1526
1527                 case 204: /* unused opcode */
1528                 case 205:
1529                 case 206:
1530                 case 207:
1531                 case 208:
1532                 case 209:
1533                 case 210:
1534                 case 211:
1535                 case 212:
1536                 case 213:
1537                 case 214:
1538                 case 215:
1539                 case 216:
1540                 case 217:
1541                 case 218:
1542                 case 219:
1543                 case 220:
1544                 case 221:
1545                 case 222:
1546                 case 223:
1547                 case 224:
1548                 case 225:
1549                 case 226:
1550                 case 227:
1551                 case 228:
1552                 case 229:
1553                 case 230:
1554                 case 231:
1555                 case 232:
1556                 case 233:
1557                 case 234:
1558                 case 235:
1559                 case 236:
1560                 case 237:
1561                 case 238:
1562                 case 239:
1563                 case 240:
1564                 case 241:
1565                 case 242:
1566                 case 243:
1567                 case 244:
1568                 case 245:
1569                 case 246:
1570                 case 247:
1571                 case 248:
1572                 case 249:
1573                 case 250:
1574                 case 251:
1575                 case 252:
1576                 case 253:
1577                 case 254:
1578                 case 255:
1579                         printf("Illegal opcode %d at instr %d\n", opcode, ipc);
1580                         panic("Illegal opcode encountered");
1581                         break;
1582
1583                 default:
1584                         OP(opcode);
1585                         break;
1586                                 
1587                 } /* end switch */
1588
1589                 /* If WIDE was used correctly, iswide should have been reset by now. */
1590                 if (iswide && opcode != JAVA_WIDE)
1591                         panic("Illegal instruction: WIDE before incompatible opcode");
1592                 
1593                 /* INLINING */
1594                   
1595                 /* if (inline_env->isinlinedmethod && p == inline_env->method->jcodelength - 1) { */ /* end of an inlined method */
1596                 if (inline_env->isinlinedmethod && (nextp >= inline_env->method->jcodelength) ) { /* end of an inlined method */
1597                         /*                printf("setting gp from %d to %d\n",gp, inlinfo->stopgp); */
1598                         gp = inlinfo->stopgp; 
1599                         inlining_restore_compiler_variables();
1600                         OP(ICMD_INLINE_END);
1601 /*label_index = inlinfo->label_index;*/
1602
1603 METHINFOt(inline_env->method,"AFTER RESTORE : ",DEBUG);
1604                         list_remove(inlinfo->inlinedmethods, list_first(inlinfo->inlinedmethods));
1605                         if (inlinfo->inlinedmethods == NULL) { /* JJJJ */
1606                                 nextgp = -1;
1607                         } else {
1608                                 tmpinlinf = list_first(inlinfo->inlinedmethods);
1609                                 nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
1610                         }
1611                         /*                printf("nextpgp: %d\n", nextgp); */
1612                         label_index=inlinfo->label_index;
1613                         firstlocal = inlinfo->firstlocal;
1614                 }
1615
1616         } /* end for */
1617
1618
1619         if (p != m->jcodelength) {
1620                 printf("p (%d) != m->jcodelength (%d)\n",p,m->jcodelength);
1621                 panic("Command-sequence crosses code-boundary");
1622         }
1623         if (!blockend) {
1624                 *exceptionptr = new_verifyerror(m, "Falling off the end of the code");
1625                 return NULL;
1626         }
1627
1628         /* adjust block count if target 0 is not first intermediate instruction */
1629
1630         if (!m->basicblockindex[0] || (m->basicblockindex[0] > 1))
1631                 b_count++;
1632
1633         /* copy local to method variables */
1634
1635         m->instructioncount = ipc;
1636         m->basicblockcount = b_count;
1637         m->stackcount = s_count + m->basicblockcount * m->maxstack;
1638
1639         /* allocate stack table */
1640
1641         m->stack = DMNEW(stackelement, m->stackcount);
1642
1643         {
1644                 basicblock *bptr;
1645
1646                 bptr = m->basicblocks = DMNEW(basicblock, b_count + 1);    /* one more for end ipc */
1647
1648                 b_count = 0;
1649                 m->c_debug_nr = 0;
1650         
1651                 /* additional block if target 0 is not first intermediate instruction */
1652
1653                 if (!m->basicblockindex[0] || (m->basicblockindex[0] > 1)) {
1654                         bptr->iinstr = m->instructions;
1655                         bptr->mpc = -1;
1656                         bptr->flags = -1;
1657                         bptr->type = BBTYPE_STD;
1658                         bptr->branchrefs = NULL;
1659                         bptr->pre_count = 0;
1660                         bptr->debug_nr = m->c_debug_nr++;
1661                         bptr++;
1662                         b_count++;
1663                         (bptr - 1)->next = bptr;
1664                 }
1665
1666                 /* allocate blocks */
1667
1668                 for (p = 0; p < inline_env->cumjcodelength; p++) { 
1669                 /* for (p = 0; p < m->jcodelength; p++) { */
1670                         if (m->basicblockindex[p] & 1) {
1671                                 /* check if this block starts at the beginning of an instruction */
1672                                 if (!instructionstart[p]) {
1673                                         printf("Basic Block beginn: %d\n",p);
1674                                         panic("Branch into middle of instruction");
1675                                 }
1676                                 /* allocate the block */
1677                                 bptr->iinstr = m->instructions + (m->basicblockindex[p] >> 1);
1678                                 bptr->debug_nr = m->c_debug_nr++;
1679                                 if (b_count != 0)
1680                                         (bptr - 1)->icount = bptr->iinstr - (bptr - 1)->iinstr;
1681                                 bptr->mpc = -1;
1682                                 bptr->flags = -1;
1683                                 bptr->lflags = 0;
1684                                 bptr->type = BBTYPE_STD;
1685                                 bptr->branchrefs = NULL;
1686                                 m->basicblockindex[p] = b_count;
1687                                 bptr->pre_count = 0;
1688                                 bptr++;
1689                                 b_count++;
1690                                 (bptr - 1)->next = bptr;
1691                         }
1692                 }
1693
1694                 /* allocate additional block at end */
1695
1696                 bptr->instack = bptr->outstack = NULL;
1697                 bptr->indepth = bptr->outdepth = 0;
1698                 bptr->iinstr = NULL;
1699                 (bptr - 1)->icount = (m->instructions + m->instructioncount) - (bptr - 1)->iinstr;
1700                 bptr->icount = 0;
1701                 bptr->mpc = -1;
1702                 bptr->flags = -1;
1703                 bptr->lflags = 0;
1704                 bptr->type = BBTYPE_STD;
1705                 bptr->branchrefs = NULL;
1706                 bptr->pre_count = 0;
1707                 bptr->debug_nr = m->c_debug_nr++;
1708                 (bptr - 1)->next = bptr;
1709                 bptr->next = NULL;
1710
1711                 if (cd->exceptiontablelength > 0) {
1712                         cd->exceptiontable[cd->exceptiontablelength - 1].down = NULL;
1713                 }
1714                 
1715                 for (i = 0; i < cd->exceptiontablelength; ++i) {
1716                         p = cd->exceptiontable[i].startpc;
1717                         cd->exceptiontable[i].start = m->basicblocks + m->basicblockindex[p];
1718
1719                         p = cd->exceptiontable[i].endpc;
1720                         cd->exceptiontable[i].end = (p == inline_env->method->jcodelength) ? (m->basicblocks + m->basicblockcount /*+ 1*/) : (m->basicblocks + m->basicblockindex[p]);
1721
1722                         p = cd->exceptiontable[i].handlerpc;
1723                         cd->exceptiontable[i].handler = m->basicblocks + m->basicblockindex[p];
1724             }
1725         }
1726         
1727         if (useinlining) inlining_cleanup(inline_env);
1728
1729         /* just return methodinfo* to signal everything was ok */
1730
1731         return m;
1732 }
1733
1734
1735 /*
1736  * These are local overrides for various environment variables in Emacs.
1737  * Please do not remove this and leave it at the end of the file, where
1738  * Emacs will automagically detect them.
1739  * ---------------------------------------------------------------------
1740  * Local variables:
1741  * mode: c
1742  * indent-tabs-mode: t
1743  * c-basic-offset: 4
1744  * tab-width: 4
1745  * End:
1746  */
1747