* src/threads/native/lock.c: Implemented Sable extension to tasuki lock.
[cacao.git] / src / vm / global.h
1 /* src/vm/global.h - global definitions
2
3    Copyright (C) 1996-2005, 2007, 2006 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25 */
26
27
28 #ifndef _GLOBAL_H
29 #define _GLOBAL_H
30
31 #include "config.h"
32
33 #include <stdint.h>
34
35 #include "vm/types.h"
36
37
38 /* additional data types ******************************************************/
39
40 typedef void *voidptr;                  /* generic pointer                    */
41 typedef void (*functionptr) (void);     /* generic function pointer           */
42 typedef u1* methodptr;
43
44 typedef unsigned int bool;              /* boolean data type                  */
45
46 #define true         1
47 #define false        0
48
49
50 #if defined(ENABLE_SSA)
51 /* immediate to get an addidional target Local Var Index */
52 /* for IINC in Combination with SSA */
53 struct imm {
54         s4 i;
55         s4 op1_t;
56 };
57 #endif
58
59 /* immediate data union */
60
61 typedef union {
62         s4          i;
63         s8          l;
64         float       f;
65         double      d;
66         void       *a;
67         functionptr fp;
68         u1          b[8];
69 #if defined(ENABLE_SSA)
70         struct imm  _i;
71 #endif
72 } imm_union;
73
74
75 /* alignment macros ***********************************************************/
76
77 #define ALIGN_EVEN(a)                   ((a) = (((a) + 1) & ~1))
78 #define ALIGN_ODD(a)                    ((a) =   (a) | 1       )
79
80 #define ALIGN_2(a)                      ALIGN_EVEN(a)
81
82
83 /* forward typedefs ***********************************************************/
84
85 typedef struct java_object_t java_object_t; 
86 typedef struct java_objectarray_t java_objectarray_t;
87
88
89 #define MAX_ALIGN 8             /* most generic alignment for JavaVM values   */
90
91
92 /* basic data types ***********************************************************/
93
94 /* The JavaVM types must numbered in the same order as the ICMD_Ixxx
95    to ICMD_Axxx instructions (LOAD and STORE).  All other types can be
96    numbered arbitrarily. */
97
98 #define TYPE_INT     0
99 #define TYPE_LNG     1
100 #define TYPE_FLT     2
101 #define TYPE_DBL     3
102 #define TYPE_ADR     4
103
104 #define TYPE_RET     8   /* must not share bits with TYPE_FLT or TYPE_LNG */
105
106 #define TYPE_VOID    10
107
108
109 #define IS_INT_LNG_TYPE(a)      (!((a) & TYPE_FLT))
110 #define IS_FLT_DBL_TYPE(a)      ((a) & TYPE_FLT)
111 #define IS_2_WORD_TYPE(a)       ((a) & TYPE_LNG)
112
113 #define IS_INT_TYPE(a)          ((a) == TYPE_INT)
114 #define IS_LNG_TYPE(a)          ((a) == TYPE_LNG)
115 #define IS_FLT_TYPE(a)          ((a) == TYPE_FLT)
116 #define IS_DBL_TYPE(a)          ((a) == TYPE_DBL)
117 #define IS_ADR_TYPE(a)          ((a) == TYPE_ADR)
118
119 #define IS_VOID_TYPE(a)         ((a) == TYPE_VOID)
120
121
122 /* some Java related defines **************************************************/
123
124 #define JAVA_VERSION    "1.5.0"         /* this version is supported by CACAO */
125 #define CLASS_VERSION   "50.0"
126
127
128 /* Java class file constants **************************************************/
129
130 #define MAGIC             0xCAFEBABE
131 #define MAJOR_VERSION     50
132 #define MINOR_VERSION     0
133
134
135 /* Constant pool tags *********************************************************/
136
137 #define CONSTANT_Class                 7
138 #define CONSTANT_Fieldref              9
139 #define CONSTANT_Methodref            10
140 #define CONSTANT_InterfaceMethodref   11
141 #define CONSTANT_String                8
142 #define CONSTANT_Integer               3
143 #define CONSTANT_Float                 4
144 #define CONSTANT_Long                  5
145 #define CONSTANT_Double                6
146 #define CONSTANT_NameAndType          12
147 #define CONSTANT_Utf8                  1
148
149 #define CONSTANT_UNUSED                0
150
151
152 /* Class/Field/Method access and property flags *******************************/
153
154 #define ACC_UNDEF               -1      /* used internally                    */
155 #define ACC_NONE                 0      /* used internally                    */
156
157 #define ACC_PUBLIC          0x0001
158 #define ACC_PRIVATE         0x0002
159 #define ACC_PROTECTED       0x0004
160 #define ACC_STATIC          0x0008
161 #define ACC_FINAL           0x0010
162 #define ACC_SUPER           0x0020
163 #define ACC_SYNCHRONIZED    0x0020
164 #define ACC_VOLATILE        0x0040
165 #define ACC_BRIDGE          0x0040
166 #define ACC_TRANSIENT       0x0080
167 #define ACC_VARARGS         0x0080
168 #define ACC_NATIVE          0x0100
169 #define ACC_INTERFACE       0x0200
170 #define ACC_ABSTRACT        0x0400
171 #define ACC_STRICT          0x0800
172 #define ACC_SYNTHETIC       0x1000
173 #define ACC_ANNOTATION      0x2000
174 #define ACC_ENUM            0x4000
175 #define ACC_MIRANDA         0x8000
176
177 /* special flags used in classinfo ********************************************/
178
179 #define ACC_CLASS_REFLECT_MASK      0x0000ffff/* flags reported by reflection */
180
181 #define ACC_CLASS_PRIMITIVE         0x00010000
182 #define ACC_CLASS_MEMBER            0x00020000
183 #define ACC_CLASS_ANONYMOUS         0x00040000
184
185 #define ACC_CLASS_HAS_POINTERS      0x00080000/* instance contains pointers   */
186
187 #define ACC_CLASS_REFERENCE_MASK    0x00700000
188 #define ACC_CLASS_REFERENCE_SOFT    0x00100000
189 #define ACC_CLASS_REFERENCE_WEAK    0x00200000
190 #define ACC_CLASS_REFERENCE_PHANTOM 0x00400000
191
192
193 /* special flags used in methodinfo *******************************************/
194
195 #define ACC_METHOD_BUILTIN     0x00010000     /* use for descriptor parsing   */
196 #define ACC_METHOD_IMPLEMENTED 0x00020000     /* there is an implementation   */
197 #define ACC_METHOD_MONOMORPHIC 0x00040000     /* currently monomorphic method */
198
199
200 /* data structures of the runtime system **************************************/
201
202 /* java_object_t ***************************************************************
203
204    All objects (and arrays) which resides on the heap need the
205    following header at the beginning of the data structure.
206
207    TODO: Include detailed description from the Wiki (ObjectHeader) here.
208
209 *******************************************************************************/
210
211 #define HDRFLAG_MARK1         0x02
212 #define HDRFLAG_MARK2         0x04
213 #define HDRFLAG_UNCOLLECTABLE 0x08
214 #define HDRFLAG_HASH_TAKEN    0x10
215 #define HDRFLAG_HASH_ATTACHED 0x20
216 #define HDRFLAG_REFERENCING   0x40
217
218 struct java_object_t {                 /* header for all objects              */
219         struct _vftbl *vftbl;              /* pointer to virtual function table   */
220 #if defined(ENABLE_THREADS)
221         uintptr_t      lockword;
222 #endif
223 #if defined(ENABLE_GC_CACAO)
224         uintptr_t      hdrflags;           /* word containing the GC bits         */
225 #endif
226 };
227
228
229 /* arrays **********************************************************************
230
231         All arrays are objects (they need the object header with a pointer
232         to a vftbl (array class table). There is one class for each array
233         type. The array type is described by an arraydescriptor struct
234         which is referenced by the vftbl.
235 */
236
237 typedef struct java_array_t {           /* header for all arrays              */
238         java_object_t objheader;            /* object header                      */
239         s4 size;                            /* array size                         */
240 } java_array_t;
241
242
243
244 /* structs for all kinds of arrays ********************************************/
245
246 /*  booleanarray and bytearray need identical memory layout (access methods
247     use the same machine code */
248
249 typedef struct java_booleanarray_t {
250         java_array_t header;
251         u1 data[1];
252 } java_booleanarray_t;
253
254 typedef struct java_bytearray_t {
255         java_array_t header;
256         s1 data[1];
257 } java_bytearray_t;
258
259 typedef struct java_chararray_t {
260         java_array_t header;
261         u2 data[1];
262 } java_chararray_t;
263
264 typedef struct java_shortarray_t {
265         java_array_t header;
266         s2 data[1];
267 } java_shortarray_t;
268
269 typedef struct java_intarray_t {
270         java_array_t header;
271         s4 data[1];
272 } java_intarray_t;
273
274 typedef struct java_longarray_t {
275         java_array_t header;
276         s8 data[1];
277 } java_longarray_t;
278
279 typedef struct java_floatarray_t {
280         java_array_t header;
281         float data[1];
282 } java_floatarray_t;
283
284 typedef struct java_doublearray_t {
285         java_array_t header;
286         double data[1];
287 } java_doublearray_t;
288
289 /*  objectarray and arrayarray need identical memory layout (access methods
290     use the same machine code */
291
292 struct java_objectarray_t {
293         java_array_t   header;
294         java_object_t *data[1];
295 };
296
297
298 /* java_handle_t ***************************************************************
299
300    TODO: document me!
301
302 *******************************************************************************/
303
304 #if defined(ENABLE_HANDLES)
305 typedef struct java_handle_t {
306         java_object_t *heap_object;
307 } java_handle_t;
308
309 typedef struct java_handle_objectarray_t  { java_objectarray_t  *heap_object; } java_handle_objectarray_t;
310 typedef struct java_handle_booleanarray_t { java_booleanarray_t *heap_object; } java_handle_booleanarray_t;
311 typedef struct java_handle_bytearray_t    { java_bytearray_t    *heap_object; } java_handle_bytearray_t;
312 typedef struct java_handle_chararray_t    { java_chararray_t    *heap_object; } java_handle_chararray_t;
313 typedef struct java_handle_shortarray_t   { java_shortarray_t   *heap_object; } java_handle_shortarray_t;
314 typedef struct java_handle_intarray_t     { java_intarray_t     *heap_object; } java_handle_intarray_t;
315 typedef struct java_handle_longarray_t    { java_longarray_t    *heap_object; } java_handle_longarray_t;
316 typedef struct java_handle_floatarray_t   { java_floatarray_t   *heap_object; } java_handle_floatarray_t;
317 typedef struct java_handle_doublearray_t  { java_doublearray_t  *heap_object; } java_handle_doublearray_t;
318 #else
319 typedef java_object_t       java_handle_t;
320 typedef java_objectarray_t  java_handle_objectarray_t;
321 typedef java_booleanarray_t java_handle_booleanarray_t;
322 typedef java_bytearray_t    java_handle_bytearray_t;
323 typedef java_chararray_t    java_handle_chararray_t;
324 typedef java_shortarray_t   java_handle_shortarray_t;
325 typedef java_intarray_t     java_handle_intarray_t;
326 typedef java_longarray_t    java_handle_longarray_t;
327 typedef java_floatarray_t   java_handle_floatarray_t;
328 typedef java_doublearray_t  java_handle_doublearray_t;
329 #endif
330
331
332 /* global constants related to the verifier ***********************************/
333
334 /* The verifier needs additional variables in the variable array. Since these */
335 /* must be reserved and set by parse.c and stack.c, we define these numbers   */
336 /* here to avoid mysterious hard-coded constants.                             */
337 /* stack.c needs an extra variable if the verifier is disabled.               */
338
339 #if defined(ENABLE_VERIFIER)
340 #    define VERIFIER_EXTRA_LOCALS  1
341 #    define VERIFIER_EXTRA_VARS    1
342 #    define STACK_EXTRA_VARS       0
343 #else
344 #    define VERIFIER_EXTRA_LOCALS  0
345 #    define VERIFIER_EXTRA_VARS    0
346 #    define STACK_EXTRA_VARS       1
347 #endif
348
349 #endif /* _GLOBAL_H */
350
351
352 /*
353  * These are local overrides for various environment variables in Emacs.
354  * Please do not remove this and leave it at the end of the file, where
355  * Emacs will automagically detect them.
356  * ---------------------------------------------------------------------
357  * Local variables:
358  * mode: c
359  * indent-tabs-mode: t
360  * c-basic-offset: 4
361  * tab-width: 4
362  * End:
363  * vim:noexpandtab:sw=4:ts=4:
364  */