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 # define TRACECOMPILERCALLS() \
110 if (opt_TraceCompilerCalls) { \
112 log_print("[JIT compiler started: method="); \
119 # define TRACECOMPILERCALLS()
123 /* the ICMD table ************************************************************/
126 #define N(name) name,
131 /* abbreviations for flags */
133 #define PEI ICMDTABLE_PEI
134 #define CALLS ICMDTABLE_CALLS
136 /* some machine dependent values */
141 #define IDIV_CALLS ICMDTABLE_CALLS
144 #if (SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
147 #define LDIV_CALLS ICMDTABLE_CALLS
150 /* include the actual table */
152 icmdtable_entry_t icmd_table[256] = {
153 #include <vm/jit/icmdtable.inc>
160 /* XXX hack until the old "PEI" definition is removed */
164 /* stackelement requirements of Java opcodes **********************************/
166 int stackreq[256] = {
168 1, /* JAVA_ACONST 1 */
169 1, /* JAVA_ICONST_M1 2 */
170 1, /* JAVA_ICONST_0 3 */
171 1, /* JAVA_ICONST_1 4 */
172 1, /* JAVA_ICONST_2 5 */
173 1, /* JAVA_ICONST_3 6 */
174 1, /* JAVA_ICONST_4 7 */
175 1, /* JAVA_ICONST_5 8 */
176 1, /* JAVA_LCONST_0 9 */
177 1, /* JAVA_LCONST_1 10 */
178 1, /* JAVA_FCONST_0 11 */
179 1, /* JAVA_FCONST_1 12 */
180 1, /* JAVA_FCONST_2 13 */
181 1, /* JAVA_DCONST_0 14 */
182 1, /* JAVA_DCONST_1 15 */
183 1, /* JAVA_BIPUSH 16 */
184 1, /* JAVA_SIPUSH 17 */
186 1, /* JAVA_LDC_W 19 */
187 1, /* JAVA_LDC2_W 20 */
188 1, /* JAVA_ILOAD 21 */
189 1, /* JAVA_LLOAD 22 */
190 1, /* JAVA_FLOAD 23 */
191 1, /* JAVA_DLOAD 24 */
192 1, /* JAVA_ALOAD 25 */
193 1, /* JAVA_ILOAD_0 26 */
194 1, /* JAVA_ILOAD_1 27 */
195 1, /* JAVA_ILOAD_2 28 */
196 1, /* JAVA_ILOAD_3 29 */
197 1, /* JAVA_LLOAD_0 30 */
198 1, /* JAVA_LLOAD_1 31 */
199 1, /* JAVA_LLOAD_2 32 */
200 1, /* JAVA_LLOAD_3 33 */
201 1, /* JAVA_FLOAD_0 34 */
202 1, /* JAVA_FLOAD_1 35 */
203 1, /* JAVA_FLOAD_2 36 */
204 1, /* JAVA_FLOAD_3 37 */
205 1, /* JAVA_DLOAD_0 38 */
206 1, /* JAVA_DLOAD_1 39 */
207 1, /* JAVA_DLOAD_2 40 */
208 1, /* JAVA_DLOAD_3 41 */
209 1, /* JAVA_ALOAD_0 42 */
210 1, /* JAVA_ALOAD_1 43 */
211 1, /* JAVA_ALOAD_2 44 */
212 1, /* JAVA_ALOAD_3 45 */
213 1, /* JAVA_IALOAD 46 */
214 1, /* JAVA_LALOAD 47 */
215 1, /* JAVA_FALOAD 48 */
216 1, /* JAVA_DALOAD 49 */
217 1, /* JAVA_AALOAD 50 */
218 1, /* JAVA_BALOAD 51 */
219 1, /* JAVA_CALOAD 52 */
220 1, /* JAVA_SALOAD 53 */
221 0, /* JAVA_ISTORE 54 */
222 0, /* JAVA_LSTORE 55 */
223 0, /* JAVA_FSTORE 56 */
224 0, /* JAVA_DSTORE 57 */
225 0, /* JAVA_ASTORE 58 */
226 0, /* JAVA_ISTORE_0 59 */
227 0, /* JAVA_ISTORE_1 60 */
228 0, /* JAVA_ISTORE_2 61 */
229 0, /* JAVA_ISTORE_3 62 */
230 0, /* JAVA_LSTORE_0 63 */
231 0, /* JAVA_LSTORE_1 64 */
232 0, /* JAVA_LSTORE_2 65 */
233 0, /* JAVA_LSTORE_3 66 */
234 0, /* JAVA_FSTORE_0 67 */
235 0, /* JAVA_FSTORE_1 68 */
236 0, /* JAVA_FSTORE_2 69 */
237 0, /* JAVA_FSTORE_3 70 */
238 0, /* JAVA_DSTORE_0 71 */
239 0, /* JAVA_DSTORE_1 72 */
240 0, /* JAVA_DSTORE_2 73 */
241 0, /* JAVA_DSTORE_3 74 */
242 0, /* JAVA_ASTORE_0 75 */
243 0, /* JAVA_ASTORE_1 76 */
244 0, /* JAVA_ASTORE_2 77 */
245 0, /* JAVA_ASTORE_3 78 */
246 0, /* JAVA_IASTORE 79 */
247 0, /* JAVA_LASTORE 80 */
248 0, /* JAVA_FASTORE 81 */
249 0, /* JAVA_DASTORE 82 */
250 0, /* JAVA_AASTORE 83 */
251 0, /* JAVA_BASTORE 84 */
252 0, /* JAVA_CASTORE 85 */
253 0, /* JAVA_SASTORE 86 */
255 0, /* JAVA_POP2 88 */
257 1+3, /* JAVA_DUP_X1 90 */
258 2+4, /* JAVA_DUP_X2 91 */
259 2, /* JAVA_DUP2 92 */
260 2+5, /* JAVA_DUP2_X1 93 */
261 3+6, /* JAVA_DUP2_X2 94 */
262 1+2, /* JAVA_SWAP 95 */
263 1, /* JAVA_IADD 96 */
264 1, /* JAVA_LADD 97 */
265 1, /* JAVA_FADD 98 */
266 1, /* JAVA_DADD 99 */
267 1, /* JAVA_ISUB 100 */
268 1, /* JAVA_LSUB 101 */
269 1, /* JAVA_FSUB 102 */
270 1, /* JAVA_DSUB 103 */
271 1, /* JAVA_IMUL 104 */
272 1, /* JAVA_LMUL 105 */
273 1, /* JAVA_FMUL 106 */
274 1, /* JAVA_DMUL 107 */
275 1, /* JAVA_IDIV 108 */
276 1, /* JAVA_LDIV 109 */
277 1, /* JAVA_FDIV 110 */
278 1, /* JAVA_DDIV 111 */
279 1, /* JAVA_IREM 112 */
280 1, /* JAVA_LREM 113 */
281 1, /* JAVA_FREM 114 */
282 1, /* JAVA_DREM 115 */
283 1, /* JAVA_INEG 116 */
284 1, /* JAVA_LNEG 117 */
285 1, /* JAVA_FNEG 118 */
286 1, /* JAVA_DNEG 119 */
287 1, /* JAVA_ISHL 120 */
288 1, /* JAVA_LSHL 121 */
289 1, /* JAVA_ISHR 122 */
290 1, /* JAVA_LSHR 123 */
291 1, /* JAVA_IUSHR 124 */
292 1, /* JAVA_LUSHR 125 */
293 1, /* JAVA_IAND 126 */
294 1, /* JAVA_LAND 127 */
295 1, /* JAVA_IOR 128 */
296 1, /* JAVA_LOR 129 */
297 1, /* JAVA_IXOR 130 */
298 1, /* JAVA_LXOR 131 */
299 0, /* JAVA_IINC 132 */
300 1, /* JAVA_I2L 133 */
301 1, /* JAVA_I2F 134 */
302 1, /* JAVA_I2D 135 */
303 1, /* JAVA_L2I 136 */
304 1, /* JAVA_L2F 137 */
305 1, /* JAVA_L2D 138 */
306 1, /* JAVA_F2I 139 */
307 1, /* JAVA_F2L 140 */
308 1, /* JAVA_F2D 141 */
309 1, /* JAVA_D2I 142 */
310 1, /* JAVA_D2L 143 */
311 1, /* JAVA_D2F 144 */
312 1, /* JAVA_INT2BYTE 145 */
313 1, /* JAVA_INT2CHAR 146 */
314 1, /* JAVA_INT2SHORT 147 */
315 1, /* JAVA_LCMP 148 */
316 1, /* JAVA_FCMPL 149 */
317 1, /* JAVA_FCMPG 150 */
318 1, /* JAVA_DCMPL 151 */
319 1, /* JAVA_DCMPG 152 */
320 0, /* JAVA_IFEQ 153 */
321 0, /* JAVA_IFNE 154 */
322 0, /* JAVA_IFLT 155 */
323 0, /* JAVA_IFGE 156 */
324 0, /* JAVA_IFGT 157 */
325 0, /* JAVA_IFLE 158 */
326 0, /* JAVA_IF_ICMPEQ 159 */
327 0, /* JAVA_IF_ICMPNE 160 */
328 0, /* JAVA_IF_ICMPLT 161 */
329 0, /* JAVA_IF_ICMPGE 162 */
330 0, /* JAVA_IF_ICMPGT 163 */
331 0, /* JAVA_IF_ICMPLE 164 */
332 0, /* JAVA_IF_ACMPEQ 165 */
333 0, /* JAVA_IF_ACMPNE 166 */
334 0, /* JAVA_GOTO 167 */
335 1, /* JAVA_JSR 168 */
336 0, /* JAVA_RET 169 */
337 0, /* JAVA_TABLESWITCH 170 */
338 0, /* JAVA_LOOKUPSWITCH 171 */
339 0, /* JAVA_IRETURN 172 */
340 0, /* JAVA_LRETURN 173 */
341 0, /* JAVA_FRETURN 174 */
342 0, /* JAVA_DRETURN 175 */
343 0, /* JAVA_ARETURN 176 */
344 0, /* JAVA_RETURN 177 */
345 1, /* JAVA_GETSTATIC 178 */
346 0, /* JAVA_PUTSTATIC 179 */
347 1, /* JAVA_GETFIELD 180 */
348 0, /* JAVA_PUTFIELD 181 */
349 1, /* JAVA_INVOKEVIRTUAL 182 */
350 1, /* JAVA_INVOKESPECIAL 183 */
351 1, /* JAVA_INVOKESTATIC 184 */
352 1, /* JAVA_INVOKEINTERFACE 185 */
353 1, /* JAVA_UNDEF186 186 */
354 1, /* JAVA_NEW 187 */
355 1, /* JAVA_NEWARRAY 188 */
356 1, /* JAVA_ANEWARRAY 189 */
357 1, /* JAVA_ARRAYLENGTH 190 */
358 1, /* JAVA_ATHROW 191 */
359 1, /* JAVA_CHECKCAST 192 */
360 1, /* JAVA_INSTANCEOF 193 */
361 0, /* JAVA_MONITORENTER 194 */
362 0, /* JAVA_MONITOREXIT 195 */
363 0, /* JAVA_WIDE 196 */
364 1, /* JAVA_MULTIANEWARRAY 197 */
365 0, /* JAVA_IFNULL 198 */
366 0, /* JAVA_IFNONNULL 199 */
367 0, /* JAVA_GOTO_W 200 */
368 1, /* JAVA_JSR_W 201 */
369 0, /* JAVA_BREAKPOINT 202 */
370 1, /* JAVA_UNDEF203 203 */
371 1, /* JAVA_UNDEF204 204 */
372 1, /* JAVA_UNDEF205 205 */
373 1, /* JAVA_UNDEF206 206 */
374 1, /* JAVA_UNDEF207 207 */
375 1, /* JAVA_UNDEF208 208 */
376 1, /* JAVA_UNDEF209 209 */
377 1, /* JAVA_UNDEF210 210 */
378 1, /* JAVA_UNDEF211 211 */
379 1, /* JAVA_UNDEF212 212 */
380 1, /* JAVA_UNDEF213 213 */
381 1, /* JAVA_UNDEF214 214 */
382 1, /* JAVA_UNDEF215 215 */
383 1, /* JAVA_UNDEF216 216 */
384 1, /* JAVA_UNDEF217 217 */
385 1, /* JAVA_UNDEF218 218 */
386 1, /* JAVA_UNDEF219 219 */
387 1, /* JAVA_UNDEF220 220 */
388 1, /* JAVA_UNDEF221 221 */
389 1, /* JAVA_UNDEF222 222 */
390 1, /* JAVA_UNDEF223 223 */
391 1, /* JAVA_UNDEF224 224 */
392 1, /* JAVA_UNDEF225 225 */
393 1, /* JAVA_UNDEF226 226 */
394 1, /* JAVA_UNDEF227 227 */
395 1, /* JAVA_UNDEF228 228 */
396 1, /* JAVA_UNDEF229 229 */
397 1, /* JAVA_UNDEF230 230 */
398 1, /* JAVA_UNDEF231 231 */
399 1, /* JAVA_UNDEF232 232 */
400 1, /* JAVA_UNDEF233 233 */
401 1, /* JAVA_UNDEF234 234 */
402 1, /* JAVA_UNDEF235 235 */
403 1, /* JAVA_UNDEF236 236 */
404 1, /* JAVA_UNDEF237 237 */
405 1, /* JAVA_UNDEF238 238 */
406 1, /* JAVA_UNDEF239 239 */
407 1, /* JAVA_UNDEF240 240 */
408 1, /* JAVA_UNDEF241 241 */
409 1, /* JAVA_UNDEF242 242 */
410 1, /* JAVA_UNDEF243 243 */
411 1, /* JAVA_UNDEF244 244 */
412 1, /* JAVA_UNDEF245 245 */
413 1, /* JAVA_UNDEF246 246 */
414 1, /* JAVA_UNDEF247 247 */
415 1, /* JAVA_UNDEF248 248 */
416 1, /* JAVA_UNDEF249 249 */
417 1, /* JAVA_UNDEF250 250 */
418 1, /* JAVA_UNDEF251 251 */
419 1, /* JAVA_UNDEF252 252 */
420 1, /* JAVA_UNDEF253 253 */
421 1, /* JAVA_UNDEF254 254 */
422 1, /* JAVA_UNDEF255 255 */
426 /* size in bytes of Java opcodes **********************************************/
428 int jcommandsize[256] = {
431 1, /* JAVA_ACONST_NULL 1 */
432 1, /* JAVA_ICONST_M1 2 */
433 1, /* JAVA_ICONST_0 3 */
434 1, /* JAVA_ICONST_1 4 */
435 1, /* JAVA_ICONST_2 5 */
436 1, /* JAVA_ICONST_3 6 */
437 1, /* JAVA_ICONST_4 7 */
438 1, /* JAVA_ICONST_5 8 */
439 1, /* JAVA_LCONST_0 9 */
440 1, /* JAVA_LCONST_1 10 */
441 1, /* JAVA_FCONST_0 11 */
442 1, /* JAVA_FCONST_1 12 */
443 1, /* JAVA_FCONST_2 13 */
444 1, /* JAVA_DCONST_0 14 */
445 1, /* JAVA_DCONST_1 15 */
446 2, /* JAVA_BIPUSH 16 */
447 3, /* JAVA_SIPUSH 17 */
448 2, /* JAVA_LDC1 18 */
449 3, /* JAVA_LDC2 19 */
450 3, /* JAVA_LDC2W 20 */
451 2, /* JAVA_ILOAD 21 */
452 2, /* JAVA_LLOAD 22 */
453 2, /* JAVA_FLOAD 23 */
454 2, /* JAVA_DLOAD 24 */
455 2, /* JAVA_ALOAD 25 */
456 1, /* JAVA_ILOAD_0 26 */
457 1, /* JAVA_ILOAD_1 27 */
458 1, /* JAVA_ILOAD_2 28 */
459 1, /* JAVA_ILOAD_3 29 */
460 1, /* JAVA_LLOAD_0 30 */
461 1, /* JAVA_LLOAD_1 31 */
462 1, /* JAVA_LLOAD_2 32 */
463 1, /* JAVA_LLOAD_3 33 */
464 1, /* JAVA_FLOAD_0 34 */
465 1, /* JAVA_FLOAD_1 35 */
466 1, /* JAVA_FLOAD_2 36 */
467 1, /* JAVA_FLOAD_3 37 */
468 1, /* JAVA_DLOAD_0 38 */
469 1, /* JAVA_DLOAD_1 39 */
470 1, /* JAVA_DLOAD_2 40 */
471 1, /* JAVA_DLOAD_3 41 */
472 1, /* JAVA_ALOAD_0 42 */
473 1, /* JAVA_ALOAD_1 43 */
474 1, /* JAVA_ALOAD_2 44 */
475 1, /* JAVA_ALOAD_3 45 */
476 1, /* JAVA_IALOAD 46 */
477 1, /* JAVA_LALOAD 47 */
478 1, /* JAVA_FALOAD 48 */
479 1, /* JAVA_DALOAD 49 */
480 1, /* JAVA_AALOAD 50 */
481 1, /* JAVA_BALOAD 51 */
482 1, /* JAVA_CALOAD 52 */
483 1, /* JAVA_SALOAD 53 */
484 2, /* JAVA_ISTORE 54 */
485 2, /* JAVA_LSTORE 55 */
486 2, /* JAVA_FSTORE 56 */
487 2, /* JAVA_DSTORE 57 */
488 2, /* JAVA_ASTORE 58 */
489 1, /* JAVA_ISTORE_0 59 */
490 1, /* JAVA_ISTORE_1 60 */
491 1, /* JAVA_ISTORE_2 61 */
492 1, /* JAVA_ISTORE_3 62 */
493 1, /* JAVA_LSTORE_0 63 */
494 1, /* JAVA_LSTORE_1 64 */
495 1, /* JAVA_LSTORE_2 65 */
496 1, /* JAVA_LSTORE_3 66 */
497 1, /* JAVA_FSTORE_0 67 */
498 1, /* JAVA_FSTORE_1 68 */
499 1, /* JAVA_FSTORE_2 69 */
500 1, /* JAVA_FSTORE_3 70 */
501 1, /* JAVA_DSTORE_0 71 */
502 1, /* JAVA_DSTORE_1 72 */
503 1, /* JAVA_DSTORE_2 73 */
504 1, /* JAVA_DSTORE_3 74 */
505 1, /* JAVA_ASTORE_0 75 */
506 1, /* JAVA_ASTORE_1 76 */
507 1, /* JAVA_ASTORE_2 77 */
508 1, /* JAVA_ASTORE_3 78 */
509 1, /* JAVA_IASTORE 79 */
510 1, /* JAVA_LASTORE 80 */
511 1, /* JAVA_FASTORE 81 */
512 1, /* JAVA_DASTORE 82 */
513 1, /* JAVA_AASTORE 83 */
514 1, /* JAVA_BASTORE 84 */
515 1, /* JAVA_CASTORE 85 */
516 1, /* JAVA_SASTORE 86 */
518 1, /* JAVA_POP2 88 */
520 1, /* JAVA_DUP_X1 90 */
521 1, /* JAVA_DUP_X2 91 */
522 1, /* JAVA_DUP2 92 */
523 1, /* JAVA_DUP2_X1 93 */
524 1, /* JAVA_DUP2_X2 94 */
525 1, /* JAVA_SWAP 95 */
526 1, /* JAVA_IADD 96 */
527 1, /* JAVA_LADD 97 */
528 1, /* JAVA_FADD 98 */
529 1, /* JAVA_DADD 99 */
530 1, /* JAVA_ISUB 100 */
531 1, /* JAVA_LSUB 101 */
532 1, /* JAVA_FSUB 102 */
533 1, /* JAVA_DSUB 103 */
534 1, /* JAVA_IMUL 104 */
535 1, /* JAVA_LMUL 105 */
536 1, /* JAVA_FMUL 106 */
537 1, /* JAVA_DMUL 107 */
538 1, /* JAVA_IDIV 108 */
539 1, /* JAVA_LDIV 109 */
540 1, /* JAVA_FDIV 110 */
541 1, /* JAVA_DDIV 111 */
542 1, /* JAVA_IREM 112 */
543 1, /* JAVA_LREM 113 */
544 1, /* JAVA_FREM 114 */
545 1, /* JAVA_DREM 115 */
546 1, /* JAVA_INEG 116 */
547 1, /* JAVA_LNEG 117 */
548 1, /* JAVA_FNEG 118 */
549 1, /* JAVA_DNEG 119 */
550 1, /* JAVA_ISHL 120 */
551 1, /* JAVA_LSHL 121 */
552 1, /* JAVA_ISHR 122 */
553 1, /* JAVA_LSHR 123 */
554 1, /* JAVA_IUSHR 124 */
555 1, /* JAVA_LUSHR 125 */
556 1, /* JAVA_IAND 126 */
557 1, /* JAVA_LAND 127 */
558 1, /* JAVA_IOR 128 */
559 1, /* JAVA_LOR 129 */
560 1, /* JAVA_IXOR 130 */
561 1, /* JAVA_LXOR 131 */
562 3, /* JAVA_IINC 132 */
563 1, /* JAVA_I2L 133 */
564 1, /* JAVA_I2F 134 */
565 1, /* JAVA_I2D 135 */
566 1, /* JAVA_L2I 136 */
567 1, /* JAVA_L2F 137 */
568 1, /* JAVA_L2D 138 */
569 1, /* JAVA_F2I 139 */
570 1, /* JAVA_F2L 140 */
571 1, /* JAVA_F2D 141 */
572 1, /* JAVA_D2I 142 */
573 1, /* JAVA_D2L 143 */
574 1, /* JAVA_D2F 144 */
575 1, /* JAVA_INT2BYTE 145 */
576 1, /* JAVA_INT2CHAR 146 */
577 1, /* JAVA_INT2SHORT 147 */
578 1, /* JAVA_LCMP 148 */
579 1, /* JAVA_FCMPL 149 */
580 1, /* JAVA_FCMPG 150 */
581 1, /* JAVA_DCMPL 151 */
582 1, /* JAVA_DCMPG 152 */
583 3, /* JAVA_IFEQ 153 */
584 3, /* JAVA_IFNE 154 */
585 3, /* JAVA_IFLT 155 */
586 3, /* JAVA_IFGE 156 */
587 3, /* JAVA_IFGT 157 */
588 3, /* JAVA_IFLE 158 */
589 3, /* JAVA_IF_ICMPEQ 159 */
590 3, /* JAVA_IF_ICMPNE 160 */
591 3, /* JAVA_IF_ICMPLT 161 */
592 3, /* JAVA_IF_ICMPGE 162 */
593 3, /* JAVA_IF_ICMPGT 163 */
594 3, /* JAVA_IF_ICMPLE 164 */
595 3, /* JAVA_IF_ACMPEQ 165 */
596 3, /* JAVA_IF_ACMPNE 166 */
597 3, /* JAVA_GOTO 167 */
598 3, /* JAVA_JSR 168 */
599 2, /* JAVA_RET 169 */
600 0, /* JAVA_TABLESWITCH 170 */ /* variable length */
601 0, /* JAVA_LOOKUPSWITCH 171 */ /* variable length */
602 1, /* JAVA_IRETURN 172 */
603 1, /* JAVA_LRETURN 173 */
604 1, /* JAVA_FRETURN 174 */
605 1, /* JAVA_DRETURN 175 */
606 1, /* JAVA_ARETURN 176 */
607 1, /* JAVA_RETURN 177 */
608 3, /* JAVA_GETSTATIC 178 */
609 3, /* JAVA_PUTSTATIC 179 */
610 3, /* JAVA_GETFIELD 180 */
611 3, /* JAVA_PUTFIELD 181 */
612 3, /* JAVA_INVOKEVIRTUAL 182 */
613 3, /* JAVA_INVOKESPECIAL 183 */
614 3, /* JAVA_INVOKESTATIC 184 */
615 5, /* JAVA_INVOKEINTERFACE 185 */
617 3, /* JAVA_NEW 187 */
618 2, /* JAVA_NEWARRAY 188 */
619 3, /* JAVA_ANEWARRAY 189 */
620 1, /* JAVA_ARRAYLENGTH 190 */
621 1, /* JAVA_ATHROW 191 */
622 3, /* JAVA_CHECKCAST 192 */
623 3, /* JAVA_INSTANCEOF 193 */
624 1, /* JAVA_MONITORENTER 194 */
625 1, /* JAVA_MONITOREXIT 195 */
626 0, /* JAVA_WIDE 196 */ /* variable length */
627 4, /* JAVA_MULTIANEWARRAY 197 */
628 3, /* JAVA_IFNULL 198 */
629 3, /* JAVA_IFNONNULL 199 */
630 5, /* JAVA_GOTO_W 200 */
631 5, /* JAVA_JSR_W 201 */
632 1, /* JAVA_BREAKPOINT 202 */
669 1,1,1,1,1,1,1,1,1,1,
674 /* Java opcode names *********************************************************/
676 char *opcode_names[256] = {
679 "ICONST_M1 ", /* ICONST_M1 2 */
680 "ICONST_0 ", /* ICONST_0 3 */
681 "ICONST_1 ", /* ICONST_1 4 */
682 "ICONST_2 ", /* ICONST_2 5 */
683 "ICONST_3 ", /* ICONST_3 6 */
684 "ICONST_4 ", /* ICONST_4 7 */
685 "ICONST_5 ", /* ICONST_5 8 */
686 "LCONST_0 ", /* LCONST_0 9 */
687 "LCONST_1 ", /* LCONST_1 10 */
688 "FCONST_0 ", /* FCONST_0 11 */
689 "FCONST_1 ", /* FCONST_1 12 */
690 "FCONST_2 ", /* FCONST_2 13 */
691 "DCONST_0 ", /* DCONST_0 14 */
692 "DCONST_1 ", /* DCONST_1 15 */
693 "BIPUSH ", /* BIPUSH 16 */
694 "SIPUSH ", /* SIPUSH 17 */
696 "LDC_W ", /* LDC_W 19 */
697 "LDC2_W ", /* LDC2_W 20 */
703 "ILOAD_0 ", /* ILOAD_0 26 */
704 "ILOAD_1 ", /* ILOAD_1 27 */
705 "ILOAD_2 ", /* ILOAD_2 28 */
706 "ILOAD_3 ", /* ILOAD_3 29 */
707 "LLOAD_0 ", /* LLOAD_0 30 */
708 "LLOAD_1 ", /* LLOAD_1 31 */
709 "LLOAD_2 ", /* LLOAD_2 32 */
710 "LLOAD_3 ", /* LLOAD_3 33 */
711 "FLOAD_0 ", /* FLOAD_0 34 */
712 "FLOAD_1 ", /* FLOAD_1 35 */
713 "FLOAD_2 ", /* FLOAD_2 36 */
714 "FLOAD_3 ", /* FLOAD_3 37 */
715 "DLOAD_0 ", /* DLOAD_0 38 */
716 "DLOAD_1 ", /* DLOAD_1 39 */
717 "DLOAD_2 ", /* DLOAD_2 40 */
718 "DLOAD_3 ", /* DLOAD_3 41 */
719 "ALOAD_0 ", /* ALOAD_0 42 */
720 "ALOAD_1 ", /* ALOAD_1 43 */
721 "ALOAD_2 ", /* ALOAD_2 44 */
722 "ALOAD_3 ", /* ALOAD_3 45 */
736 "ISTORE_0 ", /* ISTORE_0 59 */
737 "ISTORE_1 ", /* ISTORE_1 60 */
738 "ISTORE_2 ", /* ISTORE_2 61 */
739 "ISTORE_3 ", /* ISTORE_3 62 */
740 "LSTORE_0 ", /* LSTORE_0 63 */
741 "LSTORE_1 ", /* LSTORE_1 64 */
742 "LSTORE_2 ", /* LSTORE_2 65 */
743 "LSTORE_3 ", /* LSTORE_3 66 */
744 "FSTORE_0 ", /* FSTORE_0 67 */
745 "FSTORE_1 ", /* FSTORE_1 68 */
746 "FSTORE_2 ", /* FSTORE_2 69 */
747 "FSTORE_3 ", /* FSTORE_3 70 */
748 "DSTORE_0 ", /* DSTORE_0 71 */
749 "DSTORE_1 ", /* DSTORE_1 72 */
750 "DSTORE_2 ", /* DSTORE_2 73 */
751 "DSTORE_3 ", /* DSTORE_3 74 */
752 "ASTORE_0 ", /* ASTORE_0 75 */
753 "ASTORE_1 ", /* ASTORE_1 76 */
754 "ASTORE_2 ", /* ASTORE_2 77 */
755 "ASTORE_3 ", /* ASTORE_3 78 */
822 "INT2BYTE ", /* 145 */
823 "INT2CHAR ", /* 146 */
824 "INT2SHORT ", /* 147 */
836 "IF_ICMPEQ ", /* 159 */
837 "IF_ICMPNE ", /* 160 */
838 "IF_ICMPLT ", /* 161 */
839 "IF_ICMPGE ", /* 162 */
840 "IF_ICMPGT ", /* 163 */
841 "IF_ICMPLE ", /* 164 */
842 "IF_ACMPEQ ", /* 165 */
843 "IF_ACMPNE ", /* 166 */
847 "TABLESWITCH ", /* 170 */
848 "LOOKUPSWITCH ", /* 171 */
849 "IRETURN ", /* 172 */
850 "LRETURN ", /* 173 */
851 "FRETURN ", /* 174 */
852 "DRETURN ", /* 175 */
853 "ARETURN ", /* 176 */
855 "GETSTATIC ", /* 178 */
856 "PUTSTATIC ", /* 179 */
857 "GETFIELD ", /* 180 */
858 "PUTFIELD ", /* 181 */
859 "INVOKEVIRTUAL ", /* 182 */
860 "INVOKESPECIAL ", /* 183 */
861 "INVOKESTATIC ", /* 184 */
862 "INVOKEINTERFACE", /* 185 */
863 "UNDEF186 ", /* 186 */
865 "NEWARRAY ", /* 188 */
866 "ANEWARRAY ", /* 189 */
867 "ARRAYLENGTH ", /* 190 */
869 "CHECKCAST ", /* 192 */
870 "INSTANCEOF ", /* 193 */
871 "MONITORENTER ", /* 194 */
872 "MONITOREXIT ", /* 195 */
873 "WIDE ", /* WIDE 196 */
874 "MULTIANEWARRAY ", /* 197 */
876 "IFNONNULL ", /* 199 */
877 "GOTO_W ", /* GOTO_W 200 */
878 "JSR_W ", /* JSR_W 201 */
879 "BREAKPOINT ", /* BREAKPOINT 202 */
881 "UNDEF203", "UNDEF204", "UNDEF205",
882 "UNDEF206", "UNDEF207", "UNDEF208", "UNDEF209", "UNDEF210",
883 "UNDEF211", "UNDEF212", "UNDEF213", "UNDEF214", "UNDEF215",
884 "UNDEF216", "UNDEF217", "UNDEF218", "UNDEF219", "UNDEF220",
885 "UNDEF221", "UNDEF222", "UNDEF223", "UNDEF224", "UNDEF225",
886 "UNDEF226", "UNDEF227", "UNDEF228", "UNDEF229", "UNDEF230",
887 "UNDEF231", "UNDEF232", "UNDEF233", "UNDEF234", "UNDEF235",
888 "UNDEF236", "UNDEF237", "UNDEF238", "UNDEF239", "UNDEF240",
889 "UNDEF241", "UNDEF242", "UNDEF243", "UNDEF244", "UNDEF245",
890 "UNDEF246", "UNDEF247", "UNDEF248", "UNDEF249", "UNDEF250",
891 "UNDEF251", "UNDEF252", "UNDEF253", "UNDEF254", "UNDEF255"
895 /* jit_init ********************************************************************
897 Initializes the JIT subsystem.
899 *******************************************************************************/
903 #if defined(ENABLE_JIT)
904 /* initialize stack analysis subsystem */
909 /* initialize show subsystem */
915 /* initialize codegen subsystem */
919 /* initialize code subsystem */
925 /* jit_close *******************************************************************
927 Close the JIT subsystem.
929 *******************************************************************************/
937 /* dummy function, used when there is no JavaVM code available */
939 static u1 *do_nothing_function(void)
945 /* jit_jitdata_new *************************************************************
947 Allocates and initalizes a new jitdata structure.
949 *******************************************************************************/
951 jitdata *jit_jitdata_new(methodinfo *m)
955 /* allocate jitdata structure and fill it */
960 jd->cd = DNEW(codegendata);
961 jd->rd = DNEW(registerdata);
962 #if defined(ENABLE_LOOP)
963 jd->ld = DNEW(loopdata);
966 /* Allocate codeinfo memory from the heap as we need to keep them. */
968 jd->code = code_codeinfo_new(m);
970 /* initialize variables */
973 jd->exceptiontable = NULL;
974 jd->exceptiontablelength = 0;
976 jd->branchtoentry = false;
977 jd->branchtoend = false;
979 jd->returnblock = NULL;
980 jd->maxlocals = m->maxlocals;
982 #if defined(ENABLE_THREADS)
983 if (checksync && (m->flags & ACC_SYNCHRONIZED))
984 jd->isleafmethod = false;
987 jd->isleafmethod = true;
993 /* jit_compile *****************************************************************
995 Translates one method to machine code.
997 *******************************************************************************/
999 static u1 *jit_compile_intern(jitdata *jd);
1001 u1 *jit_compile(methodinfo *m)
1007 STATISTICS(count_jit_calls++);
1009 /* Initialize the static function's class. */
1011 /* ATTENTION: This MUST be done before the method lock is aquired,
1012 otherwise we could run into a deadlock with <clinit>'s that
1013 call static methods of it's own class. */
1015 if ((m->flags & ACC_STATIC) && !(m->class->state & CLASS_INITIALIZED)) {
1016 #if !defined(NDEBUG)
1018 log_message_class("Initialize class ", m->class);
1021 if (!initialize_class(m->class))
1024 /* check if the method has been compiled during initialization */
1026 if ((m->code != NULL) && (m->code->entrypoint != NULL))
1027 return m->code->entrypoint;
1030 /* enter a monitor on the method */
1032 LOCK_MONITOR_ENTER(m);
1034 /* if method has been already compiled return immediately */
1036 if (m->code != NULL) {
1037 LOCK_MONITOR_EXIT(m);
1039 assert(m->code->entrypoint);
1040 return m->code->entrypoint;
1043 TRACECOMPILERCALLS();
1045 STATISTICS(count_methods++);
1047 #if defined(ENABLE_STATISTICS)
1050 if (opt_getcompilingtime)
1051 compilingtime_start();
1054 /* mark start of dump memory area */
1056 dumpsize = dump_size();
1058 /* create jitdata structure */
1060 jd = jit_jitdata_new(m);
1062 /* set the flags for the current JIT run */
1064 jd->flags = JITDATA_FLAG_PARSE;
1066 #if defined(ENABLE_VERIFIER)
1068 jd->flags |= JITDATA_FLAG_VERIFY;
1071 #if defined(ENABLE_PROFILING)
1073 jd->flags |= JITDATA_FLAG_INSTRUMENT;
1076 #if defined(ENABLE_IFCONV)
1078 jd->flags |= JITDATA_FLAG_IFCONV;
1081 #if defined(ENABLE_INLINING) && defined(ENABLE_INLINING_DEBUG)
1082 if (opt_inlining && opt_inline_debug_all)
1083 jd->flags |= JITDATA_FLAG_INLINE;
1086 if (opt_showintermediate)
1087 jd->flags |= JITDATA_FLAG_SHOWINTERMEDIATE;
1089 if (opt_showdisassemble)
1090 jd->flags |= JITDATA_FLAG_SHOWDISASSEMBLE;
1092 if (opt_verbosecall)
1093 jd->flags |= JITDATA_FLAG_VERBOSECALL;
1095 #if defined(ENABLE_REPLACEMENT) && defined(ENABLE_INLINING)
1097 jd->flags |= JITDATA_FLAG_COUNTDOWN;
1100 #if defined(ENABLE_JIT)
1101 # if defined(ENABLE_INTRP)
1104 /* initialize the register allocator */
1110 /* setup the codegendata memory */
1114 /* now call internal compile function */
1116 r = jit_compile_intern(jd);
1119 /* We had an exception! Finish stuff here if necessary. */
1121 /* release codeinfo */
1123 code_codeinfo_free(jd->code);
1125 #if defined(ENABLE_PROFILING)
1126 /* Release memory for basic block profiling information. */
1128 if (JITDATA_HAS_FLAG_INSTRUMENT(jd))
1129 if (jd->code->bbfrequency != NULL)
1130 MFREE(jd->code->bbfrequency, u4, jd->code->basicblockcount);
1134 DEBUG_JIT_COMPILEVERBOSE("Running: ");
1137 /* release dump area */
1139 dump_release(dumpsize);
1141 #if defined(ENABLE_STATISTICS)
1144 if (opt_getcompilingtime)
1145 compilingtime_stop();
1148 /* leave the monitor */
1150 LOCK_MONITOR_EXIT(m);
1152 /* return pointer to the methods entry point */
1158 /* jit_recompile ***************************************************************
1160 Recompiles a Java method.
1162 *******************************************************************************/
1164 u1 *jit_recompile(methodinfo *m)
1171 /* check for max. optimization level */
1173 optlevel = (m->code) ? m->code->optlevel : 0;
1176 if (optlevel == 1) {
1177 /* log_message_method("not recompiling: ", m); */
1182 DEBUG_JIT_COMPILEVERBOSE("Recompiling start: ");
1184 STATISTICS(count_jit_calls++);
1186 #if defined(ENABLE_STATISTICS)
1189 if (opt_getcompilingtime)
1190 compilingtime_start();
1193 /* mark start of dump memory area */
1195 dumpsize = dump_size();
1197 /* create jitdata structure */
1199 jd = jit_jitdata_new(m);
1201 /* set the current optimization level to the previous one plus 1 */
1203 jd->code->optlevel = optlevel + 1;
1205 /* get the optimization flags for the current JIT run */
1207 #if defined(ENABLE_VERIFIER)
1208 jd->flags |= JITDATA_FLAG_VERIFY;
1211 /* jd->flags |= JITDATA_FLAG_REORDER; */
1212 if (opt_showintermediate)
1213 jd->flags |= JITDATA_FLAG_SHOWINTERMEDIATE;
1214 if (opt_showdisassemble)
1215 jd->flags |= JITDATA_FLAG_SHOWDISASSEMBLE;
1216 if (opt_verbosecall)
1217 jd->flags |= JITDATA_FLAG_VERBOSECALL;
1219 #if defined(ENABLE_INLINING)
1221 jd->flags |= JITDATA_FLAG_INLINE;
1224 #if defined(ENABLE_JIT)
1225 # if defined(ENABLE_INTRP)
1228 /* initialize the register allocator */
1233 /* setup the codegendata memory */
1237 /* now call internal compile function */
1239 r = jit_compile_intern(jd);
1242 /* We had an exception! Finish stuff here if necessary. */
1244 /* release codeinfo */
1246 code_codeinfo_free(jd->code);
1249 /* release dump area */
1251 dump_release(dumpsize);
1253 #if defined(ENABLE_STATISTICS)
1256 if (opt_getcompilingtime)
1257 compilingtime_stop();
1260 DEBUG_JIT_COMPILEVERBOSE("Recompiling done: ");
1262 /* return pointer to the methods entry point */
1268 /* jit_compile_intern **********************************************************
1270 Static internal function which does the actual compilation.
1272 *******************************************************************************/
1274 static u1 *jit_compile_intern(jitdata *jd)
1280 #if defined(ENABLE_RT_TIMING)
1281 struct timespec time_start,time_checks,time_parse,time_stack,
1282 time_typecheck,time_loop,time_ifconv,time_alloc,
1286 RT_TIMING_GET_TIME(time_start);
1288 /* get required compiler data */
1290 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1297 #if defined(ENABLE_DEBUG_FILTER)
1298 show_filters_apply(jd->m);
1301 /* handle native methods and create a native stub */
1303 if (m->flags & ACC_NATIVE) {
1306 f = native_method_resolve(m);
1311 code = codegen_generate_stub_native(m, f);
1313 /* Native methods are never recompiled. */
1319 return code->entrypoint;
1322 /* if there is no javacode, print error message and return empty method */
1324 if (m->jcode == NULL) {
1325 DEBUG_JIT_COMPILEVERBOSE("No code given for: ");
1327 code->entrypoint = (u1 *) (ptrint) do_nothing_function;
1330 return code->entrypoint; /* return empty method */
1333 #if defined(ENABLE_STATISTICS)
1335 count_javacodesize += m->jcodelength + 18;
1336 count_tryblocks += jd->exceptiontablelength;
1337 count_javaexcsize += jd->exceptiontablelength * SIZEOF_VOID_P;
1341 RT_TIMING_GET_TIME(time_checks);
1343 #if defined(WITH_CLASSPATH_SUN)
1344 /* Code for Sun's OpenJDK (see
1345 hotspot/src/share/vm/classfile/verifier.cpp
1346 (Verifier::is_eligible_for_verification)): Don't verify
1347 dynamically-generated bytecodes. */
1349 # if defined(ENABLE_VERIFIER)
1350 if (class_issubclass(m->class, class_sun_reflect_MagicAccessorImpl))
1351 jd->flags &= ~JITDATA_FLAG_VERIFY;
1355 /* call the compiler passes ***********************************************/
1357 DEBUG_JIT_COMPILEVERBOSE("Parsing: ");
1359 /* call parse pass */
1362 DEBUG_JIT_COMPILEVERBOSE("Exception while parsing: ");
1366 RT_TIMING_GET_TIME(time_parse);
1368 DEBUG_JIT_COMPILEVERBOSE("Parsing done: ");
1370 #if defined(ENABLE_JIT)
1371 # if defined(ENABLE_INTRP)
1374 DEBUG_JIT_COMPILEVERBOSE("Analysing: ");
1376 /* call stack analysis pass */
1378 if (!stack_analyse(jd)) {
1379 DEBUG_JIT_COMPILEVERBOSE("Exception while analysing: ");
1383 RT_TIMING_GET_TIME(time_stack);
1385 DEBUG_JIT_COMPILEVERBOSE("Analysing done: ");
1387 /* Build the CFG. This has to be done after stack_analyse, as
1388 there happens the JSR elimination. */
1393 #ifdef ENABLE_VERIFIER
1394 if (JITDATA_HAS_FLAG_VERIFY(jd)) {
1395 DEBUG_JIT_COMPILEVERBOSE("Typechecking: ");
1397 /* call typecheck pass */
1398 if (!typecheck(jd)) {
1399 DEBUG_JIT_COMPILEVERBOSE("Exception while typechecking: ");
1404 DEBUG_JIT_COMPILEVERBOSE("Typechecking done: ");
1407 RT_TIMING_GET_TIME(time_typecheck);
1409 #if defined(ENABLE_LOOP)
1414 jit_renumber_basicblocks(jd);
1417 RT_TIMING_GET_TIME(time_loop);
1419 #if defined(ENABLE_IFCONV)
1420 if (JITDATA_HAS_FLAG_IFCONV(jd)) {
1421 if (!ifconv_static(jd))
1423 jit_renumber_basicblocks(jd);
1426 RT_TIMING_GET_TIME(time_ifconv);
1430 #if defined(ENABLE_INLINING)
1431 if (JITDATA_HAS_FLAG_INLINE(jd)) {
1432 if (!inline_inline(jd))
1437 #if defined(ENABLE_PROFILING)
1438 /* Basic block reordering. I think this should be done after
1439 if-conversion, as we could lose the ability to do the
1442 if (JITDATA_HAS_FLAG_REORDER(jd)) {
1445 jit_renumber_basicblocks(jd);
1449 DEBUG_JIT_COMPILEVERBOSE("Allocating registers: ");
1451 #if defined(ENABLE_LSRA) && !defined(ENABLE_SSA)
1452 /* allocate registers */
1457 STATISTICS(count_methods_allocated_by_lsra++);
1460 # endif /* defined(ENABLE_LSRA) && !defined(ENABLE_SSA) */
1461 #if defined(ENABLE_SSA)
1462 /* allocate registers */
1463 if ((opt_lsra) && (jd->exceptiontablelength == 0)) {
1464 jd->ls = DNEW(lsradata);
1467 STATISTICS(count_methods_allocated_by_lsra++);
1470 # endif /* defined(ENABLE_SSA) */
1472 STATISTICS(count_locals_conflicts += (jd->maxlocals - 1) * (jd->maxlocals));
1477 STATISTICS(simplereg_make_statistics(jd));
1479 DEBUG_JIT_COMPILEVERBOSE("Allocating registers done: ");
1480 # if defined(ENABLE_INTRP)
1483 #endif /* defined(ENABLE_JIT) */
1484 RT_TIMING_GET_TIME(time_alloc);
1486 #if defined(ENABLE_PROFILING)
1487 /* Allocate memory for basic block profiling information. This
1488 _must_ be done after loop optimization and register allocation,
1489 since they can change the basic block count. */
1491 if (JITDATA_HAS_FLAG_INSTRUMENT(jd))
1492 code->bbfrequency = MNEW(u4, jd->basicblockcount);
1495 DEBUG_JIT_COMPILEVERBOSE("Generating code: ");
1497 /* now generate the machine code */
1499 #if defined(ENABLE_JIT)
1500 # if defined(ENABLE_INTRP)
1502 #if defined(ENABLE_VERIFIER)
1504 DEBUG_JIT_COMPILEVERBOSE("Typechecking (stackbased): ");
1506 if (!typecheck_stackbased(jd)) {
1507 DEBUG_JIT_COMPILEVERBOSE("Exception while typechecking (stackbased): ");
1512 if (!intrp_codegen(jd)) {
1513 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1520 if (!codegen_generate(jd)) {
1521 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1527 if (!intrp_codegen(jd)) {
1528 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1533 RT_TIMING_GET_TIME(time_codegen);
1535 DEBUG_JIT_COMPILEVERBOSE("Generating code done: ");
1537 #if !defined(NDEBUG) && defined(ENABLE_REPLACEMENT)
1538 /* activate replacement points inside newly created code */
1540 if (opt_TestReplacement)
1541 replace_activate_replacement_points(code, false);
1544 #if !defined(NDEBUG)
1545 #if defined(ENABLE_DEBUG_FILTER)
1546 if (jd->m->filtermatches & SHOW_FILTER_FLAG_SHOW_METHOD)
1549 /* intermediate and assembly code listings */
1551 if (JITDATA_HAS_FLAG_SHOWINTERMEDIATE(jd)) {
1552 show_method(jd, SHOW_CODE);
1554 else if (JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd)) {
1555 # if defined(ENABLE_DISASSEMBLER)
1556 DISASSEMBLE(code->entrypoint,
1557 code->entrypoint + (code->mcodelength - cd->dseglen));
1561 if (opt_showddatasegment)
1566 /* switch to the newly generated code */
1569 assert(code->entrypoint);
1571 /* add the current compile version to the methodinfo */
1573 code->prev = m->code;
1576 RT_TIMING_TIME_DIFF(time_start,time_checks,RT_TIMING_JIT_CHECKS);
1577 RT_TIMING_TIME_DIFF(time_checks,time_parse,RT_TIMING_JIT_PARSE);
1578 RT_TIMING_TIME_DIFF(time_parse,time_stack,RT_TIMING_JIT_STACK);
1579 RT_TIMING_TIME_DIFF(time_stack,time_typecheck,RT_TIMING_JIT_TYPECHECK);
1580 RT_TIMING_TIME_DIFF(time_typecheck,time_loop,RT_TIMING_JIT_LOOP);
1581 RT_TIMING_TIME_DIFF(time_loop,time_alloc,RT_TIMING_JIT_ALLOC);
1582 RT_TIMING_TIME_DIFF(time_alloc,time_codegen,RT_TIMING_JIT_CODEGEN);
1583 RT_TIMING_TIME_DIFF(time_start,time_codegen,RT_TIMING_JIT_TOTAL);
1585 /* return pointer to the methods entry point */
1587 return code->entrypoint;
1591 /* jit_invalidate_code *********************************************************
1593 Mark the compiled code of the given method as invalid and take care that
1594 it is replaced if necessary.
1596 XXX Not fully implemented, yet.
1598 *******************************************************************************/
1600 void jit_invalidate_code(methodinfo *m)
1605 if (code == NULL || CODE_IS_INVALID(code))
1608 CODE_SETFLAG_INVALID(code);
1610 /* activate mappable replacement points */
1612 #if defined(ENABLE_REPLACEMENT)
1613 replace_activate_replacement_points(code, true);
1615 vm_abort("invalidating code only works with ENABLE_REPLACEMENT");
1620 /* jit_request_optimization ****************************************************
1622 Request optimization of the given method. If the code of the method is
1623 unoptimized, it will be invalidated, so the next jit_get_current_code(m)
1624 triggers an optimized recompilation.
1625 If the method is already optimized, this function does nothing.
1628 m................the method
1630 *******************************************************************************/
1632 void jit_request_optimization(methodinfo *m)
1638 if (code && code->optlevel == 0)
1639 jit_invalidate_code(m);
1643 /* jit_get_current_code ********************************************************
1645 Get the currently valid code for the given method. If there is no valid
1646 code, (re)compile the method.
1649 m................the method
1652 the codeinfo* for the current code, or
1653 NULL if an exception has been thrown during recompilation.
1655 *******************************************************************************/
1657 codeinfo *jit_get_current_code(methodinfo *m)
1661 /* if we have valid code, return it */
1663 if (m->code && CODE_IS_VALID(m->code))
1666 /* otherwise: recompile */
1668 if (!jit_recompile(m))
1677 /* jit_asm_compile *************************************************************
1679 This method is called from asm_vm_call_method and does:
1681 - create stackframe info for exceptions
1682 - compile the method
1683 - patch the entrypoint of the method into the calculated address in
1685 - flushes the instruction cache.
1687 *******************************************************************************/
1689 #if defined(ENABLE_JIT)
1690 #if !defined(JIT_COMPILER_VIA_SIGNAL)
1691 u1 *jit_asm_compile(methodinfo *m, u1 *mptr, u1 *sp, u1 *ra)
1698 /* create the stackframeinfo (subtract 1 from RA as it points to the */
1699 /* instruction after the call) */
1701 stacktrace_stackframeinfo_add(&sfi, NULL, sp, ra, ra-1);
1703 /* actually compile the method */
1705 entrypoint = jit_compile(m);
1707 /* remove the stackframeinfo */
1709 stacktrace_stackframeinfo_remove(&sfi);
1711 /* there was a problem during compilation */
1713 if (entrypoint == NULL)
1716 /* get the method patch address */
1718 pa = md_jit_method_patch_address(sfi.pv, (void *) ra, mptr);
1720 /* patch the method entry point */
1724 *p = (ptrint) entrypoint;
1726 /* flush the instruction cache */
1728 md_icacheflush(pa, SIZEOF_VOID_P);
1734 /* jit_compile_handle **********************************************************
1736 This method is called from the appropriate signal handler which
1737 handles compiler-traps and does the following:
1739 - compile the method
1740 - patch the entrypoint of the method into the calculated address in
1742 - flush the instruction cache
1744 *******************************************************************************/
1746 void *jit_compile_handle(methodinfo *m, void *pv, void *ra, void *mptr)
1748 void *newpv; /* new compiled method PV */
1749 void *pa; /* patch address */
1750 uintptr_t *p; /* convenience pointer */
1752 /* Compile the method. */
1754 newpv = jit_compile(m);
1756 /* There was a problem during compilation. */
1761 /* Get the method patch address. */
1763 pa = md_jit_method_patch_address(pv, ra, mptr);
1765 /* Patch the method entry point. */
1767 p = (uintptr_t *) pa;
1769 *p = (uintptr_t) newpv;
1771 /* Flush both caches. */
1773 md_cacheflush(pa, SIZEOF_VOID_P);
1777 #endif /* defined(ENABLE_JIT) */
1780 /* jit_complement_condition ****************************************************
1782 Returns the complement of the passed conditional instruction.
1784 We use the order of the different conditions, e.g.:
1789 If the passed opcode is odd, we simply add 1 to get the complement.
1790 If the opcode is even, we subtract 1.
1797 *******************************************************************************/
1799 s4 jit_complement_condition(s4 opcode)
1803 return ICMD_IFNONNULL;
1805 case ICMD_IFNONNULL:
1809 /* check if opcode is odd */
1819 /* jit_renumber_basicblocks ****************************************************
1821 Set the ->nr of all blocks so it increases when traversing ->next.
1824 jitdata..........the current jitdata
1826 *******************************************************************************/
1828 void jit_renumber_basicblocks(jitdata *jd)
1834 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
1838 /* we have one block more than jd->basicblockcount (the end marker) */
1840 assert(nr == jd->basicblockcount + 1);
1844 /* jit_check_basicblock_numbers ************************************************
1846 Assert that the ->nr of the first block is zero and increases by 1 each
1847 time ->next is traversed.
1848 This function should be called before any analysis that relies on
1849 the basicblock numbers.
1852 jitdata..........the current jitdata
1854 NOTE: Aborts with an assertion if the condition is not met!
1856 *******************************************************************************/
1858 #if !defined(NDEBUG)
1859 void jit_check_basicblock_numbers(jitdata *jd)
1865 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
1866 assert(bptr->nr == nr);
1870 /* we have one block more than jd->basicblockcount (the end marker) */
1872 assert(nr == jd->basicblockcount + 1);
1874 #endif /* !defined(NDEBUG) */
1878 * These are local overrides for various environment variables in Emacs.
1879 * Please do not remove this and leave it at the end of the file, where
1880 * Emacs will automagically detect them.
1881 * ---------------------------------------------------------------------
1884 * indent-tabs-mode: t
1888 * vim:noexpandtab:sw=4:ts=4: