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