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