* src/vm/jit/x86_64/md.c (md_signal_handler_sigusr2): Fixed comment.
[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 5088 2006-07-08 20:16:05Z 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_ClassCastException;
184 extern classinfo *class_java_lang_ClassNotFoundException;
185 extern classinfo *class_java_lang_IllegalArgumentException;
186 extern classinfo *class_java_lang_IllegalMonitorStateException;
187
188
189 extern classinfo *class_java_lang_Void;
190 extern classinfo *class_java_lang_Boolean;
191 extern classinfo *class_java_lang_Byte;
192 extern classinfo *class_java_lang_Character;
193 extern classinfo *class_java_lang_Short;
194 extern classinfo *class_java_lang_Integer;
195 extern classinfo *class_java_lang_Long;
196 extern classinfo *class_java_lang_Float;
197 extern classinfo *class_java_lang_Double;
198
199
200 /* some runtime exception */
201
202 extern classinfo *class_java_lang_NullPointerException;
203
204
205 /* some classes which may be used more often */
206
207 extern classinfo *class_java_lang_StackTraceElement;
208 extern classinfo *class_java_lang_reflect_Constructor;
209 extern classinfo *class_java_lang_reflect_Field;
210 extern classinfo *class_java_lang_reflect_Method;
211 extern classinfo *class_java_security_PrivilegedAction;
212 extern classinfo *class_java_util_Vector;
213
214 extern classinfo *arrayclass_java_lang_Object;
215
216
217 /* pseudo classes for the type checker ****************************************/
218
219 /*
220  * pseudo_class_Arraystub
221  *     (extends Object implements Cloneable, java.io.Serializable)
222  *
223  *     If two arrays of incompatible component types are merged,
224  *     the resulting reference has no accessible components.
225  *     The result does, however, implement the interfaces Cloneable
226  *     and java.io.Serializable. This pseudo class is used internally
227  *     to represent such results. (They are *not* considered arrays!)
228  *
229  * pseudo_class_Null
230  *
231  *     This pseudo class is used internally to represent the
232  *     null type.
233  *
234  * pseudo_class_New
235  *
236  *     This pseudo class is used internally to represent the
237  *     the 'uninitialized object' type.
238  */
239
240 extern classinfo *pseudo_class_Arraystub;
241 extern classinfo *pseudo_class_Null;
242 extern classinfo *pseudo_class_New;
243
244
245 /* function prototypes ********************************************************/
246
247 /* create a new classinfo struct */
248 classinfo *class_create_classinfo(utf *u);
249
250 /* postset's the header.vftbl */
251 void class_postset_header_vftbl(void);
252
253 /* set the package name after the name has been set */
254 void class_set_packagename(classinfo *c);
255
256 /* retrieve constantpool element */
257 voidptr class_getconstant(classinfo *class, u4 pos, u4 ctype);
258 voidptr innerclass_getconstant(classinfo *c, u4 pos, u4 ctype);
259
260 /* frees all resources used by the class */
261 void class_free(classinfo *);
262
263 /* return an array class with the given component class */
264 classinfo *class_array_of(classinfo *component,bool link);
265
266 /* return an array class with the given dimension and element class */
267 classinfo *class_multiarray_of(s4 dim, classinfo *element,bool link);
268
269 /* return a classref for the given class name */
270 /* (does a linear search!)                    */
271 constant_classref *class_lookup_classref(classinfo *cls,utf *name);
272
273 /* return a classref for the given class name */
274 /* (does a linear search!)                    */
275 constant_classref *class_get_classref(classinfo *cls,utf *name);
276
277 /* return a classref to the class itself */
278 /* (does a linear search!)                    */
279 constant_classref *class_get_self_classref(classinfo *cls);
280
281 /* return a classref for an array with the given dimension of with the */
282 /* given component type */
283 constant_classref *class_get_classref_multiarray_of(s4 dim,constant_classref *ref);
284
285 /* return a classref for the component type of the given array type */
286 constant_classref *class_get_classref_component_of(constant_classref *ref);
287
288 /* get a class' field by name and descriptor */
289 fieldinfo *class_findfield(classinfo *c, utf *name, utf *desc);
290
291 /* search 'classinfo'-structure for a field with the specified name */
292 fieldinfo *class_findfield_by_name(classinfo *c, utf *name);
293 s4 class_findfield_index_by_name(classinfo *c, utf *name);
294
295 /* search class for a field */
296 fieldinfo *class_resolvefield(classinfo *c, utf *name, utf *desc, classinfo *referer, bool throwexception);
297
298 /* search for a method with a specified name and descriptor */
299 methodinfo *class_findmethod(classinfo *c, utf *name, utf *desc);
300 methodinfo *class_resolvemethod(classinfo *c, utf *name, utf *dest);
301 methodinfo *class_resolveclassmethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool throwexception);
302 methodinfo *class_resolveinterfacemethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool throwexception);
303
304 bool class_issubclass(classinfo *sub, classinfo *super);
305
306 /* some debugging functions */
307
308 #if !defined(NDEBUG)
309 void class_printflags(classinfo *c);
310 void class_print(classinfo *c);
311 void class_println(classinfo *c);
312 void class_classref_print(constant_classref *cr);
313 void class_classref_println(constant_classref *cr);
314 #endif
315
316 /* debug purposes */
317 void class_showmethods(classinfo *c);
318 void class_showconstantpool(classinfo *c);
319
320 #endif /* _CLASS_H */
321
322
323 /*
324  * These are local overrides for various environment variables in Emacs.
325  * Please do not remove this and leave it at the end of the file, where
326  * Emacs will automagically detect them.
327  * ---------------------------------------------------------------------
328  * Local variables:
329  * mode: c
330  * indent-tabs-mode: t
331  * c-basic-offset: 4
332  * tab-width: 4
333  * End:
334  */