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