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 8179 2007-07-05 11:21:08Z michi $
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;
47 #include "toolbox/list.h"
49 #include "vm/global.h"
51 #if defined(ENABLE_JAVASE)
52 # include "vmcore/annotation.h"
55 #include "vmcore/field.h"
56 #include "vmcore/linker.h"
57 #include "vmcore/loader.h"
58 #include "vmcore/method.h"
59 #include "vmcore/references.h"
60 #include "vmcore/utf8.h"
63 /* class state defines ********************************************************/
65 #define CLASS_LOADING 0x0001
66 #define CLASS_LOADED 0x0002
67 #define CLASS_LINKING 0x0004
68 #define CLASS_LINKED 0x0008
69 #define CLASS_INITIALIZING 0x0010
70 #define CLASS_INITIALIZED 0x0020
71 #define CLASS_ERROR 0x0040
74 /* some macros ****************************************************************/
76 #define CLASS_IS_OR_ALMOST_INITIALIZED(c) \
77 (((c)->state & CLASS_INITIALIZING) || ((c)->state & CLASS_INITIALIZED))
80 /* classinfo ******************************************************************/
82 /* We define this dummy structure of java_lang_Class so we can
83 bootstrap cacaoh without needing a java_lang_Class.h file. If the
84 size is big enough, is checked during runtime in vm_create. */
87 java_objectheader header;
88 #if defined(WITH_CLASSPATH_GNU)
90 #elif defined(WITH_CLASSPATH_SUN)
92 #elif defined(WITH_CLASSPATH_CLDC1_1)
95 # error unknown classpath configuration
97 } dummy_java_lang_Class;
99 struct classinfo { /* class structure */
100 dummy_java_lang_Class object;
102 s4 flags; /* ACC flags */
103 utf *name; /* class name */
105 s4 cpcount; /* number of entries in constant pool */
106 u1 *cptags; /* constant pool tags */
107 voidptr *cpinfos; /* pointer to constant pool info structures */
109 s4 classrefcount; /* number of symbolic class references */
110 constant_classref *classrefs; /* table of symbolic class references */
111 extra_classref *extclassrefs; /* additional classrefs */
112 s4 parseddescsize; /* size of the parsed descriptors block */
113 u1 *parseddescs; /* parsed descriptors */
115 classref_or_classinfo super; /* super class */
116 classinfo *sub; /* sub class pointer */
117 classinfo *nextsub; /* pointer to next class in sub class list */
119 s4 interfacescount; /* number of interfaces */
120 classref_or_classinfo *interfaces; /* superinterfaces */
122 s4 fieldscount; /* number of fields */
123 fieldinfo *fields; /* field table */
125 s4 methodscount; /* number of methods */
126 methodinfo *methods; /* method table */
128 listnode_t listnode; /* linkage */
130 s4 state; /* current class state */
131 s4 index; /* hierarchy depth (classes) or index */
133 s4 instancesize; /* size of an instance of this class */
135 vftbl_t *vftbl; /* pointer to virtual function table */
137 methodinfo *finalizer; /* finalizer method */
139 u2 innerclasscount; /* number of inner classes */
140 innerclassinfo *innerclass;
142 #if defined(ENABLE_JAVASE)
143 classref_or_classinfo enclosingclass; /* enclosing class */
144 constant_nameandtype *enclosingmethod; /* enclosing method */
147 utf *packagename; /* full name of the package */
148 utf *sourcefile; /* SourceFile attribute */
149 #if defined(ENABLE_JAVASE)
150 utf *signature; /* Signature attribute */
151 s4 runtimevisibleannotationscount;
152 annotation_t *runtimevisibleannotations;
154 classloader *classloader; /* NULL for bootstrap classloader */
158 /* innerclassinfo *************************************************************/
160 struct innerclassinfo {
161 classref_or_classinfo inner_class; /* inner class pointer */
162 classref_or_classinfo outer_class; /* outer class pointer */
163 utf *name; /* innerclass name */
164 s4 flags; /* ACC flags */
168 /* extra_classref **************************************************************
170 for classrefs not occurring within descriptors
172 *******************************************************************************/
174 struct extra_classref {
175 extra_classref *next;
176 constant_classref classref;
180 /* castinfo *******************************************************************/
189 /* global variables ***********************************************************/
191 extern list_t unlinkedclasses; /* this is only used for eager class loading */
194 /* frequently used classes ****************************************************/
196 /* important system classes */
198 extern classinfo *class_java_lang_Object;
199 extern classinfo *class_java_lang_Class;
200 extern classinfo *class_java_lang_ClassLoader;
201 extern classinfo *class_java_lang_Cloneable;
202 extern classinfo *class_java_lang_SecurityManager;
203 extern classinfo *class_java_lang_String;
204 extern classinfo *class_java_lang_System;
205 extern classinfo *class_java_lang_Thread;
206 extern classinfo *class_java_lang_ThreadGroup;
207 extern classinfo *class_java_lang_VMSystem;
208 extern classinfo *class_java_lang_VMThread;
209 extern classinfo *class_java_io_Serializable;
212 /* system exception classes required in cacao */
214 extern classinfo *class_java_lang_Throwable;
215 extern classinfo *class_java_lang_Error;
216 extern classinfo *class_java_lang_LinkageError;
217 extern classinfo *class_java_lang_NoClassDefFoundError;
218 extern classinfo *class_java_lang_OutOfMemoryError;
219 extern classinfo *class_java_lang_VirtualMachineError;
221 #if defined(WITH_CLASSPATH_GNU)
222 extern classinfo *class_java_lang_VMThrowable;
225 extern classinfo *class_java_lang_Exception;
226 extern classinfo *class_java_lang_ClassCastException;
227 extern classinfo *class_java_lang_ClassNotFoundException;
229 #if defined(ENABLE_JAVASE)
230 extern classinfo *class_java_lang_Void;
233 extern classinfo *class_java_lang_Boolean;
234 extern classinfo *class_java_lang_Byte;
235 extern classinfo *class_java_lang_Character;
236 extern classinfo *class_java_lang_Short;
237 extern classinfo *class_java_lang_Integer;
238 extern classinfo *class_java_lang_Long;
239 extern classinfo *class_java_lang_Float;
240 extern classinfo *class_java_lang_Double;
243 /* some runtime exception */
245 extern classinfo *class_java_lang_NullPointerException;
248 /* some classes which may be used more often */
250 #if defined(ENABLE_JAVASE)
251 extern classinfo *class_java_lang_StackTraceElement;
252 extern classinfo *class_java_lang_reflect_Constructor;
253 extern classinfo *class_java_lang_reflect_Field;
254 extern classinfo *class_java_lang_reflect_Method;
255 extern classinfo *class_java_security_PrivilegedAction;
256 extern classinfo *class_java_util_Vector;
258 extern classinfo *arrayclass_java_lang_Object;
262 /* pseudo classes for the type checker ****************************************/
265 * pseudo_class_Arraystub
266 * (extends Object implements Cloneable, java.io.Serializable)
268 * If two arrays of incompatible component types are merged,
269 * the resulting reference has no accessible components.
270 * The result does, however, implement the interfaces Cloneable
271 * and java.io.Serializable. This pseudo class is used internally
272 * to represent such results. (They are *not* considered arrays!)
276 * This pseudo class is used internally to represent the
281 * This pseudo class is used internally to represent the
282 * the 'uninitialized object' type.
285 extern classinfo *pseudo_class_Arraystub;
286 extern classinfo *pseudo_class_Null;
287 extern classinfo *pseudo_class_New;
290 /* function prototypes ********************************************************/
292 /* create a new classinfo struct */
293 classinfo *class_create_classinfo(utf *u);
295 /* postset's the header.vftbl */
296 void class_postset_header_vftbl(void);
298 classinfo *class_define(utf *name, classloader *cl, s4 length, u1 *data);
300 /* set the package name after the name has been set */
301 void class_set_packagename(classinfo *c);
303 bool class_load_attributes(classbuffer *cb);
305 /* retrieve constantpool element */
306 voidptr class_getconstant(classinfo *class, u4 pos, u4 ctype);
307 voidptr innerclass_getconstant(classinfo *c, u4 pos, u4 ctype);
309 /* frees all resources used by the class */
310 void class_free(classinfo *);
312 /* return an array class with the given component class */
313 classinfo *class_array_of(classinfo *component,bool link);
315 /* return an array class with the given dimension and element class */
316 classinfo *class_multiarray_of(s4 dim, classinfo *element,bool link);
318 /* return a classref for the given class name */
319 /* (does a linear search!) */
320 constant_classref *class_lookup_classref(classinfo *cls,utf *name);
322 /* return a classref for the given class name */
323 /* (does a linear search!) */
324 constant_classref *class_get_classref(classinfo *cls,utf *name);
326 /* return a classref to the class itself */
327 /* (does a linear search!) */
328 constant_classref *class_get_self_classref(classinfo *cls);
330 /* return a classref for an array with the given dimension of with the */
331 /* given component type */
332 constant_classref *class_get_classref_multiarray_of(s4 dim,constant_classref *ref);
334 /* return a classref for the component type of the given array type */
335 constant_classref *class_get_classref_component_of(constant_classref *ref);
337 /* get a class' field by name and descriptor */
338 fieldinfo *class_findfield(classinfo *c, utf *name, utf *desc);
340 /* search 'classinfo'-structure for a field with the specified name */
341 fieldinfo *class_findfield_by_name(classinfo *c, utf *name);
342 s4 class_findfield_index_by_name(classinfo *c, utf *name);
344 /* search class for a field */
345 fieldinfo *class_resolvefield(classinfo *c, utf *name, utf *desc, classinfo *referer, bool throwexception);
347 /* search for a method with a specified name and descriptor */
348 methodinfo *class_findmethod(classinfo *c, utf *name, utf *desc);
349 methodinfo *class_resolvemethod(classinfo *c, utf *name, utf *dest);
350 methodinfo *class_resolveclassmethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool throwexception);
351 methodinfo *class_resolveinterfacemethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool throwexception);
353 bool class_issubclass(classinfo *sub, classinfo *super);
354 bool class_isanysubclass(classinfo *sub, classinfo *super);
355 bool class_is_array(classinfo *c);
356 bool class_is_interface(classinfo *c);
358 /* some debugging functions */
361 void class_printflags(classinfo *c);
362 void class_print(classinfo *c);
363 void class_println(classinfo *c);
364 void class_classref_print(constant_classref *cr);
365 void class_classref_println(constant_classref *cr);
366 void class_classref_or_classinfo_print(classref_or_classinfo c);
367 void class_classref_or_classinfo_println(classref_or_classinfo c);
371 void class_showmethods(classinfo *c);
372 void class_showconstantpool(classinfo *c);
374 #endif /* _CLASS_H */
378 * These are local overrides for various environment variables in Emacs.
379 * Please do not remove this and leave it at the end of the file, where
380 * Emacs will automagically detect them.
381 * ---------------------------------------------------------------------
384 * indent-tabs-mode: t