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