* Updated header: Added 2006. Changed address of FSF. Changed email
[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 4357 2006-01-22 23:33:38Z twisti $
37
38 */
39
40
41 #ifndef _GLOBAL_H
42 #define _GLOBAL_H
43
44 #include "config.h"
45 #include "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 int   bool;                     /* boolean data type                  */
55
56 #define true  1
57 #define false 0
58
59
60 /* immediate data union */
61
62 typedef union {
63         s4          i;
64         s8          l;
65         float       f;
66         double      d;
67         void       *a;
68         functionptr fp;
69         u1          b[8];
70 } imm_union;
71
72
73 /* forward typedefs ***********************************************************/
74
75 typedef struct java_objectheader java_objectheader; 
76 typedef struct java_objectarray java_objectarray;
77
78
79 /* define some CACAO paths ****************************************************/
80
81 #define CACAO_VM_ZIP_PATH           CACAO_PREFIX "/share/cacao/vm.zip"
82 #define CLASSPATH_GLIBJ_ZIP_PATH    CLASSPATH_PREFIX "/share/classpath/" GLIBJZ_STRING
83 #define CLASSPATH_LIBRARY_PATH      CLASSPATH_LIBDIR "/classpath"
84
85
86 /*
87  * ENABLE_VERIFIER activates bytecode verification and other checks
88  */
89 #define ENABLE_VERIFIER
90
91 /*
92  * TYPECHECK_STACK_COMPCAT activates full checking of computational
93  * categories for stack manipulations (POP,POP2,SWAP,DUP,DUP2,DUP_X1,
94  * DUP2_X1,DUP_X2,DUP2_X2).
95  */
96 #define TYPECHECK_STACK_COMPCAT
97
98 /* if we have threads disabled this one is not defined ************************/
99
100 #if !defined(USE_THREADS)
101 #define THREADSPECIFIC
102 #endif
103
104
105 #define MAX_ALIGN 8             /* most generic alignment for JavaVM values   */
106
107
108 /* basic data types ***********************************************************/
109
110 /* CAUTION: jit/jit.h relies on these numerical values! */
111 #define TYPE_INT      0         /* the JavaVM types must numbered in the      */
112 #define TYPE_LONG     1         /* same order as the ICMD_Ixxx to ICMD_Axxx   */
113 #define TYPE_FLOAT    2         /* instructions (LOAD and STORE)              */
114 #define TYPE_DOUBLE   3         /* integer, long, float, double, address      */
115 #define TYPE_ADDRESS  4         /* all other types can be numbered arbitrarly */
116
117 #define TYPE_VOID    10
118
119 /* primitive data types *******************************************************/
120
121 /* These values are used in parsed descriptors and in some other places       */
122 /* were the different types handled internally as TYPE_INT have to be         */
123 /* distinguished.                                                             */
124
125 #define PRIMITIVETYPE_COUNT  11  /* number of primitive types (+ dummies)     */
126
127 /* CAUTION: Don't change the numerical values! These constants are
128  * used as indices into the primitive type table.
129  */
130 #define PRIMITIVETYPE_INT     TYPE_INT
131 #define PRIMITIVETYPE_LONG    TYPE_LONG
132 #define PRIMITIVETYPE_FLOAT   TYPE_FLOAT
133 #define PRIMITIVETYPE_DOUBLE  TYPE_DOUBLE
134 #define PRIMITIVETYPE_DUMMY1  TYPE_ADR     /* not used! */
135 #define PRIMITIVETYPE_BYTE    5
136 #define PRIMITIVETYPE_CHAR    6
137 #define PRIMITIVETYPE_SHORT   7
138 #define PRIMITIVETYPE_BOOLEAN 8
139 #define PRIMITIVETYPE_DUMMY2  9            /* not used! */
140 #define PRIMITIVETYPE_VOID    TYPE_VOID
141
142 /* some Java related defines **************************************************/
143
144 #define JAVA_VERSION    "1.4.2"         /* this version is supported by CACAO */
145 #define CLASS_VERSION   "49.0"
146
147
148 /* Java class file constants **************************************************/
149
150 #define MAGIC             0xCAFEBABE
151 #define MAJOR_VERSION     49
152 #define MINOR_VERSION     0
153
154
155 /* Constant pool tags *********************************************************/
156
157 #define CONSTANT_Class                 7
158 #define CONSTANT_Fieldref              9
159 #define CONSTANT_Methodref            10
160 #define CONSTANT_InterfaceMethodref   11
161 #define CONSTANT_String                8
162 #define CONSTANT_Integer               3
163 #define CONSTANT_Float                 4
164 #define CONSTANT_Long                  5
165 #define CONSTANT_Double                6
166 #define CONSTANT_NameAndType          12
167 #define CONSTANT_Utf8                  1
168
169 #define CONSTANT_UNUSED                0
170
171
172 /* Class/Field/Method access and property flags *******************************/
173
174 #define ACC_UNDEF               -1      /* used internally                    */
175 #define ACC_NONE                 0      /* used internally                    */
176
177 #define ACC_PUBLIC          0x0001
178 #define ACC_PRIVATE         0x0002
179 #define ACC_PROTECTED       0x0004
180 #define ACC_STATIC          0x0008
181 #define ACC_FINAL           0x0010
182 #define ACC_SUPER           0x0020
183 #define ACC_SYNCHRONIZED    0x0020
184 #define ACC_VOLATILE        0x0040
185 #define ACC_BRIDGE          0x0040
186 #define ACC_TRANSIENT       0x0080
187 #define ACC_VARARGS         0x0080
188 #define ACC_NATIVE          0x0100
189 #define ACC_INTERFACE       0x0200
190 #define ACC_ABSTRACT        0x0400
191 #define ACC_STRICT          0x0800
192 #define ACC_SYNTHETIC       0x1000
193 #define ACC_ANNOTATION      0x2000
194 #define ACC_ENUM            0x4000
195
196
197 /* data structure for calls from c code to java methods */
198
199 struct jni_callblock {
200         u8 itemtype;
201         u8 item;
202 };
203
204 typedef struct jni_callblock jni_callblock;
205
206
207 /* data structures of the runtime system **************************************/
208
209 /* java_objectheader ***********************************************************
210
211    All objects (and arrays) which resides on the heap need the
212    following header at the beginning of the data structure.
213
214 *******************************************************************************/
215
216 struct java_objectheader {              /* header for all objects             */
217         struct _vftbl *vftbl;               /* pointer to virtual function table  */
218 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
219         void          *monitorPtr;
220 #endif
221 };
222
223
224 /* arrays **********************************************************************
225
226         All arrays are objects (they need the object header with a pointer
227         to a vftbl (array class table). There is one class for each array
228         type. The array type is described by an arraydescriptor struct
229         which is referenced by the vftbl.
230 */
231
232 /* CAUTION: Don't change the numerical values! These constants (with
233  * the exception of ARRAYTYPE_OBJECT) are used as indices in the
234  * primitive type table.
235  */
236 #define ARRAYTYPE_INT      PRIMITIVETYPE_INT
237 #define ARRAYTYPE_LONG     PRIMITIVETYPE_LONG
238 #define ARRAYTYPE_FLOAT    PRIMITIVETYPE_FLOAT
239 #define ARRAYTYPE_DOUBLE   PRIMITIVETYPE_DOUBLE
240 #define ARRAYTYPE_BYTE     PRIMITIVETYPE_BYTE
241 #define ARRAYTYPE_CHAR     PRIMITIVETYPE_CHAR
242 #define ARRAYTYPE_SHORT    PRIMITIVETYPE_SHORT
243 #define ARRAYTYPE_BOOLEAN  PRIMITIVETYPE_BOOLEAN
244 #define ARRAYTYPE_OBJECT   PRIMITIVETYPE_VOID     /* don't use as index! */
245
246 typedef struct java_arrayheader {       /* header for all arrays              */
247         java_objectheader objheader;        /* object header                      */
248         s4 size;                            /* array size                         */
249 } java_arrayheader;
250
251
252
253 /* structs for all kinds of arrays ********************************************/
254
255 typedef struct java_chararray {
256         java_arrayheader header;
257         u2 data[1];
258 } java_chararray;
259
260 typedef struct java_floatarray {
261         java_arrayheader header;
262         float data[1];
263 } java_floatarray;
264
265 typedef struct java_doublearray {
266         java_arrayheader header;
267         double data[1];
268 } java_doublearray;
269
270 /*  booleanarray and bytearray need identical memory layout (access methods
271     use the same machine code */
272
273 typedef struct java_booleanarray {
274         java_arrayheader header;
275         u1 data[1];
276 } java_booleanarray;
277
278 typedef struct java_bytearray {
279         java_arrayheader header;
280         s1 data[1];
281 } java_bytearray;
282
283 typedef struct java_shortarray {
284         java_arrayheader header;
285         s2 data[1];
286 } java_shortarray;
287
288 typedef struct java_intarray {
289         java_arrayheader header;
290         s4 data[1];
291 } java_intarray;
292
293 typedef struct java_longarray {
294         java_arrayheader header;
295         s8 data[1];
296 } java_longarray;
297
298 /*  objectarray and arrayarray need identical memory layout (access methods
299     use the same machine code */
300
301 struct java_objectarray {
302         java_arrayheader   header;
303         java_objectheader *data[1];
304 };
305
306
307 #define VFTBLINTERFACETABLE(v,i)       (v)->interfacetable[-i]
308
309
310 /* flag variables *************************************************************/
311
312 extern bool cacao_initializing;
313
314
315 /* Synchronization ************************************************************/
316
317 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
318 void cast_lock();
319 void cast_unlock();
320 void compiler_lock();
321 void compiler_unlock();
322 #endif
323
324
325 /**** Methods: called directly by cacao, which defines the callpath ***/
326 #define MAINCLASS mainstring
327 #define MAINMETH "main"
328 #define MAINDESC "([Ljava/lang/String;)V"
329
330 #define EXITCLASS "java/lang/System"
331 #define EXITMETH  "exit"
332 #define EXITDESC  "(I)V"
333
334 #if defined(USE_THREADS)
335  #define THREADCLASS "java/lang/Thread"
336  #define THREADMETH  "<init>"
337  #define THREADDESC  "(Ljava/lang/VMThread;Ljava/lang/String;IZ)V"
338
339  #define THREADGROUPCLASS "java/lang/ThreadGroup"
340  #define THREADGROUPMETH  "addThread"
341  #define THREADGROUPDESC  "(Ljava/lang/Thread;)V"
342 #endif
343
344 #endif /* _GLOBAL_H */
345
346
347 /*
348  * These are local overrides for various environment variables in Emacs.
349  * Please do not remove this and leave it at the end of the file, where
350  * Emacs will automagically detect them.
351  * ---------------------------------------------------------------------
352  * Local variables:
353  * mode: c
354  * indent-tabs-mode: t
355  * c-basic-offset: 4
356  * tab-width: 4
357  * End:
358  */