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 8395 2007-08-22 13:12:46Z panzi $
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. Whether
84 the size of the dummy structure is big enough is checked during
85 runtime in vm_create. */
89 #if defined(WITH_CLASSPATH_GNU)
91 #elif defined(WITH_CLASSPATH_SUN)
93 #elif defined(WITH_CLASSPATH_CLDC1_1)
96 # error unknown classpath configuration
98 } dummy_java_lang_Class;
100 struct classinfo { /* class structure */
101 dummy_java_lang_Class object;
103 s4 flags; /* ACC flags */
104 utf *name; /* class name */
106 s4 cpcount; /* number of entries in constant pool */
107 u1 *cptags; /* constant pool tags */
108 voidptr *cpinfos; /* pointer to constant pool info structures */
110 s4 classrefcount; /* number of symbolic class references */
111 constant_classref *classrefs; /* table of symbolic class references */
112 extra_classref *extclassrefs; /* additional classrefs */
113 s4 parseddescsize; /* size of the parsed descriptors block */
114 u1 *parseddescs; /* parsed descriptors */
116 classref_or_classinfo super; /* super class */
117 classinfo *sub; /* sub class pointer */
118 classinfo *nextsub; /* pointer to next class in sub class list */
120 s4 interfacescount; /* number of interfaces */
121 classref_or_classinfo *interfaces; /* superinterfaces */
123 s4 fieldscount; /* number of fields */
124 fieldinfo *fields; /* field table */
126 s4 methodscount; /* number of methods */
127 methodinfo *methods; /* method table */
129 s4 state; /* current class state */
130 s4 index; /* hierarchy depth (classes) or index */
132 s4 instancesize; /* size of an instance of this class */
134 vftbl_t *vftbl; /* pointer to virtual function table */
136 methodinfo *finalizer; /* finalizer method */
138 u2 innerclasscount; /* number of inner classes */
139 innerclassinfo *innerclass;
141 classref_or_classinfo declaringclass;
142 classref_or_classinfo enclosingclass; /* enclosing class */
143 constant_nameandtype *enclosingmethod; /* enclosing method */
145 utf *packagename; /* full name of the package */
146 utf *sourcefile; /* SourceFile attribute */
147 #if defined(ENABLE_JAVASE)
148 utf *signature; /* Signature attribute */
149 #if defined(ENABLE_ANNOTATIONS)
150 /* all the anntation attributes are NULL (and not a zero length array)
151 if there is nothing */
152 annotation_bytearray_t *annotations; /* annotations of this class */
154 annotation_bytearrays_t *method_annotations; /* array of annotations for */
156 annotation_bytearrays_t *method_parameterannotations; /* array of */
157 /* parameter annotations for the methods */
158 annotation_bytearrays_t *method_annotationdefaults; /* array for */
159 /* annotation default values for the */
162 annotation_bytearrays_t *field_annotations; /* array of annotations for */
166 classloader *classloader; /* NULL for bootstrap classloader */
168 #if defined(ENABLE_JAVASE)
169 # if defined(WITH_CLASSPATH_SUN)
170 java_object_t *protectiondomain;
176 /* innerclassinfo *************************************************************/
178 struct innerclassinfo {
179 classref_or_classinfo inner_class; /* inner class pointer */
180 classref_or_classinfo outer_class; /* outer class pointer */
181 utf *name; /* innerclass name */
182 s4 flags; /* ACC flags */
186 /* extra_classref **************************************************************
188 for classrefs not occurring within descriptors
190 *******************************************************************************/
192 struct extra_classref {
193 extra_classref *next;
194 constant_classref classref;
198 /* castinfo *******************************************************************/
207 /* global variables ***********************************************************/
209 /* frequently used classes ****************************************************/
211 /* important system classes */
213 extern classinfo *class_java_lang_Object;
214 extern classinfo *class_java_lang_Class;
215 extern classinfo *class_java_lang_ClassLoader;
216 extern classinfo *class_java_lang_Cloneable;
217 extern classinfo *class_java_lang_SecurityManager;
218 extern classinfo *class_java_lang_String;
219 extern classinfo *class_java_lang_System;
220 extern classinfo *class_java_lang_Thread;
221 extern classinfo *class_java_lang_ThreadGroup;
222 extern classinfo *class_java_lang_VMSystem;
223 extern classinfo *class_java_lang_VMThread;
224 extern classinfo *class_java_io_Serializable;
226 #if defined(WITH_CLASSPATH_SUN)
227 extern classinfo *class_sun_reflect_MagicAccessorImpl;
230 /* system exception classes required in cacao */
232 extern classinfo *class_java_lang_Throwable;
233 extern classinfo *class_java_lang_Error;
234 extern classinfo *class_java_lang_LinkageError;
235 extern classinfo *class_java_lang_NoClassDefFoundError;
236 extern classinfo *class_java_lang_OutOfMemoryError;
237 extern classinfo *class_java_lang_VirtualMachineError;
239 #if defined(WITH_CLASSPATH_GNU)
240 extern classinfo *class_java_lang_VMThrowable;
243 extern classinfo *class_java_lang_Exception;
244 extern classinfo *class_java_lang_ClassCastException;
245 extern classinfo *class_java_lang_ClassNotFoundException;
247 #if defined(ENABLE_JAVASE)
248 extern classinfo *class_java_lang_Void;
250 #if defined(ENABLE_ANNOTATIONS)
251 extern classinfo *class_sun_reflect_ConstantPool;
252 #if defined(WITH_CLASSPATH_GNU)
253 extern classinfo *class_sun_reflect_annotation_AnnotationParser;
258 extern classinfo *class_java_lang_Boolean;
259 extern classinfo *class_java_lang_Byte;
260 extern classinfo *class_java_lang_Character;
261 extern classinfo *class_java_lang_Short;
262 extern classinfo *class_java_lang_Integer;
263 extern classinfo *class_java_lang_Long;
264 extern classinfo *class_java_lang_Float;
265 extern classinfo *class_java_lang_Double;
268 /* some runtime exception */
270 extern classinfo *class_java_lang_NullPointerException;
273 /* some classes which may be used more often */
275 #if defined(ENABLE_JAVASE)
276 extern classinfo *class_java_lang_StackTraceElement;
277 extern classinfo *class_java_lang_reflect_Constructor;
278 extern classinfo *class_java_lang_reflect_Field;
279 extern classinfo *class_java_lang_reflect_Method;
280 extern classinfo *class_java_security_PrivilegedAction;
281 extern classinfo *class_java_util_Vector;
283 extern classinfo *arrayclass_java_lang_Object;
287 /* pseudo classes for the type checker ****************************************/
290 * pseudo_class_Arraystub
291 * (extends Object implements Cloneable, java.io.Serializable)
293 * If two arrays of incompatible component types are merged,
294 * the resulting reference has no accessible components.
295 * The result does, however, implement the interfaces Cloneable
296 * and java.io.Serializable. This pseudo class is used internally
297 * to represent such results. (They are *not* considered arrays!)
301 * This pseudo class is used internally to represent the
306 * This pseudo class is used internally to represent the
307 * the 'uninitialized object' type.
310 extern classinfo *pseudo_class_Arraystub;
311 extern classinfo *pseudo_class_Null;
312 extern classinfo *pseudo_class_New;
315 /* function prototypes ********************************************************/
317 classinfo *class_create_classinfo(utf *u);
318 void class_postset_header_vftbl(void);
319 classinfo *class_define(utf *name, classloader *cl, int32_t length, const uint8_t *data, java_handle_t *pd);
320 void class_set_packagename(classinfo *c);
322 bool class_load_attributes(classbuffer *cb);
324 /* retrieve constantpool element */
325 voidptr class_getconstant(classinfo *class, u4 pos, u4 ctype);
326 voidptr innerclass_getconstant(classinfo *c, u4 pos, u4 ctype);
328 /* frees all resources used by the class */
329 void class_free(classinfo *);
331 /* return an array class with the given component class */
332 classinfo *class_array_of(classinfo *component,bool link);
334 /* return an array class with the given dimension and element class */
335 classinfo *class_multiarray_of(s4 dim, classinfo *element,bool link);
337 /* return a classref for the given class name */
338 /* (does a linear search!) */
339 constant_classref *class_lookup_classref(classinfo *cls,utf *name);
341 /* return a classref for the given class name */
342 /* (does a linear search!) */
343 constant_classref *class_get_classref(classinfo *cls,utf *name);
345 /* return a classref to the class itself */
346 /* (does a linear search!) */
347 constant_classref *class_get_self_classref(classinfo *cls);
349 /* return a classref for an array with the given dimension of with the */
350 /* given component type */
351 constant_classref *class_get_classref_multiarray_of(s4 dim,constant_classref *ref);
353 /* return a classref for the component type of the given array type */
354 constant_classref *class_get_classref_component_of(constant_classref *ref);
356 /* get a class' field by name and descriptor */
357 fieldinfo *class_findfield(classinfo *c, utf *name, utf *desc);
359 /* search 'classinfo'-structure for a field with the specified name */
360 fieldinfo *class_findfield_by_name(classinfo *c, utf *name);
361 s4 class_findfield_index_by_name(classinfo *c, utf *name);
363 /* search class for a field */
364 fieldinfo *class_resolvefield(classinfo *c, utf *name, utf *desc, classinfo *referer, bool throwexception);
366 /* search for a method with a specified name and descriptor */
367 methodinfo *class_findmethod(classinfo *c, utf *name, utf *desc);
368 methodinfo *class_resolvemethod(classinfo *c, utf *name, utf *dest);
369 methodinfo *class_resolveclassmethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool throwexception);
370 methodinfo *class_resolveinterfacemethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool throwexception);
372 bool class_issubclass(classinfo *sub, classinfo *super);
373 bool class_isanysubclass(classinfo *sub, classinfo *super);
375 bool class_is_primitive(classinfo *c);
376 bool class_is_anonymousclass(classinfo *c);
377 bool class_is_array(classinfo *c);
378 bool class_is_interface(classinfo *c);
379 bool class_is_localclass(classinfo *c);
380 bool class_is_memberclass(classinfo *c);
382 classinfo *class_get_superclass(classinfo *c);
383 classinfo *class_get_componenttype(classinfo *c);
384 java_handle_objectarray_t *class_get_declaredclasses(classinfo *c, bool publicOnly);
385 classinfo *class_get_declaringclass(classinfo *c);
386 classinfo *class_get_enclosingclass(classinfo *c);
387 java_handle_objectarray_t *class_get_interfaces(classinfo *c);
388 java_handle_bytearray_t *class_get_annotations(classinfo *c);
390 #if defined(ENABLE_JAVASE)
391 utf *class_get_signature(classinfo *c);
394 /* some debugging functions */
397 void class_printflags(classinfo *c);
398 void class_print(classinfo *c);
399 void class_println(classinfo *c);
400 void class_classref_print(constant_classref *cr);
401 void class_classref_println(constant_classref *cr);
402 void class_classref_or_classinfo_print(classref_or_classinfo c);
403 void class_classref_or_classinfo_println(classref_or_classinfo c);
407 void class_showmethods(classinfo *c);
408 void class_showconstantpool(classinfo *c);
410 #endif /* _CLASS_H */
414 * These are local overrides for various environment variables in Emacs.
415 * Please do not remove this and leave it at the end of the file, where
416 * Emacs will automagically detect them.
417 * ---------------------------------------------------------------------
420 * indent-tabs-mode: t