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 7307 2007-02-09 12:47:10Z twisti $
33 /* forward typedefs ***********************************************************/
35 typedef struct classinfo classinfo;
36 typedef struct innerclassinfo innerclassinfo;
37 typedef struct extra_classref extra_classref;
43 #include "toolbox/list.h"
45 #include "vm/global.h"
47 #if defined(ENABLE_JAVASE)
48 # include "vmcore/annotation.h"
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"
59 /* class state defines ********************************************************/
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
70 /* some macros ****************************************************************/
72 #define CLASS_IS_OR_ALMOST_INITIALIZED(c) \
73 (((c)->state & CLASS_INITIALIZING) || ((c)->state & CLASS_INITIALIZED))
76 /* classinfo ******************************************************************/
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. */
83 java_objectheader header;
85 } dummy_java_lang_Class;
87 struct classinfo { /* class structure */
88 dummy_java_lang_Class object;
90 s4 flags; /* ACC flags */
91 utf *name; /* class name */
93 s4 cpcount; /* number of entries in constant pool */
94 u1 *cptags; /* constant pool tags */
95 voidptr *cpinfos; /* pointer to constant pool info structures */
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 */
103 classref_or_classinfo super; /* super class */
104 classinfo *sub; /* sub class pointer */
105 classinfo *nextsub; /* pointer to next class in sub class list */
107 s4 interfacescount; /* number of interfaces */
108 classref_or_classinfo *interfaces; /* superinterfaces */
110 s4 fieldscount; /* number of fields */
111 fieldinfo *fields; /* field table */
113 s4 methodscount; /* number of methods */
114 methodinfo *methods; /* method table */
116 listnode listnode; /* linkage */
118 s4 state; /* current class state */
119 s4 index; /* hierarchy depth (classes) or index */
121 s4 instancesize; /* size of an instance of this class */
123 vftbl_t *vftbl; /* pointer to virtual function table */
125 methodinfo *finalizer; /* finalizer method */
127 u2 innerclasscount; /* number of inner classes */
128 innerclassinfo *innerclass;
130 #if defined(ENABLE_JAVASE)
131 classref_or_classinfo enclosingclass; /* enclosing class */
132 constant_nameandtype *enclosingmethod; /* enclosing method */
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;
142 java_objectheader *classloader; /* NULL for bootstrap classloader */
146 /* innerclassinfo *************************************************************/
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 */
156 /* extra_classref **************************************************************
158 for classrefs not occurring within descriptors
160 *******************************************************************************/
162 struct extra_classref {
163 extra_classref *next;
164 constant_classref classref;
168 /* global variables ***********************************************************/
170 extern list unlinkedclasses; /* this is only used for eager class loading */
173 /* frequently used classes ****************************************************/
175 /* important system classes */
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;
191 /* system exception classes required in cacao */
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;
200 #if defined(WITH_CLASSPATH_GNU)
201 extern classinfo *class_java_lang_VMThrowable;
204 extern classinfo *class_java_lang_Exception;
205 extern classinfo *class_java_lang_ClassCastException;
206 extern classinfo *class_java_lang_ClassNotFoundException;
208 #if defined(ENABLE_JAVASE)
209 extern classinfo *class_java_lang_Void;
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;
222 /* some runtime exception */
224 extern classinfo *class_java_lang_NullPointerException;
227 /* some classes which may be used more often */
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;
237 extern classinfo *arrayclass_java_lang_Object;
241 /* pseudo classes for the type checker ****************************************/
244 * pseudo_class_Arraystub
245 * (extends Object implements Cloneable, java.io.Serializable)
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!)
255 * This pseudo class is used internally to represent the
260 * This pseudo class is used internally to represent the
261 * the 'uninitialized object' type.
264 extern classinfo *pseudo_class_Arraystub;
265 extern classinfo *pseudo_class_Null;
266 extern classinfo *pseudo_class_New;
269 /* function prototypes ********************************************************/
271 /* create a new classinfo struct */
272 classinfo *class_create_classinfo(utf *u);
274 /* postset's the header.vftbl */
275 void class_postset_header_vftbl(void);
277 /* set the package name after the name has been set */
278 void class_set_packagename(classinfo *c);
280 bool class_load_attributes(classbuffer *cb);
282 /* retrieve constantpool element */
283 voidptr class_getconstant(classinfo *class, u4 pos, u4 ctype);
284 voidptr innerclass_getconstant(classinfo *c, u4 pos, u4 ctype);
286 /* frees all resources used by the class */
287 void class_free(classinfo *);
289 /* return an array class with the given component class */
290 classinfo *class_array_of(classinfo *component,bool link);
292 /* return an array class with the given dimension and element class */
293 classinfo *class_multiarray_of(s4 dim, classinfo *element,bool link);
295 /* return a classref for the given class name */
296 /* (does a linear search!) */
297 constant_classref *class_lookup_classref(classinfo *cls,utf *name);
299 /* return a classref for the given class name */
300 /* (does a linear search!) */
301 constant_classref *class_get_classref(classinfo *cls,utf *name);
303 /* return a classref to the class itself */
304 /* (does a linear search!) */
305 constant_classref *class_get_self_classref(classinfo *cls);
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);
311 /* return a classref for the component type of the given array type */
312 constant_classref *class_get_classref_component_of(constant_classref *ref);
314 /* get a class' field by name and descriptor */
315 fieldinfo *class_findfield(classinfo *c, utf *name, utf *desc);
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);
321 /* search class for a field */
322 fieldinfo *class_resolvefield(classinfo *c, utf *name, utf *desc, classinfo *referer, bool throwexception);
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);
330 bool class_issubclass(classinfo *sub, classinfo *super);
332 /* some debugging functions */
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);
345 void class_showmethods(classinfo *c);
346 void class_showconstantpool(classinfo *c);
348 #endif /* _CLASS_H */
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 * ---------------------------------------------------------------------
358 * indent-tabs-mode: t