37beb0d62f6e3d4676c77bf2da447073f5e2b660
[cacao.git] / src / vm / class.h
1 /* src/vm/class.h - class related functions header
2
3    Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4    R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5    C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6    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., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Christian Thalinger
28
29    Changes:
30
31    $Id: class.h 3259 2005-09-21 19:41:11Z 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 "toolbox/list.h"
49 #include "vm/global.h"
50 #include "vm/utf8.h"
51 #include "vm/references.h"
52 #include "vm/field.h"
53 #include "vm/linker.h"
54 #include "vm/tables.h"
55 #include "vm/jit/inline/sets.h"
56
57
58 /* classinfo ******************************************************************/
59
60 struct classinfo {                /* class structure                          */
61         java_objectheader header;     /* classes are also objects                 */
62         java_objectarray* signers;
63         struct java_security_ProtectionDomain* pd;
64         struct java_lang_VMClass* vmClass;
65         struct java_lang_reflect_Constructor* constructor;
66
67         s4 initializing_thread;       /* gnu classpath                            */
68         s4 erroneous_state;           /* gnu classpath                            */
69         struct gnu_classpath_RawData* vmData; /* gnu classpath                    */
70
71         s4          flags;            /* ACC flags                                */
72         utf        *name;             /* class name                               */
73
74         s4          cpcount;          /* number of entries in constant pool       */
75         u1         *cptags;           /* constant pool tags                       */
76         voidptr    *cpinfos;          /* pointer to constant pool info structures */
77
78         s4          classrefcount;    /* number of symbolic class references      */
79         constant_classref *classrefs; /* table of symbolic class references       */
80         extra_classref *extclassrefs; /* additional classrefs                     */
81         s4          parseddescsize;   /* size of the parsed descriptors block     */
82         u1         *parseddescs;      /* parsed descriptors                       */
83
84         classref_or_classinfo super;  /* super class                              */
85         classinfo  *sub;              /* sub class pointer                        */
86         classinfo  *nextsub;          /* pointer to next class in sub class list  */
87
88         s4          interfacescount;  /* number of interfaces                     */
89         classref_or_classinfo *interfaces; /* superinterfaces                     */
90
91         s4          fieldscount;      /* number of fields                         */
92         fieldinfo  *fields;           /* field table                              */
93
94         s4          methodscount;     /* number of methods                        */
95         methodinfo *methods;          /* method table                             */
96
97         listnode    listnode;         /* linkage                                  */
98
99         bool        initialized;      /* true, if class already initialized       */
100         bool        initializing;     /* flag for the compiler                    */
101         bool        loaded;           /* true, if class already loaded            */
102         bool        linked;           /* true, if class already linked            */
103         s4          index;            /* hierarchy depth (classes) or index       */
104                                       /* (interfaces)                             */
105         s4          instancesize;     /* size of an instance of this class        */
106
107         vftbl_t    *vftbl;            /* pointer to virtual function table        */
108
109         methodinfo *finalizer;        /* finalizer method                         */
110
111         u2          innerclasscount;  /* number of inner classes                  */
112         innerclassinfo *innerclass;
113
114         bool        classvftbl;       /* has its own copy of the Class vtbl       */
115
116         s4          classUsed;        /* 0= not used 1 = used   CO-RT             */
117
118         classSetNode *impldBy;        /* interface class implemented by class set */
119                                       /*   Object class 's impldBy is list of all */
120                                       /*   interface classes used (RT & XTA only  */
121                                       /*     normally no list of interfaces used) */
122         utf        *packagename;      /* full name of the package                 */
123         utf        *sourcefile;       /* classfile name containing this class     */
124         java_objectheader *classloader; /* NULL for bootstrap classloader         */
125 };
126
127
128 /* innerclassinfo *************************************************************/
129
130 struct innerclassinfo {
131         classref_or_classinfo inner_class; /* inner class pointer                 */
132         classref_or_classinfo outer_class; /* outer class pointer                 */
133         utf                  *name;        /* innerclass name                     */
134         s4                    flags;       /* ACC flags                           */
135 };
136
137
138 /* extra_classref **************************************************************
139
140    for classrefs not occurring within descriptors
141
142 *******************************************************************************/
143
144 struct extra_classref {
145         extra_classref    *next;
146         constant_classref  classref;
147 };
148
149
150 /* global variables ***********************************************************/
151
152 extern list unlinkedclasses;   /* this is only used for eager class loading   */
153
154
155 /* frequently used classes ****************************************************/
156
157 /* important system classes */
158
159 extern classinfo *class_java_lang_Object;
160 extern classinfo *class_java_lang_Class;
161 extern classinfo *class_java_lang_ClassLoader;
162 extern classinfo *class_java_lang_Cloneable;
163 extern classinfo *class_java_lang_SecurityManager;
164 extern classinfo *class_java_lang_String;
165 extern classinfo *class_java_lang_System;
166 extern classinfo *class_java_lang_ThreadGroup;
167 extern classinfo *class_java_io_Serializable;
168
169
170 /* system exception classes required in cacao */
171
172 extern classinfo *class_java_lang_Throwable;
173 extern classinfo *class_java_lang_VMThrowable;
174 extern classinfo *class_java_lang_Error;
175 extern classinfo *class_java_lang_NoClassDefFoundError;
176 extern classinfo *class_java_lang_OutOfMemoryError;
177
178 extern classinfo *class_java_lang_Exception;
179 extern classinfo *class_java_lang_ClassNotFoundException;
180
181
182 extern classinfo *class_java_lang_Void;
183 extern classinfo *class_java_lang_Boolean;
184 extern classinfo *class_java_lang_Byte;
185 extern classinfo *class_java_lang_Character;
186 extern classinfo *class_java_lang_Short;
187 extern classinfo *class_java_lang_Integer;
188 extern classinfo *class_java_lang_Long;
189 extern classinfo *class_java_lang_Float;
190 extern classinfo *class_java_lang_Double;
191
192
193 /* some classes which may be used more often */
194
195 extern classinfo *class_java_lang_StackTraceElement;
196 extern classinfo *class_java_lang_reflect_Constructor;
197 extern classinfo *class_java_lang_reflect_Field;
198 extern classinfo *class_java_lang_reflect_Method;
199 extern classinfo *class_java_security_PrivilegedAction;
200 extern classinfo *class_java_util_Vector;
201
202 extern classinfo *arrayclass_java_lang_Object;
203
204
205 /* pseudo classes for the type checker ****************************************/
206
207 /*
208  * pseudo_class_Arraystub
209  *     (extends Object implements Cloneable, java.io.Serializable)
210  *
211  *     If two arrays of incompatible component types are merged,
212  *     the resulting reference has no accessible components.
213  *     The result does, however, implement the interfaces Cloneable
214  *     and java.io.Serializable. This pseudo class is used internally
215  *     to represent such results. (They are *not* considered arrays!)
216  *
217  * pseudo_class_Null
218  *
219  *     This pseudo class is used internally to represent the
220  *     null type.
221  *
222  * pseudo_class_New
223  *
224  *     This pseudo class is used internally to represent the
225  *     the 'uninitialized object' type.
226  */
227
228 extern classinfo *pseudo_class_Arraystub;
229 extern classinfo *pseudo_class_Null;
230 extern classinfo *pseudo_class_New;
231
232
233 /* function prototypes ********************************************************/
234
235 /* create a new classinfo struct */
236 classinfo *class_create_classinfo(utf *u);
237
238 /* set the package name after the name has been set */
239 void class_set_packagename(classinfo *c);
240
241 /* retrieve constantpool element */
242 voidptr class_getconstant(classinfo *class, u4 pos, u4 ctype);
243 voidptr innerclass_getconstant(classinfo *c, u4 pos, u4 ctype);
244
245 /* frees all resources used by the class */
246 void class_free(classinfo *);
247
248 /* return an array class with the given component class */
249 classinfo *class_array_of(classinfo *component,bool link);
250
251 /* return an array class with the given dimension and element class */
252 classinfo *class_multiarray_of(s4 dim, classinfo *element,bool link);
253
254 /* return a classref for the given class name */
255 /* (does a linear search!)                    */
256 constant_classref *class_lookup_classref(classinfo *cls,utf *name);
257
258 /* return a classref for the given class name */
259 /* (does a linear search!)                    */
260 constant_classref *class_get_classref(classinfo *cls,utf *name);
261
262 /* return a classref to the class itself */
263 /* (does a linear search!)                    */
264 constant_classref *class_get_self_classref(classinfo *cls);
265
266 /* return a classref for an array with the given dimension of with the */
267 /* given component type */
268 constant_classref *class_get_classref_multiarray_of(s4 dim,constant_classref *ref);
269
270 /* return a classref for the component type of the given array type */
271 constant_classref *class_get_classref_component_of(constant_classref *ref);
272
273 #endif /* _CLASS_H */
274
275
276 /*
277  * These are local overrides for various environment variables in Emacs.
278  * Please do not remove this and leave it at the end of the file, where
279  * Emacs will automagically detect them.
280  * ---------------------------------------------------------------------
281  * Local variables:
282  * mode: c
283  * indent-tabs-mode: t
284  * c-basic-offset: 4
285  * tab-width: 4
286  * End:
287  */