1 /* src/vm/class.h - class related functions header
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 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., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Christian Thalinger
31 $Id: class.h 4323 2006-01-20 13:05:09Z twisti $
39 /* forward typedefs ***********************************************************/
41 typedef struct innerclassinfo innerclassinfo;
42 typedef struct extra_classref extra_classref;
48 #include "vm/global.h" /* define java_objectheader for j.l.C */
49 #include "native/include/java_lang_Class.h"
51 #include "toolbox/list.h"
53 #include "vm/linker.h"
54 #include "vm/references.h"
56 #include "vm/jit/inline/sets.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 struct classinfo { /* class structure */
79 java_lang_Class object; /* classinfos are also j.l.C objects */
81 s4 flags; /* ACC flags */
82 utf *name; /* class name */
84 s4 cpcount; /* number of entries in constant pool */
85 u1 *cptags; /* constant pool tags */
86 voidptr *cpinfos; /* pointer to constant pool info structures */
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 */
94 classref_or_classinfo super; /* super class */
95 classinfo *sub; /* sub class pointer */
96 classinfo *nextsub; /* pointer to next class in sub class list */
98 s4 interfacescount; /* number of interfaces */
99 classref_or_classinfo *interfaces; /* superinterfaces */
101 s4 fieldscount; /* number of fields */
102 fieldinfo *fields; /* field table */
104 s4 methodscount; /* number of methods */
105 methodinfo *methods; /* method table */
107 listnode listnode; /* linkage */
109 s4 state; /* current class state */
110 s4 index; /* hierarchy depth (classes) or index */
112 s4 instancesize; /* size of an instance of this class */
114 vftbl_t *vftbl; /* pointer to virtual function table */
116 methodinfo *finalizer; /* finalizer method */
118 u2 innerclasscount; /* number of inner classes */
119 innerclassinfo *innerclass;
121 s4 classUsed; /* 0= not used 1 = used CO-RT */
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 */
133 /* innerclassinfo *************************************************************/
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 */
143 /* extra_classref **************************************************************
145 for classrefs not occurring within descriptors
147 *******************************************************************************/
149 struct extra_classref {
150 extra_classref *next;
151 constant_classref classref;
155 /* global variables ***********************************************************/
157 extern list unlinkedclasses; /* this is only used for eager class loading */
160 /* frequently used classes ****************************************************/
162 /* important system classes */
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;
177 /* system exception classes required in cacao */
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;
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;
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;
204 /* some runtime exception */
206 extern classinfo *class_java_lang_NullPointerException;
209 /* some classes which may be used more often */
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;
218 extern classinfo *arrayclass_java_lang_Object;
221 /* pseudo classes for the type checker ****************************************/
224 * pseudo_class_Arraystub
225 * (extends Object implements Cloneable, java.io.Serializable)
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!)
235 * This pseudo class is used internally to represent the
240 * This pseudo class is used internally to represent the
241 * the 'uninitialized object' type.
244 extern classinfo *pseudo_class_Arraystub;
245 extern classinfo *pseudo_class_Null;
246 extern classinfo *pseudo_class_New;
249 /* function prototypes ********************************************************/
251 /* create a new classinfo struct */
252 classinfo *class_create_classinfo(utf *u);
254 /* postset's the header.vftbl */
255 void class_postset_header_vftbl(void);
257 /* set the package name after the name has been set */
258 void class_set_packagename(classinfo *c);
260 /* retrieve constantpool element */
261 voidptr class_getconstant(classinfo *class, u4 pos, u4 ctype);
262 voidptr innerclass_getconstant(classinfo *c, u4 pos, u4 ctype);
264 /* frees all resources used by the class */
265 void class_free(classinfo *);
267 /* return an array class with the given component class */
268 classinfo *class_array_of(classinfo *component,bool link);
270 /* return an array class with the given dimension and element class */
271 classinfo *class_multiarray_of(s4 dim, classinfo *element,bool link);
273 /* return a classref for the given class name */
274 /* (does a linear search!) */
275 constant_classref *class_lookup_classref(classinfo *cls,utf *name);
277 /* return a classref for the given class name */
278 /* (does a linear search!) */
279 constant_classref *class_get_classref(classinfo *cls,utf *name);
281 /* return a classref to the class itself */
282 /* (does a linear search!) */
283 constant_classref *class_get_self_classref(classinfo *cls);
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);
289 /* return a classref for the component type of the given array type */
290 constant_classref *class_get_classref_component_of(constant_classref *ref);
292 /* get a class' field by name and descriptor */
293 fieldinfo *class_findfield(classinfo *c, utf *name, utf *desc);
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);
299 /* search class for a field */
300 fieldinfo *class_resolvefield(classinfo *c, utf *name, utf *desc, classinfo *referer, bool throwexception);
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);
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);
312 bool class_issubclass(classinfo *sub, classinfo *super);
314 /* some debugging functions */
317 void class_printflags(classinfo *c);
318 void class_print(classinfo *c);
319 void class_println(classinfo *c);
323 void class_showmethods(classinfo *c);
324 void class_showconstantpool(classinfo *c);
326 #endif /* _CLASS_H */
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 * ---------------------------------------------------------------------
336 * indent-tabs-mode: t