CACAO
parse.cpp
Go to the documentation of this file.
1 /* src/vm/jit/parse.cpp - parser for JavaVM to intermediate code translation
2 
3  Copyright (C) 1996-2014
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 
6  This file is part of CACAO.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2, or (at
11  your option) any later version.
12 
13  This program is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  02110-1301, USA.
22 
23 */
24 
25 #include "vm/jit/parse.hpp"
26 #include <assert.h> // for assert
27 #include <string.h> // for NULL
28 #include "config.h" // for ENABLE_VERIFIER, etc
29 #include "native/native.hpp"
30 #include "mm/dumpmemory.hpp" // for DumpMemory
31 #include "threads/lock.hpp"
32 #include "toolbox/endianess.hpp"
33 #include "toolbox/logging.hpp"
34 #include "vm/breakpoint.hpp" // for BreakpointTable
35 #include "vm/class.hpp" // for class_getconstant, etc
36 #include "vm/descriptor.hpp" // for methoddesc
37 #include "vm/exceptions.hpp"
38 #include "vm/global.hpp"
39 #include "vm/jit/builtin.hpp" // for builtintable_get_internal
40 #include "vm/jit/code.hpp" // for code_unflag_leafmethod
41 #include "vm/jit/ir/bytecode.hpp" // for ::BC_aload_0, ::BC_astore_0, etc
42 #include "vm/jit/ir/icmd.hpp" // for ::ICMD_NOP, ::ICMD_BUILTIN, etc
43 #include "vm/jit/ir/instruction.hpp" // for instruction, etc
44 #include "vm/jit/jit.hpp" // for jitdata, basicblock, etc
45 #include "vm/jit/parse.hpp"
46 #include "vm/jit/reg.hpp" // for varinfo
47 #include "vm/jit/stack.hpp" // for stackelement_t
48 #include "vm/linker.hpp"
49 #include "vm/loader.hpp" // for constant_double, etc
50 #include "vm/method.hpp" // for methodinfo, etc
51 #include "vm/options.hpp" // for checksync
52 #include "vm/references.hpp" // for classref_or_classinfo, etc
53 #include "vm/resolve.hpp" // for resolve_classref, etc
54 #include "vm/statistics.hpp"
55 #include "vm/string.hpp" // for JavaString
56 #include "vm/suck.hpp"
57 #include "vm/types.hpp" // for s4, u1, u2, u4
58 #include "vm/utf8.hpp" // for Utf8String
59 
60 struct parsedata_t;
61 struct utf;
62 
63 using namespace cacao;
64 
65 
66 /* macros for verifier checks during parsing **********************************/
67 
68 #if defined(ENABLE_VERIFIER)
69 
70 /* We have to check local variables indices here because they are */
71 /* used in stack.c to index the locals array. */
72 
73 #define INDEX_ONEWORD(num) \
74  do { \
75  if (((num) < 0) || ((num) >= m->maxlocals)) \
76  goto throw_illegal_local_variable_number; \
77  } while (0)
78 
79 #define INDEX_TWOWORD(num) \
80  do { \
81  if (((num) < 0) || (((num) + 1) >= m->maxlocals)) \
82  goto throw_illegal_local_variable_number; \
83  } while (0)
84 
85 /* CHECK_BYTECODE_INDEX(i) checks whether i is a valid bytecode index. */
86 /* The end of the bytecode (i == m->jcodelength) is considered valid. */
87 
88 #define CHECK_BYTECODE_INDEX(i) \
89  do { \
90  if (((i) < 0) || ((i) >= m->jcodelength)) \
91  goto throw_invalid_bytecode_index; \
92  } while (0)
93 
94 /* CHECK_BYTECODE_INDEX_EXCLUSIVE is used for the exclusive ends */
95 /* of exception handler ranges. */
96 #define CHECK_BYTECODE_INDEX_EXCLUSIVE(i) \
97  do { \
98  if ((i) < 0 || (i) > m->jcodelength) \
99  goto throw_invalid_bytecode_index; \
100  } while (0)
101 
102 #else /* !defined(ENABLE_VERIFIER) */
103 
104 #define INDEX_ONEWORD(num)
105 #define INDEX_TWOWORD(num)
106 #define CHECK_BYTECODE_INDEX(i)
107 #define CHECK_BYTECODE_INDEX_EXCLUSIVE(i)
108 
109 #endif /* defined(ENABLE_VERIFIER) */
110 
111 
112 /* basic block generating macro ***********************************************/
113 
114 #define MARK_BASICBLOCK(pd, i) \
115  do { \
116  (pd)->basicblockstart[(i)] = 1; \
117  } while (0)
118 
119 #define INSTRUCTIONS_CHECK(i) \
120  if ((ircount + (i)) > pd.instructionslength) \
121  iptr = parse_realloc_instructions(&pd, ircount, (i))
122 
123 
124 /* intermediate code generating macros ****************************************/
125 
126 /* These macros ALWAYS set the following fields of *iptr to valid values: */
127 /* iptr->opc */
128 /* iptr->flags */
129 /* iptr->line */
130 
131 /* These macros do NOT touch the following fields of *iptr, unless a value is */
132 /* given for them: */
133 /* iptr->s1 */
134 /* iptr->sx */
135 /* iptr->dst */
136 
137 /* The _PREPARE macros omit the PINC, so you can set additional fields */
138 /* afterwards. */
139 
140 #define PINC \
141  iptr++; ircount++
142 
143 #define OP_PREPARE_FLAGS(o, f) \
144  iptr->opc = (ICMD) (o); \
145  iptr->line = currentline; \
146  iptr->flags.bits |= (f) | (ircount << INS_FLAG_ID_SHIFT);
147 
148 #define OP_PREPARE_ZEROFLAGS(o) \
149  OP_PREPARE_FLAGS(o, 0)
150 
151 #define OP_PREPARE(o) \
152  OP_PREPARE_ZEROFLAGS(o)
153 
154 #define OP(o) \
155  OP_PREPARE_ZEROFLAGS(o); \
156  PINC
157 
158 #define OP_CHECK_EXCEPTION(o) \
159  OP_PREPARE_FLAGS(o, INS_FLAG_CHECK); \
160  PINC
161 
162 #define OP_LOADCONST_I(v) \
163  OP_PREPARE_ZEROFLAGS(ICMD_ICONST); \
164  iptr->sx.val.i = (v); \
165  PINC
166 
167 #define OP_LOADCONST_L(v) \
168  OP_PREPARE_ZEROFLAGS(ICMD_LCONST); \
169  iptr->sx.val.l = (v); \
170  PINC
171 
172 #define OP_LOADCONST_F(v) \
173  OP_PREPARE_ZEROFLAGS(ICMD_FCONST); \
174  iptr->sx.val.f = (v); \
175  PINC
176 
177 #define OP_LOADCONST_D(v) \
178  OP_PREPARE_ZEROFLAGS(ICMD_DCONST); \
179  iptr->sx.val.d = (v); \
180  PINC
181 
182 #define OP_LOADCONST_NULL() \
183  OP_PREPARE_FLAGS(ICMD_ACONST, INS_FLAG_CHECK); \
184  iptr->sx.val.anyptr = NULL; \
185  PINC
186 
187 #define OP_LOADCONST_STRING(v) \
188  OP_PREPARE_FLAGS(ICMD_ACONST, INS_FLAG_CHECK); \
189  iptr->sx.val.stringconst = (v); \
190  PINC
191 
192 #define OP_LOADCONST_CLASSINFO_OR_CLASSREF_FLAGS(cl, cr, extraflags) \
193  OP_PREPARE(ICMD_ACONST); \
194  if (cl) { \
195  iptr->sx.val.c.cls = (cl); \
196  iptr->flags.bits |= INS_FLAG_CLASS | (extraflags); \
197  } \
198  else { \
199  iptr->sx.val.c.ref = (cr); \
200  iptr->flags.bits |= INS_FLAG_CLASS | INS_FLAG_UNRESOLVED \
201  | (extraflags); \
202  } \
203  PINC
204 
205 #define OP_LOADCONST_CLASSINFO_OR_CLASSREF_CHECK(c, cr) \
206  OP_LOADCONST_CLASSINFO_OR_CLASSREF_FLAGS((c), (cr), INS_FLAG_CHECK)
207 
208 #define OP_LOADCONST_CLASSINFO_OR_CLASSREF_NOCHECK(c, cr) \
209  OP_LOADCONST_CLASSINFO_OR_CLASSREF_FLAGS((c), (cr), 0)
210 
211 #define OP_S3_CLASSINFO_OR_CLASSREF(o, c, cr, extraflags) \
212  OP_PREPARE(o); \
213  if (c) { \
214  iptr->sx.s23.s3.c.cls= (c); \
215  iptr->flags.bits |= (extraflags); \
216  } \
217  else { \
218  iptr->sx.s23.s3.c.ref= (cr); \
219  iptr->flags.bits |= INS_FLAG_UNRESOLVED | (extraflags); \
220  } \
221  PINC
222 
223 #define OP_INSINDEX(o, iindex) \
224  OP_PREPARE_ZEROFLAGS(o); \
225  iptr->dst.insindex = (iindex); \
226  PINC
227 
228 # define OP_LOCALINDEX(o,index) \
229  OP_PREPARE_ZEROFLAGS(o); \
230  iptr->s1.varindex = (index); \
231  PINC
232 
233 # define OP_LOCALINDEX_I(o,index,v) \
234  OP_PREPARE_ZEROFLAGS(o); \
235  iptr->s1.varindex = (index); \
236  iptr->sx.val.i = (v); \
237  PINC
238 
239 # define LOCALTYPE_USED(index,type) \
240  do { \
241  local_map[(index) * 5 + (type)] = 1; \
242  } while (0)
243 
244 #define OP_LOAD_ONEWORD(o,index,type) \
245  do { \
246  INDEX_ONEWORD(index); \
247  OP_LOCALINDEX(o,index); \
248  LOCALTYPE_USED(index,type); \
249  } while (0)
250 
251 #define OP_LOAD_TWOWORD(o,index,type) \
252  do { \
253  INDEX_TWOWORD(index); \
254  OP_LOCALINDEX(o,index); \
255  LOCALTYPE_USED(index,type); \
256  } while (0)
257 
258 # define OP_STORE_ONEWORD(o,index,type) \
259  do { \
260  INDEX_ONEWORD(index); \
261  OP_PREPARE_ZEROFLAGS(o); \
262  iptr->dst.varindex = (index); \
263  LOCALTYPE_USED(index,type); \
264  PINC; \
265  } while (0)
266 
267 # define OP_STORE_TWOWORD(o,index,type) \
268  do { \
269  INDEX_TWOWORD(index); \
270  OP_PREPARE_ZEROFLAGS(o); \
271  iptr->dst.varindex = (index); \
272  LOCALTYPE_USED(index,type); \
273  PINC; \
274  } while (0)
275 
276 #define OP_BUILTIN_CHECK_EXCEPTION(BTE) \
277  code_unflag_leafmethod(code); \
278  OP_PREPARE_FLAGS(ICMD_BUILTIN, INS_FLAG_CHECK); \
279  iptr->sx.s23.s3.bte = (BTE); \
280  PINC
281 
282 #define OP_BUILTIN_NO_EXCEPTION(BTE) \
283  code_unflag_leafmethod(code); \
284  OP_PREPARE_ZEROFLAGS(ICMD_BUILTIN); \
285  iptr->sx.s23.s3.bte = (BTE); \
286  PINC
287 
288 #define OP_BUILTIN_ARITHMETIC(opcode, BTE) \
289  code_unflag_leafmethod(code); \
290  OP_PREPARE_FLAGS(opcode, INS_FLAG_CHECK); \
291  iptr->sx.s23.s3.bte = (BTE); \
292  PINC
293 
294 /* CAUTION: You must set iptr->flags yourself when using this! */
295 #define OP_FMIREF_PREPARE(o, FMIREF) \
296  OP_PREPARE(o); \
297  iptr->sx.s23.s3.fmiref = (FMIREF);
298 
299 
300 #define INSTRUCTIONS_INCREMENT 5 /* number of additional instructions to */
301  /* allocate if space runs out */
302 
303 
304 /* local macros ***************************************************************/
305 
306 #define BYTECODEINDEX_TO_BASICBLOCK(dst) \
307  do { \
308  (dst).block = \
309  parse_bytecodeindex_to_basicblock(jd, &pd, (dst).insindex); \
310  } while (0)
311 
312 
313 /* parserdata_t ***************************************************************/
314 
315 typedef struct parsedata_t parsedata_t;
316 
317 struct parsedata_t {
318  u1 *bytecodestart; /* start of bytecode instructions */
319  u1 *basicblockstart; /* start of bytecode basic-blocks */
320 
321  s4 *bytecodemap; /* bytecode to IR mapping */
322 
323  instruction *instructions; /* instruction array */
324  s4 instructionslength; /* length of the instruction array */
325 
326  s4 *instructionmap; /* IR to basic-block mapping */
327 };
328 
329 /* parse_setup *****************************************************************
330 
331  Fills the passed parsedata_t structure.
332 
333 *******************************************************************************/
334 
335 static void parse_setup(jitdata *jd, parsedata_t *pd)
336 {
337  methodinfo *m;
338 
339  /* get required compiler data */
340 
341  m = jd->m;
342 
343  /* bytecode start array */
344 
345  pd->bytecodestart = (u1*) DumpMemory::allocate(sizeof(u1) * (m->jcodelength + 1));
346  MZERO(pd->bytecodestart, u1, m->jcodelength + 1);
347 
348  /* bytecode basic-block start array */
349 
350  pd->basicblockstart = (u1*) DumpMemory::allocate(sizeof(u1) *(m->jcodelength + 1));
351  MZERO(pd->basicblockstart, u1, m->jcodelength + 1);
352 
353  /* bytecode instruction index to IR instruction mapping */
354 
355  pd->bytecodemap = (s4*) DumpMemory::allocate(sizeof(s4) * (m->jcodelength + 1));
356  MSET(pd->bytecodemap, -1, s4, m->jcodelength + 1);
357 
358  /* allocate the instruction array */
359 
360  pd->instructionslength = m->jcodelength + 1;
362 
363  /* Zero the intermediate instructions array so we don't have any
364  invalid pointers in it if we cannot finish stack_analyse(). */
365 
367 
368  /* The instructionmap is allocated later when we know the count of
369  instructions. */
370 
371  pd->instructionmap = NULL;
372 }
373 
374 
375 /* parse_realloc_instructions **************************************************
376 
377  Reallocate the instructions array so there is room for at least N
378  additional instructions.
379 
380  RETURN VALUE:
381  the new value for iptr
382 
383 *******************************************************************************/
384 
386 {
387  /* increase the size of the instruction array */
388 
390 
391  /* reallocate the array */
392 
394  sizeof(instruction) * pd->instructionslength);
395  MZERO(pd->instructions + icount, instruction,
396  (pd->instructionslength - icount));
397 
398  /* return the iptr */
399 
400  return pd->instructions + icount;
401 }
402 
403 
404 /* parse_bytecodeindex_to_basicblock *******************************************
405 
406  Resolves a bytecode index to the corresponding basic block.
407 
408 *******************************************************************************/
409 
411  parsedata_t *pd,
412  s4 bcindex)
413 {
414  s4 irindex;
415  basicblock *bb;
416 
417  irindex = pd->bytecodemap[bcindex];
418  bb = jd->basicblocks + pd->instructionmap[irindex];
419 
420  return bb;
421 }
422 
423 
424 /* parse_mark_exception_boundaries *********************************************
425 
426  Mark exception handlers and the boundaries of the handled regions as
427  basic block boundaries.
428 
429  IN:
430  jd...............current jitdata
431 
432  RETURN VALUE:
433  true.............everything ok
434  false............an exception has been thrown
435 
436 *******************************************************************************/
437 
439 {
440  s4 bcindex;
441  s4 len;
442  raw_exception_entry *rex;
443  methodinfo *m;
444 
445  m = jd->m;
446 
447  len = m->rawexceptiontablelength;
448 
449  if (len == 0)
450  return true;
451 
452  rex = m->rawexceptiontable;
453 
454  for (s4 i = 0; i < len; ++i, ++rex) {
455 
456  /* the start of the handled region becomes a basic block start */
457 
458  bcindex = rex->startpc;
459  CHECK_BYTECODE_INDEX(bcindex);
460  MARK_BASICBLOCK(pd, bcindex);
461 
462  bcindex = rex->endpc; /* see JVM Spec 4.7.3 */
464 
465  /* check that the range is valid */
466 
467 #if defined(ENABLE_VERIFIER)
468  if (bcindex <= rex->startpc) {
469  exceptions_throw_verifyerror(m, "Invalid exception handler range");
470  return false;
471  }
472 #endif
473 
474  /* End of handled region becomes a basic block boundary (if it
475  is the bytecode end, we'll use the special end block that
476  is created anyway). */
477 
478  if (bcindex < m->jcodelength)
479  MARK_BASICBLOCK(pd, bcindex);
480  else
481  jd->branchtoend = true;
482 
483  /* the start of the handler becomes a basic block start */
484 
485  bcindex = rex->handlerpc;
486  CHECK_BYTECODE_INDEX(bcindex);
487  MARK_BASICBLOCK(pd, bcindex);
488  }
489 
490  /* everything ok */
491 
492  return true;
493 
494 #if defined(ENABLE_VERIFIER)
495 throw_invalid_bytecode_index:
497  "Illegal bytecode index in exception table");
498  return false;
499 #endif
500 }
501 
502 
503 /* parse_resolve_exception_table ***********************************************
504 
505  Enter the exception handlers and their ranges, resolved to basicblock *s,
506  in the jitdata.
507 
508  IN:
509  jd...............current jitdata
510 
511  RETURN VALUE:
512  true.............everything ok
513  false............an exception has been thrown
514 
515 *******************************************************************************/
516 
518 {
519  methodinfo *m;
520  raw_exception_entry *rex;
521  exception_entry *ex;
522  s4 len;
523  classinfo *exclass;
524 
525  m = jd->m;
526 
527  len = m->rawexceptiontablelength;
528 
529  /* common case: no handler entries */
530 
531  if (len == 0)
532  return true;
533 
534  /* allocate the exception table */
535 
536  jd->exceptiontablelength = len;
537  jd->exceptiontable = (exception_entry*) DumpMemory::allocate(sizeof(exception_entry) * (len + 1)); /* XXX why +1? */
538 
539  /* copy and resolve the entries */
540 
541  ex = jd->exceptiontable;
542  rex = m->rawexceptiontable;
543 
544  for (s4 i = 0; i < len; ++i, ++rex, ++ex) {
545  /* resolve instruction indices to basic blocks */
546 
547  ex->start = parse_bytecodeindex_to_basicblock(jd, pd, rex->startpc);
548  ex->end = parse_bytecodeindex_to_basicblock(jd, pd, rex->endpc);
549  ex->handler = parse_bytecodeindex_to_basicblock(jd, pd, rex->handlerpc);
550 
551  /* lazily resolve the catchtype */
552 
553  if (rex->catchtype.any != NULL) {
555  rex->catchtype,
556  resolveLazy, true, false,
557  &exclass))
558  return false;
559 
560  /* if resolved, enter the result of resolution in the table */
561 
562  if (exclass != NULL)
563  rex->catchtype.cls = exclass;
564  }
565 
566  ex->catchtype = rex->catchtype;
567  ex->next = NULL; /* set by loop analysis */
568  ex->down = ex + 1; /* link to next exception entry */
569  }
570 
571  /* terminate the ->down linked list */
572 
573  assert(ex != jd->exceptiontable);
574  ex[-1].down = NULL;
575 
576  return true;
577 }
578 
579 
580 /*******************************************************************************
581 
582  function 'parse' scans the JavaVM code and generates intermediate code
583 
584  During parsing the block index table is used to store at bit pos 0
585  a flag which marks basic block starts and at position 1 to 31 the
586  intermediate instruction index. After parsing the block index table
587  is scanned, for marked positions a block is generated and the block
588  number is stored in the block index table.
589 
590 *******************************************************************************/
591 
592 /*** macro for checking the length of the bytecode ***/
593 
594 #if defined(ENABLE_VERIFIER)
595 #define CHECK_END_OF_BYTECODE(neededlength) \
596  do { \
597  if ((neededlength) > m->jcodelength) \
598  goto throw_unexpected_end_of_bytecode; \
599  } while (0)
600 #else /* !ENABLE_VERIFIER */
601 #define CHECK_END_OF_BYTECODE(neededlength)
602 #endif /* ENABLE_VERIFIER */
603 
604 bool parse(jitdata *jd)
605 {
606  methodinfo *m; /* method being parsed */
607  codeinfo *code;
608  parsedata_t pd;
609  instruction *iptr; /* current ptr into instruction array */
610 
611  s4 bcindex; /* bytecode instruction index */
612  s4 nextbc; /* start of next bytecode instruction */
613 
614  s4 irindex; /* IR instruction index */
615  s4 ircount; /* IR instruction count */
616 
617  s4 bbcount; /* basic block count */
618 
619  int s_count = 0; /* stack element counter */
620  bool blockend; /* true if basic block end has been reached */
621  bool iswide; /* true if last instruction was a wide */
622 
623  constant_FMIref *fmi;
624  methoddesc *md;
625 
626  u2 lineindex = 0;
627  u2 currentline = 0;
628  u2 linepcchange = 0;
629  basicblock *bptr;
630 
631  int *local_map; /* local pointer to renaming map */
632  /* is assigned to rd->local_map at the end */
633  branch_target_t *table;
634  lookup_target_t *lookup;
635  s4 i;
636 
637  /* get required compiler data */
638 
639  m = jd->m;
640  code = jd->code;
641 
642  /* allocate buffers for local variable renaming */
643 
644  local_map = (int*) DumpMemory::allocate(sizeof(int) * m->maxlocals * 5);
645 
646  for (s4 i = 0; i < m->maxlocals; i++) {
647  local_map[i * 5 + 0] = 0;
648  local_map[i * 5 + 1] = 0;
649  local_map[i * 5 + 2] = 0;
650  local_map[i * 5 + 3] = 0;
651  local_map[i * 5 + 4] = 0;
652  }
653 
654  /* initialize the parse data structures */
655 
656  parse_setup(jd, &pd);
657 
658  /* initialize local variables */
659 
660  iptr = pd.instructions;
661  ircount = 0;
662  bbcount = 0;
663  blockend = false;
664  iswide = false;
665 
666  /* mark basic block boundaries for exception table */
667 
668  if (!parse_mark_exception_boundaries(jd, &pd))
669  return false;
670 
671  /* initialize stack element counter */
672 
673  s_count = 1 + m->rawexceptiontablelength;
674 
675  /* setup line number info */
676 
677  currentline = 0;
678  linepcchange = 0;
679 
680  if (m->linenumbercount == 0) {
681  lineindex = 0;
682  }
683  else {
684  linepcchange = m->linenumbers[0].start_pc;
685  }
686 
687  /*** LOOP OVER ALL BYTECODE INSTRUCTIONS **********************************/
688 
689  for (bcindex = 0; bcindex < m->jcodelength; bcindex = nextbc) {
690 
691  /* mark this position as a valid bytecode instruction start */
692 
693  pd.bytecodestart[bcindex] = 1;
694 
695  /* change the current line number, if necessary */
696 
697  /* XXX rewrite this using pointer arithmetic */
698 
699  if (linepcchange == bcindex) {
700  if (m->linenumbercount > lineindex) {
701 next_linenumber:
702  currentline = m->linenumbers[lineindex].line_number;
703  lineindex++;
704  if (lineindex < m->linenumbercount) {
705  linepcchange = m->linenumbers[lineindex].start_pc;
706  if (linepcchange == bcindex)
707  goto next_linenumber;
708  }
709  }
710  }
711 
712 fetch_opcode:
713  /* fetch next opcode */
714 
715  ByteCode opcode = (ByteCode) read_u1_be(m->jcode + bcindex);
716 
717  /* If the previous instruction was a block-end instruction,
718  mark the current bytecode instruction as basic-block
719  starting instruction. */
720 
721  /* NOTE: Some compilers put a BC_nop after a blockend
722  instruction. */
723 
724  if (blockend && (opcode != BC_nop)) {
725  MARK_BASICBLOCK(&pd, bcindex);
726  blockend = false;
727  }
728 
729  /* If the current bytecode instruction was marked as
730  basic-block starting instruction before (e.g. blockend,
731  forward-branch target), mark the current IR instruction
732  too. */
733 
734  if (pd.basicblockstart[bcindex] != 0) {
735  /* We need a NOP as last instruction in each basic block
736  for basic block reordering (may be replaced with a GOTO
737  later). */
738 
740  OP(ICMD_NOP);
741  }
742 
743  /* store intermediate instruction count (bit 0 mark block starts) */
744 
745  pd.bytecodemap[bcindex] = ircount;
746 
747  /* compute next instruction start */
748 
749  nextbc = bcindex + bytecode[opcode].length;
750 
751  CHECK_END_OF_BYTECODE(nextbc);
752 
753  /* add stack elements produced by this instruction */
754 
755  s_count += bytecode[opcode].slots;
756 
757  /* Generate a breakpoint instruction right before the actual
758  instruction, if the method contains a breakpoint at the
759  current bytecode index. */
760 
761  if (m->breakpoints != NULL && m->breakpoints->contains(bcindex)) {
764  iptr->sx.val.anyptr = m->breakpoints->get_breakpoint(bcindex);
765  PINC;
766  }
767 
768  /* We check here for the space of 1 instruction in the
769  instruction array. If an opcode is converted to more than
770  1 instruction, this is checked in the corresponding
771  case. */
772 
774 
775  /* translate this bytecode instruction */
776  switch (opcode) {
777 
778  case BC_nop:
779  break;
780 
781  /* pushing constants onto the stack ***********************************/
782 
783  case BC_bipush:
784  OP_LOADCONST_I(read_s1_be(m->jcode + bcindex + 1));
785  break;
786 
787  case BC_sipush:
788  OP_LOADCONST_I(read_s2_be(m->jcode + bcindex + 1));
789  break;
790 
791  case BC_ldc1:
792  i = read_u1_be(m->jcode + bcindex + 1);
793  goto pushconstantitem;
794 
795  case BC_ldc2:
796  case BC_ldc2w:
797  i = read_u2_be(m->jcode + bcindex + 1);
798  // fallthrough!
799 
800  pushconstantitem:
801 
802 #if defined(ENABLE_VERIFIER)
803  if (i >= m->clazz->cpcount) {
805  "Attempt to access constant outside range");
806  return false;
807  }
808 #endif
809 
810  switch (m->clazz->cptags[i]) {
811  case CONSTANT_Integer:
812  OP_LOADCONST_I(*reinterpret_cast<int32_t*>(m->clazz->cpinfos[i]));
813  break;
814  case CONSTANT_Long:
815  OP_LOADCONST_L(*reinterpret_cast<int64_t*>(m->clazz->cpinfos[i]));
816  break;
817  case CONSTANT_Float:
818  OP_LOADCONST_F(*reinterpret_cast<float*>(m->clazz->cpinfos[i]));
819  break;
820  case CONSTANT_Double:
821  OP_LOADCONST_D(*reinterpret_cast<double*>(m->clazz->cpinfos[i]));
822  break;
823  case CONSTANT_String:
825  break;
826  case CONSTANT_Class: {
828 
829  classinfo *c;
830  if (!resolve_classref(m, cr, resolveLazy, true, true, &c))
831  return false;
832 
833  /* if not resolved, c == NULL */
834 
836 
837  break;
838  }
839 
840 #if defined(ENABLE_VERIFIER)
841  default:
842  exceptions_throw_verifyerror(m, "Invalid constant type to push: %u", m->clazz->cptags[i]);
843  return false;
844 #endif
845  }
846  break;
847 
848  case BC_aconst_null:
850  break;
851 
852  case BC_iconst_m1:
853  case BC_iconst_0:
854  case BC_iconst_1:
855  case BC_iconst_2:
856  case BC_iconst_3:
857  case BC_iconst_4:
858  case BC_iconst_5:
859  OP_LOADCONST_I(opcode - BC_iconst_0);
860  break;
861 
862  case BC_lconst_0:
863  case BC_lconst_1:
864  OP_LOADCONST_L(opcode - BC_lconst_0);
865  break;
866 
867  case BC_fconst_0:
868  case BC_fconst_1:
869  case BC_fconst_2:
870  OP_LOADCONST_F(opcode - BC_fconst_0);
871  break;
872 
873  case BC_dconst_0:
874  case BC_dconst_1:
875  OP_LOADCONST_D(opcode - BC_dconst_0);
876  break;
877 
878  /* stack operations ***************************************************/
879 
880  /* We need space for additional instruction so we can
881  translate these instructions to sequences of ICMD_COPY and
882  ICMD_MOVE instructions. */
883 
884  case BC_dup_x1:
886  OP(opcode);
887  OP(ICMD_NOP);
888  OP(ICMD_NOP);
889  OP(ICMD_NOP);
890  break;
891 
892  case BC_dup_x2:
894  OP(opcode);
895  OP(ICMD_NOP);
896  OP(ICMD_NOP);
897  OP(ICMD_NOP);
898  OP(ICMD_NOP);
899  OP(ICMD_NOP);
900  break;
901 
902  case BC_dup2:
904  OP(opcode);
905  OP(ICMD_NOP);
906  break;
907 
908  case BC_dup2_x1:
910  OP(opcode);
911  OP(ICMD_NOP);
912  OP(ICMD_NOP);
913  OP(ICMD_NOP);
914  OP(ICMD_NOP);
915  OP(ICMD_NOP);
916  OP(ICMD_NOP);
917  break;
918 
919  case BC_dup2_x2:
921  OP(opcode);
922  OP(ICMD_NOP);
923  OP(ICMD_NOP);
924  OP(ICMD_NOP);
925  OP(ICMD_NOP);
926  OP(ICMD_NOP);
927  OP(ICMD_NOP);
928  OP(ICMD_NOP);
929  OP(ICMD_NOP);
930  break;
931 
932  case BC_swap:
934  OP(opcode);
935  OP(ICMD_NOP);
936  OP(ICMD_NOP);
937  break;
938 
939  /* local variable access instructions *********************************/
940 
941  case BC_iload:
942  case BC_fload:
943  case BC_aload: {
944  int i; // must be signed because of OP_LOAD_ONEWORD
945 
946 
947  if (iswide == false) {
948  i = read_u1_be(m->jcode + bcindex + 1);
949  }
950  else {
951  i = read_u2_be(m->jcode + bcindex + 1);
952  nextbc = bcindex + 3;
953  iswide = false;
954  }
955  OP_LOAD_ONEWORD(opcode, i, opcode - BC_iload);
956  break;
957  }
958 
959  case BC_lload:
960  case BC_dload: {
961  int i; // must be signed because of OP_LOAD_ONEWORD
962 
963  if (iswide == false) {
964  i = read_u1_be(m->jcode + bcindex + 1);
965  }
966  else {
967  i = read_u2_be(m->jcode + bcindex + 1);
968  nextbc = bcindex + 3;
969  iswide = false;
970  }
971  OP_LOAD_TWOWORD(opcode, i, opcode - BC_iload);
972  break;
973  }
974 
975  case BC_iload_0:
976  case BC_iload_1:
977  case BC_iload_2:
978  case BC_iload_3:
980  break;
981 
982  case BC_lload_0:
983  case BC_lload_1:
984  case BC_lload_2:
985  case BC_lload_3:
987  break;
988 
989  case BC_fload_0:
990  case BC_fload_1:
991  case BC_fload_2:
992  case BC_fload_3:
994  break;
995 
996  case BC_dload_0:
997  case BC_dload_1:
998  case BC_dload_2:
999  case BC_dload_3:
1001  break;
1002 
1003  case BC_aload_0:
1004  case BC_aload_1:
1005  case BC_aload_2:
1006  case BC_aload_3:
1008  break;
1009 
1010  case BC_istore:
1011  case BC_fstore:
1012  case BC_astore: {
1013  int i; // must be signed because of OP_LOAD_ONEWORD
1014 
1015 
1016  if (iswide == false) {
1017  i = read_u1_be(m->jcode + bcindex + 1);
1018  }
1019  else {
1020  i = read_u2_be(m->jcode + bcindex + 1);
1021  nextbc = bcindex + 3;
1022  iswide = false;
1023  }
1024  OP_STORE_ONEWORD(opcode, i, opcode - BC_istore);
1025  break;
1026  }
1027 
1028  case BC_lstore:
1029  case BC_dstore:
1030  if (iswide == false) {
1031  i = read_u1_be(m->jcode + bcindex + 1);
1032  }
1033  else {
1034  i = read_u2_be(m->jcode + bcindex + 1);
1035  nextbc = bcindex + 3;
1036  iswide = false;
1037  }
1038  OP_STORE_TWOWORD(opcode, i, opcode - BC_istore);
1039  break;
1040 
1041  case BC_istore_0:
1042  case BC_istore_1:
1043  case BC_istore_2:
1044  case BC_istore_3:
1046  break;
1047 
1048  case BC_lstore_0:
1049  case BC_lstore_1:
1050  case BC_lstore_2:
1051  case BC_lstore_3:
1053  break;
1054 
1055  case BC_fstore_0:
1056  case BC_fstore_1:
1057  case BC_fstore_2:
1058  case BC_fstore_3:
1060  break;
1061 
1062  case BC_dstore_0:
1063  case BC_dstore_1:
1064  case BC_dstore_2:
1065  case BC_dstore_3:
1067  break;
1068 
1069  case BC_astore_0:
1070  case BC_astore_1:
1071  case BC_astore_2:
1072  case BC_astore_3:
1074  break;
1075 
1076  case BC_iinc: {
1077  int i; // must be signed because of INDEX_ONEWORD
1078  int v;
1079 
1080  if (iswide == false) {
1081  i = read_u1_be(m->jcode + bcindex + 1);
1082  v = read_s1_be(m->jcode + bcindex + 2);
1083  } else {
1084  i = read_u2_be(m->jcode + bcindex + 1);
1085  v = read_s2_be(m->jcode + bcindex + 3);
1086  nextbc = bcindex + 5;
1087  iswide = false;
1088  }
1089  INDEX_ONEWORD(i);
1091  OP_LOCALINDEX_I(opcode, i, v);
1092  break;
1093  }
1094 
1095  /* wider index for loading, storing and incrementing ******************/
1096 
1097  case BC_wide:
1098  bcindex++;
1099  iswide = true;
1100  goto fetch_opcode;
1101 
1102  /* managing arrays ****************************************************/
1103 
1104  case BC_newarray: {
1105  builtintable_entry *bte;
1106  switch (read_s1_be(m->jcode + bcindex + 1)) {
1107  case 4:
1109  break;
1110  case 5:
1112  break;
1113  case 6:
1115  break;
1116  case 7:
1118  break;
1119  case 8:
1121  break;
1122  case 9:
1124  break;
1125  case 10:
1127  break;
1128  case 11:
1130  break;
1131 #if defined(ENABLE_VERIFIER)
1132  default:
1133  exceptions_throw_verifyerror(m, "Invalid array-type to create");
1134  return false;
1135 #endif
1136  }
1138  break;
1139  }
1140 
1141  case BC_anewarray: {
1142  u2 i = read_u2_be(m->jcode + bcindex + 1);
1144 
1145  if (compr == NULL)
1146  return false;
1147 
1149 
1150  if (cr == NULL)
1151  return false;
1152 
1153  classinfo *c;
1154  if (!resolve_classref(m, cr, resolveLazy, true, true, &c))
1155  return false;
1156 
1157  INSTRUCTIONS_CHECK(2);
1161  s_count++;
1162  break;
1163  }
1164 
1165  case BC_multianewarray: {
1166  u2 i = read_u2_be(m->jcode + bcindex + 1);
1167  u1 j = read_u1_be(m->jcode + bcindex + 3);
1168 
1170  if (cr == NULL)
1171  return false;
1172 
1173  classinfo *c;
1174  if (!resolve_classref(m, cr, resolveLazy, true, true, &c))
1175  return false;
1176 
1177  /* if unresolved, c == NULL */
1178 
1179  iptr->s1.argcount = j;
1181  code_unflag_leafmethod(code);
1182  break;
1183  }
1184 
1185  /* control flow instructions ******************************************/
1186 
1187  case BC_ifeq:
1188  case BC_iflt:
1189  case BC_ifle:
1190  case BC_ifne:
1191  case BC_ifgt:
1192  case BC_ifge:
1193  case BC_ifnull:
1194  case BC_ifnonnull:
1195  case BC_if_icmpeq:
1196  case BC_if_icmpne:
1197  case BC_if_icmplt:
1198  case BC_if_icmpgt:
1199  case BC_if_icmple:
1200  case BC_if_icmpge:
1201  case BC_if_acmpeq:
1202  case BC_if_acmpne:
1203  case BC_goto: {
1204  s4 i = bcindex + read_s2_be(m->jcode + bcindex + 1);
1206  MARK_BASICBLOCK(&pd, i);
1207  blockend = true;
1208  OP_INSINDEX(opcode, i);
1209  break;
1210  }
1211 
1212  case BC_goto_w: {
1213  s8 i = ((s8) bcindex) + read_s4_be(m->jcode + bcindex + 1);
1215  MARK_BASICBLOCK(&pd, i);
1216  blockend = true;
1217  OP_INSINDEX(ICMD_GOTO, i);
1218  break;
1219  }
1220 
1221  case BC_jsr: {
1222  s4 i = bcindex + read_s2_be(m->jcode + bcindex + 1);
1224  MARK_BASICBLOCK(&pd, i);
1225  blockend = true;
1227  iptr->sx.s23.s3.jsrtarget.insindex = i;
1228  PINC;
1229  break;
1230  }
1231 
1232  case BC_jsr_w: {
1233  s8 i = ((s8) bcindex) + read_s4_be(m->jcode + bcindex + 1);
1235  MARK_BASICBLOCK(&pd, i);
1236  blockend = true;
1238  iptr->sx.s23.s3.jsrtarget.insindex = i;
1239  PINC;
1240  break;
1241  }
1242 
1243  case BC_ret: {
1244  int i; // must be signed because of OP_LOAD_ONEWORD
1245 
1246  if (iswide == false) {
1247  i = read_u1_be(m->jcode + bcindex + 1);
1248  } else {
1249  i = read_u2_be(m->jcode + bcindex + 1);
1250  nextbc = bcindex + 3;
1251  iswide = false;
1252  }
1253  blockend = true;
1254 
1255  OP_LOAD_ONEWORD(opcode, i, TYPE_ADR);
1256  break;
1257  }
1258 
1259  case BC_ireturn:
1260  case BC_lreturn:
1261  case BC_freturn:
1262  case BC_dreturn:
1263  case BC_areturn:
1264  case BC_return:
1265  blockend = true;
1266  /* XXX ARETURN will need a flag in the typechecker */
1267  OP(opcode);
1268  break;
1269 
1270  case BC_athrow:
1271  blockend = true;
1272  /* XXX ATHROW will need a flag in the typechecker */
1273  OP(opcode);
1274  break;
1275 
1276 
1277  /* table jumps ********************************************************/
1278 
1279  case BC_lookupswitch: {
1280 #if defined(ENABLE_VERIFIER)
1281  s4 prevvalue = 0;
1282 #endif
1283  blockend = true;
1284  nextbc = MEMORY_ALIGN((bcindex + 1), 4);
1285 
1286  CHECK_END_OF_BYTECODE(nextbc + 8);
1287 
1288  OP_PREPARE_ZEROFLAGS(opcode);
1289 
1290  /* default target */
1291 
1292  s8 j = ((s8) bcindex) + read_s4_be(m->jcode + nextbc);
1294  MARK_BASICBLOCK(&pd, j);
1295  iptr->sx.s23.s3.lookupdefault.insindex = j;
1296  nextbc += 4;
1297 
1298  /* number of pairs */
1299 
1300  s8 num = read_u4_be(m->jcode + nextbc);
1301  iptr->sx.s23.s2.lookupcount = num;
1302  nextbc += 4;
1303 
1304  /* allocate the intermediate code table */
1305 
1307  iptr->dst.lookup = lookup;
1308 
1309  /* iterate over the lookup table */
1310 
1311  CHECK_END_OF_BYTECODE(nextbc + 8 * num);
1312 
1313  for (u4 i = 0; i < num; i++) {
1314  /* value */
1315 
1316  s4 value = read_s4_be(m->jcode + nextbc);
1317  lookup->value = value;
1318 
1319  nextbc += 4;
1320 
1321 #if defined(ENABLE_VERIFIER)
1322  /* check if the lookup table is sorted correctly */
1323 
1324  if (i && (value <= prevvalue)) {
1325  exceptions_throw_verifyerror(m, "Unsorted lookup switch");
1326  return false;
1327  }
1328  prevvalue = value;
1329 #endif
1330  /* target */
1331 
1332  s8 target = ((s8) bcindex) + read_s4_be(m->jcode + nextbc);
1333  CHECK_BYTECODE_INDEX(target);
1334  MARK_BASICBLOCK(&pd, target);
1335  lookup->target.insindex = target;
1336  lookup++;
1337  nextbc += 4;
1338  }
1339 
1340  PINC;
1341  break;
1342  }
1343 
1344  case BC_tableswitch: {
1345  blockend = true;
1346  nextbc = MEMORY_ALIGN((bcindex + 1), 4);
1347 
1348  CHECK_END_OF_BYTECODE(nextbc + 12);
1349 
1350  OP_PREPARE_ZEROFLAGS(opcode);
1351 
1352  /* default target */
1353 
1354  s8 deftarget = ((s8) bcindex) + read_s4_be(m->jcode + nextbc);
1355  CHECK_BYTECODE_INDEX(deftarget);
1356  MARK_BASICBLOCK(&pd, deftarget);
1357  nextbc += 4;
1358 
1359  /* lower bound */
1360 
1361  s4 lo = read_s4_be(m->jcode + nextbc);
1362  iptr->sx.s23.s2.tablelow = lo;
1363  nextbc += 4;
1364 
1365  /* upper bound */
1366 
1367  s4 hi = read_s4_be(m->jcode + nextbc);
1368  iptr->sx.s23.s3.tablehigh = hi;
1369  nextbc += 4;
1370 
1371  /* calculate the number of table entries */
1372 
1373  s8 num = ((s8) hi) - ((s8) lo) + 1;
1374 
1375 #if defined(ENABLE_VERIFIER)
1376  if (num < 1) {
1377  exceptions_throw_verifyerror(m, "invalid TABLESWITCH: upper bound < lower bound");
1378  return false;
1379  }
1380 #endif
1381  /* create the intermediate code table */
1382  /* the first entry is the default target */
1383 
1384  branch_target_t *table = (branch_target_t*) DumpMemory::allocate(sizeof(branch_target_t) * (1 + num));
1385  iptr->dst.table = table;
1386  (table++)->insindex = deftarget;
1387 
1388  /* iterate over the target table */
1389 
1390  CHECK_END_OF_BYTECODE(nextbc + 4 * num);
1391 
1392  for (s4 i = 0; i < num; i++) {
1393  s8 j = ((s8) bcindex) + read_s4_be(m->jcode + nextbc);
1395  MARK_BASICBLOCK(&pd, j);
1396  (table++)->insindex = j;
1397  nextbc += 4;
1398  }
1399 
1400  PINC;
1401  break;
1402  }
1403 
1404 
1405  /* load and store of object fields ************************************/
1406 
1407  case BC_aastore:
1408  OP(opcode);
1409  code_unflag_leafmethod(code);
1410  break;
1411 
1412  case BC_getstatic:
1413  case BC_putstatic:
1414  case BC_getfield:
1415  case BC_putfield: {
1416  u2 i = read_u2_be(m->jcode + bcindex + 1);
1418 
1419  if (fmi == NULL)
1420  return false;
1421 
1422  OP_PREPARE_ZEROFLAGS(opcode);
1423  iptr->sx.s23.s3.fmiref = fmi;
1424 
1425  /* only with -noverify, otherwise the typechecker does this */
1426 
1427 #if defined(ENABLE_VERIFIER)
1428  if (!JITDATA_HAS_FLAG_VERIFY(jd)) {
1429 #endif
1430  resolve_result_t result = resolve_field_lazy(m, fmi);
1431 
1432  if (result == resolveFailed)
1433  return false;
1434 
1435  if (result != resolveSucceeded) {
1437 
1438  if (uf == NULL)
1439  return false;
1440 
1441  /* store the unresolved_field pointer */
1442 
1443  iptr->sx.s23.s3.uf = uf;
1444  iptr->flags.bits |= INS_FLAG_UNRESOLVED;
1445  }
1446 #if defined(ENABLE_VERIFIER)
1447  }
1448 #endif
1449  PINC;
1450  break;
1451  }
1452 
1453 
1454  /* method invocation **************************************************/
1455 
1456  case BC_invokestatic: {
1457  OP_PREPARE_ZEROFLAGS(opcode);
1458 
1459  u2 i = read_u2_be(m->jcode + bcindex + 1);
1461 
1462  if (fmi == NULL)
1463  return false;
1464 
1465  md = fmi->parseddesc.md;
1466 
1468 
1469  goto invoke_method;
1470  }
1471 
1472  case BC_invokespecial: {
1474 
1475  u2 i = read_u2_be(m->jcode + bcindex + 1);
1477 
1478  goto invoke_nonstatic_method;
1479  }
1480 
1481  case BC_invokeinterface: {
1482  OP_PREPARE_ZEROFLAGS(opcode);
1483 
1484  u2 i = read_u2_be(m->jcode + bcindex + 1);
1486 
1487  goto invoke_nonstatic_method;
1488  }
1489 
1490  case BC_invokevirtual: {
1491  OP_PREPARE_ZEROFLAGS(opcode);
1492 
1493  u2 i = read_u2_be(m->jcode + bcindex + 1);
1495  // fallthrough!
1496  }
1497 
1498  invoke_nonstatic_method:
1499  if (fmi == NULL)
1500  return false;
1501 
1502  md = fmi->parseddesc.md;
1503 
1504  md->params_from_paramtypes(0);
1505 
1506  invoke_method: {
1507  code_unflag_leafmethod(code);
1508 
1509  iptr->sx.s23.s3.fmiref = fmi;
1510 
1511  /* only with -noverify, otherwise the typechecker does this */
1512 
1513 #if defined(ENABLE_VERIFIER)
1514  if (!JITDATA_HAS_FLAG_VERIFY(jd)) {
1515 #endif
1516  resolve_result_t result = resolve_method_lazy(m, fmi, opcode == BC_invokespecial);
1517 
1518  if (result == resolveFailed)
1519  return false;
1520 
1521  if (result == resolveSucceeded) {
1522  methodinfo *mi = iptr->sx.s23.s3.fmiref->p.method;
1523 
1524  /* if this call is monomorphic, turn it into an
1525  INVOKESPECIAL */
1526 
1527  assert(iptr->sx.s23.s3.fmiref->is_resolved());
1528 
1529  if ((opcode == BC_invokevirtual) && (mi->flags & (ACC_FINAL | ACC_PRIVATE))) {
1530  iptr->opc = ICMD_INVOKESPECIAL;
1531  iptr->flags.bits |= INS_FLAG_CHECK;
1532  }
1533  }
1534  else {
1536  m,
1537  fmi,
1538  opcode == BC_invokestatic,
1539  opcode == BC_invokespecial);
1540 
1541  /* store the unresolved_method pointer */
1542 
1543  iptr->sx.s23.s3.um = um;
1544  iptr->flags.bits |= INS_FLAG_UNRESOLVED;
1545  }
1546 #if defined(ENABLE_VERIFIER)
1547  }
1548 #endif
1549  PINC;
1550  break;
1551  }
1552 
1553  /* instructions taking class arguments ********************************/
1554 
1555  case BC_new: {
1556  u2 i = read_u2_be(m->jcode + bcindex + 1);
1558 
1559  if (cr == NULL)
1560  return false;
1561 
1562  classinfo *c;
1563  if (!resolve_classref(m, cr, resolveLazy, true, true, &c))
1564  return false;
1565 
1566  INSTRUCTIONS_CHECK(2);
1570  s_count++;
1571  break;
1572  }
1573 
1574  case BC_checkcast: {
1575  u2 i = read_u2_be(m->jcode + bcindex + 1);
1577 
1578  if (cr == NULL)
1579  return false;
1580 
1581  classinfo *c;
1582  if (!resolve_classref(m, cr, resolveLazy, true, true, &c))
1583  return false;
1584 
1585  u4 flags;
1586 
1587  if (cr->name[0] == '[') {
1588  /* array type cast-check */
1589  flags = INS_FLAG_CHECK | INS_FLAG_ARRAY;
1590  code_unflag_leafmethod(code);
1591  }
1592  else {
1593  /* object type cast-check */
1594  flags = INS_FLAG_CHECK;
1595  }
1596  OP_S3_CLASSINFO_OR_CLASSREF(opcode, c, cr, flags);
1597  break;
1598  }
1599 
1600  case BC_instanceof: {
1601  u2 i = read_u2_be(m->jcode + bcindex + 1);
1603 
1604  if (cr == NULL)
1605  return false;
1606 
1607  classinfo *c;
1608  if (!resolve_classref(m, cr, resolveLazy, true, true, &c))
1609  return false;
1610 
1611  if (cr->name[0] == '[') {
1612  /* array type cast-check */
1613  INSTRUCTIONS_CHECK(2);
1617  s_count++;
1618  }
1619  else {
1620  /* object type cast-check */
1621  OP_S3_CLASSINFO_OR_CLASSREF(opcode, c, cr, 0 /* flags*/);
1622  }
1623  break;
1624  }
1625 
1626  /* synchronization instructions ***************************************/
1627 
1628  case BC_monitorenter:
1629  if (checksync) {
1632  } else {
1634  OP(ICMD_POP);
1635  }
1636  break;
1637 
1638  case BC_monitorexit:
1639  if (checksync) {
1642  } else {
1644  OP(ICMD_POP);
1645  }
1646  break;
1647 
1648  /* arithmetic instructions that may become builtin functions **********/
1649 
1650  case BC_idiv: {
1651 #if !SUPPORT_DIVISION
1653  OP_BUILTIN_ARITHMETIC(opcode, bte);
1654 #else
1655 # if SUPPORT_HARDWARE_DIVIDE_BY_ZERO
1656  OP(opcode);
1657 # else
1658  OP_CHECK_EXCEPTION(opcode);
1659 # endif
1660 #endif
1661  break;
1662  }
1663 
1664  case BC_irem: {
1665 #if !SUPPORT_DIVISION
1667  OP_BUILTIN_ARITHMETIC(opcode, bte);
1668 #else
1669 # if SUPPORT_HARDWARE_DIVIDE_BY_ZERO
1670  OP(opcode);
1671 # else
1672  OP_CHECK_EXCEPTION(opcode);
1673 # endif
1674 #endif
1675  break;
1676  }
1677 
1678  case BC_ldiv: {
1679 #if !(SUPPORT_DIVISION && SUPPORT_LONG_DIV)
1681  OP_BUILTIN_ARITHMETIC(opcode, bte);
1682 #else
1683 # if SUPPORT_HARDWARE_DIVIDE_BY_ZERO
1684  OP(opcode);
1685 # else
1686  OP_CHECK_EXCEPTION(opcode);
1687 # endif
1688 #endif
1689  break;
1690  }
1691 
1692  case BC_lrem: {
1693 #if !(SUPPORT_DIVISION && SUPPORT_LONG_DIV)
1695  OP_BUILTIN_ARITHMETIC(opcode, bte);
1696 #else
1697 # if SUPPORT_HARDWARE_DIVIDE_BY_ZERO
1698  OP(opcode);
1699 # else
1700  OP_CHECK_EXCEPTION(opcode);
1701 # endif
1702 #endif
1703  break;
1704  }
1705 
1706  case BC_frem: {
1707 #if defined(__I386__)
1708  OP(opcode);
1709 #else
1712 #endif
1713  break;
1714  }
1715 
1716  case BC_drem: {
1717 #if defined(__I386__)
1718  OP(opcode);
1719 #else
1722 #endif
1723  break;
1724  }
1725 
1726  case BC_f2i: {
1727 #if defined(__ALPHA__)
1730 #else
1731  OP(opcode);
1732 #endif
1733  break;
1734  }
1735 
1736  case BC_f2l: {
1737 #if defined(__ALPHA__)
1740 #else
1741  OP(opcode);
1742 #endif
1743  break;
1744  }
1745 
1746  case BC_d2i: {
1747 #if defined(__ALPHA__)
1750 #else
1751  OP(opcode);
1752 #endif
1753  break;
1754  }
1755 
1756  case BC_d2l: {
1757 #if defined(__ALPHA__)
1760 #else
1761  OP(opcode);
1762 #endif
1763  break;
1764  }
1765 
1766 
1767  /* invalid opcodes ****************************************************/
1768 
1769  /* check for invalid opcodes if the verifier is enabled */
1770 #if defined(ENABLE_VERIFIER)
1771  case BC_breakpoint:
1772  exceptions_throw_verifyerror(m, "Quick instructions shouldn't appear, yet.");
1773  return false;
1774 
1775 
1776  /* Unused opcodes ************************************************** */
1777 
1778  default:
1779  exceptions_throw_verifyerror(m, "Illegal opcode %d at instr %d\n",
1780  opcode, ircount);
1781  return false;
1782  break;
1783 #else
1784  default: break;
1785 #endif /* defined(ENABLE_VERIFIER) */
1786 
1787  /* opcodes that don't require translation *****************************/
1788  case BC_iaload:
1789  case BC_laload:
1790  case BC_faload:
1791  case BC_daload:
1792  case BC_aaload:
1793  case BC_baload:
1794  case BC_caload:
1795  case BC_saload:
1796  case BC_iastore:
1797  case BC_lastore:
1798  case BC_fastore:
1799  case BC_dastore:
1800  case BC_bastore:
1801  case BC_castore:
1802  case BC_sastore:
1803  case BC_pop:
1804  case BC_pop2:
1805  case BC_dup:
1806  case BC_iadd:
1807  case BC_ladd:
1808  case BC_fadd:
1809  case BC_dadd:
1810  case BC_isub:
1811  case BC_lsub:
1812  case BC_fsub:
1813  case BC_dsub:
1814  case BC_imul:
1815  case BC_lmul:
1816  case BC_fmul:
1817  case BC_dmul:
1818  case BC_fdiv:
1819  case BC_ddiv:
1820  case BC_ineg:
1821  case BC_lneg:
1822  case BC_fneg:
1823  case BC_dneg:
1824  case BC_ishl:
1825  case BC_lshl:
1826  case BC_ishr:
1827  case BC_lshr:
1828  case BC_iushr:
1829  case BC_lushr:
1830  case BC_iand:
1831  case BC_land:
1832  case BC_ior:
1833  case BC_lor:
1834  case BC_ixor:
1835  case BC_lxor:
1836  case BC_i2l:
1837  case BC_i2f:
1838  case BC_i2d:
1839  case BC_l2i:
1840  case BC_l2f:
1841  case BC_l2d:
1842  case BC_f2d:
1843  case BC_d2f:
1844  case BC_int2byte:
1845  case BC_int2char:
1846  case BC_int2short:
1847  case BC_lcmp:
1848  case BC_fcmpl:
1849  case BC_fcmpg:
1850  case BC_dcmpl:
1851  case BC_dcmpg:
1852  case BC_arraylength:
1853  case BC_impdep1:
1854  case BC_impdep2:
1855  /* Straight-forward translation to HIR. */
1856  OP(opcode);
1857  break;
1858  } /* end switch */
1859 
1860  /* verifier checks ****************************************************/
1861 
1862 #if defined(ENABLE_VERIFIER)
1863  /* If WIDE was used correctly, iswide should have been reset by now. */
1864  if (iswide) {
1865  exceptions_throw_verifyerror(m, "Illegal instruction: WIDE before incompatible opcode");
1866  return false;
1867  }
1868 #endif /* defined(ENABLE_VERIFIER) */
1869 
1870  } /* end for */
1871 
1872  if (JITDATA_HAS_FLAG_REORDER(jd)) {
1873  /* add a NOP to the last basic block */
1874 
1875  INSTRUCTIONS_CHECK(1);
1876  OP(ICMD_NOP);
1877  }
1878 
1879  /*** END OF LOOP **********************************************************/
1880 
1881  /* assert that we did not write more ICMDs than allocated */
1882 
1883  assert(ircount <= pd.instructionslength);
1884  assert(ircount == (iptr - pd.instructions));
1885 
1886  /*** verifier checks ******************************************************/
1887 
1888 #if defined(ENABLE_VERIFIER)
1889  if (bcindex != m->jcodelength) {
1891  "Command-sequence crosses code-boundary");
1892  return false;
1893  }
1894 
1895  if (!blockend) {
1896  exceptions_throw_verifyerror(m, "Falling off the end of the code");
1897  return false;
1898  }
1899 #endif /* defined(ENABLE_VERIFIER) */
1900 
1901  /*** setup the methodinfo, allocate stack and basic blocks ****************/
1902 
1903  /* identify basic blocks */
1904 
1905  /* check if first instruction is a branch target */
1906 
1907  if (pd.basicblockstart[0] == 1) {
1908  jd->branchtoentry = true;
1909  }
1910  else {
1911  /* first instruction always starts a basic block */
1912 
1913  iptr = pd.instructions;
1914 
1915  iptr->flags.bits |= INS_FLAG_BASICBLOCK;
1916  }
1917 
1918  /* Iterate over all bytecode instructions and set missing
1919  basic-block starts in IR instructions. */
1920 
1921  for (bcindex = 0; bcindex < m->jcodelength; bcindex++) {
1922  /* Does the current bytecode instruction start a basic
1923  block? */
1924 
1925  if (pd.basicblockstart[bcindex] == 1) {
1926 #if defined(ENABLE_VERIFIER)
1927  /* Check if this bytecode basic-block start at the
1928  beginning of a bytecode instruction. */
1929 
1930  if (pd.bytecodestart[bcindex] == 0) {
1932  "Branch into middle of instruction");
1933  return false;
1934  }
1935 #endif
1936 
1937  /* Get the IR instruction mapped to the bytecode
1938  instruction and set the basic block flag. */
1939 
1940  irindex = pd.bytecodemap[bcindex];
1941  iptr = pd.instructions + irindex;
1942 
1943  iptr->flags.bits |= INS_FLAG_BASICBLOCK;
1944  }
1945  }
1946 
1947  /* IR instruction index to basic-block index mapping */
1948 
1949  pd.instructionmap = (s4*) DumpMemory::allocate(sizeof(s4) * ircount);
1950  MZERO(pd.instructionmap, s4, ircount);
1951 
1952  /* Iterate over all IR instructions and count the basic blocks. */
1953 
1954  iptr = pd.instructions;
1955 
1956  bbcount = 0;
1957 
1958  for (s4 i = 0; i < ircount; i++, iptr++) {
1959  if (INSTRUCTION_STARTS_BASICBLOCK(iptr)) {
1960  /* store the basic-block number in the IR instruction
1961  map */
1962 
1963  pd.instructionmap[i] = bbcount;
1964 
1965  /* post-increment the basic-block count */
1966 
1967  bbcount++;
1968  }
1969  }
1970 
1971  /* Allocate basic block array (one more for end ipc). */
1972 
1973  jd->basicblocks = (basicblock*) DumpMemory::allocate(sizeof(basicblock) * (bbcount + 1));
1974  MZERO(jd->basicblocks, basicblock, bbcount + 1);
1975 
1976  /* Now iterate again over all IR instructions and initialize the
1977  basic block structures and, in the same loop, resolve the
1978  branch-target instruction indices to basic blocks. */
1979 
1980  iptr = pd.instructions;
1981  bptr = jd->basicblocks;
1982 
1983  bbcount = 0;
1984 
1985  for (s4 i = 0; i < ircount; i++, iptr++) {
1986  /* check for basic block */
1987 
1988  if (INSTRUCTION_STARTS_BASICBLOCK(iptr)) {
1989  /* intialize the basic block */
1990 
1991  BASICBLOCK_INIT(bptr, m);
1992 
1993  bptr->iinstr = iptr;
1994 
1995  if (bbcount > 0) {
1996  bptr[-1].icount = bptr->iinstr - bptr[-1].iinstr;
1997  }
1998 
1999  /* bptr->icount is set when the next block is allocated */
2000 
2001  bptr->nr = bbcount++;
2002  bptr++;
2003  bptr[-1].next = bptr;
2004  }
2005 
2006  /* resolve instruction indices to basic blocks */
2007 
2008  switch (iptr->opc) {
2009  case ICMD_IFEQ:
2010  case ICMD_IFLT:
2011  case ICMD_IFLE:
2012  case ICMD_IFNE:
2013  case ICMD_IFGT:
2014  case ICMD_IFGE:
2015  case ICMD_IFNULL:
2016  case ICMD_IFNONNULL:
2017  case ICMD_IF_ICMPEQ:
2018  case ICMD_IF_ICMPNE:
2019  case ICMD_IF_ICMPLT:
2020  case ICMD_IF_ICMPGT:
2021  case ICMD_IF_ICMPLE:
2022  case ICMD_IF_ICMPGE:
2023  case ICMD_IF_ACMPEQ:
2024  case ICMD_IF_ACMPNE:
2025  case ICMD_GOTO:
2027  break;
2028 
2029  case ICMD_JSR:
2030  BYTECODEINDEX_TO_BASICBLOCK(iptr->sx.s23.s3.jsrtarget);
2031  break;
2032 
2033  case ICMD_TABLESWITCH: {
2034  table = iptr->dst.table;
2035 
2037  table++;
2038 
2039  s4 j = iptr->sx.s23.s3.tablehigh - iptr->sx.s23.s2.tablelow + 1;
2040 
2041  while (--j >= 0) {
2043  table++;
2044  }
2045  break;
2046  }
2047 
2048  case ICMD_LOOKUPSWITCH: {
2049  BYTECODEINDEX_TO_BASICBLOCK(iptr->sx.s23.s3.lookupdefault);
2050 
2051  lookup = iptr->dst.lookup;
2052 
2053  s4 j = iptr->sx.s23.s2.lookupcount;
2054 
2055  while (--j >= 0) {
2057  lookup++;
2058  }
2059  break;
2060  }
2061  default:
2062  break;
2063  }
2064  }
2065 
2066  /* set instruction count of last real block */
2067 
2068  if (bbcount > 0) {
2069  bptr[-1].icount = (pd.instructions + ircount) - bptr[-1].iinstr;
2070  }
2071 
2072  /* allocate additional block at end */
2073 
2074  BASICBLOCK_INIT(bptr, m);
2075  bptr->nr = bbcount;
2076 
2077  /* set basicblock pointers in exception table */
2078 
2079  if (!parse_resolve_exception_table(jd, &pd))
2080  return false;
2081 
2082  /* store the local map */
2083 
2084  jd->local_map = local_map;
2085 
2086  /* calculate local variable renaming */
2087 
2088  {
2089  s4 nlocals = 0;
2090  s4 varindex;
2091  s4 *mapptr;
2092  s4 *reversemap;
2093 
2094  mapptr = local_map;
2095 
2096  /* iterate over local_map[0..m->maxlocals*5-1] and allocate a unique */
2097  /* variable index for each _used_ (javaindex,type) pair. */
2098  /* (local_map[javaindex*5+type] = cacaoindex) */
2099  /* Unused (javaindex,type) pairs are marked with UNUSED. */
2100 
2101  for (s4 i = 0; i < (m->maxlocals * 5); i++, mapptr++) {
2102  if (*mapptr)
2103  *mapptr = nlocals++;
2104  else
2105  *mapptr = jitdata::UNUSED;
2106  }
2107 
2108  jd->localcount = nlocals;
2109 
2110  /* calculate the (maximum) number of variables needed */
2111 
2112  jd->varcount =
2113  nlocals /* local variables */
2114  + bbcount * m->maxstack /* invars */
2115  + s_count; /* variables created within blocks (non-invar) */
2116 
2117  /* reserve the first indices for local variables */
2118 
2119  jd->vartop = nlocals;
2120 
2121  /* reserve extra variables needed by stack analyse */
2122 
2123  jd->varcount += STACK_EXTRA_VARS;
2124  jd->vartop += STACK_EXTRA_VARS;
2125 
2126  /* The verifier needs space for saving invars in some cases and */
2127  /* extra variables. */
2128 
2129 #if defined(ENABLE_VERIFIER)
2132 #endif
2133  /* allocate and initialize the variable array */
2134 
2135  jd->var = (varinfo*) DumpMemory::allocate(sizeof(varinfo) * jd->varcount);
2136  MZERO(jd->var, varinfo, jd->varcount);
2137 
2138  /* set types of all locals in jd->var */
2139  /* and fill the reverselocalmap */
2140 
2141  reversemap = (s4*) DumpMemory::allocate(sizeof(s4) * nlocals);
2142 
2143  for (s4 i = 0; i < m->maxlocals; i++)
2144  for (s4 t=0; t<5; t++) {
2145  varindex = local_map[5*i + t];
2146  if (varindex != jitdata::UNUSED) {
2147  VAR(varindex)->type = (Type) t;
2148  reversemap[varindex] = i;
2149  }
2150  }
2151 
2152  jd->reverselocalmap = reversemap;
2153  }
2154 
2155  /* assign local variables to method variables */
2156 
2157  jd->instructions = pd.instructions;
2158  jd->instructioncount = ircount;
2159  jd->basicblockcount = bbcount;
2160  jd->stackcount = s_count + bbcount * m->maxstack; /* in-stacks */
2161 
2162  /* allocate stack table */
2163 
2165 
2166  /* everything's ok */
2167 
2168  return true;
2169 
2170  /*** goto labels for throwing verifier exceptions *************************/
2171 
2172 #if defined(ENABLE_VERIFIER)
2173 
2174 throw_unexpected_end_of_bytecode:
2175  exceptions_throw_verifyerror(m, "Unexpected end of bytecode");
2176  return false;
2177 
2178 throw_invalid_bytecode_index:
2179  exceptions_throw_verifyerror(m, "Illegal target of branch instruction");
2180  return false;
2181 
2182 throw_illegal_local_variable_number:
2183  exceptions_throw_verifyerror(m, "Illegal local variable number");
2184  return false;
2185 
2186 #endif /* ENABLE_VERIFIER */
2187 }
2188 
2189 
2190 /*
2191  * These are local overrides for various environment variables in Emacs.
2192  * Please do not remove this and leave it at the end of the file, where
2193  * Emacs will automagically detect them.
2194  * ---------------------------------------------------------------------
2195  * Local variables:
2196  * mode: c++
2197  * indent-tabs-mode: t
2198  * c-basic-offset: 4
2199  * tab-width: 4
2200  * End:
2201  * vim:noexpandtab:sw=4:ts=4:
2202  */
void exceptions_throw_verifyerror(methodinfo *m, const char *message,...)
Definition: exceptions.cpp:973
#define OP(o)
Definition: parse.cpp:154
val_operand_t val
#define BUILTIN_f2l
Definition: builtin.hpp:303
static void parse_setup(jitdata *jd, parsedata_t *pd)
Definition: parse.cpp:335
s4 exceptiontablelength
Definition: jit.hpp:167
#define BUILTIN_d2i
Definition: builtin.hpp:311
official tags from JVM spec
Definition: global.hpp:164
basicblock * basicblocks
Definition: jit.hpp:141
Definition: jit.hpp:126
static bool parse_mark_exception_boundaries(jitdata *jd, parsedata_t *pd)
Definition: parse.cpp:438
void * class_getconstant(classinfo *c, u4 pos, ConstantPoolTag ctype)
Definition: class.cpp:679
#define BASICBLOCK_INIT(bptr, m)
Definition: jit.hpp:423
#define JITDATA_HAS_FLAG_REORDER(jd)
Definition: jit.hpp:212
s4 jcodelength
Definition: method.hpp:85
u1 * bytecodestart
Definition: parse.cpp:318
#define MSET(ptr, byte, type, num)
Definition: memory.hpp:104
unresolved_field * resolve_create_unresolved_field(classinfo *referer, methodinfo *refmethod, instruction *iptr)
Definition: resolve.cpp:2402
s4 localcount
Definition: jit.hpp:152
exception_entry * exceptiontable
Definition: jit.hpp:168
#define OP_S3_CLASSINFO_OR_CLASSREF(o, c, cr, extraflags)
Definition: parse.cpp:211
#define BUILTIN_newarray_float
Definition: builtin.hpp:186
s4 rawexceptiontablelength
Definition: method.hpp:88
#define OP_LOADCONST_I(v)
Definition: parse.cpp:162
basicblock * next
Definition: jit.hpp:337
#define INSTRUCTION_STARTS_BASICBLOCK(iptr)
#define OP_LOAD_TWOWORD(o, index, type)
Definition: parse.cpp:251
codeinfo * code
Definition: jit.hpp:128
#define OP_INSINDEX(o, iindex)
Definition: parse.cpp:223
u1 * cptags
Definition: class.hpp:95
unresolved_method * resolve_create_unresolved_method(classinfo *referer, methodinfo *refmethod, constant_FMIref *methodref, bool invokestatic, bool invokespecial)
Definition: resolve.cpp:2596
int32_t argcount
Definition: instruction.hpp:64
resolve_result_t resolve_field_lazy(methodinfo *refmethod, constant_FMIref *fieldref)
Definition: resolve.cpp:1261
varinfo * var
Definition: jit.hpp:148
bool resolve_classref(methodinfo *refmethod, constant_classref *ref, resolve_mode_t mode, bool checkaccess, bool link, classinfo **result)
Definition: resolve.cpp:309
#define OP_LOADCONST_CLASSINFO_OR_CLASSREF_CHECK(c, cr)
Definition: parse.cpp:205
s4 vartop
Definition: jit.hpp:149
#define OP_CHECK_EXCEPTION(o)
Definition: parse.cpp:158
#define OP_PREPARE_ZEROFLAGS(o)
Definition: parse.cpp:148
#define BUILTIN_newarray_long
Definition: builtin.hpp:196
methoddesc * md
Definition: references.hpp:75
#define OP_BUILTIN_ARITHMETIC(opcode, BTE)
Definition: parse.cpp:288
u2 startpc
Definition: method.hpp:157
uint8_t u1
Definition: types.hpp:40
static void code_unflag_leafmethod(codeinfo *code)
Definition: code.hpp:161
Breakpoint * get_breakpoint(int32_t location)
Definition: breakpoint.hpp:89
#define BUILTIN_newarray_char
Definition: builtin.hpp:184
int64_t s8
Definition: types.hpp:48
static instruction * parse_realloc_instructions(parsedata_t *pd, s4 icount, s4 n)
Definition: parse.cpp:385
lookup_target_t * lookup
#define OP_LOADCONST_NULL()
Definition: parse.cpp:182
instruction * iinstr
Definition: jit.hpp:319
#define VAR(i)
Definition: jit.hpp:252
Definition: reg.hpp:43
s4 icount
Definition: jit.hpp:318
u2 endpc
Definition: method.hpp:158
#define MZERO(ptr, type, num)
Definition: memory.hpp:105
#define BUILTIN_newarray_byte
Definition: builtin.hpp:190
#define OP_LOADCONST_CLASSINFO_OR_CLASSREF_NOCHECK(c, cr)
Definition: parse.cpp:208
#define OP_LOADCONST_F(v)
Definition: parse.cpp:172
stackelement_t * stack
Definition: jit.hpp:142
#define CHECK_BYTECODE_INDEX_EXCLUSIVE(i)
Definition: parse.cpp:96
s4 varcount
Definition: jit.hpp:151
#define BUILTIN_frem
Definition: builtin.hpp:270
raw_exception_entry * rawexceptiontable
Definition: method.hpp:89
s4 * bytecodemap
Definition: parse.cpp:321
#define OP_BUILTIN_NO_EXCEPTION(BTE)
Definition: parse.cpp:282
static basicblock * parse_bytecodeindex_to_basicblock(jitdata *jd, parsedata_t *pd, s4 bcindex)
Definition: parse.cpp:410
#define OP_PREPARE_FLAGS(o, f)
Definition: parse.cpp:143
builtintable_entry * builtintable_get_internal(functionptr fp)
Definition: builtin.cpp:275
resolve_result_t resolve_method_lazy(methodinfo *refmethod, constant_FMIref *methodref, bool invokespecial)
Definition: resolve.cpp:1950
#define STACK_EXTRA_VARS
Definition: global.hpp:375
#define CHECK_BYTECODE_INDEX(i)
Definition: parse.cpp:88
#define LOCALTYPE_USED(index, type)
Definition: parse.cpp:239
branch_target_t target
Definition: instruction.hpp:57
dst_operand_t dst
#define OP_LOAD_ONEWORD(o, index, type)
Definition: parse.cpp:244
flags_operand_t flags
s4 instructionslength
Definition: parse.cpp:324
uint16_t u2
Definition: types.hpp:43
#define BUILTIN_drem
Definition: builtin.hpp:287
#define LOCK_monitor_enter
Definition: builtin.hpp:124
u2 handlerpc
Definition: method.hpp:159
classinfo * clazz
Definition: method.hpp:80
u1 * basicblockstart
Definition: parse.cpp:319
basicblock * start
Definition: jit.hpp:234
static uint8_t read_u1_be(const uint8_t *src)
read uint8_t from pointer big endian
Definition: endianess.hpp:93
This file contains the statistics framework.
Definition: method.hpp:155
basicblock * handler
Definition: jit.hpp:236
bool checksync
Definition: options.cpp:90
#define INSTRUCTIONS_CHECK(i)
Definition: parse.cpp:119
#define OP_LOCALINDEX_I(o, index, v)
Definition: parse.cpp:233
#define BUILTIN_newarray_boolean
Definition: builtin.hpp:182
static void * reallocate(void *src, size_t len1, size_t len2)
Stupid realloc implementation for dump memory.
Definition: dumpmemory.cpp:57
#define JITDATA_HAS_FLAG_VERIFY(jd)
Definition: jit.hpp:203
exception_entry * next
Definition: jit.hpp:238
Type
Types used internally by JITTED code.
Definition: global.hpp:117
#define OP_LOADCONST_L(v)
Definition: parse.cpp:167
#define OP_BUILTIN_CHECK_EXCEPTION(BTE)
Definition: parse.cpp:276
static int16_t read_s2_be(const uint8_t *src)
read int16_t from pointer big endian
Definition: endianess.hpp:129
classref_or_classinfo catchtype
Definition: jit.hpp:237
u2 linenumbercount
Definition: method.hpp:94
#define BUILTIN_new
Definition: builtin.hpp:163
bool contains(int32_t location)
Definition: breakpoint.hpp:77
s4 * local_map
Definition: jit.hpp:153
u1 * jcode
Definition: method.hpp:86
s4 maxstack
Definition: method.hpp:83
#define VERIFIER_EXTRA_LOCALS
Definition: global.hpp:373
MIIterator i
Fieldref, Methodref and InterfaceMethodref.
Definition: references.hpp:86
bool branchtoentry
Definition: jit.hpp:173
int32_t s4
Definition: types.hpp:45
#define BUILTIN_newarray
Definition: builtin.hpp:179
s4 cpcount
Definition: class.hpp:94
s4 maxlocals
Definition: method.hpp:84
static uint16_t read_u2_be(const uint8_t *src)
read uint16_t from pointer big endian
Definition: endianess.hpp:98
#define OP_STORE_ONEWORD(o, index, type)
Definition: parse.cpp:258
union instruction::@12 sx
#define BUILTIN_arrayinstanceof
Definition: builtin.hpp:146
#define BUILTIN_newarray_int
Definition: builtin.hpp:194
s4 instructioncount
Definition: jit.hpp:143
exception_entry * down
Definition: jit.hpp:240
#define OP_LOADCONST_D(v)
Definition: parse.cpp:177
void params_from_paramtypes(s4 mflags)
Definition: descriptor.cpp:877
#define LOCK_monitor_exit
Definition: builtin.hpp:132
#define INSTRUCTIONS_INCREMENT
Definition: parse.cpp:300
static bool parse_resolve_exception_table(jitdata *jd, parsedata_t *pd)
Definition: parse.cpp:517
instruction * instructions
Definition: parse.cpp:323
#define PINC
Definition: parse.cpp:140
s1_operand_t s1
uint32_t u4
Definition: types.hpp:46
#define BUILTIN_newarray_double
Definition: builtin.hpp:188
u2 line_number
Definition: method.hpp:167
#define BUILTIN_ldiv
Definition: builtin.hpp:234
#define MARK_BASICBLOCK(pd, i)
Definition: parse.cpp:114
Definition: builtin.hpp:60
methodinfo * m
Definition: jit.hpp:127
#define OP_LOADCONST_STRING(v)
Definition: parse.cpp:187
#define BUILTIN_idiv
Definition: builtin.hpp:222
u2 start_pc
Definition: method.hpp:166
#define BUILTIN_irem
Definition: builtin.hpp:224
ByteCode
Definition: bytecode.hpp:47
basicblock * end
Definition: jit.hpp:235
bool parse(jitdata *jd)
Definition: parse.cpp:604
#define BUILTIN_newarray_short
Definition: builtin.hpp:192
int length
Definition: bytecode.hpp:37
static void * allocate(size_t size)
Definition: dumpmemory.hpp:251
#define MEMORY_ALIGN(pos, size)
Definition: memory.hpp:37
s4 nr
Definition: jit.hpp:312
s4 basicblockcount
Definition: jit.hpp:144
bool resolve_classref_or_classinfo(methodinfo *refmethod, classref_or_classinfo cls, resolve_mode_t mode, bool checkaccess, bool link, classinfo **result)
Definition: resolve.cpp:351
bool branchtoend
Definition: jit.hpp:174
struct instruction::@12::@13 s23
void ** cpinfos
Definition: class.hpp:96
const parseddesc_t parseddesc
Definition: references.hpp:105
lineinfo * linenumbers
Definition: method.hpp:95
BeginInst * target
BreakpointTable * breakpoints
Definition: method.hpp:112
#define BYTECODEINDEX_TO_BASICBLOCK(dst)
Definition: parse.cpp:306
Definition: jit.hpp:233
#define INDEX_ONEWORD(num)
Definition: parse.cpp:73
bytecode_t bytecode[256]
Definition: bytecode.cpp:33
s4 stackcount
Definition: jit.hpp:145
s4 flags
Definition: method.hpp:70
#define OP_STORE_TWOWORD(o, index, type)
Definition: parse.cpp:267
static int32_t read_s4_be(const uint8_t *src)
read int32_t from pointer big endian
Definition: endianess.hpp:132
s4 * instructionmap
Definition: parse.cpp:326
static JavaString literal(Utf8String)
Definition: string.cpp:257
instruction * instructions
Definition: jit.hpp:140
resolve_result_t
Definition: resolve.hpp:67
const Utf8String name
Definition: references.hpp:48
branch_target_t * table
#define CHECK_END_OF_BYTECODE(neededlength)
Definition: parse.cpp:595
#define BUILTIN_d2l
Definition: builtin.hpp:315
s4 * reverselocalmap
Definition: jit.hpp:159
constant_classref * class_get_classref_multiarray_of(s4 dim, constant_classref *ref)
Definition: class.cpp:1038
static uint32_t read_u4_be(const uint8_t *src)
read uint32_t from pointer big endian
Definition: endianess.hpp:104
#define VERIFIER_EXTRA_VARS
Definition: global.hpp:374
static int8_t read_s1_be(const uint8_t *src)
read int8_t from pointer big endian
Definition: endianess.hpp:126
#define BUILTIN_f2i
Definition: builtin.hpp:299
#define BUILTIN_lrem
Definition: builtin.hpp:236