4f842ea66631f92c5d00858a8414c957d6b2bbf7
[cacao.git] / src / vm / global.h
1 /* src/vm/global.h - global definitions
2
3    Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4    R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5    C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6    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., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
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 3090 2005-07-21 11:29:43Z 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 /* some Java related defines **************************************************/
80
81 #define JAVA_VERSION    "1.4.2"         /* this version is supported by CACAO */
82
83
84 /* define some CACAO paths ****************************************************/
85
86 #define CACAO_JRE_DIR               "/jre"
87 #define CACAO_LIBRARY_PATH          "/jre/lib/"ARCH_DIR"/"
88 #define CACAO_RT_JAR_PATH           "/jre/lib/rt.jar"
89 #define CACAO_EXT_DIR               "/jre/lib/ext"
90
91 #if defined(WITH_EXTERNAL_CLASSPATH)
92 #define CACAO_VM_ZIP_PATH           "/jre/lib/vm.zip"
93 #define CLASSPATH_LIBRARY_PATH      "/lib/classpath"
94 #define CLASSPATH_GLIBJ_ZIP_PATH    "/share/classpath/glibj.zip"
95 #endif
96
97
98 /*
99  * CACAO_TYPECHECK activates typechecking (part of bytecode verification)
100  */
101 #define CACAO_TYPECHECK
102
103 /*
104  * TYPECHECK_STACK_COMPCAT activates full checking of computational
105  * categories for stack manipulations (POP,POP2,SWAP,DUP,DUP2,DUP_X1,
106  * DUP2_X1,DUP_X2,DUP2_X2).
107  */
108 #define TYPECHECK_STACK_COMPCAT
109
110 /* if we have threads disabled this one is not defined ************************/
111
112 #if !defined(USE_THREADS)
113 #define THREADSPECIFIC
114 #endif
115
116
117 #define MAX_ALIGN 8             /* most generic alignment for JavaVM values   */
118
119
120 /* basic data types ***********************************************************/
121
122 /* CAUTION: jit/jit.h relies on these numerical values! */
123 #define TYPE_INT      0         /* the JavaVM types must numbered in the      */
124 #define TYPE_LONG     1         /* same order as the ICMD_Ixxx to ICMD_Axxx   */
125 #define TYPE_FLOAT    2         /* instructions (LOAD and STORE)              */
126 #define TYPE_DOUBLE   3         /* integer, long, float, double, address      */
127 #define TYPE_ADDRESS  4         /* all other types can be numbered arbitrarly */
128
129 #define TYPE_VOID    10
130
131 /* primitive data types *******************************************************/
132
133 /* These values are used in parsed descriptors and in some other places       */
134 /* were the different types handled internally as TYPE_INT have to be         */
135 /* distinguished.                                                             */
136
137 #define PRIMITIVETYPE_COUNT  11  /* number of primitive types (+ dummies)     */
138
139 /* CAUTION: Don't change the numerical values! These constants are
140  * used as indices into the primitive type table.
141  */
142 #define PRIMITIVETYPE_INT     TYPE_INT
143 #define PRIMITIVETYPE_LONG    TYPE_LONG
144 #define PRIMITIVETYPE_FLOAT   TYPE_FLOAT
145 #define PRIMITIVETYPE_DOUBLE  TYPE_DOUBLE
146 #define PRIMITIVETYPE_DUMMY1  TYPE_ADR     /* not used! */
147 #define PRIMITIVETYPE_BYTE    5
148 #define PRIMITIVETYPE_CHAR    6
149 #define PRIMITIVETYPE_SHORT   7
150 #define PRIMITIVETYPE_BOOLEAN 8
151 #define PRIMITIVETYPE_DUMMY2  9            /* not used! */
152 #define PRIMITIVETYPE_VOID    TYPE_VOID
153
154 /* Java class file constants **************************************************/
155
156 #define MAGIC             0xCAFEBABE
157 #define MAJOR_VERSION     48
158 #define MINOR_VERSION     0
159
160
161 /* Constant pool tags *********************************************************/
162
163 #define CONSTANT_Class                 7
164 #define CONSTANT_Fieldref              9
165 #define CONSTANT_Methodref            10
166 #define CONSTANT_InterfaceMethodref   11
167 #define CONSTANT_String                8
168 #define CONSTANT_Integer               3
169 #define CONSTANT_Float                 4
170 #define CONSTANT_Long                  5
171 #define CONSTANT_Double                6
172 #define CONSTANT_NameAndType          12
173 #define CONSTANT_Utf8                  1
174
175 #define CONSTANT_UNUSED                0
176
177
178 /* Class/Field/Method access and property flags *******************************/
179
180 #define ACC_UNDEF               -1      /* used internally                    */
181 #define ACC_NONE                 0      /* used internally                    */
182
183 #define ACC_PUBLIC          0x0001
184 #define ACC_PRIVATE         0x0002
185 #define ACC_PROTECTED       0x0004
186 #define ACC_STATIC          0x0008
187 #define ACC_FINAL           0x0010
188 #define ACC_SUPER           0x0020
189 #define ACC_SYNCHRONIZED    0x0020
190 #define ACC_VOLATILE        0x0040
191 #define ACC_BRIDGE          0x0040
192 #define ACC_TRANSIENT       0x0080
193 #define ACC_VARARGS         0x0080
194 #define ACC_NATIVE          0x0100
195 #define ACC_INTERFACE       0x0200
196 #define ACC_ABSTRACT        0x0400
197 #define ACC_STRICT          0x0800
198 #define ACC_SYNTHETIC       0x1000
199 #define ACC_ANNOTATION      0x2000
200 #define ACC_ENUM            0x4000
201
202
203 /* data structure for calls from c code to java methods */
204
205 struct jni_callblock {
206         u8 itemtype;
207         u8 item;
208 };
209
210 typedef struct jni_callblock jni_callblock;
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(USE_THREADS) && defined(NATIVE_THREADS)
225         void          *monitorPtr;
226 #endif
227 };
228
229
230 /* arrays **********************************************************************
231
232         All arrays are objects (they need the object header with a pointer
233         to a vftbl (array class table). There is one class for each array
234         type. The array type is described by an arraydescriptor struct
235         which is referenced by the vftbl.
236 */
237
238 /* CAUTION: Don't change the numerical values! These constants (with
239  * the exception of ARRAYTYPE_OBJECT) are used as indices in the
240  * primitive type table.
241  */
242 #define ARRAYTYPE_INT      PRIMITIVETYPE_INT
243 #define ARRAYTYPE_LONG     PRIMITIVETYPE_LONG
244 #define ARRAYTYPE_FLOAT    PRIMITIVETYPE_FLOAT
245 #define ARRAYTYPE_DOUBLE   PRIMITIVETYPE_DOUBLE
246 #define ARRAYTYPE_BYTE     PRIMITIVETYPE_BYTE
247 #define ARRAYTYPE_CHAR     PRIMITIVETYPE_CHAR
248 #define ARRAYTYPE_SHORT    PRIMITIVETYPE_SHORT
249 #define ARRAYTYPE_BOOLEAN  PRIMITIVETYPE_BOOLEAN
250 #define ARRAYTYPE_OBJECT   PRIMITIVETYPE_VOID     /* don't use as index! */
251
252 typedef struct java_arrayheader {       /* header for all arrays              */
253         java_objectheader objheader;        /* object header                      */
254         s4 size;                            /* array size                         */
255 } java_arrayheader;
256
257
258
259 /* structs for all kinds of arrays ********************************************/
260
261 typedef struct java_chararray {
262         java_arrayheader header;
263         u2 data[1];
264 } java_chararray;
265
266 typedef struct java_floatheader {
267         java_arrayheader header;
268         float data[1];
269 } java_floatarray;
270
271 typedef struct java_doublearray {
272         java_arrayheader header;
273         double data[1];
274 } java_doublearray;
275
276 /*  booleanarray and bytearray need identical memory layout (access methods
277     use the same machine code */
278
279 typedef struct java_booleanarray {
280         java_arrayheader header;
281         u1 data[1];
282 } java_booleanarray;
283
284 typedef struct java_bytearray {
285         java_arrayheader header;
286         s1 data[1];
287 } java_bytearray;
288
289 typedef struct java_shortarray {
290         java_arrayheader header;
291         s2 data[1];
292 } java_shortarray;
293
294 typedef struct java_intarray {
295         java_arrayheader header;
296         s4 data[1];
297 } java_intarray;
298
299 typedef struct java_longarray {
300         java_arrayheader header;
301         s8 data[1];
302 } java_longarray;
303
304 /*  objectarray and arrayarray need identical memory layout (access methods
305     use the same machine code */
306
307 struct java_objectarray {
308         java_arrayheader   header;
309         java_objectheader *data[1];
310 };
311
312
313 #define VFTBLINTERFACETABLE(v,i)       (v)->interfacetable[-i]
314
315
316 /* flag variables *************************************************************/
317
318 extern bool cacao_initializing;
319
320
321 /* Synchronization ************************************************************/
322
323 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
324 void cast_lock();
325 void cast_unlock();
326 void compiler_lock();
327 void compiler_unlock();
328 #endif
329
330
331 /**** Methods: called directly by cacao, which defines the callpath ***/
332 #define MAINCLASS mainstring
333 #define MAINMETH "main"
334 #define MAINDESC "([Ljava/lang/String;)V"
335
336 #define EXITCLASS "java/lang/System"
337 #define EXITMETH  "exit"
338 #define EXITDESC  "(I)V"
339
340 #if defined(USE_THREADS)
341  #define THREADCLASS "java/lang/Thread"
342  #define THREADMETH  "<init>"
343  #define THREADDESC  "(Ljava/lang/VMThread;Ljava/lang/String;IZ)V"
344
345  #define THREADGROUPCLASS "java/lang/ThreadGroup"
346  #define THREADGROUPMETH  "addThread"
347  #define THREADGROUPDESC  "(Ljava/lang/Thread;)V"
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  */