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