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