1 /* src/vm/jit/jit.c - calls the code generation functions
3 Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 Contact: cacao@cacaojvm.org
27 Authors: Andreas Krall
30 Changes: Edwin Steiner
34 $Id: jit.c 5099 2006-07-10 14:20:38Z twisti $
44 #include "mm/memory.h"
45 #include "native/native.h"
46 #include "toolbox/logging.h"
47 #include "vm/builtin.h"
49 #include "vm/global.h"
50 #include "vm/initialize.h"
51 #include "vm/loader.h"
52 #include "vm/method.h"
53 #include "vm/options.h"
54 #include "vm/statistics.h"
55 #include "vm/jit/asmpart.h"
56 #include "vm/jit/codegen-common.h"
57 #include "vm/jit/disass.h"
58 #include "vm/jit/dseg.h"
59 #include "vm/jit/jit.h"
60 #include "vm/jit/show.h"
63 #include "vm/jit/parse.h"
64 #include "vm/jit/reg.h"
65 #include "vm/jit/stack.h"
67 #include "vm/jit/allocator/simplereg.h"
68 #if defined(ENABLE_LSRA)
69 # include "vm/jit/allocator/lsra.h"
72 #if defined(ENABLE_IFCONV)
73 # include "vm/jit/ifconv/ifconv.h"
76 #include "vm/jit/loop/analyze.h"
77 #include "vm/jit/loop/graph.h"
78 #include "vm/jit/loop/loop.h"
79 #include "vm/jit/verify/typecheck.h"
80 #include "vm/rt-timing.h"
82 #if defined(ENABLE_THREADS)
83 # include "threads/native/threads.h"
87 /* debug macros ***************************************************************/
90 #define DEBUG_JIT_COMPILEVERBOSE(x) \
92 if (compileverbose) { \
93 log_message_method(x, m); \
97 #define DEBUG_JIT_COMPILEVERBOSE(x) /* nothing */
101 /* global switches ************************************************************/
106 int jcommandsize[256] = {
109 1, /* JAVA_ACONST_NULL 1 */
110 1, /* JAVA_ICONST_M1 2 */
111 1, /* JAVA_ICONST_0 3 */
112 1, /* JAVA_ICONST_1 4 */
113 1, /* JAVA_ICONST_2 5 */
114 1, /* JAVA_ICONST_3 6 */
115 1, /* JAVA_ICONST_4 7 */
116 1, /* JAVA_ICONST_5 8 */
117 1, /* JAVA_LCONST_0 9 */
118 1, /* JAVA_LCONST_1 10 */
119 1, /* JAVA_FCONST_0 11 */
120 1, /* JAVA_FCONST_1 12 */
121 1, /* JAVA_FCONST_2 13 */
122 1, /* JAVA_DCONST_0 14 */
123 1, /* JAVA_DCONST_1 15 */
124 2, /* JAVA_BIPUSH 16 */
125 3, /* JAVA_SIPUSH 17 */
126 2, /* JAVA_LDC1 18 */
127 3, /* JAVA_LDC2 19 */
128 3, /* JAVA_LDC2W 20 */
129 2, /* JAVA_ILOAD 21 */
130 2, /* JAVA_LLOAD 22 */
131 2, /* JAVA_FLOAD 23 */
132 2, /* JAVA_DLOAD 24 */
133 2, /* JAVA_ALOAD 25 */
134 1, /* JAVA_ILOAD_0 26 */
135 1, /* JAVA_ILOAD_1 27 */
136 1, /* JAVA_ILOAD_2 28 */
137 1, /* JAVA_ILOAD_3 29 */
138 1, /* JAVA_LLOAD_0 30 */
139 1, /* JAVA_LLOAD_1 31 */
140 1, /* JAVA_LLOAD_2 32 */
141 1, /* JAVA_LLOAD_3 33 */
142 1, /* JAVA_FLOAD_0 34 */
143 1, /* JAVA_FLOAD_1 35 */
144 1, /* JAVA_FLOAD_2 36 */
145 1, /* JAVA_FLOAD_3 37 */
146 1, /* JAVA_DLOAD_0 38 */
147 1, /* JAVA_DLOAD_1 39 */
148 1, /* JAVA_DLOAD_2 40 */
149 1, /* JAVA_DLOAD_3 41 */
150 1, /* JAVA_ALOAD_0 42 */
151 1, /* JAVA_ALOAD_1 43 */
152 1, /* JAVA_ALOAD_2 44 */
153 1, /* JAVA_ALOAD_3 45 */
154 1, /* JAVA_IALOAD 46 */
155 1, /* JAVA_LALOAD 47 */
156 1, /* JAVA_FALOAD 48 */
157 1, /* JAVA_DALOAD 49 */
158 1, /* JAVA_AALOAD 50 */
159 1, /* JAVA_BALOAD 51 */
160 1, /* JAVA_CALOAD 52 */
161 1, /* JAVA_SALOAD 53 */
162 2, /* JAVA_ISTORE 54 */
163 2, /* JAVA_LSTORE 55 */
164 2, /* JAVA_FSTORE 56 */
165 2, /* JAVA_DSTORE 57 */
166 2, /* JAVA_ASTORE 58 */
167 1, /* JAVA_ISTORE_0 59 */
168 1, /* JAVA_ISTORE_1 60 */
169 1, /* JAVA_ISTORE_2 61 */
170 1, /* JAVA_ISTORE_3 62 */
171 1, /* JAVA_LSTORE_0 63 */
172 1, /* JAVA_LSTORE_1 64 */
173 1, /* JAVA_LSTORE_2 65 */
174 1, /* JAVA_LSTORE_3 66 */
175 1, /* JAVA_FSTORE_0 67 */
176 1, /* JAVA_FSTORE_1 68 */
177 1, /* JAVA_FSTORE_2 69 */
178 1, /* JAVA_FSTORE_3 70 */
179 1, /* JAVA_DSTORE_0 71 */
180 1, /* JAVA_DSTORE_1 72 */
181 1, /* JAVA_DSTORE_2 73 */
182 1, /* JAVA_DSTORE_3 74 */
183 1, /* JAVA_ASTORE_0 75 */
184 1, /* JAVA_ASTORE_1 76 */
185 1, /* JAVA_ASTORE_2 77 */
186 1, /* JAVA_ASTORE_3 78 */
187 1, /* JAVA_IASTORE 79 */
188 1, /* JAVA_LASTORE 80 */
189 1, /* JAVA_FASTORE 81 */
190 1, /* JAVA_DASTORE 82 */
191 1, /* JAVA_AASTORE 83 */
192 1, /* JAVA_BASTORE 84 */
193 1, /* JAVA_CASTORE 85 */
194 1, /* JAVA_SASTORE 86 */
196 1, /* JAVA_POP2 88 */
198 1, /* JAVA_DUP_X1 90 */
199 1, /* JAVA_DUP_X2 91 */
200 1, /* JAVA_DUP2 92 */
201 1, /* JAVA_DUP2_X1 93 */
202 1, /* JAVA_DUP2_X2 94 */
203 1, /* JAVA_SWAP 95 */
204 1, /* JAVA_IADD 96 */
205 1, /* JAVA_LADD 97 */
206 1, /* JAVA_FADD 98 */
207 1, /* JAVA_DADD 99 */
208 1, /* JAVA_ISUB 100 */
209 1, /* JAVA_LSUB 101 */
210 1, /* JAVA_FSUB 102 */
211 1, /* JAVA_DSUB 103 */
212 1, /* JAVA_IMUL 104 */
213 1, /* JAVA_LMUL 105 */
214 1, /* JAVA_FMUL 106 */
215 1, /* JAVA_DMUL 107 */
216 1, /* JAVA_IDIV 108 */
217 1, /* JAVA_LDIV 109 */
218 1, /* JAVA_FDIV 110 */
219 1, /* JAVA_DDIV 111 */
220 1, /* JAVA_IREM 112 */
221 1, /* JAVA_LREM 113 */
222 1, /* JAVA_FREM 114 */
223 1, /* JAVA_DREM 115 */
224 1, /* JAVA_INEG 116 */
225 1, /* JAVA_LNEG 117 */
226 1, /* JAVA_FNEG 118 */
227 1, /* JAVA_DNEG 119 */
228 1, /* JAVA_ISHL 120 */
229 1, /* JAVA_LSHL 121 */
230 1, /* JAVA_ISHR 122 */
231 1, /* JAVA_LSHR 123 */
232 1, /* JAVA_IUSHR 124 */
233 1, /* JAVA_LUSHR 125 */
234 1, /* JAVA_IAND 126 */
235 1, /* JAVA_LAND 127 */
236 1, /* JAVA_IOR 128 */
237 1, /* JAVA_LOR 129 */
238 1, /* JAVA_IXOR 130 */
239 1, /* JAVA_LXOR 131 */
240 3, /* JAVA_IINC 132 */
241 1, /* JAVA_I2L 133 */
242 1, /* JAVA_I2F 134 */
243 1, /* JAVA_I2D 135 */
244 1, /* JAVA_L2I 136 */
245 1, /* JAVA_L2F 137 */
246 1, /* JAVA_L2D 138 */
247 1, /* JAVA_F2I 139 */
248 1, /* JAVA_F2L 140 */
249 1, /* JAVA_F2D 141 */
250 1, /* JAVA_D2I 142 */
251 1, /* JAVA_D2L 143 */
252 1, /* JAVA_D2F 144 */
253 1, /* JAVA_INT2BYTE 145 */
254 1, /* JAVA_INT2CHAR 146 */
255 1, /* JAVA_INT2SHORT 147 */
256 1, /* JAVA_LCMP 148 */
257 1, /* JAVA_FCMPL 149 */
258 1, /* JAVA_FCMPG 150 */
259 1, /* JAVA_DCMPL 151 */
260 1, /* JAVA_DCMPG 152 */
261 3, /* JAVA_IFEQ 153 */
262 3, /* JAVA_IFNE 154 */
263 3, /* JAVA_IFLT 155 */
264 3, /* JAVA_IFGE 156 */
265 3, /* JAVA_IFGT 157 */
266 3, /* JAVA_IFLE 158 */
267 3, /* JAVA_IF_ICMPEQ 159 */
268 3, /* JAVA_IF_ICMPNE 160 */
269 3, /* JAVA_IF_ICMPLT 161 */
270 3, /* JAVA_IF_ICMPGE 162 */
271 3, /* JAVA_IF_ICMPGT 163 */
272 3, /* JAVA_IF_ICMPLE 164 */
273 3, /* JAVA_IF_ACMPEQ 165 */
274 3, /* JAVA_IF_ACMPNE 166 */
275 3, /* JAVA_GOTO 167 */
276 3, /* JAVA_JSR 168 */
277 2, /* JAVA_RET 169 */
278 0, /* JAVA_TABLESWITCH 170 */ /* variable length */
279 0, /* JAVA_LOOKUPSWITCH 171 */ /* variable length */
280 1, /* JAVA_IRETURN 172 */
281 1, /* JAVA_LRETURN 173 */
282 1, /* JAVA_FRETURN 174 */
283 1, /* JAVA_DRETURN 175 */
284 1, /* JAVA_ARETURN 176 */
285 1, /* JAVA_RETURN 177 */
286 3, /* JAVA_GETSTATIC 178 */
287 3, /* JAVA_PUTSTATIC 179 */
288 3, /* JAVA_GETFIELD 180 */
289 3, /* JAVA_PUTFIELD 181 */
290 3, /* JAVA_INVOKEVIRTUAL 182 */
291 3, /* JAVA_INVOKESPECIAL 183 */
292 3, /* JAVA_INVOKESTATIC 184 */
293 5, /* JAVA_INVOKEINTERFACE 185 */
295 3, /* JAVA_NEW 187 */
296 2, /* JAVA_NEWARRAY 188 */
297 3, /* JAVA_ANEWARRAY 189 */
298 1, /* JAVA_ARRAYLENGTH 190 */
299 1, /* JAVA_ATHROW 191 */
300 3, /* JAVA_CHECKCAST 192 */
301 3, /* JAVA_INSTANCEOF 193 */
302 1, /* JAVA_MONITORENTER 194 */
303 1, /* JAVA_MONITOREXIT 195 */
304 0, /* JAVA_WIDE 196 */ /* variable length */
305 4, /* JAVA_MULTIANEWARRAY 197 */
306 3, /* JAVA_IFNULL 198 */
307 3, /* JAVA_IFNONNULL 199 */
308 5, /* JAVA_GOTO_W 200 */
309 5, /* JAVA_JSR_W 201 */
310 1, /* JAVA_BREAKPOINT 202 */
347 1,1,1,1,1,1,1,1,1,1,
352 char *icmd_names[256] = {
355 "CHECKNULL ", /* ICONST_M1 2 */
357 "CHECKNULL_POP ", /* ICONST_1 4 */
358 "IDIVPOW2 ", /* ICONST_2 5 */
359 "LDIVPOW2 ", /* ICONST_3 6 */
360 "UNDEF7 ", /* ICONST_4 7 */
361 "UNDEF8 ", /* ICONST_5 8 */
363 "LCMPCONST ", /* LCONST_1 10 */
365 "UNDEF12 ", /* FCONST_1 12 */
366 "ELSE_ICONST ", /* FCONST_2 13 */
368 "IFEQ_ICONST ", /* DCONST_1 15 */
369 "IFNE_ICONST ", /* BIPUSH 16 */
370 "IFLT_ICONST ", /* SIPUSH 17 */
371 "IFGE_ICONST ", /* LDC1 18 */
372 "IFGT_ICONST ", /* LDC2 19 */
373 "IFLE_ICONST ", /* LDC2W 20 */
379 "IADDCONST ", /* ILOAD_0 26 */
380 "ISUBCONST ", /* ILOAD_1 27 */
381 "IMULCONST ", /* ILOAD_2 28 */
382 "IANDCONST ", /* ILOAD_3 29 */
383 "IORCONST ", /* LLOAD_0 30 */
384 "IXORCONST ", /* LLOAD_1 31 */
385 "ISHLCONST ", /* LLOAD_2 32 */
386 "ISHRCONST ", /* LLOAD_3 33 */
387 "IUSHRCONST ", /* FLOAD_0 34 */
388 "IREMPOW2 ", /* FLOAD_1 35 */
389 "LADDCONST ", /* FLOAD_2 36 */
390 "LSUBCONST ", /* FLOAD_3 37 */
391 "LMULCONST ", /* DLOAD_0 38 */
392 "LANDCONST ", /* DLOAD_1 39 */
393 "LORCONST ", /* DLOAD_2 40 */
394 "LXORCONST ", /* DLOAD_3 41 */
395 "LSHLCONST ", /* ALOAD_0 42 */
396 "LSHRCONST ", /* ALOAD_1 43 */
397 "LUSHRCONST ", /* ALOAD_2 44 */
398 "LREMPOW2 ", /* ALOAD_3 45 */
412 "IF_LEQ ", /* ISTORE_0 59 */
413 "IF_LNE ", /* ISTORE_1 60 */
414 "IF_LLT ", /* ISTORE_2 61 */
415 "IF_LGE ", /* ISTORE_3 62 */
416 "IF_LGT ", /* LSTORE_0 63 */
417 "IF_LLE ", /* LSTORE_1 64 */
418 "IF_LCMPEQ ", /* LSTORE_2 65 */
419 "IF_LCMPNE ", /* LSTORE_3 66 */
420 "IF_LCMPLT ", /* FSTORE_0 67 */
421 "IF_LCMPGE ", /* FSTORE_1 68 */
422 "IF_LCMPGT ", /* FSTORE_2 69 */
423 "IF_LCMPLE ", /* FSTORE_3 70 */
424 "UNDEF71 ", /* DSTORE_0 71 */
425 "UNDEF72 ", /* DSTORE_1 72 */
426 "UNDEF73 ", /* DSTORE_2 73 */
427 "UNDEF74 ", /* DSTORE_3 74 */
428 "UNDEF75 ", /* ASTORE_0 75 */
429 "UNDEF76 ", /* ASTORE_1 76 */
430 "UNDEF77 ", /* ASTORE_2 77 */
431 "UNDEF78 ", /* ASTORE_3 78 */
498 "INT2BYTE ", /* 145 */
499 "INT2CHAR ", /* 146 */
500 "INT2SHORT ", /* 147 */
512 "IF_ICMPEQ ", /* 159 */
513 "IF_ICMPNE ", /* 160 */
514 "IF_ICMPLT ", /* 161 */
515 "IF_ICMPGE ", /* 162 */
516 "IF_ICMPGT ", /* 163 */
517 "IF_ICMPLE ", /* 164 */
518 "IF_ACMPEQ ", /* 165 */
519 "IF_ACMPNE ", /* 166 */
523 "TABLESWITCH ", /* 170 */
524 "LOOKUPSWITCH ", /* 171 */
525 "IRETURN ", /* 172 */
526 "LRETURN ", /* 173 */
527 "FRETURN ", /* 174 */
528 "DRETURN ", /* 175 */
529 "ARETURN ", /* 176 */
531 "GETSTATIC ", /* 178 */
532 "PUTSTATIC ", /* 179 */
533 "GETFIELD ", /* 180 */
534 "PUTFIELD ", /* 181 */
535 "INVOKEVIRTUAL ", /* 182 */
536 "INVOKESPECIAL ", /* 183 */
537 "INVOKESTATIC ", /* 184 */
538 "INVOKEINTERFACE", /* 185 */
539 "UNDEF186 ", /* UNDEF186 186 */
541 "NEWARRAY ", /* 188 */
542 "ANEWARRAY ", /* 189 */
543 "ARRAYLENGTH ", /* 190 */
545 "CHECKCAST ", /* 192 */
546 "INSTANCEOF ", /* 193 */
547 "MONITORENTER ", /* 194 */
548 "MONITOREXIT ", /* 195 */
549 "UNDEF196 ", /* WIDE 196 */
550 "MULTIANEWARRAY ", /* 197 */
552 "IFNONNULL ", /* 199 */
553 "UNDEF200 ", /* GOTO_W 200 */
554 "UNDEF201 ", /* JSR_W 201 */
555 "UNDEF202 ", /* BREAKPOINT 202 */
556 "UNDEF203 ", /* UNDEF203 203 */
557 "IASTORECONST ", /* 204 */
558 "LASTORECONST ", /* 205 */
559 "FASTORECONST ", /* 206 */
560 "DASTORECONST ", /* 207 */
561 "AASTORECONST ", /* 208 */
562 "BASTORECONST ", /* 209 */
563 "CASTORECONST ", /* 210 */
564 "SASTORECONST ", /* 211 */
565 "PUTSTATICCONST ", /* 212 */
566 "PUTFIELDCONST ", /* 213 */
567 "IMULPOW2 ", /* 214 */
568 "LMULPOW2 ", /* 215 */
570 "IF_FCMPEQ ", /* 216 */
571 "IF_FCMPNE ", /* 217 */
573 "IF_FCMPL_LT ", /* 218 */
574 "IF_FCMPL_GE ", /* 219 */
575 "IF_FCMPL_GT ", /* 220 */
576 "IF_FCMPL_LE ", /* 221 */
578 "IF_FCMPG_LT ", /* 222 */
579 "IF_FCMPG_GE ", /* 223 */
580 "IF_FCMPG_GT ", /* 224 */
581 "IF_FCMPG_LE ", /* 225 */
583 "IF_DCMPEQ ", /* 226 */
584 "IF_DCMPNE ", /* 227 */
586 "IF_DCMPL_LT ", /* 228 */
587 "IF_DCMPL_GE ", /* 229 */
588 "IF_DCMPL_GT ", /* 230 */
589 "IF_DCMPL_LE ", /* 231 */
591 "IF_DCMPG_LT ", /* 232 */
592 "IF_DCMPG_GE ", /* 233 */
593 "IF_DCMPG_GT ", /* 234 */
594 "IF_DCMPG_LE ", /* 235 */
596 "UNDEF236", "UNDEF237", "UNDEF238", "UNDEF239", "UNDEF240",
597 "UNDEF241", "UNDEF242", "UNDEF243", "UNDEF244", "UNDEF245",
598 "UNDEF246", "UNDEF247", "UNDEF248", "UNDEF249", "UNDEF250",
600 "INLINE_START ", /* 251 */
601 "INLINE_END ", /* 252 */
602 "INLINE_GOTO ", /* 253 */
610 char *opcode_names[256] = {
613 "ICONST_M1 ", /* ICONST_M1 2 */
614 "ICONST_0 ", /* ICONST_0 3 */
615 "ICONST_1 ", /* ICONST_1 4 */
616 "ICONST_2 ", /* ICONST_2 5 */
617 "ICONST_3 ", /* ICONST_3 6 */
618 "ICONST_4 ", /* ICONST_4 7 */
619 "ICONST_5 ", /* ICONST_5 8 */
620 "LCONST_0 ", /* LCONST_0 9 */
621 "LCONST_1 ", /* LCONST_1 10 */
622 "FCONST_0 ", /* FCONST_0 11 */
623 "FCONST_1 ", /* FCONST_1 12 */
624 "FCONST_2 ", /* FCONST_2 13 */
625 "DCONST_0 ", /* DCONST_0 14 */
626 "DCONST_1 ", /* DCONST_1 15 */
627 "BIPUSH ", /* BIPUSH 16 */
628 "SIPUSH ", /* SIPUSH 17 */
630 "LDC_W ", /* LDC_W 19 */
631 "LDC2_W ", /* LDC2_W 20 */
637 "ILOAD_0 ", /* ILOAD_0 26 */
638 "ILOAD_1 ", /* ILOAD_1 27 */
639 "ILOAD_2 ", /* ILOAD_2 28 */
640 "ILOAD_3 ", /* ILOAD_3 29 */
641 "LLOAD_0 ", /* LLOAD_0 30 */
642 "LLOAD_1 ", /* LLOAD_1 31 */
643 "LLOAD_2 ", /* LLOAD_2 32 */
644 "LLOAD_3 ", /* LLOAD_3 33 */
645 "FLOAD_0 ", /* FLOAD_0 34 */
646 "FLOAD_1 ", /* FLOAD_1 35 */
647 "FLOAD_2 ", /* FLOAD_2 36 */
648 "FLOAD_3 ", /* FLOAD_3 37 */
649 "DLOAD_0 ", /* DLOAD_0 38 */
650 "DLOAD_1 ", /* DLOAD_1 39 */
651 "DLOAD_2 ", /* DLOAD_2 40 */
652 "DLOAD_3 ", /* DLOAD_3 41 */
653 "ALOAD_0 ", /* ALOAD_0 42 */
654 "ALOAD_1 ", /* ALOAD_1 43 */
655 "ALOAD_2 ", /* ALOAD_2 44 */
656 "ALOAD_3 ", /* ALOAD_3 45 */
670 "ISTORE_0 ", /* ISTORE_0 59 */
671 "ISTORE_1 ", /* ISTORE_1 60 */
672 "ISTORE_2 ", /* ISTORE_2 61 */
673 "ISTORE_3 ", /* ISTORE_3 62 */
674 "LSTORE_0 ", /* LSTORE_0 63 */
675 "LSTORE_1 ", /* LSTORE_1 64 */
676 "LSTORE_2 ", /* LSTORE_2 65 */
677 "LSTORE_3 ", /* LSTORE_3 66 */
678 "FSTORE_0 ", /* FSTORE_0 67 */
679 "FSTORE_1 ", /* FSTORE_1 68 */
680 "FSTORE_2 ", /* FSTORE_2 69 */
681 "FSTORE_3 ", /* FSTORE_3 70 */
682 "DSTORE_0 ", /* DSTORE_0 71 */
683 "DSTORE_1 ", /* DSTORE_1 72 */
684 "DSTORE_2 ", /* DSTORE_2 73 */
685 "DSTORE_3 ", /* DSTORE_3 74 */
686 "ASTORE_0 ", /* ASTORE_0 75 */
687 "ASTORE_1 ", /* ASTORE_1 76 */
688 "ASTORE_2 ", /* ASTORE_2 77 */
689 "ASTORE_3 ", /* ASTORE_3 78 */
756 "INT2BYTE ", /* 145 */
757 "INT2CHAR ", /* 146 */
758 "INT2SHORT ", /* 147 */
770 "IF_ICMPEQ ", /* 159 */
771 "IF_ICMPNE ", /* 160 */
772 "IF_ICMPLT ", /* 161 */
773 "IF_ICMPGE ", /* 162 */
774 "IF_ICMPGT ", /* 163 */
775 "IF_ICMPLE ", /* 164 */
776 "IF_ACMPEQ ", /* 165 */
777 "IF_ACMPNE ", /* 166 */
781 "TABLESWITCH ", /* 170 */
782 "LOOKUPSWITCH ", /* 171 */
783 "IRETURN ", /* 172 */
784 "LRETURN ", /* 173 */
785 "FRETURN ", /* 174 */
786 "DRETURN ", /* 175 */
787 "ARETURN ", /* 176 */
789 "GETSTATIC ", /* 178 */
790 "PUTSTATIC ", /* 179 */
791 "GETFIELD ", /* 180 */
792 "PUTFIELD ", /* 181 */
793 "INVOKEVIRTUAL ", /* 182 */
794 "INVOKESPECIAL ", /* 183 */
795 "INVOKESTATIC ", /* 184 */
796 "INVOKEINTERFACE", /* 185 */
797 "UNDEF186 ", /* 186 */
799 "NEWARRAY ", /* 188 */
800 "ANEWARRAY ", /* 189 */
801 "ARRAYLENGTH ", /* 190 */
803 "CHECKCAST ", /* 192 */
804 "INSTANCEOF ", /* 193 */
805 "MONITORENTER ", /* 194 */
806 "MONITOREXIT ", /* 195 */
807 "WIDE ", /* WIDE 196 */
808 "MULTIANEWARRAY ", /* 197 */
810 "IFNONNULL ", /* 199 */
811 "GOTO_W ", /* GOTO_W 200 */
812 "JSR_W ", /* JSR_W 201 */
813 "BREAKPOINT ", /* BREAKPOINT 202 */
815 "UNDEF203", "UNDEF204", "UNDEF205",
816 "UNDEF206", "UNDEF207", "UNDEF208", "UNDEF209", "UNDEF210",
817 "UNDEF211", "UNDEF212", "UNDEF213", "UNDEF214", "UNDEF215",
818 "UNDEF216", "UNDEF217", "UNDEF218", "UNDEF219", "UNDEF220",
819 "UNDEF221", "UNDEF222", "UNDEF223", "UNDEF224", "UNDEF225",
820 "UNDEF226", "UNDEF227", "UNDEF228", "UNDEF229", "UNDEF230",
821 "UNDEF231", "UNDEF232", "UNDEF233", "UNDEF234", "UNDEF235",
822 "UNDEF236", "UNDEF237", "UNDEF238", "UNDEF239", "UNDEF240",
823 "UNDEF241", "UNDEF242", "UNDEF243", "UNDEF244", "UNDEF245",
824 "UNDEF246", "UNDEF247", "UNDEF248", "UNDEF249", "UNDEF250",
825 "UNDEF251", "UNDEF252", "UNDEF253", "UNDEF254", "UNDEF255"
829 /* jit_init ********************************************************************
831 Initializes the JIT subsystem.
833 *******************************************************************************/
839 for (i = 0; i < 256; i++)
842 stackreq[JAVA_NOP] = 0;
843 stackreq[JAVA_ISTORE] = 0;
844 stackreq[JAVA_LSTORE] = 0;
845 stackreq[JAVA_FSTORE] = 0;
846 stackreq[JAVA_DSTORE] = 0;
847 stackreq[JAVA_ASTORE] = 0;
848 stackreq[JAVA_ISTORE_0] = 0;
849 stackreq[JAVA_ISTORE_1] = 0;
850 stackreq[JAVA_ISTORE_2] = 0;
851 stackreq[JAVA_ISTORE_3] = 0;
852 stackreq[JAVA_LSTORE_0] = 0;
853 stackreq[JAVA_LSTORE_1] = 0;
854 stackreq[JAVA_LSTORE_2] = 0;
855 stackreq[JAVA_LSTORE_3] = 0;
856 stackreq[JAVA_FSTORE_0] = 0;
857 stackreq[JAVA_FSTORE_1] = 0;
858 stackreq[JAVA_FSTORE_2] = 0;
859 stackreq[JAVA_FSTORE_3] = 0;
860 stackreq[JAVA_DSTORE_0] = 0;
861 stackreq[JAVA_DSTORE_1] = 0;
862 stackreq[JAVA_DSTORE_2] = 0;
863 stackreq[JAVA_DSTORE_3] = 0;
864 stackreq[JAVA_ASTORE_0] = 0;
865 stackreq[JAVA_ASTORE_1] = 0;
866 stackreq[JAVA_ASTORE_2] = 0;
867 stackreq[JAVA_ASTORE_3] = 0;
868 stackreq[JAVA_IASTORE] = 0;
869 stackreq[JAVA_LASTORE] = 0;
870 stackreq[JAVA_FASTORE] = 0;
871 stackreq[JAVA_DASTORE] = 0;
872 stackreq[JAVA_AASTORE] = 0;
873 stackreq[JAVA_BASTORE] = 0;
874 stackreq[JAVA_CASTORE] = 0;
875 stackreq[JAVA_SASTORE] = 0;
876 stackreq[JAVA_POP] = 0;
877 stackreq[JAVA_POP2] = 0;
878 stackreq[JAVA_IFEQ] = 0;
879 stackreq[JAVA_IFNE] = 0;
880 stackreq[JAVA_IFLT] = 0;
881 stackreq[JAVA_IFGE] = 0;
882 stackreq[JAVA_IFGT] = 0;
883 stackreq[JAVA_IFLE] = 0;
884 stackreq[JAVA_IF_ICMPEQ] = 0;
885 stackreq[JAVA_IF_ICMPNE] = 0;
886 stackreq[JAVA_IF_ICMPLT] = 0;
887 stackreq[JAVA_IF_ICMPGE] = 0;
888 stackreq[JAVA_IF_ICMPGT] = 0;
889 stackreq[JAVA_IF_ICMPLE] = 0;
890 stackreq[JAVA_IF_ACMPEQ] = 0;
891 stackreq[JAVA_IF_ACMPNE] = 0;
892 stackreq[JAVA_GOTO] = 0;
893 stackreq[JAVA_RET] = 0;
894 stackreq[JAVA_TABLESWITCH] = 0;
895 stackreq[JAVA_LOOKUPSWITCH] = 0;
896 stackreq[JAVA_IRETURN] = 0;
897 stackreq[JAVA_LRETURN] = 0;
898 stackreq[JAVA_FRETURN] = 0;
899 stackreq[JAVA_DRETURN] = 0;
900 stackreq[JAVA_ARETURN] = 0;
901 stackreq[JAVA_RETURN] = 0;
902 stackreq[JAVA_PUTSTATIC] = 0;
903 stackreq[JAVA_PUTFIELD] = 0;
904 stackreq[JAVA_MONITORENTER] = 0;
905 stackreq[JAVA_MONITOREXIT] = 0;
906 stackreq[JAVA_WIDE] = 0;
907 stackreq[JAVA_IFNULL] = 0;
908 stackreq[JAVA_IFNONNULL] = 0;
909 stackreq[JAVA_GOTO_W] = 0;
910 stackreq[JAVA_BREAKPOINT] = 0;
911 stackreq[JAVA_IINC] = 0;
913 stackreq[JAVA_SWAP] = 2;
914 stackreq[JAVA_DUP2] = 2;
915 stackreq[JAVA_DUP_X1] = 3;
916 stackreq[JAVA_DUP_X2] = 4;
917 stackreq[JAVA_DUP2_X1] = 3;
918 stackreq[JAVA_DUP2_X2] = 4;
920 /* initialize stack analysis subsystem */
924 /* initialize show subsystem */
930 /* initialize codegen subsystem */
936 /* jit_close *******************************************************************
938 Close the JIT subsystem.
940 *******************************************************************************/
948 /* dummy function, used when there is no JavaVM code available */
950 static u1 *do_nothing_function(void)
956 /* jit_jitdata_new *************************************************************
958 Allocates and initalizes a new jitdata structure.
960 *******************************************************************************/
962 static jitdata *jit_jitdata_new(methodinfo *m)
966 /* allocate jitdata structure and fill it */
971 jd->cd = DNEW(codegendata);
972 jd->rd = DNEW(registerdata);
973 #if defined(ENABLE_LOOP)
974 jd->ld = DNEW(loopdata);
977 /* Allocate codeinfo memory from the heap as we need to keep them. */
979 jd->code = code_codeinfo_new(m);
981 /* initialize variables */
984 jd->isleafmethod = true;
990 /* jit_compile *****************************************************************
992 Translates one method to machine code.
994 *******************************************************************************/
996 static u1 *jit_compile_intern(jitdata *jd);
998 u1 *jit_compile(methodinfo *m)
1004 STATISTICS(count_jit_calls++);
1006 /* Initialize the static function's class. */
1008 /* ATTENTION: This MUST be done before the method lock is aquired,
1009 otherwise we could run into a deadlock with <clinit>'s that
1010 call static methods of it's own class. */
1012 if ((m->flags & ACC_STATIC) && !(m->class->state & CLASS_INITIALIZED)) {
1013 #if !defined(NDEBUG)
1015 log_message_class("Initialize class ", m->class);
1018 if (!initialize_class(m->class))
1021 /* check if the method has been compiled during initialization */
1023 if ((m->code != NULL) && (m->code->entrypoint != NULL))
1024 return m->code->entrypoint;
1027 /* enter a monitor on the method */
1029 BUILTIN_MONITOR_ENTER(m);
1031 /* if method has been already compiled return immediately */
1033 if (m->code != NULL) {
1034 BUILTIN_MONITOR_EXIT(m);
1036 assert(m->code->entrypoint);
1037 return m->code->entrypoint;
1040 STATISTICS(count_methods++);
1042 #if defined(ENABLE_STATISTICS)
1045 if (opt_getcompilingtime)
1046 compilingtime_start();
1049 /* mark start of dump memory area */
1051 dumpsize = dump_size();
1053 /* create jitdata structure */
1055 jd = jit_jitdata_new(m);
1057 /* set the flags for the current JIT run */
1059 jd->flags = JITDATA_FLAG_PARSE;
1062 jd->flags |= JITDATA_FLAG_VERIFY;
1065 jd->flags |= JITDATA_FLAG_INSTRUMENT;
1068 jd->flags |= JITDATA_FLAG_IFCONV;
1070 if (opt_showintermediate)
1071 jd->flags |= JITDATA_FLAG_SHOWINTERMEDIATE;
1073 if (opt_showdisassemble)
1074 jd->flags |= JITDATA_FLAG_SHOWDISASSEMBLE;
1076 if (opt_verbosecall)
1077 jd->flags |= JITDATA_FLAG_VERBOSECALL;
1079 #if defined(ENABLE_JIT)
1080 # if defined(ENABLE_INTRP)
1083 /* initialize the register allocator */
1088 /* setup the codegendata memory */
1092 /* now call internal compile function */
1094 r = jit_compile_intern(jd);
1096 /* clear pointers to dump memory area */
1098 m->basicblocks = NULL;
1099 m->basicblockindex = NULL;
1100 m->instructions = NULL;
1104 /* We had an exception! Finish stuff here if necessary. */
1106 /* release codeinfo */
1108 code_codeinfo_free(jd->code);
1110 /* Release memory for basic block profiling information. */
1112 if (JITDATA_HAS_FLAG_INSTRUMENT(jd))
1113 if (jd->code->bbfrequency != NULL)
1114 MFREE(jd->code->bbfrequency, u4, jd->code->basicblockcount);
1117 DEBUG_JIT_COMPILEVERBOSE("Running: ");
1120 /* release dump area */
1122 dump_release(dumpsize);
1124 #if defined(ENABLE_STATISTICS)
1127 if (opt_getcompilingtime)
1128 compilingtime_stop();
1131 /* leave the monitor */
1133 BUILTIN_MONITOR_EXIT(m);
1135 /* return pointer to the methods entry point */
1141 /* jit_recompile ***************************************************************
1143 Recompiles a Java method.
1145 *******************************************************************************/
1147 u1 *jit_recompile(methodinfo *m)
1154 /* check for max. optimization level */
1156 optlevel = m->code->optlevel;
1158 if (optlevel == 1) {
1159 log_message_method("not recompiling: ", m);
1163 log_message_method("Recompiling start: ", m);
1165 STATISTICS(count_jit_calls++);
1167 #if defined(ENABLE_STATISTICS)
1170 if (opt_getcompilingtime)
1171 compilingtime_start();
1174 /* mark start of dump memory area */
1176 dumpsize = dump_size();
1178 /* create jitdata structure */
1180 jd = jit_jitdata_new(m);
1182 /* set the current optimization level to the previous one plus 1 */
1184 jd->code->optlevel = optlevel + 1;
1186 /* get the optimization flags for the current JIT run */
1188 jd->flags |= JITDATA_FLAG_SHOWINTERMEDIATE;
1189 jd->flags |= JITDATA_FLAG_SHOWDISASSEMBLE;
1190 /* jd->flags |= JITDATA_FLAG_VERBOSECALL; */
1192 #if defined(ENABLE_JIT)
1193 # if defined(ENABLE_INTRP)
1196 /* initialize the register allocator */
1201 /* setup the codegendata memory */
1205 /* now call internal compile function */
1207 r = jit_compile_intern(jd);
1209 /* clear pointers to dump memory area */
1211 m->basicblocks = NULL;
1212 m->basicblockindex = NULL;
1213 m->instructions = NULL;
1217 /* We had an exception! Finish stuff here if necessary. */
1219 /* release codeinfo */
1221 code_codeinfo_free(jd->code);
1224 /* release dump area */
1226 dump_release(dumpsize);
1228 #if defined(ENABLE_STATISTICS)
1231 if (opt_getcompilingtime)
1232 compilingtime_stop();
1235 log_message_method("Recompiling done: ", m);
1237 /* return pointer to the methods entry point */
1243 /* jit_compile_intern **********************************************************
1245 Static internal function which does the actual compilation.
1247 *******************************************************************************/
1249 static u1 *jit_compile_intern(jitdata *jd)
1255 #if defined(ENABLE_RT_TIMING)
1256 struct timespec time_start,time_checks,time_parse,time_stack,
1257 time_typecheck,time_loop,time_ifconv,time_alloc,
1258 time_rplpoints,time_codegen;
1261 RT_TIMING_GET_TIME(time_start);
1263 /* get required compiler data */
1269 /* print log message for compiled method */
1271 DEBUG_JIT_COMPILEVERBOSE("Compiling: ");
1273 /* handle native methods and create a native stub */
1275 if (m->flags & ACC_NATIVE) {
1278 #if defined(WITH_STATIC_CLASSPATH)
1279 f = native_findfunction(m->class->name, m->name, m->descriptor,
1280 (m->flags & ACC_STATIC));
1287 code = codegen_createnativestub(f, m);
1289 assert(!m->code); /* native methods are never recompiled */
1292 return code->entrypoint;
1295 /* if there is no javacode, print error message and return empty method */
1297 if (m->jcode == NULL) {
1298 DEBUG_JIT_COMPILEVERBOSE("No code given for: ");
1300 code->entrypoint = (u1 *) (ptrint) do_nothing_function;
1303 return code->entrypoint; /* return empty method */
1306 #if defined(ENABLE_STATISTICS)
1308 count_tryblocks += m->exceptiontablelength;
1309 count_javacodesize += m->jcodelength + 18;
1310 count_javaexcsize += m->exceptiontablelength * SIZEOF_VOID_P;
1314 RT_TIMING_GET_TIME(time_checks);
1316 /* call the compiler passes ***********************************************/
1318 DEBUG_JIT_COMPILEVERBOSE("Parsing: ");
1320 /* call parse pass */
1323 DEBUG_JIT_COMPILEVERBOSE("Exception while parsing: ");
1327 RT_TIMING_GET_TIME(time_parse);
1329 DEBUG_JIT_COMPILEVERBOSE("Parsing done: ");
1330 DEBUG_JIT_COMPILEVERBOSE("Analysing: ");
1332 /* call stack analysis pass */
1334 if (!stack_analyse(jd)) {
1335 DEBUG_JIT_COMPILEVERBOSE("Exception while analysing: ");
1339 RT_TIMING_GET_TIME(time_stack);
1341 DEBUG_JIT_COMPILEVERBOSE("Analysing done: ");
1343 #ifdef ENABLE_VERIFIER
1344 if (jd->flags & JITDATA_FLAG_VERIFY) {
1345 DEBUG_JIT_COMPILEVERBOSE("Typechecking: ");
1347 /* call typecheck pass */
1348 if (!typecheck(jd)) {
1349 DEBUG_JIT_COMPILEVERBOSE("Exception while typechecking: ");
1354 DEBUG_JIT_COMPILEVERBOSE("Typechecking done: ");
1357 RT_TIMING_GET_TIME(time_typecheck);
1359 #if defined(ENABLE_LOOP)
1366 RT_TIMING_GET_TIME(time_loop);
1368 #if defined(ENABLE_IFCONV)
1369 if (JITDATA_HAS_FLAG_IFCONV(jd))
1370 if (!ifconv_static(jd))
1373 RT_TIMING_GET_TIME(time_ifconv);
1375 #if defined(ENABLE_JIT)
1376 # if defined(ENABLE_INTRP)
1379 DEBUG_JIT_COMPILEVERBOSE("Allocating registers: ");
1381 /* allocate registers */
1382 # if defined(ENABLE_LSRA)
1387 STATISTICS(count_methods_allocated_by_lsra++);
1390 # endif /* defined(ENABLE_LSRA) */
1392 STATISTICS(count_locals_conflicts += (cd->maxlocals - 1) * (cd->maxlocals));
1397 STATISTICS(reg_make_statistics(jd));
1399 DEBUG_JIT_COMPILEVERBOSE("Allocating registers done: ");
1400 # if defined(ENABLE_INTRP)
1403 #endif /* defined(ENABLE_JIT) */
1404 RT_TIMING_GET_TIME(time_alloc);
1406 /* Allocate memory for basic block profiling information. This
1407 _must_ be done after loop optimization and register allocation,
1408 since they can change the basic block count. */
1410 if (JITDATA_HAS_FLAG_INSTRUMENT(jd))
1411 code->bbfrequency = MNEW(u4, code->basicblockcount);
1413 DEBUG_JIT_COMPILEVERBOSE("Generating code: ");
1415 /* create the replacement points */
1417 if (!replace_create_replacement_points(jd))
1419 RT_TIMING_GET_TIME(time_rplpoints);
1421 /* now generate the machine code */
1423 #if defined(ENABLE_JIT)
1424 # if defined(ENABLE_INTRP)
1426 if (!intrp_codegen(jd)) {
1427 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1435 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1441 if (!intrp_codegen(jd)) {
1442 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1447 RT_TIMING_GET_TIME(time_codegen);
1449 DEBUG_JIT_COMPILEVERBOSE("Generating code done: ");
1451 #if !defined(NDEBUG)
1452 /* intermediate and assembly code listings */
1454 if (JITDATA_HAS_FLAG_SHOWINTERMEDIATE(jd)) {
1457 else if (JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd)) {
1458 # if defined(ENABLE_DISASSEMBLER)
1459 DISASSEMBLE(code->entrypoint,
1460 code->entrypoint + (code->mcodelength - cd->dseglen));
1464 if (opt_showddatasegment)
1468 DEBUG_JIT_COMPILEVERBOSE("Compiling done: ");
1470 /* switch to the newly generated code */
1473 assert(code->entrypoint);
1475 /* add the current compile version to the methodinfo */
1477 code->prev = m->code;
1480 RT_TIMING_TIME_DIFF(time_start,time_checks,RT_TIMING_JIT_CHECKS);
1481 RT_TIMING_TIME_DIFF(time_checks,time_parse,RT_TIMING_JIT_PARSE);
1482 RT_TIMING_TIME_DIFF(time_parse,time_stack,RT_TIMING_JIT_STACK);
1483 RT_TIMING_TIME_DIFF(time_stack,time_typecheck,RT_TIMING_JIT_TYPECHECK);
1484 RT_TIMING_TIME_DIFF(time_typecheck,time_loop,RT_TIMING_JIT_LOOP);
1485 RT_TIMING_TIME_DIFF(time_loop,time_alloc,RT_TIMING_JIT_ALLOC);
1486 RT_TIMING_TIME_DIFF(time_alloc,time_rplpoints,RT_TIMING_JIT_RPLPOINTS);
1487 RT_TIMING_TIME_DIFF(time_rplpoints,time_codegen,RT_TIMING_JIT_CODEGEN);
1488 RT_TIMING_TIME_DIFF(time_start,time_codegen,RT_TIMING_JIT_TOTAL);
1490 /* return pointer to the methods entry point */
1492 return code->entrypoint;
1496 /* jit_asm_compile *************************************************************
1498 This method is called from asm_vm_call_method and does:
1500 - create stackframe info for exceptions
1501 - compile the method
1502 - patch the entrypoint of the method into the calculated address in
1504 - flushes the instruction cache.
1506 *******************************************************************************/
1508 u1 *jit_asm_compile(methodinfo *m, u1 *mptr, u1 *sp, u1 *ra)
1515 /* create the stackframeinfo (XPC is equal to RA) */
1517 stacktrace_create_extern_stackframeinfo(&sfi, NULL, sp, ra, ra);
1519 /* actually compile the method */
1521 entrypoint = jit_compile(m);
1523 /* remove the stackframeinfo */
1525 stacktrace_remove_stackframeinfo(&sfi);
1527 /* there was a problem during compilation */
1529 if (entrypoint == NULL)
1532 /* get the method patch address */
1534 pa = md_get_method_patch_address(ra, &sfi, mptr);
1536 /* patch the method entry point */
1540 *p = (ptrint) entrypoint;
1542 /* flush the instruction cache */
1544 md_icacheflush(pa, SIZEOF_VOID_P);
1551 * These are local overrides for various environment variables in Emacs.
1552 * Please do not remove this and leave it at the end of the file, where
1553 * Emacs will automagically detect them.
1554 * ---------------------------------------------------------------------
1557 * indent-tabs-mode: t
1561 * vim:noexpandtab:sw=4:ts=4: