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