CACAO
global.hpp
Go to the documentation of this file.
1 /* src/vm/global.hpp - global definitions
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 
26 #ifndef GLOBAL_HPP_
27 #define GLOBAL_HPP_ 1
28 
29 #include "config.h"
30 
31 #include <stdbool.h>
32 #include <stdint.h>
33 
34 #include "vm/types.hpp"
35 
36 
37 /* additional data types ******************************************************/
38 
39 typedef void (*functionptr) (void); /* generic function pointer */
40 typedef u1* methodptr;
41 
42 #if defined(ENABLE_SSA)
43 /* immediate to get an addidional target Local Var Index */
44 /* for IINC in Combination with SSA */
45 struct imm {
46  s4 i;
47  s4 op1_t;
48 };
49 #endif
50 
51 /* immediate data union */
52 
53 typedef union {
54  s4 i;
55  s8 l;
56  float f;
57  double d;
58  void *a;
60  u1 b[8];
61 #if defined(ENABLE_SSA)
62  struct imm _i;
63 #endif
64 } imm_union;
65 
66 
67 /* alignment macros ***********************************************************/
68 
69 #define ALIGN_EVEN(a) ((a) = (((a) + 1) & ~1))
70 #define ALIGN_ODD(a) ((a) = (a) | 1 )
71 
72 #define ALIGN_2(a) ALIGN_EVEN(a)
73 
74 
75 /* printf format defines ******************************************************/
76 
77 /* Define printf formats which change size between 32- and 64-bit. */
78 
79 #if SIZEOF_VOID_P == 8
80 # define PRINTF_INTPTR_NUM_HEXDIGITS "16"
81 #else
82 # define PRINTF_INTPTR_NUM_HEXDIGITS "8"
83 #endif
84 
85 
86 /* convenience macros *********************************************************/
87 
88 /* Makes a string of the argument (which is not macro-expanded). */
89 
90 #define STR(a) #a
91 
92 /* There are multiple definitions of MIN out there, but we cannot be sure. */
93 
94 #ifndef MIN
95 # define MIN(a,b) (((a) < (b)) ? (a) : (b))
96 #endif
97 
98 #ifndef MAX
99 # define MAX(a,b) (((a) > (b)) ? (a) : (b))
100 #endif
101 
102 #define MAX_ALIGN 8 /* most generic alignment for JavaVM values */
103 
104 
105 /* basic data types ***********************************************************/
106 
107 /**
108  * Types used internally by JITTED code.
109  *
110  * The JavaVM types must numbered in the same order as the ICMD_Ixxx
111  * to ICMD_Axxx instructions (LOAD and STORE). All other types can be
112  * numbered arbitrarily.
113  *
114  * @Cpp11 Use an enum class for better scoping and control over
115  * storage type.
116  */
117 enum Type {
118  TYPE_INT = 0,
119  TYPE_LNG = 1,
120  TYPE_FLT = 2,
121  TYPE_DBL = 3,
122  TYPE_ADR = 4,
123 
124  TYPE_RET = 8, // must not share bits with TYPE_FLT or TYPE_LNG
125 
127 };
128 
129 
130 #define IS_INT_LNG_TYPE(a) (!((a) & TYPE_FLT))
131 #define IS_FLT_DBL_TYPE(a) ((a) & TYPE_FLT)
132 #define IS_2_WORD_TYPE(a) ((a) & TYPE_LNG)
133 
134 #define IS_INT_TYPE(a) ((a) == TYPE_INT)
135 #define IS_LNG_TYPE(a) ((a) == TYPE_LNG)
136 #define IS_FLT_TYPE(a) ((a) == TYPE_FLT)
137 #define IS_DBL_TYPE(a) ((a) == TYPE_DBL)
138 #define IS_ADR_TYPE(a) ((a) == TYPE_ADR)
139 
140 #define IS_VOID_TYPE(a) ((a) == TYPE_VOID)
141 
142 
143 /* some Java related defines **************************************************/
144 
145 #define JAVA_VERSION "1.6.0" /* this version is supported by CACAO */
146 #define CLASS_VERSION "51.0"
147 
148 /* Java class file constants **************************************************/
149 
150 #define MAGIC 0xCAFEBABE
151 #define MAJOR_VERSION 51
152 #define MINOR_VERSION 0
153 
154 
155 /* Constant pool tags *********************************************************/
156 
157 /**
158  * Types for entries of a classes constant pool
159  *
160  * @Cpp11 Use an enum class and set storage type to uint8_t
161  */
163  /// official tags from JVM spec
178 
179  /// internally used tags
180  CONSTANT_ClassName = 19, // used in loader before classrefs are created
182 };
183 
184 
185 /* Class/Field/Method access and property flags *******************************/
186 
187 enum {
188  ACC_UNDEF = -1, // used internally
189  ACC_NONE = 0, // used internally
190 
191  ACC_PUBLIC = 0x0001,
192  ACC_PRIVATE = 0x0002,
193  ACC_PROTECTED = 0x0004,
194  ACC_STATIC = 0x0008,
195  ACC_FINAL = 0x0010,
196  ACC_SUPER = 0x0020,
198  ACC_VOLATILE = 0x0040,
199  ACC_BRIDGE = 0x0040,
200  ACC_TRANSIENT = 0x0080,
201  ACC_VARARGS = 0x0080,
202  ACC_NATIVE = 0x0100,
203  ACC_INTERFACE = 0x0200,
204  ACC_ABSTRACT = 0x0400,
205  ACC_STRICT = 0x0800,
206  ACC_SYNTHETIC = 0x1000,
207  ACC_ANNOTATION = 0x2000,
208  ACC_ENUM = 0x4000,
209  ACC_MIRANDA = 0x8000
210 };
211 
212 /* special flags used in classinfo ********************************************/
213 
214 enum ClassFlag {
215  ACC_CLASS_REFLECT_MASK = 0x0000ffff, // flags reported by reflection
216 
217  ACC_CLASS_PRIMITIVE = 0x00010000,
218  ACC_CLASS_MEMBER = 0x00020000,
219  ACC_CLASS_ANONYMOUS = 0x00040000,
220 
221  ACC_CLASS_HAS_POINTERS = 0x00080000, // instance contains pointers
222 
227 };
228 
229 /* special flags used in methodinfo *******************************************/
230 
232  ACC_METHOD_BUILTIN = 0x00010000, // use for descriptor parsing
233  ACC_METHOD_IMPLEMENTED = 0x00020000, // there is an implementation
234  ACC_METHOD_MONOMORPHIC = 0x00040000, // currently monomorphic method
235  ACC_METHOD_EA = 0x00080000, // method being escape analyzed
238 };
239 
240 /* data structures of the runtime system **************************************/
241 
242 /* java_object_t **************************************************************/
243 
244 /**
245  * All objects (and arrays) which resides on the heap need the
246  * following header at the beginning of the data structure.
247  *
248  * TODO: Include detailed description from the Wiki (ObjectHeader) here.
249  *
250  * @Cpp11 Use an enum class for better scoping.
251  */
259 };
260 
261 struct vftbl_t;
262 
263 struct java_object_t { /* header for all objects */
264  vftbl_t *vftbl; /* pointer to virtual function table */
265  uintptr_t lockword;
266 #if defined(ENABLE_GC_CACAO)
267  uintptr_t hdrflags; /* word containing the GC bits */
268 #endif
269 #if defined(ENABLE_ESCAPE_CHECK)
270  void *method;
271  void *thread;
272  uintptr_t escape;
273 #endif
274 };
275 
276 
277 /* arrays **********************************************************************
278 
279  All arrays are objects (they need the object header with a pointer
280  to a vftbl (array class table). There is one class for each array
281  type. The array type is described by an arraydescriptor struct
282  which is referenced by the vftbl.
283 */
284 
285 typedef struct java_array_t { /* header for all arrays */
286  java_object_t objheader; /* object header */
287  s4 size; /* array size */
288 } java_array_t;
289 
290 
291 
292 /* structs for all kinds of arrays ********************************************/
293 
294 /* booleanarray and bytearray need identical memory layout (access methods
295  use the same machine code */
296 
297 typedef struct java_booleanarray_t {
299  u1 data[1];
301 
302 typedef struct java_bytearray_t {
304  s1 data[1];
306 
307 typedef struct java_chararray_t {
309  u2 data[1];
311 
312 typedef struct java_shortarray_t {
314  s2 data[1];
316 
317 typedef struct java_intarray_t {
319  s4 data[1];
321 
322 typedef struct java_longarray_t {
324  s8 data[1];
326 
327 typedef struct java_floatarray_t {
329  float data[1];
331 
332 typedef struct java_doublearray_t {
334  double data[1];
336 
337 /* objectarray and arrayarray need identical memory layout (access methods
338  use the same machine code */
339 
343 };
344 
345 
346 /* java_handle_t ***************************************************************
347 
348  TODO: document me!
349 
350 *******************************************************************************/
351 
363 
364 
365 /* global constants related to the verifier ***********************************/
366 
367 /* The verifier needs additional variables in the variable array. Since these */
368 /* must be reserved and set by parse.c and stack.c, we define these numbers */
369 /* here to avoid mysterious hard-coded constants. */
370 /* stack.c needs an extra variable if the verifier is disabled. */
371 
372 #if defined(ENABLE_VERIFIER)
373 # define VERIFIER_EXTRA_LOCALS 1
374 # define VERIFIER_EXTRA_VARS 1
375 # define STACK_EXTRA_VARS 0
376 #else
377 # define VERIFIER_EXTRA_LOCALS 0
378 # define VERIFIER_EXTRA_VARS 0
379 # define STACK_EXTRA_VARS 1
380 #endif
381 
382 #endif // GLOBAL_HPP_
383 
384 /*
385  * These are local overrides for various environment variables in Emacs.
386  * Please do not remove this and leave it at the end of the file, where
387  * Emacs will automagically detect them.
388  * ---------------------------------------------------------------------
389  * Local variables:
390  * mode: c++
391  * indent-tabs-mode: t
392  * c-basic-offset: 4
393  * tab-width: 4
394  * End:
395  * vim:noexpandtab:sw=4:ts=4:
396  */
float data[1]
Definition: global.hpp:329
java_object_t java_handle_t
Definition: global.hpp:352
java_object_t * data[1]
Definition: global.hpp:342
ConstantPoolTag
Types for entries of a classes constant pool.
Definition: global.hpp:162
float f
Definition: global.hpp:56
official tags from JVM spec
Definition: global.hpp:164
java_array_t header
Definition: global.hpp:341
struct java_bytearray_t java_bytearray_t
double d
Definition: global.hpp:57
struct java_booleanarray_t java_booleanarray_t
java_array_t header
Definition: global.hpp:303
void * a
Definition: global.hpp:58
struct java_longarray_t java_longarray_t
java_handle_t java_handle_array_t
Definition: global.hpp:353
uintptr_t lockword
Definition: global.hpp:265
struct java_shortarray_t java_shortarray_t
java_handle_array_t java_handle_longarray_t
Definition: global.hpp:360
typedef void(JNICALL *jvmtiEventSingleStep)(jvmtiEnv *jvmti_env
uint8_t u1
Definition: types.hpp:40
u1 * methodptr
Definition: global.hpp:40
java_array_t header
Definition: global.hpp:323
int64_t s8
Definition: types.hpp:48
java_handle_array_t java_handle_objectarray_t
Definition: global.hpp:354
java_handle_array_t java_handle_booleanarray_t
Definition: global.hpp:355
void(* functionptr)(void)
Definition: global.hpp:39
java_handle_array_t java_handle_floatarray_t
Definition: global.hpp:361
struct java_doublearray_t java_doublearray_t
JNIEnv jthread jmethodID method
Definition: jvmti.h:207
uint16_t u2
Definition: types.hpp:43
internally used tags
Definition: global.hpp:180
MethodFlag
Definition: global.hpp:231
HeaderFlag
All objects (and arrays) which resides on the heap need the following header at the beginning of the ...
Definition: global.hpp:252
Type
Types used internally by JITTED code.
Definition: global.hpp:117
struct java_chararray_t java_chararray_t
java_array_t header
Definition: global.hpp:328
JNIEnv jthread thread
Definition: jvmti.h:207
java_handle_array_t java_handle_chararray_t
Definition: global.hpp:357
MIIterator i
int32_t s4
Definition: types.hpp:45
java_object_t objheader
Definition: global.hpp:286
java_handle_array_t java_handle_shortarray_t
Definition: global.hpp:358
java_handle_array_t java_handle_intarray_t
Definition: global.hpp:359
java_array_t header
Definition: global.hpp:318
java_handle_array_t java_handle_bytearray_t
Definition: global.hpp:356
java_handle_array_t java_handle_doublearray_t
Definition: global.hpp:362
java_array_t header
Definition: global.hpp:333
int8_t s1
Definition: types.hpp:39
struct java_floatarray_t java_floatarray_t
int16_t s2
Definition: types.hpp:42
functionptr fp
Definition: global.hpp:59
java_array_t header
Definition: global.hpp:313
struct java_intarray_t java_intarray_t
java_array_t header
Definition: global.hpp:308
double data[1]
Definition: global.hpp:334
vftbl_t * vftbl
Definition: global.hpp:264
ClassFlag
Definition: global.hpp:214
java_array_t header
Definition: global.hpp:298
struct java_array_t java_array_t