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
31 /* forward typedefs ***********************************************************/
33 typedef struct classinfo classinfo;
34 typedef struct innerclassinfo innerclassinfo;
35 typedef struct extra_classref extra_classref;
36 typedef struct castinfo castinfo;
45 #include "toolbox/list.h"
47 #include "vm/global.h"
49 #if defined(ENABLE_JAVASE)
50 # include "vmcore/annotation.h"
53 #include "vmcore/field.h"
54 #include "vmcore/linker.h"
55 #include "vmcore/loader.h"
56 #include "vmcore/method.h"
57 #include "vmcore/references.h"
58 #include "vmcore/utf8.h"
61 /* class state defines ********************************************************/
63 #define CLASS_LOADING 0x0001
64 #define CLASS_LOADED 0x0002
65 #define CLASS_LINKING 0x0004
66 #define CLASS_LINKED 0x0008
67 #define CLASS_INITIALIZING 0x0010
68 #define CLASS_INITIALIZED 0x0020
69 #define CLASS_ERROR 0x0040
72 /* some macros ****************************************************************/
74 #define CLASS_IS_OR_ALMOST_INITIALIZED(c) \
75 (((c)->state & CLASS_INITIALIZING) || ((c)->state & CLASS_INITIALIZED))
78 /* classinfo ******************************************************************/
80 /* We define this dummy structure of java_lang_Class so we can
81 bootstrap cacaoh without needing a java_lang_Class.h file. Whether
82 the size of the dummy structure is big enough is checked during
83 runtime in vm_create. */
87 #if defined(WITH_CLASSPATH_GNU)
89 #elif defined(WITH_CLASSPATH_SUN)
91 #elif defined(WITH_CLASSPATH_CLDC1_1)
94 # error unknown classpath configuration
96 } dummy_java_lang_Class;
98 struct classinfo { /* class structure */
99 dummy_java_lang_Class object;
101 s4 flags; /* ACC flags */
102 utf *name; /* class name */
104 s4 cpcount; /* number of entries in constant pool */
105 u1 *cptags; /* constant pool tags */
106 voidptr *cpinfos; /* pointer to constant pool info structures */
108 s4 classrefcount; /* number of symbolic class references */
109 constant_classref *classrefs; /* table of symbolic class references */
110 extra_classref *extclassrefs; /* additional classrefs */
111 s4 parseddescsize; /* size of the parsed descriptors block */
112 u1 *parseddescs; /* parsed descriptors */
114 classinfo *super; /* super class */
115 classinfo *sub; /* sub class pointer */
116 classinfo *nextsub; /* pointer to next class in sub class list */
118 int32_t interfacescount; /* number of interfaces */
119 classinfo **interfaces; /* super interfaces */
121 int32_t fieldscount; /* number of fields */
122 fieldinfo *fields; /* field table */
124 int32_t methodscount; /* number of methods */
125 methodinfo *methods; /* method table */
127 s4 state; /* current class state */
128 s4 index; /* hierarchy depth (classes) or index */
130 s4 instancesize; /* size of an instance of this class */
132 vftbl_t *vftbl; /* pointer to virtual function table */
134 methodinfo *finalizer; /* finalizer method */
136 u2 innerclasscount; /* number of inner classes */
137 innerclassinfo *innerclass;
139 classref_or_classinfo declaringclass;
140 classref_or_classinfo enclosingclass; /* enclosing class */
141 constant_nameandtype *enclosingmethod; /* enclosing method */
143 utf *packagename; /* full name of the package */
144 utf *sourcefile; /* SourceFile attribute */
145 #if defined(ENABLE_JAVASE)
146 utf *signature; /* Signature attribute */
147 #if defined(ENABLE_ANNOTATIONS)
148 /* All the annotation attributes are NULL (and not a zero length array) */
149 /* if there is nothing. */
150 java_object_t *annotations; /* annotations of this class */
152 java_object_t *method_annotations; /* array of annotations of the methods */
153 java_object_t *method_parameterannotations; /* array of parameter */
154 /* annotations of the methods */
155 java_object_t *method_annotationdefaults; /* array of annotation default */
156 /* values of the methods */
158 java_object_t *field_annotations; /* array of annotations of the fields */
162 classloader *classloader; /* NULL for bootstrap classloader */
164 #if defined(ENABLE_JAVASE)
165 # if defined(WITH_CLASSPATH_SUN)
166 java_object_t *protectiondomain;
172 /* innerclassinfo *************************************************************/
174 struct innerclassinfo {
175 classref_or_classinfo inner_class; /* inner class pointer */
176 classref_or_classinfo outer_class; /* outer class pointer */
177 utf *name; /* innerclass name */
178 s4 flags; /* ACC flags */
182 /* extra_classref **************************************************************
184 for classrefs not occurring within descriptors
186 *******************************************************************************/
188 struct extra_classref {
189 extra_classref *next;
190 constant_classref classref;
194 /* castinfo *******************************************************************/
203 /* global variables ***********************************************************/
205 /* frequently used classes ****************************************************/
207 /* important system classes */
209 extern classinfo *class_java_lang_Object;
210 extern classinfo *class_java_lang_Class;
211 extern classinfo *class_java_lang_ClassLoader;
212 extern classinfo *class_java_lang_Cloneable;
213 extern classinfo *class_java_lang_SecurityManager;
214 extern classinfo *class_java_lang_String;
215 extern classinfo *class_java_lang_System;
216 extern classinfo *class_java_lang_Thread;
217 extern classinfo *class_java_lang_ThreadGroup;
218 extern classinfo *class_java_lang_VMSystem;
219 extern classinfo *class_java_lang_VMThread;
220 extern classinfo *class_java_io_Serializable;
222 #if defined(WITH_CLASSPATH_SUN)
223 extern classinfo *class_sun_reflect_MagicAccessorImpl;
226 /* system exception classes required in cacao */
228 extern classinfo *class_java_lang_Throwable;
229 extern classinfo *class_java_lang_Error;
230 extern classinfo *class_java_lang_LinkageError;
231 extern classinfo *class_java_lang_NoClassDefFoundError;
232 extern classinfo *class_java_lang_OutOfMemoryError;
233 extern classinfo *class_java_lang_VirtualMachineError;
235 #if defined(WITH_CLASSPATH_GNU)
236 extern classinfo *class_java_lang_VMThrowable;
239 extern classinfo *class_java_lang_Exception;
240 extern classinfo *class_java_lang_ClassCastException;
241 extern classinfo *class_java_lang_ClassNotFoundException;
243 #if defined(ENABLE_JAVASE)
244 extern classinfo *class_java_lang_Void;
246 #if defined(ENABLE_ANNOTATIONS)
247 extern classinfo *class_sun_reflect_ConstantPool;
248 #if defined(WITH_CLASSPATH_GNU)
249 extern classinfo *class_sun_reflect_annotation_AnnotationParser;
254 extern classinfo *class_java_lang_Boolean;
255 extern classinfo *class_java_lang_Byte;
256 extern classinfo *class_java_lang_Character;
257 extern classinfo *class_java_lang_Short;
258 extern classinfo *class_java_lang_Integer;
259 extern classinfo *class_java_lang_Long;
260 extern classinfo *class_java_lang_Float;
261 extern classinfo *class_java_lang_Double;
264 /* some runtime exception */
266 extern classinfo *class_java_lang_NullPointerException;
269 /* some classes which may be used more often */
271 #if defined(ENABLE_JAVASE)
272 extern classinfo *class_java_lang_StackTraceElement;
273 extern classinfo *class_java_lang_reflect_Constructor;
274 extern classinfo *class_java_lang_reflect_Field;
275 extern classinfo *class_java_lang_reflect_Method;
276 extern classinfo *class_java_security_PrivilegedAction;
277 extern classinfo *class_java_util_Vector;
279 extern classinfo *arrayclass_java_lang_Object;
283 /* pseudo classes for the type checker ****************************************/
286 * pseudo_class_Arraystub
287 * (extends Object implements Cloneable, java.io.Serializable)
289 * If two arrays of incompatible component types are merged,
290 * the resulting reference has no accessible components.
291 * The result does, however, implement the interfaces Cloneable
292 * and java.io.Serializable. This pseudo class is used internally
293 * to represent such results. (They are *not* considered arrays!)
297 * This pseudo class is used internally to represent the
302 * This pseudo class is used internally to represent the
303 * the 'uninitialized object' type.
306 extern classinfo *pseudo_class_Arraystub;
307 extern classinfo *pseudo_class_Null;
308 extern classinfo *pseudo_class_New;
311 /* function prototypes ********************************************************/
313 classinfo *class_create_classinfo(utf *u);
314 void class_postset_header_vftbl(void);
315 classinfo *class_define(utf *name, classloader *cl, int32_t length, const uint8_t *data, java_handle_t *pd);
316 void class_set_packagename(classinfo *c);
318 bool class_load_attributes(classbuffer *cb);
320 /* retrieve constantpool element */
321 voidptr class_getconstant(classinfo *class, u4 pos, u4 ctype);
322 voidptr innerclass_getconstant(classinfo *c, u4 pos, u4 ctype);
324 /* frees all resources used by the class */
325 void class_free(classinfo *);
327 /* return an array class with the given component class */
328 classinfo *class_array_of(classinfo *component,bool link);
330 /* return an array class with the given dimension and element class */
331 classinfo *class_multiarray_of(s4 dim, classinfo *element,bool link);
333 /* return a classref for the given class name */
334 /* (does a linear search!) */
335 constant_classref *class_lookup_classref(classinfo *cls,utf *name);
337 /* return a classref for the given class name */
338 /* (does a linear search!) */
339 constant_classref *class_get_classref(classinfo *cls,utf *name);
341 /* return a classref to the class itself */
342 /* (does a linear search!) */
343 constant_classref *class_get_self_classref(classinfo *cls);
345 /* return a classref for an array with the given dimension of with the */
346 /* given component type */
347 constant_classref *class_get_classref_multiarray_of(s4 dim,constant_classref *ref);
349 /* return a classref for the component type of the given array type */
350 constant_classref *class_get_classref_component_of(constant_classref *ref);
352 /* get a class' field by name and descriptor */
353 fieldinfo *class_findfield(classinfo *c, utf *name, utf *desc);
355 /* search 'classinfo'-structure for a field with the specified name */
356 fieldinfo *class_findfield_by_name(classinfo *c, utf *name);
357 s4 class_findfield_index_by_name(classinfo *c, utf *name);
359 /* search class for a field */
360 fieldinfo *class_resolvefield(classinfo *c, utf *name, utf *desc, classinfo *referer, bool throwexception);
362 /* search for a method with a specified name and descriptor */
363 methodinfo *class_findmethod(classinfo *c, utf *name, utf *desc);
364 methodinfo *class_resolvemethod(classinfo *c, utf *name, utf *dest);
365 methodinfo *class_resolveclassmethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool throwexception);
366 methodinfo *class_resolveinterfacemethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool throwexception);
368 bool class_issubclass(classinfo *sub, classinfo *super);
369 bool class_isanysubclass(classinfo *sub, classinfo *super);
371 bool class_is_primitive(classinfo *c);
372 bool class_is_anonymousclass(classinfo *c);
373 bool class_is_array(classinfo *c);
374 bool class_is_interface(classinfo *c);
375 bool class_is_localclass(classinfo *c);
376 bool class_is_memberclass(classinfo *c);
378 classloader *class_get_classloader(classinfo *c);
379 classinfo *class_get_superclass(classinfo *c);
380 classinfo *class_get_componenttype(classinfo *c);
381 java_handle_objectarray_t *class_get_declaredclasses(classinfo *c, bool publicOnly);
382 classinfo *class_get_declaringclass(classinfo *c);
383 classinfo *class_get_enclosingclass(classinfo *c);
384 java_handle_objectarray_t *class_get_interfaces(classinfo *c);
385 java_handle_bytearray_t *class_get_annotations(classinfo *c);
387 #if defined(ENABLE_JAVASE)
388 utf *class_get_signature(classinfo *c);
391 /* some debugging functions */
394 void class_printflags(classinfo *c);
395 void class_print(classinfo *c);
396 void class_println(classinfo *c);
397 void class_classref_print(constant_classref *cr);
398 void class_classref_println(constant_classref *cr);
399 void class_classref_or_classinfo_print(classref_or_classinfo c);
400 void class_classref_or_classinfo_println(classref_or_classinfo c);
404 void class_showmethods(classinfo *c);
405 void class_showconstantpool(classinfo *c);
407 #endif /* _CLASS_H */
411 * These are local overrides for various environment variables in Emacs.
412 * Please do not remove this and leave it at the end of the file, where
413 * Emacs will automagically detect them.
414 * ---------------------------------------------------------------------
417 * indent-tabs-mode: t