10467083b6e596e2347697ef5de632db6897c4de
[cacao.git] / src / vm / loader.h
1 /* 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 1967 2005-02-25 15:51:05Z carolyn $
30 */
31
32
33 #ifndef _LOADER_H
34 #define _LOADER_H
35
36 #include <stdio.h>
37
38 #if defined(USE_ZLIB)
39 # include "vm/unzip.h"
40 #endif
41
42
43 /* datastruture from a classfile */
44
45 typedef struct classbuffer {
46         classinfo *class;                   /* pointer to classinfo structure     */
47         u1        *data;                    /* pointer to byte code               */
48         s4         size;                    /* size of the byte code              */
49         u1         *pos;                    /* current read position              */
50 } classbuffer;
51
52
53
54 /* classpath_info *************************************************************/
55
56 #define CLASSPATH_PATH       0
57 #define CLASSPATH_ARCHIVE    1
58
59 typedef struct classpath_info classpath_info;
60
61 struct classpath_info {
62 #if defined(USE_THREADS)
63         /* Required for monitor locking on zip/jar files. */
64         java_objectheader  header;
65 #endif
66         s4                 type;
67         char              *path;
68         s4                 pathlen;
69         struct java_security_ProtectionDomain *pd;
70 #if defined(USE_ZLIB)
71         unzFile            uf;
72 #endif  
73         classpath_info    *next;
74 };
75
76
77 /* export variables */
78
79 #if defined(USE_THREADS)
80 extern int blockInts;
81 #endif
82
83
84 /* pseudo classes for the type checker ****************************************/
85
86 /*
87  * pseudo_class_Arraystub
88  *     (extends Object implements Cloneable, java.io.Serializable)
89  *
90  *     If two arrays of incompatible component types are merged,
91  *     the resulting reference has no accessible components.
92  *     The result does, however, implement the interfaces Cloneable
93  *     and java.io.Serializable. This pseudo class is used internally
94  *     to represent such results. (They are *not* considered arrays!)
95  *
96  * pseudo_class_Null
97  *
98  *     This pseudo class is used internally to represent the
99  *     null type.
100  *
101  * pseudo_class_New
102  *
103  *     This pseudo class is used internally to represent the
104  *     the 'uninitialized object' type.
105  */
106
107 extern classinfo *pseudo_class_Arraystub;
108 extern classinfo *pseudo_class_Null;
109 extern classinfo *pseudo_class_New;
110 extern vftbl_t *pseudo_class_Arraystub_vftbl;
111
112 extern utf *array_packagename;
113
114
115 /************************ prototypes ******************************************/
116
117 /* initialize loader, load important systemclasses */
118 bool loader_init(u1 *stackbottom);
119
120 void suck_init(char *cpath);
121 void create_all_classes(void);
122 void suck_stop(classbuffer *cb);
123
124 /* free resources */
125 void loader_close(void);
126
127 void loader_compute_subclasses(classinfo *c);
128
129 /* retrieve constantpool element */
130 voidptr class_getconstant(classinfo *class, u4 pos, u4 ctype);
131
132 /* determine type of a constantpool element */
133 u4 class_constanttype(classinfo *class, u4 pos);
134
135 s4 class_findmethodIndex(classinfo *c, utf *name, utf *desc);
136
137 /* search class for a field */
138 fieldinfo *class_findfield(classinfo *c, utf *name, utf *desc);
139 fieldinfo *class_resolvefield(classinfo *c, utf *name, utf *desc, classinfo *referer, bool except);
140
141 /* search for a method with a specified name and descriptor */
142 methodinfo *class_findmethod(classinfo *c, utf *name, utf *desc);
143 methodinfo *class_fetchmethod(classinfo *c, utf *name, utf *desc);
144 methodinfo *class_findmethod_w(classinfo *c, utf *name, utf *desc, char*);
145 methodinfo *class_resolvemethod(classinfo *c, utf *name, utf *dest);
146 methodinfo *class_resolveclassmethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool except);
147 methodinfo *class_resolveinterfacemethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool except);
148
149 /* search for a method with specified name and arguments (returntype ignored) */
150 methodinfo *class_findmethod_approx(classinfo *c, utf *name, utf *desc);
151 methodinfo *class_resolvemethod_approx(classinfo *c, utf *name, utf *dest);
152
153 bool class_issubclass(classinfo *sub, classinfo *super);
154
155 /* call initializer of class */
156 classinfo *class_init(classinfo *c);
157
158 void class_showconstanti(classinfo *c, int ii);
159
160 /* debug purposes */
161 void class_showmethods(classinfo *c);
162 void class_showconstantpool(classinfo *c);
163 void print_arraydescriptor(FILE *file, arraydescriptor *desc);
164
165 /* return the primitive class inidicated by the given signature character */
166 classinfo *class_primitive_from_sig(char sig);
167
168
169 /* return the class indicated by the given descriptor */
170 /* (see loader.c for documentation) */
171 #define CLASSLOAD_NEW           0      /* default */
172 #define CLASSLOAD_LOAD          0x0001
173 #define CLASSLOAD_SKIP          0x0002
174 #define CLASSLOAD_PANIC         0      /* default */
175 #define CLASSLOAD_NOPANIC       0x0010
176 #define CLASSLOAD_PRIMITIVE     0      /* default */
177 #define CLASSLOAD_NULLPRIMITIVE 0x0020
178 #define CLASSLOAD_VOID          0      /* default */
179 #define CLASSLOAD_NOVOID        0x0040
180 #define CLASSLOAD_NOCHECKEND    0      /* default */
181 #define CLASSLOAD_CHECKEND      0x1000
182
183 classinfo *class_from_descriptor(char *utf_ptr,char *end_ptr,char **next,int mode);
184 int type_from_descriptor(classinfo **cls,char *utf_ptr,char *end_ptr,char **next,int mode);
185
186 /* (used by class_new, don't use directly) */
187 void class_new_array(classinfo *c);
188
189 #define LAZYLOADING(class) { \
190         if (!class->loaded) \
191             if (!class_load(class)) \
192                 return 0; \
193         if (!class->linked) \
194             if (!class_link(class)) \
195                 return 0; }
196
197
198
199 #define LAZYLOADING1(class) { \
200         if (!class->loaded) \
201             if (!class_load(class)) \
202                 return; \
203         if (!class->linked) \
204             if (!class_link(class)) \
205                 return; }
206
207
208 classinfo *class_load(classinfo *c);
209 classinfo *class_load_intern(classbuffer *cb);
210 classinfo *class_link(classinfo *c);
211 void class_free(classinfo *c);
212
213 void field_display(fieldinfo *f);
214
215 void method_display(methodinfo *m);
216 void method_display_w_class(methodinfo *m);
217
218 utf* clinit_desc(void);
219 utf* clinit_name(void);
220
221 #endif /* _LOADER_H */
222
223
224 /*
225  * These are local overrides for various environment variables in Emacs.
226  * Please do not remove this and leave it at the end of the file, where
227  * Emacs will automagically detect them.
228  * ---------------------------------------------------------------------
229  * Local variables:
230  * mode: c
231  * indent-tabs-mode: t
232  * c-basic-offset: 4
233  * tab-width: 4
234  * End:
235  */