Moved LAZYLOADING* to xta header.
[cacao.git] / src / vm / loader.h
1 /* src/vm/loader.h - class loader 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: Reinhard Grafl
28
29    $Id: loader.h 2154 2005-03-30 20:03:06Z twisti $
30 */
31
32
33 #ifndef _LOADER_H
34 #define _LOADER_H
35
36 #include <stdio.h>
37
38
39 /* forward typedefs ***********************************************************/
40
41 typedef struct classbuffer classbuffer;
42 typedef struct classpath_info classpath_info;
43
44
45 #include "config.h"
46 #include "types.h"
47 #include "vm/class.h"
48 #include "vm/descriptor.h"
49 #include "vm/global.h"
50 #include "vm/method.h"
51 #include "vm/utf8.h"
52
53 #if defined(USE_ZLIB)
54 # include "vm/unzip.h"
55 #endif
56
57
58 /* signed suck defines ********************************************************/
59
60 #define suck_s8(a)    (s8) suck_u8((a))
61 #define suck_s2(a)    (s2) suck_u2((a))
62 #define suck_s4(a)    (s4) suck_u4((a))
63 #define suck_s1(a)    (s1) suck_u1((a))
64
65
66 /* constant pool entries *******************************************************
67
68         All constant pool entries need a data structure which contain the entrys
69         value. In some cases this structure exist already, in the remaining cases
70         this structure must be generated:
71
72                 kind                      structure                     generated?
73         ----------------------------------------------------------------------
74     CONSTANT_Class               classinfo                           no   XXX this will change
75     CONSTANT_Fieldref            constant_FMIref                    yes
76     CONSTANT_Methodref           constant_FMIref                    yes
77     CONSTANT_InterfaceMethodref  constant_FMIref                    yes
78     CONSTANT_String              unicode                             no
79     CONSTANT_Integer             constant_integer                   yes
80     CONSTANT_Float               constant_float                     yes
81     CONSTANT_Long                constant_long                      yes
82     CONSTANT_Double              constant_double                    yes
83     CONSTANT_NameAndType         constant_nameandtype               yes
84     CONSTANT_Utf8                unicode                             no
85     CONSTANT_UNUSED              -
86
87 *******************************************************************************/
88
89 typedef struct {            /* Fieldref, Methodref and InterfaceMethodref     */
90         classinfo *class;       /* class containing this field/method/intfmeth.   */ /* XXX remove */
91         constant_classref *classref;  /* class containing this field/meth./intfm. */
92         utf       *name;        /* field/method/interfacemethod name              */
93         utf       *descriptor;  /* field/method/intfmeth. type descriptor string  */
94         parseddesc parseddesc;  /* parsed descriptor                              */
95 } constant_FMIref;
96
97
98 typedef struct {            /* Integer                                        */
99         s4 value;
100 } constant_integer;
101
102         
103 typedef struct {            /* Float                                          */
104         float value;
105 } constant_float;
106
107
108 typedef struct {            /* Long                                           */
109         s8 value;
110 } constant_long;
111         
112
113 typedef struct {            /* Double                                         */
114         double value;
115 } constant_double;
116
117
118 typedef struct {            /* NameAndType (Field or Method)                  */
119         utf *name;              /* field/method name                              */
120         utf *descriptor;        /* field/method type descriptor string            */
121 } constant_nameandtype;
122
123
124 /* classbuffer ****************************************************************/
125
126 struct classbuffer {
127         classinfo *class;                   /* pointer to classinfo structure     */
128         u1        *data;                    /* pointer to byte code               */
129         s4         size;                    /* size of the byte code              */
130         u1        *pos;                     /* current read position              */
131 };
132
133
134 /* classpath_info *************************************************************/
135
136 #define CLASSPATH_PATH       0
137 #define CLASSPATH_ARCHIVE    1
138
139 struct classpath_info {
140 #if defined(USE_THREADS)
141         /* Required for monitor locking on zip/jar files. */
142         java_objectheader  header;
143 #endif
144         s4                 type;
145         char              *path;
146         s4                 pathlen;
147 #if defined(USE_ZLIB)
148         unzFile            uf;
149 #endif
150         classpath_info    *next;
151 };
152
153
154 /* export variables ***********************************************************/
155
156 #if defined(USE_THREADS)
157 extern int blockInts;
158 #endif
159
160 extern classpath_info *classpath_entries;
161
162
163 /* function prototypes ********************************************************/
164
165 /* initialize loader, load important systemclasses */
166 bool loader_init(u1 *stackbottom);
167
168 void suck_init(char *cpath);
169 void create_all_classes(void);
170 void suck_stop(classbuffer *cb);
171
172 inline bool check_classbuffer_size(classbuffer *cb, s4 len);
173
174 inline u1 suck_u1(classbuffer *cb);
175 inline u2 suck_u2(classbuffer *cb);
176 inline u4 suck_u4(classbuffer *cb);
177
178 /* free resources */
179 void loader_close(void);
180
181 /* class loading functions */
182 classinfo *load_class_from_classloader(classinfo *c, java_objectheader *cl);
183 classinfo *load_class_bootstrap(classinfo *c);
184 classinfo *load_class_from_classbuffer(classbuffer *cb);
185
186
187 /* retrieve constantpool element */
188 voidptr class_getconstant(classinfo *class, u4 pos, u4 ctype);
189
190 /* determine type of a constantpool element */
191 u4 class_constanttype(classinfo *class, u4 pos);
192
193 /* search class for a field */
194 fieldinfo *class_findfield(classinfo *c, utf *name, utf *desc);
195 fieldinfo *class_resolvefield(classinfo *c, utf *name, utf *desc, classinfo *referer, bool except);
196
197 /* search for a method with a specified name and descriptor */
198 methodinfo *class_findmethod(classinfo *c, utf *name, utf *desc);
199 methodinfo *class_fetchmethod(classinfo *c, utf *name, utf *desc);
200 methodinfo *class_resolvemethod(classinfo *c, utf *name, utf *dest);
201 methodinfo *class_resolveclassmethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool except);
202 methodinfo *class_resolveinterfacemethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool except);
203
204 /* search for a method with specified name and arguments (returntype ignored) */
205 methodinfo *class_findmethod_approx(classinfo *c, utf *name, utf *desc);
206 methodinfo *class_resolvemethod_approx(classinfo *c, utf *name, utf *dest);
207
208 bool class_issubclass(classinfo *sub, classinfo *super);
209
210 /* call initializer of class */
211 classinfo *class_init(classinfo *c);
212
213 /* debug purposes */
214 void class_showmethods(classinfo *c);
215 void class_showconstantpool(classinfo *c);
216 void print_arraydescriptor(FILE *file, arraydescriptor *desc);
217
218 /* return the primitive class inidicated by the given signature character */
219 classinfo *class_primitive_from_sig(char sig);
220
221
222 /* return the class indicated by the given descriptor */
223 /* (see loader.c for documentation) */
224 #define CLASSLOAD_NEW           0      /* default */
225 #define CLASSLOAD_LOAD          0x0001
226 #define CLASSLOAD_SKIP          0x0002
227 #define CLASSLOAD_PANIC         0      /* default */
228 #define CLASSLOAD_NOPANIC       0x0010
229 #define CLASSLOAD_PRIMITIVE     0      /* default */
230 #define CLASSLOAD_NULLPRIMITIVE 0x0020
231 #define CLASSLOAD_VOID          0      /* default */
232 #define CLASSLOAD_NOVOID        0x0040
233 #define CLASSLOAD_NOCHECKEND    0      /* default */
234 #define CLASSLOAD_CHECKEND      0x1000
235
236 classinfo *class_from_descriptor(char *utf_ptr,char *end_ptr,char **next,int mode);
237 int type_from_descriptor(classinfo **cls,char *utf_ptr,char *end_ptr,char **next,int mode);
238
239 /* (used by class_new, don't use directly) */
240 void class_new_array(classinfo *c);
241
242 #endif /* _LOADER_H */
243
244
245 /*
246  * These are local overrides for various environment variables in Emacs.
247  * Please do not remove this and leave it at the end of the file, where
248  * Emacs will automagically detect them.
249  * ---------------------------------------------------------------------
250  * Local variables:
251  * mode: c
252  * indent-tabs-mode: t
253  * c-basic-offset: 4
254  * tab-width: 4
255  * End:
256  */