* src/vm/class.h [ENABLE_JAVASE] (vm/annotation.h): Added.
[cacao.git] / src / vm / class.h
1 /* src/vm/class.h - class related functions header
2
3    Copyright (C) 1996-2005, 2006 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
7
8    This file is part of CACAO.
9
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.
14
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.
19
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
23    02110-1301, USA.
24
25    Contact: cacao@cacaojvm.org
26
27    Authors: Christian Thalinger
28
29    $Id: class.h 6085 2006-11-29 17:08:27Z twisti $
30
31 */
32
33
34 #ifndef _CLASS_H
35 #define _CLASS_H
36
37 /* forward typedefs ***********************************************************/
38
39 typedef struct classinfo      classinfo; 
40 typedef struct innerclassinfo innerclassinfo;
41 typedef struct extra_classref extra_classref;
42
43
44 #include "config.h"
45 #include "vm/types.h"
46
47 #include "vm/global.h"                  /* define java_objectheader for j.l.C */
48 #include "native/include/java_lang_Class.h"
49
50 #include "toolbox/list.h"
51
52 #if defined(ENABLE_JAVASE)
53 # include "vm/annotation.h"
54 #endif
55
56 #include "vm/field.h"
57 #include "vm/linker.h"
58 #include "vm/method.h"
59 #include "vm/references.h"
60 #include "vm/utf8.h"
61
62
63 /* class state defines ********************************************************/
64
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
72
73
74 /* some macros ****************************************************************/
75
76 #define CLASS_IS_OR_ALMOST_INITIALIZED(c) \
77     (((c)->state & CLASS_INITIALIZING) || ((c)->state & CLASS_INITIALIZED))
78
79
80 /* classinfo ******************************************************************/
81
82 struct classinfo {                /* class structure                          */
83         java_lang_Class object;       /* classinfos are also j.l.C objects        */
84
85         s4          flags;            /* ACC flags                                */
86         utf        *name;             /* class name                               */
87
88         s4          cpcount;          /* number of entries in constant pool       */
89         u1         *cptags;           /* constant pool tags                       */
90         voidptr    *cpinfos;          /* pointer to constant pool info structures */
91
92         s4          classrefcount;    /* number of symbolic class references      */
93         constant_classref *classrefs; /* table of symbolic class references       */
94         extra_classref *extclassrefs; /* additional classrefs                     */
95         s4          parseddescsize;   /* size of the parsed descriptors block     */
96         u1         *parseddescs;      /* parsed descriptors                       */
97
98         classref_or_classinfo super;  /* super class                              */
99         classinfo  *sub;              /* sub class pointer                        */
100         classinfo  *nextsub;          /* pointer to next class in sub class list  */
101
102         s4          interfacescount;  /* number of interfaces                     */
103         classref_or_classinfo *interfaces; /* superinterfaces                     */
104
105         s4          fieldscount;      /* number of fields                         */
106         fieldinfo  *fields;           /* field table                              */
107
108         s4          methodscount;     /* number of methods                        */
109         methodinfo *methods;          /* method table                             */
110
111         listnode    listnode;         /* linkage                                  */
112
113         s4          state;            /* current class state                      */
114         s4          index;            /* hierarchy depth (classes) or index       */
115                                       /* (interfaces)                             */
116         s4          instancesize;     /* size of an instance of this class        */
117
118         vftbl_t    *vftbl;            /* pointer to virtual function table        */
119
120         methodinfo *finalizer;        /* finalizer method                         */
121
122         u2          innerclasscount;  /* number of inner classes                  */
123         innerclassinfo *innerclass;
124
125         utf        *packagename;      /* full name of the package                 */
126         utf        *sourcefile;       /* SourceFile attribute                     */
127 #if defined(ENABLE_JAVASE)
128         utf        *signature;        /* Signature attribute                      */
129         s4            runtimevisibleannotationscount;
130         annotation_t *runtimevisibleannotations;
131 #endif
132         java_objectheader *classloader; /* NULL for bootstrap classloader         */
133 };
134
135
136 /* innerclassinfo *************************************************************/
137
138 struct innerclassinfo {
139         classref_or_classinfo inner_class; /* inner class pointer                 */
140         classref_or_classinfo outer_class; /* outer class pointer                 */
141         utf                  *name;        /* innerclass name                     */
142         s4                    flags;       /* ACC flags                           */
143 };
144
145
146 /* extra_classref **************************************************************
147
148    for classrefs not occurring within descriptors
149
150 *******************************************************************************/
151
152 struct extra_classref {
153         extra_classref    *next;
154         constant_classref  classref;
155 };
156
157
158 /* global variables ***********************************************************/
159
160 extern list unlinkedclasses;   /* this is only used for eager class loading   */
161
162
163 /* frequently used classes ****************************************************/
164
165 /* important system classes */
166
167 extern classinfo *class_java_lang_Object;
168 extern classinfo *class_java_lang_Class;
169 extern classinfo *class_java_lang_ClassLoader;
170 extern classinfo *class_java_lang_Cloneable;
171 extern classinfo *class_java_lang_SecurityManager;
172 extern classinfo *class_java_lang_String;
173 extern classinfo *class_java_lang_System;
174 extern classinfo *class_java_lang_Thread;
175 extern classinfo *class_java_lang_ThreadGroup;
176 extern classinfo *class_java_lang_VMSystem;
177 extern classinfo *class_java_lang_VMThread;
178 extern classinfo *class_java_io_Serializable;
179
180
181 /* system exception classes required in cacao */
182
183 extern classinfo *class_java_lang_Throwable;
184 extern classinfo *class_java_lang_VMThrowable;
185 extern classinfo *class_java_lang_Error;
186 extern classinfo *class_java_lang_AbstractMethodError;
187 extern classinfo *class_java_lang_LinkageError;
188 extern classinfo *class_java_lang_NoClassDefFoundError;
189 extern classinfo *class_java_lang_NoSuchMethodError;
190 extern classinfo *class_java_lang_OutOfMemoryError;
191
192 extern classinfo *class_java_lang_Exception;
193 extern classinfo *class_java_lang_ClassCastException;
194 extern classinfo *class_java_lang_ClassNotFoundException;
195 extern classinfo *class_java_lang_IllegalArgumentException;
196 extern classinfo *class_java_lang_IllegalMonitorStateException;
197
198
199 extern classinfo *class_java_lang_Void;
200 extern classinfo *class_java_lang_Boolean;
201 extern classinfo *class_java_lang_Byte;
202 extern classinfo *class_java_lang_Character;
203 extern classinfo *class_java_lang_Short;
204 extern classinfo *class_java_lang_Integer;
205 extern classinfo *class_java_lang_Long;
206 extern classinfo *class_java_lang_Float;
207 extern classinfo *class_java_lang_Double;
208
209
210 /* some runtime exception */
211
212 extern classinfo *class_java_lang_NullPointerException;
213
214
215 /* some classes which may be used more often */
216
217 extern classinfo *class_java_lang_StackTraceElement;
218 extern classinfo *class_java_lang_reflect_Constructor;
219 extern classinfo *class_java_lang_reflect_Field;
220 extern classinfo *class_java_lang_reflect_Method;
221 extern classinfo *class_java_security_PrivilegedAction;
222 extern classinfo *class_java_util_Vector;
223
224 extern classinfo *arrayclass_java_lang_Object;
225
226
227 /* pseudo classes for the type checker ****************************************/
228
229 /*
230  * pseudo_class_Arraystub
231  *     (extends Object implements Cloneable, java.io.Serializable)
232  *
233  *     If two arrays of incompatible component types are merged,
234  *     the resulting reference has no accessible components.
235  *     The result does, however, implement the interfaces Cloneable
236  *     and java.io.Serializable. This pseudo class is used internally
237  *     to represent such results. (They are *not* considered arrays!)
238  *
239  * pseudo_class_Null
240  *
241  *     This pseudo class is used internally to represent the
242  *     null type.
243  *
244  * pseudo_class_New
245  *
246  *     This pseudo class is used internally to represent the
247  *     the 'uninitialized object' type.
248  */
249
250 extern classinfo *pseudo_class_Arraystub;
251 extern classinfo *pseudo_class_Null;
252 extern classinfo *pseudo_class_New;
253
254
255 /* function prototypes ********************************************************/
256
257 /* create a new classinfo struct */
258 classinfo *class_create_classinfo(utf *u);
259
260 /* postset's the header.vftbl */
261 void class_postset_header_vftbl(void);
262
263 /* set the package name after the name has been set */
264 void class_set_packagename(classinfo *c);
265
266 /* retrieve constantpool element */
267 voidptr class_getconstant(classinfo *class, u4 pos, u4 ctype);
268 voidptr innerclass_getconstant(classinfo *c, u4 pos, u4 ctype);
269
270 /* frees all resources used by the class */
271 void class_free(classinfo *);
272
273 /* return an array class with the given component class */
274 classinfo *class_array_of(classinfo *component,bool link);
275
276 /* return an array class with the given dimension and element class */
277 classinfo *class_multiarray_of(s4 dim, classinfo *element,bool link);
278
279 /* return a classref for the given class name */
280 /* (does a linear search!)                    */
281 constant_classref *class_lookup_classref(classinfo *cls,utf *name);
282
283 /* return a classref for the given class name */
284 /* (does a linear search!)                    */
285 constant_classref *class_get_classref(classinfo *cls,utf *name);
286
287 /* return a classref to the class itself */
288 /* (does a linear search!)                    */
289 constant_classref *class_get_self_classref(classinfo *cls);
290
291 /* return a classref for an array with the given dimension of with the */
292 /* given component type */
293 constant_classref *class_get_classref_multiarray_of(s4 dim,constant_classref *ref);
294
295 /* return a classref for the component type of the given array type */
296 constant_classref *class_get_classref_component_of(constant_classref *ref);
297
298 /* get a class' field by name and descriptor */
299 fieldinfo *class_findfield(classinfo *c, utf *name, utf *desc);
300
301 /* search 'classinfo'-structure for a field with the specified name */
302 fieldinfo *class_findfield_by_name(classinfo *c, utf *name);
303 s4 class_findfield_index_by_name(classinfo *c, utf *name);
304
305 /* search class for a field */
306 fieldinfo *class_resolvefield(classinfo *c, utf *name, utf *desc, classinfo *referer, bool throwexception);
307
308 /* search for a method with a specified name and descriptor */
309 methodinfo *class_findmethod(classinfo *c, utf *name, utf *desc);
310 methodinfo *class_resolvemethod(classinfo *c, utf *name, utf *dest);
311 methodinfo *class_resolveclassmethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool throwexception);
312 methodinfo *class_resolveinterfacemethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool throwexception);
313
314 bool class_issubclass(classinfo *sub, classinfo *super);
315
316 /* some debugging functions */
317
318 #if !defined(NDEBUG)
319 void class_printflags(classinfo *c);
320 void class_print(classinfo *c);
321 void class_println(classinfo *c);
322 void class_classref_print(constant_classref *cr);
323 void class_classref_println(constant_classref *cr);
324 void class_classref_or_classinfo_print(classref_or_classinfo c);
325 void class_classref_or_classinfo_println(classref_or_classinfo c);
326 #endif
327
328 /* debug purposes */
329 void class_showmethods(classinfo *c);
330 void class_showconstantpool(classinfo *c);
331
332 #endif /* _CLASS_H */
333
334
335 /*
336  * These are local overrides for various environment variables in Emacs.
337  * Please do not remove this and leave it at the end of the file, where
338  * Emacs will automagically detect them.
339  * ---------------------------------------------------------------------
340  * Local variables:
341  * mode: c
342  * indent-tabs-mode: t
343  * c-basic-offset: 4
344  * tab-width: 4
345  * End:
346  */