1 /* src/vmcore/class.h - class related functions header
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
8 This file is part of CACAO.
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.
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.
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
25 $Id: class.h 8042 2007-06-07 17:43:29Z twisti $
33 /* forward typedefs ***********************************************************/
35 typedef struct classinfo classinfo;
36 typedef struct innerclassinfo innerclassinfo;
37 typedef struct extra_classref extra_classref;
38 typedef struct castinfo castinfo;
44 #include "toolbox/list.h"
46 #include "vm/global.h"
48 #if defined(ENABLE_JAVASE)
49 # include "vmcore/annotation.h"
52 #include "vmcore/field.h"
53 #include "vmcore/linker.h"
54 #include "vmcore/loader.h"
55 #include "vmcore/method.h"
56 #include "vmcore/references.h"
57 #include "vmcore/utf8.h"
60 /* class state defines ********************************************************/
62 #define CLASS_LOADING 0x0001
63 #define CLASS_LOADED 0x0002
64 #define CLASS_LINKING 0x0004
65 #define CLASS_LINKED 0x0008
66 #define CLASS_INITIALIZING 0x0010
67 #define CLASS_INITIALIZED 0x0020
68 #define CLASS_ERROR 0x0040
71 /* some macros ****************************************************************/
73 #define CLASS_IS_OR_ALMOST_INITIALIZED(c) \
74 (((c)->state & CLASS_INITIALIZING) || ((c)->state & CLASS_INITIALIZED))
77 /* classinfo ******************************************************************/
79 /* We define this dummy structure of java_lang_Class so we can
80 bootstrap cacaoh without needing a java_lang_Class.h file. If the
81 size is big enough, is checked during runtime in vm_create. */
84 java_objectheader header;
86 } dummy_java_lang_Class;
88 struct classinfo { /* class structure */
89 dummy_java_lang_Class object;
91 s4 flags; /* ACC flags */
92 utf *name; /* class name */
94 s4 cpcount; /* number of entries in constant pool */
95 u1 *cptags; /* constant pool tags */
96 voidptr *cpinfos; /* pointer to constant pool info structures */
98 s4 classrefcount; /* number of symbolic class references */
99 constant_classref *classrefs; /* table of symbolic class references */
100 extra_classref *extclassrefs; /* additional classrefs */
101 s4 parseddescsize; /* size of the parsed descriptors block */
102 u1 *parseddescs; /* parsed descriptors */
104 classref_or_classinfo super; /* super class */
105 classinfo *sub; /* sub class pointer */
106 classinfo *nextsub; /* pointer to next class in sub class list */
108 s4 interfacescount; /* number of interfaces */
109 classref_or_classinfo *interfaces; /* superinterfaces */
111 s4 fieldscount; /* number of fields */
112 fieldinfo *fields; /* field table */
114 s4 methodscount; /* number of methods */
115 methodinfo *methods; /* method table */
117 listnode_t listnode; /* linkage */
119 s4 state; /* current class state */
120 s4 index; /* hierarchy depth (classes) or index */
122 s4 instancesize; /* size of an instance of this class */
124 vftbl_t *vftbl; /* pointer to virtual function table */
126 methodinfo *finalizer; /* finalizer method */
128 u2 innerclasscount; /* number of inner classes */
129 innerclassinfo *innerclass;
131 #if defined(ENABLE_JAVASE)
132 classref_or_classinfo enclosingclass; /* enclosing class */
133 constant_nameandtype *enclosingmethod; /* enclosing method */
136 utf *packagename; /* full name of the package */
137 utf *sourcefile; /* SourceFile attribute */
138 #if defined(ENABLE_JAVASE)
139 utf *signature; /* Signature attribute */
140 s4 runtimevisibleannotationscount;
141 annotation_t *runtimevisibleannotations;
143 java_objectheader *classloader; /* NULL for bootstrap classloader */
147 /* innerclassinfo *************************************************************/
149 struct innerclassinfo {
150 classref_or_classinfo inner_class; /* inner class pointer */
151 classref_or_classinfo outer_class; /* outer class pointer */
152 utf *name; /* innerclass name */
153 s4 flags; /* ACC flags */
157 /* extra_classref **************************************************************
159 for classrefs not occurring within descriptors
161 *******************************************************************************/
163 struct extra_classref {
164 extra_classref *next;
165 constant_classref classref;
169 /* castinfo *******************************************************************/
178 /* global variables ***********************************************************/
180 extern list_t unlinkedclasses; /* this is only used for eager class loading */
183 /* frequently used classes ****************************************************/
185 /* important system classes */
187 extern classinfo *class_java_lang_Object;
188 extern classinfo *class_java_lang_Class;
189 extern classinfo *class_java_lang_ClassLoader;
190 extern classinfo *class_java_lang_Cloneable;
191 extern classinfo *class_java_lang_SecurityManager;
192 extern classinfo *class_java_lang_String;
193 extern classinfo *class_java_lang_System;
194 extern classinfo *class_java_lang_Thread;
195 extern classinfo *class_java_lang_ThreadGroup;
196 extern classinfo *class_java_lang_VMSystem;
197 extern classinfo *class_java_lang_VMThread;
198 extern classinfo *class_java_io_Serializable;
201 /* system exception classes required in cacao */
203 extern classinfo *class_java_lang_Throwable;
204 extern classinfo *class_java_lang_Error;
205 extern classinfo *class_java_lang_LinkageError;
206 extern classinfo *class_java_lang_NoClassDefFoundError;
207 extern classinfo *class_java_lang_OutOfMemoryError;
208 extern classinfo *class_java_lang_VirtualMachineError;
210 #if defined(WITH_CLASSPATH_GNU)
211 extern classinfo *class_java_lang_VMThrowable;
214 extern classinfo *class_java_lang_Exception;
215 extern classinfo *class_java_lang_ClassCastException;
216 extern classinfo *class_java_lang_ClassNotFoundException;
218 #if defined(ENABLE_JAVASE)
219 extern classinfo *class_java_lang_Void;
222 extern classinfo *class_java_lang_Boolean;
223 extern classinfo *class_java_lang_Byte;
224 extern classinfo *class_java_lang_Character;
225 extern classinfo *class_java_lang_Short;
226 extern classinfo *class_java_lang_Integer;
227 extern classinfo *class_java_lang_Long;
228 extern classinfo *class_java_lang_Float;
229 extern classinfo *class_java_lang_Double;
232 /* some runtime exception */
234 extern classinfo *class_java_lang_NullPointerException;
237 /* some classes which may be used more often */
239 #if defined(ENABLE_JAVASE)
240 extern classinfo *class_java_lang_StackTraceElement;
241 extern classinfo *class_java_lang_reflect_Constructor;
242 extern classinfo *class_java_lang_reflect_Field;
243 extern classinfo *class_java_lang_reflect_Method;
244 extern classinfo *class_java_security_PrivilegedAction;
245 extern classinfo *class_java_util_Vector;
247 extern classinfo *arrayclass_java_lang_Object;
251 /* pseudo classes for the type checker ****************************************/
254 * pseudo_class_Arraystub
255 * (extends Object implements Cloneable, java.io.Serializable)
257 * If two arrays of incompatible component types are merged,
258 * the resulting reference has no accessible components.
259 * The result does, however, implement the interfaces Cloneable
260 * and java.io.Serializable. This pseudo class is used internally
261 * to represent such results. (They are *not* considered arrays!)
265 * This pseudo class is used internally to represent the
270 * This pseudo class is used internally to represent the
271 * the 'uninitialized object' type.
274 extern classinfo *pseudo_class_Arraystub;
275 extern classinfo *pseudo_class_Null;
276 extern classinfo *pseudo_class_New;
279 /* function prototypes ********************************************************/
281 /* create a new classinfo struct */
282 classinfo *class_create_classinfo(utf *u);
284 /* postset's the header.vftbl */
285 void class_postset_header_vftbl(void);
287 /* set the package name after the name has been set */
288 void class_set_packagename(classinfo *c);
290 bool class_load_attributes(classbuffer *cb);
292 /* retrieve constantpool element */
293 voidptr class_getconstant(classinfo *class, u4 pos, u4 ctype);
294 voidptr innerclass_getconstant(classinfo *c, u4 pos, u4 ctype);
296 /* frees all resources used by the class */
297 void class_free(classinfo *);
299 /* return an array class with the given component class */
300 classinfo *class_array_of(classinfo *component,bool link);
302 /* return an array class with the given dimension and element class */
303 classinfo *class_multiarray_of(s4 dim, classinfo *element,bool link);
305 /* return a classref for the given class name */
306 /* (does a linear search!) */
307 constant_classref *class_lookup_classref(classinfo *cls,utf *name);
309 /* return a classref for the given class name */
310 /* (does a linear search!) */
311 constant_classref *class_get_classref(classinfo *cls,utf *name);
313 /* return a classref to the class itself */
314 /* (does a linear search!) */
315 constant_classref *class_get_self_classref(classinfo *cls);
317 /* return a classref for an array with the given dimension of with the */
318 /* given component type */
319 constant_classref *class_get_classref_multiarray_of(s4 dim,constant_classref *ref);
321 /* return a classref for the component type of the given array type */
322 constant_classref *class_get_classref_component_of(constant_classref *ref);
324 /* get a class' field by name and descriptor */
325 fieldinfo *class_findfield(classinfo *c, utf *name, utf *desc);
327 /* search 'classinfo'-structure for a field with the specified name */
328 fieldinfo *class_findfield_by_name(classinfo *c, utf *name);
329 s4 class_findfield_index_by_name(classinfo *c, utf *name);
331 /* search class for a field */
332 fieldinfo *class_resolvefield(classinfo *c, utf *name, utf *desc, classinfo *referer, bool throwexception);
334 /* search for a method with a specified name and descriptor */
335 methodinfo *class_findmethod(classinfo *c, utf *name, utf *desc);
336 methodinfo *class_resolvemethod(classinfo *c, utf *name, utf *dest);
337 methodinfo *class_resolveclassmethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool throwexception);
338 methodinfo *class_resolveinterfacemethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool throwexception);
340 classinfo *class_primitive_get(utf *name);
341 bool class_is_primitive(classinfo *c);
343 bool class_issubclass(classinfo *sub, classinfo *super);
344 bool class_isanysubclass(classinfo *sub, classinfo *super);
346 /* some debugging functions */
349 void class_printflags(classinfo *c);
350 void class_print(classinfo *c);
351 void class_println(classinfo *c);
352 void class_classref_print(constant_classref *cr);
353 void class_classref_println(constant_classref *cr);
354 void class_classref_or_classinfo_print(classref_or_classinfo c);
355 void class_classref_or_classinfo_println(classref_or_classinfo c);
359 void class_showmethods(classinfo *c);
360 void class_showconstantpool(classinfo *c);
362 #endif /* _CLASS_H */
366 * These are local overrides for various environment variables in Emacs.
367 * Please do not remove this and leave it at the end of the file, where
368 * Emacs will automagically detect them.
369 * ---------------------------------------------------------------------
372 * indent-tabs-mode: t