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