1 /* src/vm/class.hpp - class related functions header
3 Copyright (C) 1996-2011
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;
42 #if defined(ENABLE_JAVASE)
43 # include "vm/annotation.hpp"
46 #include "vm/field.hpp"
47 #include "vm/global.h"
48 #include "vm/linker.hpp"
49 #include "vm/loader.hpp"
50 #include "vm/method.hpp"
51 #include "vm/references.h"
52 #include "vm/string.hpp"
56 /* class state defines ********************************************************/
58 #define CLASS_LOADING 0x0001
59 #define CLASS_LOADED 0x0002
60 #define CLASS_LINKING 0x0004
61 #define CLASS_LINKED 0x0008
62 #define CLASS_INITIALIZING 0x0010
63 #define CLASS_INITIALIZED 0x0020
64 #define CLASS_ERROR 0x0040
67 /* some macros ****************************************************************/
69 #define CLASS_IS_OR_ALMOST_INITIALIZED(c) \
70 (((c)->state & CLASS_INITIALIZED) || ((c)->state & CLASS_INITIALIZING && class_initializing_thread_is_self((c))))
73 /* classinfo ******************************************************************/
75 /* We define this dummy structure of java_lang_Class so we can
76 bootstrap cacaoh without needing a java_lang_Class.h file. Whether
77 the size of the dummy structure is big enough is checked during
78 runtime in vm_create. */
82 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
84 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
86 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1)
89 # error unknown classpath configuration
91 } dummy_java_lang_Class;
95 struct classinfo { /* class structure */
96 dummy_java_lang_Class object;
98 s4 flags; /* ACC flags */
99 utf *name; /* class name */
101 s4 cpcount; /* number of entries in constant pool */
102 u1 *cptags; /* constant pool tags */
103 void* *cpinfos; /* pointer to constant pool info structures */
105 s4 classrefcount; /* number of symbolic class references */
106 constant_classref *classrefs; /* table of symbolic class references */
107 extra_classref *extclassrefs; /* additional classrefs */
109 classinfo *super; /* super class */
110 classinfo *sub; /* sub class pointer */
111 classinfo *nextsub; /* pointer to next class in sub class list */
113 int32_t interfacescount; /* number of interfaces */
114 classinfo **interfaces; /* super interfaces */
116 int32_t fieldscount; /* number of fields */
117 fieldinfo *fields; /* field table */
119 int32_t methodscount; /* number of methods */
120 methodinfo *methods; /* method table */
122 s4 state; /* current class state */
123 s4 index; /* hierarchy depth (classes) or index */
125 s4 instancesize; /* size of an instance of this class */
127 struct threadobject *initializing_thread;
128 vftbl_t *vftbl; /* pointer to virtual function table */
130 methodinfo *finalizer; /* finalizer method */
132 u2 innerclasscount; /* number of inner classes */
133 innerclassinfo *innerclass;
135 classref_or_classinfo declaringclass;
136 classref_or_classinfo enclosingclass; /* enclosing class */
137 constant_nameandtype *enclosingmethod; /* enclosing method */
139 utf *packagename; /* full name of the package */
140 utf *sourcefile; /* SourceFile attribute */
141 #if defined(ENABLE_JAVASE)
142 utf *signature; /* Signature attribute */
143 #if defined(ENABLE_ANNOTATIONS)
144 /* All the annotation attributes are NULL (and not a zero length array) */
145 /* if there is nothing. */
146 java_object_t *annotations; /* annotations of this class */
148 java_object_t *method_annotations; /* array of annotations of the methods */
149 java_object_t *method_parameterannotations; /* array of parameter */
150 /* annotations of the methods */
151 java_object_t *method_annotationdefaults; /* array of annotation default */
152 /* values of the methods */
154 java_object_t *field_annotations; /* array of annotations of the fields */
158 classloader_t *classloader; /* NULL for bootstrap classloader */
160 #if defined(ENABLE_JAVASE)
161 # if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
162 java_object_t *protectiondomain;
163 java_objectarray_t *signers;
169 /* innerclassinfo *************************************************************/
171 struct innerclassinfo {
172 classref_or_classinfo inner_class; /* inner class pointer */
173 classref_or_classinfo outer_class; /* outer class pointer */
174 utf *name; /* innerclass name */
175 s4 flags; /* ACC flags */
179 /* extra_classref **************************************************************
181 for classrefs not occurring within descriptors
183 *******************************************************************************/
185 struct extra_classref {
186 extra_classref *next;
187 constant_classref classref;
191 /* inline functions ***********************************************************/
198 * Returns the classname of the class, where slashes ('/') are
199 * replaced by dots ('.').
201 * @param c class to get name of
204 inline static java_handle_t* class_get_classname(classinfo* c)
208 /* Create a java string. */
210 s = javastring_new_slash_to_dot(c->name);
216 /* class_is_primitive **********************************************************
218 Checks if the given class is a primitive class.
220 *******************************************************************************/
222 static inline bool class_is_primitive(classinfo *c)
224 if (c->flags & ACC_CLASS_PRIMITIVE)
231 /* class_is_anonymousclass *****************************************************
233 Checks if the given class is an anonymous class.
235 *******************************************************************************/
237 static inline bool class_is_anonymousclass(classinfo *c)
239 if (c->flags & ACC_CLASS_ANONYMOUS)
246 /* class_is_array **************************************************************
248 Checks if the given class is an array class.
250 *******************************************************************************/
252 static inline bool class_is_array(classinfo *c)
254 if (!(c->state & CLASS_LINKED))
258 return (c->vftbl->arraydesc != NULL);
262 /* class_is_interface **********************************************************
264 Checks if the given class is an interface.
266 *******************************************************************************/
268 static inline bool class_is_interface(classinfo *c)
270 if (c->flags & ACC_INTERFACE)
277 /* class_is_localclass *********************************************************
279 Checks if the given class is a local class.
281 *******************************************************************************/
283 static inline bool class_is_localclass(classinfo *c)
285 if ((c->enclosingmethod != NULL) && !class_is_anonymousclass(c))
292 /* class_is_memberclass ********************************************************
294 Checks if the given class is a member class.
296 *******************************************************************************/
298 static inline bool class_is_memberclass(classinfo *c)
300 if (c->flags & ACC_CLASS_MEMBER)
307 /* class_get_classloader *******************************************************
309 Return the classloader of the given class.
311 *******************************************************************************/
313 static inline classloader_t *class_get_classloader(classinfo *c)
319 /* The classloader may be NULL. */
325 /* class_get_superclass ********************************************************
327 Return the super class of the given class.
329 *******************************************************************************/
331 static inline classinfo *class_get_superclass(classinfo *c)
333 /* For interfaces we return NULL. */
335 if (c->flags & ACC_INTERFACE)
338 /* For java/lang/Object, primitive-type and Void classes c->super
339 is NULL and we return NULL. */
345 /* function prototypes ********************************************************/
347 classinfo *class_create_classinfo(utf *u);
348 void class_postset_header_vftbl(void);
349 classinfo *class_define(utf *name, classloader_t *cl, int32_t length, uint8_t *data, java_handle_t *pd);
350 void class_set_packagename(classinfo *c);
352 bool class_load_attributes(classbuffer *cb);
354 /* retrieve constantpool element */
355 void* class_getconstant(classinfo *c, u4 pos, u4 ctype);
356 void* innerclass_getconstant(classinfo *c, u4 pos, u4 ctype);
358 /* frees all resources used by the class */
359 void class_free(classinfo *);
361 /* return an array class with the given component class */
362 classinfo *class_array_of(classinfo *component,bool link);
364 /* return an array class with the given dimension and element class */
365 classinfo *class_multiarray_of(s4 dim, classinfo *element,bool link);
367 /* return a classref for the given class name */
368 /* (does a linear search!) */
369 constant_classref *class_lookup_classref(classinfo *cls,utf *name);
371 /* return a classref for the given class name */
372 /* (does a linear search!) */
373 constant_classref *class_get_classref(classinfo *cls,utf *name);
375 /* return a classref to the class itself */
376 /* (does a linear search!) */
377 constant_classref *class_get_self_classref(classinfo *cls);
379 /* return a classref for an array with the given dimension of with the */
380 /* given component type */
381 constant_classref *class_get_classref_multiarray_of(s4 dim,constant_classref *ref);
383 /* return a classref for the component type of the given array type */
384 constant_classref *class_get_classref_component_of(constant_classref *ref);
386 /* get a class' field by name and descriptor */
387 fieldinfo *class_findfield(classinfo *c, utf *name, utf *desc);
389 /* search 'classinfo'-structure for a field with the specified name */
390 fieldinfo *class_findfield_by_name(classinfo *c, utf *name);
392 /* search class for a field */
393 fieldinfo *class_resolvefield(classinfo *c, utf *name, utf *desc, classinfo *referer);
395 /* search for a method with a specified name and descriptor */
396 methodinfo *class_findmethod(classinfo *c, utf *name, utf *desc);
397 methodinfo *class_resolvemethod(classinfo *c, utf *name, utf *dest);
398 methodinfo *class_resolveclassmethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool throwexception);
399 methodinfo *class_resolveinterfacemethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool throwexception);
401 bool class_issubclass(classinfo *sub, classinfo *super);
402 bool class_isanysubclass(classinfo *sub, classinfo *super);
403 bool class_is_arraycompatible(arraydescriptor *desc, arraydescriptor *target);
404 bool class_is_assignable_from(classinfo *to, classinfo *from);
405 bool class_is_instance(classinfo *c, java_handle_t *h);
407 classloader_t *class_get_classloader(classinfo *c);
408 classinfo *class_get_superclass(classinfo *c);
409 classinfo *class_get_componenttype(classinfo *c);
410 java_handle_objectarray_t *class_get_declaredclasses(classinfo *c, bool publicOnly);
411 java_handle_objectarray_t *class_get_declaredconstructors(classinfo *c, bool publicOnly);
412 java_handle_objectarray_t *class_get_declaredfields(classinfo *c, bool publicOnly);
413 java_handle_objectarray_t *class_get_declaredmethods(classinfo *c, bool publicOnly);
414 classinfo *class_get_declaringclass(classinfo *c);
415 classinfo *class_get_enclosingclass(classinfo *c);
416 java_handle_t* class_get_enclosingconstructor(classinfo *c);
417 methodinfo* class_get_enclosingmethod_raw(classinfo *c);
418 java_handle_t* class_get_enclosingmethod(classinfo *c);
419 java_handle_objectarray_t *class_get_interfaces(classinfo *c);
420 java_handle_bytearray_t *class_get_annotations(classinfo *c);
421 int32_t class_get_modifiers(classinfo *c, bool ignoreInnerClassesAttrib);
422 java_handle_t *class_get_name(classinfo *c);
424 #if defined(ENABLE_JAVASE)
425 utf *class_get_signature(classinfo *c);
428 bool class_initializing_thread_is_self(classinfo *c);
430 /* some debugging functions */
433 void class_printflags(classinfo *c);
434 void class_print(classinfo *c);
435 void class_println(classinfo *c);
436 void class_classref_print(constant_classref *cr);
437 void class_classref_println(constant_classref *cr);
438 void class_classref_or_classinfo_print(classref_or_classinfo c);
439 void class_classref_or_classinfo_println(classref_or_classinfo c);
443 void class_showmethods(classinfo *c);
444 void class_showconstantpool(classinfo *c);
450 #endif /* _CLASS_HPP */
454 * These are local overrides for various environment variables in Emacs.
455 * Please do not remove this and leave it at the end of the file, where
456 * Emacs will automagically detect them.
457 * ---------------------------------------------------------------------
460 * indent-tabs-mode: t
464 * vim:noexpandtab:sw=4:ts=4: