* Merged with df1b780317c3.
[cacao.git] / src / vm / jit / jit.c
1 /* src/vm/jit/jit.c - calls the code generation functions
2
3    Copyright (C) 1996-2005, 2006, 2007, 2008
4    CACAOVM - Verein zu Foerderung der freien virtuellen Machine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #include "config.h"
27
28 #include <assert.h>
29 #include <stdint.h>
30
31 #include "vm/types.h"
32
33 #include "md.h"
34
35 #include "mm/memory.h"
36
37 #include "native/native.h"
38
39 #include "toolbox/logging.h"
40
41 #include "threads/lock-common.h"
42 #include "threads/threads-common.h"
43
44 #include "vm/global.h"
45 #include "vm/initialize.h"
46
47 #include "vm/jit/asmpart.h"
48
49 #include "vm/jit/cfg.h"
50
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/parse.h"
56 #include "vm/jit/reg.h"
57
58 #include "vm/jit/show.h"
59 #include "vm/jit/stack.h"
60
61 #include "vm/jit/allocator/simplereg.h"
62 #if defined(ENABLE_LSRA) && !defined(ENABLE_SSA)
63 # include "vm/jit/allocator/lsra.h"
64 #endif
65
66 #if defined(ENABLE_SSA)
67 # include "vm/jit/optimizing/lsra.h"
68 # include "vm/jit/optimizing/ssa.h"
69 #endif
70
71 #if defined(ENABLE_INLINING)
72 # include "vm/jit/inline/inline.h"
73 #endif
74
75 #include "vm/jit/ir/bytecode.h"
76
77 #include "vm/jit/loop/analyze.h"
78 #include "vm/jit/loop/graph.h"
79 #include "vm/jit/loop/loop.h"
80
81 #if defined(ENABLE_IFCONV)
82 # include "vm/jit/optimizing/ifconv.h"
83 #endif
84
85 #include "vm/jit/optimizing/reorder.h"
86
87 #if defined(ENABLE_PYTHON)
88 # include "vm/jit/python.h"
89 #endif
90
91 #include "vm/jit/verify/typecheck.h"
92
93 #include "vmcore/class.h"
94 #include "vmcore/loader.h"
95 #include "vmcore/method.h"
96 #include "vmcore/options.h"
97 #include "vmcore/rt-timing.h"
98 #include "vmcore/statistics.h"
99
100
101 /* debug macros ***************************************************************/
102
103 #if !defined(NDEBUG)
104 #define DEBUG_JIT_COMPILEVERBOSE(x)                             \
105     do {                                                                                \
106         if (compileverbose) {                                   \
107             log_message_method(x, m);                   \
108         }                                                                               \
109     } while (0)
110 #else
111 #define DEBUG_JIT_COMPILEVERBOSE(x)    /* nothing */
112 #endif
113
114 #if !defined(NDEBUG)
115 # define TRACECOMPILERCALLS()                                                           \
116         do {                                                                                                    \
117                 if (opt_TraceCompilerCalls) {                                           \
118                         log_start();                                                                    \
119                         log_print("[JIT compiler started: method=");    \
120                         method_print(m);                                                                \
121                         log_print("]");                                                                 \
122                         log_finish();                                                                   \
123                 }                                                                                                       \
124         } while (0)
125 #else
126 # define TRACECOMPILERCALLS()
127 #endif
128
129
130 /* the ICMD table ************************************************************/
131
132 #if !defined(NDEBUG)
133 #define N(name)  name,
134 #else
135 #define N(name)
136 #endif
137
138 /* abbreviations for flags */
139
140 #define PEI     ICMDTABLE_PEI
141 #define CALLS   ICMDTABLE_CALLS
142
143 /* some machine dependent values */
144
145 #if SUPPORT_DIVISION
146 #define IDIV_CALLS  0
147 #else
148 #define IDIV_CALLS  ICMDTABLE_CALLS
149 #endif
150
151 #if (SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
152 #define LDIV_CALLS  0
153 #else
154 #define LDIV_CALLS  ICMDTABLE_CALLS
155 #endif
156
157 /* include the actual table */
158
159 icmdtable_entry_t icmd_table[256] = {
160 #include <vm/jit/icmdtable.inc>
161 };
162
163 #undef N
164 #undef PEI
165 #undef CALLS
166
167 /* XXX hack until the old "PEI" definition is removed */
168 #define PEI 1
169
170
171 /* stackelement requirements of Java opcodes **********************************/
172
173 int stackreq[256] = {
174         0,    /* JAVA_NOP                         0 */
175         1,    /* JAVA_ACONST                      1 */
176         1,    /* JAVA_ICONST_M1                   2 */
177         1,    /* JAVA_ICONST_0                    3 */
178         1,    /* JAVA_ICONST_1                    4 */
179         1,    /* JAVA_ICONST_2                    5 */
180         1,    /* JAVA_ICONST_3                    6 */
181         1,    /* JAVA_ICONST_4                    7 */
182         1,    /* JAVA_ICONST_5                    8 */
183         1,    /* JAVA_LCONST_0                    9 */
184         1,    /* JAVA_LCONST_1                   10 */
185         1,    /* JAVA_FCONST_0                   11 */
186         1,    /* JAVA_FCONST_1                   12 */
187         1,    /* JAVA_FCONST_2                   13 */
188         1,    /* JAVA_DCONST_0                   14 */
189         1,    /* JAVA_DCONST_1                   15 */
190         1,    /* JAVA_BIPUSH                     16 */
191         1,    /* JAVA_SIPUSH                     17 */
192         1,    /* JAVA_LDC                        18 */
193         1,    /* JAVA_LDC_W                      19 */
194         1,    /* JAVA_LDC2_W                     20 */
195         1,    /* JAVA_ILOAD                      21 */
196         1,    /* JAVA_LLOAD                      22 */
197         1,    /* JAVA_FLOAD                      23 */
198         1,    /* JAVA_DLOAD                      24 */
199         1,    /* JAVA_ALOAD                      25 */
200         1,    /* JAVA_ILOAD_0                    26 */
201         1,    /* JAVA_ILOAD_1                    27 */
202         1,    /* JAVA_ILOAD_2                    28 */
203         1,    /* JAVA_ILOAD_3                    29 */
204         1,    /* JAVA_LLOAD_0                    30 */
205         1,    /* JAVA_LLOAD_1                    31 */
206         1,    /* JAVA_LLOAD_2                    32 */
207         1,    /* JAVA_LLOAD_3                    33 */
208         1,    /* JAVA_FLOAD_0                    34 */
209         1,    /* JAVA_FLOAD_1                    35 */
210         1,    /* JAVA_FLOAD_2                    36 */
211         1,    /* JAVA_FLOAD_3                    37 */
212         1,    /* JAVA_DLOAD_0                    38 */
213         1,    /* JAVA_DLOAD_1                    39 */
214         1,    /* JAVA_DLOAD_2                    40 */
215         1,    /* JAVA_DLOAD_3                    41 */
216         1,    /* JAVA_ALOAD_0                    42 */
217         1,    /* JAVA_ALOAD_1                    43 */
218         1,    /* JAVA_ALOAD_2                    44 */
219         1,    /* JAVA_ALOAD_3                    45 */
220         1,    /* JAVA_IALOAD                     46 */
221         1,    /* JAVA_LALOAD                     47 */
222         1,    /* JAVA_FALOAD                     48 */
223         1,    /* JAVA_DALOAD                     49 */
224         1,    /* JAVA_AALOAD                     50 */
225         1,    /* JAVA_BALOAD                     51 */
226         1,    /* JAVA_CALOAD                     52 */
227         1,    /* JAVA_SALOAD                     53 */
228         0,    /* JAVA_ISTORE                     54 */
229         0,    /* JAVA_LSTORE                     55 */
230         0,    /* JAVA_FSTORE                     56 */
231         0,    /* JAVA_DSTORE                     57 */
232         0,    /* JAVA_ASTORE                     58 */
233         0,    /* JAVA_ISTORE_0                   59 */
234         0,    /* JAVA_ISTORE_1                   60 */
235         0,    /* JAVA_ISTORE_2                   61 */
236         0,    /* JAVA_ISTORE_3                   62 */
237         0,    /* JAVA_LSTORE_0                   63 */
238         0,    /* JAVA_LSTORE_1                   64 */
239         0,    /* JAVA_LSTORE_2                   65 */
240         0,    /* JAVA_LSTORE_3                   66 */
241         0,    /* JAVA_FSTORE_0                   67 */
242         0,    /* JAVA_FSTORE_1                   68 */
243         0,    /* JAVA_FSTORE_2                   69 */
244         0,    /* JAVA_FSTORE_3                   70 */
245         0,    /* JAVA_DSTORE_0                   71 */
246         0,    /* JAVA_DSTORE_1                   72 */
247         0,    /* JAVA_DSTORE_2                   73 */
248         0,    /* JAVA_DSTORE_3                   74 */
249         0,    /* JAVA_ASTORE_0                   75 */
250         0,    /* JAVA_ASTORE_1                   76 */
251         0,    /* JAVA_ASTORE_2                   77 */
252         0,    /* JAVA_ASTORE_3                   78 */
253         0,    /* JAVA_IASTORE                    79 */
254         0,    /* JAVA_LASTORE                    80 */
255         0,    /* JAVA_FASTORE                    81 */
256         0,    /* JAVA_DASTORE                    82 */
257         0,    /* JAVA_AASTORE                    83 */
258         0,    /* JAVA_BASTORE                    84 */
259         0,    /* JAVA_CASTORE                    85 */
260         0,    /* JAVA_SASTORE                    86 */
261         0,    /* JAVA_POP                        87 */
262         0,    /* JAVA_POP2                       88 */
263         1,    /* JAVA_DUP                        89 */
264         1+3,  /* JAVA_DUP_X1                     90 */
265         2+4,  /* JAVA_DUP_X2                     91 */
266         2,    /* JAVA_DUP2                       92 */
267         2+5,  /* JAVA_DUP2_X1                    93 */
268         3+6,  /* JAVA_DUP2_X2                    94 */
269         1+2,  /* JAVA_SWAP                       95 */
270         1,    /* JAVA_IADD                       96 */
271         1,    /* JAVA_LADD                       97 */
272         1,    /* JAVA_FADD                       98 */
273         1,    /* JAVA_DADD                       99 */
274         1,    /* JAVA_ISUB                      100 */
275         1,    /* JAVA_LSUB                      101 */
276         1,    /* JAVA_FSUB                      102 */
277         1,    /* JAVA_DSUB                      103 */
278         1,    /* JAVA_IMUL                      104 */
279         1,    /* JAVA_LMUL                      105 */
280         1,    /* JAVA_FMUL                      106 */
281         1,    /* JAVA_DMUL                      107 */
282         1,    /* JAVA_IDIV                      108 */
283         1,    /* JAVA_LDIV                      109 */
284         1,    /* JAVA_FDIV                      110 */
285         1,    /* JAVA_DDIV                      111 */
286         1,    /* JAVA_IREM                      112 */
287         1,    /* JAVA_LREM                      113 */
288         1,    /* JAVA_FREM                      114 */
289         1,    /* JAVA_DREM                      115 */
290         1,    /* JAVA_INEG                      116 */
291         1,    /* JAVA_LNEG                      117 */
292         1,    /* JAVA_FNEG                      118 */
293         1,    /* JAVA_DNEG                      119 */
294         1,    /* JAVA_ISHL                      120 */
295         1,    /* JAVA_LSHL                      121 */
296         1,    /* JAVA_ISHR                      122 */
297         1,    /* JAVA_LSHR                      123 */
298         1,    /* JAVA_IUSHR                     124 */
299         1,    /* JAVA_LUSHR                     125 */
300         1,    /* JAVA_IAND                      126 */
301         1,    /* JAVA_LAND                      127 */
302         1,    /* JAVA_IOR                       128 */
303         1,    /* JAVA_LOR                       129 */
304         1,    /* JAVA_IXOR                      130 */
305         1,    /* JAVA_LXOR                      131 */
306         0,    /* JAVA_IINC                      132 */
307         1,    /* JAVA_I2L                       133 */
308         1,    /* JAVA_I2F                       134 */
309         1,    /* JAVA_I2D                       135 */
310         1,    /* JAVA_L2I                       136 */
311         1,    /* JAVA_L2F                       137 */
312         1,    /* JAVA_L2D                       138 */
313         1,    /* JAVA_F2I                       139 */
314         1,    /* JAVA_F2L                       140 */
315         1,    /* JAVA_F2D                       141 */
316         1,    /* JAVA_D2I                       142 */
317         1,    /* JAVA_D2L                       143 */
318         1,    /* JAVA_D2F                       144 */
319         1,    /* JAVA_INT2BYTE                  145 */
320         1,    /* JAVA_INT2CHAR                  146 */
321         1,    /* JAVA_INT2SHORT                 147 */
322         1,    /* JAVA_LCMP                      148 */
323         1,    /* JAVA_FCMPL                     149 */
324         1,    /* JAVA_FCMPG                     150 */
325         1,    /* JAVA_DCMPL                     151 */
326         1,    /* JAVA_DCMPG                     152 */
327         0,    /* JAVA_IFEQ                      153 */
328         0,    /* JAVA_IFNE                      154 */
329         0,    /* JAVA_IFLT                      155 */
330         0,    /* JAVA_IFGE                      156 */
331         0,    /* JAVA_IFGT                      157 */
332         0,    /* JAVA_IFLE                      158 */
333         0,    /* JAVA_IF_ICMPEQ                 159 */
334         0,    /* JAVA_IF_ICMPNE                 160 */
335         0,    /* JAVA_IF_ICMPLT                 161 */
336         0,    /* JAVA_IF_ICMPGE                 162 */
337         0,    /* JAVA_IF_ICMPGT                 163 */
338         0,    /* JAVA_IF_ICMPLE                 164 */
339         0,    /* JAVA_IF_ACMPEQ                 165 */
340         0,    /* JAVA_IF_ACMPNE                 166 */
341         0,    /* JAVA_GOTO                      167 */
342         1,    /* JAVA_JSR                       168 */
343         0,    /* JAVA_RET                       169 */
344         0,    /* JAVA_TABLESWITCH               170 */
345         0,    /* JAVA_LOOKUPSWITCH              171 */
346         0,    /* JAVA_IRETURN                   172 */
347         0,    /* JAVA_LRETURN                   173 */
348         0,    /* JAVA_FRETURN                   174 */
349         0,    /* JAVA_DRETURN                   175 */
350         0,    /* JAVA_ARETURN                   176 */
351         0,    /* JAVA_RETURN                    177 */
352         1,    /* JAVA_GETSTATIC                 178 */
353         0,    /* JAVA_PUTSTATIC                 179 */
354         1,    /* JAVA_GETFIELD                  180 */
355         0,    /* JAVA_PUTFIELD                  181 */
356         1,    /* JAVA_INVOKEVIRTUAL             182 */
357         1,    /* JAVA_INVOKESPECIAL             183 */
358         1,    /* JAVA_INVOKESTATIC              184 */
359         1,    /* JAVA_INVOKEINTERFACE           185 */
360         1,    /* JAVA_UNDEF186                  186 */
361         1,    /* JAVA_NEW                       187 */
362         1,    /* JAVA_NEWARRAY                  188 */
363         1,    /* JAVA_ANEWARRAY                 189 */
364         1,    /* JAVA_ARRAYLENGTH               190 */
365         1,    /* JAVA_ATHROW                    191 */
366         1,    /* JAVA_CHECKCAST                 192 */
367         1,    /* JAVA_INSTANCEOF                193 */
368         0,    /* JAVA_MONITORENTER              194 */
369         0,    /* JAVA_MONITOREXIT               195 */
370         0,    /* JAVA_WIDE                      196 */
371         1,    /* JAVA_MULTIANEWARRAY            197 */
372         0,    /* JAVA_IFNULL                    198 */
373         0,    /* JAVA_IFNONNULL                 199 */
374         0,    /* JAVA_GOTO_W                    200 */
375         1,    /* JAVA_JSR_W                     201 */
376         0,    /* JAVA_BREAKPOINT                202 */
377         1,    /* JAVA_UNDEF203                  203 */
378         1,    /* JAVA_UNDEF204                  204 */
379         1,    /* JAVA_UNDEF205                  205 */
380         1,    /* JAVA_UNDEF206                  206 */
381         1,    /* JAVA_UNDEF207                  207 */
382         1,    /* JAVA_UNDEF208                  208 */
383         1,    /* JAVA_UNDEF209                  209 */
384         1,    /* JAVA_UNDEF210                  210 */
385         1,    /* JAVA_UNDEF211                  211 */
386         1,    /* JAVA_UNDEF212                  212 */
387         1,    /* JAVA_UNDEF213                  213 */
388         1,    /* JAVA_UNDEF214                  214 */
389         1,    /* JAVA_UNDEF215                  215 */
390         1,    /* JAVA_UNDEF216                  216 */
391         1,    /* JAVA_UNDEF217                  217 */
392         1,    /* JAVA_UNDEF218                  218 */
393         1,    /* JAVA_UNDEF219                  219 */
394         1,    /* JAVA_UNDEF220                  220 */
395         1,    /* JAVA_UNDEF221                  221 */
396         1,    /* JAVA_UNDEF222                  222 */
397         1,    /* JAVA_UNDEF223                  223 */
398         1,    /* JAVA_UNDEF224                  224 */
399         1,    /* JAVA_UNDEF225                  225 */
400         1,    /* JAVA_UNDEF226                  226 */
401         1,    /* JAVA_UNDEF227                  227 */
402         1,    /* JAVA_UNDEF228                  228 */
403         1,    /* JAVA_UNDEF229                  229 */
404         1,    /* JAVA_UNDEF230                  230 */
405         1,    /* JAVA_UNDEF231                  231 */
406         1,    /* JAVA_UNDEF232                  232 */
407         1,    /* JAVA_UNDEF233                  233 */
408         1,    /* JAVA_UNDEF234                  234 */
409         1,    /* JAVA_UNDEF235                  235 */
410         1,    /* JAVA_UNDEF236                  236 */
411         1,    /* JAVA_UNDEF237                  237 */
412         1,    /* JAVA_UNDEF238                  238 */
413         1,    /* JAVA_UNDEF239                  239 */
414         1,    /* JAVA_UNDEF240                  240 */
415         1,    /* JAVA_UNDEF241                  241 */
416         1,    /* JAVA_UNDEF242                  242 */
417         1,    /* JAVA_UNDEF243                  243 */
418         1,    /* JAVA_UNDEF244                  244 */
419         1,    /* JAVA_UNDEF245                  245 */
420         1,    /* JAVA_UNDEF246                  246 */
421         1,    /* JAVA_UNDEF247                  247 */
422         1,    /* JAVA_UNDEF248                  248 */
423         1,    /* JAVA_UNDEF249                  249 */
424         1,    /* JAVA_UNDEF250                  250 */
425         1,    /* JAVA_UNDEF251                  251 */
426         1,    /* JAVA_UNDEF252                  252 */
427         1,    /* JAVA_UNDEF253                  253 */
428         1,    /* JAVA_UNDEF254                  254 */
429         1,    /* JAVA_UNDEF255                  255 */
430 };
431
432
433 /* size in bytes of Java opcodes **********************************************/
434                                 
435 int jcommandsize[256] = {
436
437         1,    /* JAVA_NOP                         0 */
438         1,    /* JAVA_ACONST_NULL                 1 */
439         1,    /* JAVA_ICONST_M1                   2 */
440         1,    /* JAVA_ICONST_0                    3 */
441         1,    /* JAVA_ICONST_1                    4 */
442         1,    /* JAVA_ICONST_2                    5 */
443         1,    /* JAVA_ICONST_3                    6 */
444         1,    /* JAVA_ICONST_4                    7 */
445         1,    /* JAVA_ICONST_5                    8 */
446         1,    /* JAVA_LCONST_0                    9 */
447         1,    /* JAVA_LCONST_1                   10 */
448         1,    /* JAVA_FCONST_0                   11 */
449         1,    /* JAVA_FCONST_1                   12 */
450         1,    /* JAVA_FCONST_2                   13 */
451         1,    /* JAVA_DCONST_0                   14 */
452         1,    /* JAVA_DCONST_1                   15 */
453         2,    /* JAVA_BIPUSH                     16 */
454         3,    /* JAVA_SIPUSH                     17 */
455         2,    /* JAVA_LDC1                       18 */
456         3,    /* JAVA_LDC2                       19 */
457         3,    /* JAVA_LDC2W                      20 */
458         2,    /* JAVA_ILOAD                      21 */
459         2,    /* JAVA_LLOAD                      22 */
460         2,    /* JAVA_FLOAD                      23 */
461         2,    /* JAVA_DLOAD                      24 */
462         2,    /* JAVA_ALOAD                      25 */
463         1,    /* JAVA_ILOAD_0                    26 */
464         1,    /* JAVA_ILOAD_1                    27 */
465         1,    /* JAVA_ILOAD_2                    28 */
466         1,    /* JAVA_ILOAD_3                    29 */
467         1,    /* JAVA_LLOAD_0                    30 */
468         1,    /* JAVA_LLOAD_1                    31 */
469         1,    /* JAVA_LLOAD_2                    32 */
470         1,    /* JAVA_LLOAD_3                    33 */
471         1,    /* JAVA_FLOAD_0                    34 */
472         1,    /* JAVA_FLOAD_1                    35 */
473         1,    /* JAVA_FLOAD_2                    36 */
474         1,    /* JAVA_FLOAD_3                    37 */
475         1,    /* JAVA_DLOAD_0                    38 */
476         1,    /* JAVA_DLOAD_1                    39 */
477         1,    /* JAVA_DLOAD_2                    40 */
478         1,    /* JAVA_DLOAD_3                    41 */
479         1,    /* JAVA_ALOAD_0                    42 */
480         1,    /* JAVA_ALOAD_1                    43 */
481         1,    /* JAVA_ALOAD_2                    44 */
482         1,    /* JAVA_ALOAD_3                    45 */
483         1,    /* JAVA_IALOAD                     46 */
484         1,    /* JAVA_LALOAD                     47 */
485         1,    /* JAVA_FALOAD                     48 */
486         1,    /* JAVA_DALOAD                     49 */
487         1,    /* JAVA_AALOAD                     50 */
488         1,    /* JAVA_BALOAD                     51 */
489         1,    /* JAVA_CALOAD                     52 */
490         1,    /* JAVA_SALOAD                     53 */
491         2,    /* JAVA_ISTORE                     54 */
492         2,    /* JAVA_LSTORE                     55 */
493         2,    /* JAVA_FSTORE                     56 */
494         2,    /* JAVA_DSTORE                     57 */
495         2,    /* JAVA_ASTORE                     58 */
496         1,    /* JAVA_ISTORE_0                   59 */
497         1,    /* JAVA_ISTORE_1                   60 */
498         1,    /* JAVA_ISTORE_2                   61 */
499         1,    /* JAVA_ISTORE_3                   62 */
500         1,    /* JAVA_LSTORE_0                   63 */
501         1,    /* JAVA_LSTORE_1                   64 */
502         1,    /* JAVA_LSTORE_2                   65 */
503         1,    /* JAVA_LSTORE_3                   66 */
504         1,    /* JAVA_FSTORE_0                   67 */
505         1,    /* JAVA_FSTORE_1                   68 */
506         1,    /* JAVA_FSTORE_2                   69 */
507         1,    /* JAVA_FSTORE_3                   70 */
508         1,    /* JAVA_DSTORE_0                   71 */
509         1,    /* JAVA_DSTORE_1                   72 */
510         1,    /* JAVA_DSTORE_2                   73 */
511         1,    /* JAVA_DSTORE_3                   74 */
512         1,    /* JAVA_ASTORE_0                   75 */
513         1,    /* JAVA_ASTORE_1                   76 */
514         1,    /* JAVA_ASTORE_2                   77 */
515         1,    /* JAVA_ASTORE_3                   78 */
516         1,    /* JAVA_IASTORE                    79 */
517         1,    /* JAVA_LASTORE                    80 */
518         1,    /* JAVA_FASTORE                    81 */
519         1,    /* JAVA_DASTORE                    82 */
520         1,    /* JAVA_AASTORE                    83 */
521         1,    /* JAVA_BASTORE                    84 */
522         1,    /* JAVA_CASTORE                    85 */
523         1,    /* JAVA_SASTORE                    86 */
524         1,    /* JAVA_POP                        87 */
525         1,    /* JAVA_POP2                       88 */
526         1,    /* JAVA_DUP                        89 */
527         1,    /* JAVA_DUP_X1                     90 */
528         1,    /* JAVA_DUP_X2                     91 */
529         1,    /* JAVA_DUP2                       92 */
530         1,    /* JAVA_DUP2_X1                    93 */
531         1,    /* JAVA_DUP2_X2                    94 */
532         1,    /* JAVA_SWAP                       95 */
533         1,    /* JAVA_IADD                       96 */
534         1,    /* JAVA_LADD                       97 */
535         1,    /* JAVA_FADD                       98 */
536         1,    /* JAVA_DADD                       99 */
537         1,    /* JAVA_ISUB                      100 */
538         1,    /* JAVA_LSUB                      101 */
539         1,    /* JAVA_FSUB                      102 */
540         1,    /* JAVA_DSUB                      103 */
541         1,    /* JAVA_IMUL                      104 */
542         1,    /* JAVA_LMUL                      105 */
543         1,    /* JAVA_FMUL                      106 */
544         1,    /* JAVA_DMUL                      107 */
545         1,    /* JAVA_IDIV                      108 */
546         1,    /* JAVA_LDIV                      109 */
547         1,    /* JAVA_FDIV                      110 */
548         1,    /* JAVA_DDIV                      111 */
549         1,    /* JAVA_IREM                      112 */
550         1,    /* JAVA_LREM                      113 */
551         1,    /* JAVA_FREM                      114 */
552         1,    /* JAVA_DREM                      115 */
553         1,    /* JAVA_INEG                      116 */
554         1,    /* JAVA_LNEG                      117 */
555         1,    /* JAVA_FNEG                      118 */
556         1,    /* JAVA_DNEG                      119 */
557         1,    /* JAVA_ISHL                      120 */
558         1,    /* JAVA_LSHL                      121 */
559         1,    /* JAVA_ISHR                      122 */
560         1,    /* JAVA_LSHR                      123 */
561         1,    /* JAVA_IUSHR                     124 */
562         1,    /* JAVA_LUSHR                     125 */
563         1,    /* JAVA_IAND                      126 */
564         1,    /* JAVA_LAND                      127 */
565         1,    /* JAVA_IOR                       128 */
566         1,    /* JAVA_LOR                       129 */
567         1,    /* JAVA_IXOR                      130 */
568         1,    /* JAVA_LXOR                      131 */
569         3,    /* JAVA_IINC                      132 */
570         1,    /* JAVA_I2L                       133 */
571         1,    /* JAVA_I2F                       134 */
572         1,    /* JAVA_I2D                       135 */
573         1,    /* JAVA_L2I                       136 */
574         1,    /* JAVA_L2F                       137 */
575         1,    /* JAVA_L2D                       138 */
576         1,    /* JAVA_F2I                       139 */
577         1,    /* JAVA_F2L                       140 */
578         1,    /* JAVA_F2D                       141 */
579         1,    /* JAVA_D2I                       142 */
580         1,    /* JAVA_D2L                       143 */
581         1,    /* JAVA_D2F                       144 */
582         1,    /* JAVA_INT2BYTE                  145 */
583         1,    /* JAVA_INT2CHAR                  146 */
584         1,    /* JAVA_INT2SHORT                 147 */
585         1,    /* JAVA_LCMP                      148 */
586         1,    /* JAVA_FCMPL                     149 */
587         1,    /* JAVA_FCMPG                     150 */
588         1,    /* JAVA_DCMPL                     151 */
589         1,    /* JAVA_DCMPG                     152 */
590         3,    /* JAVA_IFEQ                      153 */
591         3,    /* JAVA_IFNE                      154 */
592         3,    /* JAVA_IFLT                      155 */
593         3,    /* JAVA_IFGE                      156 */
594         3,    /* JAVA_IFGT                      157 */
595         3,    /* JAVA_IFLE                      158 */
596         3,    /* JAVA_IF_ICMPEQ                 159 */
597         3,    /* JAVA_IF_ICMPNE                 160 */
598         3,    /* JAVA_IF_ICMPLT                 161 */
599         3,    /* JAVA_IF_ICMPGE                 162 */
600         3,    /* JAVA_IF_ICMPGT                 163 */
601         3,    /* JAVA_IF_ICMPLE                 164 */
602         3,    /* JAVA_IF_ACMPEQ                 165 */
603         3,    /* JAVA_IF_ACMPNE                 166 */
604         3,    /* JAVA_GOTO                      167 */
605         3,    /* JAVA_JSR                       168 */
606         2,    /* JAVA_RET                       169 */
607         0,    /* JAVA_TABLESWITCH               170 */ /* variable length */
608         0,    /* JAVA_LOOKUPSWITCH              171 */ /* variable length */
609         1,    /* JAVA_IRETURN                   172 */
610         1,    /* JAVA_LRETURN                   173 */
611         1,    /* JAVA_FRETURN                   174 */
612         1,    /* JAVA_DRETURN                   175 */
613         1,    /* JAVA_ARETURN                   176 */
614         1,    /* JAVA_RETURN                    177 */
615         3,    /* JAVA_GETSTATIC                 178 */
616         3,    /* JAVA_PUTSTATIC                 179 */
617         3,    /* JAVA_GETFIELD                  180 */
618         3,    /* JAVA_PUTFIELD                  181 */
619         3,    /* JAVA_INVOKEVIRTUAL             182 */
620         3,    /* JAVA_INVOKESPECIAL             183 */
621         3,    /* JAVA_INVOKESTATIC              184 */
622         5,    /* JAVA_INVOKEINTERFACE           185 */
623         1,    /* UNDEF186 */
624         3,    /* JAVA_NEW                       187 */
625         2,    /* JAVA_NEWARRAY                  188 */
626         3,    /* JAVA_ANEWARRAY                 189 */
627         1,    /* JAVA_ARRAYLENGTH               190 */
628         1,    /* JAVA_ATHROW                    191 */
629         3,    /* JAVA_CHECKCAST                 192 */
630         3,    /* JAVA_INSTANCEOF                193 */
631         1,    /* JAVA_MONITORENTER              194 */
632         1,    /* JAVA_MONITOREXIT               195 */
633         0,    /* JAVA_WIDE                      196 */ /* variable length */
634         4,    /* JAVA_MULTIANEWARRAY            197 */
635         3,    /* JAVA_IFNULL                    198 */
636         3,    /* JAVA_IFNONNULL                 199 */
637         5,    /* JAVA_GOTO_W                    200 */
638         5,    /* JAVA_JSR_W                     201 */
639         1,    /* JAVA_BREAKPOINT                202 */
640
641         1,    /* UNDEF203 */
642         1,
643         1,
644         1,
645         1,
646         1,
647         1,
648         1,    /* UNDEF210 */
649         1,
650         1,
651         1,
652         1,
653         1,
654         1,
655         1,
656         1,
657         1,
658         1,    /* UNDEF220 */
659         1,
660         1,
661         1,
662         1,
663         1,
664         1,
665         1,
666         1,
667         1,
668         1,    /* UNDEF230 */
669         1,
670         1,
671         1,
672         1,
673
674         /* unused */
675                 1,1,1,1,1,1,
676         1,1,1,1,1,1,1,1,1,1,
677         1,1,1,1,1
678 };
679
680
681 /* Java opcode names *********************************************************/
682
683 char *opcode_names[256] = {
684         "NOP            ", /*               0 */
685         "ACONST         ", /*               1 */
686         "ICONST_M1      ", /* ICONST_M1     2 */
687         "ICONST_0       ", /* ICONST_0      3 */
688         "ICONST_1       ", /* ICONST_1      4 */
689         "ICONST_2       ", /* ICONST_2      5 */
690         "ICONST_3       ", /* ICONST_3      6 */
691         "ICONST_4       ", /* ICONST_4      7 */
692         "ICONST_5       ", /* ICONST_5      8 */
693         "LCONST_0       ", /* LCONST_0      9 */
694         "LCONST_1       ", /* LCONST_1     10 */
695         "FCONST_0       ", /* FCONST_0     11 */
696         "FCONST_1       ", /* FCONST_1     12 */
697         "FCONST_2       ", /* FCONST_2     13 */
698         "DCONST_0       ", /* DCONST_0     14 */
699         "DCONST_1       ", /* DCONST_1     15 */
700         "BIPUSH         ", /* BIPUSH       16 */
701         "SIPUSH         ", /* SIPUSH       17 */
702         "LDC            ", /* LDC          18 */
703         "LDC_W          ", /* LDC_W        19 */
704         "LDC2_W         ", /* LDC2_W       20 */
705         "ILOAD          ", /*              21 */
706         "LLOAD          ", /*              22 */
707         "FLOAD          ", /*              23 */
708         "DLOAD          ", /*              24 */
709         "ALOAD          ", /*              25 */
710         "ILOAD_0        ", /* ILOAD_0      26 */
711         "ILOAD_1        ", /* ILOAD_1      27 */
712         "ILOAD_2        ", /* ILOAD_2      28 */
713         "ILOAD_3        ", /* ILOAD_3      29 */
714         "LLOAD_0        ", /* LLOAD_0      30 */
715         "LLOAD_1        ", /* LLOAD_1      31 */
716         "LLOAD_2        ", /* LLOAD_2      32 */
717         "LLOAD_3        ", /* LLOAD_3      33 */
718         "FLOAD_0        ", /* FLOAD_0      34 */
719         "FLOAD_1        ", /* FLOAD_1      35 */
720         "FLOAD_2        ", /* FLOAD_2      36 */
721         "FLOAD_3        ", /* FLOAD_3      37 */
722         "DLOAD_0        ", /* DLOAD_0      38 */
723         "DLOAD_1        ", /* DLOAD_1      39 */
724         "DLOAD_2        ", /* DLOAD_2      40 */ 
725         "DLOAD_3        ", /* DLOAD_3      41 */
726         "ALOAD_0        ", /* ALOAD_0      42 */
727         "ALOAD_1        ", /* ALOAD_1      43 */
728         "ALOAD_2        ", /* ALOAD_2      44 */
729         "ALOAD_3        ", /* ALOAD_3      45 */
730         "IALOAD         ", /*              46 */
731         "LALOAD         ", /*              47 */
732         "FALOAD         ", /*              48 */
733         "DALOAD         ", /*              49 */
734         "AALOAD         ", /*              50 */
735         "BALOAD         ", /*              51 */
736         "CALOAD         ", /*              52 */
737         "SALOAD         ", /*              53 */
738         "ISTORE         ", /*              54 */
739         "LSTORE         ", /*              55 */
740         "FSTORE         ", /*              56 */
741         "DSTORE         ", /*              57 */
742         "ASTORE         ", /*              58 */
743         "ISTORE_0       ", /* ISTORE_0     59 */
744         "ISTORE_1       ", /* ISTORE_1     60 */
745         "ISTORE_2       ", /* ISTORE_2     61 */
746         "ISTORE_3       ", /* ISTORE_3     62 */
747         "LSTORE_0       ", /* LSTORE_0     63 */
748         "LSTORE_1       ", /* LSTORE_1     64 */
749         "LSTORE_2       ", /* LSTORE_2     65 */
750         "LSTORE_3       ", /* LSTORE_3     66 */
751         "FSTORE_0       ", /* FSTORE_0     67 */
752         "FSTORE_1       ", /* FSTORE_1     68 */
753         "FSTORE_2       ", /* FSTORE_2     69 */
754         "FSTORE_3       ", /* FSTORE_3     70 */
755         "DSTORE_0       ", /* DSTORE_0     71 */
756         "DSTORE_1       ", /* DSTORE_1     72 */
757         "DSTORE_2       ", /* DSTORE_2     73 */
758         "DSTORE_3       ", /* DSTORE_3     74 */
759         "ASTORE_0       ", /* ASTORE_0     75 */
760         "ASTORE_1       ", /* ASTORE_1     76 */
761         "ASTORE_2       ", /* ASTORE_2     77 */
762         "ASTORE_3       ", /* ASTORE_3     78 */
763         "IASTORE        ", /*              79 */
764         "LASTORE        ", /*              80 */
765         "FASTORE        ", /*              81 */
766         "DASTORE        ", /*              82 */
767         "AASTORE        ", /*              83 */
768         "BASTORE        ", /*              84 */
769         "CASTORE        ", /*              85 */
770         "SASTORE        ", /*              86 */
771         "POP            ", /*              87 */
772         "POP2           ", /*              88 */
773         "DUP            ", /*              89 */
774         "DUP_X1         ", /*              90 */
775         "DUP_X2         ", /*              91 */
776         "DUP2           ", /*              92 */
777         "DUP2_X1        ", /*              93 */
778         "DUP2_X2        ", /*              94 */
779         "SWAP           ", /*              95 */
780         "IADD           ", /*              96 */
781         "LADD           ", /*              97 */
782         "FADD           ", /*              98 */
783         "DADD           ", /*              99 */
784         "ISUB           ", /*             100 */
785         "LSUB           ", /*             101 */
786         "FSUB           ", /*             102 */
787         "DSUB           ", /*             103 */
788         "IMUL           ", /*             104 */
789         "LMUL           ", /*             105 */
790         "FMUL           ", /*             106 */
791         "DMUL           ", /*             107 */
792         "IDIV           ", /*             108 */
793         "LDIV           ", /*             109 */
794         "FDIV           ", /*             110 */
795         "DDIV           ", /*             111 */
796         "IREM           ", /*             112 */
797         "LREM           ", /*             113 */
798         "FREM           ", /*             114 */
799         "DREM           ", /*             115 */
800         "INEG           ", /*             116 */
801         "LNEG           ", /*             117 */
802         "FNEG           ", /*             118 */
803         "DNEG           ", /*             119 */
804         "ISHL           ", /*             120 */
805         "LSHL           ", /*             121 */
806         "ISHR           ", /*             122 */
807         "LSHR           ", /*             123 */
808         "IUSHR          ", /*             124 */
809         "LUSHR          ", /*             125 */
810         "IAND           ", /*             126 */
811         "LAND           ", /*             127 */
812         "IOR            ", /*             128 */
813         "LOR            ", /*             129 */
814         "IXOR           ", /*             130 */
815         "LXOR           ", /*             131 */
816         "IINC           ", /*             132 */
817         "I2L            ", /*             133 */
818         "I2F            ", /*             134 */
819         "I2D            ", /*             135 */
820         "L2I            ", /*             136 */
821         "L2F            ", /*             137 */
822         "L2D            ", /*             138 */
823         "F2I            ", /*             139 */
824         "F2L            ", /*             140 */
825         "F2D            ", /*             141 */
826         "D2I            ", /*             142 */
827         "D2L            ", /*             143 */
828         "D2F            ", /*             144 */
829         "INT2BYTE       ", /*             145 */
830         "INT2CHAR       ", /*             146 */
831         "INT2SHORT      ", /*             147 */
832         "LCMP           ", /*             148 */
833         "FCMPL          ", /*             149 */
834         "FCMPG          ", /*             150 */
835         "DCMPL          ", /*             151 */
836         "DCMPG          ", /*             152 */
837         "IFEQ           ", /*             153 */
838         "IFNE           ", /*             154 */
839         "IFLT           ", /*             155 */
840         "IFGE           ", /*             156 */
841         "IFGT           ", /*             157 */
842         "IFLE           ", /*             158 */
843         "IF_ICMPEQ      ", /*             159 */
844         "IF_ICMPNE      ", /*             160 */
845         "IF_ICMPLT      ", /*             161 */
846         "IF_ICMPGE      ", /*             162 */
847         "IF_ICMPGT      ", /*             163 */
848         "IF_ICMPLE      ", /*             164 */
849         "IF_ACMPEQ      ", /*             165 */
850         "IF_ACMPNE      ", /*             166 */
851         "GOTO           ", /*             167 */
852         "JSR            ", /*             168 */
853         "RET            ", /*             169 */
854         "TABLESWITCH    ", /*             170 */
855         "LOOKUPSWITCH   ", /*             171 */
856         "IRETURN        ", /*             172 */
857         "LRETURN        ", /*             173 */
858         "FRETURN        ", /*             174 */
859         "DRETURN        ", /*             175 */
860         "ARETURN        ", /*             176 */
861         "RETURN         ", /*             177 */
862         "GETSTATIC      ", /*             178 */
863         "PUTSTATIC      ", /*             179 */
864         "GETFIELD       ", /*             180 */
865         "PUTFIELD       ", /*             181 */
866         "INVOKEVIRTUAL  ", /*             182 */
867         "INVOKESPECIAL  ", /*             183 */
868         "INVOKESTATIC   ", /*             184 */
869         "INVOKEINTERFACE", /*             185 */
870         "UNDEF186       ", /*             186 */
871         "NEW            ", /*             187 */
872         "NEWARRAY       ", /*             188 */
873         "ANEWARRAY      ", /*             189 */
874         "ARRAYLENGTH    ", /*             190 */
875         "ATHROW         ", /*             191 */
876         "CHECKCAST      ", /*             192 */
877         "INSTANCEOF     ", /*             193 */
878         "MONITORENTER   ", /*             194 */
879         "MONITOREXIT    ", /*             195 */
880         "WIDE           ", /* WIDE        196 */
881         "MULTIANEWARRAY ", /*             197 */
882         "IFNULL         ", /*             198 */
883         "IFNONNULL      ", /*             199 */
884         "GOTO_W         ", /* GOTO_W      200 */
885         "JSR_W          ", /* JSR_W       201 */
886         "BREAKPOINT     ", /* BREAKPOINT  202 */
887
888                                 "UNDEF203", "UNDEF204", "UNDEF205",
889         "UNDEF206", "UNDEF207", "UNDEF208", "UNDEF209", "UNDEF210",
890         "UNDEF211", "UNDEF212", "UNDEF213", "UNDEF214", "UNDEF215",
891         "UNDEF216", "UNDEF217", "UNDEF218", "UNDEF219", "UNDEF220",
892         "UNDEF221", "UNDEF222", "UNDEF223", "UNDEF224", "UNDEF225",
893         "UNDEF226", "UNDEF227", "UNDEF228", "UNDEF229", "UNDEF230",
894         "UNDEF231", "UNDEF232", "UNDEF233", "UNDEF234", "UNDEF235",
895         "UNDEF236", "UNDEF237", "UNDEF238", "UNDEF239", "UNDEF240",
896         "UNDEF241", "UNDEF242", "UNDEF243", "UNDEF244", "UNDEF245",
897         "UNDEF246", "UNDEF247", "UNDEF248", "UNDEF249", "UNDEF250",
898         "UNDEF251", "UNDEF252", "UNDEF253", "UNDEF254", "UNDEF255"
899 };
900
901
902 /* jit_init ********************************************************************
903
904    Initializes the JIT subsystem.
905
906 *******************************************************************************/
907
908 void jit_init(void)
909 {
910 #if defined(ENABLE_JIT)
911         /* initialize stack analysis subsystem */
912
913         (void) stack_init();
914 #endif
915
916         /* initialize show subsystem */
917
918 #if !defined(NDEBUG)
919         (void) show_init();
920 #endif
921
922         /* initialize codegen subsystem */
923
924         codegen_init();
925
926         /* initialize code subsystem */
927
928         (void) code_init();
929
930         /* Machine dependent initialization. */
931
932 #if defined(ENABLE_JIT)
933 # if defined(ENABLE_INTRP)
934         if (opt_intrp)
935                 intrp_md_init();
936         else
937 # endif
938                 md_init();
939 #else
940         intrp_md_init();
941 #endif
942 }
943
944
945 /* jit_close *******************************************************************
946
947    Close the JIT subsystem.
948
949 *******************************************************************************/
950
951 void jit_close(void)
952 {
953         /* do nothing */
954 }
955
956
957 /* dummy function, used when there is no JavaVM code available                */
958
959 static u1 *do_nothing_function(void)
960 {
961         return NULL;
962 }
963
964
965 /* jit_jitdata_new *************************************************************
966
967    Allocates and initalizes a new jitdata structure.
968
969 *******************************************************************************/
970
971 jitdata *jit_jitdata_new(methodinfo *m)
972 {
973         jitdata  *jd;
974         codeinfo *code;
975
976         /* allocate jitdata structure and fill it */
977
978         jd = DNEW(jitdata);
979
980         jd->m     = m;
981         jd->cd    = DNEW(codegendata);
982         jd->rd    = DNEW(registerdata);
983 #if defined(ENABLE_LOOP)
984         jd->ld    = DNEW(loopdata);
985 #endif
986
987         /* Allocate codeinfo memory from the heap as we need to keep them. */
988
989         code = code_codeinfo_new(m);
990
991         /* Set codeinfo flags. */
992
993 #if defined(ENABLE_THREADS)
994         if (checksync && (m->flags & ACC_SYNCHRONIZED))
995                 code_flag_synchronized(code);
996
997         if (checksync && (m->flags & ACC_SYNCHRONIZED))
998                 code_unflag_leafmethod(code);
999         else
1000 #endif
1001                 code_flag_leafmethod(code);
1002
1003         /* initialize variables */
1004
1005         jd->code                 = code;
1006         jd->flags                = 0;
1007         jd->exceptiontable       = NULL;
1008         jd->exceptiontablelength = 0;
1009         jd->returncount          = 0;
1010         jd->branchtoentry        = false;
1011         jd->branchtoend          = false;
1012         jd->returncount          = 0;
1013         jd->returnblock          = NULL;
1014         jd->maxlocals            = m->maxlocals;
1015
1016         return jd;
1017 }
1018
1019
1020 /* jit_compile *****************************************************************
1021
1022    Translates one method to machine code.
1023
1024 *******************************************************************************/
1025
1026 static u1 *jit_compile_intern(jitdata *jd);
1027
1028 u1 *jit_compile(methodinfo *m)
1029 {
1030         u1      *r;
1031         jitdata *jd;
1032         int32_t  dumpmarker;
1033
1034         STATISTICS(count_jit_calls++);
1035
1036         /* Initialize the static function's class. */
1037
1038         /* ATTENTION: This MUST be done before the method lock is aquired,
1039            otherwise we could run into a deadlock with <clinit>'s that
1040            call static methods of it's own class. */
1041
1042         if ((m->flags & ACC_STATIC) && !(m->class->state & CLASS_INITIALIZED)) {
1043 #if !defined(NDEBUG)
1044                 if (initverbose)
1045                         log_message_class("Initialize class ", m->class);
1046 #endif
1047
1048                 if (!initialize_class(m->class))
1049                         return NULL;
1050
1051                 /* check if the method has been compiled during initialization */
1052
1053                 if ((m->code != NULL) && (m->code->entrypoint != NULL))
1054                         return m->code->entrypoint;
1055         }
1056
1057         /* enter a monitor on the method */
1058
1059         LOCK_MONITOR_ENTER(m);
1060
1061         /* if method has been already compiled return immediately */
1062
1063         if (m->code != NULL) {
1064                 LOCK_MONITOR_EXIT(m);
1065
1066                 assert(m->code->entrypoint);
1067                 return m->code->entrypoint;
1068         }
1069
1070         TRACECOMPILERCALLS();
1071
1072         STATISTICS(count_methods++);
1073
1074 #if defined(ENABLE_STATISTICS)
1075         /* measure time */
1076
1077         if (opt_getcompilingtime)
1078                 compilingtime_start();
1079 #endif
1080
1081         /* mark start of dump memory area */
1082
1083         DMARKER;
1084
1085         /* create jitdata structure */
1086
1087         jd = jit_jitdata_new(m);
1088
1089         /* set the flags for the current JIT run */
1090
1091         jd->flags = JITDATA_FLAG_PARSE;
1092
1093 #if defined(ENABLE_VERIFIER)
1094         if (opt_verify)
1095                 jd->flags |= JITDATA_FLAG_VERIFY;
1096 #endif
1097
1098 #if defined(ENABLE_PROFILING)
1099         if (opt_prof)
1100                 jd->flags |= JITDATA_FLAG_INSTRUMENT;
1101 #endif
1102
1103 #if defined(ENABLE_IFCONV)
1104         if (opt_ifconv)
1105                 jd->flags |= JITDATA_FLAG_IFCONV;
1106 #endif
1107
1108 #if defined(ENABLE_INLINING) && defined(ENABLE_INLINING_DEBUG)
1109         if (opt_inlining && opt_inline_debug_all)
1110                 jd->flags |= JITDATA_FLAG_INLINE;
1111 #endif
1112
1113         if (opt_showintermediate)
1114                 jd->flags |= JITDATA_FLAG_SHOWINTERMEDIATE;
1115
1116         if (opt_showdisassemble)
1117                 jd->flags |= JITDATA_FLAG_SHOWDISASSEMBLE;
1118
1119         if (opt_verbosecall)
1120                 jd->flags |= JITDATA_FLAG_VERBOSECALL;
1121
1122 #if defined(ENABLE_REPLACEMENT) && defined(ENABLE_INLINING)
1123         if (opt_inlining)
1124                 jd->flags |= JITDATA_FLAG_COUNTDOWN;
1125 #endif
1126
1127 #if defined(ENABLE_JIT)
1128 # if defined(ENABLE_INTRP)
1129         if (!opt_intrp)
1130 # endif
1131                 /* initialize the register allocator */
1132         {
1133                 reg_setup(jd);
1134         }
1135 #endif
1136
1137         /* setup the codegendata memory */
1138
1139         codegen_setup(jd);
1140
1141         /* now call internal compile function */
1142
1143         r = jit_compile_intern(jd);
1144
1145         if (r == NULL) {
1146                 /* We had an exception! Finish stuff here if necessary. */
1147
1148                 /* release codeinfo */
1149
1150                 code_codeinfo_free(jd->code);
1151
1152 #if defined(ENABLE_PROFILING)
1153                 /* Release memory for basic block profiling information. */
1154
1155                 if (JITDATA_HAS_FLAG_INSTRUMENT(jd))
1156                         if (jd->code->bbfrequency != NULL)
1157                                 MFREE(jd->code->bbfrequency, u4, jd->code->basicblockcount);
1158 #endif
1159         }
1160         else {
1161                 DEBUG_JIT_COMPILEVERBOSE("Running: ");
1162         }
1163
1164         /* release dump area */
1165
1166         DRELEASE;
1167
1168 #if defined(ENABLE_STATISTICS)
1169         /* measure time */
1170
1171         if (opt_getcompilingtime)
1172                 compilingtime_stop();
1173 #endif
1174
1175         /* leave the monitor */
1176
1177         LOCK_MONITOR_EXIT(m);
1178
1179         /* return pointer to the methods entry point */
1180
1181         return r;
1182 }
1183
1184
1185 /* jit_recompile ***************************************************************
1186
1187    Recompiles a Java method.
1188
1189 *******************************************************************************/
1190
1191 u1 *jit_recompile(methodinfo *m)
1192 {
1193         u1      *r;
1194         jitdata *jd;
1195         u1       optlevel;
1196         int32_t  dumpmarker;
1197
1198         /* check for max. optimization level */
1199
1200         optlevel = (m->code) ? m->code->optlevel : 0;
1201
1202 #if 0
1203         if (optlevel == 1) {
1204 /*              log_message_method("not recompiling: ", m); */
1205                 return NULL;
1206         }
1207 #endif
1208
1209         DEBUG_JIT_COMPILEVERBOSE("Recompiling start: ");
1210
1211         STATISTICS(count_jit_calls++);
1212
1213 #if defined(ENABLE_STATISTICS)
1214         /* measure time */
1215
1216         if (opt_getcompilingtime)
1217                 compilingtime_start();
1218 #endif
1219
1220         /* mark start of dump memory area */
1221
1222         DMARKER;
1223
1224         /* create jitdata structure */
1225
1226         jd = jit_jitdata_new(m);
1227
1228         /* set the current optimization level to the previous one plus 1 */
1229
1230         jd->code->optlevel = optlevel + 1;
1231
1232         /* get the optimization flags for the current JIT run */
1233
1234 #if defined(ENABLE_VERIFIER)
1235         jd->flags |= JITDATA_FLAG_VERIFY;
1236 #endif
1237
1238         /* jd->flags |= JITDATA_FLAG_REORDER; */
1239         if (opt_showintermediate)
1240                 jd->flags |= JITDATA_FLAG_SHOWINTERMEDIATE;
1241         if (opt_showdisassemble)
1242                 jd->flags |= JITDATA_FLAG_SHOWDISASSEMBLE;
1243         if (opt_verbosecall)
1244                 jd->flags |= JITDATA_FLAG_VERBOSECALL;
1245
1246 #if defined(ENABLE_INLINING)
1247         if (opt_inlining)
1248                 jd->flags |= JITDATA_FLAG_INLINE;
1249 #endif
1250
1251 #if defined(ENABLE_JIT)
1252 # if defined(ENABLE_INTRP)
1253         if (!opt_intrp)
1254 # endif
1255                 /* initialize the register allocator */
1256
1257                 reg_setup(jd);
1258 #endif
1259
1260         /* setup the codegendata memory */
1261
1262         codegen_setup(jd);
1263
1264         /* now call internal compile function */
1265
1266         r = jit_compile_intern(jd);
1267
1268         if (r == NULL) {
1269                 /* We had an exception! Finish stuff here if necessary. */
1270
1271                 /* release codeinfo */
1272
1273                 code_codeinfo_free(jd->code);
1274         }
1275
1276         /* release dump area */
1277
1278         DRELEASE;
1279
1280 #if defined(ENABLE_STATISTICS)
1281         /* measure time */
1282
1283         if (opt_getcompilingtime)
1284                 compilingtime_stop();
1285 #endif
1286
1287         DEBUG_JIT_COMPILEVERBOSE("Recompiling done: ");
1288
1289         /* return pointer to the methods entry point */
1290
1291         return r;
1292 }
1293
1294
1295 /* jit_compile_intern **********************************************************
1296
1297    Static internal function which does the actual compilation.
1298
1299 *******************************************************************************/
1300
1301 static u1 *jit_compile_intern(jitdata *jd)
1302 {
1303         methodinfo  *m;
1304         codegendata *cd;
1305         codeinfo    *code;
1306
1307 #if defined(ENABLE_RT_TIMING)
1308         struct timespec time_start,time_checks,time_parse,time_stack,
1309                                         time_typecheck,time_loop,time_ifconv,time_alloc,
1310                                         time_codegen;
1311 #endif
1312         
1313         RT_TIMING_GET_TIME(time_start);
1314
1315         /* get required compiler data */
1316
1317 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1318         jd->ls = NULL;
1319 #endif
1320         m    = jd->m;
1321         code = jd->code;
1322         cd   = jd->cd;
1323         
1324 #if defined(ENABLE_DEBUG_FILTER)
1325         show_filters_apply(jd->m);
1326 #endif
1327
1328         /* Handle native methods and create a native stub. */
1329
1330         if (m->flags & ACC_NATIVE) {
1331                 functionptr f;
1332
1333                 f = native_method_resolve(m);
1334
1335                 if (f == NULL)
1336                         return NULL;
1337
1338                 code = codegen_generate_stub_native(m, f);
1339
1340                 /* Native methods are never recompiled. */
1341                 
1342                 assert(!m->code);
1343
1344                 m->code = code;
1345                 
1346                 return code->entrypoint;
1347         }
1348
1349         /* if there is no javacode, print error message and return empty method   */
1350
1351         if (m->jcode == NULL) {
1352                 DEBUG_JIT_COMPILEVERBOSE("No code given for: ");
1353
1354                 code->entrypoint = (u1 *) (ptrint) do_nothing_function;
1355                 m->code = code;
1356
1357                 return code->entrypoint;        /* return empty method                */
1358         }
1359
1360 #if defined(ENABLE_STATISTICS)
1361         if (opt_stat) {
1362                 count_javacodesize += m->jcodelength + 18;
1363                 count_tryblocks    += jd->exceptiontablelength;
1364                 count_javaexcsize  += jd->exceptiontablelength * SIZEOF_VOID_P;
1365         }
1366 #endif
1367
1368         RT_TIMING_GET_TIME(time_checks);
1369
1370 #if defined(WITH_CLASSPATH_SUN)
1371         /* Code for Sun's OpenJDK (see
1372            hotspot/src/share/vm/classfile/verifier.cpp
1373            (Verifier::is_eligible_for_verification)): Don't verify
1374            dynamically-generated bytecodes. */
1375
1376 # if defined(ENABLE_VERIFIER)
1377         if (class_issubclass(m->class, class_sun_reflect_MagicAccessorImpl))
1378                 jd->flags &= ~JITDATA_FLAG_VERIFY;
1379 # endif
1380 #endif
1381
1382         /* call the compiler passes ***********************************************/
1383
1384         DEBUG_JIT_COMPILEVERBOSE("Parsing: ");
1385
1386         /* call parse pass */
1387
1388         if (!parse(jd)) {
1389                 DEBUG_JIT_COMPILEVERBOSE("Exception while parsing: ");
1390
1391                 return NULL;
1392         }
1393         RT_TIMING_GET_TIME(time_parse);
1394
1395         DEBUG_JIT_COMPILEVERBOSE("Parsing done: ");
1396         
1397 #if defined(ENABLE_JIT)
1398 # if defined(ENABLE_INTRP)
1399         if (!opt_intrp) {
1400 # endif
1401                 DEBUG_JIT_COMPILEVERBOSE("Analysing: ");
1402
1403                 /* call stack analysis pass */
1404
1405                 if (!stack_analyse(jd)) {
1406                         DEBUG_JIT_COMPILEVERBOSE("Exception while analysing: ");
1407
1408                         return NULL;
1409                 }
1410                 RT_TIMING_GET_TIME(time_stack);
1411
1412                 DEBUG_JIT_COMPILEVERBOSE("Analysing done: ");
1413
1414                 /* Build the CFG.  This has to be done after stack_analyse, as
1415                    there happens the JSR elimination. */
1416
1417                 if (!cfg_build(jd))
1418                         return NULL;
1419
1420 #ifdef ENABLE_VERIFIER
1421                 if (JITDATA_HAS_FLAG_VERIFY(jd)) {
1422                         DEBUG_JIT_COMPILEVERBOSE("Typechecking: ");
1423
1424                         /* call typecheck pass */
1425                         if (!typecheck(jd)) {
1426                                 DEBUG_JIT_COMPILEVERBOSE("Exception while typechecking: ");
1427
1428                                 return NULL;
1429                         }
1430
1431                         DEBUG_JIT_COMPILEVERBOSE("Typechecking done: ");
1432                 }
1433 #endif
1434                 RT_TIMING_GET_TIME(time_typecheck);
1435
1436 #if defined(ENABLE_LOOP)
1437                 if (opt_loops) {
1438                         depthFirst(jd);
1439                         analyseGraph(jd);
1440                         optimize_loops(jd);
1441                         jit_renumber_basicblocks(jd);
1442                 }
1443 #endif
1444                 RT_TIMING_GET_TIME(time_loop);
1445
1446 #if defined(ENABLE_IFCONV)
1447                 if (JITDATA_HAS_FLAG_IFCONV(jd)) {
1448                         if (!ifconv_static(jd))
1449                                 return NULL;
1450                         jit_renumber_basicblocks(jd);
1451                 }
1452 #endif
1453                 RT_TIMING_GET_TIME(time_ifconv);
1454
1455                 /* inlining */
1456
1457 #if defined(ENABLE_INLINING)
1458                 if (JITDATA_HAS_FLAG_INLINE(jd)) {
1459                         if (!inline_inline(jd))
1460                                 return NULL;
1461                 }
1462 #endif
1463
1464 #if defined(ENABLE_PYTHON)
1465                 if (!pythonpass_run(jd, "langauer_tarjan", "main")) {
1466                         /*return NULL;*/
1467                 }
1468 #endif
1469
1470 #if defined(ENABLE_PROFILING)
1471                 /* Basic block reordering.  I think this should be done after
1472                    if-conversion, as we could lose the ability to do the
1473                    if-conversion. */
1474
1475                 if (JITDATA_HAS_FLAG_REORDER(jd)) {
1476                         if (!reorder(jd))
1477                                 return NULL;
1478                         jit_renumber_basicblocks(jd);
1479                 }
1480 #endif
1481
1482                 DEBUG_JIT_COMPILEVERBOSE("Allocating registers: ");
1483
1484 #if defined(ENABLE_LSRA) && !defined(ENABLE_SSA)
1485                 /* allocate registers */
1486                 if (opt_lsra) {
1487                         if (!lsra(jd))
1488                                 return NULL;
1489
1490                         STATISTICS(count_methods_allocated_by_lsra++);
1491
1492                 } else
1493 # endif /* defined(ENABLE_LSRA) && !defined(ENABLE_SSA) */
1494 #if defined(ENABLE_SSA)
1495                 /* allocate registers */
1496                 if ((opt_lsra) && (jd->exceptiontablelength == 0)) {
1497                         jd->ls = DNEW(lsradata);
1498                         ssa(jd);
1499                         lsra(jd);
1500
1501                         STATISTICS(count_methods_allocated_by_lsra++);
1502
1503                 } else
1504 # endif /* defined(ENABLE_SSA) */
1505                 {
1506                         STATISTICS(count_locals_conflicts += (jd->maxlocals - 1) * (jd->maxlocals));
1507
1508                         regalloc(jd);
1509                 }
1510
1511                 STATISTICS(simplereg_make_statistics(jd));
1512
1513                 DEBUG_JIT_COMPILEVERBOSE("Allocating registers done: ");
1514 # if defined(ENABLE_INTRP)
1515         }
1516 # endif
1517 #endif /* defined(ENABLE_JIT) */
1518         RT_TIMING_GET_TIME(time_alloc);
1519
1520 #if defined(ENABLE_PROFILING)
1521         /* Allocate memory for basic block profiling information. This
1522            _must_ be done after loop optimization and register allocation,
1523            since they can change the basic block count. */
1524
1525         if (JITDATA_HAS_FLAG_INSTRUMENT(jd))
1526                 code->bbfrequency = MNEW(u4, jd->basicblockcount);
1527 #endif
1528
1529         DEBUG_JIT_COMPILEVERBOSE("Generating code: ");
1530
1531         /* now generate the machine code */
1532
1533 #if defined(ENABLE_JIT)
1534 # if defined(ENABLE_INTRP)
1535         if (opt_intrp) {
1536 #if defined(ENABLE_VERIFIER)
1537                 if (opt_verify) {
1538                         DEBUG_JIT_COMPILEVERBOSE("Typechecking (stackbased): ");
1539
1540                         if (!typecheck_stackbased(jd)) {
1541                                 DEBUG_JIT_COMPILEVERBOSE("Exception while typechecking (stackbased): ");
1542                                 return NULL;
1543                         }
1544                 }
1545 #endif
1546                 if (!intrp_codegen(jd)) {
1547                         DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1548
1549                         return NULL;
1550                 }
1551         } else
1552 # endif
1553                 {
1554                         if (!codegen_generate(jd)) {
1555                                 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1556
1557                                 return NULL;
1558                         }
1559                 }
1560 #else
1561         if (!intrp_codegen(jd)) {
1562                 DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
1563
1564                 return NULL;
1565         }
1566 #endif
1567         RT_TIMING_GET_TIME(time_codegen);
1568
1569         DEBUG_JIT_COMPILEVERBOSE("Generating code done: ");
1570
1571 #if !defined(NDEBUG) && defined(ENABLE_REPLACEMENT)
1572         /* activate replacement points inside newly created code */
1573
1574         if (opt_TestReplacement)
1575                 replace_activate_replacement_points(code, false);
1576 #endif
1577
1578 #if !defined(NDEBUG)
1579 #if defined(ENABLE_DEBUG_FILTER)
1580         if (jd->m->filtermatches & SHOW_FILTER_FLAG_SHOW_METHOD)
1581 #endif
1582         {
1583                 /* intermediate and assembly code listings */
1584                 
1585                 if (JITDATA_HAS_FLAG_SHOWINTERMEDIATE(jd)) {
1586                         show_method(jd, SHOW_CODE);
1587                 }
1588                 else if (JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd)) {
1589 # if defined(ENABLE_DISASSEMBLER)
1590                         DISASSEMBLE(code->entrypoint,
1591                                                 code->entrypoint + (code->mcodelength - cd->dseglen));
1592 # endif
1593                 }
1594
1595                 if (opt_showddatasegment)
1596                         dseg_display(jd);
1597         }
1598 #endif
1599
1600         /* switch to the newly generated code */
1601
1602         assert(code);
1603         assert(code->entrypoint);
1604
1605         /* add the current compile version to the methodinfo */
1606
1607         code->prev = m->code;
1608         m->code = code;
1609
1610         RT_TIMING_TIME_DIFF(time_start,time_checks,RT_TIMING_JIT_CHECKS);
1611         RT_TIMING_TIME_DIFF(time_checks,time_parse,RT_TIMING_JIT_PARSE);
1612         RT_TIMING_TIME_DIFF(time_parse,time_stack,RT_TIMING_JIT_STACK);
1613         RT_TIMING_TIME_DIFF(time_stack,time_typecheck,RT_TIMING_JIT_TYPECHECK);
1614         RT_TIMING_TIME_DIFF(time_typecheck,time_loop,RT_TIMING_JIT_LOOP);
1615         RT_TIMING_TIME_DIFF(time_loop,time_alloc,RT_TIMING_JIT_ALLOC);
1616         RT_TIMING_TIME_DIFF(time_alloc,time_codegen,RT_TIMING_JIT_CODEGEN);
1617         RT_TIMING_TIME_DIFF(time_start,time_codegen,RT_TIMING_JIT_TOTAL);
1618
1619         /* return pointer to the methods entry point */
1620
1621         return code->entrypoint;
1622
1623
1624
1625 /* jit_invalidate_code *********************************************************
1626
1627    Mark the compiled code of the given method as invalid and take care that
1628    it is replaced if necessary.
1629
1630    XXX Not fully implemented, yet.
1631
1632 *******************************************************************************/
1633
1634 void jit_invalidate_code(methodinfo *m)
1635 {
1636         codeinfo *code;
1637
1638         code = m->code;
1639
1640         if (code == NULL || code_is_invalid(code))
1641                 return;
1642
1643         code_flag_invalid(code);
1644
1645         /* activate mappable replacement points */
1646
1647 #if defined(ENABLE_REPLACEMENT)
1648         replace_activate_replacement_points(code, true);
1649 #else
1650         vm_abort("invalidating code only works with ENABLE_REPLACEMENT");
1651 #endif
1652 }
1653
1654
1655 /* jit_request_optimization ****************************************************
1656
1657    Request optimization of the given method. If the code of the method is
1658    unoptimized, it will be invalidated, so the next jit_get_current_code(m)
1659    triggers an optimized recompilation.
1660    If the method is already optimized, this function does nothing.
1661
1662    IN:
1663        m................the method
1664
1665 *******************************************************************************/
1666
1667 void jit_request_optimization(methodinfo *m)
1668 {
1669         codeinfo *code;
1670
1671         code = m->code;
1672
1673         if (code && code->optlevel == 0)
1674                 jit_invalidate_code(m);
1675 }
1676
1677
1678 /* jit_get_current_code ********************************************************
1679
1680    Get the currently valid code for the given method. If there is no valid
1681    code, (re)compile the method.
1682
1683    IN:
1684        m................the method
1685
1686    RETURN VALUE:
1687        the codeinfo* for the current code, or
1688            NULL if an exception has been thrown during recompilation.
1689
1690 *******************************************************************************/
1691
1692 codeinfo *jit_get_current_code(methodinfo *m)
1693 {
1694         assert(m);
1695
1696         /* if we have valid code, return it */
1697
1698         if (m->code && !code_is_invalid(m->code))
1699                 return m->code;
1700
1701         /* otherwise: recompile */
1702
1703         if (!jit_recompile(m))
1704                 return NULL;
1705
1706         assert(m->code);
1707
1708         return m->code;
1709 }
1710
1711
1712 /* jit_asm_compile *************************************************************
1713
1714    This method is called from asm_vm_call_method and does:
1715
1716      - create stackframe info for exceptions
1717      - compile the method
1718      - patch the entrypoint of the method into the calculated address in
1719        the JIT code
1720      - flushes the instruction cache.
1721
1722 *******************************************************************************/
1723
1724 #if defined(ENABLE_JIT)
1725 #if !defined(JIT_COMPILER_VIA_SIGNAL)
1726 u1 *jit_asm_compile(methodinfo *m, u1 *mptr, u1 *sp, u1 *ra)
1727 {
1728         stackframeinfo_t  sfi;
1729         u1               *entrypoint;
1730         u1               *pa;
1731         ptrint           *p;
1732
1733         /* create the stackframeinfo (subtract 1 from RA as it points to the */
1734         /* instruction after the call)                                       */
1735
1736         stacktrace_stackframeinfo_add(&sfi, NULL, sp, ra, ra-1);
1737
1738         /* actually compile the method */
1739
1740         entrypoint = jit_compile(m);
1741
1742         /* remove the stackframeinfo */
1743
1744         stacktrace_stackframeinfo_remove(&sfi);
1745
1746         /* there was a problem during compilation */
1747
1748         if (entrypoint == NULL)
1749                 return NULL;
1750
1751         /* get the method patch address */
1752
1753         pa = md_jit_method_patch_address(sfi.pv, (void *) ra, mptr);
1754
1755         /* patch the method entry point */
1756
1757         p = (ptrint *) pa;
1758
1759         *p = (ptrint) entrypoint;
1760
1761         /* flush the instruction cache */
1762
1763         md_icacheflush(pa, SIZEOF_VOID_P);
1764
1765         return entrypoint;
1766 }
1767 #endif
1768
1769 /* jit_compile_handle **********************************************************
1770
1771    This method is called from the appropriate signal handler which
1772    handles compiler-traps and does the following:
1773
1774      - compile the method
1775      - patch the entrypoint of the method into the calculated address in
1776        the JIT code
1777      - flush the instruction cache
1778
1779 *******************************************************************************/
1780
1781 void *jit_compile_handle(methodinfo *m, void *pv, void *ra, void *mptr)
1782 {
1783         void      *newpv;                               /* new compiled method PV */
1784         void      *pa;                                           /* patch address */
1785         uintptr_t *p;                                      /* convenience pointer */
1786
1787         /* Compile the method. */
1788
1789         newpv = jit_compile(m);
1790
1791         /* There was a problem during compilation. */
1792
1793         if (newpv == NULL)
1794                 return NULL;
1795
1796         /* Get the method patch address. */
1797
1798         pa = md_jit_method_patch_address(pv, ra, mptr);
1799
1800         /* Patch the method entry point. */
1801
1802         p = (uintptr_t *) pa;
1803
1804         *p = (uintptr_t) newpv;
1805
1806         /* Flush both caches. */
1807
1808         md_cacheflush(pa, SIZEOF_VOID_P);
1809
1810         return newpv;
1811 }
1812 #endif /* defined(ENABLE_JIT) */
1813
1814
1815 /* jit_complement_condition ****************************************************
1816
1817    Returns the complement of the passed conditional instruction.
1818
1819    We use the order of the different conditions, e.g.:
1820
1821    ICMD_IFEQ         153
1822    ICMD_IFNE         154
1823
1824    If the passed opcode is odd, we simply add 1 to get the complement.
1825    If the opcode is even, we subtract 1.
1826
1827    Exception:
1828
1829    ICMD_IFNULL       198
1830    ICMD_IFNONNULL    199
1831
1832 *******************************************************************************/
1833
1834 s4 jit_complement_condition(s4 opcode)
1835 {
1836         switch (opcode) {
1837         case ICMD_IFNULL:
1838                 return ICMD_IFNONNULL;
1839
1840         case ICMD_IFNONNULL:
1841                 return ICMD_IFNULL;
1842
1843         default:
1844                 /* check if opcode is odd */
1845
1846                 if (opcode & 0x1)
1847                         return opcode + 1;
1848                 else
1849                         return opcode - 1;
1850         }
1851 }
1852
1853
1854 /* jit_renumber_basicblocks ****************************************************
1855
1856    Set the ->nr of all blocks so it increases when traversing ->next.
1857
1858    IN:
1859        jitdata..........the current jitdata
1860
1861 *******************************************************************************/
1862
1863 void jit_renumber_basicblocks(jitdata *jd)
1864 {
1865         s4          nr;
1866         basicblock *bptr;
1867
1868         nr = 0;
1869         for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
1870                 bptr->nr = nr++;
1871         }
1872
1873         /* we have one block more than jd->basicblockcount (the end marker) */
1874
1875         assert(nr == jd->basicblockcount + 1);
1876 }
1877
1878
1879 /* jit_check_basicblock_numbers ************************************************
1880
1881    Assert that the ->nr of the first block is zero and increases by 1 each
1882    time ->next is traversed.
1883    This function should be called before any analysis that relies on
1884    the basicblock numbers.
1885
1886    IN:
1887        jitdata..........the current jitdata
1888
1889    NOTE: Aborts with an assertion if the condition is not met!
1890
1891 *******************************************************************************/
1892
1893 #if !defined(NDEBUG)
1894 void jit_check_basicblock_numbers(jitdata *jd)
1895 {
1896         s4          nr;
1897         basicblock *bptr;
1898
1899         nr = 0;
1900         for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
1901                 assert(bptr->nr == nr);
1902                 nr++;
1903         }
1904
1905         /* we have one block more than jd->basicblockcount (the end marker) */
1906
1907         assert(nr == jd->basicblockcount + 1);
1908 }
1909 #endif /* !defined(NDEBUG) */
1910
1911
1912 /*
1913  * These are local overrides for various environment variables in Emacs.
1914  * Please do not remove this and leave it at the end of the file, where
1915  * Emacs will automagically detect them.
1916  * ---------------------------------------------------------------------
1917  * Local variables:
1918  * mode: c
1919  * indent-tabs-mode: t
1920  * c-basic-offset: 4
1921  * tab-width: 4
1922  * End:
1923  * vim:noexpandtab:sw=4:ts=4:
1924  */