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
37 #include "mm/memory.h"
39 #include "native/native.h"
41 #include "toolbox/logging.h"
43 #include "threads/lock-common.h"
44 #include "threads/threads-common.h"
46 #include "vm/global.h"
47 #include "vm/initialize.h"
49 #include "vm/jit/asmpart.h"
51 # include "vm/jit/cfg.h"
53 #include "vm/jit/codegen-common.h"
54 #include "vm/jit/disass.h"
55 #include "vm/jit/dseg.h"
56 #include "vm/jit/jit.h"
57 #include "vm/jit/parse.h"
58 #include "vm/jit/reg.h"
60 #include "vm/jit/show.h"
61 #include "vm/jit/stack.h"
63 #include "vm/jit/allocator/simplereg.h"
64 #if defined(ENABLE_LSRA) && !defined(ENABLE_SSA)
65 # include "vm/jit/allocator/lsra.h"
67 #if defined(ENABLE_SSA)
68 # include "vm/jit/optimizing/lsra.h"
69 # include "vm/jit/optimizing/ssa.h"
72 #if defined(ENABLE_INLINING)
73 # include "vm/jit/inline/inline.h"
76 #include "vm/jit/loop/analyze.h"
77 #include "vm/jit/loop/graph.h"
78 #include "vm/jit/loop/loop.h"
80 #if defined(ENABLE_IFCONV)
81 # include "vm/jit/optimizing/ifconv.h"
84 #include "vm/jit/optimizing/reorder.h"
86 #include "vm/jit/verify/typecheck.h"
88 #include "vmcore/class.h"
89 #include "vmcore/loader.h"
90 #include "vmcore/method.h"
91 #include "vmcore/options.h"
92 #include "vmcore/rt-timing.h"
93 #include "vmcore/statistics.h"
96 /* debug macros ***************************************************************/
99 #define DEBUG_JIT_COMPILEVERBOSE(x) \
101 if (compileverbose) { \
102 log_message_method(x, m); \
106 #define DEBUG_JIT_COMPILEVERBOSE(x) /* nothing */
110 # define TRACECOMPILERCALLS() \
112 if (opt_TraceCompilerCalls) { \
114 log_print("[JIT compiler started: method="); \
121 # define TRACECOMPILERCALLS()
125 /* the ICMD table ************************************************************/
128 #define N(name) name,
133 /* abbreviations for flags */
135 #define PEI ICMDTABLE_PEI
136 #define CALLS ICMDTABLE_CALLS
138 /* some machine dependent values */
143 #define IDIV_CALLS ICMDTABLE_CALLS
146 #if (SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
149 #define LDIV_CALLS ICMDTABLE_CALLS
152 /* include the actual table */
154 icmdtable_entry_t icmd_table[256] = {
155 #include <vm/jit/icmdtable.inc>
162 /* XXX hack until the old "PEI" definition is removed */
166 /* stackelement requirements of Java opcodes **********************************/
168 int stackreq[256] = {
170 1, /* JAVA_ACONST 1 */
171 1, /* JAVA_ICONST_M1 2 */
172 1, /* JAVA_ICONST_0 3 */
173 1, /* JAVA_ICONST_1 4 */
174 1, /* JAVA_ICONST_2 5 */
175 1, /* JAVA_ICONST_3 6 */
176 1, /* JAVA_ICONST_4 7 */
177 1, /* JAVA_ICONST_5 8 */
178 1, /* JAVA_LCONST_0 9 */
179 1, /* JAVA_LCONST_1 10 */
180 1, /* JAVA_FCONST_0 11 */
181 1, /* JAVA_FCONST_1 12 */
182 1, /* JAVA_FCONST_2 13 */
183 1, /* JAVA_DCONST_0 14 */
184 1, /* JAVA_DCONST_1 15 */
185 1, /* JAVA_BIPUSH 16 */
186 1, /* JAVA_SIPUSH 17 */
188 1, /* JAVA_LDC_W 19 */
189 1, /* JAVA_LDC2_W 20 */
190 1, /* JAVA_ILOAD 21 */
191 1, /* JAVA_LLOAD 22 */
192 1, /* JAVA_FLOAD 23 */
193 1, /* JAVA_DLOAD 24 */
194 1, /* JAVA_ALOAD 25 */
195 1, /* JAVA_ILOAD_0 26 */
196 1, /* JAVA_ILOAD_1 27 */
197 1, /* JAVA_ILOAD_2 28 */
198 1, /* JAVA_ILOAD_3 29 */
199 1, /* JAVA_LLOAD_0 30 */
200 1, /* JAVA_LLOAD_1 31 */
201 1, /* JAVA_LLOAD_2 32 */
202 1, /* JAVA_LLOAD_3 33 */
203 1, /* JAVA_FLOAD_0 34 */
204 1, /* JAVA_FLOAD_1 35 */
205 1, /* JAVA_FLOAD_2 36 */
206 1, /* JAVA_FLOAD_3 37 */
207 1, /* JAVA_DLOAD_0 38 */
208 1, /* JAVA_DLOAD_1 39 */
209 1, /* JAVA_DLOAD_2 40 */
210 1, /* JAVA_DLOAD_3 41 */
211 1, /* JAVA_ALOAD_0 42 */
212 1, /* JAVA_ALOAD_1 43 */
213 1, /* JAVA_ALOAD_2 44 */
214 1, /* JAVA_ALOAD_3 45 */
215 1, /* JAVA_IALOAD 46 */
216 1, /* JAVA_LALOAD 47 */
217 1, /* JAVA_FALOAD 48 */
218 1, /* JAVA_DALOAD 49 */
219 1, /* JAVA_AALOAD 50 */
220 1, /* JAVA_BALOAD 51 */
221 1, /* JAVA_CALOAD 52 */
222 1, /* JAVA_SALOAD 53 */
223 0, /* JAVA_ISTORE 54 */
224 0, /* JAVA_LSTORE 55 */
225 0, /* JAVA_FSTORE 56 */
226 0, /* JAVA_DSTORE 57 */
227 0, /* JAVA_ASTORE 58 */
228 0, /* JAVA_ISTORE_0 59 */
229 0, /* JAVA_ISTORE_1 60 */
230 0, /* JAVA_ISTORE_2 61 */
231 0, /* JAVA_ISTORE_3 62 */
232 0, /* JAVA_LSTORE_0 63 */
233 0, /* JAVA_LSTORE_1 64 */
234 0, /* JAVA_LSTORE_2 65 */
235 0, /* JAVA_LSTORE_3 66 */
236 0, /* JAVA_FSTORE_0 67 */
237 0, /* JAVA_FSTORE_1 68 */
238 0, /* JAVA_FSTORE_2 69 */
239 0, /* JAVA_FSTORE_3 70 */
240 0, /* JAVA_DSTORE_0 71 */
241 0, /* JAVA_DSTORE_1 72 */
242 0, /* JAVA_DSTORE_2 73 */
243 0, /* JAVA_DSTORE_3 74 */
244 0, /* JAVA_ASTORE_0 75 */
245 0, /* JAVA_ASTORE_1 76 */
246 0, /* JAVA_ASTORE_2 77 */
247 0, /* JAVA_ASTORE_3 78 */
248 0, /* JAVA_IASTORE 79 */
249 0, /* JAVA_LASTORE 80 */
250 0, /* JAVA_FASTORE 81 */
251 0, /* JAVA_DASTORE 82 */
252 0, /* JAVA_AASTORE 83 */
253 0, /* JAVA_BASTORE 84 */
254 0, /* JAVA_CASTORE 85 */
255 0, /* JAVA_SASTORE 86 */
257 0, /* JAVA_POP2 88 */
259 1+3, /* JAVA_DUP_X1 90 */
260 2+4, /* JAVA_DUP_X2 91 */
261 2, /* JAVA_DUP2 92 */
262 2+5, /* JAVA_DUP2_X1 93 */
263 3+6, /* JAVA_DUP2_X2 94 */
264 1+2, /* JAVA_SWAP 95 */
265 1, /* JAVA_IADD 96 */
266 1, /* JAVA_LADD 97 */
267 1, /* JAVA_FADD 98 */
268 1, /* JAVA_DADD 99 */
269 1, /* JAVA_ISUB 100 */
270 1, /* JAVA_LSUB 101 */
271 1, /* JAVA_FSUB 102 */
272 1, /* JAVA_DSUB 103 */
273 1, /* JAVA_IMUL 104 */
274 1, /* JAVA_LMUL 105 */
275 1, /* JAVA_FMUL 106 */
276 1, /* JAVA_DMUL 107 */
277 1, /* JAVA_IDIV 108 */
278 1, /* JAVA_LDIV 109 */
279 1, /* JAVA_FDIV 110 */
280 1, /* JAVA_DDIV 111 */
281 1, /* JAVA_IREM 112 */
282 1, /* JAVA_LREM 113 */
283 1, /* JAVA_FREM 114 */
284 1, /* JAVA_DREM 115 */
285 1, /* JAVA_INEG 116 */
286 1, /* JAVA_LNEG 117 */
287 1, /* JAVA_FNEG 118 */
288 1, /* JAVA_DNEG 119 */
289 1, /* JAVA_ISHL 120 */
290 1, /* JAVA_LSHL 121 */
291 1, /* JAVA_ISHR 122 */
292 1, /* JAVA_LSHR 123 */
293 1, /* JAVA_IUSHR 124 */
294 1, /* JAVA_LUSHR 125 */
295 1, /* JAVA_IAND 126 */
296 1, /* JAVA_LAND 127 */
297 1, /* JAVA_IOR 128 */
298 1, /* JAVA_LOR 129 */
299 1, /* JAVA_IXOR 130 */
300 1, /* JAVA_LXOR 131 */
301 0, /* JAVA_IINC 132 */
302 1, /* JAVA_I2L 133 */
303 1, /* JAVA_I2F 134 */
304 1, /* JAVA_I2D 135 */
305 1, /* JAVA_L2I 136 */
306 1, /* JAVA_L2F 137 */
307 1, /* JAVA_L2D 138 */
308 1, /* JAVA_F2I 139 */
309 1, /* JAVA_F2L 140 */
310 1, /* JAVA_F2D 141 */
311 1, /* JAVA_D2I 142 */
312 1, /* JAVA_D2L 143 */
313 1, /* JAVA_D2F 144 */
314 1, /* JAVA_INT2BYTE 145 */
315 1, /* JAVA_INT2CHAR 146 */
316 1, /* JAVA_INT2SHORT 147 */
317 1, /* JAVA_LCMP 148 */
318 1, /* JAVA_FCMPL 149 */
319 1, /* JAVA_FCMPG 150 */
320 1, /* JAVA_DCMPL 151 */
321 1, /* JAVA_DCMPG 152 */
322 0, /* JAVA_IFEQ 153 */
323 0, /* JAVA_IFNE 154 */
324 0, /* JAVA_IFLT 155 */
325 0, /* JAVA_IFGE 156 */
326 0, /* JAVA_IFGT 157 */
327 0, /* JAVA_IFLE 158 */
328 0, /* JAVA_IF_ICMPEQ 159 */
329 0, /* JAVA_IF_ICMPNE 160 */
330 0, /* JAVA_IF_ICMPLT 161 */
331 0, /* JAVA_IF_ICMPGE 162 */
332 0, /* JAVA_IF_ICMPGT 163 */
333 0, /* JAVA_IF_ICMPLE 164 */
334 0, /* JAVA_IF_ACMPEQ 165 */
335 0, /* JAVA_IF_ACMPNE 166 */
336 0, /* JAVA_GOTO 167 */
337 1, /* JAVA_JSR 168 */
338 0, /* JAVA_RET 169 */
339 0, /* JAVA_TABLESWITCH 170 */
340 0, /* JAVA_LOOKUPSWITCH 171 */
341 0, /* JAVA_IRETURN 172 */
342 0, /* JAVA_LRETURN 173 */
343 0, /* JAVA_FRETURN 174 */
344 0, /* JAVA_DRETURN 175 */
345 0, /* JAVA_ARETURN 176 */
346 0, /* JAVA_RETURN 177 */
347 1, /* JAVA_GETSTATIC 178 */
348 0, /* JAVA_PUTSTATIC 179 */
349 1, /* JAVA_GETFIELD 180 */
350 0, /* JAVA_PUTFIELD 181 */
351 1, /* JAVA_INVOKEVIRTUAL 182 */
352 1, /* JAVA_INVOKESPECIAL 183 */
353 1, /* JAVA_INVOKESTATIC 184 */
354 1, /* JAVA_INVOKEINTERFACE 185 */
355 1, /* JAVA_UNDEF186 186 */
356 1, /* JAVA_NEW 187 */
357 1, /* JAVA_NEWARRAY 188 */
358 1, /* JAVA_ANEWARRAY 189 */
359 1, /* JAVA_ARRAYLENGTH 190 */
360 1, /* JAVA_ATHROW 191 */
361 1, /* JAVA_CHECKCAST 192 */
362 1, /* JAVA_INSTANCEOF 193 */
363 0, /* JAVA_MONITORENTER 194 */
364 0, /* JAVA_MONITOREXIT 195 */
365 0, /* JAVA_WIDE 196 */
366 1, /* JAVA_MULTIANEWARRAY 197 */
367 0, /* JAVA_IFNULL 198 */
368 0, /* JAVA_IFNONNULL 199 */
369 0, /* JAVA_GOTO_W 200 */
370 1, /* JAVA_JSR_W 201 */
371 0, /* JAVA_BREAKPOINT 202 */
372 1, /* JAVA_UNDEF203 203 */
373 1, /* JAVA_UNDEF204 204 */
374 1, /* JAVA_UNDEF205 205 */
375 1, /* JAVA_UNDEF206 206 */
376 1, /* JAVA_UNDEF207 207 */
377 1, /* JAVA_UNDEF208 208 */
378 1, /* JAVA_UNDEF209 209 */
379 1, /* JAVA_UNDEF210 210 */
380 1, /* JAVA_UNDEF211 211 */
381 1, /* JAVA_UNDEF212 212 */
382 1, /* JAVA_UNDEF213 213 */
383 1, /* JAVA_UNDEF214 214 */
384 1, /* JAVA_UNDEF215 215 */
385 1, /* JAVA_UNDEF216 216 */
386 1, /* JAVA_UNDEF217 217 */
387 1, /* JAVA_UNDEF218 218 */
388 1, /* JAVA_UNDEF219 219 */
389 1, /* JAVA_UNDEF220 220 */
390 1, /* JAVA_UNDEF221 221 */
391 1, /* JAVA_UNDEF222 222 */
392 1, /* JAVA_UNDEF223 223 */
393 1, /* JAVA_UNDEF224 224 */
394 1, /* JAVA_UNDEF225 225 */
395 1, /* JAVA_UNDEF226 226 */
396 1, /* JAVA_UNDEF227 227 */
397 1, /* JAVA_UNDEF228 228 */
398 1, /* JAVA_UNDEF229 229 */
399 1, /* JAVA_UNDEF230 230 */
400 1, /* JAVA_UNDEF231 231 */
401 1, /* JAVA_UNDEF232 232 */
402 1, /* JAVA_UNDEF233 233 */
403 1, /* JAVA_UNDEF234 234 */
404 1, /* JAVA_UNDEF235 235 */
405 1, /* JAVA_UNDEF236 236 */
406 1, /* JAVA_UNDEF237 237 */
407 1, /* JAVA_UNDEF238 238 */
408 1, /* JAVA_UNDEF239 239 */
409 1, /* JAVA_UNDEF240 240 */
410 1, /* JAVA_UNDEF241 241 */
411 1, /* JAVA_UNDEF242 242 */
412 1, /* JAVA_UNDEF243 243 */
413 1, /* JAVA_UNDEF244 244 */
414 1, /* JAVA_UNDEF245 245 */
415 1, /* JAVA_UNDEF246 246 */
416 1, /* JAVA_UNDEF247 247 */
417 1, /* JAVA_UNDEF248 248 */
418 1, /* JAVA_UNDEF249 249 */
419 1, /* JAVA_UNDEF250 250 */
420 1, /* JAVA_UNDEF251 251 */
421 1, /* JAVA_UNDEF252 252 */
422 1, /* JAVA_UNDEF253 253 */
423 1, /* JAVA_UNDEF254 254 */
424 1, /* JAVA_UNDEF255 255 */
428 /* size in bytes of Java opcodes **********************************************/
430 int jcommandsize[256] = {
433 1, /* JAVA_ACONST_NULL 1 */
434 1, /* JAVA_ICONST_M1 2 */
435 1, /* JAVA_ICONST_0 3 */
436 1, /* JAVA_ICONST_1 4 */
437 1, /* JAVA_ICONST_2 5 */
438 1, /* JAVA_ICONST_3 6 */
439 1, /* JAVA_ICONST_4 7 */
440 1, /* JAVA_ICONST_5 8 */
441 1, /* JAVA_LCONST_0 9 */
442 1, /* JAVA_LCONST_1 10 */
443 1, /* JAVA_FCONST_0 11 */
444 1, /* JAVA_FCONST_1 12 */
445 1, /* JAVA_FCONST_2 13 */
446 1, /* JAVA_DCONST_0 14 */
447 1, /* JAVA_DCONST_1 15 */
448 2, /* JAVA_BIPUSH 16 */
449 3, /* JAVA_SIPUSH 17 */
450 2, /* JAVA_LDC1 18 */
451 3, /* JAVA_LDC2 19 */
452 3, /* JAVA_LDC2W 20 */
453 2, /* JAVA_ILOAD 21 */
454 2, /* JAVA_LLOAD 22 */
455 2, /* JAVA_FLOAD 23 */
456 2, /* JAVA_DLOAD 24 */
457 2, /* JAVA_ALOAD 25 */
458 1, /* JAVA_ILOAD_0 26 */
459 1, /* JAVA_ILOAD_1 27 */
460 1, /* JAVA_ILOAD_2 28 */
461 1, /* JAVA_ILOAD_3 29 */
462 1, /* JAVA_LLOAD_0 30 */
463 1, /* JAVA_LLOAD_1 31 */
464 1, /* JAVA_LLOAD_2 32 */
465 1, /* JAVA_LLOAD_3 33 */
466 1, /* JAVA_FLOAD_0 34 */
467 1, /* JAVA_FLOAD_1 35 */
468 1, /* JAVA_FLOAD_2 36 */
469 1, /* JAVA_FLOAD_3 37 */
470 1, /* JAVA_DLOAD_0 38 */
471 1, /* JAVA_DLOAD_1 39 */
472 1, /* JAVA_DLOAD_2 40 */
473 1, /* JAVA_DLOAD_3 41 */
474 1, /* JAVA_ALOAD_0 42 */
475 1, /* JAVA_ALOAD_1 43 */
476 1, /* JAVA_ALOAD_2 44 */
477 1, /* JAVA_ALOAD_3 45 */
478 1, /* JAVA_IALOAD 46 */
479 1, /* JAVA_LALOAD 47 */
480 1, /* JAVA_FALOAD 48 */
481 1, /* JAVA_DALOAD 49 */
482 1, /* JAVA_AALOAD 50 */
483 1, /* JAVA_BALOAD 51 */
484 1, /* JAVA_CALOAD 52 */
485 1, /* JAVA_SALOAD 53 */
486 2, /* JAVA_ISTORE 54 */
487 2, /* JAVA_LSTORE 55 */
488 2, /* JAVA_FSTORE 56 */
489 2, /* JAVA_DSTORE 57 */
490 2, /* JAVA_ASTORE 58 */
491 1, /* JAVA_ISTORE_0 59 */
492 1, /* JAVA_ISTORE_1 60 */
493 1, /* JAVA_ISTORE_2 61 */
494 1, /* JAVA_ISTORE_3 62 */
495 1, /* JAVA_LSTORE_0 63 */
496 1, /* JAVA_LSTORE_1 64 */
497 1, /* JAVA_LSTORE_2 65 */
498 1, /* JAVA_LSTORE_3 66 */
499 1, /* JAVA_FSTORE_0 67 */
500 1, /* JAVA_FSTORE_1 68 */
501 1, /* JAVA_FSTORE_2 69 */
502 1, /* JAVA_FSTORE_3 70 */
503 1, /* JAVA_DSTORE_0 71 */
504 1, /* JAVA_DSTORE_1 72 */
505 1, /* JAVA_DSTORE_2 73 */
506 1, /* JAVA_DSTORE_3 74 */
507 1, /* JAVA_ASTORE_0 75 */
508 1, /* JAVA_ASTORE_1 76 */
509 1, /* JAVA_ASTORE_2 77 */
510 1, /* JAVA_ASTORE_3 78 */
511 1, /* JAVA_IASTORE 79 */
512 1, /* JAVA_LASTORE 80 */
513 1, /* JAVA_FASTORE 81 */
514 1, /* JAVA_DASTORE 82 */
515 1, /* JAVA_AASTORE 83 */
516 1, /* JAVA_BASTORE 84 */
517 1, /* JAVA_CASTORE 85 */
518 1, /* JAVA_SASTORE 86 */
520 1, /* JAVA_POP2 88 */
522 1, /* JAVA_DUP_X1 90 */
523 1, /* JAVA_DUP_X2 91 */
524 1, /* JAVA_DUP2 92 */
525 1, /* JAVA_DUP2_X1 93 */
526 1, /* JAVA_DUP2_X2 94 */
527 1, /* JAVA_SWAP 95 */
528 1, /* JAVA_IADD 96 */
529 1, /* JAVA_LADD 97 */
530 1, /* JAVA_FADD 98 */
531 1, /* JAVA_DADD 99 */
532 1, /* JAVA_ISUB 100 */
533 1, /* JAVA_LSUB 101 */
534 1, /* JAVA_FSUB 102 */
535 1, /* JAVA_DSUB 103 */
536 1, /* JAVA_IMUL 104 */
537 1, /* JAVA_LMUL 105 */
538 1, /* JAVA_FMUL 106 */
539 1, /* JAVA_DMUL 107 */
540 1, /* JAVA_IDIV 108 */
541 1, /* JAVA_LDIV 109 */
542 1, /* JAVA_FDIV 110 */
543 1, /* JAVA_DDIV 111 */
544 1, /* JAVA_IREM 112 */
545 1, /* JAVA_LREM 113 */
546 1, /* JAVA_FREM 114 */
547 1, /* JAVA_DREM 115 */
548 1, /* JAVA_INEG 116 */
549 1, /* JAVA_LNEG 117 */
550 1, /* JAVA_FNEG 118 */
551 1, /* JAVA_DNEG 119 */
552 1, /* JAVA_ISHL 120 */
553 1, /* JAVA_LSHL 121 */
554 1, /* JAVA_ISHR 122 */
555 1, /* JAVA_LSHR 123 */
556 1, /* JAVA_IUSHR 124 */
557 1, /* JAVA_LUSHR 125 */
558 1, /* JAVA_IAND 126 */
559 1, /* JAVA_LAND 127 */
560 1, /* JAVA_IOR 128 */
561 1, /* JAVA_LOR 129 */
562 1, /* JAVA_IXOR 130 */
563 1, /* JAVA_LXOR 131 */
564 3, /* JAVA_IINC 132 */
565 1, /* JAVA_I2L 133 */
566 1, /* JAVA_I2F 134 */
567 1, /* JAVA_I2D 135 */
568 1, /* JAVA_L2I 136 */
569 1, /* JAVA_L2F 137 */
570 1, /* JAVA_L2D 138 */
571 1, /* JAVA_F2I 139 */
572 1, /* JAVA_F2L 140 */
573 1, /* JAVA_F2D 141 */
574 1, /* JAVA_D2I 142 */
575 1, /* JAVA_D2L 143 */
576 1, /* JAVA_D2F 144 */
577 1, /* JAVA_INT2BYTE 145 */
578 1, /* JAVA_INT2CHAR 146 */
579 1, /* JAVA_INT2SHORT 147 */
580 1, /* JAVA_LCMP 148 */
581 1, /* JAVA_FCMPL 149 */
582 1, /* JAVA_FCMPG 150 */
583 1, /* JAVA_DCMPL 151 */
584 1, /* JAVA_DCMPG 152 */
585 3, /* JAVA_IFEQ 153 */
586 3, /* JAVA_IFNE 154 */
587 3, /* JAVA_IFLT 155 */
588 3, /* JAVA_IFGE 156 */
589 3, /* JAVA_IFGT 157 */
590 3, /* JAVA_IFLE 158 */
591 3, /* JAVA_IF_ICMPEQ 159 */
592 3, /* JAVA_IF_ICMPNE 160 */
593 3, /* JAVA_IF_ICMPLT 161 */
594 3, /* JAVA_IF_ICMPGE 162 */
595 3, /* JAVA_IF_ICMPGT 163 */
596 3, /* JAVA_IF_ICMPLE 164 */
597 3, /* JAVA_IF_ACMPEQ 165 */
598 3, /* JAVA_IF_ACMPNE 166 */
599 3, /* JAVA_GOTO 167 */
600 3, /* JAVA_JSR 168 */
601 2, /* JAVA_RET 169 */
602 0, /* JAVA_TABLESWITCH 170 */ /* variable length */
603 0, /* JAVA_LOOKUPSWITCH 171 */ /* variable length */
604 1, /* JAVA_IRETURN 172 */
605 1, /* JAVA_LRETURN 173 */
606 1, /* JAVA_FRETURN 174 */
607 1, /* JAVA_DRETURN 175 */
608 1, /* JAVA_ARETURN 176 */
609 1, /* JAVA_RETURN 177 */
610 3, /* JAVA_GETSTATIC 178 */
611 3, /* JAVA_PUTSTATIC 179 */
612 3, /* JAVA_GETFIELD 180 */
613 3, /* JAVA_PUTFIELD 181 */
614 3, /* JAVA_INVOKEVIRTUAL 182 */
615 3, /* JAVA_INVOKESPECIAL 183 */
616 3, /* JAVA_INVOKESTATIC 184 */
617 5, /* JAVA_INVOKEINTERFACE 185 */
619 3, /* JAVA_NEW 187 */
620 2, /* JAVA_NEWARRAY 188 */
621 3, /* JAVA_ANEWARRAY 189 */
622 1, /* JAVA_ARRAYLENGTH 190 */
623 1, /* JAVA_ATHROW 191 */
624 3, /* JAVA_CHECKCAST 192 */
625 3, /* JAVA_INSTANCEOF 193 */
626 1, /* JAVA_MONITORENTER 194 */
627 1, /* JAVA_MONITOREXIT 195 */
628 0, /* JAVA_WIDE 196 */ /* variable length */
629 4, /* JAVA_MULTIANEWARRAY 197 */
630 3, /* JAVA_IFNULL 198 */
631 3, /* JAVA_IFNONNULL 199 */
632 5, /* JAVA_GOTO_W 200 */
633 5, /* JAVA_JSR_W 201 */
634 1, /* JAVA_BREAKPOINT 202 */
671 1,1,1,1,1,1,1,1,1,1,
676 /* Java opcode names *********************************************************/
678 char *opcode_names[256] = {
681 "ICONST_M1 ", /* ICONST_M1 2 */
682 "ICONST_0 ", /* ICONST_0 3 */
683 "ICONST_1 ", /* ICONST_1 4 */
684 "ICONST_2 ", /* ICONST_2 5 */
685 "ICONST_3 ", /* ICONST_3 6 */
686 "ICONST_4 ", /* ICONST_4 7 */
687 "ICONST_5 ", /* ICONST_5 8 */
688 "LCONST_0 ", /* LCONST_0 9 */
689 "LCONST_1 ", /* LCONST_1 10 */
690 "FCONST_0 ", /* FCONST_0 11 */
691 "FCONST_1 ", /* FCONST_1 12 */
692 "FCONST_2 ", /* FCONST_2 13 */
693 "DCONST_0 ", /* DCONST_0 14 */
694 "DCONST_1 ", /* DCONST_1 15 */
695 "BIPUSH ", /* BIPUSH 16 */
696 "SIPUSH ", /* SIPUSH 17 */
698 "LDC_W ", /* LDC_W 19 */
699 "LDC2_W ", /* LDC2_W 20 */
705 "ILOAD_0 ", /* ILOAD_0 26 */
706 "ILOAD_1 ", /* ILOAD_1 27 */
707 "ILOAD_2 ", /* ILOAD_2 28 */
708 "ILOAD_3 ", /* ILOAD_3 29 */
709 "LLOAD_0 ", /* LLOAD_0 30 */
710 "LLOAD_1 ", /* LLOAD_1 31 */
711 "LLOAD_2 ", /* LLOAD_2 32 */
712 "LLOAD_3 ", /* LLOAD_3 33 */
713 "FLOAD_0 ", /* FLOAD_0 34 */
714 "FLOAD_1 ", /* FLOAD_1 35 */
715 "FLOAD_2 ", /* FLOAD_2 36 */
716 "FLOAD_3 ", /* FLOAD_3 37 */
717 "DLOAD_0 ", /* DLOAD_0 38 */
718 "DLOAD_1 ", /* DLOAD_1 39 */
719 "DLOAD_2 ", /* DLOAD_2 40 */
720 "DLOAD_3 ", /* DLOAD_3 41 */
721 "ALOAD_0 ", /* ALOAD_0 42 */
722 "ALOAD_1 ", /* ALOAD_1 43 */
723 "ALOAD_2 ", /* ALOAD_2 44 */
724 "ALOAD_3 ", /* ALOAD_3 45 */
738 "ISTORE_0 ", /* ISTORE_0 59 */
739 "ISTORE_1 ", /* ISTORE_1 60 */
740 "ISTORE_2 ", /* ISTORE_2 61 */
741 "ISTORE_3 ", /* ISTORE_3 62 */
742 "LSTORE_0 ", /* LSTORE_0 63 */
743 "LSTORE_1 ", /* LSTORE_1 64 */
744 "LSTORE_2 ", /* LSTORE_2 65 */
745 "LSTORE_3 ", /* LSTORE_3 66 */
746 "FSTORE_0 ", /* FSTORE_0 67 */
747 "FSTORE_1 ", /* FSTORE_1 68 */
748 "FSTORE_2 ", /* FSTORE_2 69 */
749 "FSTORE_3 ", /* FSTORE_3 70 */
750 "DSTORE_0 ", /* DSTORE_0 71 */
751 "DSTORE_1 ", /* DSTORE_1 72 */
752 "DSTORE_2 ", /* DSTORE_2 73 */
753 "DSTORE_3 ", /* DSTORE_3 74 */
754 "ASTORE_0 ", /* ASTORE_0 75 */
755 "ASTORE_1 ", /* ASTORE_1 76 */
756 "ASTORE_2 ", /* ASTORE_2 77 */
757 "ASTORE_3 ", /* ASTORE_3 78 */
824 "INT2BYTE ", /* 145 */
825 "INT2CHAR ", /* 146 */
826 "INT2SHORT ", /* 147 */
838 "IF_ICMPEQ ", /* 159 */
839 "IF_ICMPNE ", /* 160 */
840 "IF_ICMPLT ", /* 161 */
841 "IF_ICMPGE ", /* 162 */
842 "IF_ICMPGT ", /* 163 */
843 "IF_ICMPLE ", /* 164 */
844 "IF_ACMPEQ ", /* 165 */
845 "IF_ACMPNE ", /* 166 */
849 "TABLESWITCH ", /* 170 */
850 "LOOKUPSWITCH ", /* 171 */
851 "IRETURN ", /* 172 */
852 "LRETURN ", /* 173 */
853 "FRETURN ", /* 174 */
854 "DRETURN ", /* 175 */
855 "ARETURN ", /* 176 */
857 "GETSTATIC ", /* 178 */
858 "PUTSTATIC ", /* 179 */
859 "GETFIELD ", /* 180 */
860 "PUTFIELD ", /* 181 */
861 "INVOKEVIRTUAL ", /* 182 */
862 "INVOKESPECIAL ", /* 183 */
863 "INVOKESTATIC ", /* 184 */
864 "INVOKEINTERFACE", /* 185 */
865 "UNDEF186 ", /* 186 */
867 "NEWARRAY ", /* 188 */
868 "ANEWARRAY ", /* 189 */
869 "ARRAYLENGTH ", /* 190 */
871 "CHECKCAST ", /* 192 */
872 "INSTANCEOF ", /* 193 */
873 "MONITORENTER ", /* 194 */
874 "MONITOREXIT ", /* 195 */
875 "WIDE ", /* WIDE 196 */
876 "MULTIANEWARRAY ", /* 197 */
878 "IFNONNULL ", /* 199 */
879 "GOTO_W ", /* GOTO_W 200 */
880 "JSR_W ", /* JSR_W 201 */
881 "BREAKPOINT ", /* BREAKPOINT 202 */
883 "UNDEF203", "UNDEF204", "UNDEF205",
884 "UNDEF206", "UNDEF207", "UNDEF208", "UNDEF209", "UNDEF210",
885 "UNDEF211", "UNDEF212", "UNDEF213", "UNDEF214", "UNDEF215",
886 "UNDEF216", "UNDEF217", "UNDEF218", "UNDEF219", "UNDEF220",
887 "UNDEF221", "UNDEF222", "UNDEF223", "UNDEF224", "UNDEF225",
888 "UNDEF226", "UNDEF227", "UNDEF228", "UNDEF229", "UNDEF230",
889 "UNDEF231", "UNDEF232", "UNDEF233", "UNDEF234", "UNDEF235",
890 "UNDEF236", "UNDEF237", "UNDEF238", "UNDEF239", "UNDEF240",
891 "UNDEF241", "UNDEF242", "UNDEF243", "UNDEF244", "UNDEF245",
892 "UNDEF246", "UNDEF247", "UNDEF248", "UNDEF249", "UNDEF250",
893 "UNDEF251", "UNDEF252", "UNDEF253", "UNDEF254", "UNDEF255"
897 /* jit_init ********************************************************************
899 Initializes the JIT subsystem.
901 *******************************************************************************/
905 #if defined(ENABLE_JIT)
906 /* initialize stack analysis subsystem */
911 /* initialize show subsystem */
917 /* initialize codegen subsystem */
921 /* initialize code subsystem */
925 /* Machine dependent initialization. */
927 #if defined(ENABLE_JIT)
928 # if defined(ENABLE_INTRP)
940 /* jit_close *******************************************************************
942 Close the JIT subsystem.
944 *******************************************************************************/
952 /* dummy function, used when there is no JavaVM code available */
954 static u1 *do_nothing_function(void)
960 /* jit_jitdata_new *************************************************************
962 Allocates and initalizes a new jitdata structure.
964 *******************************************************************************/
966 jitdata *jit_jitdata_new(methodinfo *m)
971 /* allocate jitdata structure and fill it */
976 jd->cd = DNEW(codegendata);
977 jd->rd = DNEW(registerdata);
978 #if defined(ENABLE_LOOP)
979 jd->ld = DNEW(loopdata);
982 /* Allocate codeinfo memory from the heap as we need to keep them. */
984 code = code_codeinfo_new(m);
986 /* Set codeinfo flags. */
988 #if defined(ENABLE_THREADS)
989 if (checksync && (m->flags & ACC_SYNCHRONIZED))
990 code_flag_synchronized(code);
992 if (checksync && (m->flags & ACC_SYNCHRONIZED))
993 code_unflag_leafmethod(code);
996 code_flag_leafmethod(code);
998 /* initialize variables */
1002 jd->exceptiontable = NULL;
1003 jd->exceptiontablelength = 0;
1004 jd->returncount = 0;
1005 jd->branchtoentry = false;
1006 jd->branchtoend = false;
1007 jd->returncount = 0;
1008 jd->returnblock = NULL;
1009 jd->maxlocals = m->maxlocals;
1015 /* jit_compile *****************************************************************
1017 Translates one method to machine code.
1019 *******************************************************************************/
1021 static u1 *jit_compile_intern(jitdata *jd);
1023 u1 *jit_compile(methodinfo *m)
1029 STATISTICS(count_jit_calls++);
1031 /* Initialize the static function's class. */
1033 /* ATTENTION: This MUST be done before the method lock is aquired,
1034 otherwise we could run into a deadlock with <clinit>'s that
1035 call static methods of it's own class. */
1037 if ((m->flags & ACC_STATIC) && !(m->class->state & CLASS_INITIALIZED)) {
1038 #if !defined(NDEBUG)
1040 log_message_class("Initialize class ", m->class);
1043 if (!initialize_class(m->class))
1046 /* check if the method has been compiled during initialization */
1048 if ((m->code != NULL) && (m->code->entrypoint != NULL))
1049 return m->code->entrypoint;
1052 /* enter a monitor on the method */
1054 LOCK_MONITOR_ENTER(m);
1056 /* if method has been already compiled return immediately */
1058 if (m->code != NULL) {
1059 LOCK_MONITOR_EXIT(m);
1061 assert(m->code->entrypoint);
1062 return m->code->entrypoint;
1065 TRACECOMPILERCALLS();
1067 STATISTICS(count_methods++);
1069 #if defined(ENABLE_STATISTICS)
1072 if (opt_getcompilingtime)
1073 compilingtime_start();
1076 /* mark start of dump memory area */
1078 dumpsize = dump_size();
1080 /* create jitdata structure */
1082 jd = jit_jitdata_new(m);
1084 /* set the flags for the current JIT run */
1086 jd->flags = JITDATA_FLAG_PARSE;
1088 #if defined(ENABLE_VERIFIER)
1090 jd->flags |= JITDATA_FLAG_VERIFY;
1093 #if defined(ENABLE_PROFILING)
1095 jd->flags |= JITDATA_FLAG_INSTRUMENT;
1098 #if defined(ENABLE_IFCONV)
1100 jd->flags |= JITDATA_FLAG_IFCONV;
1103 #if defined(ENABLE_INLINING) && defined(ENABLE_INLINING_DEBUG)
1104 if (opt_inlining && opt_inline_debug_all)
1105 jd->flags |= JITDATA_FLAG_INLINE;
1108 if (opt_showintermediate)
1109 jd->flags |= JITDATA_FLAG_SHOWINTERMEDIATE;
1111 if (opt_showdisassemble)
1112 jd->flags |= JITDATA_FLAG_SHOWDISASSEMBLE;
1114 if (opt_verbosecall)
1115 jd->flags |= JITDATA_FLAG_VERBOSECALL;
1117 #if defined(ENABLE_REPLACEMENT) && defined(ENABLE_INLINING)
1119 jd->flags |= JITDATA_FLAG_COUNTDOWN;
1122 #if defined(ENABLE_JIT)
1123 # if defined(ENABLE_INTRP)
1126 /* initialize the register allocator */
1132 /* setup the codegendata memory */
1136 /* now call internal compile function */
1138 r = jit_compile_intern(jd);
1141 /* We had an exception! Finish stuff here if necessary. */
1143 /* release codeinfo */
1145 code_codeinfo_free(jd->code);
1147 #if defined(ENABLE_PROFILING)
1148 /* Release memory for basic block profiling information. */
1150 if (JITDATA_HAS_FLAG_INSTRUMENT(jd))
1151 if (jd->code->bbfrequency != NULL)
1152 MFREE(jd->code->bbfrequency, u4, jd->code->basicblockcount);
1156 DEBUG_JIT_COMPILEVERBOSE("Running: ");
1159 /* release dump area */
1161 dump_release(dumpsize);
1163 #if defined(ENABLE_STATISTICS)
1166 if (opt_getcompilingtime)
1167 compilingtime_stop();
1170 /* leave the monitor */
1172 LOCK_MONITOR_EXIT(m);
1174 /* return pointer to the methods entry point */
1180 /* jit_recompile ***************************************************************
1182 Recompiles a Java method.
1184 *******************************************************************************/
1186 u1 *jit_recompile(methodinfo *m)
1193 /* check for max. optimization level */
1195 optlevel = (m->code) ? m->code->optlevel : 0;
1198 if (optlevel == 1) {
1199 /* log_message_method("not recompiling: ", m); */
1204 DEBUG_JIT_COMPILEVERBOSE("Recompiling start: ");
1206 STATISTICS(count_jit_calls++);
1208 #if defined(ENABLE_STATISTICS)
1211 if (opt_getcompilingtime)
1212 compilingtime_start();
1215 /* mark start of dump memory area */
1217 dumpsize = dump_size();
1219 /* create jitdata structure */
1221 jd = jit_jitdata_new(m);
1223 /* set the current optimization level to the previous one plus 1 */
1225 jd->code->optlevel = optlevel + 1;
1227 /* get the optimization flags for the current JIT run */
1229 #if defined(ENABLE_VERIFIER)
1230 jd->flags |= JITDATA_FLAG_VERIFY;
1233 /* jd->flags |= JITDATA_FLAG_REORDER; */
1234 if (opt_showintermediate)
1235 jd->flags |= JITDATA_FLAG_SHOWINTERMEDIATE;
1236 if (opt_showdisassemble)
1237 jd->flags |= JITDATA_FLAG_SHOWDISASSEMBLE;
1238 if (opt_verbosecall)
1239 jd->flags |= JITDATA_FLAG_VERBOSECALL;
1241 #if defined(ENABLE_INLINING)
1243 jd->flags |= JITDATA_FLAG_INLINE;
1246 #if defined(ENABLE_JIT)
1247 # if defined(ENABLE_INTRP)
1250 /* initialize the register allocator */
1255 /* setup the codegendata memory */
1259 /* now call internal compile function */
1261 r = jit_compile_intern(jd);
1264 /* We had an exception! Finish stuff here if necessary. */
1266 /* release codeinfo */
1268 code_codeinfo_free(jd->code);
1271 /* release dump area */
1273 dump_release(dumpsize);
1275 #if defined(ENABLE_STATISTICS)
1278 if (opt_getcompilingtime)
1279 compilingtime_stop();
1282 DEBUG_JIT_COMPILEVERBOSE("Recompiling done: ");
1284 /* return pointer to the methods entry point */
1290 /* jit_compile_intern **********************************************************
1292 Static internal function which does the actual compilation.
1294 *******************************************************************************/
1296 static u1 *jit_compile_intern(jitdata *jd)
1302 #if defined(ENABLE_RT_TIMING)
1303 struct timespec time_start,time_checks,time_parse,time_stack,
1304 time_typecheck,time_loop,time_ifconv,time_alloc,
1308 RT_TIMING_GET_TIME(time_start);
1310 /* get required compiler data */
1312 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1319 #if defined(ENABLE_DEBUG_FILTER)
1320 show_filters_apply(jd->m);
1323 /* handle native methods and create a native stub */
1325 if (m->flags & ACC_NATIVE) {
1328 f = native_method_resolve(m);
1333 code = codegen_generate_stub_native(m, f);
1335 /* Native methods are never recompiled. */
1341 return code->entrypoint;
1344 /* if there is no javacode, print error message and return empty method */
1346 if (m->jcode == NULL) {
1347 DEBUG_JIT_COMPILEVERBOSE("No code given for: ");
1349 code->entrypoint = (u1 *) (ptrint) do_nothing_function;
1352 return code->entrypoint; /* return empty method */
1355 #if defined(ENABLE_STATISTICS)
1357 count_javacodesize += m->jcodelength + 18;
1358 count_tryblocks += jd->exceptiontablelength;
1359 count_javaexcsize += jd->exceptiontablelength * SIZEOF_VOID_P;
1363 RT_TIMING_GET_TIME(time_checks);
1365 #if defined(WITH_CLASSPATH_SUN)
1366 /* Code for Sun's OpenJDK (see
1367 hotspot/src/share/vm/classfile/verifier.cpp
1368 (Verifier::is_eligible_for_verification)): Don't verify
1369 dynamically-generated bytecodes. */
1371 # if defined(ENABLE_VERIFIER)
1372 if (class_issubclass(m->class, class_sun_reflect_MagicAccessorImpl))
1373 jd->flags &= ~JITDATA_FLAG_VERIFY;
1377 /* call the compiler passes ***********************************************/
1379 DEBUG_JIT_COMPILEVERBOSE("Parsing: ");
1381 /* call parse pass */
1384 DEBUG_JIT_COMPILEVERBOSE("Exception while parsing: ");
1388 RT_TIMING_GET_TIME(time_parse);
1390 DEBUG_JIT_COMPILEVERBOSE("Parsing done: ");
1392 #if defined(ENABLE_JIT)
1393 # if defined(ENABLE_INTRP)
1396 DEBUG_JIT_COMPILEVERBOSE("Analysing: ");
1398 /* call stack analysis pass */
1400 if (!stack_analyse(jd)) {
1401 DEBUG_JIT_COMPILEVERBOSE("Exception while analysing: ");
1405 RT_TIMING_GET_TIME(time_stack);
1407 DEBUG_JIT_COMPILEVERBOSE("Analysing done: ");
1409 /* Build the CFG. This has to be done after stack_analyse, as
1410 there happens the JSR elimination. */
1415 #ifdef ENABLE_VERIFIER
1416 if (JITDATA_HAS_FLAG_VERIFY(jd)) {
1417 DEBUG_JIT_COMPILEVERBOSE("Typechecking: ");
1419 /* call typecheck pass */
1420 if (!typecheck(jd)) {
1421 DEBUG_JIT_COMPILEVERBOSE("Exception while typechecking: ");
1426 DEBUG_JIT_COMPILEVERBOSE("Typechecking done: ");
1429 RT_TIMING_GET_TIME(time_typecheck);
1431 #if defined(ENABLE_LOOP)
1436 jit_renumber_basicblocks(jd);
1439 RT_TIMING_GET_TIME(time_loop);
1441 #if defined(ENABLE_IFCONV)
1442 if (JITDATA_HAS_FLAG_IFCONV(jd)) {
1443 if (!ifconv_static(jd))
1445 jit_renumber_basicblocks(jd);
1448 RT_TIMING_GET_TIME(time_ifconv);
1452 #if defined(ENABLE_INLINING)
1453 if (JITDATA_HAS_FLAG_INLINE(jd)) {
1454 if (!inline_inline(jd))
1459 #if defined(ENABLE_PROFILING)
1460 /* Basic block reordering. I think this should be done after
1461 if-conversion, as we could lose the ability to do the
1464 if (JITDATA_HAS_FLAG_REORDER(jd)) {
1467 jit_renumber_basicblocks(jd);
1471 DEBUG_JIT_COMPILEVERBOSE("Allocating registers: ");
1473 #if defined(ENABLE_LSRA) && !defined(ENABLE_SSA)
1474 /* allocate registers */
1479 STATISTICS(count_methods_allocated_by_lsra++);
1482 # endif /* defined(ENABLE_LSRA) && !defined(ENABLE_SSA) */
1483 #if defined(ENABLE_SSA)
1484 /* allocate registers */
1485 if ((opt_lsra) && (jd->exceptiontablelength == 0)) {
1486 jd->ls = DNEW(lsradata);
1489 STATISTICS(count_methods_allocated_by_lsra++);
1492 # endif /* defined(ENABLE_SSA) */
1494 STATISTICS(count_locals_conflicts += (jd->maxlocals - 1) * (jd->maxlocals));
1499 STATISTICS(simplereg_make_statistics(jd));
1501 DEBUG_JIT_COMPILEVERBOSE("Allocating registers done: ");
1502 # if defined(ENABLE_INTRP)
1505 #endif /* defined(ENABLE_JIT) */
1506 RT_TIMING_GET_TIME(time_alloc);
1508 #if defined(ENABLE_PROFILING)
1509 /* Allocate memory for basic block profiling information. This
1510 _must_ be done after loop optimization and register allocation,
1511 since they can change the basic block count. */
1513 if (JITDATA_HAS_FLAG_INSTRUMENT(jd))
1514 code->bbfrequency = MNEW(u4, jd->basicblockcount);
1517 DEBUG_JIT_COMPILEVERBOSE("Generating code: ");
1519 /* now generate the machine code */
1521 #if defined(ENABLE_JIT)
1522 # if defined(ENABLE_INTRP)
1524 #if defined(ENABLE_VERIFIER)
1526 DEBUG_JIT_COMPILEVERBOSE("Typechecking (stackbased): ");
1528 if (!typecheck_stackbased(jd)) {
1529 DEBUG_JIT_COMPILEVERBOSE("Exception while typechecking (stackbased): ");
1534 if (!intrp_codegen(jd)) {
1535 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1542 if (!codegen_generate(jd)) {
1543 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1549 if (!intrp_codegen(jd)) {
1550 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1555 RT_TIMING_GET_TIME(time_codegen);
1557 DEBUG_JIT_COMPILEVERBOSE("Generating code done: ");
1559 #if !defined(NDEBUG) && defined(ENABLE_REPLACEMENT)
1560 /* activate replacement points inside newly created code */
1562 if (opt_TestReplacement)
1563 replace_activate_replacement_points(code, false);
1566 #if !defined(NDEBUG)
1567 #if defined(ENABLE_DEBUG_FILTER)
1568 if (jd->m->filtermatches & SHOW_FILTER_FLAG_SHOW_METHOD)
1571 /* intermediate and assembly code listings */
1573 if (JITDATA_HAS_FLAG_SHOWINTERMEDIATE(jd)) {
1574 show_method(jd, SHOW_CODE);
1576 else if (JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd)) {
1577 # if defined(ENABLE_DISASSEMBLER)
1578 DISASSEMBLE(code->entrypoint,
1579 code->entrypoint + (code->mcodelength - cd->dseglen));
1583 if (opt_showddatasegment)
1588 /* switch to the newly generated code */
1591 assert(code->entrypoint);
1593 /* add the current compile version to the methodinfo */
1595 code->prev = m->code;
1598 RT_TIMING_TIME_DIFF(time_start,time_checks,RT_TIMING_JIT_CHECKS);
1599 RT_TIMING_TIME_DIFF(time_checks,time_parse,RT_TIMING_JIT_PARSE);
1600 RT_TIMING_TIME_DIFF(time_parse,time_stack,RT_TIMING_JIT_STACK);
1601 RT_TIMING_TIME_DIFF(time_stack,time_typecheck,RT_TIMING_JIT_TYPECHECK);
1602 RT_TIMING_TIME_DIFF(time_typecheck,time_loop,RT_TIMING_JIT_LOOP);
1603 RT_TIMING_TIME_DIFF(time_loop,time_alloc,RT_TIMING_JIT_ALLOC);
1604 RT_TIMING_TIME_DIFF(time_alloc,time_codegen,RT_TIMING_JIT_CODEGEN);
1605 RT_TIMING_TIME_DIFF(time_start,time_codegen,RT_TIMING_JIT_TOTAL);
1607 /* return pointer to the methods entry point */
1609 return code->entrypoint;
1613 /* jit_invalidate_code *********************************************************
1615 Mark the compiled code of the given method as invalid and take care that
1616 it is replaced if necessary.
1618 XXX Not fully implemented, yet.
1620 *******************************************************************************/
1622 void jit_invalidate_code(methodinfo *m)
1628 if (code == NULL || code_is_invalid(code))
1631 code_flag_invalid(code);
1633 /* activate mappable replacement points */
1635 #if defined(ENABLE_REPLACEMENT)
1636 replace_activate_replacement_points(code, true);
1638 vm_abort("invalidating code only works with ENABLE_REPLACEMENT");
1643 /* jit_request_optimization ****************************************************
1645 Request optimization of the given method. If the code of the method is
1646 unoptimized, it will be invalidated, so the next jit_get_current_code(m)
1647 triggers an optimized recompilation.
1648 If the method is already optimized, this function does nothing.
1651 m................the method
1653 *******************************************************************************/
1655 void jit_request_optimization(methodinfo *m)
1661 if (code && code->optlevel == 0)
1662 jit_invalidate_code(m);
1666 /* jit_get_current_code ********************************************************
1668 Get the currently valid code for the given method. If there is no valid
1669 code, (re)compile the method.
1672 m................the method
1675 the codeinfo* for the current code, or
1676 NULL if an exception has been thrown during recompilation.
1678 *******************************************************************************/
1680 codeinfo *jit_get_current_code(methodinfo *m)
1684 /* if we have valid code, return it */
1686 if (m->code && !code_is_invalid(m->code))
1689 /* otherwise: recompile */
1691 if (!jit_recompile(m))
1700 /* jit_asm_compile *************************************************************
1702 This method is called from asm_vm_call_method and does:
1704 - create stackframe info for exceptions
1705 - compile the method
1706 - patch the entrypoint of the method into the calculated address in
1708 - flushes the instruction cache.
1710 *******************************************************************************/
1712 #if defined(ENABLE_JIT)
1713 #if !defined(JIT_COMPILER_VIA_SIGNAL)
1714 u1 *jit_asm_compile(methodinfo *m, u1 *mptr, u1 *sp, u1 *ra)
1716 stackframeinfo_t sfi;
1721 /* create the stackframeinfo (subtract 1 from RA as it points to the */
1722 /* instruction after the call) */
1724 stacktrace_stackframeinfo_add(&sfi, NULL, sp, ra, ra-1);
1726 /* actually compile the method */
1728 entrypoint = jit_compile(m);
1730 /* remove the stackframeinfo */
1732 stacktrace_stackframeinfo_remove(&sfi);
1734 /* there was a problem during compilation */
1736 if (entrypoint == NULL)
1739 /* get the method patch address */
1741 pa = md_jit_method_patch_address(sfi.pv, (void *) ra, mptr);
1743 /* patch the method entry point */
1747 *p = (ptrint) entrypoint;
1749 /* flush the instruction cache */
1751 md_icacheflush(pa, SIZEOF_VOID_P);
1757 /* jit_compile_handle **********************************************************
1759 This method is called from the appropriate signal handler which
1760 handles compiler-traps and does the following:
1762 - compile the method
1763 - patch the entrypoint of the method into the calculated address in
1765 - flush the instruction cache
1767 *******************************************************************************/
1769 void *jit_compile_handle(methodinfo *m, void *pv, void *ra, void *mptr)
1771 void *newpv; /* new compiled method PV */
1772 void *pa; /* patch address */
1773 uintptr_t *p; /* convenience pointer */
1775 /* Compile the method. */
1777 newpv = jit_compile(m);
1779 /* There was a problem during compilation. */
1784 /* Get the method patch address. */
1786 pa = md_jit_method_patch_address(pv, ra, mptr);
1788 /* Patch the method entry point. */
1790 p = (uintptr_t *) pa;
1792 *p = (uintptr_t) newpv;
1794 /* Flush both caches. */
1796 md_cacheflush(pa, SIZEOF_VOID_P);
1800 #endif /* defined(ENABLE_JIT) */
1803 /* jit_complement_condition ****************************************************
1805 Returns the complement of the passed conditional instruction.
1807 We use the order of the different conditions, e.g.:
1812 If the passed opcode is odd, we simply add 1 to get the complement.
1813 If the opcode is even, we subtract 1.
1820 *******************************************************************************/
1822 s4 jit_complement_condition(s4 opcode)
1826 return ICMD_IFNONNULL;
1828 case ICMD_IFNONNULL:
1832 /* check if opcode is odd */
1842 /* jit_renumber_basicblocks ****************************************************
1844 Set the ->nr of all blocks so it increases when traversing ->next.
1847 jitdata..........the current jitdata
1849 *******************************************************************************/
1851 void jit_renumber_basicblocks(jitdata *jd)
1857 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
1861 /* we have one block more than jd->basicblockcount (the end marker) */
1863 assert(nr == jd->basicblockcount + 1);
1867 /* jit_check_basicblock_numbers ************************************************
1869 Assert that the ->nr of the first block is zero and increases by 1 each
1870 time ->next is traversed.
1871 This function should be called before any analysis that relies on
1872 the basicblock numbers.
1875 jitdata..........the current jitdata
1877 NOTE: Aborts with an assertion if the condition is not met!
1879 *******************************************************************************/
1881 #if !defined(NDEBUG)
1882 void jit_check_basicblock_numbers(jitdata *jd)
1888 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
1889 assert(bptr->nr == nr);
1893 /* we have one block more than jd->basicblockcount (the end marker) */
1895 assert(nr == jd->basicblockcount + 1);
1897 #endif /* !defined(NDEBUG) */
1901 * These are local overrides for various environment variables in Emacs.
1902 * Please do not remove this and leave it at the end of the file, where
1903 * Emacs will automagically detect them.
1904 * ---------------------------------------------------------------------
1907 * indent-tabs-mode: t
1911 * vim:noexpandtab:sw=4:ts=4: