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