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