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