1 /* src/vm/jit/jit.c - calls the code generation functions
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zu Foerderung der freien virtuellen Machine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
35 #include "mm/memory.h"
37 #include "native/native.h"
39 #include "toolbox/logging.h"
41 #include "threads/lock-common.h"
42 #include "threads/threads-common.h"
44 #include "vm/global.h"
45 #include "vm/initialize.h"
47 #include "vm/jit/asmpart.h"
49 #include "vm/jit/cfg.h"
51 #include "vm/jit/codegen-common.h"
52 #include "vm/jit/disass.h"
53 #include "vm/jit/dseg.h"
54 #include "vm/jit/jit.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"
66 #if defined(ENABLE_SSA)
67 # include "vm/jit/optimizing/lsra.h"
68 # include "vm/jit/optimizing/ssa.h"
71 #if defined(ENABLE_INLINING)
72 # include "vm/jit/inline/inline.h"
75 #include "vm/jit/ir/bytecode.h"
77 #include "vm/jit/loop/analyze.h"
78 #include "vm/jit/loop/graph.h"
79 #include "vm/jit/loop/loop.h"
81 #if defined(ENABLE_IFCONV)
82 # include "vm/jit/optimizing/ifconv.h"
85 #include "vm/jit/optimizing/reorder.h"
87 #if defined(ENABLE_PYTHON)
88 # include "vm/jit/python.h"
91 #include "vm/jit/verify/typecheck.h"
93 #include "vmcore/class.h"
94 #include "vmcore/loader.h"
95 #include "vmcore/method.h"
96 #include "vmcore/options.h"
97 #include "vmcore/rt-timing.h"
98 #include "vmcore/statistics.h"
101 /* debug macros ***************************************************************/
104 #define DEBUG_JIT_COMPILEVERBOSE(x) \
106 if (compileverbose) { \
107 log_message_method(x, m); \
111 #define DEBUG_JIT_COMPILEVERBOSE(x) /* nothing */
115 # define TRACECOMPILERCALLS() \
117 if (opt_TraceCompilerCalls) { \
119 log_print("[JIT compiler started: method="); \
126 # define TRACECOMPILERCALLS()
130 /* the ICMD table ************************************************************/
133 #define N(name) name,
138 /* abbreviations for flags */
140 #define PEI ICMDTABLE_PEI
141 #define CALLS ICMDTABLE_CALLS
143 /* some machine dependent values */
148 #define IDIV_CALLS ICMDTABLE_CALLS
151 #if (SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
154 #define LDIV_CALLS ICMDTABLE_CALLS
157 /* include the actual table */
159 icmdtable_entry_t icmd_table[256] = {
160 #include <vm/jit/icmdtable.inc>
167 /* XXX hack until the old "PEI" definition is removed */
171 /* stackelement requirements of Java opcodes **********************************/
173 int stackreq[256] = {
175 1, /* JAVA_ACONST 1 */
176 1, /* JAVA_ICONST_M1 2 */
177 1, /* JAVA_ICONST_0 3 */
178 1, /* JAVA_ICONST_1 4 */
179 1, /* JAVA_ICONST_2 5 */
180 1, /* JAVA_ICONST_3 6 */
181 1, /* JAVA_ICONST_4 7 */
182 1, /* JAVA_ICONST_5 8 */
183 1, /* JAVA_LCONST_0 9 */
184 1, /* JAVA_LCONST_1 10 */
185 1, /* JAVA_FCONST_0 11 */
186 1, /* JAVA_FCONST_1 12 */
187 1, /* JAVA_FCONST_2 13 */
188 1, /* JAVA_DCONST_0 14 */
189 1, /* JAVA_DCONST_1 15 */
190 1, /* JAVA_BIPUSH 16 */
191 1, /* JAVA_SIPUSH 17 */
193 1, /* JAVA_LDC_W 19 */
194 1, /* JAVA_LDC2_W 20 */
195 1, /* JAVA_ILOAD 21 */
196 1, /* JAVA_LLOAD 22 */
197 1, /* JAVA_FLOAD 23 */
198 1, /* JAVA_DLOAD 24 */
199 1, /* JAVA_ALOAD 25 */
200 1, /* JAVA_ILOAD_0 26 */
201 1, /* JAVA_ILOAD_1 27 */
202 1, /* JAVA_ILOAD_2 28 */
203 1, /* JAVA_ILOAD_3 29 */
204 1, /* JAVA_LLOAD_0 30 */
205 1, /* JAVA_LLOAD_1 31 */
206 1, /* JAVA_LLOAD_2 32 */
207 1, /* JAVA_LLOAD_3 33 */
208 1, /* JAVA_FLOAD_0 34 */
209 1, /* JAVA_FLOAD_1 35 */
210 1, /* JAVA_FLOAD_2 36 */
211 1, /* JAVA_FLOAD_3 37 */
212 1, /* JAVA_DLOAD_0 38 */
213 1, /* JAVA_DLOAD_1 39 */
214 1, /* JAVA_DLOAD_2 40 */
215 1, /* JAVA_DLOAD_3 41 */
216 1, /* JAVA_ALOAD_0 42 */
217 1, /* JAVA_ALOAD_1 43 */
218 1, /* JAVA_ALOAD_2 44 */
219 1, /* JAVA_ALOAD_3 45 */
220 1, /* JAVA_IALOAD 46 */
221 1, /* JAVA_LALOAD 47 */
222 1, /* JAVA_FALOAD 48 */
223 1, /* JAVA_DALOAD 49 */
224 1, /* JAVA_AALOAD 50 */
225 1, /* JAVA_BALOAD 51 */
226 1, /* JAVA_CALOAD 52 */
227 1, /* JAVA_SALOAD 53 */
228 0, /* JAVA_ISTORE 54 */
229 0, /* JAVA_LSTORE 55 */
230 0, /* JAVA_FSTORE 56 */
231 0, /* JAVA_DSTORE 57 */
232 0, /* JAVA_ASTORE 58 */
233 0, /* JAVA_ISTORE_0 59 */
234 0, /* JAVA_ISTORE_1 60 */
235 0, /* JAVA_ISTORE_2 61 */
236 0, /* JAVA_ISTORE_3 62 */
237 0, /* JAVA_LSTORE_0 63 */
238 0, /* JAVA_LSTORE_1 64 */
239 0, /* JAVA_LSTORE_2 65 */
240 0, /* JAVA_LSTORE_3 66 */
241 0, /* JAVA_FSTORE_0 67 */
242 0, /* JAVA_FSTORE_1 68 */
243 0, /* JAVA_FSTORE_2 69 */
244 0, /* JAVA_FSTORE_3 70 */
245 0, /* JAVA_DSTORE_0 71 */
246 0, /* JAVA_DSTORE_1 72 */
247 0, /* JAVA_DSTORE_2 73 */
248 0, /* JAVA_DSTORE_3 74 */
249 0, /* JAVA_ASTORE_0 75 */
250 0, /* JAVA_ASTORE_1 76 */
251 0, /* JAVA_ASTORE_2 77 */
252 0, /* JAVA_ASTORE_3 78 */
253 0, /* JAVA_IASTORE 79 */
254 0, /* JAVA_LASTORE 80 */
255 0, /* JAVA_FASTORE 81 */
256 0, /* JAVA_DASTORE 82 */
257 0, /* JAVA_AASTORE 83 */
258 0, /* JAVA_BASTORE 84 */
259 0, /* JAVA_CASTORE 85 */
260 0, /* JAVA_SASTORE 86 */
262 0, /* JAVA_POP2 88 */
264 1+3, /* JAVA_DUP_X1 90 */
265 2+4, /* JAVA_DUP_X2 91 */
266 2, /* JAVA_DUP2 92 */
267 2+5, /* JAVA_DUP2_X1 93 */
268 3+6, /* JAVA_DUP2_X2 94 */
269 1+2, /* JAVA_SWAP 95 */
270 1, /* JAVA_IADD 96 */
271 1, /* JAVA_LADD 97 */
272 1, /* JAVA_FADD 98 */
273 1, /* JAVA_DADD 99 */
274 1, /* JAVA_ISUB 100 */
275 1, /* JAVA_LSUB 101 */
276 1, /* JAVA_FSUB 102 */
277 1, /* JAVA_DSUB 103 */
278 1, /* JAVA_IMUL 104 */
279 1, /* JAVA_LMUL 105 */
280 1, /* JAVA_FMUL 106 */
281 1, /* JAVA_DMUL 107 */
282 1, /* JAVA_IDIV 108 */
283 1, /* JAVA_LDIV 109 */
284 1, /* JAVA_FDIV 110 */
285 1, /* JAVA_DDIV 111 */
286 1, /* JAVA_IREM 112 */
287 1, /* JAVA_LREM 113 */
288 1, /* JAVA_FREM 114 */
289 1, /* JAVA_DREM 115 */
290 1, /* JAVA_INEG 116 */
291 1, /* JAVA_LNEG 117 */
292 1, /* JAVA_FNEG 118 */
293 1, /* JAVA_DNEG 119 */
294 1, /* JAVA_ISHL 120 */
295 1, /* JAVA_LSHL 121 */
296 1, /* JAVA_ISHR 122 */
297 1, /* JAVA_LSHR 123 */
298 1, /* JAVA_IUSHR 124 */
299 1, /* JAVA_LUSHR 125 */
300 1, /* JAVA_IAND 126 */
301 1, /* JAVA_LAND 127 */
302 1, /* JAVA_IOR 128 */
303 1, /* JAVA_LOR 129 */
304 1, /* JAVA_IXOR 130 */
305 1, /* JAVA_LXOR 131 */
306 0, /* JAVA_IINC 132 */
307 1, /* JAVA_I2L 133 */
308 1, /* JAVA_I2F 134 */
309 1, /* JAVA_I2D 135 */
310 1, /* JAVA_L2I 136 */
311 1, /* JAVA_L2F 137 */
312 1, /* JAVA_L2D 138 */
313 1, /* JAVA_F2I 139 */
314 1, /* JAVA_F2L 140 */
315 1, /* JAVA_F2D 141 */
316 1, /* JAVA_D2I 142 */
317 1, /* JAVA_D2L 143 */
318 1, /* JAVA_D2F 144 */
319 1, /* JAVA_INT2BYTE 145 */
320 1, /* JAVA_INT2CHAR 146 */
321 1, /* JAVA_INT2SHORT 147 */
322 1, /* JAVA_LCMP 148 */
323 1, /* JAVA_FCMPL 149 */
324 1, /* JAVA_FCMPG 150 */
325 1, /* JAVA_DCMPL 151 */
326 1, /* JAVA_DCMPG 152 */
327 0, /* JAVA_IFEQ 153 */
328 0, /* JAVA_IFNE 154 */
329 0, /* JAVA_IFLT 155 */
330 0, /* JAVA_IFGE 156 */
331 0, /* JAVA_IFGT 157 */
332 0, /* JAVA_IFLE 158 */
333 0, /* JAVA_IF_ICMPEQ 159 */
334 0, /* JAVA_IF_ICMPNE 160 */
335 0, /* JAVA_IF_ICMPLT 161 */
336 0, /* JAVA_IF_ICMPGE 162 */
337 0, /* JAVA_IF_ICMPGT 163 */
338 0, /* JAVA_IF_ICMPLE 164 */
339 0, /* JAVA_IF_ACMPEQ 165 */
340 0, /* JAVA_IF_ACMPNE 166 */
341 0, /* JAVA_GOTO 167 */
342 1, /* JAVA_JSR 168 */
343 0, /* JAVA_RET 169 */
344 0, /* JAVA_TABLESWITCH 170 */
345 0, /* JAVA_LOOKUPSWITCH 171 */
346 0, /* JAVA_IRETURN 172 */
347 0, /* JAVA_LRETURN 173 */
348 0, /* JAVA_FRETURN 174 */
349 0, /* JAVA_DRETURN 175 */
350 0, /* JAVA_ARETURN 176 */
351 0, /* JAVA_RETURN 177 */
352 1, /* JAVA_GETSTATIC 178 */
353 0, /* JAVA_PUTSTATIC 179 */
354 1, /* JAVA_GETFIELD 180 */
355 0, /* JAVA_PUTFIELD 181 */
356 1, /* JAVA_INVOKEVIRTUAL 182 */
357 1, /* JAVA_INVOKESPECIAL 183 */
358 1, /* JAVA_INVOKESTATIC 184 */
359 1, /* JAVA_INVOKEINTERFACE 185 */
360 1, /* JAVA_UNDEF186 186 */
361 1, /* JAVA_NEW 187 */
362 1, /* JAVA_NEWARRAY 188 */
363 1, /* JAVA_ANEWARRAY 189 */
364 1, /* JAVA_ARRAYLENGTH 190 */
365 1, /* JAVA_ATHROW 191 */
366 1, /* JAVA_CHECKCAST 192 */
367 1, /* JAVA_INSTANCEOF 193 */
368 0, /* JAVA_MONITORENTER 194 */
369 0, /* JAVA_MONITOREXIT 195 */
370 0, /* JAVA_WIDE 196 */
371 1, /* JAVA_MULTIANEWARRAY 197 */
372 0, /* JAVA_IFNULL 198 */
373 0, /* JAVA_IFNONNULL 199 */
374 0, /* JAVA_GOTO_W 200 */
375 1, /* JAVA_JSR_W 201 */
376 0, /* JAVA_BREAKPOINT 202 */
377 1, /* JAVA_UNDEF203 203 */
378 1, /* JAVA_UNDEF204 204 */
379 1, /* JAVA_UNDEF205 205 */
380 1, /* JAVA_UNDEF206 206 */
381 1, /* JAVA_UNDEF207 207 */
382 1, /* JAVA_UNDEF208 208 */
383 1, /* JAVA_UNDEF209 209 */
384 1, /* JAVA_UNDEF210 210 */
385 1, /* JAVA_UNDEF211 211 */
386 1, /* JAVA_UNDEF212 212 */
387 1, /* JAVA_UNDEF213 213 */
388 1, /* JAVA_UNDEF214 214 */
389 1, /* JAVA_UNDEF215 215 */
390 1, /* JAVA_UNDEF216 216 */
391 1, /* JAVA_UNDEF217 217 */
392 1, /* JAVA_UNDEF218 218 */
393 1, /* JAVA_UNDEF219 219 */
394 1, /* JAVA_UNDEF220 220 */
395 1, /* JAVA_UNDEF221 221 */
396 1, /* JAVA_UNDEF222 222 */
397 1, /* JAVA_UNDEF223 223 */
398 1, /* JAVA_UNDEF224 224 */
399 1, /* JAVA_UNDEF225 225 */
400 1, /* JAVA_UNDEF226 226 */
401 1, /* JAVA_UNDEF227 227 */
402 1, /* JAVA_UNDEF228 228 */
403 1, /* JAVA_UNDEF229 229 */
404 1, /* JAVA_UNDEF230 230 */
405 1, /* JAVA_UNDEF231 231 */
406 1, /* JAVA_UNDEF232 232 */
407 1, /* JAVA_UNDEF233 233 */
408 1, /* JAVA_UNDEF234 234 */
409 1, /* JAVA_UNDEF235 235 */
410 1, /* JAVA_UNDEF236 236 */
411 1, /* JAVA_UNDEF237 237 */
412 1, /* JAVA_UNDEF238 238 */
413 1, /* JAVA_UNDEF239 239 */
414 1, /* JAVA_UNDEF240 240 */
415 1, /* JAVA_UNDEF241 241 */
416 1, /* JAVA_UNDEF242 242 */
417 1, /* JAVA_UNDEF243 243 */
418 1, /* JAVA_UNDEF244 244 */
419 1, /* JAVA_UNDEF245 245 */
420 1, /* JAVA_UNDEF246 246 */
421 1, /* JAVA_UNDEF247 247 */
422 1, /* JAVA_UNDEF248 248 */
423 1, /* JAVA_UNDEF249 249 */
424 1, /* JAVA_UNDEF250 250 */
425 1, /* JAVA_UNDEF251 251 */
426 1, /* JAVA_UNDEF252 252 */
427 1, /* JAVA_UNDEF253 253 */
428 1, /* JAVA_UNDEF254 254 */
429 1, /* JAVA_UNDEF255 255 */
433 /* size in bytes of Java opcodes **********************************************/
435 int jcommandsize[256] = {
438 1, /* JAVA_ACONST_NULL 1 */
439 1, /* JAVA_ICONST_M1 2 */
440 1, /* JAVA_ICONST_0 3 */
441 1, /* JAVA_ICONST_1 4 */
442 1, /* JAVA_ICONST_2 5 */
443 1, /* JAVA_ICONST_3 6 */
444 1, /* JAVA_ICONST_4 7 */
445 1, /* JAVA_ICONST_5 8 */
446 1, /* JAVA_LCONST_0 9 */
447 1, /* JAVA_LCONST_1 10 */
448 1, /* JAVA_FCONST_0 11 */
449 1, /* JAVA_FCONST_1 12 */
450 1, /* JAVA_FCONST_2 13 */
451 1, /* JAVA_DCONST_0 14 */
452 1, /* JAVA_DCONST_1 15 */
453 2, /* JAVA_BIPUSH 16 */
454 3, /* JAVA_SIPUSH 17 */
455 2, /* JAVA_LDC1 18 */
456 3, /* JAVA_LDC2 19 */
457 3, /* JAVA_LDC2W 20 */
458 2, /* JAVA_ILOAD 21 */
459 2, /* JAVA_LLOAD 22 */
460 2, /* JAVA_FLOAD 23 */
461 2, /* JAVA_DLOAD 24 */
462 2, /* JAVA_ALOAD 25 */
463 1, /* JAVA_ILOAD_0 26 */
464 1, /* JAVA_ILOAD_1 27 */
465 1, /* JAVA_ILOAD_2 28 */
466 1, /* JAVA_ILOAD_3 29 */
467 1, /* JAVA_LLOAD_0 30 */
468 1, /* JAVA_LLOAD_1 31 */
469 1, /* JAVA_LLOAD_2 32 */
470 1, /* JAVA_LLOAD_3 33 */
471 1, /* JAVA_FLOAD_0 34 */
472 1, /* JAVA_FLOAD_1 35 */
473 1, /* JAVA_FLOAD_2 36 */
474 1, /* JAVA_FLOAD_3 37 */
475 1, /* JAVA_DLOAD_0 38 */
476 1, /* JAVA_DLOAD_1 39 */
477 1, /* JAVA_DLOAD_2 40 */
478 1, /* JAVA_DLOAD_3 41 */
479 1, /* JAVA_ALOAD_0 42 */
480 1, /* JAVA_ALOAD_1 43 */
481 1, /* JAVA_ALOAD_2 44 */
482 1, /* JAVA_ALOAD_3 45 */
483 1, /* JAVA_IALOAD 46 */
484 1, /* JAVA_LALOAD 47 */
485 1, /* JAVA_FALOAD 48 */
486 1, /* JAVA_DALOAD 49 */
487 1, /* JAVA_AALOAD 50 */
488 1, /* JAVA_BALOAD 51 */
489 1, /* JAVA_CALOAD 52 */
490 1, /* JAVA_SALOAD 53 */
491 2, /* JAVA_ISTORE 54 */
492 2, /* JAVA_LSTORE 55 */
493 2, /* JAVA_FSTORE 56 */
494 2, /* JAVA_DSTORE 57 */
495 2, /* JAVA_ASTORE 58 */
496 1, /* JAVA_ISTORE_0 59 */
497 1, /* JAVA_ISTORE_1 60 */
498 1, /* JAVA_ISTORE_2 61 */
499 1, /* JAVA_ISTORE_3 62 */
500 1, /* JAVA_LSTORE_0 63 */
501 1, /* JAVA_LSTORE_1 64 */
502 1, /* JAVA_LSTORE_2 65 */
503 1, /* JAVA_LSTORE_3 66 */
504 1, /* JAVA_FSTORE_0 67 */
505 1, /* JAVA_FSTORE_1 68 */
506 1, /* JAVA_FSTORE_2 69 */
507 1, /* JAVA_FSTORE_3 70 */
508 1, /* JAVA_DSTORE_0 71 */
509 1, /* JAVA_DSTORE_1 72 */
510 1, /* JAVA_DSTORE_2 73 */
511 1, /* JAVA_DSTORE_3 74 */
512 1, /* JAVA_ASTORE_0 75 */
513 1, /* JAVA_ASTORE_1 76 */
514 1, /* JAVA_ASTORE_2 77 */
515 1, /* JAVA_ASTORE_3 78 */
516 1, /* JAVA_IASTORE 79 */
517 1, /* JAVA_LASTORE 80 */
518 1, /* JAVA_FASTORE 81 */
519 1, /* JAVA_DASTORE 82 */
520 1, /* JAVA_AASTORE 83 */
521 1, /* JAVA_BASTORE 84 */
522 1, /* JAVA_CASTORE 85 */
523 1, /* JAVA_SASTORE 86 */
525 1, /* JAVA_POP2 88 */
527 1, /* JAVA_DUP_X1 90 */
528 1, /* JAVA_DUP_X2 91 */
529 1, /* JAVA_DUP2 92 */
530 1, /* JAVA_DUP2_X1 93 */
531 1, /* JAVA_DUP2_X2 94 */
532 1, /* JAVA_SWAP 95 */
533 1, /* JAVA_IADD 96 */
534 1, /* JAVA_LADD 97 */
535 1, /* JAVA_FADD 98 */
536 1, /* JAVA_DADD 99 */
537 1, /* JAVA_ISUB 100 */
538 1, /* JAVA_LSUB 101 */
539 1, /* JAVA_FSUB 102 */
540 1, /* JAVA_DSUB 103 */
541 1, /* JAVA_IMUL 104 */
542 1, /* JAVA_LMUL 105 */
543 1, /* JAVA_FMUL 106 */
544 1, /* JAVA_DMUL 107 */
545 1, /* JAVA_IDIV 108 */
546 1, /* JAVA_LDIV 109 */
547 1, /* JAVA_FDIV 110 */
548 1, /* JAVA_DDIV 111 */
549 1, /* JAVA_IREM 112 */
550 1, /* JAVA_LREM 113 */
551 1, /* JAVA_FREM 114 */
552 1, /* JAVA_DREM 115 */
553 1, /* JAVA_INEG 116 */
554 1, /* JAVA_LNEG 117 */
555 1, /* JAVA_FNEG 118 */
556 1, /* JAVA_DNEG 119 */
557 1, /* JAVA_ISHL 120 */
558 1, /* JAVA_LSHL 121 */
559 1, /* JAVA_ISHR 122 */
560 1, /* JAVA_LSHR 123 */
561 1, /* JAVA_IUSHR 124 */
562 1, /* JAVA_LUSHR 125 */
563 1, /* JAVA_IAND 126 */
564 1, /* JAVA_LAND 127 */
565 1, /* JAVA_IOR 128 */
566 1, /* JAVA_LOR 129 */
567 1, /* JAVA_IXOR 130 */
568 1, /* JAVA_LXOR 131 */
569 3, /* JAVA_IINC 132 */
570 1, /* JAVA_I2L 133 */
571 1, /* JAVA_I2F 134 */
572 1, /* JAVA_I2D 135 */
573 1, /* JAVA_L2I 136 */
574 1, /* JAVA_L2F 137 */
575 1, /* JAVA_L2D 138 */
576 1, /* JAVA_F2I 139 */
577 1, /* JAVA_F2L 140 */
578 1, /* JAVA_F2D 141 */
579 1, /* JAVA_D2I 142 */
580 1, /* JAVA_D2L 143 */
581 1, /* JAVA_D2F 144 */
582 1, /* JAVA_INT2BYTE 145 */
583 1, /* JAVA_INT2CHAR 146 */
584 1, /* JAVA_INT2SHORT 147 */
585 1, /* JAVA_LCMP 148 */
586 1, /* JAVA_FCMPL 149 */
587 1, /* JAVA_FCMPG 150 */
588 1, /* JAVA_DCMPL 151 */
589 1, /* JAVA_DCMPG 152 */
590 3, /* JAVA_IFEQ 153 */
591 3, /* JAVA_IFNE 154 */
592 3, /* JAVA_IFLT 155 */
593 3, /* JAVA_IFGE 156 */
594 3, /* JAVA_IFGT 157 */
595 3, /* JAVA_IFLE 158 */
596 3, /* JAVA_IF_ICMPEQ 159 */
597 3, /* JAVA_IF_ICMPNE 160 */
598 3, /* JAVA_IF_ICMPLT 161 */
599 3, /* JAVA_IF_ICMPGE 162 */
600 3, /* JAVA_IF_ICMPGT 163 */
601 3, /* JAVA_IF_ICMPLE 164 */
602 3, /* JAVA_IF_ACMPEQ 165 */
603 3, /* JAVA_IF_ACMPNE 166 */
604 3, /* JAVA_GOTO 167 */
605 3, /* JAVA_JSR 168 */
606 2, /* JAVA_RET 169 */
607 0, /* JAVA_TABLESWITCH 170 */ /* variable length */
608 0, /* JAVA_LOOKUPSWITCH 171 */ /* variable length */
609 1, /* JAVA_IRETURN 172 */
610 1, /* JAVA_LRETURN 173 */
611 1, /* JAVA_FRETURN 174 */
612 1, /* JAVA_DRETURN 175 */
613 1, /* JAVA_ARETURN 176 */
614 1, /* JAVA_RETURN 177 */
615 3, /* JAVA_GETSTATIC 178 */
616 3, /* JAVA_PUTSTATIC 179 */
617 3, /* JAVA_GETFIELD 180 */
618 3, /* JAVA_PUTFIELD 181 */
619 3, /* JAVA_INVOKEVIRTUAL 182 */
620 3, /* JAVA_INVOKESPECIAL 183 */
621 3, /* JAVA_INVOKESTATIC 184 */
622 5, /* JAVA_INVOKEINTERFACE 185 */
624 3, /* JAVA_NEW 187 */
625 2, /* JAVA_NEWARRAY 188 */
626 3, /* JAVA_ANEWARRAY 189 */
627 1, /* JAVA_ARRAYLENGTH 190 */
628 1, /* JAVA_ATHROW 191 */
629 3, /* JAVA_CHECKCAST 192 */
630 3, /* JAVA_INSTANCEOF 193 */
631 1, /* JAVA_MONITORENTER 194 */
632 1, /* JAVA_MONITOREXIT 195 */
633 0, /* JAVA_WIDE 196 */ /* variable length */
634 4, /* JAVA_MULTIANEWARRAY 197 */
635 3, /* JAVA_IFNULL 198 */
636 3, /* JAVA_IFNONNULL 199 */
637 5, /* JAVA_GOTO_W 200 */
638 5, /* JAVA_JSR_W 201 */
639 1, /* JAVA_BREAKPOINT 202 */
676 1,1,1,1,1,1,1,1,1,1,
681 /* Java opcode names *********************************************************/
683 char *opcode_names[256] = {
686 "ICONST_M1 ", /* ICONST_M1 2 */
687 "ICONST_0 ", /* ICONST_0 3 */
688 "ICONST_1 ", /* ICONST_1 4 */
689 "ICONST_2 ", /* ICONST_2 5 */
690 "ICONST_3 ", /* ICONST_3 6 */
691 "ICONST_4 ", /* ICONST_4 7 */
692 "ICONST_5 ", /* ICONST_5 8 */
693 "LCONST_0 ", /* LCONST_0 9 */
694 "LCONST_1 ", /* LCONST_1 10 */
695 "FCONST_0 ", /* FCONST_0 11 */
696 "FCONST_1 ", /* FCONST_1 12 */
697 "FCONST_2 ", /* FCONST_2 13 */
698 "DCONST_0 ", /* DCONST_0 14 */
699 "DCONST_1 ", /* DCONST_1 15 */
700 "BIPUSH ", /* BIPUSH 16 */
701 "SIPUSH ", /* SIPUSH 17 */
703 "LDC_W ", /* LDC_W 19 */
704 "LDC2_W ", /* LDC2_W 20 */
710 "ILOAD_0 ", /* ILOAD_0 26 */
711 "ILOAD_1 ", /* ILOAD_1 27 */
712 "ILOAD_2 ", /* ILOAD_2 28 */
713 "ILOAD_3 ", /* ILOAD_3 29 */
714 "LLOAD_0 ", /* LLOAD_0 30 */
715 "LLOAD_1 ", /* LLOAD_1 31 */
716 "LLOAD_2 ", /* LLOAD_2 32 */
717 "LLOAD_3 ", /* LLOAD_3 33 */
718 "FLOAD_0 ", /* FLOAD_0 34 */
719 "FLOAD_1 ", /* FLOAD_1 35 */
720 "FLOAD_2 ", /* FLOAD_2 36 */
721 "FLOAD_3 ", /* FLOAD_3 37 */
722 "DLOAD_0 ", /* DLOAD_0 38 */
723 "DLOAD_1 ", /* DLOAD_1 39 */
724 "DLOAD_2 ", /* DLOAD_2 40 */
725 "DLOAD_3 ", /* DLOAD_3 41 */
726 "ALOAD_0 ", /* ALOAD_0 42 */
727 "ALOAD_1 ", /* ALOAD_1 43 */
728 "ALOAD_2 ", /* ALOAD_2 44 */
729 "ALOAD_3 ", /* ALOAD_3 45 */
743 "ISTORE_0 ", /* ISTORE_0 59 */
744 "ISTORE_1 ", /* ISTORE_1 60 */
745 "ISTORE_2 ", /* ISTORE_2 61 */
746 "ISTORE_3 ", /* ISTORE_3 62 */
747 "LSTORE_0 ", /* LSTORE_0 63 */
748 "LSTORE_1 ", /* LSTORE_1 64 */
749 "LSTORE_2 ", /* LSTORE_2 65 */
750 "LSTORE_3 ", /* LSTORE_3 66 */
751 "FSTORE_0 ", /* FSTORE_0 67 */
752 "FSTORE_1 ", /* FSTORE_1 68 */
753 "FSTORE_2 ", /* FSTORE_2 69 */
754 "FSTORE_3 ", /* FSTORE_3 70 */
755 "DSTORE_0 ", /* DSTORE_0 71 */
756 "DSTORE_1 ", /* DSTORE_1 72 */
757 "DSTORE_2 ", /* DSTORE_2 73 */
758 "DSTORE_3 ", /* DSTORE_3 74 */
759 "ASTORE_0 ", /* ASTORE_0 75 */
760 "ASTORE_1 ", /* ASTORE_1 76 */
761 "ASTORE_2 ", /* ASTORE_2 77 */
762 "ASTORE_3 ", /* ASTORE_3 78 */
829 "INT2BYTE ", /* 145 */
830 "INT2CHAR ", /* 146 */
831 "INT2SHORT ", /* 147 */
843 "IF_ICMPEQ ", /* 159 */
844 "IF_ICMPNE ", /* 160 */
845 "IF_ICMPLT ", /* 161 */
846 "IF_ICMPGE ", /* 162 */
847 "IF_ICMPGT ", /* 163 */
848 "IF_ICMPLE ", /* 164 */
849 "IF_ACMPEQ ", /* 165 */
850 "IF_ACMPNE ", /* 166 */
854 "TABLESWITCH ", /* 170 */
855 "LOOKUPSWITCH ", /* 171 */
856 "IRETURN ", /* 172 */
857 "LRETURN ", /* 173 */
858 "FRETURN ", /* 174 */
859 "DRETURN ", /* 175 */
860 "ARETURN ", /* 176 */
862 "GETSTATIC ", /* 178 */
863 "PUTSTATIC ", /* 179 */
864 "GETFIELD ", /* 180 */
865 "PUTFIELD ", /* 181 */
866 "INVOKEVIRTUAL ", /* 182 */
867 "INVOKESPECIAL ", /* 183 */
868 "INVOKESTATIC ", /* 184 */
869 "INVOKEINTERFACE", /* 185 */
870 "UNDEF186 ", /* 186 */
872 "NEWARRAY ", /* 188 */
873 "ANEWARRAY ", /* 189 */
874 "ARRAYLENGTH ", /* 190 */
876 "CHECKCAST ", /* 192 */
877 "INSTANCEOF ", /* 193 */
878 "MONITORENTER ", /* 194 */
879 "MONITOREXIT ", /* 195 */
880 "WIDE ", /* WIDE 196 */
881 "MULTIANEWARRAY ", /* 197 */
883 "IFNONNULL ", /* 199 */
884 "GOTO_W ", /* GOTO_W 200 */
885 "JSR_W ", /* JSR_W 201 */
886 "BREAKPOINT ", /* BREAKPOINT 202 */
888 "UNDEF203", "UNDEF204", "UNDEF205",
889 "UNDEF206", "UNDEF207", "UNDEF208", "UNDEF209", "UNDEF210",
890 "UNDEF211", "UNDEF212", "UNDEF213", "UNDEF214", "UNDEF215",
891 "UNDEF216", "UNDEF217", "UNDEF218", "UNDEF219", "UNDEF220",
892 "UNDEF221", "UNDEF222", "UNDEF223", "UNDEF224", "UNDEF225",
893 "UNDEF226", "UNDEF227", "UNDEF228", "UNDEF229", "UNDEF230",
894 "UNDEF231", "UNDEF232", "UNDEF233", "UNDEF234", "UNDEF235",
895 "UNDEF236", "UNDEF237", "UNDEF238", "UNDEF239", "UNDEF240",
896 "UNDEF241", "UNDEF242", "UNDEF243", "UNDEF244", "UNDEF245",
897 "UNDEF246", "UNDEF247", "UNDEF248", "UNDEF249", "UNDEF250",
898 "UNDEF251", "UNDEF252", "UNDEF253", "UNDEF254", "UNDEF255"
902 /* jit_init ********************************************************************
904 Initializes the JIT subsystem.
906 *******************************************************************************/
910 #if defined(ENABLE_JIT)
911 /* initialize stack analysis subsystem */
916 /* initialize show subsystem */
922 /* initialize codegen subsystem */
926 /* initialize code subsystem */
930 /* Machine dependent initialization. */
932 #if defined(ENABLE_JIT)
933 # if defined(ENABLE_INTRP)
945 /* jit_close *******************************************************************
947 Close the JIT subsystem.
949 *******************************************************************************/
957 /* dummy function, used when there is no JavaVM code available */
959 static u1 *do_nothing_function(void)
965 /* jit_jitdata_new *************************************************************
967 Allocates and initalizes a new jitdata structure.
969 *******************************************************************************/
971 jitdata *jit_jitdata_new(methodinfo *m)
976 /* allocate jitdata structure and fill it */
981 jd->cd = DNEW(codegendata);
982 jd->rd = DNEW(registerdata);
983 #if defined(ENABLE_LOOP)
984 jd->ld = DNEW(loopdata);
987 /* Allocate codeinfo memory from the heap as we need to keep them. */
989 code = code_codeinfo_new(m);
991 /* Set codeinfo flags. */
993 #if defined(ENABLE_THREADS)
994 if (checksync && (m->flags & ACC_SYNCHRONIZED))
995 code_flag_synchronized(code);
997 if (checksync && (m->flags & ACC_SYNCHRONIZED))
998 code_unflag_leafmethod(code);
1001 code_flag_leafmethod(code);
1003 /* initialize variables */
1007 jd->exceptiontable = NULL;
1008 jd->exceptiontablelength = 0;
1009 jd->returncount = 0;
1010 jd->branchtoentry = false;
1011 jd->branchtoend = false;
1012 jd->returncount = 0;
1013 jd->returnblock = NULL;
1014 jd->maxlocals = m->maxlocals;
1020 /* jit_compile *****************************************************************
1022 Translates one method to machine code.
1024 *******************************************************************************/
1026 static u1 *jit_compile_intern(jitdata *jd);
1028 u1 *jit_compile(methodinfo *m)
1034 STATISTICS(count_jit_calls++);
1036 /* Initialize the static function's class. */
1038 /* ATTENTION: This MUST be done before the method lock is aquired,
1039 otherwise we could run into a deadlock with <clinit>'s that
1040 call static methods of it's own class. */
1042 if ((m->flags & ACC_STATIC) && !(m->class->state & CLASS_INITIALIZED)) {
1043 #if !defined(NDEBUG)
1045 log_message_class("Initialize class ", m->class);
1048 if (!initialize_class(m->class))
1051 /* check if the method has been compiled during initialization */
1053 if ((m->code != NULL) && (m->code->entrypoint != NULL))
1054 return m->code->entrypoint;
1057 /* enter a monitor on the method */
1059 LOCK_MONITOR_ENTER(m);
1061 /* if method has been already compiled return immediately */
1063 if (m->code != NULL) {
1064 LOCK_MONITOR_EXIT(m);
1066 assert(m->code->entrypoint);
1067 return m->code->entrypoint;
1070 TRACECOMPILERCALLS();
1072 STATISTICS(count_methods++);
1074 #if defined(ENABLE_STATISTICS)
1077 if (opt_getcompilingtime)
1078 compilingtime_start();
1081 /* mark start of dump memory area */
1085 /* create jitdata structure */
1087 jd = jit_jitdata_new(m);
1089 /* set the flags for the current JIT run */
1091 jd->flags = JITDATA_FLAG_PARSE;
1093 #if defined(ENABLE_VERIFIER)
1095 jd->flags |= JITDATA_FLAG_VERIFY;
1098 #if defined(ENABLE_PROFILING)
1100 jd->flags |= JITDATA_FLAG_INSTRUMENT;
1103 #if defined(ENABLE_IFCONV)
1105 jd->flags |= JITDATA_FLAG_IFCONV;
1108 #if defined(ENABLE_INLINING) && defined(ENABLE_INLINING_DEBUG)
1109 if (opt_inlining && opt_inline_debug_all)
1110 jd->flags |= JITDATA_FLAG_INLINE;
1113 if (opt_showintermediate)
1114 jd->flags |= JITDATA_FLAG_SHOWINTERMEDIATE;
1116 if (opt_showdisassemble)
1117 jd->flags |= JITDATA_FLAG_SHOWDISASSEMBLE;
1119 if (opt_verbosecall)
1120 jd->flags |= JITDATA_FLAG_VERBOSECALL;
1122 #if defined(ENABLE_REPLACEMENT) && defined(ENABLE_INLINING)
1124 jd->flags |= JITDATA_FLAG_COUNTDOWN;
1127 #if defined(ENABLE_JIT)
1128 # if defined(ENABLE_INTRP)
1131 /* initialize the register allocator */
1137 /* setup the codegendata memory */
1141 /* now call internal compile function */
1143 r = jit_compile_intern(jd);
1146 /* We had an exception! Finish stuff here if necessary. */
1148 /* release codeinfo */
1150 code_codeinfo_free(jd->code);
1152 #if defined(ENABLE_PROFILING)
1153 /* Release memory for basic block profiling information. */
1155 if (JITDATA_HAS_FLAG_INSTRUMENT(jd))
1156 if (jd->code->bbfrequency != NULL)
1157 MFREE(jd->code->bbfrequency, u4, jd->code->basicblockcount);
1161 DEBUG_JIT_COMPILEVERBOSE("Running: ");
1164 /* release dump area */
1168 #if defined(ENABLE_STATISTICS)
1171 if (opt_getcompilingtime)
1172 compilingtime_stop();
1175 /* leave the monitor */
1177 LOCK_MONITOR_EXIT(m);
1179 /* return pointer to the methods entry point */
1185 /* jit_recompile ***************************************************************
1187 Recompiles a Java method.
1189 *******************************************************************************/
1191 u1 *jit_recompile(methodinfo *m)
1198 /* check for max. optimization level */
1200 optlevel = (m->code) ? m->code->optlevel : 0;
1203 if (optlevel == 1) {
1204 /* log_message_method("not recompiling: ", m); */
1209 DEBUG_JIT_COMPILEVERBOSE("Recompiling start: ");
1211 STATISTICS(count_jit_calls++);
1213 #if defined(ENABLE_STATISTICS)
1216 if (opt_getcompilingtime)
1217 compilingtime_start();
1220 /* mark start of dump memory area */
1224 /* create jitdata structure */
1226 jd = jit_jitdata_new(m);
1228 /* set the current optimization level to the previous one plus 1 */
1230 jd->code->optlevel = optlevel + 1;
1232 /* get the optimization flags for the current JIT run */
1234 #if defined(ENABLE_VERIFIER)
1235 jd->flags |= JITDATA_FLAG_VERIFY;
1238 /* jd->flags |= JITDATA_FLAG_REORDER; */
1239 if (opt_showintermediate)
1240 jd->flags |= JITDATA_FLAG_SHOWINTERMEDIATE;
1241 if (opt_showdisassemble)
1242 jd->flags |= JITDATA_FLAG_SHOWDISASSEMBLE;
1243 if (opt_verbosecall)
1244 jd->flags |= JITDATA_FLAG_VERBOSECALL;
1246 #if defined(ENABLE_INLINING)
1248 jd->flags |= JITDATA_FLAG_INLINE;
1251 #if defined(ENABLE_JIT)
1252 # if defined(ENABLE_INTRP)
1255 /* initialize the register allocator */
1260 /* setup the codegendata memory */
1264 /* now call internal compile function */
1266 r = jit_compile_intern(jd);
1269 /* We had an exception! Finish stuff here if necessary. */
1271 /* release codeinfo */
1273 code_codeinfo_free(jd->code);
1276 /* release dump area */
1280 #if defined(ENABLE_STATISTICS)
1283 if (opt_getcompilingtime)
1284 compilingtime_stop();
1287 DEBUG_JIT_COMPILEVERBOSE("Recompiling done: ");
1289 /* return pointer to the methods entry point */
1295 /* jit_compile_intern **********************************************************
1297 Static internal function which does the actual compilation.
1299 *******************************************************************************/
1301 static u1 *jit_compile_intern(jitdata *jd)
1307 #if defined(ENABLE_RT_TIMING)
1308 struct timespec time_start,time_checks,time_parse,time_stack,
1309 time_typecheck,time_loop,time_ifconv,time_alloc,
1313 RT_TIMING_GET_TIME(time_start);
1315 /* get required compiler data */
1317 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1324 #if defined(ENABLE_DEBUG_FILTER)
1325 show_filters_apply(jd->m);
1328 /* Handle native methods and create a native stub. */
1330 if (m->flags & ACC_NATIVE) {
1333 f = native_method_resolve(m);
1338 code = codegen_generate_stub_native(m, f);
1340 /* Native methods are never recompiled. */
1346 return code->entrypoint;
1349 /* if there is no javacode, print error message and return empty method */
1351 if (m->jcode == NULL) {
1352 DEBUG_JIT_COMPILEVERBOSE("No code given for: ");
1354 code->entrypoint = (u1 *) (ptrint) do_nothing_function;
1357 return code->entrypoint; /* return empty method */
1360 #if defined(ENABLE_STATISTICS)
1362 count_javacodesize += m->jcodelength + 18;
1363 count_tryblocks += jd->exceptiontablelength;
1364 count_javaexcsize += jd->exceptiontablelength * SIZEOF_VOID_P;
1368 RT_TIMING_GET_TIME(time_checks);
1370 #if defined(WITH_CLASSPATH_SUN)
1371 /* Code for Sun's OpenJDK (see
1372 hotspot/src/share/vm/classfile/verifier.cpp
1373 (Verifier::is_eligible_for_verification)): Don't verify
1374 dynamically-generated bytecodes. */
1376 # if defined(ENABLE_VERIFIER)
1377 if (class_issubclass(m->class, class_sun_reflect_MagicAccessorImpl))
1378 jd->flags &= ~JITDATA_FLAG_VERIFY;
1382 /* call the compiler passes ***********************************************/
1384 DEBUG_JIT_COMPILEVERBOSE("Parsing: ");
1386 /* call parse pass */
1389 DEBUG_JIT_COMPILEVERBOSE("Exception while parsing: ");
1393 RT_TIMING_GET_TIME(time_parse);
1395 DEBUG_JIT_COMPILEVERBOSE("Parsing done: ");
1397 #if defined(ENABLE_JIT)
1398 # if defined(ENABLE_INTRP)
1401 DEBUG_JIT_COMPILEVERBOSE("Analysing: ");
1403 /* call stack analysis pass */
1405 if (!stack_analyse(jd)) {
1406 DEBUG_JIT_COMPILEVERBOSE("Exception while analysing: ");
1410 RT_TIMING_GET_TIME(time_stack);
1412 DEBUG_JIT_COMPILEVERBOSE("Analysing done: ");
1414 /* Build the CFG. This has to be done after stack_analyse, as
1415 there happens the JSR elimination. */
1420 #ifdef ENABLE_VERIFIER
1421 if (JITDATA_HAS_FLAG_VERIFY(jd)) {
1422 DEBUG_JIT_COMPILEVERBOSE("Typechecking: ");
1424 /* call typecheck pass */
1425 if (!typecheck(jd)) {
1426 DEBUG_JIT_COMPILEVERBOSE("Exception while typechecking: ");
1431 DEBUG_JIT_COMPILEVERBOSE("Typechecking done: ");
1434 RT_TIMING_GET_TIME(time_typecheck);
1436 #if defined(ENABLE_LOOP)
1441 jit_renumber_basicblocks(jd);
1444 RT_TIMING_GET_TIME(time_loop);
1446 #if defined(ENABLE_IFCONV)
1447 if (JITDATA_HAS_FLAG_IFCONV(jd)) {
1448 if (!ifconv_static(jd))
1450 jit_renumber_basicblocks(jd);
1453 RT_TIMING_GET_TIME(time_ifconv);
1457 #if defined(ENABLE_INLINING)
1458 if (JITDATA_HAS_FLAG_INLINE(jd)) {
1459 if (!inline_inline(jd))
1464 #if defined(ENABLE_PYTHON)
1465 if (!pythonpass_run(jd, "langauer_tarjan", "main")) {
1470 #if defined(ENABLE_PROFILING)
1471 /* Basic block reordering. I think this should be done after
1472 if-conversion, as we could lose the ability to do the
1475 if (JITDATA_HAS_FLAG_REORDER(jd)) {
1478 jit_renumber_basicblocks(jd);
1482 DEBUG_JIT_COMPILEVERBOSE("Allocating registers: ");
1484 #if defined(ENABLE_LSRA) && !defined(ENABLE_SSA)
1485 /* allocate registers */
1490 STATISTICS(count_methods_allocated_by_lsra++);
1493 # endif /* defined(ENABLE_LSRA) && !defined(ENABLE_SSA) */
1494 #if defined(ENABLE_SSA)
1495 /* allocate registers */
1496 if ((opt_lsra) && (jd->exceptiontablelength == 0)) {
1497 jd->ls = DNEW(lsradata);
1501 STATISTICS(count_methods_allocated_by_lsra++);
1504 # endif /* defined(ENABLE_SSA) */
1506 STATISTICS(count_locals_conflicts += (jd->maxlocals - 1) * (jd->maxlocals));
1511 STATISTICS(simplereg_make_statistics(jd));
1513 DEBUG_JIT_COMPILEVERBOSE("Allocating registers done: ");
1514 # if defined(ENABLE_INTRP)
1517 #endif /* defined(ENABLE_JIT) */
1518 RT_TIMING_GET_TIME(time_alloc);
1520 #if defined(ENABLE_PROFILING)
1521 /* Allocate memory for basic block profiling information. This
1522 _must_ be done after loop optimization and register allocation,
1523 since they can change the basic block count. */
1525 if (JITDATA_HAS_FLAG_INSTRUMENT(jd))
1526 code->bbfrequency = MNEW(u4, jd->basicblockcount);
1529 DEBUG_JIT_COMPILEVERBOSE("Generating code: ");
1531 /* now generate the machine code */
1533 #if defined(ENABLE_JIT)
1534 # if defined(ENABLE_INTRP)
1536 #if defined(ENABLE_VERIFIER)
1538 DEBUG_JIT_COMPILEVERBOSE("Typechecking (stackbased): ");
1540 if (!typecheck_stackbased(jd)) {
1541 DEBUG_JIT_COMPILEVERBOSE("Exception while typechecking (stackbased): ");
1546 if (!intrp_codegen(jd)) {
1547 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1554 if (!codegen_generate(jd)) {
1555 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1561 if (!intrp_codegen(jd)) {
1562 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1567 RT_TIMING_GET_TIME(time_codegen);
1569 DEBUG_JIT_COMPILEVERBOSE("Generating code done: ");
1571 #if !defined(NDEBUG) && defined(ENABLE_REPLACEMENT)
1572 /* activate replacement points inside newly created code */
1574 if (opt_TestReplacement)
1575 replace_activate_replacement_points(code, false);
1578 #if !defined(NDEBUG)
1579 #if defined(ENABLE_DEBUG_FILTER)
1580 if (jd->m->filtermatches & SHOW_FILTER_FLAG_SHOW_METHOD)
1583 /* intermediate and assembly code listings */
1585 if (JITDATA_HAS_FLAG_SHOWINTERMEDIATE(jd)) {
1586 show_method(jd, SHOW_CODE);
1588 else if (JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd)) {
1589 # if defined(ENABLE_DISASSEMBLER)
1590 DISASSEMBLE(code->entrypoint,
1591 code->entrypoint + (code->mcodelength - cd->dseglen));
1595 if (opt_showddatasegment)
1600 /* switch to the newly generated code */
1603 assert(code->entrypoint);
1605 /* add the current compile version to the methodinfo */
1607 code->prev = m->code;
1610 RT_TIMING_TIME_DIFF(time_start,time_checks,RT_TIMING_JIT_CHECKS);
1611 RT_TIMING_TIME_DIFF(time_checks,time_parse,RT_TIMING_JIT_PARSE);
1612 RT_TIMING_TIME_DIFF(time_parse,time_stack,RT_TIMING_JIT_STACK);
1613 RT_TIMING_TIME_DIFF(time_stack,time_typecheck,RT_TIMING_JIT_TYPECHECK);
1614 RT_TIMING_TIME_DIFF(time_typecheck,time_loop,RT_TIMING_JIT_LOOP);
1615 RT_TIMING_TIME_DIFF(time_loop,time_alloc,RT_TIMING_JIT_ALLOC);
1616 RT_TIMING_TIME_DIFF(time_alloc,time_codegen,RT_TIMING_JIT_CODEGEN);
1617 RT_TIMING_TIME_DIFF(time_start,time_codegen,RT_TIMING_JIT_TOTAL);
1619 /* return pointer to the methods entry point */
1621 return code->entrypoint;
1625 /* jit_invalidate_code *********************************************************
1627 Mark the compiled code of the given method as invalid and take care that
1628 it is replaced if necessary.
1630 XXX Not fully implemented, yet.
1632 *******************************************************************************/
1634 void jit_invalidate_code(methodinfo *m)
1640 if (code == NULL || code_is_invalid(code))
1643 code_flag_invalid(code);
1645 /* activate mappable replacement points */
1647 #if defined(ENABLE_REPLACEMENT)
1648 replace_activate_replacement_points(code, true);
1650 vm_abort("invalidating code only works with ENABLE_REPLACEMENT");
1655 /* jit_request_optimization ****************************************************
1657 Request optimization of the given method. If the code of the method is
1658 unoptimized, it will be invalidated, so the next jit_get_current_code(m)
1659 triggers an optimized recompilation.
1660 If the method is already optimized, this function does nothing.
1663 m................the method
1665 *******************************************************************************/
1667 void jit_request_optimization(methodinfo *m)
1673 if (code && code->optlevel == 0)
1674 jit_invalidate_code(m);
1678 /* jit_get_current_code ********************************************************
1680 Get the currently valid code for the given method. If there is no valid
1681 code, (re)compile the method.
1684 m................the method
1687 the codeinfo* for the current code, or
1688 NULL if an exception has been thrown during recompilation.
1690 *******************************************************************************/
1692 codeinfo *jit_get_current_code(methodinfo *m)
1696 /* if we have valid code, return it */
1698 if (m->code && !code_is_invalid(m->code))
1701 /* otherwise: recompile */
1703 if (!jit_recompile(m))
1712 /* jit_asm_compile *************************************************************
1714 This method is called from asm_vm_call_method and does:
1716 - create stackframe info for exceptions
1717 - compile the method
1718 - patch the entrypoint of the method into the calculated address in
1720 - flushes the instruction cache.
1722 *******************************************************************************/
1724 #if defined(ENABLE_JIT)
1725 #if !defined(JIT_COMPILER_VIA_SIGNAL)
1726 u1 *jit_asm_compile(methodinfo *m, u1 *mptr, u1 *sp, u1 *ra)
1728 stackframeinfo_t sfi;
1733 /* create the stackframeinfo (subtract 1 from RA as it points to the */
1734 /* instruction after the call) */
1736 stacktrace_stackframeinfo_add(&sfi, NULL, sp, ra, ra-1);
1738 /* actually compile the method */
1740 entrypoint = jit_compile(m);
1742 /* remove the stackframeinfo */
1744 stacktrace_stackframeinfo_remove(&sfi);
1746 /* there was a problem during compilation */
1748 if (entrypoint == NULL)
1751 /* get the method patch address */
1753 pa = md_jit_method_patch_address(sfi.pv, (void *) ra, mptr);
1755 /* patch the method entry point */
1759 *p = (ptrint) entrypoint;
1761 /* flush the instruction cache */
1763 md_icacheflush(pa, SIZEOF_VOID_P);
1769 /* jit_compile_handle **********************************************************
1771 This method is called from the appropriate signal handler which
1772 handles compiler-traps and does the following:
1774 - compile the method
1775 - patch the entrypoint of the method into the calculated address in
1777 - flush the instruction cache
1779 *******************************************************************************/
1781 void *jit_compile_handle(methodinfo *m, void *pv, void *ra, void *mptr)
1783 void *newpv; /* new compiled method PV */
1784 void *pa; /* patch address */
1785 uintptr_t *p; /* convenience pointer */
1787 /* Compile the method. */
1789 newpv = jit_compile(m);
1791 /* There was a problem during compilation. */
1796 /* Get the method patch address. */
1798 pa = md_jit_method_patch_address(pv, ra, mptr);
1800 /* Patch the method entry point. */
1802 p = (uintptr_t *) pa;
1804 *p = (uintptr_t) newpv;
1806 /* Flush both caches. */
1808 md_cacheflush(pa, SIZEOF_VOID_P);
1812 #endif /* defined(ENABLE_JIT) */
1815 /* jit_complement_condition ****************************************************
1817 Returns the complement of the passed conditional instruction.
1819 We use the order of the different conditions, e.g.:
1824 If the passed opcode is odd, we simply add 1 to get the complement.
1825 If the opcode is even, we subtract 1.
1832 *******************************************************************************/
1834 s4 jit_complement_condition(s4 opcode)
1838 return ICMD_IFNONNULL;
1840 case ICMD_IFNONNULL:
1844 /* check if opcode is odd */
1854 /* jit_renumber_basicblocks ****************************************************
1856 Set the ->nr of all blocks so it increases when traversing ->next.
1859 jitdata..........the current jitdata
1861 *******************************************************************************/
1863 void jit_renumber_basicblocks(jitdata *jd)
1869 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
1873 /* we have one block more than jd->basicblockcount (the end marker) */
1875 assert(nr == jd->basicblockcount + 1);
1879 /* jit_check_basicblock_numbers ************************************************
1881 Assert that the ->nr of the first block is zero and increases by 1 each
1882 time ->next is traversed.
1883 This function should be called before any analysis that relies on
1884 the basicblock numbers.
1887 jitdata..........the current jitdata
1889 NOTE: Aborts with an assertion if the condition is not met!
1891 *******************************************************************************/
1893 #if !defined(NDEBUG)
1894 void jit_check_basicblock_numbers(jitdata *jd)
1900 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
1901 assert(bptr->nr == nr);
1905 /* we have one block more than jd->basicblockcount (the end marker) */
1907 assert(nr == jd->basicblockcount + 1);
1909 #endif /* !defined(NDEBUG) */
1913 * These are local overrides for various environment variables in Emacs.
1914 * Please do not remove this and leave it at the end of the file, where
1915 * Emacs will automagically detect them.
1916 * ---------------------------------------------------------------------
1919 * indent-tabs-mode: t
1923 * vim:noexpandtab:sw=4:ts=4: