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 5404 2006-09-07 13:29:05Z 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_data[256][OP_DATA_SIZE];
1101 /* int op_needs_saved[256]; */
1102 /* int op_is_pei[256]; */
1104 /* jit_init ********************************************************************
1106 Initializes the JIT subsystem.
1108 *******************************************************************************/
1114 for( i = 0; i < 256; i++) {
1115 op_data[i][NEEDS_SAVED] = 0;
1116 op_data[i][PEI] = 0;
1119 op_data[ICMD_AASTORE ][NEEDS_SAVED] = 1;
1120 #if !SUPPORT_DIVISION
1121 op_data[ICMD_IDIV ][NEEDS_SAVED] = 1;
1122 op_data[ICMD_IREM ][NEEDS_SAVED] = 1;
1124 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1125 op_data[ICMD_LDIV ][NEEDS_SAVED] = 1;
1126 op_data[ICMD_LREM ][NEEDS_SAVED] = 1;
1128 op_data[ICMD_CHECKCAST][NEEDS_SAVED] = 1;
1130 op_data[ICMD_BUILTIN ][NEEDS_SAVED] = 1;
1131 op_data[ICMD_INVOKESTATIC ][NEEDS_SAVED] = 1;
1132 op_data[ICMD_INVOKESPECIAL ][NEEDS_SAVED] = 1;
1133 op_data[ICMD_INVOKEVIRTUAL ][NEEDS_SAVED] = 1;
1134 op_data[ICMD_INVOKEINTERFACE][NEEDS_SAVED] = 1;
1135 op_data[ICMD_MULTIANEWARRAY ][NEEDS_SAVED] = 1;
1137 op_data[ICMD_ACONST][PEI] = 1; /* OutOfMemoryError */
1138 op_data[ICMD_NEWARRAY][PEI] = 1; /* NegativeArraySizeException,OutOfMemoryError */
1139 op_data[ICMD_ANEWARRAY][PEI] = 1; /* NegativeArraySizeException,OutOfMemoryError */
1140 op_data[ICMD_MULTIANEWARRAY][PEI] = 1; /* NegativeArraySizeException,OutOfMemoryError */
1141 op_data[ICMD_ARRAYLENGTH][PEI] = 1; /* NullPointerException */
1142 op_data[ICMD_IALOAD][PEI] = 1; /* NullPointerException, ArrayIndexOutOfBoundsException */
1143 op_data[ICMD_LALOAD][PEI] = 1; /* NullPointerException, ArrayIndexOutOfBoundsException */
1144 op_data[ICMD_FALOAD][PEI] = 1; /* NullPointerException, ArrayIndexOutOfBoundsException */
1145 op_data[ICMD_DALOAD][PEI] = 1; /* NullPointerException, ArrayIndexOutOfBoundsException */
1146 op_data[ICMD_AALOAD][PEI] = 1; /* NullPointerException, ArrayIndexOutOfBoundsException */
1147 op_data[ICMD_BALOAD][PEI] = 1; /* NullPointerException, ArrayIndexOutOfBoundsException */
1148 op_data[ICMD_CALOAD][PEI] = 1; /* NullPointerException, ArrayIndexOutOfBoundsException */
1149 op_data[ICMD_SALOAD][PEI] = 1; /* NullPointerException, ArrayIndexOutOfBoundsException */
1150 op_data[ICMD_IASTORE][PEI] = 1; /* NullPointerException, ArrayIndexOutOfBoundsException */
1151 op_data[ICMD_LASTORE][PEI] = 1; /* NullPointerException, ArrayIndexOutOfBoundsException */
1152 op_data[ICMD_FASTORE][PEI] = 1; /* NullPointerException, ArrayIndexOutOfBoundsException */
1153 op_data[ICMD_DASTORE][PEI] = 1; /* NullPointerException, ArrayIndexOutOfBoundsException */
1154 op_data[ICMD_AASTORE][PEI] = 1; /* NullPointerException, ArrayIndexOutOfBoundsException */
1155 /* ArrayStoreException */
1156 op_data[ICMD_BASTORE][PEI] = 1; /* NullPointerException, ArrayIndexOutOfBoundsException */
1157 op_data[ICMD_CASTORE][PEI] = 1; /* NullPointerException, ArrayIndexOutOfBoundsException */
1158 op_data[ICMD_SASTORE][PEI] = 1; /* NullPointerException, ArrayIndexOutOfBoundsException */
1160 op_data[ICMD_IDIV][PEI] = 1; /* "/ by Zero" ArithmeticException */
1161 op_data[ICMD_LDIV][PEI] = 1; /* "/ by Zero" ArithmeticException */
1162 op_data[ICMD_IREM][PEI] = 1; /* "/ by Zero" ArithmeticException */
1163 op_data[ICMD_LREM][PEI] = 1; /* "/ by Zero" ArithmeticException */
1165 op_data[ICMD_PUTFIELD][PEI] = 1; /* NullPointerException, IncompatibleClassChangeError */
1166 op_data[ICMD_GETFIELD][PEI] = 1; /* NullPointerException, IncompatibleClassChangeError */
1168 op_data[ICMD_PUTFIELDCONST][PEI] = 1; /*NullPointerException, IncompatibleClassChangeError */
1169 op_data[ICMD_GETFIELDCONST][PEI] = 1; /*NullPointerException, IncompatibleClassChangeError */
1171 op_data[ICMD_PUTSTATIC][PEI] = 1; /* IncompatibleClassChangeError */
1172 op_data[ICMD_GETSTATIC][PEI] = 1; /* IncompatibleClassChangeError */
1174 op_data[ICMD_BUILTIN][PEI] = 1; /* ?NullPointerException, StackOverflowError,? * */
1175 op_data[ICMD_INVOKEVIRTUAL][PEI] = 1; /* NullPointerException, StackOverflowError, * */
1176 op_data[ICMD_INVOKESPECIAL][PEI] = 1; /* NullPointerException, StackOverflowError, * */
1177 op_data[ICMD_INVOKESTATIC][PEI] = 1; /* StackOverflowError, * */
1178 op_data[ICMD_INVOKEINTERFACE][PEI] = 1; /* NullPointerException, StackOverflowError, * */
1180 op_data[ICMD_ATHROW][PEI] = 1; /* NullPointerException, * */
1182 op_data[ICMD_CHECKCAST][PEI] = 1; /* ClassCastException */
1184 op_data[ICMD_MONITORENTER][PEI] = 1; /* NullPointerException */
1185 op_data[ICMD_MONITOREXIT][PEI] = 1; /* NullPointerException */
1187 op_data[ICMD_CHECKNULL][PEI] = 1; /* NullPointerException */
1189 /* initialize stack analysis subsystem */
1191 (void) stack_init();
1193 /* initialize show subsystem */
1195 #if !defined(NDEBUG)
1199 /* initialize codegen subsystem */
1205 /* jit_close *******************************************************************
1207 Close the JIT subsystem.
1209 *******************************************************************************/
1211 void jit_close(void)
1217 /* dummy function, used when there is no JavaVM code available */
1219 static u1 *do_nothing_function(void)
1225 /* jit_jitdata_new *************************************************************
1227 Allocates and initalizes a new jitdata structure.
1229 *******************************************************************************/
1231 static jitdata *jit_jitdata_new(methodinfo *m)
1235 /* allocate jitdata structure and fill it */
1240 jd->cd = DNEW(codegendata);
1241 jd->rd = DNEW(registerdata);
1242 #if defined(ENABLE_LOOP)
1243 jd->ld = DNEW(loopdata);
1246 /* Allocate codeinfo memory from the heap as we need to keep them. */
1248 jd->code = code_codeinfo_new(m);
1250 /* initialize variables */
1253 jd->isleafmethod = true;
1259 /* jit_compile *****************************************************************
1261 Translates one method to machine code.
1263 *******************************************************************************/
1265 static u1 *jit_compile_intern(jitdata *jd);
1267 u1 *jit_compile(methodinfo *m)
1273 STATISTICS(count_jit_calls++);
1275 /* Initialize the static function's class. */
1277 /* ATTENTION: This MUST be done before the method lock is aquired,
1278 otherwise we could run into a deadlock with <clinit>'s that
1279 call static methods of it's own class. */
1281 if ((m->flags & ACC_STATIC) && !(m->class->state & CLASS_INITIALIZED)) {
1282 #if !defined(NDEBUG)
1284 log_message_class("Initialize class ", m->class);
1287 if (!initialize_class(m->class))
1290 /* check if the method has been compiled during initialization */
1292 if ((m->code != NULL) && (m->code->entrypoint != NULL))
1293 return m->code->entrypoint;
1296 /* enter a monitor on the method */
1298 LOCK_MONITOR_ENTER(m);
1300 /* if method has been already compiled return immediately */
1302 if (m->code != NULL) {
1303 LOCK_MONITOR_EXIT(m);
1305 assert(m->code->entrypoint);
1306 return m->code->entrypoint;
1309 STATISTICS(count_methods++);
1311 #if defined(ENABLE_STATISTICS)
1314 if (opt_getcompilingtime)
1315 compilingtime_start();
1318 /* mark start of dump memory area */
1320 dumpsize = dump_size();
1322 /* create jitdata structure */
1324 jd = jit_jitdata_new(m);
1326 /* set the flags for the current JIT run */
1328 jd->flags = JITDATA_FLAG_PARSE;
1330 #if defined(ENABLE_VERIFY)
1332 jd->flags |= JITDATA_FLAG_VERIFY;
1336 jd->flags |= JITDATA_FLAG_INSTRUMENT;
1338 #if defined(ENABLE_IFCONV)
1340 jd->flags |= JITDATA_FLAG_IFCONV;
1343 if (opt_showintermediate)
1344 jd->flags |= JITDATA_FLAG_SHOWINTERMEDIATE;
1346 if (opt_showdisassemble)
1347 jd->flags |= JITDATA_FLAG_SHOWDISASSEMBLE;
1349 if (opt_verbosecall)
1350 jd->flags |= JITDATA_FLAG_VERBOSECALL;
1352 #if defined(ENABLE_JIT)
1353 # if defined(ENABLE_INTRP)
1356 /* initialize the register allocator */
1362 /* setup the codegendata memory */
1366 /* now call internal compile function */
1368 r = jit_compile_intern(jd);
1371 /* We had an exception! Finish stuff here if necessary. */
1373 /* release codeinfo */
1375 code_codeinfo_free(jd->code);
1377 /* Release memory for basic block profiling information. */
1379 if (JITDATA_HAS_FLAG_INSTRUMENT(jd))
1380 if (jd->code->bbfrequency != NULL)
1381 MFREE(jd->code->bbfrequency, u4, jd->code->basicblockcount);
1384 DEBUG_JIT_COMPILEVERBOSE("Running: ");
1387 /* release dump area */
1389 dump_release(dumpsize);
1391 #if defined(ENABLE_STATISTICS)
1394 if (opt_getcompilingtime)
1395 compilingtime_stop();
1398 /* leave the monitor */
1400 LOCK_MONITOR_EXIT(m);
1402 /* return pointer to the methods entry point */
1408 /* jit_recompile ***************************************************************
1410 Recompiles a Java method.
1412 *******************************************************************************/
1414 u1 *jit_recompile(methodinfo *m)
1421 /* check for max. optimization level */
1423 optlevel = m->code->optlevel;
1425 if (optlevel == 1) {
1426 /* log_message_method("not recompiling: ", m); */
1430 log_message_method("Recompiling start: ", m);
1432 STATISTICS(count_jit_calls++);
1434 #if defined(ENABLE_STATISTICS)
1437 if (opt_getcompilingtime)
1438 compilingtime_start();
1441 /* mark start of dump memory area */
1443 dumpsize = dump_size();
1445 /* create jitdata structure */
1447 jd = jit_jitdata_new(m);
1449 /* set the current optimization level to the previous one plus 1 */
1451 jd->code->optlevel = optlevel + 1;
1453 /* get the optimization flags for the current JIT run */
1455 jd->flags |= JITDATA_FLAG_REORDER;
1456 jd->flags |= JITDATA_FLAG_SHOWINTERMEDIATE;
1457 jd->flags |= JITDATA_FLAG_SHOWDISASSEMBLE;
1458 /* jd->flags |= JITDATA_FLAG_VERBOSECALL; */
1460 #if defined(ENABLE_JIT)
1461 # if defined(ENABLE_INTRP)
1464 /* initialize the register allocator */
1469 /* setup the codegendata memory */
1473 /* now call internal compile function */
1475 r = jit_compile_intern(jd);
1478 /* We had an exception! Finish stuff here if necessary. */
1480 /* release codeinfo */
1482 code_codeinfo_free(jd->code);
1485 /* release dump area */
1487 dump_release(dumpsize);
1489 #if defined(ENABLE_STATISTICS)
1492 if (opt_getcompilingtime)
1493 compilingtime_stop();
1496 log_message_method("Recompiling done: ", m);
1498 /* return pointer to the methods entry point */
1504 /* jit_compile_intern **********************************************************
1506 Static internal function which does the actual compilation.
1508 *******************************************************************************/
1510 static u1 *jit_compile_intern(jitdata *jd)
1516 #if defined(ENABLE_RT_TIMING)
1517 struct timespec time_start,time_checks,time_parse,time_stack,
1518 time_typecheck,time_loop,time_ifconv,time_alloc,
1519 time_rplpoints,time_codegen;
1522 RT_TIMING_GET_TIME(time_start);
1524 /* get required compiler data */
1526 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1533 /* print log message for compiled method */
1535 DEBUG_JIT_COMPILEVERBOSE("Compiling: ");
1537 /* handle native methods and create a native stub */
1539 if (m->flags & ACC_NATIVE) {
1542 #if defined(WITH_STATIC_CLASSPATH)
1543 f = native_findfunction(m->class->name, m->name, m->descriptor,
1544 (m->flags & ACC_STATIC));
1551 code = codegen_createnativestub(f, m);
1553 assert(!m->code); /* native methods are never recompiled */
1556 return code->entrypoint;
1559 /* if there is no javacode, print error message and return empty method */
1561 if (m->jcode == NULL) {
1562 DEBUG_JIT_COMPILEVERBOSE("No code given for: ");
1564 code->entrypoint = (u1 *) (ptrint) do_nothing_function;
1567 return code->entrypoint; /* return empty method */
1570 #if defined(ENABLE_STATISTICS)
1572 count_tryblocks += m->exceptiontablelength;
1573 count_javacodesize += m->jcodelength + 18;
1574 count_javaexcsize += m->exceptiontablelength * SIZEOF_VOID_P;
1578 RT_TIMING_GET_TIME(time_checks);
1580 /* call the compiler passes ***********************************************/
1582 DEBUG_JIT_COMPILEVERBOSE("Parsing: ");
1584 /* call parse pass */
1586 if (!new_parse(jd)) {
1587 DEBUG_JIT_COMPILEVERBOSE("Exception while parsing: ");
1591 RT_TIMING_GET_TIME(time_parse);
1593 DEBUG_JIT_COMPILEVERBOSE("Parsing done: ");
1600 DEBUG_JIT_COMPILEVERBOSE("Analysing: ");
1602 /* call stack analysis pass */
1604 if (!new_stack_analyse(jd)) {
1605 DEBUG_JIT_COMPILEVERBOSE("Exception while analysing: ");
1609 RT_TIMING_GET_TIME(time_stack);
1611 DEBUG_JIT_COMPILEVERBOSE("Analysing done: ");
1613 #ifdef ENABLE_VERIFIER
1614 if (jd->flags & JITDATA_FLAG_VERIFY) {
1615 DEBUG_JIT_COMPILEVERBOSE("Typechecking: ");
1617 /* call typecheck pass */
1618 #if !defined(NEW_VAR)
1619 if (!typecheck(jd)) {
1620 DEBUG_JIT_COMPILEVERBOSE("Exception while typechecking: ");
1625 DEBUG_JIT_COMPILEVERBOSE("Typechecking done: ");
1629 RT_TIMING_GET_TIME(time_typecheck);
1631 #if defined(ENABLE_LOOP)
1638 RT_TIMING_GET_TIME(time_loop);
1640 #if defined(ENABLE_IFCONV)
1641 if (JITDATA_HAS_FLAG_IFCONV(jd))
1642 if (!ifconv_static(jd))
1645 RT_TIMING_GET_TIME(time_ifconv);
1647 /* Basic block reordering. I think this should be done after
1648 if-conversion, as we could lose the ability to do the
1651 if (JITDATA_HAS_FLAG_REORDER(jd))
1655 #if defined(ENABLE_JIT)
1656 # if defined(ENABLE_INTRP)
1659 DEBUG_JIT_COMPILEVERBOSE("Allocating registers: ");
1661 #if defined(ENABLE_LSRA) && !defined(ENABLE_SSA)
1662 /* allocate registers */
1667 STATISTICS(count_methods_allocated_by_lsra++);
1670 # endif /* defined(ENABLE_LSRA) && !defined(ENABLE_SSA) */
1671 #if defined(ENABLE_SSA)
1672 /* allocate registers */
1673 if ((opt_lsra) && (cd->exceptiontablelength == 0)) {
1674 jd->ls = DNEW(lsradata);
1677 STATISTICS(count_methods_allocated_by_lsra++);
1680 # endif /* defined(ENABLE_SSA) */
1682 STATISTICS(count_locals_conflicts += (cd->maxlocals - 1) * (cd->maxlocals));
1687 STATISTICS(reg_make_statistics(jd));
1689 DEBUG_JIT_COMPILEVERBOSE("Allocating registers done: ");
1690 # if defined(ENABLE_INTRP)
1693 #endif /* defined(ENABLE_JIT) */
1694 RT_TIMING_GET_TIME(time_alloc);
1696 /* Allocate memory for basic block profiling information. This
1697 _must_ be done after loop optimization and register allocation,
1698 since they can change the basic block count. */
1700 if (JITDATA_HAS_FLAG_INSTRUMENT(jd))
1701 code->bbfrequency = MNEW(u4, jd->new_basicblockcount);
1703 DEBUG_JIT_COMPILEVERBOSE("Generating code: ");
1705 /* create the replacement points */
1707 if (!replace_create_replacement_points(jd))
1709 RT_TIMING_GET_TIME(time_rplpoints);
1711 /* now generate the machine code */
1713 #if defined(ENABLE_JIT)
1714 # if defined(ENABLE_INTRP)
1716 if (!intrp_codegen(jd)) {
1717 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1725 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1731 if (!intrp_codegen(jd)) {
1732 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1737 RT_TIMING_GET_TIME(time_codegen);
1739 DEBUG_JIT_COMPILEVERBOSE("Generating code done: ");
1741 #if !defined(NDEBUG)
1742 /* intermediate and assembly code listings */
1744 if (JITDATA_HAS_FLAG_SHOWINTERMEDIATE(jd)) {
1745 new_show_method(jd, SHOW_CODE);
1747 else if (JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd)) {
1748 # if defined(ENABLE_DISASSEMBLER)
1749 DISASSEMBLE(code->entrypoint,
1750 code->entrypoint + (code->mcodelength - cd->dseglen));
1754 if (opt_showddatasegment)
1758 DEBUG_JIT_COMPILEVERBOSE("Compiling done: ");
1760 /* switch to the newly generated code */
1763 assert(code->entrypoint);
1765 /* add the current compile version to the methodinfo */
1767 code->prev = m->code;
1770 RT_TIMING_TIME_DIFF(time_start,time_checks,RT_TIMING_JIT_CHECKS);
1771 RT_TIMING_TIME_DIFF(time_checks,time_parse,RT_TIMING_JIT_PARSE);
1772 RT_TIMING_TIME_DIFF(time_parse,time_stack,RT_TIMING_JIT_STACK);
1773 RT_TIMING_TIME_DIFF(time_stack,time_typecheck,RT_TIMING_JIT_TYPECHECK);
1774 RT_TIMING_TIME_DIFF(time_typecheck,time_loop,RT_TIMING_JIT_LOOP);
1775 RT_TIMING_TIME_DIFF(time_loop,time_alloc,RT_TIMING_JIT_ALLOC);
1776 RT_TIMING_TIME_DIFF(time_alloc,time_rplpoints,RT_TIMING_JIT_RPLPOINTS);
1777 RT_TIMING_TIME_DIFF(time_rplpoints,time_codegen,RT_TIMING_JIT_CODEGEN);
1778 RT_TIMING_TIME_DIFF(time_start,time_codegen,RT_TIMING_JIT_TOTAL);
1780 /* return pointer to the methods entry point */
1782 return code->entrypoint;
1786 /* jit_asm_compile *************************************************************
1788 This method is called from asm_vm_call_method and does:
1790 - create stackframe info for exceptions
1791 - compile the method
1792 - patch the entrypoint of the method into the calculated address in
1794 - flushes the instruction cache.
1796 *******************************************************************************/
1798 u1 *jit_asm_compile(methodinfo *m, u1 *mptr, u1 *sp, u1 *ra)
1805 /* create the stackframeinfo (XPC is equal to RA) */
1807 stacktrace_create_extern_stackframeinfo(&sfi, NULL, sp, ra, ra);
1809 /* actually compile the method */
1811 entrypoint = jit_compile(m);
1813 /* remove the stackframeinfo */
1815 stacktrace_remove_stackframeinfo(&sfi);
1817 /* there was a problem during compilation */
1819 if (entrypoint == NULL)
1822 /* get the method patch address */
1824 pa = md_get_method_patch_address(ra, &sfi, mptr);
1826 /* patch the method entry point */
1830 *p = (ptrint) entrypoint;
1832 /* flush the instruction cache */
1834 md_icacheflush(pa, SIZEOF_VOID_P);
1840 /* jit_complement_condition ****************************************************
1842 Returns the complement of the passed conditional instruction.
1844 We use the order of the different conditions, e.g.:
1849 If the passed opcode is odd, we simply add 1 to get the complement.
1850 If the opcode is even, we subtract 1.
1857 *******************************************************************************/
1859 s4 jit_complement_condition(s4 opcode)
1863 return ICMD_IFNONNULL;
1865 case ICMD_IFNONNULL:
1869 /* check if opcode is odd */
1880 * These are local overrides for various environment variables in Emacs.
1881 * Please do not remove this and leave it at the end of the file, where
1882 * Emacs will automagically detect them.
1883 * ---------------------------------------------------------------------
1886 * indent-tabs-mode: t
1890 * vim:noexpandtab:sw=4:ts=4: