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