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/parse.h"
55 #include "vm/jit/reg.h"
57 #include "vm/jit/show.h"
58 #include "vm/jit/stack.h"
60 #include "vm/jit/allocator/simplereg.h"
61 #if defined(ENABLE_LSRA) && !defined(ENABLE_SSA)
62 # include "vm/jit/allocator/lsra.h"
64 #if defined(ENABLE_SSA)
65 # include "vm/jit/optimizing/lsra.h"
66 # include "vm/jit/optimizing/ssa.h"
69 #if defined(ENABLE_INLINING)
70 # include "vm/jit/inline/inline.h"
73 #include "vm/jit/loop/analyze.h"
74 #include "vm/jit/loop/graph.h"
75 #include "vm/jit/loop/loop.h"
77 #if defined(ENABLE_IFCONV)
78 # include "vm/jit/optimizing/ifconv.h"
81 #include "vm/jit/optimizing/reorder.h"
83 #include "vm/jit/verify/typecheck.h"
85 #include "vmcore/class.h"
86 #include "vmcore/loader.h"
87 #include "vmcore/method.h"
88 #include "vmcore/options.h"
89 #include "vmcore/rt-timing.h"
90 #include "vmcore/statistics.h"
93 /* debug macros ***************************************************************/
96 #define DEBUG_JIT_COMPILEVERBOSE(x) \
98 if (compileverbose) { \
99 log_message_method(x, m); \
103 #define DEBUG_JIT_COMPILEVERBOSE(x) /* nothing */
107 # define TRACECOMPILERCALLS() \
109 if (opt_TraceCompilerCalls) { \
111 log_print("[JIT compiler started: method="); \
118 # define TRACECOMPILERCALLS()
122 /* the ICMD table ************************************************************/
125 #define N(name) name,
130 /* abbreviations for flags */
132 #define PEI ICMDTABLE_PEI
133 #define CALLS ICMDTABLE_CALLS
135 /* some machine dependent values */
140 #define IDIV_CALLS ICMDTABLE_CALLS
143 #if (SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
146 #define LDIV_CALLS ICMDTABLE_CALLS
149 /* include the actual table */
151 icmdtable_entry_t icmd_table[256] = {
152 #include <vm/jit/icmdtable.inc>
159 /* XXX hack until the old "PEI" definition is removed */
163 /* stackelement requirements of Java opcodes **********************************/
165 int stackreq[256] = {
167 1, /* JAVA_ACONST 1 */
168 1, /* JAVA_ICONST_M1 2 */
169 1, /* JAVA_ICONST_0 3 */
170 1, /* JAVA_ICONST_1 4 */
171 1, /* JAVA_ICONST_2 5 */
172 1, /* JAVA_ICONST_3 6 */
173 1, /* JAVA_ICONST_4 7 */
174 1, /* JAVA_ICONST_5 8 */
175 1, /* JAVA_LCONST_0 9 */
176 1, /* JAVA_LCONST_1 10 */
177 1, /* JAVA_FCONST_0 11 */
178 1, /* JAVA_FCONST_1 12 */
179 1, /* JAVA_FCONST_2 13 */
180 1, /* JAVA_DCONST_0 14 */
181 1, /* JAVA_DCONST_1 15 */
182 1, /* JAVA_BIPUSH 16 */
183 1, /* JAVA_SIPUSH 17 */
185 1, /* JAVA_LDC_W 19 */
186 1, /* JAVA_LDC2_W 20 */
187 1, /* JAVA_ILOAD 21 */
188 1, /* JAVA_LLOAD 22 */
189 1, /* JAVA_FLOAD 23 */
190 1, /* JAVA_DLOAD 24 */
191 1, /* JAVA_ALOAD 25 */
192 1, /* JAVA_ILOAD_0 26 */
193 1, /* JAVA_ILOAD_1 27 */
194 1, /* JAVA_ILOAD_2 28 */
195 1, /* JAVA_ILOAD_3 29 */
196 1, /* JAVA_LLOAD_0 30 */
197 1, /* JAVA_LLOAD_1 31 */
198 1, /* JAVA_LLOAD_2 32 */
199 1, /* JAVA_LLOAD_3 33 */
200 1, /* JAVA_FLOAD_0 34 */
201 1, /* JAVA_FLOAD_1 35 */
202 1, /* JAVA_FLOAD_2 36 */
203 1, /* JAVA_FLOAD_3 37 */
204 1, /* JAVA_DLOAD_0 38 */
205 1, /* JAVA_DLOAD_1 39 */
206 1, /* JAVA_DLOAD_2 40 */
207 1, /* JAVA_DLOAD_3 41 */
208 1, /* JAVA_ALOAD_0 42 */
209 1, /* JAVA_ALOAD_1 43 */
210 1, /* JAVA_ALOAD_2 44 */
211 1, /* JAVA_ALOAD_3 45 */
212 1, /* JAVA_IALOAD 46 */
213 1, /* JAVA_LALOAD 47 */
214 1, /* JAVA_FALOAD 48 */
215 1, /* JAVA_DALOAD 49 */
216 1, /* JAVA_AALOAD 50 */
217 1, /* JAVA_BALOAD 51 */
218 1, /* JAVA_CALOAD 52 */
219 1, /* JAVA_SALOAD 53 */
220 0, /* JAVA_ISTORE 54 */
221 0, /* JAVA_LSTORE 55 */
222 0, /* JAVA_FSTORE 56 */
223 0, /* JAVA_DSTORE 57 */
224 0, /* JAVA_ASTORE 58 */
225 0, /* JAVA_ISTORE_0 59 */
226 0, /* JAVA_ISTORE_1 60 */
227 0, /* JAVA_ISTORE_2 61 */
228 0, /* JAVA_ISTORE_3 62 */
229 0, /* JAVA_LSTORE_0 63 */
230 0, /* JAVA_LSTORE_1 64 */
231 0, /* JAVA_LSTORE_2 65 */
232 0, /* JAVA_LSTORE_3 66 */
233 0, /* JAVA_FSTORE_0 67 */
234 0, /* JAVA_FSTORE_1 68 */
235 0, /* JAVA_FSTORE_2 69 */
236 0, /* JAVA_FSTORE_3 70 */
237 0, /* JAVA_DSTORE_0 71 */
238 0, /* JAVA_DSTORE_1 72 */
239 0, /* JAVA_DSTORE_2 73 */
240 0, /* JAVA_DSTORE_3 74 */
241 0, /* JAVA_ASTORE_0 75 */
242 0, /* JAVA_ASTORE_1 76 */
243 0, /* JAVA_ASTORE_2 77 */
244 0, /* JAVA_ASTORE_3 78 */
245 0, /* JAVA_IASTORE 79 */
246 0, /* JAVA_LASTORE 80 */
247 0, /* JAVA_FASTORE 81 */
248 0, /* JAVA_DASTORE 82 */
249 0, /* JAVA_AASTORE 83 */
250 0, /* JAVA_BASTORE 84 */
251 0, /* JAVA_CASTORE 85 */
252 0, /* JAVA_SASTORE 86 */
254 0, /* JAVA_POP2 88 */
256 1+3, /* JAVA_DUP_X1 90 */
257 2+4, /* JAVA_DUP_X2 91 */
258 2, /* JAVA_DUP2 92 */
259 2+5, /* JAVA_DUP2_X1 93 */
260 3+6, /* JAVA_DUP2_X2 94 */
261 1+2, /* JAVA_SWAP 95 */
262 1, /* JAVA_IADD 96 */
263 1, /* JAVA_LADD 97 */
264 1, /* JAVA_FADD 98 */
265 1, /* JAVA_DADD 99 */
266 1, /* JAVA_ISUB 100 */
267 1, /* JAVA_LSUB 101 */
268 1, /* JAVA_FSUB 102 */
269 1, /* JAVA_DSUB 103 */
270 1, /* JAVA_IMUL 104 */
271 1, /* JAVA_LMUL 105 */
272 1, /* JAVA_FMUL 106 */
273 1, /* JAVA_DMUL 107 */
274 1, /* JAVA_IDIV 108 */
275 1, /* JAVA_LDIV 109 */
276 1, /* JAVA_FDIV 110 */
277 1, /* JAVA_DDIV 111 */
278 1, /* JAVA_IREM 112 */
279 1, /* JAVA_LREM 113 */
280 1, /* JAVA_FREM 114 */
281 1, /* JAVA_DREM 115 */
282 1, /* JAVA_INEG 116 */
283 1, /* JAVA_LNEG 117 */
284 1, /* JAVA_FNEG 118 */
285 1, /* JAVA_DNEG 119 */
286 1, /* JAVA_ISHL 120 */
287 1, /* JAVA_LSHL 121 */
288 1, /* JAVA_ISHR 122 */
289 1, /* JAVA_LSHR 123 */
290 1, /* JAVA_IUSHR 124 */
291 1, /* JAVA_LUSHR 125 */
292 1, /* JAVA_IAND 126 */
293 1, /* JAVA_LAND 127 */
294 1, /* JAVA_IOR 128 */
295 1, /* JAVA_LOR 129 */
296 1, /* JAVA_IXOR 130 */
297 1, /* JAVA_LXOR 131 */
298 0, /* JAVA_IINC 132 */
299 1, /* JAVA_I2L 133 */
300 1, /* JAVA_I2F 134 */
301 1, /* JAVA_I2D 135 */
302 1, /* JAVA_L2I 136 */
303 1, /* JAVA_L2F 137 */
304 1, /* JAVA_L2D 138 */
305 1, /* JAVA_F2I 139 */
306 1, /* JAVA_F2L 140 */
307 1, /* JAVA_F2D 141 */
308 1, /* JAVA_D2I 142 */
309 1, /* JAVA_D2L 143 */
310 1, /* JAVA_D2F 144 */
311 1, /* JAVA_INT2BYTE 145 */
312 1, /* JAVA_INT2CHAR 146 */
313 1, /* JAVA_INT2SHORT 147 */
314 1, /* JAVA_LCMP 148 */
315 1, /* JAVA_FCMPL 149 */
316 1, /* JAVA_FCMPG 150 */
317 1, /* JAVA_DCMPL 151 */
318 1, /* JAVA_DCMPG 152 */
319 0, /* JAVA_IFEQ 153 */
320 0, /* JAVA_IFNE 154 */
321 0, /* JAVA_IFLT 155 */
322 0, /* JAVA_IFGE 156 */
323 0, /* JAVA_IFGT 157 */
324 0, /* JAVA_IFLE 158 */
325 0, /* JAVA_IF_ICMPEQ 159 */
326 0, /* JAVA_IF_ICMPNE 160 */
327 0, /* JAVA_IF_ICMPLT 161 */
328 0, /* JAVA_IF_ICMPGE 162 */
329 0, /* JAVA_IF_ICMPGT 163 */
330 0, /* JAVA_IF_ICMPLE 164 */
331 0, /* JAVA_IF_ACMPEQ 165 */
332 0, /* JAVA_IF_ACMPNE 166 */
333 0, /* JAVA_GOTO 167 */
334 1, /* JAVA_JSR 168 */
335 0, /* JAVA_RET 169 */
336 0, /* JAVA_TABLESWITCH 170 */
337 0, /* JAVA_LOOKUPSWITCH 171 */
338 0, /* JAVA_IRETURN 172 */
339 0, /* JAVA_LRETURN 173 */
340 0, /* JAVA_FRETURN 174 */
341 0, /* JAVA_DRETURN 175 */
342 0, /* JAVA_ARETURN 176 */
343 0, /* JAVA_RETURN 177 */
344 1, /* JAVA_GETSTATIC 178 */
345 0, /* JAVA_PUTSTATIC 179 */
346 1, /* JAVA_GETFIELD 180 */
347 0, /* JAVA_PUTFIELD 181 */
348 1, /* JAVA_INVOKEVIRTUAL 182 */
349 1, /* JAVA_INVOKESPECIAL 183 */
350 1, /* JAVA_INVOKESTATIC 184 */
351 1, /* JAVA_INVOKEINTERFACE 185 */
352 1, /* JAVA_UNDEF186 186 */
353 1, /* JAVA_NEW 187 */
354 1, /* JAVA_NEWARRAY 188 */
355 1, /* JAVA_ANEWARRAY 189 */
356 1, /* JAVA_ARRAYLENGTH 190 */
357 1, /* JAVA_ATHROW 191 */
358 1, /* JAVA_CHECKCAST 192 */
359 1, /* JAVA_INSTANCEOF 193 */
360 0, /* JAVA_MONITORENTER 194 */
361 0, /* JAVA_MONITOREXIT 195 */
362 0, /* JAVA_WIDE 196 */
363 1, /* JAVA_MULTIANEWARRAY 197 */
364 0, /* JAVA_IFNULL 198 */
365 0, /* JAVA_IFNONNULL 199 */
366 0, /* JAVA_GOTO_W 200 */
367 1, /* JAVA_JSR_W 201 */
368 0, /* JAVA_BREAKPOINT 202 */
369 1, /* JAVA_UNDEF203 203 */
370 1, /* JAVA_UNDEF204 204 */
371 1, /* JAVA_UNDEF205 205 */
372 1, /* JAVA_UNDEF206 206 */
373 1, /* JAVA_UNDEF207 207 */
374 1, /* JAVA_UNDEF208 208 */
375 1, /* JAVA_UNDEF209 209 */
376 1, /* JAVA_UNDEF210 210 */
377 1, /* JAVA_UNDEF211 211 */
378 1, /* JAVA_UNDEF212 212 */
379 1, /* JAVA_UNDEF213 213 */
380 1, /* JAVA_UNDEF214 214 */
381 1, /* JAVA_UNDEF215 215 */
382 1, /* JAVA_UNDEF216 216 */
383 1, /* JAVA_UNDEF217 217 */
384 1, /* JAVA_UNDEF218 218 */
385 1, /* JAVA_UNDEF219 219 */
386 1, /* JAVA_UNDEF220 220 */
387 1, /* JAVA_UNDEF221 221 */
388 1, /* JAVA_UNDEF222 222 */
389 1, /* JAVA_UNDEF223 223 */
390 1, /* JAVA_UNDEF224 224 */
391 1, /* JAVA_UNDEF225 225 */
392 1, /* JAVA_UNDEF226 226 */
393 1, /* JAVA_UNDEF227 227 */
394 1, /* JAVA_UNDEF228 228 */
395 1, /* JAVA_UNDEF229 229 */
396 1, /* JAVA_UNDEF230 230 */
397 1, /* JAVA_UNDEF231 231 */
398 1, /* JAVA_UNDEF232 232 */
399 1, /* JAVA_UNDEF233 233 */
400 1, /* JAVA_UNDEF234 234 */
401 1, /* JAVA_UNDEF235 235 */
402 1, /* JAVA_UNDEF236 236 */
403 1, /* JAVA_UNDEF237 237 */
404 1, /* JAVA_UNDEF238 238 */
405 1, /* JAVA_UNDEF239 239 */
406 1, /* JAVA_UNDEF240 240 */
407 1, /* JAVA_UNDEF241 241 */
408 1, /* JAVA_UNDEF242 242 */
409 1, /* JAVA_UNDEF243 243 */
410 1, /* JAVA_UNDEF244 244 */
411 1, /* JAVA_UNDEF245 245 */
412 1, /* JAVA_UNDEF246 246 */
413 1, /* JAVA_UNDEF247 247 */
414 1, /* JAVA_UNDEF248 248 */
415 1, /* JAVA_UNDEF249 249 */
416 1, /* JAVA_UNDEF250 250 */
417 1, /* JAVA_UNDEF251 251 */
418 1, /* JAVA_UNDEF252 252 */
419 1, /* JAVA_UNDEF253 253 */
420 1, /* JAVA_UNDEF254 254 */
421 1, /* JAVA_UNDEF255 255 */
425 /* size in bytes of Java opcodes **********************************************/
427 int jcommandsize[256] = {
430 1, /* JAVA_ACONST_NULL 1 */
431 1, /* JAVA_ICONST_M1 2 */
432 1, /* JAVA_ICONST_0 3 */
433 1, /* JAVA_ICONST_1 4 */
434 1, /* JAVA_ICONST_2 5 */
435 1, /* JAVA_ICONST_3 6 */
436 1, /* JAVA_ICONST_4 7 */
437 1, /* JAVA_ICONST_5 8 */
438 1, /* JAVA_LCONST_0 9 */
439 1, /* JAVA_LCONST_1 10 */
440 1, /* JAVA_FCONST_0 11 */
441 1, /* JAVA_FCONST_1 12 */
442 1, /* JAVA_FCONST_2 13 */
443 1, /* JAVA_DCONST_0 14 */
444 1, /* JAVA_DCONST_1 15 */
445 2, /* JAVA_BIPUSH 16 */
446 3, /* JAVA_SIPUSH 17 */
447 2, /* JAVA_LDC1 18 */
448 3, /* JAVA_LDC2 19 */
449 3, /* JAVA_LDC2W 20 */
450 2, /* JAVA_ILOAD 21 */
451 2, /* JAVA_LLOAD 22 */
452 2, /* JAVA_FLOAD 23 */
453 2, /* JAVA_DLOAD 24 */
454 2, /* JAVA_ALOAD 25 */
455 1, /* JAVA_ILOAD_0 26 */
456 1, /* JAVA_ILOAD_1 27 */
457 1, /* JAVA_ILOAD_2 28 */
458 1, /* JAVA_ILOAD_3 29 */
459 1, /* JAVA_LLOAD_0 30 */
460 1, /* JAVA_LLOAD_1 31 */
461 1, /* JAVA_LLOAD_2 32 */
462 1, /* JAVA_LLOAD_3 33 */
463 1, /* JAVA_FLOAD_0 34 */
464 1, /* JAVA_FLOAD_1 35 */
465 1, /* JAVA_FLOAD_2 36 */
466 1, /* JAVA_FLOAD_3 37 */
467 1, /* JAVA_DLOAD_0 38 */
468 1, /* JAVA_DLOAD_1 39 */
469 1, /* JAVA_DLOAD_2 40 */
470 1, /* JAVA_DLOAD_3 41 */
471 1, /* JAVA_ALOAD_0 42 */
472 1, /* JAVA_ALOAD_1 43 */
473 1, /* JAVA_ALOAD_2 44 */
474 1, /* JAVA_ALOAD_3 45 */
475 1, /* JAVA_IALOAD 46 */
476 1, /* JAVA_LALOAD 47 */
477 1, /* JAVA_FALOAD 48 */
478 1, /* JAVA_DALOAD 49 */
479 1, /* JAVA_AALOAD 50 */
480 1, /* JAVA_BALOAD 51 */
481 1, /* JAVA_CALOAD 52 */
482 1, /* JAVA_SALOAD 53 */
483 2, /* JAVA_ISTORE 54 */
484 2, /* JAVA_LSTORE 55 */
485 2, /* JAVA_FSTORE 56 */
486 2, /* JAVA_DSTORE 57 */
487 2, /* JAVA_ASTORE 58 */
488 1, /* JAVA_ISTORE_0 59 */
489 1, /* JAVA_ISTORE_1 60 */
490 1, /* JAVA_ISTORE_2 61 */
491 1, /* JAVA_ISTORE_3 62 */
492 1, /* JAVA_LSTORE_0 63 */
493 1, /* JAVA_LSTORE_1 64 */
494 1, /* JAVA_LSTORE_2 65 */
495 1, /* JAVA_LSTORE_3 66 */
496 1, /* JAVA_FSTORE_0 67 */
497 1, /* JAVA_FSTORE_1 68 */
498 1, /* JAVA_FSTORE_2 69 */
499 1, /* JAVA_FSTORE_3 70 */
500 1, /* JAVA_DSTORE_0 71 */
501 1, /* JAVA_DSTORE_1 72 */
502 1, /* JAVA_DSTORE_2 73 */
503 1, /* JAVA_DSTORE_3 74 */
504 1, /* JAVA_ASTORE_0 75 */
505 1, /* JAVA_ASTORE_1 76 */
506 1, /* JAVA_ASTORE_2 77 */
507 1, /* JAVA_ASTORE_3 78 */
508 1, /* JAVA_IASTORE 79 */
509 1, /* JAVA_LASTORE 80 */
510 1, /* JAVA_FASTORE 81 */
511 1, /* JAVA_DASTORE 82 */
512 1, /* JAVA_AASTORE 83 */
513 1, /* JAVA_BASTORE 84 */
514 1, /* JAVA_CASTORE 85 */
515 1, /* JAVA_SASTORE 86 */
517 1, /* JAVA_POP2 88 */
519 1, /* JAVA_DUP_X1 90 */
520 1, /* JAVA_DUP_X2 91 */
521 1, /* JAVA_DUP2 92 */
522 1, /* JAVA_DUP2_X1 93 */
523 1, /* JAVA_DUP2_X2 94 */
524 1, /* JAVA_SWAP 95 */
525 1, /* JAVA_IADD 96 */
526 1, /* JAVA_LADD 97 */
527 1, /* JAVA_FADD 98 */
528 1, /* JAVA_DADD 99 */
529 1, /* JAVA_ISUB 100 */
530 1, /* JAVA_LSUB 101 */
531 1, /* JAVA_FSUB 102 */
532 1, /* JAVA_DSUB 103 */
533 1, /* JAVA_IMUL 104 */
534 1, /* JAVA_LMUL 105 */
535 1, /* JAVA_FMUL 106 */
536 1, /* JAVA_DMUL 107 */
537 1, /* JAVA_IDIV 108 */
538 1, /* JAVA_LDIV 109 */
539 1, /* JAVA_FDIV 110 */
540 1, /* JAVA_DDIV 111 */
541 1, /* JAVA_IREM 112 */
542 1, /* JAVA_LREM 113 */
543 1, /* JAVA_FREM 114 */
544 1, /* JAVA_DREM 115 */
545 1, /* JAVA_INEG 116 */
546 1, /* JAVA_LNEG 117 */
547 1, /* JAVA_FNEG 118 */
548 1, /* JAVA_DNEG 119 */
549 1, /* JAVA_ISHL 120 */
550 1, /* JAVA_LSHL 121 */
551 1, /* JAVA_ISHR 122 */
552 1, /* JAVA_LSHR 123 */
553 1, /* JAVA_IUSHR 124 */
554 1, /* JAVA_LUSHR 125 */
555 1, /* JAVA_IAND 126 */
556 1, /* JAVA_LAND 127 */
557 1, /* JAVA_IOR 128 */
558 1, /* JAVA_LOR 129 */
559 1, /* JAVA_IXOR 130 */
560 1, /* JAVA_LXOR 131 */
561 3, /* JAVA_IINC 132 */
562 1, /* JAVA_I2L 133 */
563 1, /* JAVA_I2F 134 */
564 1, /* JAVA_I2D 135 */
565 1, /* JAVA_L2I 136 */
566 1, /* JAVA_L2F 137 */
567 1, /* JAVA_L2D 138 */
568 1, /* JAVA_F2I 139 */
569 1, /* JAVA_F2L 140 */
570 1, /* JAVA_F2D 141 */
571 1, /* JAVA_D2I 142 */
572 1, /* JAVA_D2L 143 */
573 1, /* JAVA_D2F 144 */
574 1, /* JAVA_INT2BYTE 145 */
575 1, /* JAVA_INT2CHAR 146 */
576 1, /* JAVA_INT2SHORT 147 */
577 1, /* JAVA_LCMP 148 */
578 1, /* JAVA_FCMPL 149 */
579 1, /* JAVA_FCMPG 150 */
580 1, /* JAVA_DCMPL 151 */
581 1, /* JAVA_DCMPG 152 */
582 3, /* JAVA_IFEQ 153 */
583 3, /* JAVA_IFNE 154 */
584 3, /* JAVA_IFLT 155 */
585 3, /* JAVA_IFGE 156 */
586 3, /* JAVA_IFGT 157 */
587 3, /* JAVA_IFLE 158 */
588 3, /* JAVA_IF_ICMPEQ 159 */
589 3, /* JAVA_IF_ICMPNE 160 */
590 3, /* JAVA_IF_ICMPLT 161 */
591 3, /* JAVA_IF_ICMPGE 162 */
592 3, /* JAVA_IF_ICMPGT 163 */
593 3, /* JAVA_IF_ICMPLE 164 */
594 3, /* JAVA_IF_ACMPEQ 165 */
595 3, /* JAVA_IF_ACMPNE 166 */
596 3, /* JAVA_GOTO 167 */
597 3, /* JAVA_JSR 168 */
598 2, /* JAVA_RET 169 */
599 0, /* JAVA_TABLESWITCH 170 */ /* variable length */
600 0, /* JAVA_LOOKUPSWITCH 171 */ /* variable length */
601 1, /* JAVA_IRETURN 172 */
602 1, /* JAVA_LRETURN 173 */
603 1, /* JAVA_FRETURN 174 */
604 1, /* JAVA_DRETURN 175 */
605 1, /* JAVA_ARETURN 176 */
606 1, /* JAVA_RETURN 177 */
607 3, /* JAVA_GETSTATIC 178 */
608 3, /* JAVA_PUTSTATIC 179 */
609 3, /* JAVA_GETFIELD 180 */
610 3, /* JAVA_PUTFIELD 181 */
611 3, /* JAVA_INVOKEVIRTUAL 182 */
612 3, /* JAVA_INVOKESPECIAL 183 */
613 3, /* JAVA_INVOKESTATIC 184 */
614 5, /* JAVA_INVOKEINTERFACE 185 */
616 3, /* JAVA_NEW 187 */
617 2, /* JAVA_NEWARRAY 188 */
618 3, /* JAVA_ANEWARRAY 189 */
619 1, /* JAVA_ARRAYLENGTH 190 */
620 1, /* JAVA_ATHROW 191 */
621 3, /* JAVA_CHECKCAST 192 */
622 3, /* JAVA_INSTANCEOF 193 */
623 1, /* JAVA_MONITORENTER 194 */
624 1, /* JAVA_MONITOREXIT 195 */
625 0, /* JAVA_WIDE 196 */ /* variable length */
626 4, /* JAVA_MULTIANEWARRAY 197 */
627 3, /* JAVA_IFNULL 198 */
628 3, /* JAVA_IFNONNULL 199 */
629 5, /* JAVA_GOTO_W 200 */
630 5, /* JAVA_JSR_W 201 */
631 1, /* JAVA_BREAKPOINT 202 */
668 1,1,1,1,1,1,1,1,1,1,
673 /* Java opcode names *********************************************************/
675 char *opcode_names[256] = {
678 "ICONST_M1 ", /* ICONST_M1 2 */
679 "ICONST_0 ", /* ICONST_0 3 */
680 "ICONST_1 ", /* ICONST_1 4 */
681 "ICONST_2 ", /* ICONST_2 5 */
682 "ICONST_3 ", /* ICONST_3 6 */
683 "ICONST_4 ", /* ICONST_4 7 */
684 "ICONST_5 ", /* ICONST_5 8 */
685 "LCONST_0 ", /* LCONST_0 9 */
686 "LCONST_1 ", /* LCONST_1 10 */
687 "FCONST_0 ", /* FCONST_0 11 */
688 "FCONST_1 ", /* FCONST_1 12 */
689 "FCONST_2 ", /* FCONST_2 13 */
690 "DCONST_0 ", /* DCONST_0 14 */
691 "DCONST_1 ", /* DCONST_1 15 */
692 "BIPUSH ", /* BIPUSH 16 */
693 "SIPUSH ", /* SIPUSH 17 */
695 "LDC_W ", /* LDC_W 19 */
696 "LDC2_W ", /* LDC2_W 20 */
702 "ILOAD_0 ", /* ILOAD_0 26 */
703 "ILOAD_1 ", /* ILOAD_1 27 */
704 "ILOAD_2 ", /* ILOAD_2 28 */
705 "ILOAD_3 ", /* ILOAD_3 29 */
706 "LLOAD_0 ", /* LLOAD_0 30 */
707 "LLOAD_1 ", /* LLOAD_1 31 */
708 "LLOAD_2 ", /* LLOAD_2 32 */
709 "LLOAD_3 ", /* LLOAD_3 33 */
710 "FLOAD_0 ", /* FLOAD_0 34 */
711 "FLOAD_1 ", /* FLOAD_1 35 */
712 "FLOAD_2 ", /* FLOAD_2 36 */
713 "FLOAD_3 ", /* FLOAD_3 37 */
714 "DLOAD_0 ", /* DLOAD_0 38 */
715 "DLOAD_1 ", /* DLOAD_1 39 */
716 "DLOAD_2 ", /* DLOAD_2 40 */
717 "DLOAD_3 ", /* DLOAD_3 41 */
718 "ALOAD_0 ", /* ALOAD_0 42 */
719 "ALOAD_1 ", /* ALOAD_1 43 */
720 "ALOAD_2 ", /* ALOAD_2 44 */
721 "ALOAD_3 ", /* ALOAD_3 45 */
735 "ISTORE_0 ", /* ISTORE_0 59 */
736 "ISTORE_1 ", /* ISTORE_1 60 */
737 "ISTORE_2 ", /* ISTORE_2 61 */
738 "ISTORE_3 ", /* ISTORE_3 62 */
739 "LSTORE_0 ", /* LSTORE_0 63 */
740 "LSTORE_1 ", /* LSTORE_1 64 */
741 "LSTORE_2 ", /* LSTORE_2 65 */
742 "LSTORE_3 ", /* LSTORE_3 66 */
743 "FSTORE_0 ", /* FSTORE_0 67 */
744 "FSTORE_1 ", /* FSTORE_1 68 */
745 "FSTORE_2 ", /* FSTORE_2 69 */
746 "FSTORE_3 ", /* FSTORE_3 70 */
747 "DSTORE_0 ", /* DSTORE_0 71 */
748 "DSTORE_1 ", /* DSTORE_1 72 */
749 "DSTORE_2 ", /* DSTORE_2 73 */
750 "DSTORE_3 ", /* DSTORE_3 74 */
751 "ASTORE_0 ", /* ASTORE_0 75 */
752 "ASTORE_1 ", /* ASTORE_1 76 */
753 "ASTORE_2 ", /* ASTORE_2 77 */
754 "ASTORE_3 ", /* ASTORE_3 78 */
821 "INT2BYTE ", /* 145 */
822 "INT2CHAR ", /* 146 */
823 "INT2SHORT ", /* 147 */
835 "IF_ICMPEQ ", /* 159 */
836 "IF_ICMPNE ", /* 160 */
837 "IF_ICMPLT ", /* 161 */
838 "IF_ICMPGE ", /* 162 */
839 "IF_ICMPGT ", /* 163 */
840 "IF_ICMPLE ", /* 164 */
841 "IF_ACMPEQ ", /* 165 */
842 "IF_ACMPNE ", /* 166 */
846 "TABLESWITCH ", /* 170 */
847 "LOOKUPSWITCH ", /* 171 */
848 "IRETURN ", /* 172 */
849 "LRETURN ", /* 173 */
850 "FRETURN ", /* 174 */
851 "DRETURN ", /* 175 */
852 "ARETURN ", /* 176 */
854 "GETSTATIC ", /* 178 */
855 "PUTSTATIC ", /* 179 */
856 "GETFIELD ", /* 180 */
857 "PUTFIELD ", /* 181 */
858 "INVOKEVIRTUAL ", /* 182 */
859 "INVOKESPECIAL ", /* 183 */
860 "INVOKESTATIC ", /* 184 */
861 "INVOKEINTERFACE", /* 185 */
862 "UNDEF186 ", /* 186 */
864 "NEWARRAY ", /* 188 */
865 "ANEWARRAY ", /* 189 */
866 "ARRAYLENGTH ", /* 190 */
868 "CHECKCAST ", /* 192 */
869 "INSTANCEOF ", /* 193 */
870 "MONITORENTER ", /* 194 */
871 "MONITOREXIT ", /* 195 */
872 "WIDE ", /* WIDE 196 */
873 "MULTIANEWARRAY ", /* 197 */
875 "IFNONNULL ", /* 199 */
876 "GOTO_W ", /* GOTO_W 200 */
877 "JSR_W ", /* JSR_W 201 */
878 "BREAKPOINT ", /* BREAKPOINT 202 */
880 "UNDEF203", "UNDEF204", "UNDEF205",
881 "UNDEF206", "UNDEF207", "UNDEF208", "UNDEF209", "UNDEF210",
882 "UNDEF211", "UNDEF212", "UNDEF213", "UNDEF214", "UNDEF215",
883 "UNDEF216", "UNDEF217", "UNDEF218", "UNDEF219", "UNDEF220",
884 "UNDEF221", "UNDEF222", "UNDEF223", "UNDEF224", "UNDEF225",
885 "UNDEF226", "UNDEF227", "UNDEF228", "UNDEF229", "UNDEF230",
886 "UNDEF231", "UNDEF232", "UNDEF233", "UNDEF234", "UNDEF235",
887 "UNDEF236", "UNDEF237", "UNDEF238", "UNDEF239", "UNDEF240",
888 "UNDEF241", "UNDEF242", "UNDEF243", "UNDEF244", "UNDEF245",
889 "UNDEF246", "UNDEF247", "UNDEF248", "UNDEF249", "UNDEF250",
890 "UNDEF251", "UNDEF252", "UNDEF253", "UNDEF254", "UNDEF255"
894 /* jit_init ********************************************************************
896 Initializes the JIT subsystem.
898 *******************************************************************************/
902 #if defined(ENABLE_JIT)
903 /* initialize stack analysis subsystem */
908 /* initialize show subsystem */
914 /* initialize codegen subsystem */
918 /* initialize code subsystem */
922 /* Machine dependent initialization. */
924 #if defined(ENABLE_JIT)
925 # if defined(ENABLE_INTRP)
937 /* jit_close *******************************************************************
939 Close the JIT subsystem.
941 *******************************************************************************/
949 /* dummy function, used when there is no JavaVM code available */
951 static u1 *do_nothing_function(void)
957 /* jit_jitdata_new *************************************************************
959 Allocates and initalizes a new jitdata structure.
961 *******************************************************************************/
963 jitdata *jit_jitdata_new(methodinfo *m)
968 /* allocate jitdata structure and fill it */
973 jd->cd = DNEW(codegendata);
974 jd->rd = DNEW(registerdata);
975 #if defined(ENABLE_LOOP)
976 jd->ld = DNEW(loopdata);
979 /* Allocate codeinfo memory from the heap as we need to keep them. */
981 code = code_codeinfo_new(m);
983 /* Set codeinfo flags. */
985 #if defined(ENABLE_THREADS)
986 if (checksync && (m->flags & ACC_SYNCHRONIZED))
987 code_flag_synchronized(code);
989 if (checksync && (m->flags & ACC_SYNCHRONIZED))
990 code_unflag_leafmethod(code);
993 code_flag_leafmethod(code);
995 /* initialize variables */
999 jd->exceptiontable = NULL;
1000 jd->exceptiontablelength = 0;
1001 jd->returncount = 0;
1002 jd->branchtoentry = false;
1003 jd->branchtoend = false;
1004 jd->returncount = 0;
1005 jd->returnblock = NULL;
1006 jd->maxlocals = m->maxlocals;
1012 /* jit_compile *****************************************************************
1014 Translates one method to machine code.
1016 *******************************************************************************/
1018 static u1 *jit_compile_intern(jitdata *jd);
1020 u1 *jit_compile(methodinfo *m)
1026 STATISTICS(count_jit_calls++);
1028 /* Initialize the static function's class. */
1030 /* ATTENTION: This MUST be done before the method lock is aquired,
1031 otherwise we could run into a deadlock with <clinit>'s that
1032 call static methods of it's own class. */
1034 if ((m->flags & ACC_STATIC) && !(m->class->state & CLASS_INITIALIZED)) {
1035 #if !defined(NDEBUG)
1037 log_message_class("Initialize class ", m->class);
1040 if (!initialize_class(m->class))
1043 /* check if the method has been compiled during initialization */
1045 if ((m->code != NULL) && (m->code->entrypoint != NULL))
1046 return m->code->entrypoint;
1049 /* enter a monitor on the method */
1051 LOCK_MONITOR_ENTER(m);
1053 /* if method has been already compiled return immediately */
1055 if (m->code != NULL) {
1056 LOCK_MONITOR_EXIT(m);
1058 assert(m->code->entrypoint);
1059 return m->code->entrypoint;
1062 TRACECOMPILERCALLS();
1064 STATISTICS(count_methods++);
1066 #if defined(ENABLE_STATISTICS)
1069 if (opt_getcompilingtime)
1070 compilingtime_start();
1073 /* mark start of dump memory area */
1075 dumpsize = dump_size();
1077 /* create jitdata structure */
1079 jd = jit_jitdata_new(m);
1081 /* set the flags for the current JIT run */
1083 jd->flags = JITDATA_FLAG_PARSE;
1085 #if defined(ENABLE_VERIFIER)
1087 jd->flags |= JITDATA_FLAG_VERIFY;
1090 #if defined(ENABLE_PROFILING)
1092 jd->flags |= JITDATA_FLAG_INSTRUMENT;
1095 #if defined(ENABLE_IFCONV)
1097 jd->flags |= JITDATA_FLAG_IFCONV;
1100 #if defined(ENABLE_INLINING) && defined(ENABLE_INLINING_DEBUG)
1101 if (opt_inlining && opt_inline_debug_all)
1102 jd->flags |= JITDATA_FLAG_INLINE;
1105 if (opt_showintermediate)
1106 jd->flags |= JITDATA_FLAG_SHOWINTERMEDIATE;
1108 if (opt_showdisassemble)
1109 jd->flags |= JITDATA_FLAG_SHOWDISASSEMBLE;
1111 if (opt_verbosecall)
1112 jd->flags |= JITDATA_FLAG_VERBOSECALL;
1114 #if defined(ENABLE_REPLACEMENT) && defined(ENABLE_INLINING)
1116 jd->flags |= JITDATA_FLAG_COUNTDOWN;
1119 #if defined(ENABLE_JIT)
1120 # if defined(ENABLE_INTRP)
1123 /* initialize the register allocator */
1129 /* setup the codegendata memory */
1133 /* now call internal compile function */
1135 r = jit_compile_intern(jd);
1138 /* We had an exception! Finish stuff here if necessary. */
1140 /* release codeinfo */
1142 code_codeinfo_free(jd->code);
1144 #if defined(ENABLE_PROFILING)
1145 /* Release memory for basic block profiling information. */
1147 if (JITDATA_HAS_FLAG_INSTRUMENT(jd))
1148 if (jd->code->bbfrequency != NULL)
1149 MFREE(jd->code->bbfrequency, u4, jd->code->basicblockcount);
1153 DEBUG_JIT_COMPILEVERBOSE("Running: ");
1156 /* release dump area */
1158 dump_release(dumpsize);
1160 #if defined(ENABLE_STATISTICS)
1163 if (opt_getcompilingtime)
1164 compilingtime_stop();
1167 /* leave the monitor */
1169 LOCK_MONITOR_EXIT(m);
1171 /* return pointer to the methods entry point */
1177 /* jit_recompile ***************************************************************
1179 Recompiles a Java method.
1181 *******************************************************************************/
1183 u1 *jit_recompile(methodinfo *m)
1190 /* check for max. optimization level */
1192 optlevel = (m->code) ? m->code->optlevel : 0;
1195 if (optlevel == 1) {
1196 /* log_message_method("not recompiling: ", m); */
1201 DEBUG_JIT_COMPILEVERBOSE("Recompiling start: ");
1203 STATISTICS(count_jit_calls++);
1205 #if defined(ENABLE_STATISTICS)
1208 if (opt_getcompilingtime)
1209 compilingtime_start();
1212 /* mark start of dump memory area */
1214 dumpsize = dump_size();
1216 /* create jitdata structure */
1218 jd = jit_jitdata_new(m);
1220 /* set the current optimization level to the previous one plus 1 */
1222 jd->code->optlevel = optlevel + 1;
1224 /* get the optimization flags for the current JIT run */
1226 #if defined(ENABLE_VERIFIER)
1227 jd->flags |= JITDATA_FLAG_VERIFY;
1230 /* jd->flags |= JITDATA_FLAG_REORDER; */
1231 if (opt_showintermediate)
1232 jd->flags |= JITDATA_FLAG_SHOWINTERMEDIATE;
1233 if (opt_showdisassemble)
1234 jd->flags |= JITDATA_FLAG_SHOWDISASSEMBLE;
1235 if (opt_verbosecall)
1236 jd->flags |= JITDATA_FLAG_VERBOSECALL;
1238 #if defined(ENABLE_INLINING)
1240 jd->flags |= JITDATA_FLAG_INLINE;
1243 #if defined(ENABLE_JIT)
1244 # if defined(ENABLE_INTRP)
1247 /* initialize the register allocator */
1252 /* setup the codegendata memory */
1256 /* now call internal compile function */
1258 r = jit_compile_intern(jd);
1261 /* We had an exception! Finish stuff here if necessary. */
1263 /* release codeinfo */
1265 code_codeinfo_free(jd->code);
1268 /* release dump area */
1270 dump_release(dumpsize);
1272 #if defined(ENABLE_STATISTICS)
1275 if (opt_getcompilingtime)
1276 compilingtime_stop();
1279 DEBUG_JIT_COMPILEVERBOSE("Recompiling done: ");
1281 /* return pointer to the methods entry point */
1287 /* jit_compile_intern **********************************************************
1289 Static internal function which does the actual compilation.
1291 *******************************************************************************/
1293 static u1 *jit_compile_intern(jitdata *jd)
1299 #if defined(ENABLE_RT_TIMING)
1300 struct timespec time_start,time_checks,time_parse,time_stack,
1301 time_typecheck,time_loop,time_ifconv,time_alloc,
1305 RT_TIMING_GET_TIME(time_start);
1307 /* get required compiler data */
1309 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1316 #if defined(ENABLE_DEBUG_FILTER)
1317 show_filters_apply(jd->m);
1320 /* handle native methods and create a native stub */
1322 if (m->flags & ACC_NATIVE) {
1325 f = native_method_resolve(m);
1330 code = codegen_generate_stub_native(m, f);
1332 /* Native methods are never recompiled. */
1338 return code->entrypoint;
1341 /* if there is no javacode, print error message and return empty method */
1343 if (m->jcode == NULL) {
1344 DEBUG_JIT_COMPILEVERBOSE("No code given for: ");
1346 code->entrypoint = (u1 *) (ptrint) do_nothing_function;
1349 return code->entrypoint; /* return empty method */
1352 #if defined(ENABLE_STATISTICS)
1354 count_javacodesize += m->jcodelength + 18;
1355 count_tryblocks += jd->exceptiontablelength;
1356 count_javaexcsize += jd->exceptiontablelength * SIZEOF_VOID_P;
1360 RT_TIMING_GET_TIME(time_checks);
1362 #if defined(WITH_CLASSPATH_SUN)
1363 /* Code for Sun's OpenJDK (see
1364 hotspot/src/share/vm/classfile/verifier.cpp
1365 (Verifier::is_eligible_for_verification)): Don't verify
1366 dynamically-generated bytecodes. */
1368 # if defined(ENABLE_VERIFIER)
1369 if (class_issubclass(m->class, class_sun_reflect_MagicAccessorImpl))
1370 jd->flags &= ~JITDATA_FLAG_VERIFY;
1374 /* call the compiler passes ***********************************************/
1376 DEBUG_JIT_COMPILEVERBOSE("Parsing: ");
1378 /* call parse pass */
1381 DEBUG_JIT_COMPILEVERBOSE("Exception while parsing: ");
1385 RT_TIMING_GET_TIME(time_parse);
1387 DEBUG_JIT_COMPILEVERBOSE("Parsing done: ");
1389 #if defined(ENABLE_JIT)
1390 # if defined(ENABLE_INTRP)
1393 DEBUG_JIT_COMPILEVERBOSE("Analysing: ");
1395 /* call stack analysis pass */
1397 if (!stack_analyse(jd)) {
1398 DEBUG_JIT_COMPILEVERBOSE("Exception while analysing: ");
1402 RT_TIMING_GET_TIME(time_stack);
1404 DEBUG_JIT_COMPILEVERBOSE("Analysing done: ");
1406 /* Build the CFG. This has to be done after stack_analyse, as
1407 there happens the JSR elimination. */
1412 #ifdef ENABLE_VERIFIER
1413 if (JITDATA_HAS_FLAG_VERIFY(jd)) {
1414 DEBUG_JIT_COMPILEVERBOSE("Typechecking: ");
1416 /* call typecheck pass */
1417 if (!typecheck(jd)) {
1418 DEBUG_JIT_COMPILEVERBOSE("Exception while typechecking: ");
1423 DEBUG_JIT_COMPILEVERBOSE("Typechecking done: ");
1426 RT_TIMING_GET_TIME(time_typecheck);
1428 #if defined(ENABLE_LOOP)
1433 jit_renumber_basicblocks(jd);
1436 RT_TIMING_GET_TIME(time_loop);
1438 #if defined(ENABLE_IFCONV)
1439 if (JITDATA_HAS_FLAG_IFCONV(jd)) {
1440 if (!ifconv_static(jd))
1442 jit_renumber_basicblocks(jd);
1445 RT_TIMING_GET_TIME(time_ifconv);
1449 #if defined(ENABLE_INLINING)
1450 if (JITDATA_HAS_FLAG_INLINE(jd)) {
1451 if (!inline_inline(jd))
1456 #if defined(ENABLE_PROFILING)
1457 /* Basic block reordering. I think this should be done after
1458 if-conversion, as we could lose the ability to do the
1461 if (JITDATA_HAS_FLAG_REORDER(jd)) {
1464 jit_renumber_basicblocks(jd);
1468 DEBUG_JIT_COMPILEVERBOSE("Allocating registers: ");
1470 #if defined(ENABLE_LSRA) && !defined(ENABLE_SSA)
1471 /* allocate registers */
1476 STATISTICS(count_methods_allocated_by_lsra++);
1479 # endif /* defined(ENABLE_LSRA) && !defined(ENABLE_SSA) */
1480 #if defined(ENABLE_SSA)
1481 /* allocate registers */
1482 if ((opt_lsra) && (jd->exceptiontablelength == 0)) {
1483 jd->ls = DNEW(lsradata);
1486 STATISTICS(count_methods_allocated_by_lsra++);
1489 # endif /* defined(ENABLE_SSA) */
1491 STATISTICS(count_locals_conflicts += (jd->maxlocals - 1) * (jd->maxlocals));
1496 STATISTICS(simplereg_make_statistics(jd));
1498 DEBUG_JIT_COMPILEVERBOSE("Allocating registers done: ");
1499 # if defined(ENABLE_INTRP)
1502 #endif /* defined(ENABLE_JIT) */
1503 RT_TIMING_GET_TIME(time_alloc);
1505 #if defined(ENABLE_PROFILING)
1506 /* Allocate memory for basic block profiling information. This
1507 _must_ be done after loop optimization and register allocation,
1508 since they can change the basic block count. */
1510 if (JITDATA_HAS_FLAG_INSTRUMENT(jd))
1511 code->bbfrequency = MNEW(u4, jd->basicblockcount);
1514 DEBUG_JIT_COMPILEVERBOSE("Generating code: ");
1516 /* now generate the machine code */
1518 #if defined(ENABLE_JIT)
1519 # if defined(ENABLE_INTRP)
1521 #if defined(ENABLE_VERIFIER)
1523 DEBUG_JIT_COMPILEVERBOSE("Typechecking (stackbased): ");
1525 if (!typecheck_stackbased(jd)) {
1526 DEBUG_JIT_COMPILEVERBOSE("Exception while typechecking (stackbased): ");
1531 if (!intrp_codegen(jd)) {
1532 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1539 if (!codegen_generate(jd)) {
1540 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1546 if (!intrp_codegen(jd)) {
1547 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1552 RT_TIMING_GET_TIME(time_codegen);
1554 DEBUG_JIT_COMPILEVERBOSE("Generating code done: ");
1556 #if !defined(NDEBUG) && defined(ENABLE_REPLACEMENT)
1557 /* activate replacement points inside newly created code */
1559 if (opt_TestReplacement)
1560 replace_activate_replacement_points(code, false);
1563 #if !defined(NDEBUG)
1564 #if defined(ENABLE_DEBUG_FILTER)
1565 if (jd->m->filtermatches & SHOW_FILTER_FLAG_SHOW_METHOD)
1568 /* intermediate and assembly code listings */
1570 if (JITDATA_HAS_FLAG_SHOWINTERMEDIATE(jd)) {
1571 show_method(jd, SHOW_CODE);
1573 else if (JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd)) {
1574 # if defined(ENABLE_DISASSEMBLER)
1575 DISASSEMBLE(code->entrypoint,
1576 code->entrypoint + (code->mcodelength - cd->dseglen));
1580 if (opt_showddatasegment)
1585 /* switch to the newly generated code */
1588 assert(code->entrypoint);
1590 /* add the current compile version to the methodinfo */
1592 code->prev = m->code;
1595 RT_TIMING_TIME_DIFF(time_start,time_checks,RT_TIMING_JIT_CHECKS);
1596 RT_TIMING_TIME_DIFF(time_checks,time_parse,RT_TIMING_JIT_PARSE);
1597 RT_TIMING_TIME_DIFF(time_parse,time_stack,RT_TIMING_JIT_STACK);
1598 RT_TIMING_TIME_DIFF(time_stack,time_typecheck,RT_TIMING_JIT_TYPECHECK);
1599 RT_TIMING_TIME_DIFF(time_typecheck,time_loop,RT_TIMING_JIT_LOOP);
1600 RT_TIMING_TIME_DIFF(time_loop,time_alloc,RT_TIMING_JIT_ALLOC);
1601 RT_TIMING_TIME_DIFF(time_alloc,time_codegen,RT_TIMING_JIT_CODEGEN);
1602 RT_TIMING_TIME_DIFF(time_start,time_codegen,RT_TIMING_JIT_TOTAL);
1604 /* return pointer to the methods entry point */
1606 return code->entrypoint;
1610 /* jit_invalidate_code *********************************************************
1612 Mark the compiled code of the given method as invalid and take care that
1613 it is replaced if necessary.
1615 XXX Not fully implemented, yet.
1617 *******************************************************************************/
1619 void jit_invalidate_code(methodinfo *m)
1625 if (code == NULL || code_is_invalid(code))
1628 code_flag_invalid(code);
1630 /* activate mappable replacement points */
1632 #if defined(ENABLE_REPLACEMENT)
1633 replace_activate_replacement_points(code, true);
1635 vm_abort("invalidating code only works with ENABLE_REPLACEMENT");
1640 /* jit_request_optimization ****************************************************
1642 Request optimization of the given method. If the code of the method is
1643 unoptimized, it will be invalidated, so the next jit_get_current_code(m)
1644 triggers an optimized recompilation.
1645 If the method is already optimized, this function does nothing.
1648 m................the method
1650 *******************************************************************************/
1652 void jit_request_optimization(methodinfo *m)
1658 if (code && code->optlevel == 0)
1659 jit_invalidate_code(m);
1663 /* jit_get_current_code ********************************************************
1665 Get the currently valid code for the given method. If there is no valid
1666 code, (re)compile the method.
1669 m................the method
1672 the codeinfo* for the current code, or
1673 NULL if an exception has been thrown during recompilation.
1675 *******************************************************************************/
1677 codeinfo *jit_get_current_code(methodinfo *m)
1681 /* if we have valid code, return it */
1683 if (m->code && !code_is_invalid(m->code))
1686 /* otherwise: recompile */
1688 if (!jit_recompile(m))
1697 /* jit_asm_compile *************************************************************
1699 This method is called from asm_vm_call_method and does:
1701 - create stackframe info for exceptions
1702 - compile the method
1703 - patch the entrypoint of the method into the calculated address in
1705 - flushes the instruction cache.
1707 *******************************************************************************/
1709 #if defined(ENABLE_JIT)
1710 #if !defined(JIT_COMPILER_VIA_SIGNAL)
1711 u1 *jit_asm_compile(methodinfo *m, u1 *mptr, u1 *sp, u1 *ra)
1713 stackframeinfo_t sfi;
1718 /* create the stackframeinfo (subtract 1 from RA as it points to the */
1719 /* instruction after the call) */
1721 stacktrace_stackframeinfo_add(&sfi, NULL, sp, ra, ra-1);
1723 /* actually compile the method */
1725 entrypoint = jit_compile(m);
1727 /* remove the stackframeinfo */
1729 stacktrace_stackframeinfo_remove(&sfi);
1731 /* there was a problem during compilation */
1733 if (entrypoint == NULL)
1736 /* get the method patch address */
1738 pa = md_jit_method_patch_address(sfi.pv, (void *) ra, mptr);
1740 /* patch the method entry point */
1744 *p = (ptrint) entrypoint;
1746 /* flush the instruction cache */
1748 md_icacheflush(pa, SIZEOF_VOID_P);
1754 /* jit_compile_handle **********************************************************
1756 This method is called from the appropriate signal handler which
1757 handles compiler-traps and does the following:
1759 - compile the method
1760 - patch the entrypoint of the method into the calculated address in
1762 - flush the instruction cache
1764 *******************************************************************************/
1766 void *jit_compile_handle(methodinfo *m, void *pv, void *ra, void *mptr)
1768 void *newpv; /* new compiled method PV */
1769 void *pa; /* patch address */
1770 uintptr_t *p; /* convenience pointer */
1772 /* Compile the method. */
1774 newpv = jit_compile(m);
1776 /* There was a problem during compilation. */
1781 /* Get the method patch address. */
1783 pa = md_jit_method_patch_address(pv, ra, mptr);
1785 /* Patch the method entry point. */
1787 p = (uintptr_t *) pa;
1789 *p = (uintptr_t) newpv;
1791 /* Flush both caches. */
1793 md_cacheflush(pa, SIZEOF_VOID_P);
1797 #endif /* defined(ENABLE_JIT) */
1800 /* jit_complement_condition ****************************************************
1802 Returns the complement of the passed conditional instruction.
1804 We use the order of the different conditions, e.g.:
1809 If the passed opcode is odd, we simply add 1 to get the complement.
1810 If the opcode is even, we subtract 1.
1817 *******************************************************************************/
1819 s4 jit_complement_condition(s4 opcode)
1823 return ICMD_IFNONNULL;
1825 case ICMD_IFNONNULL:
1829 /* check if opcode is odd */
1839 /* jit_renumber_basicblocks ****************************************************
1841 Set the ->nr of all blocks so it increases when traversing ->next.
1844 jitdata..........the current jitdata
1846 *******************************************************************************/
1848 void jit_renumber_basicblocks(jitdata *jd)
1854 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
1858 /* we have one block more than jd->basicblockcount (the end marker) */
1860 assert(nr == jd->basicblockcount + 1);
1864 /* jit_check_basicblock_numbers ************************************************
1866 Assert that the ->nr of the first block is zero and increases by 1 each
1867 time ->next is traversed.
1868 This function should be called before any analysis that relies on
1869 the basicblock numbers.
1872 jitdata..........the current jitdata
1874 NOTE: Aborts with an assertion if the condition is not met!
1876 *******************************************************************************/
1878 #if !defined(NDEBUG)
1879 void jit_check_basicblock_numbers(jitdata *jd)
1885 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
1886 assert(bptr->nr == nr);
1890 /* we have one block more than jd->basicblockcount (the end marker) */
1892 assert(nr == jd->basicblockcount + 1);
1894 #endif /* !defined(NDEBUG) */
1898 * These are local overrides for various environment variables in Emacs.
1899 * Please do not remove this and leave it at the end of the file, where
1900 * Emacs will automagically detect them.
1901 * ---------------------------------------------------------------------
1904 * indent-tabs-mode: t
1908 * vim:noexpandtab:sw=4:ts=4: