* src/vm/properties.c (properties_init) [ENABLE_JAVASE]: Allocate the
[cacao.git] / src / vm / class.h
1 /* src/vm/class.h - class related functions header
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: Christian Thalinger
28
29    $Id: class.h 5919 2006-11-05 21:18:05Z twisti $
30
31 */
32
33
34 #ifndef _CLASS_H
35 #define _CLASS_H
36
37 /* forward typedefs ***********************************************************/
38
39 typedef struct innerclassinfo innerclassinfo;
40 typedef struct extra_classref extra_classref;
41
42
43 #include "config.h"
44 #include "vm/types.h"
45
46 #include "vm/global.h"                  /* define java_objectheader for j.l.C */
47 #include "native/include/java_lang_Class.h"
48
49 #include "toolbox/list.h"
50 #include "vm/field.h"
51 #include "vm/linker.h"
52 #include "vm/method.h"
53 #include "vm/references.h"
54 #include "vm/utf8.h"
55
56
57 /* class state defines ********************************************************/
58
59 #define CLASS_LOADING         0x0001
60 #define CLASS_LOADED          0x0002
61 #define CLASS_LINKING         0x0004
62 #define CLASS_LINKED          0x0008
63 #define CLASS_INITIALIZING    0x0010
64 #define CLASS_INITIALIZED     0x0020
65 #define CLASS_ERROR           0x0040
66
67
68 /* some macros ****************************************************************/
69
70 #define CLASS_IS_OR_ALMOST_INITIALIZED(c) \
71     (((c)->state & CLASS_INITIALIZING) || ((c)->state & CLASS_INITIALIZED))
72
73
74 /* classinfo ******************************************************************/
75
76 struct classinfo {                /* class structure                          */
77         java_lang_Class object;       /* classinfos are also j.l.C objects        */
78
79         s4          flags;            /* ACC flags                                */
80         utf        *name;             /* class name                               */
81
82         s4          cpcount;          /* number of entries in constant pool       */
83         u1         *cptags;           /* constant pool tags                       */
84         voidptr    *cpinfos;          /* pointer to constant pool info structures */
85
86         s4          classrefcount;    /* number of symbolic class references      */
87         constant_classref *classrefs; /* table of symbolic class references       */
88         extra_classref *extclassrefs; /* additional classrefs                     */
89         s4          parseddescsize;   /* size of the parsed descriptors block     */
90         u1         *parseddescs;      /* parsed descriptors                       */
91
92         classref_or_classinfo super;  /* super class                              */
93         classinfo  *sub;              /* sub class pointer                        */
94         classinfo  *nextsub;          /* pointer to next class in sub class list  */
95
96         s4          interfacescount;  /* number of interfaces                     */
97         classref_or_classinfo *interfaces; /* superinterfaces                     */
98
99         s4          fieldscount;      /* number of fields                         */
100         fieldinfo  *fields;           /* field table                              */
101
102         s4          methodscount;     /* number of methods                        */
103         methodinfo *methods;          /* method table                             */
104
105         listnode    listnode;         /* linkage                                  */
106
107         s4          state;            /* current class state                      */
108         s4          index;            /* hierarchy depth (classes) or index       */
109                                       /* (interfaces)                             */
110         s4          instancesize;     /* size of an instance of this class        */
111
112         vftbl_t    *vftbl;            /* pointer to virtual function table        */
113
114         methodinfo *finalizer;        /* finalizer method                         */
115
116         u2          innerclasscount;  /* number of inner classes                  */
117         innerclassinfo *innerclass;
118
119         utf        *packagename;      /* full name of the package                 */
120         utf        *sourcefile;       /* classfile name containing this class     */
121         utf        *signature;        /* classfile signature                      */
122         java_objectheader *classloader; /* NULL for bootstrap classloader         */
123 };
124
125
126 /* innerclassinfo *************************************************************/
127
128 struct innerclassinfo {
129         classref_or_classinfo inner_class; /* inner class pointer                 */
130         classref_or_classinfo outer_class; /* outer class pointer                 */
131         utf                  *name;        /* innerclass name                     */
132         s4                    flags;       /* ACC flags                           */
133 };
134
135
136 /* extra_classref **************************************************************
137
138    for classrefs not occurring within descriptors
139
140 *******************************************************************************/
141
142 struct extra_classref {
143         extra_classref    *next;
144         constant_classref  classref;
145 };
146
147
148 /* global variables ***********************************************************/
149
150 extern list unlinkedclasses;   /* this is only used for eager class loading   */
151
152
153 /* frequently used classes ****************************************************/
154
155 /* important system classes */
156
157 extern classinfo *class_java_lang_Object;
158 extern classinfo *class_java_lang_Class;
159 extern classinfo *class_java_lang_ClassLoader;
160 extern classinfo *class_java_lang_Cloneable;
161 extern classinfo *class_java_lang_SecurityManager;
162 extern classinfo *class_java_lang_String;
163 extern classinfo *class_java_lang_System;
164 extern classinfo *class_java_lang_Thread;
165 extern classinfo *class_java_lang_ThreadGroup;
166 extern classinfo *class_java_lang_VMSystem;
167 extern classinfo *class_java_lang_VMThread;
168 extern classinfo *class_java_io_Serializable;
169
170
171 /* system exception classes required in cacao */
172
173 extern classinfo *class_java_lang_Throwable;
174 extern classinfo *class_java_lang_VMThrowable;
175 extern classinfo *class_java_lang_Error;
176 extern classinfo *class_java_lang_AbstractMethodError;
177 extern classinfo *class_java_lang_LinkageError;
178 extern classinfo *class_java_lang_NoClassDefFoundError;
179 extern classinfo *class_java_lang_NoSuchMethodError;
180 extern classinfo *class_java_lang_OutOfMemoryError;
181
182 extern classinfo *class_java_lang_Exception;
183 extern classinfo *class_java_lang_ClassCastException;
184 extern classinfo *class_java_lang_ClassNotFoundException;
185 extern classinfo *class_java_lang_IllegalArgumentException;
186 extern classinfo *class_java_lang_IllegalMonitorStateException;
187
188
189 extern classinfo *class_java_lang_Void;
190 extern classinfo *class_java_lang_Boolean;
191 extern classinfo *class_java_lang_Byte;
192 extern classinfo *class_java_lang_Character;
193 extern classinfo *class_java_lang_Short;
194 extern classinfo *class_java_lang_Integer;
195 extern classinfo *class_java_lang_Long;
196 extern classinfo *class_java_lang_Float;
197 extern classinfo *class_java_lang_Double;
198
199
200 /* some runtime exception */
201
202 extern classinfo *class_java_lang_NullPointerException;
203
204
205 /* some classes which may be used more often */
206
207 extern classinfo *class_java_lang_StackTraceElement;
208 extern classinfo *class_java_lang_reflect_Constructor;
209 extern classinfo *class_java_lang_reflect_Field;
210 extern classinfo *class_java_lang_reflect_Method;
211 extern classinfo *class_java_security_PrivilegedAction;
212 extern classinfo *class_java_util_Vector;
213
214 extern classinfo *arrayclass_java_lang_Object;
215
216
217 /* pseudo classes for the type checker ****************************************/
218
219 /*
220  * pseudo_class_Arraystub
221  *     (extends Object implements Cloneable, java.io.Serializable)
222  *
223  *     If two arrays of incompatible component types are merged,
224  *     the resulting reference has no accessible components.
225  *     The result does, however, implement the interfaces Cloneable
226  *     and java.io.Serializable. This pseudo class is used internally
227  *     to represent such results. (They are *not* considered arrays!)
228  *
229  * pseudo_class_Null
230  *
231  *     This pseudo class is used internally to represent the
232  *     null type.
233  *
234  * pseudo_class_New
235  *
236  *     This pseudo class is used internally to represent the
237  *     the 'uninitialized object' type.
238  */
239
240 extern classinfo *pseudo_class_Arraystub;
241 extern classinfo *pseudo_class_Null;
242 extern classinfo *pseudo_class_New;
243
244
245 /* function prototypes ********************************************************/
246
247 /* create a new classinfo struct */
248 classinfo *class_create_classinfo(utf *u);
249
250 /* postset's the header.vftbl */
251 void class_postset_header_vftbl(void);
252
253 /* set the package name after the name has been set */
254 void class_set_packagename(classinfo *c);
255
256 /* retrieve constantpool element */
257 voidptr class_getconstant(classinfo *class, u4 pos, u4 ctype);
258 voidptr innerclass_getconstant(classinfo *c, u4 pos, u4 ctype);
259
260 /* frees all resources used by the class */
261 void class_free(classinfo *);
262
263 /* return an array class with the given component class */
264 classinfo *class_array_of(classinfo *component,bool link);
265
266 /* return an array class with the given dimension and element class */
267 classinfo *class_multiarray_of(s4 dim, classinfo *element,bool link);
268
269 /* return a classref for the given class name */
270 /* (does a linear search!)                    */
271 constant_classref *class_lookup_classref(classinfo *cls,utf *name);
272
273 /* return a classref for the given class name */
274 /* (does a linear search!)                    */
275 constant_classref *class_get_classref(classinfo *cls,utf *name);
276
277 /* return a classref to the class itself */
278 /* (does a linear search!)                    */
279 constant_classref *class_get_self_classref(classinfo *cls);
280
281 /* return a classref for an array with the given dimension of with the */
282 /* given component type */
283 constant_classref *class_get_classref_multiarray_of(s4 dim,constant_classref *ref);
284
285 /* return a classref for the component type of the given array type */
286 constant_classref *class_get_classref_component_of(constant_classref *ref);
287
288 /* get a class' field by name and descriptor */
289 fieldinfo *class_findfield(classinfo *c, utf *name, utf *desc);
290
291 /* search 'classinfo'-structure for a field with the specified name */
292 fieldinfo *class_findfield_by_name(classinfo *c, utf *name);
293 s4 class_findfield_index_by_name(classinfo *c, utf *name);
294
295 /* search class for a field */
296 fieldinfo *class_resolvefield(classinfo *c, utf *name, utf *desc, classinfo *referer, bool throwexception);
297
298 /* search for a method with a specified name and descriptor */
299 methodinfo *class_findmethod(classinfo *c, utf *name, utf *desc);
300 methodinfo *class_resolvemethod(classinfo *c, utf *name, utf *dest);
301 methodinfo *class_resolveclassmethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool throwexception);
302 methodinfo *class_resolveinterfacemethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool throwexception);
303
304 bool class_issubclass(classinfo *sub, classinfo *super);
305
306 /* some debugging functions */
307
308 #if !defined(NDEBUG)
309 void class_printflags(classinfo *c);
310 void class_print(classinfo *c);
311 void class_println(classinfo *c);
312 void class_classref_print(constant_classref *cr);
313 void class_classref_println(constant_classref *cr);
314 void class_classref_or_classinfo_print(classref_or_classinfo c);
315 void class_classref_or_classinfo_println(classref_or_classinfo c);
316 #endif
317
318 /* debug purposes */
319 void class_showmethods(classinfo *c);
320 void class_showconstantpool(classinfo *c);
321
322 #endif /* _CLASS_H */
323
324
325 /*
326  * These are local overrides for various environment variables in Emacs.
327  * Please do not remove this and leave it at the end of the file, where
328  * Emacs will automagically detect them.
329  * ---------------------------------------------------------------------
330  * Local variables:
331  * mode: c
332  * indent-tabs-mode: t
333  * c-basic-offset: 4
334  * tab-width: 4
335  * End:
336  */