- initialize class only if the called function is static
[cacao.git] / src / vm / jit / jit.c
1 /* jit/jit.c - calls the code generation functions
2
3    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4    R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
5    M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
6    P. Tomsich, J. Wenninger
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    Authors: Andreas Krall
28             Reinhard Grafl
29
30    Changes: Edwin Steiner
31
32    $Id: jit.c 909 2004-02-02 00:52:42Z twisti $
33
34 */
35
36
37 #include <stdlib.h>
38 #include <string.h>
39 #include "global.h"    /* we define _GNU_SOURCE there */
40 #include "main.h"
41 #include "tables.h"
42 #include "loader.h"
43 #include "jit.h"
44 #include "parse.h"
45 #include "stack.h"
46 #include "reg.h"
47 #include "inline.h"
48 #include "builtin.h"
49 #include "native.h"
50 #include "asmpart.h"
51 #include "codegen.h"
52 #include "types.h"
53 #include "threads/thread.h"
54 #include "disass.h"
55 #include "loop/loop.h"
56 #include "loop/graph.h"
57 #include "loop/analyze.h"
58 #include "toolbox/loging.h"
59 #include "toolbox/memory.h"
60
61
62 /* global switches ************************************************************/
63
64 int count_jit_calls = 0;
65 int count_methods = 0;
66 int count_spills = 0;
67 int count_pcmd_activ = 0;
68 int count_pcmd_drop = 0;
69 int count_pcmd_zero = 0;
70 int count_pcmd_const_store = 0;
71 int count_pcmd_const_alu = 0;
72 int count_pcmd_const_bra = 0;
73 int count_pcmd_load = 0;
74 int count_pcmd_move = 0;
75 int count_load_instruction = 0;
76 int count_pcmd_store = 0;
77 int count_pcmd_store_comb = 0;
78 int count_dup_instruction = 0;
79 int count_pcmd_op = 0;
80 int count_pcmd_mem = 0;
81 int count_pcmd_met = 0;
82 int count_pcmd_bra = 0;
83 int count_pcmd_table = 0;
84 int count_pcmd_return = 0;
85 int count_pcmd_returnx = 0;
86 int count_check_null = 0;
87 int count_check_bound = 0;
88 int count_max_basic_blocks = 0;
89 int count_basic_blocks = 0;
90 int count_javainstr = 0;
91 int count_max_javainstr = 0;
92 int count_javacodesize = 0;
93 int count_javaexcsize = 0;
94 int count_calls = 0;
95 int count_tryblocks = 0;
96 int count_code_len = 0;
97 int count_data_len = 0;
98 int count_cstub_len = 0;
99 int count_nstub_len = 0;
100 int count_max_new_stack = 0;
101 int count_upper_bound_new_stack = 0;
102 static int count_block_stack_init[11] = {
103         0, 0, 0, 0, 0, 
104         0, 0, 0, 0, 0, 
105         0
106 };
107 int *count_block_stack = count_block_stack_init;
108 static int count_analyse_iterations_init[5] = {
109         0, 0, 0, 0, 0
110 };
111 int *count_analyse_iterations = count_analyse_iterations_init;
112 static int count_method_bb_distribution_init[9] = {
113         0, 0, 0, 0, 0,
114         0, 0, 0, 0
115 };
116 int *count_method_bb_distribution = count_method_bb_distribution_init;
117 static int count_block_size_distribution_init[18] = {
118         0, 0, 0, 0, 0,
119         0, 0, 0, 0, 0,
120         0, 0, 0, 0, 0,
121         0, 0, 0
122 };
123 int *count_block_size_distribution = count_block_size_distribution_init;
124 static int count_store_length_init[21] = {
125         0, 0, 0, 0, 0,
126         0, 0, 0, 0, 0,
127         0, 0, 0, 0, 0,
128         0, 0, 0, 0, 0,
129         0
130 };
131 int *count_store_length = count_store_length_init;
132 static int count_store_depth_init[11] = {
133         0, 0, 0, 0, 0,
134         0, 0, 0, 0, 0,
135         0
136 };
137 int *count_store_depth = count_store_depth_init;
138
139
140
141 /* global compiler variables **************************************************/
142
143                                 /* data about the currently compiled method   */
144
145 classinfo  *class;              /* class the compiled method belongs to       */
146 methodinfo *method;             /* pointer to method info of compiled method  */
147 static utf *descriptor;         /* type descriptor of compiled method         */
148 int         mparamcount;        /* number of parameters (incl. this)          */
149 u1         *mparamtypes;        /* types of all parameters (TYPE_INT, ...)    */
150 static int mreturntype;         /* return type of method                      */
151         
152 int maxstack;                   /* maximal JavaVM stack size                  */
153 int maxlocals;                  /* maximal number of local JavaVM variables   */
154 int jcodelength;                /* length of JavaVM-codes                     */
155 u1 *jcode;                      /* pointer to start of JavaVM-code            */
156 int exceptiontablelength;       /* length of exception table                  */
157 xtable *extable;                /* pointer to start of exception table        */
158 exceptiontable *raw_extable;
159
160 int block_count;                /* number of basic blocks                     */
161 basicblock *block;              /* points to basic block array                */
162 int *block_index;               /* a table which contains for every byte of   */
163                                 /* JavaVM code a basic block index if at this */
164                                 /* byte there is the start of a basic block   */
165
166 int instr_count;                /* number of JavaVM instructions              */
167 instruction *instr;             /* points to intermediate code instructions   */
168
169 int stack_count;                /* number of stack elements                   */
170 stackelement *stack;            /* points to intermediate code instructions   */
171
172 bool isleafmethod;              /* true if a method doesn't call subroutines  */
173
174 basicblock *last_block;         /* points to the end of the BB list           */
175
176 bool regs_ok;                   /* true if registers have been allocated      */
177
178 /* list of all classes used by the compiled method which have to be           */
179 /* initialised (if not already done) before execution of this method          */
180 chain *uninitializedclasses;
181
182 int stackreq[256];
183
184                                 
185 #if defined(__I386__)
186 /* these define if a method has ICMDs which use %edx or %ecx */
187 bool method_uses_ecx;
188 bool method_uses_edx;
189 #endif
190
191
192 int jcommandsize[256] = {
193
194 #define JAVA_NOP               0
195 #define ICMD_NOP               0
196         1,
197 #define JAVA_ACONST_NULL       1
198 #define ICMD_ACONST            1        /* val.a = constant                   */
199         1,
200 #define JAVA_ICONST_M1         2
201 #define ICMD_NULLCHECKPOP      2
202         1,
203 #define JAVA_ICONST_0          3
204 #define ICMD_ICONST            3        /* val.i = constant                   */
205         1,
206 #define JAVA_ICONST_1          4
207 #define ICMD_IREM0X10001       4
208         1,
209 #define JAVA_ICONST_2          5
210 #define ICMD_IDIVPOW2          5        /* val.i = constant                   */
211         1,
212 #define JAVA_ICONST_3          6
213 #define ICMD_LDIVPOW2          6        /* val.l = constant                   */
214         1,
215 #define JAVA_ICONST_4          7
216         1,
217 #define JAVA_ICONST_5          8
218 #define ICMD_LREM0X10001       8
219         1,
220 #define JAVA_LCONST_0          9
221 #define ICMD_LCONST            9        /* val.l = constant                   */
222         1,
223 #define JAVA_LCONST_1         10
224 #define ICMD_LCMPCONST        10        /* val.l = constant                   */
225         1,
226 #define JAVA_FCONST_0         11
227 #define ICMD_FCONST           11        /* val.f = constant                   */
228         1,
229 #define JAVA_FCONST_1         12
230         1,
231 #define JAVA_FCONST_2         13
232 #define ICMD_ELSE_ICONST      13
233         1,
234 #define JAVA_DCONST_0         14
235 #define ICMD_DCONST           14        /* val.d = constant                   */
236         1,
237 #define JAVA_DCONST_1         15
238 #define ICMD_IFEQ_ICONST      15
239         1,
240 #define JAVA_BIPUSH           16
241 #define ICMD_IFNE_ICONST      16
242         2,
243 #define JAVA_SIPUSH           17
244 #define ICMD_IFLT_ICONST      17
245         3,
246 #define JAVA_LDC1             18
247 #define ICMD_IFGE_ICONST      18
248         2,
249 #define JAVA_LDC2             19
250 #define ICMD_IFGT_ICONST      19
251         3,
252 #define JAVA_LDC2W            20
253 #define ICMD_IFLE_ICONST      20
254         3,
255                                             /* order of LOAD instructions must be */
256                                             /* equal to order of TYPE_XXX defines */
257 #define JAVA_ILOAD            21
258 #define ICMD_ILOAD            21        /* op1 = local variable               */
259         2,                      
260 #define JAVA_LLOAD            22
261 #define ICMD_LLOAD            22        /* op1 = local variable               */
262         2,
263 #define JAVA_FLOAD            23
264 #define ICMD_FLOAD            23        /* op1 = local variable               */
265         2,
266 #define JAVA_DLOAD            24
267 #define ICMD_DLOAD            24        /* op1 = local variable               */
268         2,
269 #define JAVA_ALOAD            25
270 #define ICMD_ALOAD            25        /* op1 = local variable               */
271         2,
272 #define JAVA_ILOAD_0          26
273 #define ICMD_IADDCONST        26        /* val.i = constant                   */
274         1,
275 #define JAVA_ILOAD_1          27
276 #define ICMD_ISUBCONST        27        /* val.i = constant                   */
277         1,
278 #define JAVA_ILOAD_2          28
279 #define ICMD_IMULCONST        28        /* val.i = constant                   */
280         1,
281 #define JAVA_ILOAD_3          29
282 #define ICMD_IANDCONST        29        /* val.i = constant                   */
283         1,
284 #define JAVA_LLOAD_0          30
285 #define ICMD_IORCONST         30        /* val.i = constant                   */
286         1,
287 #define JAVA_LLOAD_1          31
288 #define ICMD_IXORCONST        31        /* val.i = constant                   */
289         1,
290 #define JAVA_LLOAD_2          32
291 #define ICMD_ISHLCONST        32        /* val.i = constant                   */
292         1,
293 #define JAVA_LLOAD_3          33
294 #define ICMD_ISHRCONST        33        /* val.i = constant                   */
295         1,
296 #define JAVA_FLOAD_0          34
297 #define ICMD_IUSHRCONST       34        /* val.i = constant                   */
298         1,
299 #define JAVA_FLOAD_1          35
300 #define ICMD_IREMPOW2         35        /* val.i = constant                   */
301         1,
302 #define JAVA_FLOAD_2          36
303 #define ICMD_LADDCONST        36        /* val.l = constant                   */
304         1,
305 #define JAVA_FLOAD_3          37
306 #define ICMD_LSUBCONST        37        /* val.l = constant                   */
307         1,
308 #define JAVA_DLOAD_0          38
309 #define ICMD_LMULCONST        38        /* val.l = constant                   */
310         1,
311 #define JAVA_DLOAD_1          39
312 #define ICMD_LANDCONST        39        /* val.l = constant                   */
313         1,
314 #define JAVA_DLOAD_2          40
315 #define ICMD_LORCONST         40        /* val.l = constant                   */
316         1,
317 #define JAVA_DLOAD_3          41
318 #define ICMD_LXORCONST        41        /* val.l = constant                   */
319         1,
320 #define JAVA_ALOAD_0          42
321 #define ICMD_LSHLCONST        42        /* val.l = constant                   */
322         1,
323 #define JAVA_ALOAD_1          43
324 #define ICMD_LSHRCONST        43        /* val.l = constant                   */
325         1,
326 #define JAVA_ALOAD_2          44
327 #define ICMD_LUSHRCONST       44        /* val.l = constant                   */
328         1,
329 #define JAVA_ALOAD_3          45
330 #define ICMD_LREMPOW2         45        /* val.l = constant                   */
331         1,
332 #define JAVA_IALOAD           46
333 #define ICMD_IALOAD           46
334         1,
335 #define JAVA_LALOAD           47
336 #define ICMD_LALOAD           47
337         1,
338 #define JAVA_FALOAD           48
339 #define ICMD_FALOAD           48
340         1,
341 #define JAVA_DALOAD           49
342 #define ICMD_DALOAD           49
343         1,
344 #define JAVA_AALOAD           50
345 #define ICMD_AALOAD           50
346         1,
347 #define JAVA_BALOAD           51
348 #define ICMD_BALOAD           51
349         1,
350 #define JAVA_CALOAD           52
351 #define ICMD_CALOAD           52
352         1,
353 #define JAVA_SALOAD           53
354 #define ICMD_SALOAD           53
355         1,
356                                             /* order of STORE instructions must be*/
357                                             /* equal to order of TYPE_XXX defines */
358 #define JAVA_ISTORE           54
359 #define ICMD_ISTORE           54        /* op1 = local variable               */
360         2,
361 #define JAVA_LSTORE           55
362 #define ICMD_LSTORE           55        /* op1 = local variable               */
363         2,
364 #define JAVA_FSTORE           56
365 #define ICMD_FSTORE           56        /* op1 = local variable               */
366         2,
367 #define JAVA_DSTORE           57
368 #define ICMD_DSTORE           57        /* op1 = local variable               */
369         2,
370 #define JAVA_ASTORE           58
371 #define ICMD_ASTORE           58        /* op1 = local variable               */
372         2,
373 #define JAVA_ISTORE_0         59
374 #define ICMD_IF_LEQ           59        /* op1 = target JavaVM pc, val.l      */
375         1,
376 #define JAVA_ISTORE_1         60
377 #define ICMD_IF_LNE           60        /* op1 = target JavaVM pc, val.l      */
378         1,
379 #define JAVA_ISTORE_2         61
380 #define ICMD_IF_LLT           61        /* op1 = target JavaVM pc, val.l      */
381         1,
382 #define JAVA_ISTORE_3         62
383 #define ICMD_IF_LGE           62        /* op1 = target JavaVM pc, val.l      */
384         1,
385 #define JAVA_LSTORE_0         63
386 #define ICMD_IF_LGT           63        /* op1 = target JavaVM pc, val.l      */
387         1,
388 #define JAVA_LSTORE_1         64
389 #define ICMD_IF_LLE           64        /* op1 = target JavaVM pc, val.l      */
390         1,
391 #define JAVA_LSTORE_2         65
392 #define ICMD_IF_LCMPEQ        65        /* op1 = target JavaVM pc             */
393         1,
394 #define JAVA_LSTORE_3         66
395 #define ICMD_IF_LCMPNE        66        /* op1 = target JavaVM pc             */
396         1,
397 #define JAVA_FSTORE_0         67
398 #define ICMD_IF_LCMPLT        67        /* op1 = target JavaVM pc             */
399         1,
400 #define JAVA_FSTORE_1         68
401 #define ICMD_IF_LCMPGE        68        /* op1 = target JavaVM pc             */
402         1,
403 #define JAVA_FSTORE_2         69
404 #define ICMD_IF_LCMPGT        69        /* op1 = target JavaVM pc             */
405         1,
406 #define JAVA_FSTORE_3         70
407 #define ICMD_IF_LCMPLE        70        /* op1 = target JavaVM pc             */
408         1,
409 #define JAVA_DSTORE_0         71
410         1,
411 #define JAVA_DSTORE_1         72
412         1,
413 #define JAVA_DSTORE_2         73
414         1,
415 #define JAVA_DSTORE_3         74
416         1,
417 #define JAVA_ASTORE_0         75
418         1,
419 #define JAVA_ASTORE_1         76
420         1,
421 #define JAVA_ASTORE_2         77
422         1,
423 #define JAVA_ASTORE_3         78
424         1,
425 #define JAVA_IASTORE          79
426 #define ICMD_IASTORE          79
427         1,
428 #define JAVA_LASTORE          80
429 #define ICMD_LASTORE          80
430         1,
431 #define JAVA_FASTORE          81
432 #define ICMD_FASTORE          81
433         1,
434 #define JAVA_DASTORE          82
435 #define ICMD_DASTORE          82
436         1,
437 #define JAVA_AASTORE          83
438 #define ICMD_AASTORE          83
439         1,
440 #define JAVA_BASTORE          84
441 #define ICMD_BASTORE          84
442         1,
443 #define JAVA_CASTORE          85
444 #define ICMD_CASTORE          85
445         1,
446 #define JAVA_SASTORE          86
447 #define ICMD_SASTORE          86
448         1,
449 #define JAVA_POP              87
450 #define ICMD_POP              87
451         1,
452 #define JAVA_POP2             88
453 #define ICMD_POP2             88
454         1,
455 #define JAVA_DUP              89
456 #define ICMD_DUP              89
457         1,
458 #define JAVA_DUP_X1           90
459 #define ICMD_DUP_X1           90
460         1,
461 #define JAVA_DUP_X2           91
462 #define ICMD_DUP_X2           91
463         1,
464 #define JAVA_DUP2             92
465 #define ICMD_DUP2             92
466         1,
467 #define JAVA_DUP2_X1          93
468 #define ICMD_DUP2_X1          93
469         1,
470 #define JAVA_DUP2_X2          94
471 #define ICMD_DUP2_X2          94
472         1,
473 #define JAVA_SWAP             95
474 #define ICMD_SWAP             95
475         1,
476 #define JAVA_IADD             96
477 #define ICMD_IADD             96
478         1,
479 #define JAVA_LADD             97
480 #define ICMD_LADD             97
481         1,
482 #define JAVA_FADD             98
483 #define ICMD_FADD             98
484         1,
485 #define JAVA_DADD             99
486 #define ICMD_DADD             99
487         1,
488 #define JAVA_ISUB             100
489 #define ICMD_ISUB             100
490         1,
491 #define JAVA_LSUB             101
492 #define ICMD_LSUB             101
493         1,
494 #define JAVA_FSUB             102
495 #define ICMD_FSUB             102
496         1,
497 #define JAVA_DSUB             103
498 #define ICMD_DSUB             103
499         1,
500 #define JAVA_IMUL             104
501 #define ICMD_IMUL             104
502         1,
503 #define JAVA_LMUL             105
504 #define ICMD_LMUL             105
505         1,
506 #define JAVA_FMUL             106
507 #define ICMD_FMUL             106
508         1,
509 #define JAVA_DMUL             107
510 #define ICMD_DMUL             107
511         1,
512 #define JAVA_IDIV             108
513 #define ICMD_IDIV             108
514         1,
515 #define JAVA_LDIV             109
516 #define ICMD_LDIV             109
517         1,
518 #define JAVA_FDIV             110
519 #define ICMD_FDIV             110
520         1,
521 #define JAVA_DDIV             111
522 #define ICMD_DDIV             111
523         1,
524 #define JAVA_IREM             112
525 #define ICMD_IREM             112
526         1,
527 #define JAVA_LREM             113
528 #define ICMD_LREM             113
529         1,
530 #define JAVA_FREM             114
531 #define ICMD_FREM             114
532         1,
533 #define JAVA_DREM             115
534 #define ICMD_DREM             115
535         1,
536 #define JAVA_INEG             116
537 #define ICMD_INEG             116
538         1,
539 #define JAVA_LNEG             117
540 #define ICMD_LNEG             117
541         1,
542 #define JAVA_FNEG             118
543 #define ICMD_FNEG             118
544         1,
545 #define JAVA_DNEG             119
546 #define ICMD_DNEG             119
547         1,
548 #define JAVA_ISHL             120
549 #define ICMD_ISHL             120
550         1,
551 #define JAVA_LSHL             121
552 #define ICMD_LSHL             121
553         1,
554 #define JAVA_ISHR             122
555 #define ICMD_ISHR             122
556         1,
557 #define JAVA_LSHR             123
558 #define ICMD_LSHR             123
559         1,
560 #define JAVA_IUSHR            124
561 #define ICMD_IUSHR            124
562         1,
563 #define JAVA_LUSHR            125
564 #define ICMD_LUSHR            125
565         1,
566 #define JAVA_IAND             126
567 #define ICMD_IAND             126
568         1,
569 #define JAVA_LAND             127
570 #define ICMD_LAND             127
571         1,
572 #define JAVA_IOR              128
573 #define ICMD_IOR              128
574         1,
575 #define JAVA_LOR              129
576 #define ICMD_LOR              129
577         1,
578 #define JAVA_IXOR             130
579 #define ICMD_IXOR             130
580         1,
581 #define JAVA_LXOR             131
582 #define ICMD_LXOR             131
583         1,
584 #define JAVA_IINC             132
585 #define ICMD_IINC             132   /* op1 = local variable, val.i = constant */
586         3,
587 #define JAVA_I2L              133
588 #define ICMD_I2L              133
589         1,
590 #define JAVA_I2F              134
591 #define ICMD_I2F              134
592         1,
593 #define JAVA_I2D              135
594 #define ICMD_I2D              135
595         1,
596 #define JAVA_L2I              136
597 #define ICMD_L2I              136
598         1,
599 #define JAVA_L2F              137
600 #define ICMD_L2F              137
601         1,
602 #define JAVA_L2D              138
603 #define ICMD_L2D              138
604         1,
605 #define JAVA_F2I              139
606 #define ICMD_F2I              139
607         1,
608 #define JAVA_F2L              140
609 #define ICMD_F2L              140
610         1,
611 #define JAVA_F2D              141
612 #define ICMD_F2D              141
613         1,
614 #define JAVA_D2I              142
615 #define ICMD_D2I              142
616         1,
617 #define JAVA_D2L              143
618 #define ICMD_D2L              143
619         1,
620 #define JAVA_D2F              144
621 #define ICMD_D2F              144
622         1,
623 #define JAVA_INT2BYTE         145
624 #define ICMD_INT2BYTE         145
625         1,
626 #define JAVA_INT2CHAR         146
627 #define ICMD_INT2CHAR         146
628         1,
629 #define JAVA_INT2SHORT        147
630 #define ICMD_INT2SHORT        147
631         1,
632 #define JAVA_LCMP             148
633 #define ICMD_LCMP             148
634         1,
635 #define JAVA_FCMPL            149
636 #define ICMD_FCMPL            149
637         1,
638 #define JAVA_FCMPG            150
639 #define ICMD_FCMPG            150
640         1,
641 #define JAVA_DCMPL            151
642 #define ICMD_DCMPL            151
643         1,
644 #define JAVA_DCMPG            152
645 #define ICMD_DCMPG            152
646         1,
647 #define JAVA_IFEQ             153
648 #define ICMD_IFEQ             153       /* op1 = target JavaVM pc, val.i      */
649         3,
650 #define JAVA_IFNE             154
651 #define ICMD_IFNE             154       /* op1 = target JavaVM pc, val.i      */
652         3,
653 #define JAVA_IFLT             155
654 #define ICMD_IFLT             155       /* op1 = target JavaVM pc, val.i      */
655         3,
656 #define JAVA_IFGE             156
657 #define ICMD_IFGE             156       /* op1 = target JavaVM pc, val.i      */
658         3,
659 #define JAVA_IFGT             157
660 #define ICMD_IFGT             157       /* op1 = target JavaVM pc, val.i      */
661         3,
662 #define JAVA_IFLE             158
663 #define ICMD_IFLE             158       /* op1 = target JavaVM pc, val.i      */
664         3,
665 #define JAVA_IF_ICMPEQ        159
666 #define ICMD_IF_ICMPEQ        159       /* op1 = target JavaVM pc             */
667         3,
668 #define JAVA_IF_ICMPNE        160
669 #define ICMD_IF_ICMPNE        160       /* op1 = target JavaVM pc             */
670         3,
671 #define JAVA_IF_ICMPLT        161
672 #define ICMD_IF_ICMPLT        161       /* op1 = target JavaVM pc             */
673         3,
674 #define JAVA_IF_ICMPGE        162
675 #define ICMD_IF_ICMPGE        162       /* op1 = target JavaVM pc             */
676         3,
677 #define JAVA_IF_ICMPGT        163
678 #define ICMD_IF_ICMPGT        163       /* op1 = target JavaVM pc             */
679         3,
680 #define JAVA_IF_ICMPLE        164
681 #define ICMD_IF_ICMPLE        164       /* op1 = target JavaVM pc             */
682         3,
683 #define JAVA_IF_ACMPEQ        165
684 #define ICMD_IF_ACMPEQ        165       /* op1 = target JavaVM pc             */
685         3,
686 #define JAVA_IF_ACMPNE        166
687 #define ICMD_IF_ACMPNE        166       /* op1 = target JavaVM pc             */
688         3,
689 #define JAVA_GOTO             167
690 #define ICMD_GOTO             167       /* op1 = target JavaVM pc             */
691         3,
692 #define JAVA_JSR              168
693 #define ICMD_JSR              168       /* op1 = target JavaVM pc             */
694         3,
695 #define JAVA_RET              169
696 #define ICMD_RET              169       /* op1 = local variable               */
697         2,
698 #define JAVA_TABLESWITCH      170
699 #define ICMD_TABLESWITCH      170       /* val.a = pointer to s4 table        */
700         0,                                  /* length must be computed            */
701 #define JAVA_LOOKUPSWITCH     171
702 #define ICMD_LOOKUPSWITCH     171       /* val.a = pointer to s4 table        */
703         0,                                  /* length must be computed            */
704 #define JAVA_IRETURN          172
705 #define ICMD_IRETURN          172
706         1,
707 #define JAVA_LRETURN          173
708 #define ICMD_LRETURN          173
709         1,
710 #define JAVA_FRETURN          174
711 #define ICMD_FRETURN          174
712         1,
713 #define JAVA_DRETURN          175
714 #define ICMD_DRETURN          175
715         1,
716 #define JAVA_ARETURN          176
717 #define ICMD_ARETURN          176
718         1,
719 #define JAVA_RETURN           177
720 #define ICMD_RETURN           177
721         1,
722 #define JAVA_GETSTATIC        178
723 #define ICMD_GETSTATIC        178       /* op1 = type, val.a = field address  */
724         3,
725 #define JAVA_PUTSTATIC        179
726 #define ICMD_PUTSTATIC        179       /* op1 = type, val.a = field address  */
727         3,
728 #define JAVA_GETFIELD         180
729 #define ICMD_GETFIELD         180       /* op1 = type, val.i = field offset   */
730         3,
731 #define JAVA_PUTFIELD         181
732 #define ICMD_PUTFIELD         181       /* op1 = type, val.i = field offset   */
733         3,
734 #define JAVA_INVOKEVIRTUAL    182
735 #define ICMD_INVOKEVIRTUAL    182       /* val.a = method info pointer        */
736         3,
737 #define JAVA_INVOKESPECIAL    183
738 #define ICMD_INVOKESPECIAL    183       /* val.a = method info pointer        */
739         3,
740 #define JAVA_INVOKESTATIC     184
741 #define ICMD_INVOKESTATIC     184       /* val.a = method info pointer        */
742         3,
743 #define JAVA_INVOKEINTERFACE  185
744 #define ICMD_INVOKEINTERFACE  185       /* val.a = method info pointer        */
745         5,
746 #define ICMD_CHECKASIZE       186       /*                                    */
747         1, /* unused */
748 #define JAVA_NEW              187
749 #define ICMD_NEW              187       /* op1 = 1, val.a = class pointer     */
750         3,
751 #define JAVA_NEWARRAY         188
752 #define ICMD_NEWARRAY         188       /* op1 = basic type                   */
753         2,
754 #define JAVA_ANEWARRAY        189
755 #define ICMD_ANEWARRAY        189       /* op1 = 0, val.a = array pointer     */
756         3,                                  /* op1 = 1, val.a = class pointer     */
757 #define JAVA_ARRAYLENGTH      190
758 #define ICMD_ARRAYLENGTH      190
759         1,
760 #define JAVA_ATHROW           191
761 #define ICMD_ATHROW           191
762         1,
763 #define JAVA_CHECKCAST        192
764 #define ICMD_CHECKCAST        192       /* op1 = 0, val.a = array pointer     */
765         3,                                  /* op1 = 1, val.a = class pointer     */
766 #define JAVA_INSTANCEOF       193
767 #define ICMD_INSTANCEOF       193       /* op1 = 0, val.a = array pointer     */
768         3,                                  /* op1 = 1, val.a = class pointer     */
769 #define JAVA_MONITORENTER     194
770 #define ICMD_MONITORENTER     194
771         1,
772 #define JAVA_MONITOREXIT      195
773 #define ICMD_MONITOREXIT      195
774         1,
775 #define JAVA_WIDE             196
776         0, /* length must be computed */
777 #define JAVA_MULTIANEWARRAY   197
778 #define ICMD_MULTIANEWARRAY   197       /* op1 = dimension, val.a = array     */
779         4,                                  /* pointer                            */
780 #define JAVA_IFNULL           198
781 #define ICMD_IFNULL           198       /* op1 = target JavaVM pc             */
782         3,
783 #define JAVA_IFNONNULL        199
784 #define ICMD_IFNONNULL        199       /* op1 = target JavaVM pc             */
785         3,
786 #define JAVA_GOTO_W           200
787         5,
788 #define JAVA_JSR_W            201
789         5,
790 #define JAVA_BREAKPOINT       202
791         1,
792
793             1,1,1,1,1,1,1,1,            /* unused */
794         1,1,1,1,1,1,1,1,1,1,
795         1,1,1,1,1,1,1,1,1,1,
796         1,1,1,1,1,1,1,1,1,1,
797         1,1,1,1,1,1,1,1,1,1,
798         1,1,1,1,1
799 };
800
801
802 char *icmd_names[256] = {
803         "NOP          ", /*               0 */
804         "ACONST       ", /*               1 */
805         "NULLCHECKPOP ", /* ICONST_M1     2 */
806         "ICONST       ", /*               3 */
807         "IREM0X10001  ", /* ICONST_1      4 */
808         "IDIVPOW2     ", /* ICONST_2      5 */
809         "LDIVPOW2     ", /* ICONST_3      6 */
810         "UNDEF__7     ", /* ICONST_4      7 */
811         "LREM0X10001  ", /* ICONST_5      8 */
812         "LCONST       ", /*               9 */
813         "LCMPCONST    ", /* LCONST_1     10 */
814         "FCONST       ", /*              11 */
815         "UNDEF_12     ", /* FCONST_1     12 */
816         "ELSE_ICONST  ", /* FCONST_2     13 */
817         "DCONST       ", /*              14 */
818         "IFEQ_ICONST  ", /* DCONST_1     15 */
819         "IFNE_ICONST  ", /* BIPUSH       16 */
820         "IFLT_ICONST  ", /* SIPUSH       17 */
821         "IFGE_ICONST  ", /* LDC1         18 */
822         "IFGT_ICONST  ", /* LDC2         19 */
823         "IFLE_ICONST  ", /* LDC2W        20 */
824         "ILOAD        ", /*              21 */
825         "LLOAD        ", /*              22 */
826         "FLOAD        ", /*              23 */
827         "DLOAD        ", /*              24 */
828         "ALOAD        ", /*              25 */
829         "IADDCONST    ", /* ILOAD_0      26 */
830         "ISUBCONST    ", /* ILOAD_1      27 */
831         "IMULCONST    ", /* ILOAD_2      28 */
832         "IANDCONST    ", /* ILOAD_3      29 */
833         "IORCONST     ", /* LLOAD_0      30 */
834         "IXORCONST    ", /* LLOAD_1      31 */
835         "ISHLCONST    ", /* LLOAD_2      32 */
836         "ISHRCONST    ", /* LLOAD_3      33 */
837         "IUSHRCONST   ", /* FLOAD_0      34 */
838         "IREMPOW2     ", /* FLOAD_1      35 */
839         "LADDCONST    ", /* FLOAD_2      36 */
840         "LSUBCONST    ", /* FLOAD_3      37 */
841         "LMULCONST    ", /* DLOAD_0      38 */
842         "LANDCONST    ", /* DLOAD_1      39 */
843         "LORCONST     ", /* DLOAD_2      40 */
844         "LXORCONST    ", /* DLOAD_3      41 */
845         "LSHLCONST    ", /* ALOAD_0      42 */
846         "LSHRCONST    ", /* ALOAD_1      43 */
847         "LUSHRCONST   ", /* ALOAD_2      44 */
848         "LREMPOW2     ", /* ALOAD_3      45 */
849         "IALOAD       ", /*              46 */
850         "LALOAD       ", /*              47 */
851         "FALOAD       ", /*              48 */
852         "DALOAD       ", /*              49 */
853         "AALOAD       ", /*              50 */
854         "BALOAD       ", /*              51 */
855         "CALOAD       ", /*              52 */
856         "SALOAD       ", /*              53 */
857         "ISTORE       ", /*              54 */
858         "LSTORE       ", /*              55 */
859         "FSTORE       ", /*              56 */
860         "DSTORE       ", /*              57 */
861         "ASTORE       ", /*              58 */
862         "IF_LEQ       ", /* ISTORE_0     59 */
863         "IF_LNE       ", /* ISTORE_1     60 */
864         "IF_LLT       ", /* ISTORE_2     61 */
865         "IF_LGE       ", /* ISTORE_3     62 */
866         "IF_LGT       ", /* LSTORE_0     63 */
867         "IF_LLE       ", /* LSTORE_1     64 */
868         "IF_LCMPEQ    ", /* LSTORE_2     65 */
869         "IF_LCMPNE    ", /* LSTORE_3     66 */
870         "IF_LCMPLT    ", /* FSTORE_0     67 */
871         "IF_LCMPGE    ", /* FSTORE_1     68 */
872         "IF_LCMPGT    ", /* FSTORE_2     69 */
873         "IF_LCMPLE    ", /* FSTORE_3     70 */
874         "UNDEF_71     ", /* DSTORE_0     71 */
875         "UNDEF_72     ", /* DSTORE_1     72 */
876         "UNDEF_73     ", /* DSTORE_2     73 */
877         "UNDEF_74     ", /* DSTORE_3     74 */
878         "UNDEF_75     ", /* ASTORE_0     75 */
879         "UNDEF_76     ", /* ASTORE_1     76 */
880         "UNDEF_77     ", /* ASTORE_2     77 */
881         "UNDEF_78     ", /* ASTORE_3     78 */
882         "IASTORE      ", /*              79 */
883         "LASTORE      ", /*              80 */
884         "FASTORE      ", /*              81 */
885         "DASTORE      ", /*              82 */
886         "AASTORE      ", /*              83 */
887         "BASTORE      ", /*              84 */
888         "CASTORE      ", /*              85 */
889         "SASTORE      ", /*              86 */
890         "POP          ", /*              87 */
891         "POP2         ", /*              88 */
892         "DUP          ", /*              89 */
893         "DUP_X1       ", /*              90 */
894         "DUP_X2       ", /*              91 */
895         "DUP2         ", /*              92 */
896         "DUP2_X1      ", /*              93 */
897         "DUP2_X2      ", /*              94 */
898         "SWAP         ", /*              95 */
899         "IADD         ", /*              96 */
900         "LADD         ", /*              97 */
901         "FADD         ", /*              98 */
902         "DADD         ", /*              99 */
903         "ISUB         ", /*             100 */
904         "LSUB         ", /*             101 */
905         "FSUB         ", /*             102 */
906         "DSUB         ", /*             103 */
907         "IMUL         ", /*             104 */
908         "LMUL         ", /*             105 */
909         "FMUL         ", /*             106 */
910         "DMUL         ", /*             107 */
911         "IDIV         ", /*             108 */
912         "LDIV         ", /*             109 */
913         "FDIV         ", /*             110 */
914         "DDIV         ", /*             111 */
915         "IREM         ", /*             112 */
916         "LREM         ", /*             113 */
917         "FREM         ", /*             114 */
918         "DREM         ", /*             115 */
919         "INEG         ", /*             116 */
920         "LNEG         ", /*             117 */
921         "FNEG         ", /*             118 */
922         "DNEG         ", /*             119 */
923         "ISHL         ", /*             120 */
924         "LSHL         ", /*             121 */
925         "ISHR         ", /*             122 */
926         "LSHR         ", /*             123 */
927         "IUSHR        ", /*             124 */
928         "LUSHR        ", /*             125 */
929         "IAND         ", /*             126 */
930         "LAND         ", /*             127 */
931         "IOR          ", /*             128 */
932         "LOR          ", /*             129 */
933         "IXOR         ", /*             130 */
934         "LXOR         ", /*             131 */
935         "IINC         ", /*             132 */
936         "I2L          ", /*             133 */
937         "I2F          ", /*             134 */
938         "I2D          ", /*             135 */
939         "L2I          ", /*             136 */
940         "L2F          ", /*             137 */
941         "L2D          ", /*             138 */
942         "F2I          ", /*             139 */
943         "F2L          ", /*             140 */
944         "F2D          ", /*             141 */
945         "D2I          ", /*             142 */
946         "D2L          ", /*             143 */
947         "D2F          ", /*             144 */
948         "INT2BYTE     ", /*             145 */
949         "INT2CHAR     ", /*             146 */
950         "INT2SHORT    ", /*             147 */
951         "LCMP         ", /*             148 */
952         "FCMPL        ", /*             149 */
953         "FCMPG        ", /*             150 */
954         "DCMPL        ", /*             151 */
955         "DCMPG        ", /*             152 */
956         "IFEQ         ", /*             153 */
957         "IFNE         ", /*             154 */
958         "IFLT         ", /*             155 */
959         "IFGE         ", /*             156 */
960         "IFGT         ", /*             157 */
961         "IFLE         ", /*             158 */
962         "IF_ICMPEQ    ", /*             159 */
963         "IF_ICMPNE    ", /*             160 */
964         "IF_ICMPLT    ", /*             161 */
965         "IF_ICMPGE    ", /*             162 */
966         "IF_ICMPGT    ", /*             163 */
967         "IF_ICMPLE    ", /*             164 */
968         "IF_ACMPEQ    ", /*             165 */
969         "IF_ACMPNE    ", /*             166 */
970         "GOTO         ", /*             167 */
971         "JSR          ", /*             168 */
972         "RET          ", /*             169 */
973         "TABLESWITCH  ", /*             170 */
974         "LOOKUPSWITCH ", /*             171 */
975         "IRETURN      ", /*             172 */
976         "LRETURN      ", /*             173 */
977         "FRETURN      ", /*             174 */
978         "DRETURN      ", /*             175 */
979         "ARETURN      ", /*             176 */
980         "RETURN       ", /*             177 */
981         "GETSTATIC    ", /*             178 */
982         "PUTSTATIC    ", /*             179 */
983         "GETFIELD     ", /*             180 */
984         "PUTFIELD     ", /*             181 */
985         "INVOKEVIRTUAL", /*             182 */
986         "INVOKESPECIAL", /*             183 */
987         "INVOKESTATIC ", /*             184 */
988         "INVOKEINTERFACE",/*            185 */
989         "CHECKASIZE   ", /* UNDEF186    186 */
990         "NEW          ", /*             187 */
991         "NEWARRAY     ", /*             188 */
992         "ANEWARRAY    ", /*             189 */
993         "ARRAYLENGTH  ", /*             190 */
994         "ATHROW       ", /*             191 */
995         "CHECKCAST    ", /*             192 */
996         "INSTANCEOF   ", /*             193 */
997         "MONITORENTER ", /*             194 */
998         "MONITOREXIT  ", /*             195 */
999         "UNDEF196     ", /* WIDE        196 */
1000         "MULTIANEWARRAY",/*             197 */
1001         "IFNULL       ", /*             198 */
1002         "IFNONNULL    ", /*             199 */
1003         "UNDEF200     ", /* GOTO_W      200 */
1004         "UNDEF201     ", /* JSR_W       201 */
1005         "UNDEF202     ", /* BREAKPOINT  202 */
1006
1007                               "UNDEF203","UNDEF204","UNDEF205",
1008         "UNDEF206","UNDEF207","UNDEF208","UNDEF209","UNDEF210",
1009         "UNDEF","UNDEF","UNDEF","UNDEF","UNDEF",
1010         "UNDEF216","UNDEF217","UNDEF218","UNDEF219","UNDEF220",
1011         "UNDEF","UNDEF","UNDEF","UNDEF","UNDEF",
1012         "UNDEF226","UNDEF227","UNDEF228","UNDEF229","UNDEF230",
1013         "UNDEF","UNDEF","UNDEF","UNDEF","UNDEF",
1014         "UNDEF236","UNDEF237","UNDEF238","UNDEF239","UNDEF240",
1015         "UNDEF","UNDEF","UNDEF","UNDEF","UNDEF",
1016         "UNDEF246","UNDEF247","UNDEF248","UNDEF249","UNDEF250",
1017         "UNDEF251","UNDEF252",
1018
1019         "BUILTIN3     ", /*             253 */
1020         "BUILTIN2     ", /*             254 */
1021         "BUILTIN1     "  /*             255 */
1022 };
1023
1024
1025 char *opcode_names[256] = {
1026         "NOP          ", /*               0 */
1027         "ACONST       ", /*               1 */
1028         "ICONST_M1    ", /* ICONST_M1     2 */
1029         "ICONST_0     ", /* ICONST_0      3 */
1030         "ICONST_1     ", /* ICONST_1      4 */
1031         "ICONST_2     ", /* ICONST_2      5 */
1032         "ICONST_3     ", /* ICONST_3      6 */
1033         "ICONST_4     ", /* ICONST_4      7 */
1034         "ICONST_5     ", /* ICONST_5      8 */
1035         "LCONST_0     ", /* LCONST_0      9 */
1036         "LCONST_1     ", /* LCONST_1     10 */
1037         "FCONST_0     ", /* FCONST_0     11 */
1038         "FCONST_1     ", /* FCONST_1     12 */
1039         "FCONST_2     ", /* FCONST_2     13 */
1040         "DCONST_0     ", /* DCONST_0     14 */
1041         "DCONST_1     ", /* DCONST_1     15 */
1042         "BIPUSH       ", /* BIPUSH       16 */
1043         "SIPUSH       ", /* SIPUSH       17 */
1044         "LDC          ", /* LDC          18 */
1045         "LDC_W        ", /* LDC_W        19 */
1046         "LDC2_W       ", /* LDC2_W       20 */
1047         "ILOAD        ", /*              21 */
1048         "LLOAD        ", /*              22 */
1049         "FLOAD        ", /*              23 */
1050         "DLOAD        ", /*              24 */
1051         "ALOAD        ", /*              25 */
1052         "ILOAD_0      ", /* ILOAD_0      26 */
1053         "ILOAD_1      ", /* ILOAD_1      27 */
1054         "ILOAD_2      ", /* ILOAD_2      28 */
1055         "ILOAD_3      ", /* ILOAD_3      29 */
1056         "LLOAD_0      ", /* LLOAD_0      30 */
1057         "LLOAD_1      ", /* LLOAD_1      31 */
1058         "LLOAD_2      ", /* LLOAD_2      32 */
1059         "LLOAD_3      ", /* LLOAD_3      33 */
1060         "FLOAD_0      ", /* FLOAD_0      34 */
1061         "FLOAD_1      ", /* FLOAD_1      35 */
1062         "FLOAD_2      ", /* FLOAD_2      36 */
1063         "FLOAD_3      ", /* FLOAD_3      37 */
1064         "DLOAD_0      ", /* DLOAD_0      38 */
1065         "DLOAD_1      ", /* DLOAD_1      39 */
1066         "DLOAD_2      ", /* DLOAD_2      40 */ 
1067         "DLOAD_3      ", /* DLOAD_3      41 */
1068         "ALOAD_0      ", /* ALOAD_0      42 */
1069         "ALOAD_1      ", /* ALOAD_1      43 */
1070         "ALOAD_2      ", /* ALOAD_2      44 */
1071         "ALOAD_3      ", /* ALOAD_3      45 */
1072         "IALOAD       ", /*              46 */
1073         "LALOAD       ", /*              47 */
1074         "FALOAD       ", /*              48 */
1075         "DALOAD       ", /*              49 */
1076         "AALOAD       ", /*              50 */
1077         "BALOAD       ", /*              51 */
1078         "CALOAD       ", /*              52 */
1079         "SALOAD       ", /*              53 */
1080         "ISTORE       ", /*              54 */
1081         "LSTORE       ", /*              55 */
1082         "FSTORE       ", /*              56 */
1083         "DSTORE       ", /*              57 */
1084         "ASTORE       ", /*              58 */
1085         "ISTORE_0     ", /* ISTORE_0     59 */
1086         "ISTORE_1     ", /* ISTORE_1     60 */
1087         "ISTORE_2     ", /* ISTORE_2     61 */
1088         "ISTORE_3     ", /* ISTORE_3     62 */
1089         "LSTORE_0     ", /* LSTORE_0     63 */
1090         "LSTORE_1     ", /* LSTORE_1     64 */
1091         "LSTORE_2     ", /* LSTORE_2     65 */
1092         "LSTORE_3     ", /* LSTORE_3     66 */
1093         "FSTORE_0     ", /* FSTORE_0     67 */
1094         "FSTORE_1     ", /* FSTORE_1     68 */
1095         "FSTORE_2     ", /* FSTORE_2     69 */
1096         "FSTORE_3     ", /* FSTORE_3     70 */
1097         "DSTORE_0     ", /* DSTORE_0     71 */
1098         "DSTORE_1     ", /* DSTORE_1     72 */
1099         "DSTORE_2     ", /* DSTORE_2     73 */
1100         "DSTORE_3     ", /* DSTORE_3     74 */
1101         "ASTORE_0     ", /* ASTORE_0     75 */
1102         "ASTORE_1     ", /* ASTORE_1     76 */
1103         "ASTORE_2     ", /* ASTORE_2     77 */
1104         "ASTORE_3     ", /* ASTORE_3     78 */
1105         "IASTORE      ", /*              79 */
1106         "LASTORE      ", /*              80 */
1107         "FASTORE      ", /*              81 */
1108         "DASTORE      ", /*              82 */
1109         "AASTORE      ", /*              83 */
1110         "BASTORE      ", /*              84 */
1111         "CASTORE      ", /*              85 */
1112         "SASTORE      ", /*              86 */
1113         "POP          ", /*              87 */
1114         "POP2         ", /*              88 */
1115         "DUP          ", /*              89 */
1116         "DUP_X1       ", /*              90 */
1117         "DUP_X2       ", /*              91 */
1118         "DUP2         ", /*              92 */
1119         "DUP2_X1      ", /*              93 */
1120         "DUP2_X2      ", /*              94 */
1121         "SWAP         ", /*              95 */
1122         "IADD         ", /*              96 */
1123         "LADD         ", /*              97 */
1124         "FADD         ", /*              98 */
1125         "DADD         ", /*              99 */
1126         "ISUB         ", /*             100 */
1127         "LSUB         ", /*             101 */
1128         "FSUB         ", /*             102 */
1129         "DSUB         ", /*             103 */
1130         "IMUL         ", /*             104 */
1131         "LMUL         ", /*             105 */
1132         "FMUL         ", /*             106 */
1133         "DMUL         ", /*             107 */
1134         "IDIV         ", /*             108 */
1135         "LDIV         ", /*             109 */
1136         "FDIV         ", /*             110 */
1137         "DDIV         ", /*             111 */
1138         "IREM         ", /*             112 */
1139         "LREM         ", /*             113 */
1140         "FREM         ", /*             114 */
1141         "DREM         ", /*             115 */
1142         "INEG         ", /*             116 */
1143         "LNEG         ", /*             117 */
1144         "FNEG         ", /*             118 */
1145         "DNEG         ", /*             119 */
1146         "ISHL         ", /*             120 */
1147         "LSHL         ", /*             121 */
1148         "ISHR         ", /*             122 */
1149         "LSHR         ", /*             123 */
1150         "IUSHR        ", /*             124 */
1151         "LUSHR        ", /*             125 */
1152         "IAND         ", /*             126 */
1153         "LAND         ", /*             127 */
1154         "IOR          ", /*             128 */
1155         "LOR          ", /*             129 */
1156         "IXOR         ", /*             130 */
1157         "LXOR         ", /*             131 */
1158         "IINC         ", /*             132 */
1159         "I2L          ", /*             133 */
1160         "I2F          ", /*             134 */
1161         "I2D          ", /*             135 */
1162         "L2I          ", /*             136 */
1163         "L2F          ", /*             137 */
1164         "L2D          ", /*             138 */
1165         "F2I          ", /*             139 */
1166         "F2L          ", /*             140 */
1167         "F2D          ", /*             141 */
1168         "D2I          ", /*             142 */
1169         "D2L          ", /*             143 */
1170         "D2F          ", /*             144 */
1171         "INT2BYTE     ", /*             145 */
1172         "INT2CHAR     ", /*             146 */
1173         "INT2SHORT    ", /*             147 */
1174         "LCMP         ", /*             148 */
1175         "FCMPL        ", /*             149 */
1176         "FCMPG        ", /*             150 */
1177         "DCMPL        ", /*             151 */
1178         "DCMPG        ", /*             152 */
1179         "IFEQ         ", /*             153 */
1180         "IFNE         ", /*             154 */
1181         "IFLT         ", /*             155 */
1182         "IFGE         ", /*             156 */
1183         "IFGT         ", /*             157 */
1184         "IFLE         ", /*             158 */
1185         "IF_ICMPEQ    ", /*             159 */
1186         "IF_ICMPNE    ", /*             160 */
1187         "IF_ICMPLT    ", /*             161 */
1188         "IF_ICMPGE    ", /*             162 */
1189         "IF_ICMPGT    ", /*             163 */
1190         "IF_ICMPLE    ", /*             164 */
1191         "IF_ACMPEQ    ", /*             165 */
1192         "IF_ACMPNE    ", /*             166 */
1193         "GOTO         ", /*             167 */
1194         "JSR          ", /*             168 */
1195         "RET          ", /*             169 */
1196         "TABLESWITCH  ", /*             170 */
1197         "LOOKUPSWITCH ", /*             171 */
1198         "IRETURN      ", /*             172 */
1199         "LRETURN      ", /*             173 */
1200         "FRETURN      ", /*             174 */
1201         "DRETURN      ", /*             175 */
1202         "ARETURN      ", /*             176 */
1203         "RETURN       ", /*             177 */
1204         "GETSTATIC    ", /*             178 */
1205         "PUTSTATIC    ", /*             179 */
1206         "GETFIELD     ", /*             180 */
1207         "PUTFIELD     ", /*             181 */
1208         "INVOKEVIRTUAL", /*             182 */
1209         "INVOKESPECIAL", /*             183 */
1210         "INVOKESTATIC ", /*             184 */
1211         "INVOKEINTERFACE",/*            185 */
1212         "CHECKASIZE   ", /* UNDEF186    186 */
1213         "NEW          ", /*             187 */
1214         "NEWARRAY     ", /*             188 */
1215         "ANEWARRAY    ", /*             189 */
1216         "ARRAYLENGTH  ", /*             190 */
1217         "ATHROW       ", /*             191 */
1218         "CHECKCAST    ", /*             192 */
1219         "INSTANCEOF   ", /*             193 */
1220         "MONITORENTER ", /*             194 */
1221         "MONITOREXIT  ", /*             195 */
1222         "WIDE         ", /* WIDE        196 */
1223         "MULTIANEWARRAY",/*             197 */
1224         "IFNULL       ", /*             198 */
1225         "IFNONNULL    ", /*             199 */
1226         "GOTO_W       ", /* GOTO_W      200 */
1227         "JSR_W        ", /* JSR_W       201 */
1228         "BREAKPOINT   ", /* BREAKPOINT  202 */
1229
1230                               "UNDEF203","UNDEF204","UNDEF205",
1231         "UNDEF206","UNDEF207","UNDEF208","UNDEF209","UNDEF210",
1232         "UNDEF","UNDEF","UNDEF","UNDEF","UNDEF",
1233         "UNDEF216","UNDEF217","UNDEF218","UNDEF219","UNDEF220",
1234         "UNDEF","UNDEF","UNDEF","UNDEF","UNDEF",
1235         "UNDEF226","UNDEF227","UNDEF228","UNDEF229","UNDEF230",
1236         "UNDEF","UNDEF","UNDEF","UNDEF","UNDEF",
1237         "UNDEF236","UNDEF237","UNDEF238","UNDEF239","UNDEF240",
1238         "UNDEF","UNDEF","UNDEF","UNDEF","UNDEF",
1239         "UNDEF246","UNDEF247","UNDEF248","UNDEF249","UNDEF250",
1240         "UNDEF251","UNDEF252",
1241
1242         "BUILTIN3     ", /*             253 */
1243         "BUILTIN2     ", /*             254 */
1244         "BUILTIN1     "  /*             255 */
1245 };
1246
1247
1248 #if defined(USEBUILTINTABLE)
1249
1250 #if 0
1251 stdopdescriptor builtintable[] = {
1252         { ICMD_LCMP,   TYPE_LONG, TYPE_LONG, TYPE_INT, ICMD_BUILTIN2,
1253           (functionptr) builtin_lcmp , SUPPORT_LONG && SUPPORT_LONG_CMP, false },
1254         { ICMD_LAND,   TYPE_LONG, TYPE_LONG, TYPE_LONG, ICMD_BUILTIN2,
1255           (functionptr) builtin_land , SUPPORT_LONG && SUPPORT_LONG_LOG, false },
1256         { ICMD_LOR,    TYPE_LONG, TYPE_LONG, TYPE_LONG, ICMD_BUILTIN2,
1257           (functionptr) builtin_lor , SUPPORT_LONG && SUPPORT_LONG_LOG, false },
1258         { ICMD_LXOR,   TYPE_LONG, TYPE_LONG, TYPE_LONG, ICMD_BUILTIN2,
1259           (functionptr) builtin_lxor , SUPPORT_LONG && SUPPORT_LONG_LOG, false },
1260         { ICMD_LSHL,   TYPE_LONG, TYPE_INT,  TYPE_LONG, ICMD_BUILTIN2,
1261           (functionptr) builtin_lshl , SUPPORT_LONG && SUPPORT_LONG_SHIFT, false },
1262         { ICMD_LSHR,   TYPE_LONG, TYPE_INT,  TYPE_LONG, ICMD_BUILTIN2,
1263           (functionptr) builtin_lshr, SUPPORT_LONG && SUPPORT_LONG_SHIFT, false },
1264         { ICMD_LUSHR,  TYPE_LONG, TYPE_INT,  TYPE_LONG, ICMD_BUILTIN2,
1265           (functionptr) builtin_lushr, SUPPORT_LONG && SUPPORT_LONG_SHIFT, false },
1266         { ICMD_LADD,   TYPE_LONG, TYPE_LONG, TYPE_LONG, ICMD_BUILTIN2,
1267           (functionptr) builtin_ladd , SUPPORT_LONG && SUPPORT_LONG_ADD, false },
1268         { ICMD_LSUB,   TYPE_LONG, TYPE_LONG, TYPE_LONG, ICMD_BUILTIN2,
1269           (functionptr) builtin_lsub , SUPPORT_LONG && SUPPORT_LONG_ADD, false },
1270         { ICMD_LNEG,   TYPE_LONG, TYPE_VOID, TYPE_LONG, ICMD_BUILTIN1, 
1271           (functionptr) builtin_lneg, SUPPORT_LONG && SUPPORT_LONG_ADD, true },
1272         { ICMD_LMUL,   TYPE_LONG, TYPE_LONG, TYPE_LONG, ICMD_BUILTIN2,
1273           (functionptr) builtin_lmul , SUPPORT_LONG && SUPPORT_LONG_MUL, false },
1274         { ICMD_I2F,    TYPE_INT, TYPE_VOID, TYPE_FLOAT, ICMD_BUILTIN1,
1275           (functionptr) builtin_i2f, SUPPORT_FLOAT && SUPPORT_IFCVT, true },
1276         { ICMD_I2D,    TYPE_INT, TYPE_VOID, TYPE_DOUBLE, ICMD_BUILTIN1, 
1277           (functionptr) builtin_i2d, SUPPORT_DOUBLE && SUPPORT_IFCVT, true },
1278         { ICMD_L2F,    TYPE_LONG, TYPE_VOID, TYPE_FLOAT, ICMD_BUILTIN1,
1279           (functionptr) builtin_l2f, SUPPORT_LONG && SUPPORT_FLOAT && SUPPORT_LONG_FCVT, true },
1280         { ICMD_L2D,    TYPE_LONG, TYPE_VOID, TYPE_DOUBLE, ICMD_BUILTIN1, 
1281           (functionptr) builtin_l2d, SUPPORT_LONG && SUPPORT_DOUBLE && SUPPORT_LONG_FCVT, true },
1282         { ICMD_F2L,    TYPE_FLOAT, TYPE_VOID, TYPE_LONG, ICMD_BUILTIN1,
1283           (functionptr) builtin_f2l, SUPPORT_FLOAT && SUPPORT_LONG && SUPPORT_LONG_ICVT, true },
1284         { ICMD_D2L,    TYPE_DOUBLE, TYPE_VOID, TYPE_LONG, ICMD_BUILTIN1,
1285           (functionptr) builtin_d2l, SUPPORT_DOUBLE && SUPPORT_LONG && SUPPORT_LONG_ICVT, true },
1286         { ICMD_F2I,    TYPE_FLOAT, TYPE_VOID, TYPE_INT, ICMD_BUILTIN1,
1287           (functionptr) builtin_f2i, SUPPORT_FLOAT && SUPPORT_FICVT, true },
1288         { ICMD_D2I,    TYPE_DOUBLE, TYPE_VOID, TYPE_INT, ICMD_BUILTIN1,
1289           (functionptr) builtin_d2i, SUPPORT_DOUBLE && SUPPORT_FICVT, true },
1290         { 255, 0, 0, 0, 0, NULL, true, false },
1291 };
1292
1293 #endif
1294
1295 static int builtintablelen;
1296
1297 #endif /* USEBUILTINTABLE */
1298
1299
1300 /*****************************************************************************
1301                                                  TABLE OF BUILTIN FUNCTIONS
1302
1303     This table lists the builtin functions which are used inside
1304     BUILTIN* opcodes.
1305
1306     The first part of the table (up to the 255-marker) lists the
1307     opcodes which are automatically replaced in stack.c.
1308
1309     The second part lists the builtin functions which are "manually"
1310     used for BUILTIN* opcodes in parse.c and stack.c.
1311
1312 *****************************************************************************/
1313
1314 builtin_descriptor builtin_desc[] = {
1315 #if defined(USEBUILTINTABLE)
1316         {ICMD_LCMP , BUILTIN_lcmp ,ICMD_BUILTIN2,TYPE_LONG  ,TYPE_LONG  ,TYPE_VOID ,TYPE_INT   ,
1317                      SUPPORT_LONG && SUPPORT_LONG_CMP,false,"lcmp"},
1318         
1319         {ICMD_LAND , BUILTIN_land ,ICMD_BUILTIN2,TYPE_LONG  ,TYPE_LONG  ,TYPE_VOID ,TYPE_LONG  ,
1320                      SUPPORT_LONG && SUPPORT_LONG_LOG,false,"land"},
1321         {ICMD_LOR  , BUILTIN_lor  ,ICMD_BUILTIN2,TYPE_LONG  ,TYPE_LONG  ,TYPE_VOID ,TYPE_LONG  ,
1322                      SUPPORT_LONG && SUPPORT_LONG_LOG,false,"lor"},
1323         {ICMD_LXOR , BUILTIN_lxor ,ICMD_BUILTIN2,TYPE_LONG  ,TYPE_LONG  ,TYPE_VOID ,TYPE_LONG  ,
1324                      SUPPORT_LONG && SUPPORT_LONG_LOG,false,"lxor"},
1325         
1326         {ICMD_LSHL , BUILTIN_lshl ,ICMD_BUILTIN2,TYPE_LONG  ,TYPE_INT   ,TYPE_VOID ,TYPE_LONG  ,
1327                      SUPPORT_LONG && SUPPORT_LONG_SHIFT,false,"lshl"},
1328         {ICMD_LSHR , BUILTIN_lshr ,ICMD_BUILTIN2,TYPE_LONG  ,TYPE_INT   ,TYPE_VOID ,TYPE_LONG  ,
1329                      SUPPORT_LONG && SUPPORT_LONG_SHIFT,false,"lshr"},
1330         {ICMD_LUSHR, BUILTIN_lushr,ICMD_BUILTIN2,TYPE_LONG  ,TYPE_INT   ,TYPE_VOID ,TYPE_LONG  ,
1331                      SUPPORT_LONG && SUPPORT_LONG_SHIFT,false,"lushr"},
1332         
1333         {ICMD_LADD , BUILTIN_ladd ,ICMD_BUILTIN2,TYPE_LONG  ,TYPE_LONG  ,TYPE_VOID ,TYPE_LONG  ,
1334                      SUPPORT_LONG && SUPPORT_LONG_ADD,false,"ladd"},
1335         {ICMD_LSUB , BUILTIN_lsub ,ICMD_BUILTIN2,TYPE_LONG  ,TYPE_LONG  ,TYPE_VOID ,TYPE_LONG  ,
1336                      SUPPORT_LONG && SUPPORT_LONG_ADD,false,"lsub"},
1337         {ICMD_LNEG , BUILTIN_lneg ,ICMD_BUILTIN1,TYPE_LONG  ,TYPE_VOID  ,TYPE_VOID ,TYPE_LONG  ,
1338                      SUPPORT_LONG && SUPPORT_LONG_ADD,false,"lneg"},
1339         {ICMD_LMUL , BUILTIN_lmul ,ICMD_BUILTIN2,TYPE_LONG  ,TYPE_LONG  ,TYPE_VOID ,TYPE_LONG  ,
1340                      SUPPORT_LONG && SUPPORT_LONG_MUL,false,"lmul"},
1341         
1342         {ICMD_I2F  , BUILTIN_i2f  ,ICMD_BUILTIN1,TYPE_INT   ,TYPE_VOID  ,TYPE_VOID ,TYPE_FLOAT ,
1343                      SUPPORT_FLOAT && SUPPORT_IFCVT,true ,"i2f"},
1344         {ICMD_I2D  , BUILTIN_i2d  ,ICMD_BUILTIN1,TYPE_INT   ,TYPE_VOID  ,TYPE_VOID ,TYPE_DOUBLE,
1345                      SUPPORT_DOUBLE && SUPPORT_IFCVT,true ,"i2d"},
1346         {ICMD_L2F  , BUILTIN_l2f  ,ICMD_BUILTIN1,TYPE_LONG  ,TYPE_VOID  ,TYPE_VOID ,TYPE_FLOAT ,
1347                      SUPPORT_LONG && SUPPORT_FLOAT && SUPPORT_LONG_FCVT,true ,"l2f"},
1348         {ICMD_L2D  , BUILTIN_l2d  ,ICMD_BUILTIN1,TYPE_LONG  ,TYPE_VOID  ,TYPE_VOID ,TYPE_DOUBLE,
1349                      SUPPORT_LONG && SUPPORT_DOUBLE && SUPPORT_LONG_FCVT,true ,"l2d"},
1350         {ICMD_F2L  , BUILTIN_f2l  ,ICMD_BUILTIN1,TYPE_FLOAT ,TYPE_VOID  ,TYPE_VOID ,TYPE_LONG  ,
1351                      SUPPORT_FLOAT && SUPPORT_LONG && SUPPORT_LONG_ICVT,true ,"f2l"},
1352         {ICMD_D2L  , BUILTIN_d2l  ,ICMD_BUILTIN1,TYPE_DOUBLE,TYPE_VOID  ,TYPE_VOID ,TYPE_LONG  ,
1353                      SUPPORT_DOUBLE && SUPPORT_LONG && SUPPORT_LONG_ICVT,true ,"d2l"},
1354         {ICMD_F2I  , BUILTIN_f2i  ,ICMD_BUILTIN1,TYPE_FLOAT ,TYPE_VOID  ,TYPE_VOID ,TYPE_INT   ,
1355                      SUPPORT_FLOAT && SUPPORT_FICVT,true ,"f2i"},
1356         {ICMD_D2I  , BUILTIN_d2i  ,ICMD_BUILTIN1,TYPE_DOUBLE,TYPE_VOID  ,TYPE_VOID ,TYPE_INT   ,
1357                      SUPPORT_DOUBLE && SUPPORT_FICVT,true ,"d2i"},
1358 #endif
1359
1360         /* this record marks the end of the automatically replaced opcodes */
1361         {255,NULL,0,0,0,0,0,0,0,"<INVALID>"},
1362
1363         /* the following functions are not replaced automatically */
1364         
1365 #if defined(__ALPHA__)
1366         {255, BUILTIN_f2l  ,ICMD_BUILTIN1,TYPE_FLOAT ,TYPE_VOID  ,TYPE_VOID ,TYPE_LONG  ,0,0,"f2l"},
1367         {255, BUILTIN_d2l  ,ICMD_BUILTIN1,TYPE_DOUBLE,TYPE_VOID  ,TYPE_VOID ,TYPE_LONG  ,0,0,"d2l"},
1368         {255, BUILTIN_f2i  ,ICMD_BUILTIN1,TYPE_FLOAT ,TYPE_VOID  ,TYPE_VOID ,TYPE_INT   ,0,0,"f2i"},
1369         {255, BUILTIN_d2i  ,ICMD_BUILTIN1,TYPE_DOUBLE,TYPE_VOID  ,TYPE_VOID ,TYPE_INT   ,0,0,"d2i"},
1370 #endif
1371
1372         {255,BUILTIN_instanceof      ,ICMD_BUILTIN2,TYPE_ADR   ,TYPE_ADR   ,TYPE_VOID  ,TYPE_INT   ,0,0,"instanceof"},
1373         {255,BUILTIN_arrayinstanceof ,ICMD_BUILTIN2,TYPE_ADR   ,TYPE_ADR   ,TYPE_VOID  ,TYPE_INT   ,0,0,"arrayinstanceof"},
1374         {255,BUILTIN_checkarraycast  ,ICMD_BUILTIN2,TYPE_ADR   ,TYPE_ADR   ,TYPE_VOID  ,TYPE_VOID  ,0,0,"checkarraycast"},
1375         {255,BUILTIN_aastore         ,ICMD_BUILTIN3,TYPE_ADR   ,TYPE_INT   ,TYPE_ADR   ,TYPE_VOID  ,0,0,"aastore"},
1376         {255,BUILTIN_new             ,ICMD_BUILTIN1,TYPE_ADR   ,TYPE_VOID  ,TYPE_VOID  ,TYPE_ADR   ,0,0,"new"},
1377         {255,BUILTIN_newarray        ,ICMD_BUILTIN2,TYPE_INT   ,TYPE_ADR   ,TYPE_VOID  ,TYPE_ADR   ,0,0,"newarray"},
1378         {255,BUILTIN_newarray_boolean,ICMD_BUILTIN1,TYPE_INT   ,TYPE_VOID  ,TYPE_VOID  ,TYPE_ADR   ,0,0,"newarray_boolean"},
1379         {255,BUILTIN_newarray_char   ,ICMD_BUILTIN1,TYPE_INT   ,TYPE_VOID  ,TYPE_VOID  ,TYPE_ADR   ,0,0,"newarray_char"},
1380         {255,BUILTIN_newarray_float  ,ICMD_BUILTIN1,TYPE_INT   ,TYPE_VOID  ,TYPE_VOID  ,TYPE_ADR   ,0,0,"newarray_float"},
1381         {255,BUILTIN_newarray_double ,ICMD_BUILTIN1,TYPE_INT   ,TYPE_VOID  ,TYPE_VOID  ,TYPE_ADR   ,0,0,"newarray_double"},
1382         {255,BUILTIN_newarray_byte   ,ICMD_BUILTIN1,TYPE_INT   ,TYPE_VOID  ,TYPE_VOID  ,TYPE_ADR   ,0,0,"newarray_byte"},
1383         {255,BUILTIN_newarray_short  ,ICMD_BUILTIN1,TYPE_INT   ,TYPE_VOID  ,TYPE_VOID  ,TYPE_ADR   ,0,0,"newarray_short"},
1384         {255,BUILTIN_newarray_int    ,ICMD_BUILTIN1,TYPE_INT   ,TYPE_VOID  ,TYPE_VOID  ,TYPE_ADR   ,0,0,"newarray_int"},
1385         {255,BUILTIN_newarray_long   ,ICMD_BUILTIN1,TYPE_INT   ,TYPE_VOID  ,TYPE_VOID  ,TYPE_ADR   ,0,0,"newarray_long"},
1386         {255,BUILTIN_monitorenter    ,ICMD_BUILTIN1,TYPE_ADR   ,TYPE_VOID  ,TYPE_VOID  ,TYPE_VOID  ,0,0,"monitorenter"},
1387         {255,BUILTIN_monitorexit     ,ICMD_BUILTIN1,TYPE_ADR   ,TYPE_VOID  ,TYPE_VOID  ,TYPE_VOID  ,0,0,"monitorexit"},
1388 #if !SUPPORT_DIVISION
1389         {255,BUILTIN_idiv            ,ICMD_BUILTIN2,TYPE_INT   ,TYPE_INT   ,TYPE_VOID  ,TYPE_INT   ,0,0,"idiv"},
1390         {255,BUILTIN_irem            ,ICMD_BUILTIN2,TYPE_INT   ,TYPE_INT   ,TYPE_VOID  ,TYPE_INT   ,0,0,"irem"},
1391 #endif
1392 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1393         {255,BUILTIN_ldiv            ,ICMD_BUILTIN2,TYPE_LONG  ,TYPE_LONG  ,TYPE_VOID  ,TYPE_LONG  ,0,0,"ldiv"},
1394         {255,BUILTIN_lrem            ,ICMD_BUILTIN2,TYPE_LONG  ,TYPE_LONG  ,TYPE_VOID  ,TYPE_LONG  ,0,0,"lrem"},
1395 #endif
1396         {255,BUILTIN_frem            ,ICMD_BUILTIN2,TYPE_FLOAT ,TYPE_FLOAT ,TYPE_VOID  ,TYPE_FLOAT ,0,0,"frem"},
1397         {255,BUILTIN_drem            ,ICMD_BUILTIN2,TYPE_DOUBLE,TYPE_DOUBLE,TYPE_VOID  ,TYPE_DOUBLE,0,0,"drem"},
1398
1399         /* this record marks the end of the list */
1400         {  0,NULL,0,0,0,0,0,0,0,"<END>"}
1401 };
1402
1403 /* include compiler subsystems ************************************************/
1404
1405 /* from codegen.inc */
1406 extern int dseglen;
1407
1408
1409 /* dummy function, used when there is no JavaVM code available                */
1410
1411 static void* do_nothing_function()
1412 {
1413         return NULL;
1414 }
1415
1416
1417 /* jit_compile *****************************************************************
1418
1419         jit_compile, new version of compiler, translates one method to machine code
1420
1421 *******************************************************************************/
1422
1423 #if 0
1424 #define LOG_STEP(step)                                                                                  \
1425         if (compileverbose) {                                                                           \
1426                 char logtext[MAXLOGTEXT];                                                               \
1427                 sprintf(logtext, "%s: ",step);                                                  \
1428                 utf_sprint(logtext+strlen(logtext), m->class->name);    \
1429                 strcpy(logtext+strlen(logtext), ".");                                   \
1430                 utf_sprint(logtext+strlen(logtext), m->name);                   \
1431                 utf_sprint(logtext+strlen(logtext), m->descriptor);             \
1432                 log_text(logtext);                                                                              \
1433         }
1434 #else
1435 #define LOG_STEP(step)
1436 #endif
1437
1438 methodptr jit_compile(methodinfo *m)
1439 {
1440         s4 dumpsize;
1441         s8 starttime = 0;
1442         s8 stoptime  = 0;
1443
1444         count_jit_calls++;
1445
1446         /* if method has been already compiled return immediately */
1447
1448         if (m->entrypoint)
1449                 return m->entrypoint;
1450
1451         count_methods++;
1452
1453 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1454         pthread_mutex_lock(&compiler_mutex);
1455 #endif
1456
1457 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
1458         intsDisable();      /* disable interrupts */
1459 #endif
1460
1461         regs_ok = false;
1462
1463         /* mark start of dump memory area */
1464
1465         dumpsize = dump_size();
1466
1467         /* measure time */
1468
1469         if (getcompilingtime)
1470                 starttime = getcputime();
1471
1472         /* if there is no javacode print error message and return empty method    */
1473
1474         if (!m->jcode) {
1475                 char logtext[MAXLOGTEXT];
1476                 sprintf(logtext, "No code given for: ");
1477                 utf_sprint(logtext+strlen(logtext), m->class->name);
1478                 strcpy(logtext+strlen(logtext), ".");
1479                 utf_sprint(logtext+strlen(logtext), m->name);
1480                 utf_sprint(logtext+strlen(logtext), m->descriptor);
1481                 log_text(logtext);
1482 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
1483                 intsRestore();                             /* enable interrupts again */
1484 #endif
1485                 return (methodptr) do_nothing_function;    /* return empty method     */
1486         }
1487
1488         /* print log message for compiled method */
1489
1490         if (compileverbose) {
1491                 char logtext[MAXLOGTEXT];
1492                 sprintf(logtext, "Compiling: ");
1493                 utf_sprint(logtext+strlen(logtext), m->class->name);
1494                 strcpy(logtext+strlen(logtext), ".");
1495                 utf_sprint(logtext+strlen(logtext), m->name);
1496                 utf_sprint(logtext+strlen(logtext), m->descriptor);
1497                 log_text(logtext);
1498         }
1499
1500         /* initialize the static function's class */
1501         if (m->flags & ACC_STATIC && !m->class->initialized) {
1502                 if (initverbose) {
1503                         char logtext[MAXLOGTEXT];
1504                         sprintf(logtext, "Initialize class ");
1505                         utf_sprint(logtext + strlen(logtext), m->class->name);
1506                         log_text(logtext);
1507                 }
1508                 class_init(m->class);
1509         }
1510
1511         /* initialisation of variables and subsystems */
1512
1513         isleafmethod = true;
1514
1515         method = m;
1516         class = m->class;
1517         descriptor = m->descriptor;
1518         maxstack = m->maxstack;
1519         maxlocals = m->maxlocals;
1520         jcodelength = m->jcodelength;
1521         jcode = m->jcode;
1522         exceptiontablelength = m->exceptiontablelength;
1523         raw_extable = m->exceptiontable;
1524
1525 #ifdef STATISTICS
1526         count_tryblocks += exceptiontablelength;
1527         count_javacodesize += jcodelength + 18;
1528         count_javaexcsize += exceptiontablelength * POINTERSIZE;
1529 #endif
1530
1531         /* initialise parameter type descriptor */
1532
1533         descriptor2types(m);
1534         mreturntype = m->returntype;
1535         mparamcount = m->paramcount;
1536         mparamtypes = m->paramtypes;
1537
1538 #if defined(__I386__)
1539         method_uses_ecx = true;
1540         method_uses_edx = false;
1541 #endif
1542
1543         /* call the compiler passes ***********************************************/
1544
1545         /* must be called before reg_init, because it can change maxlocals */
1546         if (useinlining)
1547                 inlining_init(m);
1548
1549         reg_setup();
1550
1551         codegen_init();
1552
1553         parse();
1554         analyse_stack();
1555    
1556 #ifdef CACAO_TYPECHECK
1557         if (opt_verify) {
1558                 LOG_STEP("Typechecking");
1559                 typecheck();
1560                 LOG_STEP("Done typechecking");
1561         }
1562 #endif
1563         
1564         if (opt_loops) {
1565                 depthFirst();
1566                 analyseGraph();
1567                 optimize_loops();
1568         }
1569    
1570 #ifdef SPECIALMEMUSE
1571         preregpass();
1572 #endif
1573
1574         LOG_STEP("Regalloc");
1575         regalloc();
1576         regs_ok = true;
1577
1578         LOG_STEP("Codegen");
1579         codegen();
1580
1581         /* intermediate and assembly code listings ********************************/
1582                 
1583         if (showintermediate)
1584                 show_icmd_method();
1585         else if (showdisassemble)
1586                 disassemble((void*) (m->mcode + dseglen), m->mcodelength - dseglen);
1587
1588         if (showddatasegment)
1589                 dseg_display((void*) (m->mcode));
1590
1591         /* release dump area */
1592
1593         dump_release(dumpsize);
1594
1595         /* measure time */
1596
1597         if (getcompilingtime) {
1598                 stoptime = getcputime();
1599                 compilingtime += (stoptime - starttime);
1600         }
1601
1602 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
1603         intsRestore();    /* enable interrupts again */
1604 #endif
1605
1606 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1607         pthread_mutex_unlock(&compiler_mutex);
1608 #endif
1609
1610         /* return pointer to the methods entry point */
1611         
1612         LOG_STEP("Done compiling");
1613         return m->entrypoint;
1614
1615
1616
1617
1618 /* functions for compiler initialisation and finalisation *********************/
1619
1620 #ifdef USEBUILTINTABLE
1621
1622 static int stdopcompare(const void *a, const void *b)
1623 {
1624         builtin_descriptor *o1 = (builtin_descriptor *) a;
1625         builtin_descriptor *o2 = (builtin_descriptor *) b;
1626         if (!o1->supported && o2->supported)
1627                 return -1;
1628         if (o1->supported && !o2->supported)
1629                 return 1;
1630         return (o1->opcode < o2->opcode) ? -1 : (o1->opcode > o2->opcode);
1631 }
1632
1633 static inline void sort_builtintable()
1634 {
1635         int len;
1636
1637         len = 0;
1638         while (builtin_desc[len].opcode != 255) len++;
1639         qsort(builtin_desc, len, sizeof(builtin_descriptor), stdopcompare);
1640
1641         for (--len; len>=0 && builtin_desc[len].supported; len--);
1642         builtintablelen = ++len;
1643 }
1644
1645
1646 builtin_descriptor *find_builtin(int icmd)
1647 {
1648         builtin_descriptor *first = builtin_desc;
1649         builtin_descriptor *last = builtin_desc + builtintablelen;
1650         int len = last - first;
1651         int half;
1652         builtin_descriptor *middle;
1653
1654         while (len > 0) {
1655                 half = len / 2;
1656                 middle = first + half;
1657                 if (middle->opcode < icmd) {
1658                         first = middle + 1;
1659                         len -= half + 1;
1660                 } else
1661                         len = half;
1662         }
1663         return first != last ? first : NULL;
1664 }
1665
1666 #endif
1667
1668
1669
1670 void jit_init()
1671 {
1672         int i;
1673
1674 #ifdef USEBUILTINTABLE
1675         sort_builtintable();
1676 #endif
1677
1678 #if defined(__ALPHA__)
1679         has_ext_instr_set = ! has_no_x_instr_set();
1680 #endif
1681
1682         for (i = 0; i < 256; i++)
1683                 stackreq[i] = 1;
1684
1685         stackreq[JAVA_NOP]          = 0;
1686         stackreq[JAVA_ISTORE]       = 0;
1687         stackreq[JAVA_LSTORE]       = 0;
1688         stackreq[JAVA_FSTORE]       = 0;
1689         stackreq[JAVA_DSTORE]       = 0;
1690         stackreq[JAVA_ASTORE]       = 0;
1691         stackreq[JAVA_ISTORE_0]     = 0;
1692         stackreq[JAVA_ISTORE_1]     = 0;
1693         stackreq[JAVA_ISTORE_2]     = 0;
1694         stackreq[JAVA_ISTORE_3]     = 0;
1695         stackreq[JAVA_LSTORE_0]     = 0;
1696         stackreq[JAVA_LSTORE_1]     = 0;
1697         stackreq[JAVA_LSTORE_2]     = 0;
1698         stackreq[JAVA_LSTORE_3]     = 0;
1699         stackreq[JAVA_FSTORE_0]     = 0;
1700         stackreq[JAVA_FSTORE_1]     = 0;
1701         stackreq[JAVA_FSTORE_2]     = 0;
1702         stackreq[JAVA_FSTORE_3]     = 0;
1703         stackreq[JAVA_DSTORE_0]     = 0;
1704         stackreq[JAVA_DSTORE_1]     = 0;
1705         stackreq[JAVA_DSTORE_2]     = 0;
1706         stackreq[JAVA_DSTORE_3]     = 0;
1707         stackreq[JAVA_ASTORE_0]     = 0;
1708         stackreq[JAVA_ASTORE_1]     = 0;
1709         stackreq[JAVA_ASTORE_2]     = 0;
1710         stackreq[JAVA_ASTORE_3]     = 0;
1711         stackreq[JAVA_IASTORE]      = 0;
1712         stackreq[JAVA_LASTORE]      = 0;
1713         stackreq[JAVA_FASTORE]      = 0;
1714         stackreq[JAVA_DASTORE]      = 0;
1715         stackreq[JAVA_AASTORE]      = 0;
1716         stackreq[JAVA_BASTORE]      = 0;
1717         stackreq[JAVA_CASTORE]      = 0;
1718         stackreq[JAVA_SASTORE]      = 0;
1719         stackreq[JAVA_POP]          = 0;
1720         stackreq[JAVA_POP2]         = 0;
1721         stackreq[JAVA_IINC]         = 0;
1722         stackreq[JAVA_IFEQ]         = 0;
1723         stackreq[JAVA_IFNE]         = 0;
1724         stackreq[JAVA_IFLT]         = 0;
1725         stackreq[JAVA_IFGE]         = 0;
1726         stackreq[JAVA_IFGT]         = 0;
1727         stackreq[JAVA_IFLE]         = 0;
1728         stackreq[JAVA_IF_ICMPEQ]    = 0;
1729         stackreq[JAVA_IF_ICMPNE]    = 0;
1730         stackreq[JAVA_IF_ICMPLT]    = 0;
1731         stackreq[JAVA_IF_ICMPGE]    = 0;
1732         stackreq[JAVA_IF_ICMPGT]    = 0;
1733         stackreq[JAVA_IF_ICMPLE]    = 0;
1734         stackreq[JAVA_IF_ACMPEQ]    = 0;
1735         stackreq[JAVA_IF_ACMPNE]    = 0;
1736         stackreq[JAVA_GOTO]         = 0;
1737         stackreq[JAVA_RET]          = 0;
1738         stackreq[JAVA_TABLESWITCH]  = 0;
1739         stackreq[JAVA_LOOKUPSWITCH] = 0;
1740         stackreq[JAVA_IRETURN]      = 0;
1741         stackreq[JAVA_LRETURN]      = 0;
1742         stackreq[JAVA_FRETURN]      = 0;
1743         stackreq[JAVA_DRETURN]      = 0;
1744         stackreq[JAVA_ARETURN]      = 0;
1745         stackreq[JAVA_RETURN]       = 0;
1746         stackreq[JAVA_PUTSTATIC]    = 0;
1747         stackreq[JAVA_PUTFIELD]     = 0;
1748         stackreq[JAVA_MONITORENTER] = 0;
1749         stackreq[JAVA_MONITOREXIT]  = 0;
1750         stackreq[JAVA_WIDE]         = 0;
1751         stackreq[JAVA_IFNULL]       = 0;
1752         stackreq[JAVA_IFNONNULL]    = 0;
1753         stackreq[JAVA_GOTO_W]       = 0;
1754         stackreq[JAVA_BREAKPOINT]   = 0;
1755
1756         stackreq[JAVA_SWAP] = 2;
1757         stackreq[JAVA_DUP2] = 2;
1758         stackreq[JAVA_DUP_X1] = 3;
1759         stackreq[JAVA_DUP_X2] = 4;
1760         stackreq[JAVA_DUP2_X1] = 3;
1761         stackreq[JAVA_DUP2_X2] = 4;
1762
1763         reg_init();
1764         init_exceptions();
1765 }
1766
1767
1768
1769 void jit_close()
1770 {
1771         codegen_close();
1772         reg_close();
1773 }
1774
1775
1776 /*
1777  * These are local overrides for various environment variables in Emacs.
1778  * Please do not remove this and leave it at the end of the file, where
1779  * Emacs will automagically detect them.
1780  * ---------------------------------------------------------------------
1781  * Local variables:
1782  * mode: c
1783  * indent-tabs-mode: t
1784  * c-basic-offset: 4
1785  * tab-width: 4
1786  * End:
1787  */