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)
956 /* allocate jitdata structure and fill it */
961 jd->cd = DNEW(codegendata);
962 jd->rd = DNEW(registerdata);
963 #if defined(ENABLE_LOOP)
964 jd->ld = DNEW(loopdata);
967 /* Allocate codeinfo memory from the heap as we need to keep them. */
969 code = code_codeinfo_new(m);
971 /* Set codeinfo flags. */
973 #if defined(ENABLE_THREADS)
974 if (checksync && (m->flags & ACC_SYNCHRONIZED))
975 code_flag_synchronized(code);
977 if (checksync && (m->flags & ACC_SYNCHRONIZED))
978 code_unflag_leafmethod(code);
981 code_flag_leafmethod(code);
983 /* initialize variables */
987 jd->exceptiontable = NULL;
988 jd->exceptiontablelength = 0;
990 jd->branchtoentry = false;
991 jd->branchtoend = false;
993 jd->returnblock = NULL;
994 jd->maxlocals = m->maxlocals;
1000 /* jit_compile *****************************************************************
1002 Translates one method to machine code.
1004 *******************************************************************************/
1006 static u1 *jit_compile_intern(jitdata *jd);
1008 u1 *jit_compile(methodinfo *m)
1014 STATISTICS(count_jit_calls++);
1016 /* Initialize the static function's class. */
1018 /* ATTENTION: This MUST be done before the method lock is aquired,
1019 otherwise we could run into a deadlock with <clinit>'s that
1020 call static methods of it's own class. */
1022 if ((m->flags & ACC_STATIC) && !(m->class->state & CLASS_INITIALIZED)) {
1023 #if !defined(NDEBUG)
1025 log_message_class("Initialize class ", m->class);
1028 if (!initialize_class(m->class))
1031 /* check if the method has been compiled during initialization */
1033 if ((m->code != NULL) && (m->code->entrypoint != NULL))
1034 return m->code->entrypoint;
1037 /* enter a monitor on the method */
1039 LOCK_MONITOR_ENTER(m);
1041 /* if method has been already compiled return immediately */
1043 if (m->code != NULL) {
1044 LOCK_MONITOR_EXIT(m);
1046 assert(m->code->entrypoint);
1047 return m->code->entrypoint;
1050 TRACECOMPILERCALLS();
1052 STATISTICS(count_methods++);
1054 #if defined(ENABLE_STATISTICS)
1057 if (opt_getcompilingtime)
1058 compilingtime_start();
1061 /* mark start of dump memory area */
1063 dumpsize = dump_size();
1065 /* create jitdata structure */
1067 jd = jit_jitdata_new(m);
1069 /* set the flags for the current JIT run */
1071 jd->flags = JITDATA_FLAG_PARSE;
1073 #if defined(ENABLE_VERIFIER)
1075 jd->flags |= JITDATA_FLAG_VERIFY;
1078 #if defined(ENABLE_PROFILING)
1080 jd->flags |= JITDATA_FLAG_INSTRUMENT;
1083 #if defined(ENABLE_IFCONV)
1085 jd->flags |= JITDATA_FLAG_IFCONV;
1088 #if defined(ENABLE_INLINING) && defined(ENABLE_INLINING_DEBUG)
1089 if (opt_inlining && opt_inline_debug_all)
1090 jd->flags |= JITDATA_FLAG_INLINE;
1093 if (opt_showintermediate)
1094 jd->flags |= JITDATA_FLAG_SHOWINTERMEDIATE;
1096 if (opt_showdisassemble)
1097 jd->flags |= JITDATA_FLAG_SHOWDISASSEMBLE;
1099 if (opt_verbosecall)
1100 jd->flags |= JITDATA_FLAG_VERBOSECALL;
1102 #if defined(ENABLE_REPLACEMENT) && defined(ENABLE_INLINING)
1104 jd->flags |= JITDATA_FLAG_COUNTDOWN;
1107 #if defined(ENABLE_JIT)
1108 # if defined(ENABLE_INTRP)
1111 /* initialize the register allocator */
1117 /* setup the codegendata memory */
1121 /* now call internal compile function */
1123 r = jit_compile_intern(jd);
1126 /* We had an exception! Finish stuff here if necessary. */
1128 /* release codeinfo */
1130 code_codeinfo_free(jd->code);
1132 #if defined(ENABLE_PROFILING)
1133 /* Release memory for basic block profiling information. */
1135 if (JITDATA_HAS_FLAG_INSTRUMENT(jd))
1136 if (jd->code->bbfrequency != NULL)
1137 MFREE(jd->code->bbfrequency, u4, jd->code->basicblockcount);
1141 DEBUG_JIT_COMPILEVERBOSE("Running: ");
1144 /* release dump area */
1146 dump_release(dumpsize);
1148 #if defined(ENABLE_STATISTICS)
1151 if (opt_getcompilingtime)
1152 compilingtime_stop();
1155 /* leave the monitor */
1157 LOCK_MONITOR_EXIT(m);
1159 /* return pointer to the methods entry point */
1165 /* jit_recompile ***************************************************************
1167 Recompiles a Java method.
1169 *******************************************************************************/
1171 u1 *jit_recompile(methodinfo *m)
1178 /* check for max. optimization level */
1180 optlevel = (m->code) ? m->code->optlevel : 0;
1183 if (optlevel == 1) {
1184 /* log_message_method("not recompiling: ", m); */
1189 DEBUG_JIT_COMPILEVERBOSE("Recompiling start: ");
1191 STATISTICS(count_jit_calls++);
1193 #if defined(ENABLE_STATISTICS)
1196 if (opt_getcompilingtime)
1197 compilingtime_start();
1200 /* mark start of dump memory area */
1202 dumpsize = dump_size();
1204 /* create jitdata structure */
1206 jd = jit_jitdata_new(m);
1208 /* set the current optimization level to the previous one plus 1 */
1210 jd->code->optlevel = optlevel + 1;
1212 /* get the optimization flags for the current JIT run */
1214 #if defined(ENABLE_VERIFIER)
1215 jd->flags |= JITDATA_FLAG_VERIFY;
1218 /* jd->flags |= JITDATA_FLAG_REORDER; */
1219 if (opt_showintermediate)
1220 jd->flags |= JITDATA_FLAG_SHOWINTERMEDIATE;
1221 if (opt_showdisassemble)
1222 jd->flags |= JITDATA_FLAG_SHOWDISASSEMBLE;
1223 if (opt_verbosecall)
1224 jd->flags |= JITDATA_FLAG_VERBOSECALL;
1226 #if defined(ENABLE_INLINING)
1228 jd->flags |= JITDATA_FLAG_INLINE;
1231 #if defined(ENABLE_JIT)
1232 # if defined(ENABLE_INTRP)
1235 /* initialize the register allocator */
1240 /* setup the codegendata memory */
1244 /* now call internal compile function */
1246 r = jit_compile_intern(jd);
1249 /* We had an exception! Finish stuff here if necessary. */
1251 /* release codeinfo */
1253 code_codeinfo_free(jd->code);
1256 /* release dump area */
1258 dump_release(dumpsize);
1260 #if defined(ENABLE_STATISTICS)
1263 if (opt_getcompilingtime)
1264 compilingtime_stop();
1267 DEBUG_JIT_COMPILEVERBOSE("Recompiling done: ");
1269 /* return pointer to the methods entry point */
1275 /* jit_compile_intern **********************************************************
1277 Static internal function which does the actual compilation.
1279 *******************************************************************************/
1281 static u1 *jit_compile_intern(jitdata *jd)
1287 #if defined(ENABLE_RT_TIMING)
1288 struct timespec time_start,time_checks,time_parse,time_stack,
1289 time_typecheck,time_loop,time_ifconv,time_alloc,
1293 RT_TIMING_GET_TIME(time_start);
1295 /* get required compiler data */
1297 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1304 #if defined(ENABLE_DEBUG_FILTER)
1305 show_filters_apply(jd->m);
1308 /* handle native methods and create a native stub */
1310 if (m->flags & ACC_NATIVE) {
1313 f = native_method_resolve(m);
1318 code = codegen_generate_stub_native(m, f);
1320 /* Native methods are never recompiled. */
1326 return code->entrypoint;
1329 /* if there is no javacode, print error message and return empty method */
1331 if (m->jcode == NULL) {
1332 DEBUG_JIT_COMPILEVERBOSE("No code given for: ");
1334 code->entrypoint = (u1 *) (ptrint) do_nothing_function;
1337 return code->entrypoint; /* return empty method */
1340 #if defined(ENABLE_STATISTICS)
1342 count_javacodesize += m->jcodelength + 18;
1343 count_tryblocks += jd->exceptiontablelength;
1344 count_javaexcsize += jd->exceptiontablelength * SIZEOF_VOID_P;
1348 RT_TIMING_GET_TIME(time_checks);
1350 #if defined(WITH_CLASSPATH_SUN)
1351 /* Code for Sun's OpenJDK (see
1352 hotspot/src/share/vm/classfile/verifier.cpp
1353 (Verifier::is_eligible_for_verification)): Don't verify
1354 dynamically-generated bytecodes. */
1356 # if defined(ENABLE_VERIFIER)
1357 if (class_issubclass(m->class, class_sun_reflect_MagicAccessorImpl))
1358 jd->flags &= ~JITDATA_FLAG_VERIFY;
1362 /* call the compiler passes ***********************************************/
1364 DEBUG_JIT_COMPILEVERBOSE("Parsing: ");
1366 /* call parse pass */
1369 DEBUG_JIT_COMPILEVERBOSE("Exception while parsing: ");
1373 RT_TIMING_GET_TIME(time_parse);
1375 DEBUG_JIT_COMPILEVERBOSE("Parsing done: ");
1377 #if defined(ENABLE_JIT)
1378 # if defined(ENABLE_INTRP)
1381 DEBUG_JIT_COMPILEVERBOSE("Analysing: ");
1383 /* call stack analysis pass */
1385 if (!stack_analyse(jd)) {
1386 DEBUG_JIT_COMPILEVERBOSE("Exception while analysing: ");
1390 RT_TIMING_GET_TIME(time_stack);
1392 DEBUG_JIT_COMPILEVERBOSE("Analysing done: ");
1394 /* Build the CFG. This has to be done after stack_analyse, as
1395 there happens the JSR elimination. */
1400 #ifdef ENABLE_VERIFIER
1401 if (JITDATA_HAS_FLAG_VERIFY(jd)) {
1402 DEBUG_JIT_COMPILEVERBOSE("Typechecking: ");
1404 /* call typecheck pass */
1405 if (!typecheck(jd)) {
1406 DEBUG_JIT_COMPILEVERBOSE("Exception while typechecking: ");
1411 DEBUG_JIT_COMPILEVERBOSE("Typechecking done: ");
1414 RT_TIMING_GET_TIME(time_typecheck);
1416 #if defined(ENABLE_LOOP)
1421 jit_renumber_basicblocks(jd);
1424 RT_TIMING_GET_TIME(time_loop);
1426 #if defined(ENABLE_IFCONV)
1427 if (JITDATA_HAS_FLAG_IFCONV(jd)) {
1428 if (!ifconv_static(jd))
1430 jit_renumber_basicblocks(jd);
1433 RT_TIMING_GET_TIME(time_ifconv);
1437 #if defined(ENABLE_INLINING)
1438 if (JITDATA_HAS_FLAG_INLINE(jd)) {
1439 if (!inline_inline(jd))
1444 #if defined(ENABLE_PROFILING)
1445 /* Basic block reordering. I think this should be done after
1446 if-conversion, as we could lose the ability to do the
1449 if (JITDATA_HAS_FLAG_REORDER(jd)) {
1452 jit_renumber_basicblocks(jd);
1456 DEBUG_JIT_COMPILEVERBOSE("Allocating registers: ");
1458 #if defined(ENABLE_LSRA) && !defined(ENABLE_SSA)
1459 /* allocate registers */
1464 STATISTICS(count_methods_allocated_by_lsra++);
1467 # endif /* defined(ENABLE_LSRA) && !defined(ENABLE_SSA) */
1468 #if defined(ENABLE_SSA)
1469 /* allocate registers */
1470 if ((opt_lsra) && (jd->exceptiontablelength == 0)) {
1471 jd->ls = DNEW(lsradata);
1474 STATISTICS(count_methods_allocated_by_lsra++);
1477 # endif /* defined(ENABLE_SSA) */
1479 STATISTICS(count_locals_conflicts += (jd->maxlocals - 1) * (jd->maxlocals));
1484 STATISTICS(simplereg_make_statistics(jd));
1486 DEBUG_JIT_COMPILEVERBOSE("Allocating registers done: ");
1487 # if defined(ENABLE_INTRP)
1490 #endif /* defined(ENABLE_JIT) */
1491 RT_TIMING_GET_TIME(time_alloc);
1493 #if defined(ENABLE_PROFILING)
1494 /* Allocate memory for basic block profiling information. This
1495 _must_ be done after loop optimization and register allocation,
1496 since they can change the basic block count. */
1498 if (JITDATA_HAS_FLAG_INSTRUMENT(jd))
1499 code->bbfrequency = MNEW(u4, jd->basicblockcount);
1502 DEBUG_JIT_COMPILEVERBOSE("Generating code: ");
1504 /* now generate the machine code */
1506 #if defined(ENABLE_JIT)
1507 # if defined(ENABLE_INTRP)
1509 #if defined(ENABLE_VERIFIER)
1511 DEBUG_JIT_COMPILEVERBOSE("Typechecking (stackbased): ");
1513 if (!typecheck_stackbased(jd)) {
1514 DEBUG_JIT_COMPILEVERBOSE("Exception while typechecking (stackbased): ");
1519 if (!intrp_codegen(jd)) {
1520 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1527 if (!codegen_generate(jd)) {
1528 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1534 if (!intrp_codegen(jd)) {
1535 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1540 RT_TIMING_GET_TIME(time_codegen);
1542 DEBUG_JIT_COMPILEVERBOSE("Generating code done: ");
1544 #if !defined(NDEBUG) && defined(ENABLE_REPLACEMENT)
1545 /* activate replacement points inside newly created code */
1547 if (opt_TestReplacement)
1548 replace_activate_replacement_points(code, false);
1551 #if !defined(NDEBUG)
1552 #if defined(ENABLE_DEBUG_FILTER)
1553 if (jd->m->filtermatches & SHOW_FILTER_FLAG_SHOW_METHOD)
1556 /* intermediate and assembly code listings */
1558 if (JITDATA_HAS_FLAG_SHOWINTERMEDIATE(jd)) {
1559 show_method(jd, SHOW_CODE);
1561 else if (JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd)) {
1562 # if defined(ENABLE_DISASSEMBLER)
1563 DISASSEMBLE(code->entrypoint,
1564 code->entrypoint + (code->mcodelength - cd->dseglen));
1568 if (opt_showddatasegment)
1573 /* switch to the newly generated code */
1576 assert(code->entrypoint);
1578 /* add the current compile version to the methodinfo */
1580 code->prev = m->code;
1583 RT_TIMING_TIME_DIFF(time_start,time_checks,RT_TIMING_JIT_CHECKS);
1584 RT_TIMING_TIME_DIFF(time_checks,time_parse,RT_TIMING_JIT_PARSE);
1585 RT_TIMING_TIME_DIFF(time_parse,time_stack,RT_TIMING_JIT_STACK);
1586 RT_TIMING_TIME_DIFF(time_stack,time_typecheck,RT_TIMING_JIT_TYPECHECK);
1587 RT_TIMING_TIME_DIFF(time_typecheck,time_loop,RT_TIMING_JIT_LOOP);
1588 RT_TIMING_TIME_DIFF(time_loop,time_alloc,RT_TIMING_JIT_ALLOC);
1589 RT_TIMING_TIME_DIFF(time_alloc,time_codegen,RT_TIMING_JIT_CODEGEN);
1590 RT_TIMING_TIME_DIFF(time_start,time_codegen,RT_TIMING_JIT_TOTAL);
1592 /* return pointer to the methods entry point */
1594 return code->entrypoint;
1598 /* jit_invalidate_code *********************************************************
1600 Mark the compiled code of the given method as invalid and take care that
1601 it is replaced if necessary.
1603 XXX Not fully implemented, yet.
1605 *******************************************************************************/
1607 void jit_invalidate_code(methodinfo *m)
1613 if (code == NULL || code_is_invalid(code))
1616 code_flag_invalid(code);
1618 /* activate mappable replacement points */
1620 #if defined(ENABLE_REPLACEMENT)
1621 replace_activate_replacement_points(code, true);
1623 vm_abort("invalidating code only works with ENABLE_REPLACEMENT");
1628 /* jit_request_optimization ****************************************************
1630 Request optimization of the given method. If the code of the method is
1631 unoptimized, it will be invalidated, so the next jit_get_current_code(m)
1632 triggers an optimized recompilation.
1633 If the method is already optimized, this function does nothing.
1636 m................the method
1638 *******************************************************************************/
1640 void jit_request_optimization(methodinfo *m)
1646 if (code && code->optlevel == 0)
1647 jit_invalidate_code(m);
1651 /* jit_get_current_code ********************************************************
1653 Get the currently valid code for the given method. If there is no valid
1654 code, (re)compile the method.
1657 m................the method
1660 the codeinfo* for the current code, or
1661 NULL if an exception has been thrown during recompilation.
1663 *******************************************************************************/
1665 codeinfo *jit_get_current_code(methodinfo *m)
1669 /* if we have valid code, return it */
1671 if (m->code && !code_is_invalid(m->code))
1674 /* otherwise: recompile */
1676 if (!jit_recompile(m))
1685 /* jit_asm_compile *************************************************************
1687 This method is called from asm_vm_call_method and does:
1689 - create stackframe info for exceptions
1690 - compile the method
1691 - patch the entrypoint of the method into the calculated address in
1693 - flushes the instruction cache.
1695 *******************************************************************************/
1697 #if defined(ENABLE_JIT)
1698 #if !defined(JIT_COMPILER_VIA_SIGNAL)
1699 u1 *jit_asm_compile(methodinfo *m, u1 *mptr, u1 *sp, u1 *ra)
1706 /* create the stackframeinfo (subtract 1 from RA as it points to the */
1707 /* instruction after the call) */
1709 stacktrace_stackframeinfo_add(&sfi, NULL, sp, ra, ra-1);
1711 /* actually compile the method */
1713 entrypoint = jit_compile(m);
1715 /* remove the stackframeinfo */
1717 stacktrace_stackframeinfo_remove(&sfi);
1719 /* there was a problem during compilation */
1721 if (entrypoint == NULL)
1724 /* get the method patch address */
1726 pa = md_jit_method_patch_address(sfi.pv, (void *) ra, mptr);
1728 /* patch the method entry point */
1732 *p = (ptrint) entrypoint;
1734 /* flush the instruction cache */
1736 md_icacheflush(pa, SIZEOF_VOID_P);
1742 /* jit_compile_handle **********************************************************
1744 This method is called from the appropriate signal handler which
1745 handles compiler-traps and does the following:
1747 - compile the method
1748 - patch the entrypoint of the method into the calculated address in
1750 - flush the instruction cache
1752 *******************************************************************************/
1754 void *jit_compile_handle(methodinfo *m, void *pv, void *ra, void *mptr)
1756 void *newpv; /* new compiled method PV */
1757 void *pa; /* patch address */
1758 uintptr_t *p; /* convenience pointer */
1760 /* Compile the method. */
1762 newpv = jit_compile(m);
1764 /* There was a problem during compilation. */
1769 /* Get the method patch address. */
1771 pa = md_jit_method_patch_address(pv, ra, mptr);
1773 /* Patch the method entry point. */
1775 p = (uintptr_t *) pa;
1777 *p = (uintptr_t) newpv;
1779 /* Flush both caches. */
1781 md_cacheflush(pa, SIZEOF_VOID_P);
1785 #endif /* defined(ENABLE_JIT) */
1788 /* jit_complement_condition ****************************************************
1790 Returns the complement of the passed conditional instruction.
1792 We use the order of the different conditions, e.g.:
1797 If the passed opcode is odd, we simply add 1 to get the complement.
1798 If the opcode is even, we subtract 1.
1805 *******************************************************************************/
1807 s4 jit_complement_condition(s4 opcode)
1811 return ICMD_IFNONNULL;
1813 case ICMD_IFNONNULL:
1817 /* check if opcode is odd */
1827 /* jit_renumber_basicblocks ****************************************************
1829 Set the ->nr of all blocks so it increases when traversing ->next.
1832 jitdata..........the current jitdata
1834 *******************************************************************************/
1836 void jit_renumber_basicblocks(jitdata *jd)
1842 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
1846 /* we have one block more than jd->basicblockcount (the end marker) */
1848 assert(nr == jd->basicblockcount + 1);
1852 /* jit_check_basicblock_numbers ************************************************
1854 Assert that the ->nr of the first block is zero and increases by 1 each
1855 time ->next is traversed.
1856 This function should be called before any analysis that relies on
1857 the basicblock numbers.
1860 jitdata..........the current jitdata
1862 NOTE: Aborts with an assertion if the condition is not met!
1864 *******************************************************************************/
1866 #if !defined(NDEBUG)
1867 void jit_check_basicblock_numbers(jitdata *jd)
1873 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
1874 assert(bptr->nr == nr);
1878 /* we have one block more than jd->basicblockcount (the end marker) */
1880 assert(nr == jd->basicblockcount + 1);
1882 #endif /* !defined(NDEBUG) */
1886 * These are local overrides for various environment variables in Emacs.
1887 * Please do not remove this and leave it at the end of the file, where
1888 * Emacs will automagically detect them.
1889 * ---------------------------------------------------------------------
1892 * indent-tabs-mode: t
1896 * vim:noexpandtab:sw=4:ts=4: