1 /* src/vmcore/class.h - class related functions header
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29 /* forward typedefs ***********************************************************/
31 typedef struct classinfo classinfo;
32 typedef struct innerclassinfo innerclassinfo;
33 typedef struct extra_classref extra_classref;
34 typedef struct castinfo castinfo;
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. Whether
80 the size of the dummy structure is big enough is checked during
81 runtime in vm_create. */
85 #if defined(WITH_CLASSPATH_GNU)
87 #elif defined(WITH_CLASSPATH_SUN)
89 #elif defined(WITH_CLASSPATH_CLDC1_1)
92 # error unknown classpath configuration
94 } dummy_java_lang_Class;
96 struct classinfo { /* class structure */
97 dummy_java_lang_Class object;
99 s4 flags; /* ACC flags */
100 utf *name; /* class name */
102 s4 cpcount; /* number of entries in constant pool */
103 u1 *cptags; /* constant pool tags */
104 voidptr *cpinfos; /* pointer to constant pool info structures */
106 s4 classrefcount; /* number of symbolic class references */
107 constant_classref *classrefs; /* table of symbolic class references */
108 extra_classref *extclassrefs; /* additional classrefs */
109 s4 parseddescsize; /* size of the parsed descriptors block */
110 u1 *parseddescs; /* parsed descriptors */
112 classinfo *super; /* super class */
113 classinfo *sub; /* sub class pointer */
114 classinfo *nextsub; /* pointer to next class in sub class list */
116 int32_t interfacescount; /* number of interfaces */
117 classinfo **interfaces; /* super interfaces */
119 int32_t fieldscount; /* number of fields */
120 fieldinfo *fields; /* field table */
122 int32_t methodscount; /* number of methods */
123 methodinfo *methods; /* method table */
125 s4 state; /* current class state */
126 s4 index; /* hierarchy depth (classes) or index */
128 s4 instancesize; /* size of an instance of this class */
130 vftbl_t *vftbl; /* pointer to virtual function table */
132 methodinfo *finalizer; /* finalizer method */
134 u2 innerclasscount; /* number of inner classes */
135 innerclassinfo *innerclass;
137 classref_or_classinfo declaringclass;
138 classref_or_classinfo enclosingclass; /* enclosing class */
139 constant_nameandtype *enclosingmethod; /* enclosing method */
141 utf *packagename; /* full name of the package */
142 utf *sourcefile; /* SourceFile attribute */
143 #if defined(ENABLE_JAVASE)
144 utf *signature; /* Signature attribute */
145 #if defined(ENABLE_ANNOTATIONS)
146 /* All the annotation attributes are NULL (and not a zero length array) */
147 /* if there is nothing. */
148 java_object_t *annotations; /* annotations of this class */
150 java_object_t *method_annotations; /* array of annotations of the methods */
151 java_object_t *method_parameterannotations; /* array of parameter */
152 /* annotations of the methods */
153 java_object_t *method_annotationdefaults; /* array of annotation default */
154 /* values of the methods */
156 java_object_t *field_annotations; /* array of annotations of the fields */
160 classloader *classloader; /* NULL for bootstrap classloader */
162 #if defined(ENABLE_JAVASE)
163 # if defined(WITH_CLASSPATH_SUN)
164 java_object_t *protectiondomain;
165 java_objectarray_t *signers;
171 /* innerclassinfo *************************************************************/
173 struct innerclassinfo {
174 classref_or_classinfo inner_class; /* inner class pointer */
175 classref_or_classinfo outer_class; /* outer class pointer */
176 utf *name; /* innerclass name */
177 s4 flags; /* ACC flags */
181 /* extra_classref **************************************************************
183 for classrefs not occurring within descriptors
185 *******************************************************************************/
187 struct extra_classref {
188 extra_classref *next;
189 constant_classref classref;
193 /* castinfo *******************************************************************/
202 /* global variables ***********************************************************/
204 /* frequently used classes ****************************************************/
206 /* important system classes */
208 extern classinfo *class_java_lang_Object;
209 extern classinfo *class_java_lang_Class;
210 extern classinfo *class_java_lang_ClassLoader;
211 extern classinfo *class_java_lang_Cloneable;
212 extern classinfo *class_java_lang_SecurityManager;
213 extern classinfo *class_java_lang_String;
214 extern classinfo *class_java_lang_System;
215 extern classinfo *class_java_lang_Thread;
216 extern classinfo *class_java_lang_ThreadGroup;
217 extern classinfo *class_java_lang_Throwable;
218 extern classinfo *class_java_io_Serializable;
220 #if defined(WITH_CLASSPATH_GNU)
221 extern classinfo *class_java_lang_VMSystem;
222 extern classinfo *class_java_lang_VMThread;
223 extern classinfo *class_java_lang_VMThrowable;
226 #if defined(WITH_CLASSPATH_SUN)
227 extern classinfo *class_sun_reflect_MagicAccessorImpl;
230 #if defined(ENABLE_JAVASE)
231 extern classinfo *class_java_lang_Void;
234 extern classinfo *class_java_lang_Boolean;
235 extern classinfo *class_java_lang_Byte;
236 extern classinfo *class_java_lang_Character;
237 extern classinfo *class_java_lang_Short;
238 extern classinfo *class_java_lang_Integer;
239 extern classinfo *class_java_lang_Long;
240 extern classinfo *class_java_lang_Float;
241 extern classinfo *class_java_lang_Double;
243 /* some classes which may be used more often */
245 #if defined(ENABLE_JAVASE)
246 extern classinfo *class_java_lang_StackTraceElement;
247 extern classinfo *class_java_lang_reflect_Constructor;
248 extern classinfo *class_java_lang_reflect_Field;
249 extern classinfo *class_java_lang_reflect_Method;
250 extern classinfo *class_java_security_PrivilegedAction;
251 extern classinfo *class_java_util_Vector;
252 extern classinfo *class_java_util_HashMap;
254 extern classinfo *arrayclass_java_lang_Object;
256 # if defined(ENABLE_ANNOTATIONS)
257 extern classinfo *class_sun_reflect_ConstantPool;
258 # if defined(WITH_CLASSPATH_GNU)
259 extern classinfo *class_sun_reflect_annotation_AnnotationParser;
265 /* pseudo classes for the type checker ****************************************/
268 * pseudo_class_Arraystub
269 * (extends Object implements Cloneable, java.io.Serializable)
271 * If two arrays of incompatible component types are merged,
272 * the resulting reference has no accessible components.
273 * The result does, however, implement the interfaces Cloneable
274 * and java.io.Serializable. This pseudo class is used internally
275 * to represent such results. (They are *not* considered arrays!)
279 * This pseudo class is used internally to represent the
284 * This pseudo class is used internally to represent the
285 * the 'uninitialized object' type.
288 extern classinfo *pseudo_class_Arraystub;
289 extern classinfo *pseudo_class_Null;
290 extern classinfo *pseudo_class_New;
293 /* inline functions ***********************************************************/
295 /* class_is_primitive **********************************************************
297 Checks if the given class is a primitive class.
299 *******************************************************************************/
301 static inline bool class_is_primitive(classinfo *c)
303 if (c->flags & ACC_CLASS_PRIMITIVE)
310 /* class_is_anonymousclass *****************************************************
312 Checks if the given class is an anonymous class.
314 *******************************************************************************/
316 static inline bool class_is_anonymousclass(classinfo *c)
318 if (c->flags & ACC_CLASS_ANONYMOUS)
325 /* class_is_array **************************************************************
327 Checks if the given class is an array class.
329 *******************************************************************************/
331 static inline bool class_is_array(classinfo *c)
333 if (!(c->state & CLASS_LINKED))
337 return (c->vftbl->arraydesc != NULL);
341 /* class_is_interface **********************************************************
343 Checks if the given class is an interface.
345 *******************************************************************************/
347 static inline bool class_is_interface(classinfo *c)
349 if (c->flags & ACC_INTERFACE)
356 /* class_is_localclass *********************************************************
358 Checks if the given class is a local class.
360 *******************************************************************************/
362 static inline bool class_is_localclass(classinfo *c)
364 if ((c->enclosingmethod != NULL) && !class_is_anonymousclass(c))
371 /* class_is_memberclass ********************************************************
373 Checks if the given class is a member class.
375 *******************************************************************************/
377 static inline bool class_is_memberclass(classinfo *c)
379 if (c->flags & ACC_CLASS_MEMBER)
386 /* class_get_classloader *******************************************************
388 Return the classloader of the given class.
390 *******************************************************************************/
392 static inline classloader *class_get_classloader(classinfo *c)
398 /* The classloader may be NULL. */
404 /* class_get_superclass ********************************************************
406 Return the super class of the given class.
408 *******************************************************************************/
410 static inline classinfo *class_get_superclass(classinfo *c)
412 /* For interfaces we return NULL. */
414 if (c->flags & ACC_INTERFACE)
417 /* For java/lang/Object, primitive-type and Void classes c->super
418 is NULL and we return NULL. */
424 /* function prototypes ********************************************************/
426 classinfo *class_create_classinfo(utf *u);
427 void class_postset_header_vftbl(void);
428 classinfo *class_define(utf *name, classloader *cl, int32_t length, uint8_t *data, java_handle_t *pd);
429 void class_set_packagename(classinfo *c);
431 bool class_load_attributes(classbuffer *cb);
433 /* retrieve constantpool element */
434 voidptr class_getconstant(classinfo *class, u4 pos, u4 ctype);
435 voidptr innerclass_getconstant(classinfo *c, u4 pos, u4 ctype);
437 /* frees all resources used by the class */
438 void class_free(classinfo *);
440 /* return an array class with the given component class */
441 classinfo *class_array_of(classinfo *component,bool link);
443 /* return an array class with the given dimension and element class */
444 classinfo *class_multiarray_of(s4 dim, classinfo *element,bool link);
446 /* return a classref for the given class name */
447 /* (does a linear search!) */
448 constant_classref *class_lookup_classref(classinfo *cls,utf *name);
450 /* return a classref for the given class name */
451 /* (does a linear search!) */
452 constant_classref *class_get_classref(classinfo *cls,utf *name);
454 /* return a classref to the class itself */
455 /* (does a linear search!) */
456 constant_classref *class_get_self_classref(classinfo *cls);
458 /* return a classref for an array with the given dimension of with the */
459 /* given component type */
460 constant_classref *class_get_classref_multiarray_of(s4 dim,constant_classref *ref);
462 /* return a classref for the component type of the given array type */
463 constant_classref *class_get_classref_component_of(constant_classref *ref);
465 /* get a class' field by name and descriptor */
466 fieldinfo *class_findfield(classinfo *c, utf *name, utf *desc);
468 /* search 'classinfo'-structure for a field with the specified name */
469 fieldinfo *class_findfield_by_name(classinfo *c, utf *name);
470 s4 class_findfield_index_by_name(classinfo *c, utf *name);
472 /* search class for a field */
473 fieldinfo *class_resolvefield(classinfo *c, utf *name, utf *desc, classinfo *referer, bool throwexception);
475 /* search for a method with a specified name and descriptor */
476 methodinfo *class_findmethod(classinfo *c, utf *name, utf *desc);
477 methodinfo *class_resolvemethod(classinfo *c, utf *name, utf *dest);
478 methodinfo *class_resolveclassmethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool throwexception);
479 methodinfo *class_resolveinterfacemethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool throwexception);
481 bool class_issubclass(classinfo *sub, classinfo *super);
482 bool class_isanysubclass(classinfo *sub, classinfo *super);
484 bool class_is_primitive(classinfo *c);
485 bool class_is_anonymousclass(classinfo *c);
486 bool class_is_array(classinfo *c);
487 bool class_is_interface(classinfo *c);
488 bool class_is_localclass(classinfo *c);
489 bool class_is_memberclass(classinfo *c);
491 classloader *class_get_classloader(classinfo *c);
492 classinfo *class_get_superclass(classinfo *c);
493 classinfo *class_get_componenttype(classinfo *c);
494 java_handle_objectarray_t *class_get_declaredclasses(classinfo *c, bool publicOnly);
495 classinfo *class_get_declaringclass(classinfo *c);
496 classinfo *class_get_enclosingclass(classinfo *c);
497 methodinfo *class_get_enclosingmethod(classinfo *c);
498 java_handle_objectarray_t *class_get_interfaces(classinfo *c);
499 java_handle_bytearray_t *class_get_annotations(classinfo *c);
500 int32_t class_get_modifiers(classinfo *c, bool ignoreInnerClassesAttrib);
502 #if defined(ENABLE_JAVASE)
503 utf *class_get_signature(classinfo *c);
506 /* some debugging functions */
509 void class_printflags(classinfo *c);
510 void class_print(classinfo *c);
511 void class_println(classinfo *c);
512 void class_classref_print(constant_classref *cr);
513 void class_classref_println(constant_classref *cr);
514 void class_classref_or_classinfo_print(classref_or_classinfo c);
515 void class_classref_or_classinfo_println(classref_or_classinfo c);
519 void class_showmethods(classinfo *c);
520 void class_showconstantpool(classinfo *c);
522 #endif /* _CLASS_H */
526 * These are local overrides for various environment variables in Emacs.
527 * Please do not remove this and leave it at the end of the file, where
528 * Emacs will automagically detect them.
529 * ---------------------------------------------------------------------
532 * indent-tabs-mode: t