1 /* src/vm/jit/jit.c - calls the code generation functions
3 Copyright (C) 1996-2005, 2006, 2007 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
34 #include "mm/memory.h"
36 #include "native/native.h"
38 #include "toolbox/logging.h"
40 #include "threads/lock-common.h"
41 #include "threads/threads-common.h"
43 #include "vm/global.h"
44 #include "vm/initialize.h"
46 #include "vm/jit/asmpart.h"
48 # include "vm/jit/cfg.h"
50 #include "vm/jit/codegen-common.h"
51 #include "vm/jit/disass.h"
52 #include "vm/jit/dseg.h"
53 #include "vm/jit/jit.h"
54 #include "vm/jit/md.h"
55 #include "vm/jit/parse.h"
56 #include "vm/jit/reg.h"
58 #include "vm/jit/show.h"
59 #include "vm/jit/stack.h"
61 #include "vm/jit/allocator/simplereg.h"
62 #if defined(ENABLE_LSRA) && !defined(ENABLE_SSA)
63 # include "vm/jit/allocator/lsra.h"
65 #if defined(ENABLE_SSA)
66 # include "vm/jit/optimizing/lsra.h"
67 # include "vm/jit/optimizing/ssa.h"
70 #if defined(ENABLE_INLINING)
71 # include "vm/jit/inline/inline.h"
74 #include "vm/jit/loop/analyze.h"
75 #include "vm/jit/loop/graph.h"
76 #include "vm/jit/loop/loop.h"
78 #if defined(ENABLE_IFCONV)
79 # include "vm/jit/optimizing/ifconv.h"
82 #include "vm/jit/optimizing/reorder.h"
84 #include "vm/jit/verify/typecheck.h"
86 #include "vmcore/class.h"
87 #include "vmcore/loader.h"
88 #include "vmcore/method.h"
89 #include "vmcore/options.h"
90 #include "vmcore/rt-timing.h"
91 #include "vmcore/statistics.h"
94 /* debug macros ***************************************************************/
97 #define DEBUG_JIT_COMPILEVERBOSE(x) \
99 if (compileverbose) { \
100 log_message_method(x, m); \
104 #define DEBUG_JIT_COMPILEVERBOSE(x) /* nothing */
108 /* the ICMD table ************************************************************/
111 #define N(name) name,
116 /* abbreviations for flags */
118 #define PEI ICMDTABLE_PEI
119 #define CALLS ICMDTABLE_CALLS
121 /* some machine dependent values */
126 #define IDIV_CALLS ICMDTABLE_CALLS
129 #if (SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
132 #define LDIV_CALLS ICMDTABLE_CALLS
135 /* include the actual table */
137 icmdtable_entry_t icmd_table[256] = {
138 #include <vm/jit/icmdtable.inc>
145 /* XXX hack until the old "PEI" definition is removed */
149 /* stackelement requirements of Java opcodes **********************************/
151 int stackreq[256] = {
153 1, /* JAVA_ACONST 1 */
154 1, /* JAVA_ICONST_M1 2 */
155 1, /* JAVA_ICONST_0 3 */
156 1, /* JAVA_ICONST_1 4 */
157 1, /* JAVA_ICONST_2 5 */
158 1, /* JAVA_ICONST_3 6 */
159 1, /* JAVA_ICONST_4 7 */
160 1, /* JAVA_ICONST_5 8 */
161 1, /* JAVA_LCONST_0 9 */
162 1, /* JAVA_LCONST_1 10 */
163 1, /* JAVA_FCONST_0 11 */
164 1, /* JAVA_FCONST_1 12 */
165 1, /* JAVA_FCONST_2 13 */
166 1, /* JAVA_DCONST_0 14 */
167 1, /* JAVA_DCONST_1 15 */
168 1, /* JAVA_BIPUSH 16 */
169 1, /* JAVA_SIPUSH 17 */
171 1, /* JAVA_LDC_W 19 */
172 1, /* JAVA_LDC2_W 20 */
173 1, /* JAVA_ILOAD 21 */
174 1, /* JAVA_LLOAD 22 */
175 1, /* JAVA_FLOAD 23 */
176 1, /* JAVA_DLOAD 24 */
177 1, /* JAVA_ALOAD 25 */
178 1, /* JAVA_ILOAD_0 26 */
179 1, /* JAVA_ILOAD_1 27 */
180 1, /* JAVA_ILOAD_2 28 */
181 1, /* JAVA_ILOAD_3 29 */
182 1, /* JAVA_LLOAD_0 30 */
183 1, /* JAVA_LLOAD_1 31 */
184 1, /* JAVA_LLOAD_2 32 */
185 1, /* JAVA_LLOAD_3 33 */
186 1, /* JAVA_FLOAD_0 34 */
187 1, /* JAVA_FLOAD_1 35 */
188 1, /* JAVA_FLOAD_2 36 */
189 1, /* JAVA_FLOAD_3 37 */
190 1, /* JAVA_DLOAD_0 38 */
191 1, /* JAVA_DLOAD_1 39 */
192 1, /* JAVA_DLOAD_2 40 */
193 1, /* JAVA_DLOAD_3 41 */
194 1, /* JAVA_ALOAD_0 42 */
195 1, /* JAVA_ALOAD_1 43 */
196 1, /* JAVA_ALOAD_2 44 */
197 1, /* JAVA_ALOAD_3 45 */
198 1, /* JAVA_IALOAD 46 */
199 1, /* JAVA_LALOAD 47 */
200 1, /* JAVA_FALOAD 48 */
201 1, /* JAVA_DALOAD 49 */
202 1, /* JAVA_AALOAD 50 */
203 1, /* JAVA_BALOAD 51 */
204 1, /* JAVA_CALOAD 52 */
205 1, /* JAVA_SALOAD 53 */
206 0, /* JAVA_ISTORE 54 */
207 0, /* JAVA_LSTORE 55 */
208 0, /* JAVA_FSTORE 56 */
209 0, /* JAVA_DSTORE 57 */
210 0, /* JAVA_ASTORE 58 */
211 0, /* JAVA_ISTORE_0 59 */
212 0, /* JAVA_ISTORE_1 60 */
213 0, /* JAVA_ISTORE_2 61 */
214 0, /* JAVA_ISTORE_3 62 */
215 0, /* JAVA_LSTORE_0 63 */
216 0, /* JAVA_LSTORE_1 64 */
217 0, /* JAVA_LSTORE_2 65 */
218 0, /* JAVA_LSTORE_3 66 */
219 0, /* JAVA_FSTORE_0 67 */
220 0, /* JAVA_FSTORE_1 68 */
221 0, /* JAVA_FSTORE_2 69 */
222 0, /* JAVA_FSTORE_3 70 */
223 0, /* JAVA_DSTORE_0 71 */
224 0, /* JAVA_DSTORE_1 72 */
225 0, /* JAVA_DSTORE_2 73 */
226 0, /* JAVA_DSTORE_3 74 */
227 0, /* JAVA_ASTORE_0 75 */
228 0, /* JAVA_ASTORE_1 76 */
229 0, /* JAVA_ASTORE_2 77 */
230 0, /* JAVA_ASTORE_3 78 */
231 0, /* JAVA_IASTORE 79 */
232 0, /* JAVA_LASTORE 80 */
233 0, /* JAVA_FASTORE 81 */
234 0, /* JAVA_DASTORE 82 */
235 0, /* JAVA_AASTORE 83 */
236 0, /* JAVA_BASTORE 84 */
237 0, /* JAVA_CASTORE 85 */
238 0, /* JAVA_SASTORE 86 */
240 0, /* JAVA_POP2 88 */
242 1+3, /* JAVA_DUP_X1 90 */
243 2+4, /* JAVA_DUP_X2 91 */
244 2, /* JAVA_DUP2 92 */
245 2+5, /* JAVA_DUP2_X1 93 */
246 3+6, /* JAVA_DUP2_X2 94 */
247 1+2, /* JAVA_SWAP 95 */
248 1, /* JAVA_IADD 96 */
249 1, /* JAVA_LADD 97 */
250 1, /* JAVA_FADD 98 */
251 1, /* JAVA_DADD 99 */
252 1, /* JAVA_ISUB 100 */
253 1, /* JAVA_LSUB 101 */
254 1, /* JAVA_FSUB 102 */
255 1, /* JAVA_DSUB 103 */
256 1, /* JAVA_IMUL 104 */
257 1, /* JAVA_LMUL 105 */
258 1, /* JAVA_FMUL 106 */
259 1, /* JAVA_DMUL 107 */
260 1, /* JAVA_IDIV 108 */
261 1, /* JAVA_LDIV 109 */
262 1, /* JAVA_FDIV 110 */
263 1, /* JAVA_DDIV 111 */
264 1, /* JAVA_IREM 112 */
265 1, /* JAVA_LREM 113 */
266 1, /* JAVA_FREM 114 */
267 1, /* JAVA_DREM 115 */
268 1, /* JAVA_INEG 116 */
269 1, /* JAVA_LNEG 117 */
270 1, /* JAVA_FNEG 118 */
271 1, /* JAVA_DNEG 119 */
272 1, /* JAVA_ISHL 120 */
273 1, /* JAVA_LSHL 121 */
274 1, /* JAVA_ISHR 122 */
275 1, /* JAVA_LSHR 123 */
276 1, /* JAVA_IUSHR 124 */
277 1, /* JAVA_LUSHR 125 */
278 1, /* JAVA_IAND 126 */
279 1, /* JAVA_LAND 127 */
280 1, /* JAVA_IOR 128 */
281 1, /* JAVA_LOR 129 */
282 1, /* JAVA_IXOR 130 */
283 1, /* JAVA_LXOR 131 */
284 0, /* JAVA_IINC 132 */
285 1, /* JAVA_I2L 133 */
286 1, /* JAVA_I2F 134 */
287 1, /* JAVA_I2D 135 */
288 1, /* JAVA_L2I 136 */
289 1, /* JAVA_L2F 137 */
290 1, /* JAVA_L2D 138 */
291 1, /* JAVA_F2I 139 */
292 1, /* JAVA_F2L 140 */
293 1, /* JAVA_F2D 141 */
294 1, /* JAVA_D2I 142 */
295 1, /* JAVA_D2L 143 */
296 1, /* JAVA_D2F 144 */
297 1, /* JAVA_INT2BYTE 145 */
298 1, /* JAVA_INT2CHAR 146 */
299 1, /* JAVA_INT2SHORT 147 */
300 1, /* JAVA_LCMP 148 */
301 1, /* JAVA_FCMPL 149 */
302 1, /* JAVA_FCMPG 150 */
303 1, /* JAVA_DCMPL 151 */
304 1, /* JAVA_DCMPG 152 */
305 0, /* JAVA_IFEQ 153 */
306 0, /* JAVA_IFNE 154 */
307 0, /* JAVA_IFLT 155 */
308 0, /* JAVA_IFGE 156 */
309 0, /* JAVA_IFGT 157 */
310 0, /* JAVA_IFLE 158 */
311 0, /* JAVA_IF_ICMPEQ 159 */
312 0, /* JAVA_IF_ICMPNE 160 */
313 0, /* JAVA_IF_ICMPLT 161 */
314 0, /* JAVA_IF_ICMPGE 162 */
315 0, /* JAVA_IF_ICMPGT 163 */
316 0, /* JAVA_IF_ICMPLE 164 */
317 0, /* JAVA_IF_ACMPEQ 165 */
318 0, /* JAVA_IF_ACMPNE 166 */
319 0, /* JAVA_GOTO 167 */
320 1, /* JAVA_JSR 168 */
321 0, /* JAVA_RET 169 */
322 0, /* JAVA_TABLESWITCH 170 */
323 0, /* JAVA_LOOKUPSWITCH 171 */
324 0, /* JAVA_IRETURN 172 */
325 0, /* JAVA_LRETURN 173 */
326 0, /* JAVA_FRETURN 174 */
327 0, /* JAVA_DRETURN 175 */
328 0, /* JAVA_ARETURN 176 */
329 0, /* JAVA_RETURN 177 */
330 1, /* JAVA_GETSTATIC 178 */
331 0, /* JAVA_PUTSTATIC 179 */
332 1, /* JAVA_GETFIELD 180 */
333 0, /* JAVA_PUTFIELD 181 */
334 1, /* JAVA_INVOKEVIRTUAL 182 */
335 1, /* JAVA_INVOKESPECIAL 183 */
336 1, /* JAVA_INVOKESTATIC 184 */
337 1, /* JAVA_INVOKEINTERFACE 185 */
338 1, /* JAVA_UNDEF186 186 */
339 1, /* JAVA_NEW 187 */
340 1, /* JAVA_NEWARRAY 188 */
341 1, /* JAVA_ANEWARRAY 189 */
342 1, /* JAVA_ARRAYLENGTH 190 */
343 1, /* JAVA_ATHROW 191 */
344 1, /* JAVA_CHECKCAST 192 */
345 1, /* JAVA_INSTANCEOF 193 */
346 0, /* JAVA_MONITORENTER 194 */
347 0, /* JAVA_MONITOREXIT 195 */
348 0, /* JAVA_WIDE 196 */
349 1, /* JAVA_MULTIANEWARRAY 197 */
350 0, /* JAVA_IFNULL 198 */
351 0, /* JAVA_IFNONNULL 199 */
352 0, /* JAVA_GOTO_W 200 */
353 1, /* JAVA_JSR_W 201 */
354 0, /* JAVA_BREAKPOINT 202 */
355 1, /* JAVA_UNDEF203 203 */
356 1, /* JAVA_UNDEF204 204 */
357 1, /* JAVA_UNDEF205 205 */
358 1, /* JAVA_UNDEF206 206 */
359 1, /* JAVA_UNDEF207 207 */
360 1, /* JAVA_UNDEF208 208 */
361 1, /* JAVA_UNDEF209 209 */
362 1, /* JAVA_UNDEF210 210 */
363 1, /* JAVA_UNDEF211 211 */
364 1, /* JAVA_UNDEF212 212 */
365 1, /* JAVA_UNDEF213 213 */
366 1, /* JAVA_UNDEF214 214 */
367 1, /* JAVA_UNDEF215 215 */
368 1, /* JAVA_UNDEF216 216 */
369 1, /* JAVA_UNDEF217 217 */
370 1, /* JAVA_UNDEF218 218 */
371 1, /* JAVA_UNDEF219 219 */
372 1, /* JAVA_UNDEF220 220 */
373 1, /* JAVA_UNDEF221 221 */
374 1, /* JAVA_UNDEF222 222 */
375 1, /* JAVA_UNDEF223 223 */
376 1, /* JAVA_UNDEF224 224 */
377 1, /* JAVA_UNDEF225 225 */
378 1, /* JAVA_UNDEF226 226 */
379 1, /* JAVA_UNDEF227 227 */
380 1, /* JAVA_UNDEF228 228 */
381 1, /* JAVA_UNDEF229 229 */
382 1, /* JAVA_UNDEF230 230 */
383 1, /* JAVA_UNDEF231 231 */
384 1, /* JAVA_UNDEF232 232 */
385 1, /* JAVA_UNDEF233 233 */
386 1, /* JAVA_UNDEF234 234 */
387 1, /* JAVA_UNDEF235 235 */
388 1, /* JAVA_UNDEF236 236 */
389 1, /* JAVA_UNDEF237 237 */
390 1, /* JAVA_UNDEF238 238 */
391 1, /* JAVA_UNDEF239 239 */
392 1, /* JAVA_UNDEF240 240 */
393 1, /* JAVA_UNDEF241 241 */
394 1, /* JAVA_UNDEF242 242 */
395 1, /* JAVA_UNDEF243 243 */
396 1, /* JAVA_UNDEF244 244 */
397 1, /* JAVA_UNDEF245 245 */
398 1, /* JAVA_UNDEF246 246 */
399 1, /* JAVA_UNDEF247 247 */
400 1, /* JAVA_UNDEF248 248 */
401 1, /* JAVA_UNDEF249 249 */
402 1, /* JAVA_UNDEF250 250 */
403 1, /* JAVA_UNDEF251 251 */
404 1, /* JAVA_UNDEF252 252 */
405 1, /* JAVA_UNDEF253 253 */
406 1, /* JAVA_UNDEF254 254 */
407 1, /* JAVA_UNDEF255 255 */
411 /* size in bytes of Java opcodes **********************************************/
413 int jcommandsize[256] = {
416 1, /* JAVA_ACONST_NULL 1 */
417 1, /* JAVA_ICONST_M1 2 */
418 1, /* JAVA_ICONST_0 3 */
419 1, /* JAVA_ICONST_1 4 */
420 1, /* JAVA_ICONST_2 5 */
421 1, /* JAVA_ICONST_3 6 */
422 1, /* JAVA_ICONST_4 7 */
423 1, /* JAVA_ICONST_5 8 */
424 1, /* JAVA_LCONST_0 9 */
425 1, /* JAVA_LCONST_1 10 */
426 1, /* JAVA_FCONST_0 11 */
427 1, /* JAVA_FCONST_1 12 */
428 1, /* JAVA_FCONST_2 13 */
429 1, /* JAVA_DCONST_0 14 */
430 1, /* JAVA_DCONST_1 15 */
431 2, /* JAVA_BIPUSH 16 */
432 3, /* JAVA_SIPUSH 17 */
433 2, /* JAVA_LDC1 18 */
434 3, /* JAVA_LDC2 19 */
435 3, /* JAVA_LDC2W 20 */
436 2, /* JAVA_ILOAD 21 */
437 2, /* JAVA_LLOAD 22 */
438 2, /* JAVA_FLOAD 23 */
439 2, /* JAVA_DLOAD 24 */
440 2, /* JAVA_ALOAD 25 */
441 1, /* JAVA_ILOAD_0 26 */
442 1, /* JAVA_ILOAD_1 27 */
443 1, /* JAVA_ILOAD_2 28 */
444 1, /* JAVA_ILOAD_3 29 */
445 1, /* JAVA_LLOAD_0 30 */
446 1, /* JAVA_LLOAD_1 31 */
447 1, /* JAVA_LLOAD_2 32 */
448 1, /* JAVA_LLOAD_3 33 */
449 1, /* JAVA_FLOAD_0 34 */
450 1, /* JAVA_FLOAD_1 35 */
451 1, /* JAVA_FLOAD_2 36 */
452 1, /* JAVA_FLOAD_3 37 */
453 1, /* JAVA_DLOAD_0 38 */
454 1, /* JAVA_DLOAD_1 39 */
455 1, /* JAVA_DLOAD_2 40 */
456 1, /* JAVA_DLOAD_3 41 */
457 1, /* JAVA_ALOAD_0 42 */
458 1, /* JAVA_ALOAD_1 43 */
459 1, /* JAVA_ALOAD_2 44 */
460 1, /* JAVA_ALOAD_3 45 */
461 1, /* JAVA_IALOAD 46 */
462 1, /* JAVA_LALOAD 47 */
463 1, /* JAVA_FALOAD 48 */
464 1, /* JAVA_DALOAD 49 */
465 1, /* JAVA_AALOAD 50 */
466 1, /* JAVA_BALOAD 51 */
467 1, /* JAVA_CALOAD 52 */
468 1, /* JAVA_SALOAD 53 */
469 2, /* JAVA_ISTORE 54 */
470 2, /* JAVA_LSTORE 55 */
471 2, /* JAVA_FSTORE 56 */
472 2, /* JAVA_DSTORE 57 */
473 2, /* JAVA_ASTORE 58 */
474 1, /* JAVA_ISTORE_0 59 */
475 1, /* JAVA_ISTORE_1 60 */
476 1, /* JAVA_ISTORE_2 61 */
477 1, /* JAVA_ISTORE_3 62 */
478 1, /* JAVA_LSTORE_0 63 */
479 1, /* JAVA_LSTORE_1 64 */
480 1, /* JAVA_LSTORE_2 65 */
481 1, /* JAVA_LSTORE_3 66 */
482 1, /* JAVA_FSTORE_0 67 */
483 1, /* JAVA_FSTORE_1 68 */
484 1, /* JAVA_FSTORE_2 69 */
485 1, /* JAVA_FSTORE_3 70 */
486 1, /* JAVA_DSTORE_0 71 */
487 1, /* JAVA_DSTORE_1 72 */
488 1, /* JAVA_DSTORE_2 73 */
489 1, /* JAVA_DSTORE_3 74 */
490 1, /* JAVA_ASTORE_0 75 */
491 1, /* JAVA_ASTORE_1 76 */
492 1, /* JAVA_ASTORE_2 77 */
493 1, /* JAVA_ASTORE_3 78 */
494 1, /* JAVA_IASTORE 79 */
495 1, /* JAVA_LASTORE 80 */
496 1, /* JAVA_FASTORE 81 */
497 1, /* JAVA_DASTORE 82 */
498 1, /* JAVA_AASTORE 83 */
499 1, /* JAVA_BASTORE 84 */
500 1, /* JAVA_CASTORE 85 */
501 1, /* JAVA_SASTORE 86 */
503 1, /* JAVA_POP2 88 */
505 1, /* JAVA_DUP_X1 90 */
506 1, /* JAVA_DUP_X2 91 */
507 1, /* JAVA_DUP2 92 */
508 1, /* JAVA_DUP2_X1 93 */
509 1, /* JAVA_DUP2_X2 94 */
510 1, /* JAVA_SWAP 95 */
511 1, /* JAVA_IADD 96 */
512 1, /* JAVA_LADD 97 */
513 1, /* JAVA_FADD 98 */
514 1, /* JAVA_DADD 99 */
515 1, /* JAVA_ISUB 100 */
516 1, /* JAVA_LSUB 101 */
517 1, /* JAVA_FSUB 102 */
518 1, /* JAVA_DSUB 103 */
519 1, /* JAVA_IMUL 104 */
520 1, /* JAVA_LMUL 105 */
521 1, /* JAVA_FMUL 106 */
522 1, /* JAVA_DMUL 107 */
523 1, /* JAVA_IDIV 108 */
524 1, /* JAVA_LDIV 109 */
525 1, /* JAVA_FDIV 110 */
526 1, /* JAVA_DDIV 111 */
527 1, /* JAVA_IREM 112 */
528 1, /* JAVA_LREM 113 */
529 1, /* JAVA_FREM 114 */
530 1, /* JAVA_DREM 115 */
531 1, /* JAVA_INEG 116 */
532 1, /* JAVA_LNEG 117 */
533 1, /* JAVA_FNEG 118 */
534 1, /* JAVA_DNEG 119 */
535 1, /* JAVA_ISHL 120 */
536 1, /* JAVA_LSHL 121 */
537 1, /* JAVA_ISHR 122 */
538 1, /* JAVA_LSHR 123 */
539 1, /* JAVA_IUSHR 124 */
540 1, /* JAVA_LUSHR 125 */
541 1, /* JAVA_IAND 126 */
542 1, /* JAVA_LAND 127 */
543 1, /* JAVA_IOR 128 */
544 1, /* JAVA_LOR 129 */
545 1, /* JAVA_IXOR 130 */
546 1, /* JAVA_LXOR 131 */
547 3, /* JAVA_IINC 132 */
548 1, /* JAVA_I2L 133 */
549 1, /* JAVA_I2F 134 */
550 1, /* JAVA_I2D 135 */
551 1, /* JAVA_L2I 136 */
552 1, /* JAVA_L2F 137 */
553 1, /* JAVA_L2D 138 */
554 1, /* JAVA_F2I 139 */
555 1, /* JAVA_F2L 140 */
556 1, /* JAVA_F2D 141 */
557 1, /* JAVA_D2I 142 */
558 1, /* JAVA_D2L 143 */
559 1, /* JAVA_D2F 144 */
560 1, /* JAVA_INT2BYTE 145 */
561 1, /* JAVA_INT2CHAR 146 */
562 1, /* JAVA_INT2SHORT 147 */
563 1, /* JAVA_LCMP 148 */
564 1, /* JAVA_FCMPL 149 */
565 1, /* JAVA_FCMPG 150 */
566 1, /* JAVA_DCMPL 151 */
567 1, /* JAVA_DCMPG 152 */
568 3, /* JAVA_IFEQ 153 */
569 3, /* JAVA_IFNE 154 */
570 3, /* JAVA_IFLT 155 */
571 3, /* JAVA_IFGE 156 */
572 3, /* JAVA_IFGT 157 */
573 3, /* JAVA_IFLE 158 */
574 3, /* JAVA_IF_ICMPEQ 159 */
575 3, /* JAVA_IF_ICMPNE 160 */
576 3, /* JAVA_IF_ICMPLT 161 */
577 3, /* JAVA_IF_ICMPGE 162 */
578 3, /* JAVA_IF_ICMPGT 163 */
579 3, /* JAVA_IF_ICMPLE 164 */
580 3, /* JAVA_IF_ACMPEQ 165 */
581 3, /* JAVA_IF_ACMPNE 166 */
582 3, /* JAVA_GOTO 167 */
583 3, /* JAVA_JSR 168 */
584 2, /* JAVA_RET 169 */
585 0, /* JAVA_TABLESWITCH 170 */ /* variable length */
586 0, /* JAVA_LOOKUPSWITCH 171 */ /* variable length */
587 1, /* JAVA_IRETURN 172 */
588 1, /* JAVA_LRETURN 173 */
589 1, /* JAVA_FRETURN 174 */
590 1, /* JAVA_DRETURN 175 */
591 1, /* JAVA_ARETURN 176 */
592 1, /* JAVA_RETURN 177 */
593 3, /* JAVA_GETSTATIC 178 */
594 3, /* JAVA_PUTSTATIC 179 */
595 3, /* JAVA_GETFIELD 180 */
596 3, /* JAVA_PUTFIELD 181 */
597 3, /* JAVA_INVOKEVIRTUAL 182 */
598 3, /* JAVA_INVOKESPECIAL 183 */
599 3, /* JAVA_INVOKESTATIC 184 */
600 5, /* JAVA_INVOKEINTERFACE 185 */
602 3, /* JAVA_NEW 187 */
603 2, /* JAVA_NEWARRAY 188 */
604 3, /* JAVA_ANEWARRAY 189 */
605 1, /* JAVA_ARRAYLENGTH 190 */
606 1, /* JAVA_ATHROW 191 */
607 3, /* JAVA_CHECKCAST 192 */
608 3, /* JAVA_INSTANCEOF 193 */
609 1, /* JAVA_MONITORENTER 194 */
610 1, /* JAVA_MONITOREXIT 195 */
611 0, /* JAVA_WIDE 196 */ /* variable length */
612 4, /* JAVA_MULTIANEWARRAY 197 */
613 3, /* JAVA_IFNULL 198 */
614 3, /* JAVA_IFNONNULL 199 */
615 5, /* JAVA_GOTO_W 200 */
616 5, /* JAVA_JSR_W 201 */
617 1, /* JAVA_BREAKPOINT 202 */
654 1,1,1,1,1,1,1,1,1,1,
659 /* Java opcode names *********************************************************/
661 char *opcode_names[256] = {
664 "ICONST_M1 ", /* ICONST_M1 2 */
665 "ICONST_0 ", /* ICONST_0 3 */
666 "ICONST_1 ", /* ICONST_1 4 */
667 "ICONST_2 ", /* ICONST_2 5 */
668 "ICONST_3 ", /* ICONST_3 6 */
669 "ICONST_4 ", /* ICONST_4 7 */
670 "ICONST_5 ", /* ICONST_5 8 */
671 "LCONST_0 ", /* LCONST_0 9 */
672 "LCONST_1 ", /* LCONST_1 10 */
673 "FCONST_0 ", /* FCONST_0 11 */
674 "FCONST_1 ", /* FCONST_1 12 */
675 "FCONST_2 ", /* FCONST_2 13 */
676 "DCONST_0 ", /* DCONST_0 14 */
677 "DCONST_1 ", /* DCONST_1 15 */
678 "BIPUSH ", /* BIPUSH 16 */
679 "SIPUSH ", /* SIPUSH 17 */
681 "LDC_W ", /* LDC_W 19 */
682 "LDC2_W ", /* LDC2_W 20 */
688 "ILOAD_0 ", /* ILOAD_0 26 */
689 "ILOAD_1 ", /* ILOAD_1 27 */
690 "ILOAD_2 ", /* ILOAD_2 28 */
691 "ILOAD_3 ", /* ILOAD_3 29 */
692 "LLOAD_0 ", /* LLOAD_0 30 */
693 "LLOAD_1 ", /* LLOAD_1 31 */
694 "LLOAD_2 ", /* LLOAD_2 32 */
695 "LLOAD_3 ", /* LLOAD_3 33 */
696 "FLOAD_0 ", /* FLOAD_0 34 */
697 "FLOAD_1 ", /* FLOAD_1 35 */
698 "FLOAD_2 ", /* FLOAD_2 36 */
699 "FLOAD_3 ", /* FLOAD_3 37 */
700 "DLOAD_0 ", /* DLOAD_0 38 */
701 "DLOAD_1 ", /* DLOAD_1 39 */
702 "DLOAD_2 ", /* DLOAD_2 40 */
703 "DLOAD_3 ", /* DLOAD_3 41 */
704 "ALOAD_0 ", /* ALOAD_0 42 */
705 "ALOAD_1 ", /* ALOAD_1 43 */
706 "ALOAD_2 ", /* ALOAD_2 44 */
707 "ALOAD_3 ", /* ALOAD_3 45 */
721 "ISTORE_0 ", /* ISTORE_0 59 */
722 "ISTORE_1 ", /* ISTORE_1 60 */
723 "ISTORE_2 ", /* ISTORE_2 61 */
724 "ISTORE_3 ", /* ISTORE_3 62 */
725 "LSTORE_0 ", /* LSTORE_0 63 */
726 "LSTORE_1 ", /* LSTORE_1 64 */
727 "LSTORE_2 ", /* LSTORE_2 65 */
728 "LSTORE_3 ", /* LSTORE_3 66 */
729 "FSTORE_0 ", /* FSTORE_0 67 */
730 "FSTORE_1 ", /* FSTORE_1 68 */
731 "FSTORE_2 ", /* FSTORE_2 69 */
732 "FSTORE_3 ", /* FSTORE_3 70 */
733 "DSTORE_0 ", /* DSTORE_0 71 */
734 "DSTORE_1 ", /* DSTORE_1 72 */
735 "DSTORE_2 ", /* DSTORE_2 73 */
736 "DSTORE_3 ", /* DSTORE_3 74 */
737 "ASTORE_0 ", /* ASTORE_0 75 */
738 "ASTORE_1 ", /* ASTORE_1 76 */
739 "ASTORE_2 ", /* ASTORE_2 77 */
740 "ASTORE_3 ", /* ASTORE_3 78 */
807 "INT2BYTE ", /* 145 */
808 "INT2CHAR ", /* 146 */
809 "INT2SHORT ", /* 147 */
821 "IF_ICMPEQ ", /* 159 */
822 "IF_ICMPNE ", /* 160 */
823 "IF_ICMPLT ", /* 161 */
824 "IF_ICMPGE ", /* 162 */
825 "IF_ICMPGT ", /* 163 */
826 "IF_ICMPLE ", /* 164 */
827 "IF_ACMPEQ ", /* 165 */
828 "IF_ACMPNE ", /* 166 */
832 "TABLESWITCH ", /* 170 */
833 "LOOKUPSWITCH ", /* 171 */
834 "IRETURN ", /* 172 */
835 "LRETURN ", /* 173 */
836 "FRETURN ", /* 174 */
837 "DRETURN ", /* 175 */
838 "ARETURN ", /* 176 */
840 "GETSTATIC ", /* 178 */
841 "PUTSTATIC ", /* 179 */
842 "GETFIELD ", /* 180 */
843 "PUTFIELD ", /* 181 */
844 "INVOKEVIRTUAL ", /* 182 */
845 "INVOKESPECIAL ", /* 183 */
846 "INVOKESTATIC ", /* 184 */
847 "INVOKEINTERFACE", /* 185 */
848 "UNDEF186 ", /* 186 */
850 "NEWARRAY ", /* 188 */
851 "ANEWARRAY ", /* 189 */
852 "ARRAYLENGTH ", /* 190 */
854 "CHECKCAST ", /* 192 */
855 "INSTANCEOF ", /* 193 */
856 "MONITORENTER ", /* 194 */
857 "MONITOREXIT ", /* 195 */
858 "WIDE ", /* WIDE 196 */
859 "MULTIANEWARRAY ", /* 197 */
861 "IFNONNULL ", /* 199 */
862 "GOTO_W ", /* GOTO_W 200 */
863 "JSR_W ", /* JSR_W 201 */
864 "BREAKPOINT ", /* BREAKPOINT 202 */
866 "UNDEF203", "UNDEF204", "UNDEF205",
867 "UNDEF206", "UNDEF207", "UNDEF208", "UNDEF209", "UNDEF210",
868 "UNDEF211", "UNDEF212", "UNDEF213", "UNDEF214", "UNDEF215",
869 "UNDEF216", "UNDEF217", "UNDEF218", "UNDEF219", "UNDEF220",
870 "UNDEF221", "UNDEF222", "UNDEF223", "UNDEF224", "UNDEF225",
871 "UNDEF226", "UNDEF227", "UNDEF228", "UNDEF229", "UNDEF230",
872 "UNDEF231", "UNDEF232", "UNDEF233", "UNDEF234", "UNDEF235",
873 "UNDEF236", "UNDEF237", "UNDEF238", "UNDEF239", "UNDEF240",
874 "UNDEF241", "UNDEF242", "UNDEF243", "UNDEF244", "UNDEF245",
875 "UNDEF246", "UNDEF247", "UNDEF248", "UNDEF249", "UNDEF250",
876 "UNDEF251", "UNDEF252", "UNDEF253", "UNDEF254", "UNDEF255"
880 /* jit_init ********************************************************************
882 Initializes the JIT subsystem.
884 *******************************************************************************/
888 #if defined(ENABLE_JIT)
889 /* initialize stack analysis subsystem */
894 /* initialize show subsystem */
900 /* initialize codegen subsystem */
904 /* initialize code subsystem */
910 /* jit_close *******************************************************************
912 Close the JIT subsystem.
914 *******************************************************************************/
922 /* dummy function, used when there is no JavaVM code available */
924 static u1 *do_nothing_function(void)
930 /* jit_jitdata_new *************************************************************
932 Allocates and initalizes a new jitdata structure.
934 *******************************************************************************/
936 jitdata *jit_jitdata_new(methodinfo *m)
940 /* allocate jitdata structure and fill it */
945 jd->cd = DNEW(codegendata);
946 jd->rd = DNEW(registerdata);
947 #if defined(ENABLE_LOOP)
948 jd->ld = DNEW(loopdata);
951 /* Allocate codeinfo memory from the heap as we need to keep them. */
953 jd->code = code_codeinfo_new(m);
955 /* initialize variables */
958 jd->exceptiontable = NULL;
959 jd->exceptiontablelength = 0;
961 jd->branchtoentry = false;
962 jd->branchtoend = false;
964 jd->returnblock = NULL;
965 jd->maxlocals = m->maxlocals;
967 #if defined(ENABLE_THREADS)
968 if (checksync && (m->flags & ACC_SYNCHRONIZED))
969 jd->isleafmethod = false;
972 jd->isleafmethod = true;
978 /* jit_compile *****************************************************************
980 Translates one method to machine code.
982 *******************************************************************************/
984 static u1 *jit_compile_intern(jitdata *jd);
986 u1 *jit_compile(methodinfo *m)
992 STATISTICS(count_jit_calls++);
994 /* Initialize the static function's class. */
996 /* ATTENTION: This MUST be done before the method lock is aquired,
997 otherwise we could run into a deadlock with <clinit>'s that
998 call static methods of it's own class. */
1000 if ((m->flags & ACC_STATIC) && !(m->class->state & CLASS_INITIALIZED)) {
1001 #if !defined(NDEBUG)
1003 log_message_class("Initialize class ", m->class);
1006 if (!initialize_class(m->class))
1009 /* check if the method has been compiled during initialization */
1011 if ((m->code != NULL) && (m->code->entrypoint != NULL))
1012 return m->code->entrypoint;
1015 /* enter a monitor on the method */
1017 LOCK_MONITOR_ENTER(m);
1019 /* if method has been already compiled return immediately */
1021 if (m->code != NULL) {
1022 LOCK_MONITOR_EXIT(m);
1024 assert(m->code->entrypoint);
1025 return m->code->entrypoint;
1028 STATISTICS(count_methods++);
1030 #if defined(ENABLE_STATISTICS)
1033 if (opt_getcompilingtime)
1034 compilingtime_start();
1037 /* mark start of dump memory area */
1039 dumpsize = dump_size();
1041 /* create jitdata structure */
1043 jd = jit_jitdata_new(m);
1045 /* set the flags for the current JIT run */
1047 jd->flags = JITDATA_FLAG_PARSE;
1049 #if defined(ENABLE_VERIFIER)
1051 jd->flags |= JITDATA_FLAG_VERIFY;
1054 #if defined(ENABLE_PROFILING)
1056 jd->flags |= JITDATA_FLAG_INSTRUMENT;
1059 #if defined(ENABLE_IFCONV)
1061 jd->flags |= JITDATA_FLAG_IFCONV;
1064 #if defined(ENABLE_INLINING) && defined(ENABLE_INLINING_DEBUG)
1065 if (opt_inlining && opt_inline_debug_all)
1066 jd->flags |= JITDATA_FLAG_INLINE;
1069 if (opt_showintermediate)
1070 jd->flags |= JITDATA_FLAG_SHOWINTERMEDIATE;
1072 if (opt_showdisassemble)
1073 jd->flags |= JITDATA_FLAG_SHOWDISASSEMBLE;
1075 if (opt_verbosecall)
1076 jd->flags |= JITDATA_FLAG_VERBOSECALL;
1078 #if defined(ENABLE_REPLACEMENT) && defined(ENABLE_INLINING)
1080 jd->flags |= JITDATA_FLAG_COUNTDOWN;
1083 #if defined(ENABLE_JIT)
1084 # if defined(ENABLE_INTRP)
1087 /* initialize the register allocator */
1093 /* setup the codegendata memory */
1097 /* now call internal compile function */
1099 r = jit_compile_intern(jd);
1102 /* We had an exception! Finish stuff here if necessary. */
1104 /* release codeinfo */
1106 code_codeinfo_free(jd->code);
1108 #if defined(ENABLE_PROFILING)
1109 /* Release memory for basic block profiling information. */
1111 if (JITDATA_HAS_FLAG_INSTRUMENT(jd))
1112 if (jd->code->bbfrequency != NULL)
1113 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 LOCK_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) ? m->code->optlevel : 0;
1159 if (optlevel == 1) {
1160 /* log_message_method("not recompiling: ", m); */
1165 DEBUG_JIT_COMPILEVERBOSE("Recompiling start: ");
1167 STATISTICS(count_jit_calls++);
1169 #if defined(ENABLE_STATISTICS)
1172 if (opt_getcompilingtime)
1173 compilingtime_start();
1176 /* mark start of dump memory area */
1178 dumpsize = dump_size();
1180 /* create jitdata structure */
1182 jd = jit_jitdata_new(m);
1184 /* set the current optimization level to the previous one plus 1 */
1186 jd->code->optlevel = optlevel + 1;
1188 /* get the optimization flags for the current JIT run */
1190 #if defined(ENABLE_VERIFIER)
1191 jd->flags |= JITDATA_FLAG_VERIFY;
1194 /* jd->flags |= JITDATA_FLAG_REORDER; */
1195 if (opt_showintermediate)
1196 jd->flags |= JITDATA_FLAG_SHOWINTERMEDIATE;
1197 if (opt_showdisassemble)
1198 jd->flags |= JITDATA_FLAG_SHOWDISASSEMBLE;
1199 if (opt_verbosecall)
1200 jd->flags |= JITDATA_FLAG_VERBOSECALL;
1202 #if defined(ENABLE_INLINING)
1204 jd->flags |= JITDATA_FLAG_INLINE;
1207 #if defined(ENABLE_JIT)
1208 # if defined(ENABLE_INTRP)
1211 /* initialize the register allocator */
1216 /* setup the codegendata memory */
1220 /* now call internal compile function */
1222 r = jit_compile_intern(jd);
1225 /* We had an exception! Finish stuff here if necessary. */
1227 /* release codeinfo */
1229 code_codeinfo_free(jd->code);
1232 /* release dump area */
1234 dump_release(dumpsize);
1236 #if defined(ENABLE_STATISTICS)
1239 if (opt_getcompilingtime)
1240 compilingtime_stop();
1243 DEBUG_JIT_COMPILEVERBOSE("Recompiling done: ");
1245 /* return pointer to the methods entry point */
1251 /* jit_compile_intern **********************************************************
1253 Static internal function which does the actual compilation.
1255 *******************************************************************************/
1257 static u1 *jit_compile_intern(jitdata *jd)
1263 #if defined(ENABLE_RT_TIMING)
1264 struct timespec time_start,time_checks,time_parse,time_stack,
1265 time_typecheck,time_loop,time_ifconv,time_alloc,
1269 RT_TIMING_GET_TIME(time_start);
1271 /* get required compiler data */
1273 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1280 /* print log message for compiled method */
1282 DEBUG_JIT_COMPILEVERBOSE("Compiling: ");
1284 #if defined(ENABLE_DEBUG_FILTER)
1285 show_filters_apply(jd->m);
1288 /* handle native methods and create a native stub */
1290 if (m->flags & ACC_NATIVE) {
1293 #if defined(WITH_STATIC_CLASSPATH)
1294 f = native_findfunction(m->class->name, m->name, m->descriptor,
1295 (m->flags & ACC_STATIC));
1302 code = codegen_generate_stub_native(m, f);
1304 assert(!m->code); /* native methods are never recompiled */
1307 return code->entrypoint;
1310 /* if there is no javacode, print error message and return empty method */
1312 if (m->jcode == NULL) {
1313 DEBUG_JIT_COMPILEVERBOSE("No code given for: ");
1315 code->entrypoint = (u1 *) (ptrint) do_nothing_function;
1318 return code->entrypoint; /* return empty method */
1321 #if defined(ENABLE_STATISTICS)
1323 count_javacodesize += m->jcodelength + 18;
1324 count_tryblocks += jd->exceptiontablelength;
1325 count_javaexcsize += jd->exceptiontablelength * SIZEOF_VOID_P;
1329 RT_TIMING_GET_TIME(time_checks);
1331 /* call the compiler passes ***********************************************/
1333 DEBUG_JIT_COMPILEVERBOSE("Parsing: ");
1335 /* call parse pass */
1338 DEBUG_JIT_COMPILEVERBOSE("Exception while parsing: ");
1342 RT_TIMING_GET_TIME(time_parse);
1344 DEBUG_JIT_COMPILEVERBOSE("Parsing done: ");
1346 #if defined(ENABLE_JIT)
1347 # if defined(ENABLE_INTRP)
1350 DEBUG_JIT_COMPILEVERBOSE("Analysing: ");
1352 /* call stack analysis pass */
1354 if (!stack_analyse(jd)) {
1355 DEBUG_JIT_COMPILEVERBOSE("Exception while analysing: ");
1359 RT_TIMING_GET_TIME(time_stack);
1361 DEBUG_JIT_COMPILEVERBOSE("Analysing done: ");
1363 /* Build the CFG. This has to be done after stack_analyse, as
1364 there happens the JSR elimination. */
1369 #ifdef ENABLE_VERIFIER
1370 if (JITDATA_HAS_FLAG_VERIFY(jd)) {
1371 DEBUG_JIT_COMPILEVERBOSE("Typechecking: ");
1373 /* call typecheck pass */
1374 if (!typecheck(jd)) {
1375 DEBUG_JIT_COMPILEVERBOSE("Exception while typechecking: ");
1380 DEBUG_JIT_COMPILEVERBOSE("Typechecking done: ");
1383 RT_TIMING_GET_TIME(time_typecheck);
1385 #if defined(ENABLE_LOOP)
1390 jit_renumber_basicblocks(jd);
1393 RT_TIMING_GET_TIME(time_loop);
1395 #if defined(ENABLE_IFCONV)
1396 if (JITDATA_HAS_FLAG_IFCONV(jd)) {
1397 if (!ifconv_static(jd))
1399 jit_renumber_basicblocks(jd);
1402 RT_TIMING_GET_TIME(time_ifconv);
1406 #if defined(ENABLE_INLINING)
1407 if (JITDATA_HAS_FLAG_INLINE(jd)) {
1408 if (!inline_inline(jd))
1413 #if defined(ENABLE_PROFILING)
1414 /* Basic block reordering. I think this should be done after
1415 if-conversion, as we could lose the ability to do the
1418 if (JITDATA_HAS_FLAG_REORDER(jd)) {
1421 jit_renumber_basicblocks(jd);
1425 DEBUG_JIT_COMPILEVERBOSE("Allocating registers: ");
1427 #if defined(ENABLE_LSRA) && !defined(ENABLE_SSA)
1428 /* allocate registers */
1433 STATISTICS(count_methods_allocated_by_lsra++);
1436 # endif /* defined(ENABLE_LSRA) && !defined(ENABLE_SSA) */
1437 #if defined(ENABLE_SSA)
1438 /* allocate registers */
1439 if ((opt_lsra) && (jd->exceptiontablelength == 0)) {
1440 jd->ls = DNEW(lsradata);
1443 STATISTICS(count_methods_allocated_by_lsra++);
1446 # endif /* defined(ENABLE_SSA) */
1448 STATISTICS(count_locals_conflicts += (jd->maxlocals - 1) * (jd->maxlocals));
1453 STATISTICS(simplereg_make_statistics(jd));
1455 DEBUG_JIT_COMPILEVERBOSE("Allocating registers done: ");
1456 # if defined(ENABLE_INTRP)
1459 #endif /* defined(ENABLE_JIT) */
1460 RT_TIMING_GET_TIME(time_alloc);
1462 #if defined(ENABLE_PROFILING)
1463 /* Allocate memory for basic block profiling information. This
1464 _must_ be done after loop optimization and register allocation,
1465 since they can change the basic block count. */
1467 if (JITDATA_HAS_FLAG_INSTRUMENT(jd))
1468 code->bbfrequency = MNEW(u4, jd->basicblockcount);
1471 DEBUG_JIT_COMPILEVERBOSE("Generating code: ");
1473 /* now generate the machine code */
1475 #if defined(ENABLE_JIT)
1476 # if defined(ENABLE_INTRP)
1478 #if defined(ENABLE_VERIFIER)
1480 DEBUG_JIT_COMPILEVERBOSE("Typechecking (stackbased): ");
1482 if (!typecheck_stackbased(jd)) {
1483 DEBUG_JIT_COMPILEVERBOSE("Exception while typechecking (stackbased): ");
1488 if (!intrp_codegen(jd)) {
1489 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1496 if (!codegen_generate(jd)) {
1497 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1503 if (!intrp_codegen(jd)) {
1504 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1509 RT_TIMING_GET_TIME(time_codegen);
1511 DEBUG_JIT_COMPILEVERBOSE("Generating code done: ");
1513 #if !defined(NDEBUG)
1514 #if defined(ENABLE_DEBUG_FILTER)
1515 if (jd->m->filtermatches & SHOW_FILTER_FLAG_SHOW_METHOD)
1518 /* intermediate and assembly code listings */
1520 if (JITDATA_HAS_FLAG_SHOWINTERMEDIATE(jd)) {
1521 show_method(jd, SHOW_CODE);
1523 else if (JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd)) {
1524 # if defined(ENABLE_DISASSEMBLER)
1525 DISASSEMBLE(code->entrypoint,
1526 code->entrypoint + (code->mcodelength - cd->dseglen));
1530 if (opt_showddatasegment)
1535 DEBUG_JIT_COMPILEVERBOSE("Compiling done: ");
1537 /* switch to the newly generated code */
1540 assert(code->entrypoint);
1542 /* add the current compile version to the methodinfo */
1544 code->prev = m->code;
1547 RT_TIMING_TIME_DIFF(time_start,time_checks,RT_TIMING_JIT_CHECKS);
1548 RT_TIMING_TIME_DIFF(time_checks,time_parse,RT_TIMING_JIT_PARSE);
1549 RT_TIMING_TIME_DIFF(time_parse,time_stack,RT_TIMING_JIT_STACK);
1550 RT_TIMING_TIME_DIFF(time_stack,time_typecheck,RT_TIMING_JIT_TYPECHECK);
1551 RT_TIMING_TIME_DIFF(time_typecheck,time_loop,RT_TIMING_JIT_LOOP);
1552 RT_TIMING_TIME_DIFF(time_loop,time_alloc,RT_TIMING_JIT_ALLOC);
1553 RT_TIMING_TIME_DIFF(time_alloc,time_codegen,RT_TIMING_JIT_CODEGEN);
1554 RT_TIMING_TIME_DIFF(time_start,time_codegen,RT_TIMING_JIT_TOTAL);
1556 /* return pointer to the methods entry point */
1558 return code->entrypoint;
1562 /* jit_invalidate_code *********************************************************
1564 Mark the compiled code of the given method as invalid and take care that
1565 it is replaced if necessary.
1567 XXX Not fully implemented, yet.
1569 *******************************************************************************/
1571 void jit_invalidate_code(methodinfo *m)
1576 if (code == NULL || CODE_IS_INVALID(code))
1579 CODE_SETFLAG_INVALID(code);
1581 /* activate mappable replacement points */
1583 #if defined(ENABLE_REPLACEMENT)
1584 replace_activate_replacement_points(code, true);
1586 vm_abort("invalidating code only works with ENABLE_REPLACEMENT");
1591 /* jit_request_optimization ****************************************************
1593 Request optimization of the given method. If the code of the method is
1594 unoptimized, it will be invalidated, so the next jit_get_current_code(m)
1595 triggers an optimized recompilation.
1596 If the method is already optimized, this function does nothing.
1599 m................the method
1601 *******************************************************************************/
1603 void jit_request_optimization(methodinfo *m)
1609 if (code && code->optlevel == 0)
1610 jit_invalidate_code(m);
1614 /* jit_get_current_code ********************************************************
1616 Get the currently valid code for the given method. If there is no valid
1617 code, (re)compile the method.
1620 m................the method
1623 the codeinfo* for the current code, or
1624 NULL if an exception has been thrown during recompilation.
1626 *******************************************************************************/
1628 codeinfo *jit_get_current_code(methodinfo *m)
1632 /* if we have valid code, return it */
1634 if (m->code && CODE_IS_VALID(m->code))
1637 /* otherwise: recompile */
1639 if (!jit_recompile(m))
1648 /* jit_asm_compile *************************************************************
1650 This method is called from asm_vm_call_method and does:
1652 - create stackframe info for exceptions
1653 - compile the method
1654 - patch the entrypoint of the method into the calculated address in
1656 - flushes the instruction cache.
1658 *******************************************************************************/
1660 #if defined(ENABLE_JIT)
1661 u1 *jit_asm_compile(methodinfo *m, u1 *mptr, u1 *sp, u1 *ra)
1668 /* create the stackframeinfo (subtract 1 from RA as it points to the */
1669 /* instruction after the call) */
1671 stacktrace_create_extern_stackframeinfo(&sfi, NULL, sp, ra, ra-1);
1673 /* actually compile the method */
1675 entrypoint = jit_compile(m);
1677 /* remove the stackframeinfo */
1679 stacktrace_remove_stackframeinfo(&sfi);
1681 /* there was a problem during compilation */
1683 if (entrypoint == NULL)
1686 /* get the method patch address */
1688 pa = md_get_method_patch_address(ra, &sfi, mptr);
1690 /* patch the method entry point */
1694 *p = (ptrint) entrypoint;
1696 /* flush the instruction cache */
1698 md_icacheflush(pa, SIZEOF_VOID_P);
1702 #endif /* defined(ENABLE_JIT) */
1705 /* jit_complement_condition ****************************************************
1707 Returns the complement of the passed conditional instruction.
1709 We use the order of the different conditions, e.g.:
1714 If the passed opcode is odd, we simply add 1 to get the complement.
1715 If the opcode is even, we subtract 1.
1722 *******************************************************************************/
1724 s4 jit_complement_condition(s4 opcode)
1728 return ICMD_IFNONNULL;
1730 case ICMD_IFNONNULL:
1734 /* check if opcode is odd */
1744 /* jit_renumber_basicblocks ****************************************************
1746 Set the ->nr of all blocks so it increases when traversing ->next.
1749 jitdata..........the current jitdata
1751 *******************************************************************************/
1753 void jit_renumber_basicblocks(jitdata *jd)
1759 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
1763 /* we have one block more than jd->basicblockcount (the end marker) */
1765 assert(nr == jd->basicblockcount + 1);
1769 /* jit_check_basicblock_numbers ************************************************
1771 Assert that the ->nr of the first block is zero and increases by 1 each
1772 time ->next is traversed.
1773 This function should be called before any analysis that relies on
1774 the basicblock numbers.
1777 jitdata..........the current jitdata
1779 NOTE: Aborts with an assertion if the condition is not met!
1781 *******************************************************************************/
1783 #if !defined(NDEBUG)
1784 void jit_check_basicblock_numbers(jitdata *jd)
1790 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
1791 assert(bptr->nr == nr);
1795 /* we have one block more than jd->basicblockcount (the end marker) */
1797 assert(nr == jd->basicblockcount + 1);
1799 #endif /* !defined(NDEBUG) */
1803 * These are local overrides for various environment variables in Emacs.
1804 * Please do not remove this and leave it at the end of the file, where
1805 * Emacs will automagically detect them.
1806 * ---------------------------------------------------------------------
1809 * indent-tabs-mode: t
1813 * vim:noexpandtab:sw=4:ts=4: