1 /* src/vm/jit/jit.c - calls the code generation functions
3 Copyright (C) 1996-2005, 2006 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 Contact: cacao@cacaojvm.org
27 Authors: Andreas Krall
30 Changes: Edwin Steiner
34 $Id: jit.c 5234 2006-08-14 17:50:12Z christian $
44 #include "mm/memory.h"
45 #include "native/native.h"
46 #include "toolbox/logging.h"
48 #if defined(ENABLE_THREADS)
49 # include "threads/native/lock.h"
51 # include "threads/none/lock.h"
55 #include "vm/global.h"
56 #include "vm/initialize.h"
57 #include "vm/loader.h"
58 #include "vm/method.h"
59 #include "vm/options.h"
60 #include "vm/statistics.h"
61 #include "vm/jit/asmpart.h"
63 # include "vm/jit/cfg.h"
65 #include "vm/jit/codegen-common.h"
66 #include "vm/jit/disass.h"
67 #include "vm/jit/dseg.h"
68 #include "vm/jit/jit.h"
69 #include "vm/jit/parse.h"
70 #include "vm/jit/reg.h"
72 # include "vm/jit/reorder.h"
74 #include "vm/jit/show.h"
75 #include "vm/jit/stack.h"
77 #include "vm/jit/allocator/simplereg.h"
78 #if defined(ENABLE_LSRA) && !defined(ENABLE_SSA)
79 # include "vm/jit/allocator/lsra.h"
81 #if defined(ENABLE_SSA)
82 # include "vm/jit/optimizing/lsra.h"
83 # include "vm/jit/optimizing/ssa.h"
87 #if defined(ENABLE_IFCONV)
88 # include "vm/jit/ifconv/ifconv.h"
91 #include "vm/jit/loop/analyze.h"
92 #include "vm/jit/loop/graph.h"
93 #include "vm/jit/loop/loop.h"
94 #include "vm/jit/verify/typecheck.h"
95 #include "vm/rt-timing.h"
97 #if defined(ENABLE_THREADS)
98 # include "threads/native/threads.h"
102 /* debug macros ***************************************************************/
105 #define DEBUG_JIT_COMPILEVERBOSE(x) \
107 if (compileverbose) { \
108 log_message_method(x, m); \
112 #define DEBUG_JIT_COMPILEVERBOSE(x) /* nothing */
116 /* global switches ************************************************************/
118 int stackreq[256] = {
120 1, /* JAVA_ACONST 1 */
121 1, /* JAVA_ICONST_M1 2 */
122 1, /* JAVA_ICONST_0 3 */
123 1, /* JAVA_ICONST_1 4 */
124 1, /* JAVA_ICONST_2 5 */
125 1, /* JAVA_ICONST_3 6 */
126 1, /* JAVA_ICONST_4 7 */
127 1, /* JAVA_ICONST_5 8 */
128 1, /* JAVA_LCONST_0 9 */
129 1, /* JAVA_LCONST_1 10 */
130 1, /* JAVA_FCONST_0 11 */
131 1, /* JAVA_FCONST_1 12 */
132 1, /* JAVA_FCONST_2 13 */
133 1, /* JAVA_DCONST_0 14 */
134 1, /* JAVA_DCONST_1 15 */
135 1, /* JAVA_BIPUSH 16 */
136 1, /* JAVA_SIPUSH 17 */
138 1, /* JAVA_LDC_W 19 */
139 1, /* JAVA_LDC2_W 20 */
140 1, /* JAVA_ILOAD 21 */
141 1, /* JAVA_LLOAD 22 */
142 1, /* JAVA_FLOAD 23 */
143 1, /* JAVA_DLOAD 24 */
144 1, /* JAVA_ALOAD 25 */
145 1, /* JAVA_ILOAD_0 26 */
146 1, /* JAVA_ILOAD_1 27 */
147 1, /* JAVA_ILOAD_2 28 */
148 1, /* JAVA_ILOAD_3 29 */
149 1, /* JAVA_LLOAD_0 30 */
150 1, /* JAVA_LLOAD_1 31 */
151 1, /* JAVA_LLOAD_2 32 */
152 1, /* JAVA_LLOAD_3 33 */
153 1, /* JAVA_FLOAD_0 34 */
154 1, /* JAVA_FLOAD_1 35 */
155 1, /* JAVA_FLOAD_2 36 */
156 1, /* JAVA_FLOAD_3 37 */
157 1, /* JAVA_DLOAD_0 38 */
158 1, /* JAVA_DLOAD_1 39 */
159 1, /* JAVA_DLOAD_2 40 */
160 1, /* JAVA_DLOAD_3 41 */
161 1, /* JAVA_ALOAD_0 42 */
162 1, /* JAVA_ALOAD_1 43 */
163 1, /* JAVA_ALOAD_2 44 */
164 1, /* JAVA_ALOAD_3 45 */
165 1, /* JAVA_IALOAD 46 */
166 1, /* JAVA_LALOAD 47 */
167 1, /* JAVA_FALOAD 48 */
168 1, /* JAVA_DALOAD 49 */
169 1, /* JAVA_AALOAD 50 */
170 1, /* JAVA_BALOAD 51 */
171 1, /* JAVA_CALOAD 52 */
172 1, /* JAVA_SALOAD 53 */
173 0, /* JAVA_ISTORE 54 */
174 0, /* JAVA_LSTORE 55 */
175 0, /* JAVA_FSTORE 56 */
176 0, /* JAVA_DSTORE 57 */
177 0, /* JAVA_ASTORE 58 */
178 0, /* JAVA_ISTORE_0 59 */
179 0, /* JAVA_ISTORE_1 60 */
180 0, /* JAVA_ISTORE_2 61 */
181 0, /* JAVA_ISTORE_3 62 */
182 0, /* JAVA_LSTORE_0 63 */
183 0, /* JAVA_LSTORE_1 64 */
184 0, /* JAVA_LSTORE_2 65 */
185 0, /* JAVA_LSTORE_3 66 */
186 0, /* JAVA_FSTORE_0 67 */
187 0, /* JAVA_FSTORE_1 68 */
188 0, /* JAVA_FSTORE_2 69 */
189 0, /* JAVA_FSTORE_3 70 */
190 0, /* JAVA_DSTORE_0 71 */
191 0, /* JAVA_DSTORE_1 72 */
192 0, /* JAVA_DSTORE_2 73 */
193 0, /* JAVA_DSTORE_3 74 */
194 0, /* JAVA_ASTORE_0 75 */
195 0, /* JAVA_ASTORE_1 76 */
196 0, /* JAVA_ASTORE_2 77 */
197 0, /* JAVA_ASTORE_3 78 */
198 0, /* JAVA_IASTORE 79 */
199 0, /* JAVA_LASTORE 80 */
200 0, /* JAVA_FASTORE 81 */
201 0, /* JAVA_DASTORE 82 */
202 0, /* JAVA_AASTORE 83 */
203 0, /* JAVA_BASTORE 84 */
204 0, /* JAVA_CASTORE 85 */
205 0, /* JAVA_SASTORE 86 */
207 0, /* JAVA_POP2 88 */
209 3, /* JAVA_DUP_X1 90 */
210 4, /* JAVA_DUP_X2 91 */
211 2, /* JAVA_DUP2 92 */
212 3, /* JAVA_DUP2_X1 93 */
213 4, /* JAVA_DUP2_X2 94 */
214 2, /* JAVA_SWAP 95 */
215 1, /* JAVA_IADD 96 */
216 1, /* JAVA_LADD 97 */
217 1, /* JAVA_FADD 98 */
218 1, /* JAVA_DADD 99 */
219 1, /* JAVA_ISUB 100 */
220 1, /* JAVA_LSUB 101 */
221 1, /* JAVA_FSUB 102 */
222 1, /* JAVA_DSUB 103 */
223 1, /* JAVA_IMUL 104 */
224 1, /* JAVA_LMUL 105 */
225 1, /* JAVA_FMUL 106 */
226 1, /* JAVA_DMUL 107 */
227 1, /* JAVA_IDIV 108 */
228 1, /* JAVA_LDIV 109 */
229 1, /* JAVA_FDIV 110 */
230 1, /* JAVA_DDIV 111 */
231 1, /* JAVA_IREM 112 */
232 1, /* JAVA_LREM 113 */
233 1, /* JAVA_FREM 114 */
234 1, /* JAVA_DREM 115 */
235 1, /* JAVA_INEG 116 */
236 1, /* JAVA_LNEG 117 */
237 1, /* JAVA_FNEG 118 */
238 1, /* JAVA_DNEG 119 */
239 1, /* JAVA_ISHL 120 */
240 1, /* JAVA_LSHL 121 */
241 1, /* JAVA_ISHR 122 */
242 1, /* JAVA_LSHR 123 */
243 1, /* JAVA_IUSHR 124 */
244 1, /* JAVA_LUSHR 125 */
245 1, /* JAVA_IAND 126 */
246 1, /* JAVA_LAND 127 */
247 1, /* JAVA_IOR 128 */
248 1, /* JAVA_LOR 129 */
249 1, /* JAVA_IXOR 130 */
250 1, /* JAVA_LXOR 131 */
251 0, /* JAVA_IINC 132 */
252 1, /* JAVA_I2L 133 */
253 1, /* JAVA_I2F 134 */
254 1, /* JAVA_I2D 135 */
255 1, /* JAVA_L2I 136 */
256 1, /* JAVA_L2F 137 */
257 1, /* JAVA_L2D 138 */
258 1, /* JAVA_F2I 139 */
259 1, /* JAVA_F2L 140 */
260 1, /* JAVA_F2D 141 */
261 1, /* JAVA_D2I 142 */
262 1, /* JAVA_D2L 143 */
263 1, /* JAVA_D2F 144 */
264 1, /* JAVA_INT2BYTE 145 */
265 1, /* JAVA_INT2CHAR 146 */
266 1, /* JAVA_INT2SHORT 147 */
267 1, /* JAVA_LCMP 148 */
268 1, /* JAVA_FCMPL 149 */
269 1, /* JAVA_FCMPG 150 */
270 1, /* JAVA_DCMPL 151 */
271 1, /* JAVA_DCMPG 152 */
272 0, /* JAVA_IFEQ 153 */
273 0, /* JAVA_IFNE 154 */
274 0, /* JAVA_IFLT 155 */
275 0, /* JAVA_IFGE 156 */
276 0, /* JAVA_IFGT 157 */
277 0, /* JAVA_IFLE 158 */
278 0, /* JAVA_IF_ICMPEQ 159 */
279 0, /* JAVA_IF_ICMPNE 160 */
280 0, /* JAVA_IF_ICMPLT 161 */
281 0, /* JAVA_IF_ICMPGE 162 */
282 0, /* JAVA_IF_ICMPGT 163 */
283 0, /* JAVA_IF_ICMPLE 164 */
284 0, /* JAVA_IF_ACMPEQ 165 */
285 0, /* JAVA_IF_ACMPNE 166 */
286 0, /* JAVA_GOTO 167 */
287 1, /* JAVA_JSR 168 */
288 0, /* JAVA_RET 169 */
289 0, /* JAVA_TABLESWITCH 170 */
290 0, /* JAVA_LOOKUPSWITCH 171 */
291 0, /* JAVA_IRETURN 172 */
292 0, /* JAVA_LRETURN 173 */
293 0, /* JAVA_FRETURN 174 */
294 0, /* JAVA_DRETURN 175 */
295 0, /* JAVA_ARETURN 176 */
296 0, /* JAVA_RETURN 177 */
297 1, /* JAVA_GETSTATIC 178 */
298 0, /* JAVA_PUTSTATIC 179 */
299 1, /* JAVA_GETFIELD 180 */
300 0, /* JAVA_PUTFIELD 181 */
301 1, /* JAVA_INVOKEVIRTUAL 182 */
302 1, /* JAVA_INVOKESPECIAL 183 */
303 1, /* JAVA_INVOKESTATIC 184 */
304 1, /* JAVA_INVOKEINTERFACE 185 */
305 1, /* JAVA_UNDEF186 186 */
306 1, /* JAVA_NEW 187 */
307 1, /* JAVA_NEWARRAY 188 */
308 1, /* JAVA_ANEWARRAY 189 */
309 1, /* JAVA_ARRAYLENGTH 190 */
310 1, /* JAVA_ATHROW 191 */
311 1, /* JAVA_CHECKCAST 192 */
312 1, /* JAVA_INSTANCEOF 193 */
313 0, /* JAVA_MONITORENTER 194 */
314 0, /* JAVA_MONITOREXIT 195 */
315 0, /* JAVA_WIDE 196 */
316 1, /* JAVA_MULTIANEWARRAY 197 */
317 0, /* JAVA_IFNULL 198 */
318 0, /* JAVA_IFNONNULL 199 */
319 0, /* JAVA_GOTO_W 200 */
320 1, /* JAVA_JSR_W 201 */
321 0, /* JAVA_BREAKPOINT 202 */
322 1, /* JAVA_UNDEF203 203 */
323 1, /* JAVA_UNDEF204 204 */
324 1, /* JAVA_UNDEF205 205 */
325 1, /* JAVA_UNDEF206 206 */
326 1, /* JAVA_UNDEF207 207 */
327 1, /* JAVA_UNDEF208 208 */
328 1, /* JAVA_UNDEF209 209 */
329 1, /* JAVA_UNDEF210 210 */
330 1, /* JAVA_UNDEF211 211 */
331 1, /* JAVA_UNDEF212 212 */
332 1, /* JAVA_UNDEF213 213 */
333 1, /* JAVA_UNDEF214 214 */
334 1, /* JAVA_UNDEF215 215 */
335 1, /* JAVA_UNDEF216 216 */
336 1, /* JAVA_UNDEF217 217 */
337 1, /* JAVA_UNDEF218 218 */
338 1, /* JAVA_UNDEF219 219 */
339 1, /* JAVA_UNDEF220 220 */
340 1, /* JAVA_UNDEF221 221 */
341 1, /* JAVA_UNDEF222 222 */
342 1, /* JAVA_UNDEF223 223 */
343 1, /* JAVA_UNDEF224 224 */
344 1, /* JAVA_UNDEF225 225 */
345 1, /* JAVA_UNDEF226 226 */
346 1, /* JAVA_UNDEF227 227 */
347 1, /* JAVA_UNDEF228 228 */
348 1, /* JAVA_UNDEF229 229 */
349 1, /* JAVA_UNDEF230 230 */
350 1, /* JAVA_UNDEF231 231 */
351 1, /* JAVA_UNDEF232 232 */
352 1, /* JAVA_UNDEF233 233 */
353 1, /* JAVA_UNDEF234 234 */
354 1, /* JAVA_UNDEF235 235 */
355 1, /* JAVA_UNDEF236 236 */
356 1, /* JAVA_UNDEF237 237 */
357 1, /* JAVA_UNDEF238 238 */
358 1, /* JAVA_UNDEF239 239 */
359 1, /* JAVA_UNDEF240 240 */
360 1, /* JAVA_UNDEF241 241 */
361 1, /* JAVA_UNDEF242 242 */
362 1, /* JAVA_UNDEF243 243 */
363 1, /* JAVA_UNDEF244 244 */
364 1, /* JAVA_UNDEF245 245 */
365 1, /* JAVA_UNDEF246 246 */
366 1, /* JAVA_UNDEF247 247 */
367 1, /* JAVA_UNDEF248 248 */
368 1, /* JAVA_UNDEF249 249 */
369 1, /* JAVA_UNDEF250 250 */
370 1, /* JAVA_UNDEF251 251 */
371 1, /* JAVA_UNDEF252 252 */
372 1, /* JAVA_UNDEF253 253 */
373 1, /* JAVA_UNDEF254 254 */
374 1, /* JAVA_UNDEF255 255 */
378 int jcommandsize[256] = {
381 1, /* JAVA_ACONST_NULL 1 */
382 1, /* JAVA_ICONST_M1 2 */
383 1, /* JAVA_ICONST_0 3 */
384 1, /* JAVA_ICONST_1 4 */
385 1, /* JAVA_ICONST_2 5 */
386 1, /* JAVA_ICONST_3 6 */
387 1, /* JAVA_ICONST_4 7 */
388 1, /* JAVA_ICONST_5 8 */
389 1, /* JAVA_LCONST_0 9 */
390 1, /* JAVA_LCONST_1 10 */
391 1, /* JAVA_FCONST_0 11 */
392 1, /* JAVA_FCONST_1 12 */
393 1, /* JAVA_FCONST_2 13 */
394 1, /* JAVA_DCONST_0 14 */
395 1, /* JAVA_DCONST_1 15 */
396 2, /* JAVA_BIPUSH 16 */
397 3, /* JAVA_SIPUSH 17 */
398 2, /* JAVA_LDC1 18 */
399 3, /* JAVA_LDC2 19 */
400 3, /* JAVA_LDC2W 20 */
401 2, /* JAVA_ILOAD 21 */
402 2, /* JAVA_LLOAD 22 */
403 2, /* JAVA_FLOAD 23 */
404 2, /* JAVA_DLOAD 24 */
405 2, /* JAVA_ALOAD 25 */
406 1, /* JAVA_ILOAD_0 26 */
407 1, /* JAVA_ILOAD_1 27 */
408 1, /* JAVA_ILOAD_2 28 */
409 1, /* JAVA_ILOAD_3 29 */
410 1, /* JAVA_LLOAD_0 30 */
411 1, /* JAVA_LLOAD_1 31 */
412 1, /* JAVA_LLOAD_2 32 */
413 1, /* JAVA_LLOAD_3 33 */
414 1, /* JAVA_FLOAD_0 34 */
415 1, /* JAVA_FLOAD_1 35 */
416 1, /* JAVA_FLOAD_2 36 */
417 1, /* JAVA_FLOAD_3 37 */
418 1, /* JAVA_DLOAD_0 38 */
419 1, /* JAVA_DLOAD_1 39 */
420 1, /* JAVA_DLOAD_2 40 */
421 1, /* JAVA_DLOAD_3 41 */
422 1, /* JAVA_ALOAD_0 42 */
423 1, /* JAVA_ALOAD_1 43 */
424 1, /* JAVA_ALOAD_2 44 */
425 1, /* JAVA_ALOAD_3 45 */
426 1, /* JAVA_IALOAD 46 */
427 1, /* JAVA_LALOAD 47 */
428 1, /* JAVA_FALOAD 48 */
429 1, /* JAVA_DALOAD 49 */
430 1, /* JAVA_AALOAD 50 */
431 1, /* JAVA_BALOAD 51 */
432 1, /* JAVA_CALOAD 52 */
433 1, /* JAVA_SALOAD 53 */
434 2, /* JAVA_ISTORE 54 */
435 2, /* JAVA_LSTORE 55 */
436 2, /* JAVA_FSTORE 56 */
437 2, /* JAVA_DSTORE 57 */
438 2, /* JAVA_ASTORE 58 */
439 1, /* JAVA_ISTORE_0 59 */
440 1, /* JAVA_ISTORE_1 60 */
441 1, /* JAVA_ISTORE_2 61 */
442 1, /* JAVA_ISTORE_3 62 */
443 1, /* JAVA_LSTORE_0 63 */
444 1, /* JAVA_LSTORE_1 64 */
445 1, /* JAVA_LSTORE_2 65 */
446 1, /* JAVA_LSTORE_3 66 */
447 1, /* JAVA_FSTORE_0 67 */
448 1, /* JAVA_FSTORE_1 68 */
449 1, /* JAVA_FSTORE_2 69 */
450 1, /* JAVA_FSTORE_3 70 */
451 1, /* JAVA_DSTORE_0 71 */
452 1, /* JAVA_DSTORE_1 72 */
453 1, /* JAVA_DSTORE_2 73 */
454 1, /* JAVA_DSTORE_3 74 */
455 1, /* JAVA_ASTORE_0 75 */
456 1, /* JAVA_ASTORE_1 76 */
457 1, /* JAVA_ASTORE_2 77 */
458 1, /* JAVA_ASTORE_3 78 */
459 1, /* JAVA_IASTORE 79 */
460 1, /* JAVA_LASTORE 80 */
461 1, /* JAVA_FASTORE 81 */
462 1, /* JAVA_DASTORE 82 */
463 1, /* JAVA_AASTORE 83 */
464 1, /* JAVA_BASTORE 84 */
465 1, /* JAVA_CASTORE 85 */
466 1, /* JAVA_SASTORE 86 */
468 1, /* JAVA_POP2 88 */
470 1, /* JAVA_DUP_X1 90 */
471 1, /* JAVA_DUP_X2 91 */
472 1, /* JAVA_DUP2 92 */
473 1, /* JAVA_DUP2_X1 93 */
474 1, /* JAVA_DUP2_X2 94 */
475 1, /* JAVA_SWAP 95 */
476 1, /* JAVA_IADD 96 */
477 1, /* JAVA_LADD 97 */
478 1, /* JAVA_FADD 98 */
479 1, /* JAVA_DADD 99 */
480 1, /* JAVA_ISUB 100 */
481 1, /* JAVA_LSUB 101 */
482 1, /* JAVA_FSUB 102 */
483 1, /* JAVA_DSUB 103 */
484 1, /* JAVA_IMUL 104 */
485 1, /* JAVA_LMUL 105 */
486 1, /* JAVA_FMUL 106 */
487 1, /* JAVA_DMUL 107 */
488 1, /* JAVA_IDIV 108 */
489 1, /* JAVA_LDIV 109 */
490 1, /* JAVA_FDIV 110 */
491 1, /* JAVA_DDIV 111 */
492 1, /* JAVA_IREM 112 */
493 1, /* JAVA_LREM 113 */
494 1, /* JAVA_FREM 114 */
495 1, /* JAVA_DREM 115 */
496 1, /* JAVA_INEG 116 */
497 1, /* JAVA_LNEG 117 */
498 1, /* JAVA_FNEG 118 */
499 1, /* JAVA_DNEG 119 */
500 1, /* JAVA_ISHL 120 */
501 1, /* JAVA_LSHL 121 */
502 1, /* JAVA_ISHR 122 */
503 1, /* JAVA_LSHR 123 */
504 1, /* JAVA_IUSHR 124 */
505 1, /* JAVA_LUSHR 125 */
506 1, /* JAVA_IAND 126 */
507 1, /* JAVA_LAND 127 */
508 1, /* JAVA_IOR 128 */
509 1, /* JAVA_LOR 129 */
510 1, /* JAVA_IXOR 130 */
511 1, /* JAVA_LXOR 131 */
512 3, /* JAVA_IINC 132 */
513 1, /* JAVA_I2L 133 */
514 1, /* JAVA_I2F 134 */
515 1, /* JAVA_I2D 135 */
516 1, /* JAVA_L2I 136 */
517 1, /* JAVA_L2F 137 */
518 1, /* JAVA_L2D 138 */
519 1, /* JAVA_F2I 139 */
520 1, /* JAVA_F2L 140 */
521 1, /* JAVA_F2D 141 */
522 1, /* JAVA_D2I 142 */
523 1, /* JAVA_D2L 143 */
524 1, /* JAVA_D2F 144 */
525 1, /* JAVA_INT2BYTE 145 */
526 1, /* JAVA_INT2CHAR 146 */
527 1, /* JAVA_INT2SHORT 147 */
528 1, /* JAVA_LCMP 148 */
529 1, /* JAVA_FCMPL 149 */
530 1, /* JAVA_FCMPG 150 */
531 1, /* JAVA_DCMPL 151 */
532 1, /* JAVA_DCMPG 152 */
533 3, /* JAVA_IFEQ 153 */
534 3, /* JAVA_IFNE 154 */
535 3, /* JAVA_IFLT 155 */
536 3, /* JAVA_IFGE 156 */
537 3, /* JAVA_IFGT 157 */
538 3, /* JAVA_IFLE 158 */
539 3, /* JAVA_IF_ICMPEQ 159 */
540 3, /* JAVA_IF_ICMPNE 160 */
541 3, /* JAVA_IF_ICMPLT 161 */
542 3, /* JAVA_IF_ICMPGE 162 */
543 3, /* JAVA_IF_ICMPGT 163 */
544 3, /* JAVA_IF_ICMPLE 164 */
545 3, /* JAVA_IF_ACMPEQ 165 */
546 3, /* JAVA_IF_ACMPNE 166 */
547 3, /* JAVA_GOTO 167 */
548 3, /* JAVA_JSR 168 */
549 2, /* JAVA_RET 169 */
550 0, /* JAVA_TABLESWITCH 170 */ /* variable length */
551 0, /* JAVA_LOOKUPSWITCH 171 */ /* variable length */
552 1, /* JAVA_IRETURN 172 */
553 1, /* JAVA_LRETURN 173 */
554 1, /* JAVA_FRETURN 174 */
555 1, /* JAVA_DRETURN 175 */
556 1, /* JAVA_ARETURN 176 */
557 1, /* JAVA_RETURN 177 */
558 3, /* JAVA_GETSTATIC 178 */
559 3, /* JAVA_PUTSTATIC 179 */
560 3, /* JAVA_GETFIELD 180 */
561 3, /* JAVA_PUTFIELD 181 */
562 3, /* JAVA_INVOKEVIRTUAL 182 */
563 3, /* JAVA_INVOKESPECIAL 183 */
564 3, /* JAVA_INVOKESTATIC 184 */
565 5, /* JAVA_INVOKEINTERFACE 185 */
567 3, /* JAVA_NEW 187 */
568 2, /* JAVA_NEWARRAY 188 */
569 3, /* JAVA_ANEWARRAY 189 */
570 1, /* JAVA_ARRAYLENGTH 190 */
571 1, /* JAVA_ATHROW 191 */
572 3, /* JAVA_CHECKCAST 192 */
573 3, /* JAVA_INSTANCEOF 193 */
574 1, /* JAVA_MONITORENTER 194 */
575 1, /* JAVA_MONITOREXIT 195 */
576 0, /* JAVA_WIDE 196 */ /* variable length */
577 4, /* JAVA_MULTIANEWARRAY 197 */
578 3, /* JAVA_IFNULL 198 */
579 3, /* JAVA_IFNONNULL 199 */
580 5, /* JAVA_GOTO_W 200 */
581 5, /* JAVA_JSR_W 201 */
582 1, /* JAVA_BREAKPOINT 202 */
619 1,1,1,1,1,1,1,1,1,1,
624 char *icmd_names[256] = {
627 "CHECKNULL ", /* ICONST_M1 2 */
629 "CHECKNULL_POP ", /* ICONST_1 4 */
630 "IDIVPOW2 ", /* ICONST_2 5 */
631 "LDIVPOW2 ", /* ICONST_3 6 */
632 "UNDEF7 ", /* ICONST_4 7 */
633 "UNDEF8 ", /* ICONST_5 8 */
635 "LCMPCONST ", /* LCONST_1 10 */
637 "UNDEF12 ", /* FCONST_1 12 */
638 "UNDEF13 ", /* FCONST_2 13 */
640 "UNDEF15 ", /* DCONST_1 15 */
641 "UNDEF16 ", /* BIPUSH 16 */
642 "UNDEF17 ", /* SIPUSH 17 */
643 "UNDEF18 ", /* LDC1 18 */
644 "UNDEF19 ", /* LDC2 19 */
645 "UNDEF20 ", /* LDC2W 20 */
651 "IADDCONST ", /* ILOAD_0 26 */
652 "ISUBCONST ", /* ILOAD_1 27 */
653 "IMULCONST ", /* ILOAD_2 28 */
654 "IANDCONST ", /* ILOAD_3 29 */
655 "IORCONST ", /* LLOAD_0 30 */
656 "IXORCONST ", /* LLOAD_1 31 */
657 "ISHLCONST ", /* LLOAD_2 32 */
658 "ISHRCONST ", /* LLOAD_3 33 */
659 "IUSHRCONST ", /* FLOAD_0 34 */
660 "IREMPOW2 ", /* FLOAD_1 35 */
661 "LADDCONST ", /* FLOAD_2 36 */
662 "LSUBCONST ", /* FLOAD_3 37 */
663 "LMULCONST ", /* DLOAD_0 38 */
664 "LANDCONST ", /* DLOAD_1 39 */
665 "LORCONST ", /* DLOAD_2 40 */
666 "LXORCONST ", /* DLOAD_3 41 */
667 "LSHLCONST ", /* ALOAD_0 42 */
668 "LSHRCONST ", /* ALOAD_1 43 */
669 "LUSHRCONST ", /* ALOAD_2 44 */
670 "LREMPOW2 ", /* ALOAD_3 45 */
684 "IF_LEQ ", /* ISTORE_0 59 */
685 "IF_LNE ", /* ISTORE_1 60 */
686 "IF_LLT ", /* ISTORE_2 61 */
687 "IF_LGE ", /* ISTORE_3 62 */
688 "IF_LGT ", /* LSTORE_0 63 */
689 "IF_LLE ", /* LSTORE_1 64 */
690 "IF_LCMPEQ ", /* LSTORE_2 65 */
691 "IF_LCMPNE ", /* LSTORE_3 66 */
692 "IF_LCMPLT ", /* FSTORE_0 67 */
693 "IF_LCMPGE ", /* FSTORE_1 68 */
694 "IF_LCMPGT ", /* FSTORE_2 69 */
695 "IF_LCMPLE ", /* FSTORE_3 70 */
696 "UNDEF71 ", /* DSTORE_0 71 */
697 "UNDEF72 ", /* DSTORE_1 72 */
698 "UNDEF73 ", /* DSTORE_2 73 */
699 "UNDEF74 ", /* DSTORE_3 74 */
700 "UNDEF75 ", /* ASTORE_0 75 */
701 "UNDEF76 ", /* ASTORE_1 76 */
702 "UNDEF77 ", /* ASTORE_2 77 */
703 "UNDEF78 ", /* ASTORE_3 78 */
770 "INT2BYTE ", /* 145 */
771 "INT2CHAR ", /* 146 */
772 "INT2SHORT ", /* 147 */
784 "IF_ICMPEQ ", /* 159 */
785 "IF_ICMPNE ", /* 160 */
786 "IF_ICMPLT ", /* 161 */
787 "IF_ICMPGE ", /* 162 */
788 "IF_ICMPGT ", /* 163 */
789 "IF_ICMPLE ", /* 164 */
790 "IF_ACMPEQ ", /* 165 */
791 "IF_ACMPNE ", /* 166 */
795 "TABLESWITCH ", /* 170 */
796 "LOOKUPSWITCH ", /* 171 */
797 "IRETURN ", /* 172 */
798 "LRETURN ", /* 173 */
799 "FRETURN ", /* 174 */
800 "DRETURN ", /* 175 */
801 "ARETURN ", /* 176 */
803 "GETSTATIC ", /* 178 */
804 "PUTSTATIC ", /* 179 */
805 "GETFIELD ", /* 180 */
806 "PUTFIELD ", /* 181 */
807 "INVOKEVIRTUAL ", /* 182 */
808 "INVOKESPECIAL ", /* 183 */
809 "INVOKESTATIC ", /* 184 */
810 "INVOKEINTERFACE", /* 185 */
811 "UNDEF186 ", /* UNDEF186 186 */
813 "NEWARRAY ", /* 188 */
814 "ANEWARRAY ", /* 189 */
815 "ARRAYLENGTH ", /* 190 */
817 "CHECKCAST ", /* 192 */
818 "INSTANCEOF ", /* 193 */
819 "MONITORENTER ", /* 194 */
820 "MONITOREXIT ", /* 195 */
821 "UNDEF196 ", /* WIDE 196 */
822 "MULTIANEWARRAY ", /* 197 */
824 "IFNONNULL ", /* 199 */
825 "UNDEF200 ", /* GOTO_W 200 */
826 "UNDEF201 ", /* JSR_W 201 */
827 "UNDEF202 ", /* BREAKPOINT 202 */
828 "UNDEF203 ", /* UNDEF203 203 */
829 "IASTORECONST ", /* 204 */
830 "LASTORECONST ", /* 205 */
831 "FASTORECONST ", /* 206 */
832 "DASTORECONST ", /* 207 */
833 "AASTORECONST ", /* 208 */
834 "BASTORECONST ", /* 209 */
835 "CASTORECONST ", /* 210 */
836 "SASTORECONST ", /* 211 */
837 "PUTSTATICCONST ", /* 212 */
838 "PUTFIELDCONST ", /* 213 */
839 "IMULPOW2 ", /* 214 */
840 "LMULPOW2 ", /* 215 */
842 "IF_FCMPEQ ", /* 216 */
843 "IF_FCMPNE ", /* 217 */
845 "IF_FCMPL_LT ", /* 218 */
846 "IF_FCMPL_GE ", /* 219 */
847 "IF_FCMPL_GT ", /* 220 */
848 "IF_FCMPL_LE ", /* 221 */
850 "IF_FCMPG_LT ", /* 222 */
851 "IF_FCMPG_GE ", /* 223 */
852 "IF_FCMPG_GT ", /* 224 */
853 "IF_FCMPG_LE ", /* 225 */
855 "IF_DCMPEQ ", /* 226 */
856 "IF_DCMPNE ", /* 227 */
858 "IF_DCMPL_LT ", /* 228 */
859 "IF_DCMPL_GE ", /* 229 */
860 "IF_DCMPL_GT ", /* 230 */
861 "IF_DCMPL_LE ", /* 231 */
863 "IF_DCMPG_LT ", /* 232 */
864 "IF_DCMPG_GE ", /* 233 */
865 "IF_DCMPG_GT ", /* 234 */
866 "IF_DCMPG_LE ", /* 235 */
868 "UNDEF236", "UNDEF237", "UNDEF238", "UNDEF239", "UNDEF240",
869 "UNDEF241", "UNDEF242", "UNDEF243", "UNDEF244", "UNDEF245",
870 "UNDEF246", "UNDEF247", "UNDEF248", "UNDEF249", "UNDEF250",
872 "INLINE_START ", /* 251 */
873 "INLINE_END ", /* 252 */
874 "INLINE_GOTO ", /* 253 */
882 char *opcode_names[256] = {
885 "ICONST_M1 ", /* ICONST_M1 2 */
886 "ICONST_0 ", /* ICONST_0 3 */
887 "ICONST_1 ", /* ICONST_1 4 */
888 "ICONST_2 ", /* ICONST_2 5 */
889 "ICONST_3 ", /* ICONST_3 6 */
890 "ICONST_4 ", /* ICONST_4 7 */
891 "ICONST_5 ", /* ICONST_5 8 */
892 "LCONST_0 ", /* LCONST_0 9 */
893 "LCONST_1 ", /* LCONST_1 10 */
894 "FCONST_0 ", /* FCONST_0 11 */
895 "FCONST_1 ", /* FCONST_1 12 */
896 "FCONST_2 ", /* FCONST_2 13 */
897 "DCONST_0 ", /* DCONST_0 14 */
898 "DCONST_1 ", /* DCONST_1 15 */
899 "BIPUSH ", /* BIPUSH 16 */
900 "SIPUSH ", /* SIPUSH 17 */
902 "LDC_W ", /* LDC_W 19 */
903 "LDC2_W ", /* LDC2_W 20 */
909 "ILOAD_0 ", /* ILOAD_0 26 */
910 "ILOAD_1 ", /* ILOAD_1 27 */
911 "ILOAD_2 ", /* ILOAD_2 28 */
912 "ILOAD_3 ", /* ILOAD_3 29 */
913 "LLOAD_0 ", /* LLOAD_0 30 */
914 "LLOAD_1 ", /* LLOAD_1 31 */
915 "LLOAD_2 ", /* LLOAD_2 32 */
916 "LLOAD_3 ", /* LLOAD_3 33 */
917 "FLOAD_0 ", /* FLOAD_0 34 */
918 "FLOAD_1 ", /* FLOAD_1 35 */
919 "FLOAD_2 ", /* FLOAD_2 36 */
920 "FLOAD_3 ", /* FLOAD_3 37 */
921 "DLOAD_0 ", /* DLOAD_0 38 */
922 "DLOAD_1 ", /* DLOAD_1 39 */
923 "DLOAD_2 ", /* DLOAD_2 40 */
924 "DLOAD_3 ", /* DLOAD_3 41 */
925 "ALOAD_0 ", /* ALOAD_0 42 */
926 "ALOAD_1 ", /* ALOAD_1 43 */
927 "ALOAD_2 ", /* ALOAD_2 44 */
928 "ALOAD_3 ", /* ALOAD_3 45 */
942 "ISTORE_0 ", /* ISTORE_0 59 */
943 "ISTORE_1 ", /* ISTORE_1 60 */
944 "ISTORE_2 ", /* ISTORE_2 61 */
945 "ISTORE_3 ", /* ISTORE_3 62 */
946 "LSTORE_0 ", /* LSTORE_0 63 */
947 "LSTORE_1 ", /* LSTORE_1 64 */
948 "LSTORE_2 ", /* LSTORE_2 65 */
949 "LSTORE_3 ", /* LSTORE_3 66 */
950 "FSTORE_0 ", /* FSTORE_0 67 */
951 "FSTORE_1 ", /* FSTORE_1 68 */
952 "FSTORE_2 ", /* FSTORE_2 69 */
953 "FSTORE_3 ", /* FSTORE_3 70 */
954 "DSTORE_0 ", /* DSTORE_0 71 */
955 "DSTORE_1 ", /* DSTORE_1 72 */
956 "DSTORE_2 ", /* DSTORE_2 73 */
957 "DSTORE_3 ", /* DSTORE_3 74 */
958 "ASTORE_0 ", /* ASTORE_0 75 */
959 "ASTORE_1 ", /* ASTORE_1 76 */
960 "ASTORE_2 ", /* ASTORE_2 77 */
961 "ASTORE_3 ", /* ASTORE_3 78 */
1028 "INT2BYTE ", /* 145 */
1029 "INT2CHAR ", /* 146 */
1030 "INT2SHORT ", /* 147 */
1042 "IF_ICMPEQ ", /* 159 */
1043 "IF_ICMPNE ", /* 160 */
1044 "IF_ICMPLT ", /* 161 */
1045 "IF_ICMPGE ", /* 162 */
1046 "IF_ICMPGT ", /* 163 */
1047 "IF_ICMPLE ", /* 164 */
1048 "IF_ACMPEQ ", /* 165 */
1049 "IF_ACMPNE ", /* 166 */
1053 "TABLESWITCH ", /* 170 */
1054 "LOOKUPSWITCH ", /* 171 */
1055 "IRETURN ", /* 172 */
1056 "LRETURN ", /* 173 */
1057 "FRETURN ", /* 174 */
1058 "DRETURN ", /* 175 */
1059 "ARETURN ", /* 176 */
1060 "RETURN ", /* 177 */
1061 "GETSTATIC ", /* 178 */
1062 "PUTSTATIC ", /* 179 */
1063 "GETFIELD ", /* 180 */
1064 "PUTFIELD ", /* 181 */
1065 "INVOKEVIRTUAL ", /* 182 */
1066 "INVOKESPECIAL ", /* 183 */
1067 "INVOKESTATIC ", /* 184 */
1068 "INVOKEINTERFACE", /* 185 */
1069 "UNDEF186 ", /* 186 */
1071 "NEWARRAY ", /* 188 */
1072 "ANEWARRAY ", /* 189 */
1073 "ARRAYLENGTH ", /* 190 */
1074 "ATHROW ", /* 191 */
1075 "CHECKCAST ", /* 192 */
1076 "INSTANCEOF ", /* 193 */
1077 "MONITORENTER ", /* 194 */
1078 "MONITOREXIT ", /* 195 */
1079 "WIDE ", /* WIDE 196 */
1080 "MULTIANEWARRAY ", /* 197 */
1081 "IFNULL ", /* 198 */
1082 "IFNONNULL ", /* 199 */
1083 "GOTO_W ", /* GOTO_W 200 */
1084 "JSR_W ", /* JSR_W 201 */
1085 "BREAKPOINT ", /* BREAKPOINT 202 */
1087 "UNDEF203", "UNDEF204", "UNDEF205",
1088 "UNDEF206", "UNDEF207", "UNDEF208", "UNDEF209", "UNDEF210",
1089 "UNDEF211", "UNDEF212", "UNDEF213", "UNDEF214", "UNDEF215",
1090 "UNDEF216", "UNDEF217", "UNDEF218", "UNDEF219", "UNDEF220",
1091 "UNDEF221", "UNDEF222", "UNDEF223", "UNDEF224", "UNDEF225",
1092 "UNDEF226", "UNDEF227", "UNDEF228", "UNDEF229", "UNDEF230",
1093 "UNDEF231", "UNDEF232", "UNDEF233", "UNDEF234", "UNDEF235",
1094 "UNDEF236", "UNDEF237", "UNDEF238", "UNDEF239", "UNDEF240",
1095 "UNDEF241", "UNDEF242", "UNDEF243", "UNDEF244", "UNDEF245",
1096 "UNDEF246", "UNDEF247", "UNDEF248", "UNDEF249", "UNDEF250",
1097 "UNDEF251", "UNDEF252", "UNDEF253", "UNDEF254", "UNDEF255"
1100 int op_needs_saved[256];
1102 /* jit_init ********************************************************************
1104 Initializes the JIT subsystem.
1106 *******************************************************************************/
1111 for( i = 0; i < 256; i++) {
1112 op_needs_saved[i] = 0;
1115 op_needs_saved[ICMD_AASTORE ] = 1;
1116 #if !SUPPORT_DIVISION
1117 op_needs_saved[ICMD_IDIV ] = 1;
1118 op_needs_saved[ICMD_IREM ] = 1;
1120 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1121 op_needs_saved[ICMD_LDIV ] = 1;
1122 op_needs_saved[ICMD_LREM ] = 1;
1124 op_needs_saved[ICMD_CHECKCAST] = 1;
1126 op_needs_saved[ICMD_BUILTIN ] = 1;
1127 op_needs_saved[ICMD_INVOKESTATIC ] = 1;
1128 op_needs_saved[ICMD_INVOKESPECIAL ] = 1;
1129 op_needs_saved[ICMD_INVOKEVIRTUAL ] = 1;
1130 op_needs_saved[ICMD_INVOKEINTERFACE] = 1;
1131 op_needs_saved[ICMD_MULTIANEWARRAY ] = 1;
1133 /* initialize stack analysis subsystem */
1135 (void) stack_init();
1137 /* initialize show subsystem */
1139 #if !defined(NDEBUG)
1143 /* initialize codegen subsystem */
1149 /* jit_close *******************************************************************
1151 Close the JIT subsystem.
1153 *******************************************************************************/
1155 void jit_close(void)
1161 /* dummy function, used when there is no JavaVM code available */
1163 static u1 *do_nothing_function(void)
1169 /* jit_jitdata_new *************************************************************
1171 Allocates and initalizes a new jitdata structure.
1173 *******************************************************************************/
1175 static jitdata *jit_jitdata_new(methodinfo *m)
1179 /* allocate jitdata structure and fill it */
1184 jd->cd = DNEW(codegendata);
1185 jd->rd = DNEW(registerdata);
1186 #if defined(ENABLE_LOOP)
1187 jd->ld = DNEW(loopdata);
1190 /* Allocate codeinfo memory from the heap as we need to keep them. */
1192 jd->code = code_codeinfo_new(m);
1194 /* initialize variables */
1197 jd->isleafmethod = true;
1203 /* jit_compile *****************************************************************
1205 Translates one method to machine code.
1207 *******************************************************************************/
1209 static u1 *jit_compile_intern(jitdata *jd);
1211 u1 *jit_compile(methodinfo *m)
1217 STATISTICS(count_jit_calls++);
1219 /* Initialize the static function's class. */
1221 /* ATTENTION: This MUST be done before the method lock is aquired,
1222 otherwise we could run into a deadlock with <clinit>'s that
1223 call static methods of it's own class. */
1225 if ((m->flags & ACC_STATIC) && !(m->class->state & CLASS_INITIALIZED)) {
1226 #if !defined(NDEBUG)
1228 log_message_class("Initialize class ", m->class);
1231 if (!initialize_class(m->class))
1234 /* check if the method has been compiled during initialization */
1236 if ((m->code != NULL) && (m->code->entrypoint != NULL))
1237 return m->code->entrypoint;
1240 /* enter a monitor on the method */
1242 LOCK_MONITOR_ENTER(m);
1244 /* if method has been already compiled return immediately */
1246 if (m->code != NULL) {
1247 LOCK_MONITOR_EXIT(m);
1249 assert(m->code->entrypoint);
1250 return m->code->entrypoint;
1253 STATISTICS(count_methods++);
1255 #if defined(ENABLE_STATISTICS)
1258 if (opt_getcompilingtime)
1259 compilingtime_start();
1262 /* mark start of dump memory area */
1264 dumpsize = dump_size();
1266 /* create jitdata structure */
1268 jd = jit_jitdata_new(m);
1270 /* set the flags for the current JIT run */
1272 jd->flags = JITDATA_FLAG_PARSE;
1275 jd->flags |= JITDATA_FLAG_VERIFY;
1278 jd->flags |= JITDATA_FLAG_INSTRUMENT;
1281 jd->flags |= JITDATA_FLAG_IFCONV;
1283 if (opt_showintermediate)
1284 jd->flags |= JITDATA_FLAG_SHOWINTERMEDIATE;
1286 if (opt_showdisassemble)
1287 jd->flags |= JITDATA_FLAG_SHOWDISASSEMBLE;
1289 if (opt_verbosecall)
1290 jd->flags |= JITDATA_FLAG_VERBOSECALL;
1292 #if defined(ENABLE_JIT)
1293 # if defined(ENABLE_INTRP)
1296 /* initialize the register allocator */
1301 /* setup the codegendata memory */
1305 /* now call internal compile function */
1307 r = jit_compile_intern(jd);
1309 /* clear pointers to dump memory area */
1311 m->basicblocks = NULL;
1312 m->basicblockindex = NULL;
1313 m->instructions = NULL;
1317 /* We had an exception! Finish stuff here if necessary. */
1319 /* release codeinfo */
1321 code_codeinfo_free(jd->code);
1323 /* Release memory for basic block profiling information. */
1325 if (JITDATA_HAS_FLAG_INSTRUMENT(jd))
1326 if (jd->code->bbfrequency != NULL)
1327 MFREE(jd->code->bbfrequency, u4, jd->code->basicblockcount);
1330 DEBUG_JIT_COMPILEVERBOSE("Running: ");
1333 /* release dump area */
1335 dump_release(dumpsize);
1337 #if defined(ENABLE_STATISTICS)
1340 if (opt_getcompilingtime)
1341 compilingtime_stop();
1344 /* leave the monitor */
1346 LOCK_MONITOR_EXIT(m);
1348 /* return pointer to the methods entry point */
1354 /* jit_recompile ***************************************************************
1356 Recompiles a Java method.
1358 *******************************************************************************/
1360 u1 *jit_recompile(methodinfo *m)
1367 /* check for max. optimization level */
1369 optlevel = m->code->optlevel;
1371 if (optlevel == 1) {
1372 /* log_message_method("not recompiling: ", m); */
1376 log_message_method("Recompiling start: ", m);
1378 STATISTICS(count_jit_calls++);
1380 #if defined(ENABLE_STATISTICS)
1383 if (opt_getcompilingtime)
1384 compilingtime_start();
1387 /* mark start of dump memory area */
1389 dumpsize = dump_size();
1391 /* create jitdata structure */
1393 jd = jit_jitdata_new(m);
1395 /* set the current optimization level to the previous one plus 1 */
1397 jd->code->optlevel = optlevel + 1;
1399 /* get the optimization flags for the current JIT run */
1401 jd->flags |= JITDATA_FLAG_REORDER;
1402 jd->flags |= JITDATA_FLAG_SHOWINTERMEDIATE;
1403 jd->flags |= JITDATA_FLAG_SHOWDISASSEMBLE;
1404 /* jd->flags |= JITDATA_FLAG_VERBOSECALL; */
1406 #if defined(ENABLE_JIT)
1407 # if defined(ENABLE_INTRP)
1410 /* initialize the register allocator */
1415 /* setup the codegendata memory */
1419 /* now call internal compile function */
1421 r = jit_compile_intern(jd);
1423 /* clear pointers to dump memory area */
1425 m->basicblocks = NULL;
1426 m->basicblockindex = NULL;
1427 m->instructions = NULL;
1431 /* We had an exception! Finish stuff here if necessary. */
1433 /* release codeinfo */
1435 code_codeinfo_free(jd->code);
1438 /* release dump area */
1440 dump_release(dumpsize);
1442 #if defined(ENABLE_STATISTICS)
1445 if (opt_getcompilingtime)
1446 compilingtime_stop();
1449 log_message_method("Recompiling done: ", m);
1451 /* return pointer to the methods entry point */
1457 /* jit_compile_intern **********************************************************
1459 Static internal function which does the actual compilation.
1461 *******************************************************************************/
1463 static u1 *jit_compile_intern(jitdata *jd)
1469 #if defined(ENABLE_RT_TIMING)
1470 struct timespec time_start,time_checks,time_parse,time_stack,
1471 time_typecheck,time_loop,time_ifconv,time_alloc,
1472 time_rplpoints,time_codegen;
1475 RT_TIMING_GET_TIME(time_start);
1477 /* get required compiler data */
1479 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1486 /* print log message for compiled method */
1488 DEBUG_JIT_COMPILEVERBOSE("Compiling: ");
1490 /* handle native methods and create a native stub */
1492 if (m->flags & ACC_NATIVE) {
1495 #if defined(WITH_STATIC_CLASSPATH)
1496 f = native_findfunction(m->class->name, m->name, m->descriptor,
1497 (m->flags & ACC_STATIC));
1504 code = codegen_createnativestub(f, m);
1506 assert(!m->code); /* native methods are never recompiled */
1509 return code->entrypoint;
1512 /* if there is no javacode, print error message and return empty method */
1514 if (m->jcode == NULL) {
1515 DEBUG_JIT_COMPILEVERBOSE("No code given for: ");
1517 code->entrypoint = (u1 *) (ptrint) do_nothing_function;
1520 return code->entrypoint; /* return empty method */
1523 #if defined(ENABLE_STATISTICS)
1525 count_tryblocks += m->exceptiontablelength;
1526 count_javacodesize += m->jcodelength + 18;
1527 count_javaexcsize += m->exceptiontablelength * SIZEOF_VOID_P;
1531 RT_TIMING_GET_TIME(time_checks);
1533 /* call the compiler passes ***********************************************/
1535 DEBUG_JIT_COMPILEVERBOSE("Parsing: ");
1537 /* call parse pass */
1540 DEBUG_JIT_COMPILEVERBOSE("Exception while parsing: ");
1544 RT_TIMING_GET_TIME(time_parse);
1546 DEBUG_JIT_COMPILEVERBOSE("Parsing done: ");
1553 DEBUG_JIT_COMPILEVERBOSE("Analysing: ");
1555 /* call stack analysis pass */
1557 if (!stack_analyse(jd)) {
1558 DEBUG_JIT_COMPILEVERBOSE("Exception while analysing: ");
1562 RT_TIMING_GET_TIME(time_stack);
1564 DEBUG_JIT_COMPILEVERBOSE("Analysing done: ");
1566 #ifdef ENABLE_VERIFIER
1567 if (jd->flags & JITDATA_FLAG_VERIFY) {
1568 DEBUG_JIT_COMPILEVERBOSE("Typechecking: ");
1570 /* call typecheck pass */
1571 if (!typecheck(jd)) {
1572 DEBUG_JIT_COMPILEVERBOSE("Exception while typechecking: ");
1577 DEBUG_JIT_COMPILEVERBOSE("Typechecking done: ");
1580 RT_TIMING_GET_TIME(time_typecheck);
1582 #if defined(ENABLE_LOOP)
1589 RT_TIMING_GET_TIME(time_loop);
1591 #if defined(ENABLE_IFCONV)
1592 if (JITDATA_HAS_FLAG_IFCONV(jd))
1593 if (!ifconv_static(jd))
1596 RT_TIMING_GET_TIME(time_ifconv);
1598 /* Basic block reordering. I think this should be done after
1599 if-conversion, as we could lose the ability to do the
1602 if (JITDATA_HAS_FLAG_REORDER(jd))
1606 #if defined(ENABLE_JIT)
1607 # if defined(ENABLE_INTRP)
1610 DEBUG_JIT_COMPILEVERBOSE("Allocating registers: ");
1612 #if defined(ENABLE_LSRA) && !defined(ENABLE_SSA)
1613 /* allocate registers */
1618 STATISTICS(count_methods_allocated_by_lsra++);
1621 # endif /* defined(ENABLE_LSRA) && !defined(ENABLE_SSA) */
1622 #if defined(ENABLE_SSA)
1623 /* allocate registers */
1624 if ((opt_lsra) && (cd->exceptiontablelength == 0)) {
1625 jd->ls = DNEW(lsradata);
1628 STATISTICS(count_methods_allocated_by_lsra++);
1631 # endif /* defined(ENABLE_SSA) */
1633 STATISTICS(count_locals_conflicts += (cd->maxlocals - 1) * (cd->maxlocals));
1638 STATISTICS(reg_make_statistics(jd));
1640 DEBUG_JIT_COMPILEVERBOSE("Allocating registers done: ");
1641 # if defined(ENABLE_INTRP)
1644 #endif /* defined(ENABLE_JIT) */
1645 RT_TIMING_GET_TIME(time_alloc);
1647 /* Allocate memory for basic block profiling information. This
1648 _must_ be done after loop optimization and register allocation,
1649 since they can change the basic block count. */
1651 if (JITDATA_HAS_FLAG_INSTRUMENT(jd))
1652 code->bbfrequency = MNEW(u4, m->basicblockcount);
1654 DEBUG_JIT_COMPILEVERBOSE("Generating code: ");
1656 /* create the replacement points */
1658 if (!replace_create_replacement_points(jd))
1660 RT_TIMING_GET_TIME(time_rplpoints);
1662 /* now generate the machine code */
1664 #if defined(ENABLE_JIT)
1665 # if defined(ENABLE_INTRP)
1667 if (!intrp_codegen(jd)) {
1668 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1676 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1682 if (!intrp_codegen(jd)) {
1683 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1688 RT_TIMING_GET_TIME(time_codegen);
1690 DEBUG_JIT_COMPILEVERBOSE("Generating code done: ");
1692 #if !defined(NDEBUG)
1693 /* intermediate and assembly code listings */
1695 if (JITDATA_HAS_FLAG_SHOWINTERMEDIATE(jd)) {
1698 else if (JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd)) {
1699 # if defined(ENABLE_DISASSEMBLER)
1700 DISASSEMBLE(code->entrypoint,
1701 code->entrypoint + (code->mcodelength - cd->dseglen));
1705 if (opt_showddatasegment)
1709 DEBUG_JIT_COMPILEVERBOSE("Compiling done: ");
1711 /* switch to the newly generated code */
1714 assert(code->entrypoint);
1716 /* add the current compile version to the methodinfo */
1718 code->prev = m->code;
1721 RT_TIMING_TIME_DIFF(time_start,time_checks,RT_TIMING_JIT_CHECKS);
1722 RT_TIMING_TIME_DIFF(time_checks,time_parse,RT_TIMING_JIT_PARSE);
1723 RT_TIMING_TIME_DIFF(time_parse,time_stack,RT_TIMING_JIT_STACK);
1724 RT_TIMING_TIME_DIFF(time_stack,time_typecheck,RT_TIMING_JIT_TYPECHECK);
1725 RT_TIMING_TIME_DIFF(time_typecheck,time_loop,RT_TIMING_JIT_LOOP);
1726 RT_TIMING_TIME_DIFF(time_loop,time_alloc,RT_TIMING_JIT_ALLOC);
1727 RT_TIMING_TIME_DIFF(time_alloc,time_rplpoints,RT_TIMING_JIT_RPLPOINTS);
1728 RT_TIMING_TIME_DIFF(time_rplpoints,time_codegen,RT_TIMING_JIT_CODEGEN);
1729 RT_TIMING_TIME_DIFF(time_start,time_codegen,RT_TIMING_JIT_TOTAL);
1731 /* return pointer to the methods entry point */
1733 return code->entrypoint;
1737 /* jit_asm_compile *************************************************************
1739 This method is called from asm_vm_call_method and does:
1741 - create stackframe info for exceptions
1742 - compile the method
1743 - patch the entrypoint of the method into the calculated address in
1745 - flushes the instruction cache.
1747 *******************************************************************************/
1749 u1 *jit_asm_compile(methodinfo *m, u1 *mptr, u1 *sp, u1 *ra)
1756 /* create the stackframeinfo (XPC is equal to RA) */
1758 stacktrace_create_extern_stackframeinfo(&sfi, NULL, sp, ra, ra);
1760 /* actually compile the method */
1762 entrypoint = jit_compile(m);
1764 /* remove the stackframeinfo */
1766 stacktrace_remove_stackframeinfo(&sfi);
1768 /* there was a problem during compilation */
1770 if (entrypoint == NULL)
1773 /* get the method patch address */
1775 pa = md_get_method_patch_address(ra, &sfi, mptr);
1777 /* patch the method entry point */
1781 *p = (ptrint) entrypoint;
1783 /* flush the instruction cache */
1785 md_icacheflush(pa, SIZEOF_VOID_P);
1791 /* jit_complement_condition ****************************************************
1793 Returns the complement of the passed conditional instruction.
1795 We use the order of the different conditions, e.g.:
1800 If the passed opcode is odd, we simply add 1 to get the complement.
1801 If the opcode is even, we subtract 1.
1808 *******************************************************************************/
1810 s4 jit_complement_condition(s4 opcode)
1814 return ICMD_IFNONNULL;
1816 case ICMD_IFNONNULL:
1820 /* check if opcode is odd */
1831 * These are local overrides for various environment variables in Emacs.
1832 * Please do not remove this and leave it at the end of the file, where
1833 * Emacs will automagically detect them.
1834 * ---------------------------------------------------------------------
1837 * indent-tabs-mode: t
1841 * vim:noexpandtab:sw=4:ts=4: