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
25 $Id: jit.c 7813 2007-04-25 19:20:13Z twisti $
36 #include "mm/memory.h"
38 #include "native/native.h"
40 #include "toolbox/logging.h"
42 #include "threads/lock-common.h"
44 #include "vm/global.h"
45 #include "vm/initialize.h"
47 #include "vm/jit/asmpart.h"
49 # include "vm/jit/cfg.h"
51 #include "vm/jit/codegen-common.h"
52 #include "vm/jit/disass.h"
53 #include "vm/jit/dseg.h"
54 #include "vm/jit/jit.h"
55 #include "vm/jit/md.h"
56 #include "vm/jit/parse.h"
57 #include "vm/jit/reg.h"
59 #include "vm/jit/show.h"
60 #include "vm/jit/stack.h"
62 #include "vm/jit/allocator/simplereg.h"
63 #if defined(ENABLE_LSRA) && !defined(ENABLE_SSA)
64 # include "vm/jit/allocator/lsra.h"
66 #if defined(ENABLE_SSA)
67 # include "vm/jit/optimizing/lsra.h"
68 # include "vm/jit/optimizing/ssa.h"
71 #include "vm/jit/loop/analyze.h"
72 #include "vm/jit/loop/graph.h"
73 #include "vm/jit/loop/loop.h"
75 #if defined(ENABLE_IFCONV)
76 # include "vm/jit/optimizing/ifconv.h"
79 #include "vm/jit/optimizing/reorder.h"
81 #include "vm/jit/verify/typecheck.h"
83 #if defined(ENABLE_THREADS)
84 # include "threads/native/threads.h"
87 #include "vmcore/class.h"
88 #include "vmcore/loader.h"
89 #include "vmcore/method.h"
90 #include "vmcore/options.h"
91 #include "vmcore/rt-timing.h"
92 #include "vmcore/statistics.h"
95 /* debug macros ***************************************************************/
98 #define DEBUG_JIT_COMPILEVERBOSE(x) \
100 if (compileverbose) { \
101 log_message_method(x, m); \
105 #define DEBUG_JIT_COMPILEVERBOSE(x) /* nothing */
109 /* the ICMD table ************************************************************/
112 #define N(name) name,
117 /* abbreviations for flags */
119 #define PEI ICMDTABLE_PEI
120 #define CALLS ICMDTABLE_CALLS
122 /* some machine dependent values */
127 #define IDIV_CALLS ICMDTABLE_CALLS
130 #if (SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
133 #define LDIV_CALLS ICMDTABLE_CALLS
136 /* include the actual table */
138 icmdtable_entry_t icmd_table[256] = {
139 #include <vm/jit/icmdtable.inc>
146 /* XXX hack until the old "PEI" definition is removed */
150 /* stackelement requirements of Java opcodes **********************************/
152 int stackreq[256] = {
154 1, /* JAVA_ACONST 1 */
155 1, /* JAVA_ICONST_M1 2 */
156 1, /* JAVA_ICONST_0 3 */
157 1, /* JAVA_ICONST_1 4 */
158 1, /* JAVA_ICONST_2 5 */
159 1, /* JAVA_ICONST_3 6 */
160 1, /* JAVA_ICONST_4 7 */
161 1, /* JAVA_ICONST_5 8 */
162 1, /* JAVA_LCONST_0 9 */
163 1, /* JAVA_LCONST_1 10 */
164 1, /* JAVA_FCONST_0 11 */
165 1, /* JAVA_FCONST_1 12 */
166 1, /* JAVA_FCONST_2 13 */
167 1, /* JAVA_DCONST_0 14 */
168 1, /* JAVA_DCONST_1 15 */
169 1, /* JAVA_BIPUSH 16 */
170 1, /* JAVA_SIPUSH 17 */
172 1, /* JAVA_LDC_W 19 */
173 1, /* JAVA_LDC2_W 20 */
174 1, /* JAVA_ILOAD 21 */
175 1, /* JAVA_LLOAD 22 */
176 1, /* JAVA_FLOAD 23 */
177 1, /* JAVA_DLOAD 24 */
178 1, /* JAVA_ALOAD 25 */
179 1, /* JAVA_ILOAD_0 26 */
180 1, /* JAVA_ILOAD_1 27 */
181 1, /* JAVA_ILOAD_2 28 */
182 1, /* JAVA_ILOAD_3 29 */
183 1, /* JAVA_LLOAD_0 30 */
184 1, /* JAVA_LLOAD_1 31 */
185 1, /* JAVA_LLOAD_2 32 */
186 1, /* JAVA_LLOAD_3 33 */
187 1, /* JAVA_FLOAD_0 34 */
188 1, /* JAVA_FLOAD_1 35 */
189 1, /* JAVA_FLOAD_2 36 */
190 1, /* JAVA_FLOAD_3 37 */
191 1, /* JAVA_DLOAD_0 38 */
192 1, /* JAVA_DLOAD_1 39 */
193 1, /* JAVA_DLOAD_2 40 */
194 1, /* JAVA_DLOAD_3 41 */
195 1, /* JAVA_ALOAD_0 42 */
196 1, /* JAVA_ALOAD_1 43 */
197 1, /* JAVA_ALOAD_2 44 */
198 1, /* JAVA_ALOAD_3 45 */
199 1, /* JAVA_IALOAD 46 */
200 1, /* JAVA_LALOAD 47 */
201 1, /* JAVA_FALOAD 48 */
202 1, /* JAVA_DALOAD 49 */
203 1, /* JAVA_AALOAD 50 */
204 1, /* JAVA_BALOAD 51 */
205 1, /* JAVA_CALOAD 52 */
206 1, /* JAVA_SALOAD 53 */
207 0, /* JAVA_ISTORE 54 */
208 0, /* JAVA_LSTORE 55 */
209 0, /* JAVA_FSTORE 56 */
210 0, /* JAVA_DSTORE 57 */
211 0, /* JAVA_ASTORE 58 */
212 0, /* JAVA_ISTORE_0 59 */
213 0, /* JAVA_ISTORE_1 60 */
214 0, /* JAVA_ISTORE_2 61 */
215 0, /* JAVA_ISTORE_3 62 */
216 0, /* JAVA_LSTORE_0 63 */
217 0, /* JAVA_LSTORE_1 64 */
218 0, /* JAVA_LSTORE_2 65 */
219 0, /* JAVA_LSTORE_3 66 */
220 0, /* JAVA_FSTORE_0 67 */
221 0, /* JAVA_FSTORE_1 68 */
222 0, /* JAVA_FSTORE_2 69 */
223 0, /* JAVA_FSTORE_3 70 */
224 0, /* JAVA_DSTORE_0 71 */
225 0, /* JAVA_DSTORE_1 72 */
226 0, /* JAVA_DSTORE_2 73 */
227 0, /* JAVA_DSTORE_3 74 */
228 0, /* JAVA_ASTORE_0 75 */
229 0, /* JAVA_ASTORE_1 76 */
230 0, /* JAVA_ASTORE_2 77 */
231 0, /* JAVA_ASTORE_3 78 */
232 0, /* JAVA_IASTORE 79 */
233 0, /* JAVA_LASTORE 80 */
234 0, /* JAVA_FASTORE 81 */
235 0, /* JAVA_DASTORE 82 */
236 0, /* JAVA_AASTORE 83 */
237 0, /* JAVA_BASTORE 84 */
238 0, /* JAVA_CASTORE 85 */
239 0, /* JAVA_SASTORE 86 */
241 0, /* JAVA_POP2 88 */
243 1+3, /* JAVA_DUP_X1 90 */
244 2+4, /* JAVA_DUP_X2 91 */
245 2, /* JAVA_DUP2 92 */
246 2+5, /* JAVA_DUP2_X1 93 */
247 3+6, /* JAVA_DUP2_X2 94 */
248 1+2, /* JAVA_SWAP 95 */
249 1, /* JAVA_IADD 96 */
250 1, /* JAVA_LADD 97 */
251 1, /* JAVA_FADD 98 */
252 1, /* JAVA_DADD 99 */
253 1, /* JAVA_ISUB 100 */
254 1, /* JAVA_LSUB 101 */
255 1, /* JAVA_FSUB 102 */
256 1, /* JAVA_DSUB 103 */
257 1, /* JAVA_IMUL 104 */
258 1, /* JAVA_LMUL 105 */
259 1, /* JAVA_FMUL 106 */
260 1, /* JAVA_DMUL 107 */
261 1, /* JAVA_IDIV 108 */
262 1, /* JAVA_LDIV 109 */
263 1, /* JAVA_FDIV 110 */
264 1, /* JAVA_DDIV 111 */
265 1, /* JAVA_IREM 112 */
266 1, /* JAVA_LREM 113 */
267 1, /* JAVA_FREM 114 */
268 1, /* JAVA_DREM 115 */
269 1, /* JAVA_INEG 116 */
270 1, /* JAVA_LNEG 117 */
271 1, /* JAVA_FNEG 118 */
272 1, /* JAVA_DNEG 119 */
273 1, /* JAVA_ISHL 120 */
274 1, /* JAVA_LSHL 121 */
275 1, /* JAVA_ISHR 122 */
276 1, /* JAVA_LSHR 123 */
277 1, /* JAVA_IUSHR 124 */
278 1, /* JAVA_LUSHR 125 */
279 1, /* JAVA_IAND 126 */
280 1, /* JAVA_LAND 127 */
281 1, /* JAVA_IOR 128 */
282 1, /* JAVA_LOR 129 */
283 1, /* JAVA_IXOR 130 */
284 1, /* JAVA_LXOR 131 */
285 0, /* JAVA_IINC 132 */
286 1, /* JAVA_I2L 133 */
287 1, /* JAVA_I2F 134 */
288 1, /* JAVA_I2D 135 */
289 1, /* JAVA_L2I 136 */
290 1, /* JAVA_L2F 137 */
291 1, /* JAVA_L2D 138 */
292 1, /* JAVA_F2I 139 */
293 1, /* JAVA_F2L 140 */
294 1, /* JAVA_F2D 141 */
295 1, /* JAVA_D2I 142 */
296 1, /* JAVA_D2L 143 */
297 1, /* JAVA_D2F 144 */
298 1, /* JAVA_INT2BYTE 145 */
299 1, /* JAVA_INT2CHAR 146 */
300 1, /* JAVA_INT2SHORT 147 */
301 1, /* JAVA_LCMP 148 */
302 1, /* JAVA_FCMPL 149 */
303 1, /* JAVA_FCMPG 150 */
304 1, /* JAVA_DCMPL 151 */
305 1, /* JAVA_DCMPG 152 */
306 0, /* JAVA_IFEQ 153 */
307 0, /* JAVA_IFNE 154 */
308 0, /* JAVA_IFLT 155 */
309 0, /* JAVA_IFGE 156 */
310 0, /* JAVA_IFGT 157 */
311 0, /* JAVA_IFLE 158 */
312 0, /* JAVA_IF_ICMPEQ 159 */
313 0, /* JAVA_IF_ICMPNE 160 */
314 0, /* JAVA_IF_ICMPLT 161 */
315 0, /* JAVA_IF_ICMPGE 162 */
316 0, /* JAVA_IF_ICMPGT 163 */
317 0, /* JAVA_IF_ICMPLE 164 */
318 0, /* JAVA_IF_ACMPEQ 165 */
319 0, /* JAVA_IF_ACMPNE 166 */
320 0, /* JAVA_GOTO 167 */
321 1, /* JAVA_JSR 168 */
322 0, /* JAVA_RET 169 */
323 0, /* JAVA_TABLESWITCH 170 */
324 0, /* JAVA_LOOKUPSWITCH 171 */
325 0, /* JAVA_IRETURN 172 */
326 0, /* JAVA_LRETURN 173 */
327 0, /* JAVA_FRETURN 174 */
328 0, /* JAVA_DRETURN 175 */
329 0, /* JAVA_ARETURN 176 */
330 0, /* JAVA_RETURN 177 */
331 1, /* JAVA_GETSTATIC 178 */
332 0, /* JAVA_PUTSTATIC 179 */
333 1, /* JAVA_GETFIELD 180 */
334 0, /* JAVA_PUTFIELD 181 */
335 1, /* JAVA_INVOKEVIRTUAL 182 */
336 1, /* JAVA_INVOKESPECIAL 183 */
337 1, /* JAVA_INVOKESTATIC 184 */
338 1, /* JAVA_INVOKEINTERFACE 185 */
339 1, /* JAVA_UNDEF186 186 */
340 1, /* JAVA_NEW 187 */
341 1, /* JAVA_NEWARRAY 188 */
342 1, /* JAVA_ANEWARRAY 189 */
343 1, /* JAVA_ARRAYLENGTH 190 */
344 1, /* JAVA_ATHROW 191 */
345 1, /* JAVA_CHECKCAST 192 */
346 1, /* JAVA_INSTANCEOF 193 */
347 0, /* JAVA_MONITORENTER 194 */
348 0, /* JAVA_MONITOREXIT 195 */
349 0, /* JAVA_WIDE 196 */
350 1, /* JAVA_MULTIANEWARRAY 197 */
351 0, /* JAVA_IFNULL 198 */
352 0, /* JAVA_IFNONNULL 199 */
353 0, /* JAVA_GOTO_W 200 */
354 1, /* JAVA_JSR_W 201 */
355 0, /* JAVA_BREAKPOINT 202 */
356 1, /* JAVA_UNDEF203 203 */
357 1, /* JAVA_UNDEF204 204 */
358 1, /* JAVA_UNDEF205 205 */
359 1, /* JAVA_UNDEF206 206 */
360 1, /* JAVA_UNDEF207 207 */
361 1, /* JAVA_UNDEF208 208 */
362 1, /* JAVA_UNDEF209 209 */
363 1, /* JAVA_UNDEF210 210 */
364 1, /* JAVA_UNDEF211 211 */
365 1, /* JAVA_UNDEF212 212 */
366 1, /* JAVA_UNDEF213 213 */
367 1, /* JAVA_UNDEF214 214 */
368 1, /* JAVA_UNDEF215 215 */
369 1, /* JAVA_UNDEF216 216 */
370 1, /* JAVA_UNDEF217 217 */
371 1, /* JAVA_UNDEF218 218 */
372 1, /* JAVA_UNDEF219 219 */
373 1, /* JAVA_UNDEF220 220 */
374 1, /* JAVA_UNDEF221 221 */
375 1, /* JAVA_UNDEF222 222 */
376 1, /* JAVA_UNDEF223 223 */
377 1, /* JAVA_UNDEF224 224 */
378 1, /* JAVA_UNDEF225 225 */
379 1, /* JAVA_UNDEF226 226 */
380 1, /* JAVA_UNDEF227 227 */
381 1, /* JAVA_UNDEF228 228 */
382 1, /* JAVA_UNDEF229 229 */
383 1, /* JAVA_UNDEF230 230 */
384 1, /* JAVA_UNDEF231 231 */
385 1, /* JAVA_UNDEF232 232 */
386 1, /* JAVA_UNDEF233 233 */
387 1, /* JAVA_UNDEF234 234 */
388 1, /* JAVA_UNDEF235 235 */
389 1, /* JAVA_UNDEF236 236 */
390 1, /* JAVA_UNDEF237 237 */
391 1, /* JAVA_UNDEF238 238 */
392 1, /* JAVA_UNDEF239 239 */
393 1, /* JAVA_UNDEF240 240 */
394 1, /* JAVA_UNDEF241 241 */
395 1, /* JAVA_UNDEF242 242 */
396 1, /* JAVA_UNDEF243 243 */
397 1, /* JAVA_UNDEF244 244 */
398 1, /* JAVA_UNDEF245 245 */
399 1, /* JAVA_UNDEF246 246 */
400 1, /* JAVA_UNDEF247 247 */
401 1, /* JAVA_UNDEF248 248 */
402 1, /* JAVA_UNDEF249 249 */
403 1, /* JAVA_UNDEF250 250 */
404 1, /* JAVA_UNDEF251 251 */
405 1, /* JAVA_UNDEF252 252 */
406 1, /* JAVA_UNDEF253 253 */
407 1, /* JAVA_UNDEF254 254 */
408 1, /* JAVA_UNDEF255 255 */
412 /* size in bytes of Java opcodes **********************************************/
414 int jcommandsize[256] = {
417 1, /* JAVA_ACONST_NULL 1 */
418 1, /* JAVA_ICONST_M1 2 */
419 1, /* JAVA_ICONST_0 3 */
420 1, /* JAVA_ICONST_1 4 */
421 1, /* JAVA_ICONST_2 5 */
422 1, /* JAVA_ICONST_3 6 */
423 1, /* JAVA_ICONST_4 7 */
424 1, /* JAVA_ICONST_5 8 */
425 1, /* JAVA_LCONST_0 9 */
426 1, /* JAVA_LCONST_1 10 */
427 1, /* JAVA_FCONST_0 11 */
428 1, /* JAVA_FCONST_1 12 */
429 1, /* JAVA_FCONST_2 13 */
430 1, /* JAVA_DCONST_0 14 */
431 1, /* JAVA_DCONST_1 15 */
432 2, /* JAVA_BIPUSH 16 */
433 3, /* JAVA_SIPUSH 17 */
434 2, /* JAVA_LDC1 18 */
435 3, /* JAVA_LDC2 19 */
436 3, /* JAVA_LDC2W 20 */
437 2, /* JAVA_ILOAD 21 */
438 2, /* JAVA_LLOAD 22 */
439 2, /* JAVA_FLOAD 23 */
440 2, /* JAVA_DLOAD 24 */
441 2, /* JAVA_ALOAD 25 */
442 1, /* JAVA_ILOAD_0 26 */
443 1, /* JAVA_ILOAD_1 27 */
444 1, /* JAVA_ILOAD_2 28 */
445 1, /* JAVA_ILOAD_3 29 */
446 1, /* JAVA_LLOAD_0 30 */
447 1, /* JAVA_LLOAD_1 31 */
448 1, /* JAVA_LLOAD_2 32 */
449 1, /* JAVA_LLOAD_3 33 */
450 1, /* JAVA_FLOAD_0 34 */
451 1, /* JAVA_FLOAD_1 35 */
452 1, /* JAVA_FLOAD_2 36 */
453 1, /* JAVA_FLOAD_3 37 */
454 1, /* JAVA_DLOAD_0 38 */
455 1, /* JAVA_DLOAD_1 39 */
456 1, /* JAVA_DLOAD_2 40 */
457 1, /* JAVA_DLOAD_3 41 */
458 1, /* JAVA_ALOAD_0 42 */
459 1, /* JAVA_ALOAD_1 43 */
460 1, /* JAVA_ALOAD_2 44 */
461 1, /* JAVA_ALOAD_3 45 */
462 1, /* JAVA_IALOAD 46 */
463 1, /* JAVA_LALOAD 47 */
464 1, /* JAVA_FALOAD 48 */
465 1, /* JAVA_DALOAD 49 */
466 1, /* JAVA_AALOAD 50 */
467 1, /* JAVA_BALOAD 51 */
468 1, /* JAVA_CALOAD 52 */
469 1, /* JAVA_SALOAD 53 */
470 2, /* JAVA_ISTORE 54 */
471 2, /* JAVA_LSTORE 55 */
472 2, /* JAVA_FSTORE 56 */
473 2, /* JAVA_DSTORE 57 */
474 2, /* JAVA_ASTORE 58 */
475 1, /* JAVA_ISTORE_0 59 */
476 1, /* JAVA_ISTORE_1 60 */
477 1, /* JAVA_ISTORE_2 61 */
478 1, /* JAVA_ISTORE_3 62 */
479 1, /* JAVA_LSTORE_0 63 */
480 1, /* JAVA_LSTORE_1 64 */
481 1, /* JAVA_LSTORE_2 65 */
482 1, /* JAVA_LSTORE_3 66 */
483 1, /* JAVA_FSTORE_0 67 */
484 1, /* JAVA_FSTORE_1 68 */
485 1, /* JAVA_FSTORE_2 69 */
486 1, /* JAVA_FSTORE_3 70 */
487 1, /* JAVA_DSTORE_0 71 */
488 1, /* JAVA_DSTORE_1 72 */
489 1, /* JAVA_DSTORE_2 73 */
490 1, /* JAVA_DSTORE_3 74 */
491 1, /* JAVA_ASTORE_0 75 */
492 1, /* JAVA_ASTORE_1 76 */
493 1, /* JAVA_ASTORE_2 77 */
494 1, /* JAVA_ASTORE_3 78 */
495 1, /* JAVA_IASTORE 79 */
496 1, /* JAVA_LASTORE 80 */
497 1, /* JAVA_FASTORE 81 */
498 1, /* JAVA_DASTORE 82 */
499 1, /* JAVA_AASTORE 83 */
500 1, /* JAVA_BASTORE 84 */
501 1, /* JAVA_CASTORE 85 */
502 1, /* JAVA_SASTORE 86 */
504 1, /* JAVA_POP2 88 */
506 1, /* JAVA_DUP_X1 90 */
507 1, /* JAVA_DUP_X2 91 */
508 1, /* JAVA_DUP2 92 */
509 1, /* JAVA_DUP2_X1 93 */
510 1, /* JAVA_DUP2_X2 94 */
511 1, /* JAVA_SWAP 95 */
512 1, /* JAVA_IADD 96 */
513 1, /* JAVA_LADD 97 */
514 1, /* JAVA_FADD 98 */
515 1, /* JAVA_DADD 99 */
516 1, /* JAVA_ISUB 100 */
517 1, /* JAVA_LSUB 101 */
518 1, /* JAVA_FSUB 102 */
519 1, /* JAVA_DSUB 103 */
520 1, /* JAVA_IMUL 104 */
521 1, /* JAVA_LMUL 105 */
522 1, /* JAVA_FMUL 106 */
523 1, /* JAVA_DMUL 107 */
524 1, /* JAVA_IDIV 108 */
525 1, /* JAVA_LDIV 109 */
526 1, /* JAVA_FDIV 110 */
527 1, /* JAVA_DDIV 111 */
528 1, /* JAVA_IREM 112 */
529 1, /* JAVA_LREM 113 */
530 1, /* JAVA_FREM 114 */
531 1, /* JAVA_DREM 115 */
532 1, /* JAVA_INEG 116 */
533 1, /* JAVA_LNEG 117 */
534 1, /* JAVA_FNEG 118 */
535 1, /* JAVA_DNEG 119 */
536 1, /* JAVA_ISHL 120 */
537 1, /* JAVA_LSHL 121 */
538 1, /* JAVA_ISHR 122 */
539 1, /* JAVA_LSHR 123 */
540 1, /* JAVA_IUSHR 124 */
541 1, /* JAVA_LUSHR 125 */
542 1, /* JAVA_IAND 126 */
543 1, /* JAVA_LAND 127 */
544 1, /* JAVA_IOR 128 */
545 1, /* JAVA_LOR 129 */
546 1, /* JAVA_IXOR 130 */
547 1, /* JAVA_LXOR 131 */
548 3, /* JAVA_IINC 132 */
549 1, /* JAVA_I2L 133 */
550 1, /* JAVA_I2F 134 */
551 1, /* JAVA_I2D 135 */
552 1, /* JAVA_L2I 136 */
553 1, /* JAVA_L2F 137 */
554 1, /* JAVA_L2D 138 */
555 1, /* JAVA_F2I 139 */
556 1, /* JAVA_F2L 140 */
557 1, /* JAVA_F2D 141 */
558 1, /* JAVA_D2I 142 */
559 1, /* JAVA_D2L 143 */
560 1, /* JAVA_D2F 144 */
561 1, /* JAVA_INT2BYTE 145 */
562 1, /* JAVA_INT2CHAR 146 */
563 1, /* JAVA_INT2SHORT 147 */
564 1, /* JAVA_LCMP 148 */
565 1, /* JAVA_FCMPL 149 */
566 1, /* JAVA_FCMPG 150 */
567 1, /* JAVA_DCMPL 151 */
568 1, /* JAVA_DCMPG 152 */
569 3, /* JAVA_IFEQ 153 */
570 3, /* JAVA_IFNE 154 */
571 3, /* JAVA_IFLT 155 */
572 3, /* JAVA_IFGE 156 */
573 3, /* JAVA_IFGT 157 */
574 3, /* JAVA_IFLE 158 */
575 3, /* JAVA_IF_ICMPEQ 159 */
576 3, /* JAVA_IF_ICMPNE 160 */
577 3, /* JAVA_IF_ICMPLT 161 */
578 3, /* JAVA_IF_ICMPGE 162 */
579 3, /* JAVA_IF_ICMPGT 163 */
580 3, /* JAVA_IF_ICMPLE 164 */
581 3, /* JAVA_IF_ACMPEQ 165 */
582 3, /* JAVA_IF_ACMPNE 166 */
583 3, /* JAVA_GOTO 167 */
584 3, /* JAVA_JSR 168 */
585 2, /* JAVA_RET 169 */
586 0, /* JAVA_TABLESWITCH 170 */ /* variable length */
587 0, /* JAVA_LOOKUPSWITCH 171 */ /* variable length */
588 1, /* JAVA_IRETURN 172 */
589 1, /* JAVA_LRETURN 173 */
590 1, /* JAVA_FRETURN 174 */
591 1, /* JAVA_DRETURN 175 */
592 1, /* JAVA_ARETURN 176 */
593 1, /* JAVA_RETURN 177 */
594 3, /* JAVA_GETSTATIC 178 */
595 3, /* JAVA_PUTSTATIC 179 */
596 3, /* JAVA_GETFIELD 180 */
597 3, /* JAVA_PUTFIELD 181 */
598 3, /* JAVA_INVOKEVIRTUAL 182 */
599 3, /* JAVA_INVOKESPECIAL 183 */
600 3, /* JAVA_INVOKESTATIC 184 */
601 5, /* JAVA_INVOKEINTERFACE 185 */
603 3, /* JAVA_NEW 187 */
604 2, /* JAVA_NEWARRAY 188 */
605 3, /* JAVA_ANEWARRAY 189 */
606 1, /* JAVA_ARRAYLENGTH 190 */
607 1, /* JAVA_ATHROW 191 */
608 3, /* JAVA_CHECKCAST 192 */
609 3, /* JAVA_INSTANCEOF 193 */
610 1, /* JAVA_MONITORENTER 194 */
611 1, /* JAVA_MONITOREXIT 195 */
612 0, /* JAVA_WIDE 196 */ /* variable length */
613 4, /* JAVA_MULTIANEWARRAY 197 */
614 3, /* JAVA_IFNULL 198 */
615 3, /* JAVA_IFNONNULL 199 */
616 5, /* JAVA_GOTO_W 200 */
617 5, /* JAVA_JSR_W 201 */
618 1, /* JAVA_BREAKPOINT 202 */
655 1,1,1,1,1,1,1,1,1,1,
660 /* Java opcode names *********************************************************/
662 char *opcode_names[256] = {
665 "ICONST_M1 ", /* ICONST_M1 2 */
666 "ICONST_0 ", /* ICONST_0 3 */
667 "ICONST_1 ", /* ICONST_1 4 */
668 "ICONST_2 ", /* ICONST_2 5 */
669 "ICONST_3 ", /* ICONST_3 6 */
670 "ICONST_4 ", /* ICONST_4 7 */
671 "ICONST_5 ", /* ICONST_5 8 */
672 "LCONST_0 ", /* LCONST_0 9 */
673 "LCONST_1 ", /* LCONST_1 10 */
674 "FCONST_0 ", /* FCONST_0 11 */
675 "FCONST_1 ", /* FCONST_1 12 */
676 "FCONST_2 ", /* FCONST_2 13 */
677 "DCONST_0 ", /* DCONST_0 14 */
678 "DCONST_1 ", /* DCONST_1 15 */
679 "BIPUSH ", /* BIPUSH 16 */
680 "SIPUSH ", /* SIPUSH 17 */
682 "LDC_W ", /* LDC_W 19 */
683 "LDC2_W ", /* LDC2_W 20 */
689 "ILOAD_0 ", /* ILOAD_0 26 */
690 "ILOAD_1 ", /* ILOAD_1 27 */
691 "ILOAD_2 ", /* ILOAD_2 28 */
692 "ILOAD_3 ", /* ILOAD_3 29 */
693 "LLOAD_0 ", /* LLOAD_0 30 */
694 "LLOAD_1 ", /* LLOAD_1 31 */
695 "LLOAD_2 ", /* LLOAD_2 32 */
696 "LLOAD_3 ", /* LLOAD_3 33 */
697 "FLOAD_0 ", /* FLOAD_0 34 */
698 "FLOAD_1 ", /* FLOAD_1 35 */
699 "FLOAD_2 ", /* FLOAD_2 36 */
700 "FLOAD_3 ", /* FLOAD_3 37 */
701 "DLOAD_0 ", /* DLOAD_0 38 */
702 "DLOAD_1 ", /* DLOAD_1 39 */
703 "DLOAD_2 ", /* DLOAD_2 40 */
704 "DLOAD_3 ", /* DLOAD_3 41 */
705 "ALOAD_0 ", /* ALOAD_0 42 */
706 "ALOAD_1 ", /* ALOAD_1 43 */
707 "ALOAD_2 ", /* ALOAD_2 44 */
708 "ALOAD_3 ", /* ALOAD_3 45 */
722 "ISTORE_0 ", /* ISTORE_0 59 */
723 "ISTORE_1 ", /* ISTORE_1 60 */
724 "ISTORE_2 ", /* ISTORE_2 61 */
725 "ISTORE_3 ", /* ISTORE_3 62 */
726 "LSTORE_0 ", /* LSTORE_0 63 */
727 "LSTORE_1 ", /* LSTORE_1 64 */
728 "LSTORE_2 ", /* LSTORE_2 65 */
729 "LSTORE_3 ", /* LSTORE_3 66 */
730 "FSTORE_0 ", /* FSTORE_0 67 */
731 "FSTORE_1 ", /* FSTORE_1 68 */
732 "FSTORE_2 ", /* FSTORE_2 69 */
733 "FSTORE_3 ", /* FSTORE_3 70 */
734 "DSTORE_0 ", /* DSTORE_0 71 */
735 "DSTORE_1 ", /* DSTORE_1 72 */
736 "DSTORE_2 ", /* DSTORE_2 73 */
737 "DSTORE_3 ", /* DSTORE_3 74 */
738 "ASTORE_0 ", /* ASTORE_0 75 */
739 "ASTORE_1 ", /* ASTORE_1 76 */
740 "ASTORE_2 ", /* ASTORE_2 77 */
741 "ASTORE_3 ", /* ASTORE_3 78 */
808 "INT2BYTE ", /* 145 */
809 "INT2CHAR ", /* 146 */
810 "INT2SHORT ", /* 147 */
822 "IF_ICMPEQ ", /* 159 */
823 "IF_ICMPNE ", /* 160 */
824 "IF_ICMPLT ", /* 161 */
825 "IF_ICMPGE ", /* 162 */
826 "IF_ICMPGT ", /* 163 */
827 "IF_ICMPLE ", /* 164 */
828 "IF_ACMPEQ ", /* 165 */
829 "IF_ACMPNE ", /* 166 */
833 "TABLESWITCH ", /* 170 */
834 "LOOKUPSWITCH ", /* 171 */
835 "IRETURN ", /* 172 */
836 "LRETURN ", /* 173 */
837 "FRETURN ", /* 174 */
838 "DRETURN ", /* 175 */
839 "ARETURN ", /* 176 */
841 "GETSTATIC ", /* 178 */
842 "PUTSTATIC ", /* 179 */
843 "GETFIELD ", /* 180 */
844 "PUTFIELD ", /* 181 */
845 "INVOKEVIRTUAL ", /* 182 */
846 "INVOKESPECIAL ", /* 183 */
847 "INVOKESTATIC ", /* 184 */
848 "INVOKEINTERFACE", /* 185 */
849 "UNDEF186 ", /* 186 */
851 "NEWARRAY ", /* 188 */
852 "ANEWARRAY ", /* 189 */
853 "ARRAYLENGTH ", /* 190 */
855 "CHECKCAST ", /* 192 */
856 "INSTANCEOF ", /* 193 */
857 "MONITORENTER ", /* 194 */
858 "MONITOREXIT ", /* 195 */
859 "WIDE ", /* WIDE 196 */
860 "MULTIANEWARRAY ", /* 197 */
862 "IFNONNULL ", /* 199 */
863 "GOTO_W ", /* GOTO_W 200 */
864 "JSR_W ", /* JSR_W 201 */
865 "BREAKPOINT ", /* BREAKPOINT 202 */
867 "UNDEF203", "UNDEF204", "UNDEF205",
868 "UNDEF206", "UNDEF207", "UNDEF208", "UNDEF209", "UNDEF210",
869 "UNDEF211", "UNDEF212", "UNDEF213", "UNDEF214", "UNDEF215",
870 "UNDEF216", "UNDEF217", "UNDEF218", "UNDEF219", "UNDEF220",
871 "UNDEF221", "UNDEF222", "UNDEF223", "UNDEF224", "UNDEF225",
872 "UNDEF226", "UNDEF227", "UNDEF228", "UNDEF229", "UNDEF230",
873 "UNDEF231", "UNDEF232", "UNDEF233", "UNDEF234", "UNDEF235",
874 "UNDEF236", "UNDEF237", "UNDEF238", "UNDEF239", "UNDEF240",
875 "UNDEF241", "UNDEF242", "UNDEF243", "UNDEF244", "UNDEF245",
876 "UNDEF246", "UNDEF247", "UNDEF248", "UNDEF249", "UNDEF250",
877 "UNDEF251", "UNDEF252", "UNDEF253", "UNDEF254", "UNDEF255"
881 /* jit_init ********************************************************************
883 Initializes the JIT subsystem.
885 *******************************************************************************/
889 #if defined(ENABLE_JIT)
890 /* initialize stack analysis subsystem */
895 /* initialize show subsystem */
901 /* initialize codegen subsystem */
905 /* initialize code subsystem */
911 /* jit_close *******************************************************************
913 Close the JIT subsystem.
915 *******************************************************************************/
923 /* dummy function, used when there is no JavaVM code available */
925 static u1 *do_nothing_function(void)
931 /* jit_jitdata_new *************************************************************
933 Allocates and initalizes a new jitdata structure.
935 *******************************************************************************/
937 jitdata *jit_jitdata_new(methodinfo *m)
941 /* allocate jitdata structure and fill it */
946 jd->cd = DNEW(codegendata);
947 jd->rd = DNEW(registerdata);
948 #if defined(ENABLE_LOOP)
949 jd->ld = DNEW(loopdata);
952 /* Allocate codeinfo memory from the heap as we need to keep them. */
954 jd->code = code_codeinfo_new(m);
956 /* initialize variables */
959 jd->exceptiontable = NULL;
960 jd->exceptiontablelength = 0;
962 jd->branchtoentry = false;
963 jd->branchtoend = false;
965 jd->returnblock = NULL;
966 jd->maxlocals = m->maxlocals;
968 #if defined(ENABLE_THREADS)
969 if (checksync && (m->flags & ACC_SYNCHRONIZED))
970 jd->isleafmethod = false;
973 jd->isleafmethod = true;
979 /* jit_compile *****************************************************************
981 Translates one method to machine code.
983 *******************************************************************************/
985 static u1 *jit_compile_intern(jitdata *jd);
987 u1 *jit_compile(methodinfo *m)
993 STATISTICS(count_jit_calls++);
995 /* Initialize the static function's class. */
997 /* ATTENTION: This MUST be done before the method lock is aquired,
998 otherwise we could run into a deadlock with <clinit>'s that
999 call static methods of it's own class. */
1001 if ((m->flags & ACC_STATIC) && !(m->class->state & CLASS_INITIALIZED)) {
1002 #if !defined(NDEBUG)
1004 log_message_class("Initialize class ", m->class);
1007 if (!initialize_class(m->class))
1010 /* check if the method has been compiled during initialization */
1012 if ((m->code != NULL) && (m->code->entrypoint != NULL))
1013 return m->code->entrypoint;
1016 /* enter a monitor on the method */
1018 LOCK_MONITOR_ENTER(m);
1020 /* if method has been already compiled return immediately */
1022 if (m->code != NULL) {
1023 LOCK_MONITOR_EXIT(m);
1025 assert(m->code->entrypoint);
1026 return m->code->entrypoint;
1029 STATISTICS(count_methods++);
1031 #if defined(ENABLE_STATISTICS)
1034 if (opt_getcompilingtime)
1035 compilingtime_start();
1038 /* mark start of dump memory area */
1040 dumpsize = dump_size();
1042 /* create jitdata structure */
1044 jd = jit_jitdata_new(m);
1046 /* set the flags for the current JIT run */
1048 jd->flags = JITDATA_FLAG_PARSE;
1050 #if defined(ENABLE_VERIFIER)
1052 jd->flags |= JITDATA_FLAG_VERIFY;
1055 #if defined(ENABLE_PROFILING)
1057 jd->flags |= JITDATA_FLAG_INSTRUMENT;
1060 #if defined(ENABLE_IFCONV)
1062 jd->flags |= JITDATA_FLAG_IFCONV;
1065 #if defined(ENABLE_INLINING) && defined(ENABLE_INLINING_DEBUG)
1066 if (opt_inlining && opt_inline_debug_all)
1067 jd->flags |= JITDATA_FLAG_INLINE;
1070 if (opt_showintermediate)
1071 jd->flags |= JITDATA_FLAG_SHOWINTERMEDIATE;
1073 if (opt_showdisassemble)
1074 jd->flags |= JITDATA_FLAG_SHOWDISASSEMBLE;
1076 if (opt_verbosecall)
1077 jd->flags |= JITDATA_FLAG_VERBOSECALL;
1079 #if defined(ENABLE_REPLACEMENT) && defined(ENABLE_INLINING)
1081 jd->flags |= JITDATA_FLAG_COUNTDOWN;
1084 #if defined(ENABLE_JIT)
1085 # if defined(ENABLE_INTRP)
1088 /* initialize the register allocator */
1094 /* setup the codegendata memory */
1098 /* now call internal compile function */
1100 r = jit_compile_intern(jd);
1103 /* We had an exception! Finish stuff here if necessary. */
1105 /* release codeinfo */
1107 code_codeinfo_free(jd->code);
1109 #if defined(ENABLE_PROFILING)
1110 /* Release memory for basic block profiling information. */
1112 if (JITDATA_HAS_FLAG_INSTRUMENT(jd))
1113 if (jd->code->bbfrequency != NULL)
1114 MFREE(jd->code->bbfrequency, u4, jd->code->basicblockcount);
1118 DEBUG_JIT_COMPILEVERBOSE("Running: ");
1121 /* release dump area */
1123 dump_release(dumpsize);
1125 #if defined(ENABLE_STATISTICS)
1128 if (opt_getcompilingtime)
1129 compilingtime_stop();
1132 /* leave the monitor */
1134 LOCK_MONITOR_EXIT(m);
1136 /* return pointer to the methods entry point */
1142 /* jit_recompile ***************************************************************
1144 Recompiles a Java method.
1146 *******************************************************************************/
1148 u1 *jit_recompile(methodinfo *m)
1155 /* check for max. optimization level */
1157 optlevel = (m->code) ? m->code->optlevel : 0;
1160 if (optlevel == 1) {
1161 /* log_message_method("not recompiling: ", m); */
1166 DEBUG_JIT_COMPILEVERBOSE("Recompiling start: ");
1168 STATISTICS(count_jit_calls++);
1170 #if defined(ENABLE_STATISTICS)
1173 if (opt_getcompilingtime)
1174 compilingtime_start();
1177 /* mark start of dump memory area */
1179 dumpsize = dump_size();
1181 /* create jitdata structure */
1183 jd = jit_jitdata_new(m);
1185 /* set the current optimization level to the previous one plus 1 */
1187 jd->code->optlevel = optlevel + 1;
1189 /* get the optimization flags for the current JIT run */
1191 #if defined(ENABLE_VERIFIER)
1192 jd->flags |= JITDATA_FLAG_VERIFY;
1195 /* jd->flags |= JITDATA_FLAG_REORDER; */
1196 if (opt_showintermediate)
1197 jd->flags |= JITDATA_FLAG_SHOWINTERMEDIATE;
1198 if (opt_showdisassemble)
1199 jd->flags |= JITDATA_FLAG_SHOWDISASSEMBLE;
1200 if (opt_verbosecall)
1201 jd->flags |= JITDATA_FLAG_VERBOSECALL;
1203 #if defined(ENABLE_INLINING)
1205 jd->flags |= JITDATA_FLAG_INLINE;
1208 #if defined(ENABLE_JIT)
1209 # if defined(ENABLE_INTRP)
1212 /* initialize the register allocator */
1217 /* setup the codegendata memory */
1221 /* now call internal compile function */
1223 r = jit_compile_intern(jd);
1226 /* We had an exception! Finish stuff here if necessary. */
1228 /* release codeinfo */
1230 code_codeinfo_free(jd->code);
1233 /* release dump area */
1235 dump_release(dumpsize);
1237 #if defined(ENABLE_STATISTICS)
1240 if (opt_getcompilingtime)
1241 compilingtime_stop();
1244 DEBUG_JIT_COMPILEVERBOSE("Recompiling done: ");
1246 /* return pointer to the methods entry point */
1252 /* jit_compile_intern **********************************************************
1254 Static internal function which does the actual compilation.
1256 *******************************************************************************/
1258 static u1 *jit_compile_intern(jitdata *jd)
1264 #if defined(ENABLE_RT_TIMING)
1265 struct timespec time_start,time_checks,time_parse,time_stack,
1266 time_typecheck,time_loop,time_ifconv,time_alloc,
1270 RT_TIMING_GET_TIME(time_start);
1272 /* get required compiler data */
1274 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1281 /* print log message for compiled method */
1283 DEBUG_JIT_COMPILEVERBOSE("Compiling: ");
1285 /* handle native methods and create a native stub */
1287 if (m->flags & ACC_NATIVE) {
1290 #if defined(WITH_STATIC_CLASSPATH)
1291 f = native_findfunction(m->class->name, m->name, m->descriptor,
1292 (m->flags & ACC_STATIC));
1299 code = codegen_generate_stub_native(m, f);
1301 assert(!m->code); /* native methods are never recompiled */
1304 return code->entrypoint;
1307 /* if there is no javacode, print error message and return empty method */
1309 if (m->jcode == NULL) {
1310 DEBUG_JIT_COMPILEVERBOSE("No code given for: ");
1312 code->entrypoint = (u1 *) (ptrint) do_nothing_function;
1315 return code->entrypoint; /* return empty method */
1318 #if defined(ENABLE_STATISTICS)
1320 count_javacodesize += m->jcodelength + 18;
1321 count_tryblocks += jd->exceptiontablelength;
1322 count_javaexcsize += jd->exceptiontablelength * SIZEOF_VOID_P;
1326 RT_TIMING_GET_TIME(time_checks);
1328 /* call the compiler passes ***********************************************/
1330 DEBUG_JIT_COMPILEVERBOSE("Parsing: ");
1332 /* call parse pass */
1335 DEBUG_JIT_COMPILEVERBOSE("Exception while parsing: ");
1339 RT_TIMING_GET_TIME(time_parse);
1341 DEBUG_JIT_COMPILEVERBOSE("Parsing done: ");
1343 #if defined(ENABLE_JIT)
1344 # if defined(ENABLE_INTRP)
1347 DEBUG_JIT_COMPILEVERBOSE("Analysing: ");
1349 /* call stack analysis pass */
1351 if (!stack_analyse(jd)) {
1352 DEBUG_JIT_COMPILEVERBOSE("Exception while analysing: ");
1356 RT_TIMING_GET_TIME(time_stack);
1358 DEBUG_JIT_COMPILEVERBOSE("Analysing done: ");
1360 /* Build the CFG. This has to be done after stack_analyse, as
1361 there happens the JSR elimination. */
1366 #ifdef ENABLE_VERIFIER
1367 if (JITDATA_HAS_FLAG_VERIFY(jd)) {
1368 DEBUG_JIT_COMPILEVERBOSE("Typechecking: ");
1370 /* call typecheck pass */
1371 if (!typecheck(jd)) {
1372 DEBUG_JIT_COMPILEVERBOSE("Exception while typechecking: ");
1377 DEBUG_JIT_COMPILEVERBOSE("Typechecking done: ");
1380 RT_TIMING_GET_TIME(time_typecheck);
1382 #if defined(ENABLE_LOOP)
1387 jit_renumber_basicblocks(jd);
1390 RT_TIMING_GET_TIME(time_loop);
1392 #if defined(ENABLE_IFCONV)
1393 if (JITDATA_HAS_FLAG_IFCONV(jd)) {
1394 if (!ifconv_static(jd))
1396 jit_renumber_basicblocks(jd);
1399 RT_TIMING_GET_TIME(time_ifconv);
1403 #if defined(ENABLE_INLINING)
1404 if (JITDATA_HAS_FLAG_INLINE(jd)) {
1405 if (!inline_inline(jd))
1410 #if defined(ENABLE_PROFILING)
1411 /* Basic block reordering. I think this should be done after
1412 if-conversion, as we could lose the ability to do the
1415 if (JITDATA_HAS_FLAG_REORDER(jd)) {
1418 jit_renumber_basicblocks(jd);
1422 DEBUG_JIT_COMPILEVERBOSE("Allocating registers: ");
1424 #if defined(ENABLE_LSRA) && !defined(ENABLE_SSA)
1425 /* allocate registers */
1430 STATISTICS(count_methods_allocated_by_lsra++);
1433 # endif /* defined(ENABLE_LSRA) && !defined(ENABLE_SSA) */
1434 #if defined(ENABLE_SSA)
1435 /* allocate registers */
1436 if ((opt_lsra) && (jd->exceptiontablelength == 0)) {
1437 jd->ls = DNEW(lsradata);
1440 STATISTICS(count_methods_allocated_by_lsra++);
1443 # endif /* defined(ENABLE_SSA) */
1445 STATISTICS(count_locals_conflicts += (jd->maxlocals - 1) * (jd->maxlocals));
1450 STATISTICS(simplereg_make_statistics(jd));
1452 DEBUG_JIT_COMPILEVERBOSE("Allocating registers done: ");
1453 # if defined(ENABLE_INTRP)
1456 #endif /* defined(ENABLE_JIT) */
1457 RT_TIMING_GET_TIME(time_alloc);
1459 #if defined(ENABLE_PROFLING)
1460 /* Allocate memory for basic block profiling information. This
1461 _must_ be done after loop optimization and register allocation,
1462 since they can change the basic block count. */
1464 if (JITDATA_HAS_FLAG_INSTRUMENT(jd))
1465 code->bbfrequency = MNEW(u4, jd->basicblockcount);
1468 DEBUG_JIT_COMPILEVERBOSE("Generating code: ");
1470 /* now generate the machine code */
1472 #if defined(ENABLE_JIT)
1473 # if defined(ENABLE_INTRP)
1475 #if defined(ENABLE_VERIFIER)
1477 DEBUG_JIT_COMPILEVERBOSE("Typechecking (stackbased): ");
1479 if (!typecheck_stackbased(jd)) {
1480 DEBUG_JIT_COMPILEVERBOSE("Exception while typechecking (stackbased): ");
1485 if (!intrp_codegen(jd)) {
1486 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1493 if (!codegen_generate(jd)) {
1494 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1500 if (!intrp_codegen(jd)) {
1501 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1506 RT_TIMING_GET_TIME(time_codegen);
1508 DEBUG_JIT_COMPILEVERBOSE("Generating code done: ");
1510 #if !defined(NDEBUG)
1511 /* intermediate and assembly code listings */
1513 if (JITDATA_HAS_FLAG_SHOWINTERMEDIATE(jd)) {
1514 show_method(jd, SHOW_CODE);
1516 else if (JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd)) {
1517 # if defined(ENABLE_DISASSEMBLER)
1518 DISASSEMBLE(code->entrypoint,
1519 code->entrypoint + (code->mcodelength - cd->dseglen));
1523 if (opt_showddatasegment)
1527 DEBUG_JIT_COMPILEVERBOSE("Compiling done: ");
1529 /* switch to the newly generated code */
1532 assert(code->entrypoint);
1534 /* add the current compile version to the methodinfo */
1536 code->prev = m->code;
1539 RT_TIMING_TIME_DIFF(time_start,time_checks,RT_TIMING_JIT_CHECKS);
1540 RT_TIMING_TIME_DIFF(time_checks,time_parse,RT_TIMING_JIT_PARSE);
1541 RT_TIMING_TIME_DIFF(time_parse,time_stack,RT_TIMING_JIT_STACK);
1542 RT_TIMING_TIME_DIFF(time_stack,time_typecheck,RT_TIMING_JIT_TYPECHECK);
1543 RT_TIMING_TIME_DIFF(time_typecheck,time_loop,RT_TIMING_JIT_LOOP);
1544 RT_TIMING_TIME_DIFF(time_loop,time_alloc,RT_TIMING_JIT_ALLOC);
1545 RT_TIMING_TIME_DIFF(time_alloc,time_codegen,RT_TIMING_JIT_CODEGEN);
1546 RT_TIMING_TIME_DIFF(time_start,time_codegen,RT_TIMING_JIT_TOTAL);
1548 /* return pointer to the methods entry point */
1550 return code->entrypoint;
1554 /* jit_invalidate_code *********************************************************
1556 Mark the compiled code of the given method as invalid and take care that
1557 it is replaced if necessary.
1559 XXX Not fully implemented, yet.
1561 *******************************************************************************/
1563 void jit_invalidate_code(methodinfo *m)
1568 if (code == NULL || CODE_IS_INVALID(code))
1571 CODE_SETFLAG_INVALID(code);
1573 /* activate mappable replacement points */
1575 #if defined(ENABLE_REPLACEMENT)
1576 replace_activate_replacement_points(code, true);
1578 vm_abort("invalidating code only works with ENABLE_REPLACEMENT");
1583 /* jit_request_optimization ****************************************************
1585 Request optimization of the given method. If the code of the method is
1586 unoptimized, it will be invalidated, so the next jit_get_current_code(m)
1587 triggers an optimized recompilation.
1588 If the method is already optimized, this function does nothing.
1591 m................the method
1593 *******************************************************************************/
1595 void jit_request_optimization(methodinfo *m)
1601 if (code && code->optlevel == 0)
1602 jit_invalidate_code(m);
1606 /* jit_get_current_code ********************************************************
1608 Get the currently valid code for the given method. If there is no valid
1609 code, (re)compile the method.
1612 m................the method
1615 the codeinfo* for the current code, or
1616 NULL if an exception has been thrown during recompilation.
1618 *******************************************************************************/
1620 codeinfo *jit_get_current_code(methodinfo *m)
1624 /* if we have valid code, return it */
1626 if (m->code && CODE_IS_VALID(m->code))
1629 /* otherwise: recompile */
1631 if (!jit_recompile(m))
1640 /* jit_asm_compile *************************************************************
1642 This method is called from asm_vm_call_method and does:
1644 - create stackframe info for exceptions
1645 - compile the method
1646 - patch the entrypoint of the method into the calculated address in
1648 - flushes the instruction cache.
1650 *******************************************************************************/
1652 #if defined(ENABLE_JIT)
1653 u1 *jit_asm_compile(methodinfo *m, u1 *mptr, u1 *sp, u1 *ra)
1660 /* create the stackframeinfo (subtract 1 from RA as it points to the */
1661 /* instruction after the call) */
1663 stacktrace_create_extern_stackframeinfo(&sfi, NULL, sp, ra, ra-1);
1665 /* actually compile the method */
1667 entrypoint = jit_compile(m);
1669 /* remove the stackframeinfo */
1671 stacktrace_remove_stackframeinfo(&sfi);
1673 /* there was a problem during compilation */
1675 if (entrypoint == NULL)
1678 /* get the method patch address */
1680 pa = md_get_method_patch_address(ra, &sfi, mptr);
1682 /* patch the method entry point */
1686 *p = (ptrint) entrypoint;
1688 /* flush the instruction cache */
1690 md_icacheflush(pa, SIZEOF_VOID_P);
1694 #endif /* defined(ENABLE_JIT) */
1697 /* jit_complement_condition ****************************************************
1699 Returns the complement of the passed conditional instruction.
1701 We use the order of the different conditions, e.g.:
1706 If the passed opcode is odd, we simply add 1 to get the complement.
1707 If the opcode is even, we subtract 1.
1714 *******************************************************************************/
1716 s4 jit_complement_condition(s4 opcode)
1720 return ICMD_IFNONNULL;
1722 case ICMD_IFNONNULL:
1726 /* check if opcode is odd */
1736 /* jit_renumber_basicblocks ****************************************************
1738 Set the ->nr of all blocks so it increases when traversing ->next.
1741 jitdata..........the current jitdata
1743 *******************************************************************************/
1745 void jit_renumber_basicblocks(jitdata *jd)
1751 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
1755 /* we have one block more than jd->basicblockcount (the end marker) */
1757 assert(nr == jd->basicblockcount + 1);
1761 /* jit_check_basicblock_numbers ************************************************
1763 Assert that the ->nr of the first block is zero and increases by 1 each
1764 time ->next is traversed.
1765 This function should be called before any analysis that relies on
1766 the basicblock numbers.
1769 jitdata..........the current jitdata
1771 NOTE: Aborts with an assertion if the condition is not met!
1773 *******************************************************************************/
1775 #if !defined(NDEBUG)
1776 void jit_check_basicblock_numbers(jitdata *jd)
1782 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
1783 assert(bptr->nr == nr);
1787 /* we have one block more than jd->basicblockcount (the end marker) */
1789 assert(nr == jd->basicblockcount + 1);
1791 #endif /* !defined(NDEBUG) */
1795 * These are local overrides for various environment variables in Emacs.
1796 * Please do not remove this and leave it at the end of the file, where
1797 * Emacs will automagically detect them.
1798 * ---------------------------------------------------------------------
1801 * indent-tabs-mode: t
1805 * vim:noexpandtab:sw=4:ts=4: