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