* src/vm/jit/codegen-common.cpp, src/vm/jit/x86_64/codegen.c: Generate
[cacao.git] / src / vm / global.h
1 /* src/vm/global.h - global definitions
2
3    Copyright (C) 1996-2005, 2006, 2007, 2008
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_H
27 #define _GLOBAL_H
28
29 #include "config.h"
30
31 #include <stdbool.h>
32 #include <stdint.h>
33
34 #include "vm/types.h"
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;
59         functionptr fp;
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_FORMAT_INTPTR_T   "0x%016lx"
81 # define PRINTF_FORMAT_INT64_T    "%ld"
82 #else
83 # define PRINTF_FORMAT_INTPTR_T   "0x%08lx"
84 # define PRINTF_FORMAT_INT64_T    "%lld"
85 #endif
86
87
88 /* convenience macros *********************************************************/
89
90 /* Makes a string of the argument (which is not macro-expanded). */
91
92 #define STR(a)  #a
93
94 /* There are multiple definitions of MIN out there, but we cannot be sure. */
95
96 #ifndef MIN
97 # define MIN(a,b)  (((a) < (b)) ? (a) : (b))
98 #endif
99
100
101 /* forward typedefs ***********************************************************/
102
103 typedef struct java_object_t java_object_t; 
104 typedef struct java_objectarray_t java_objectarray_t;
105
106
107 #define MAX_ALIGN 8             /* most generic alignment for JavaVM values   */
108
109
110 /* basic data types ***********************************************************/
111
112 /* The JavaVM types must numbered in the same order as the ICMD_Ixxx
113    to ICMD_Axxx instructions (LOAD and STORE).  All other types can be
114    numbered arbitrarily. */
115
116 #define TYPE_INT     0
117 #define TYPE_LNG     1
118 #define TYPE_FLT     2
119 #define TYPE_DBL     3
120 #define TYPE_ADR     4
121
122 #define TYPE_RET     8   /* must not share bits with TYPE_FLT or TYPE_LNG */
123
124 #define TYPE_VOID    10
125
126
127 #define IS_INT_LNG_TYPE(a)      (!((a) & TYPE_FLT))
128 #define IS_FLT_DBL_TYPE(a)      ((a) & TYPE_FLT)
129 #define IS_2_WORD_TYPE(a)       ((a) & TYPE_LNG)
130
131 #define IS_INT_TYPE(a)          ((a) == TYPE_INT)
132 #define IS_LNG_TYPE(a)          ((a) == TYPE_LNG)
133 #define IS_FLT_TYPE(a)          ((a) == TYPE_FLT)
134 #define IS_DBL_TYPE(a)          ((a) == TYPE_DBL)
135 #define IS_ADR_TYPE(a)          ((a) == TYPE_ADR)
136
137 #define IS_VOID_TYPE(a)         ((a) == TYPE_VOID)
138
139
140 /* some Java related defines **************************************************/
141
142 #define JAVA_VERSION    "1.5.0"         /* this version is supported by CACAO */
143 #define CLASS_VERSION   "50.0"
144
145
146 /* Java class file constants **************************************************/
147
148 #define MAGIC             0xCAFEBABE
149 #define MAJOR_VERSION     50
150 #define MINOR_VERSION     0
151
152
153 /* Constant pool tags *********************************************************/
154
155 #define CONSTANT_Class                 7
156 #define CONSTANT_Fieldref              9
157 #define CONSTANT_Methodref            10
158 #define CONSTANT_InterfaceMethodref   11
159 #define CONSTANT_String                8
160 #define CONSTANT_Integer               3
161 #define CONSTANT_Float                 4
162 #define CONSTANT_Long                  5
163 #define CONSTANT_Double                6
164 #define CONSTANT_NameAndType          12
165 #define CONSTANT_Utf8                  1
166
167 #define CONSTANT_UNUSED                0
168
169
170 /* Class/Field/Method access and property flags *******************************/
171
172 #define ACC_UNDEF               -1      /* used internally                    */
173 #define ACC_NONE                 0      /* used internally                    */
174
175 #define ACC_PUBLIC          0x0001
176 #define ACC_PRIVATE         0x0002
177 #define ACC_PROTECTED       0x0004
178 #define ACC_STATIC          0x0008
179 #define ACC_FINAL           0x0010
180 #define ACC_SUPER           0x0020
181 #define ACC_SYNCHRONIZED    0x0020
182 #define ACC_VOLATILE        0x0040
183 #define ACC_BRIDGE          0x0040
184 #define ACC_TRANSIENT       0x0080
185 #define ACC_VARARGS         0x0080
186 #define ACC_NATIVE          0x0100
187 #define ACC_INTERFACE       0x0200
188 #define ACC_ABSTRACT        0x0400
189 #define ACC_STRICT          0x0800
190 #define ACC_SYNTHETIC       0x1000
191 #define ACC_ANNOTATION      0x2000
192 #define ACC_ENUM            0x4000
193 #define ACC_MIRANDA         0x8000
194
195 /* special flags used in classinfo ********************************************/
196
197 #define ACC_CLASS_REFLECT_MASK      0x0000ffff/* flags reported by reflection */
198
199 #define ACC_CLASS_PRIMITIVE         0x00010000
200 #define ACC_CLASS_MEMBER            0x00020000
201 #define ACC_CLASS_ANONYMOUS         0x00040000
202
203 #define ACC_CLASS_HAS_POINTERS      0x00080000/* instance contains pointers   */
204
205 #define ACC_CLASS_REFERENCE_MASK    0x00700000
206 #define ACC_CLASS_REFERENCE_SOFT    0x00100000
207 #define ACC_CLASS_REFERENCE_WEAK    0x00200000
208 #define ACC_CLASS_REFERENCE_PHANTOM 0x00400000
209
210
211 /* special flags used in methodinfo *******************************************/
212
213 #define ACC_METHOD_BUILTIN     0x00010000     /* use for descriptor parsing   */
214 #define ACC_METHOD_IMPLEMENTED 0x00020000     /* there is an implementation   */
215 #define ACC_METHOD_MONOMORPHIC 0x00040000     /* currently monomorphic method */
216 #define ACC_METHOD_EA          0x00080000     /* method being escape analyzed */
217 #define ACC_METHOD_MONOMORPHY_USED \
218                                0x00100000
219 #define ACC_METHOD_PARENT_MONOMORPHY_USED \
220                                0x00200000
221
222
223 /* data structures of the runtime system **************************************/
224
225 /* java_object_t ***************************************************************
226
227    All objects (and arrays) which resides on the heap need the
228    following header at the beginning of the data structure.
229
230    TODO: Include detailed description from the Wiki (ObjectHeader) here.
231
232 *******************************************************************************/
233
234 #define HDRFLAG_MARK1         0x02
235 #define HDRFLAG_MARK2         0x04
236 #define HDRFLAG_UNCOLLECTABLE 0x08
237 #define HDRFLAG_HASH_TAKEN    0x10
238 #define HDRFLAG_HASH_ATTACHED 0x20
239 #define HDRFLAG_REFERENCING   0x40
240
241 #include "threads/lockword.hpp"
242
243 struct java_object_t {                 /* header for all objects              */
244         struct _vftbl *vftbl;              /* pointer to virtual function table   */
245 #if defined(ENABLE_THREADS)
246         Lockword       lockword;
247 #endif
248 #if defined(ENABLE_GC_CACAO)
249         uintptr_t      hdrflags;           /* word containing the GC bits         */
250 #endif
251 #if defined(ENABLE_ESCAPE_CHECK)
252         void *method;
253         void *thread;
254         uintptr_t escape;
255 #endif
256 };
257
258
259 /* arrays **********************************************************************
260
261         All arrays are objects (they need the object header with a pointer
262         to a vftbl (array class table). There is one class for each array
263         type. The array type is described by an arraydescriptor struct
264         which is referenced by the vftbl.
265 */
266
267 typedef struct java_array_t {           /* header for all arrays              */
268         java_object_t objheader;            /* object header                      */
269         s4 size;                            /* array size                         */
270 } java_array_t;
271
272
273
274 /* structs for all kinds of arrays ********************************************/
275
276 /*  booleanarray and bytearray need identical memory layout (access methods
277     use the same machine code */
278
279 typedef struct java_booleanarray_t {
280         java_array_t header;
281         u1 data[1];
282 } java_booleanarray_t;
283
284 typedef struct java_bytearray_t {
285         java_array_t header;
286         s1 data[1];
287 } java_bytearray_t;
288
289 typedef struct java_chararray_t {
290         java_array_t header;
291         u2 data[1];
292 } java_chararray_t;
293
294 typedef struct java_shortarray_t {
295         java_array_t header;
296         s2 data[1];
297 } java_shortarray_t;
298
299 typedef struct java_intarray_t {
300         java_array_t header;
301         s4 data[1];
302 } java_intarray_t;
303
304 typedef struct java_longarray_t {
305         java_array_t header;
306         s8 data[1];
307 } java_longarray_t;
308
309 typedef struct java_floatarray_t {
310         java_array_t header;
311         float data[1];
312 } java_floatarray_t;
313
314 typedef struct java_doublearray_t {
315         java_array_t header;
316         double data[1];
317 } java_doublearray_t;
318
319 /*  objectarray and arrayarray need identical memory layout (access methods
320     use the same machine code */
321
322 struct java_objectarray_t {
323         java_array_t   header;
324         java_object_t *data[1];
325 };
326
327
328 /* java_handle_t ***************************************************************
329
330    TODO: document me!
331
332 *******************************************************************************/
333
334 typedef java_object_t       java_handle_t;
335 typedef java_handle_t       java_handle_array_t;
336 typedef java_handle_array_t java_handle_objectarray_t;
337 typedef java_handle_array_t java_handle_booleanarray_t;
338 typedef java_handle_array_t java_handle_bytearray_t;
339 typedef java_handle_array_t java_handle_chararray_t;
340 typedef java_handle_array_t java_handle_shortarray_t;
341 typedef java_handle_array_t java_handle_intarray_t;
342 typedef java_handle_array_t java_handle_longarray_t;
343 typedef java_handle_array_t java_handle_floatarray_t;
344 typedef java_handle_array_t java_handle_doublearray_t;
345
346
347 /* global constants related to the verifier ***********************************/
348
349 /* The verifier needs additional variables in the variable array. Since these */
350 /* must be reserved and set by parse.c and stack.c, we define these numbers   */
351 /* here to avoid mysterious hard-coded constants.                             */
352 /* stack.c needs an extra variable if the verifier is disabled.               */
353
354 #if defined(ENABLE_VERIFIER)
355 #    define VERIFIER_EXTRA_LOCALS  1
356 #    define VERIFIER_EXTRA_VARS    1
357 #    define STACK_EXTRA_VARS       0
358 #else
359 #    define VERIFIER_EXTRA_LOCALS  0
360 #    define VERIFIER_EXTRA_VARS    0
361 #    define STACK_EXTRA_VARS       1
362 #endif
363
364 #endif /* _GLOBAL_H */
365
366
367 /*
368  * These are local overrides for various environment variables in Emacs.
369  * Please do not remove this and leave it at the end of the file, where
370  * Emacs will automagically detect them.
371  * ---------------------------------------------------------------------
372  * Local variables:
373  * mode: c
374  * indent-tabs-mode: t
375  * c-basic-offset: 4
376  * tab-width: 4
377  * End:
378  * vim:noexpandtab:sw=4:ts=4:
379  */