fix merging of classcache_class_entry:s
[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 2062 2005-03-23 11:16:45Z twisti $
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 extern classpath_info *classpath_entries;
84
85 /* pseudo classes for the type checker ****************************************/
86
87 /*
88  * pseudo_class_Arraystub
89  *     (extends Object implements Cloneable, java.io.Serializable)
90  *
91  *     If two arrays of incompatible component types are merged,
92  *     the resulting reference has no accessible components.
93  *     The result does, however, implement the interfaces Cloneable
94  *     and java.io.Serializable. This pseudo class is used internally
95  *     to represent such results. (They are *not* considered arrays!)
96  *
97  * pseudo_class_Null
98  *
99  *     This pseudo class is used internally to represent the
100  *     null type.
101  *
102  * pseudo_class_New
103  *
104  *     This pseudo class is used internally to represent the
105  *     the 'uninitialized object' type.
106  */
107
108 extern classinfo *pseudo_class_Arraystub;
109 extern classinfo *pseudo_class_Null;
110 extern classinfo *pseudo_class_New;
111 extern vftbl_t *pseudo_class_Arraystub_vftbl;
112
113 extern utf *array_packagename;
114
115
116 /************************ prototypes ******************************************/
117
118 /* initialize loader, load important systemclasses */
119 bool loader_init(u1 *stackbottom);
120
121 void suck_init(char *cpath);
122 void create_all_classes(void);
123 void suck_stop(classbuffer *cb);
124
125 /* free resources */
126 void loader_close(void);
127
128 void loader_compute_subclasses(classinfo *c);
129
130 /* retrieve constantpool element */
131 voidptr class_getconstant(classinfo *class, u4 pos, u4 ctype);
132
133 /* determine type of a constantpool element */
134 u4 class_constanttype(classinfo *class, u4 pos);
135
136 s4 class_findmethodIndex(classinfo *c, utf *name, utf *desc);
137
138 /* search class for a field */
139 fieldinfo *class_findfield(classinfo *c, utf *name, utf *desc);
140 fieldinfo *class_resolvefield(classinfo *c, utf *name, utf *desc, classinfo *referer, bool except);
141
142 /* search for a method with a specified name and descriptor */
143 methodinfo *class_findmethod(classinfo *c, utf *name, utf *desc);
144 methodinfo *class_fetchmethod(classinfo *c, utf *name, utf *desc);
145 methodinfo *class_findmethod_w(classinfo *c, utf *name, utf *desc, char*);
146 methodinfo *class_resolvemethod(classinfo *c, utf *name, utf *dest);
147 methodinfo *class_resolveclassmethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool except);
148 methodinfo *class_resolveinterfacemethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool except);
149
150 /* search for a method with specified name and arguments (returntype ignored) */
151 methodinfo *class_findmethod_approx(classinfo *c, utf *name, utf *desc);
152 methodinfo *class_resolvemethod_approx(classinfo *c, utf *name, utf *dest);
153
154 bool class_issubclass(classinfo *sub, classinfo *super);
155
156 /* call initializer of class */
157 classinfo *class_init(classinfo *c);
158
159 void class_showconstanti(classinfo *c, int ii);
160
161 /* debug purposes */
162 void class_showmethods(classinfo *c);
163 void class_showconstantpool(classinfo *c);
164 void print_arraydescriptor(FILE *file, arraydescriptor *desc);
165
166 /* return the primitive class inidicated by the given signature character */
167 classinfo *class_primitive_from_sig(char sig);
168
169
170 /* return the class indicated by the given descriptor */
171 /* (see loader.c for documentation) */
172 #define CLASSLOAD_NEW           0      /* default */
173 #define CLASSLOAD_LOAD          0x0001
174 #define CLASSLOAD_SKIP          0x0002
175 #define CLASSLOAD_PANIC         0      /* default */
176 #define CLASSLOAD_NOPANIC       0x0010
177 #define CLASSLOAD_PRIMITIVE     0      /* default */
178 #define CLASSLOAD_NULLPRIMITIVE 0x0020
179 #define CLASSLOAD_VOID          0      /* default */
180 #define CLASSLOAD_NOVOID        0x0040
181 #define CLASSLOAD_NOCHECKEND    0      /* default */
182 #define CLASSLOAD_CHECKEND      0x1000
183
184 classinfo *class_from_descriptor(char *utf_ptr,char *end_ptr,char **next,int mode);
185 int type_from_descriptor(classinfo **cls,char *utf_ptr,char *end_ptr,char **next,int mode);
186
187 /* (used by class_new, don't use directly) */
188 void class_new_array(classinfo *c);
189
190 #define LAZYLOADING(class) { \
191         if (!class->loaded) \
192             if (!class_load(class)) \
193                 return 0; \
194         if (!class->linked) \
195             if (!class_link(class)) \
196                 return 0; }
197
198
199
200 #define LAZYLOADING1(class) { \
201         if (!class->loaded) \
202             if (!class_load(class)) \
203                 return; \
204         if (!class->linked) \
205             if (!class_link(class)) \
206                 return; }
207
208
209 classinfo *class_load(classinfo *c);
210 classinfo *class_load_intern(classbuffer *cb);
211 classinfo *class_link(classinfo *c);
212 void class_free(classinfo *c);
213
214 void field_display(fieldinfo *f);
215
216 void method_display(methodinfo *m);
217 void method_display_w_class(methodinfo *m);
218
219 utf* clinit_desc(void);
220 utf* clinit_name(void);
221
222 #endif /* _LOADER_H */
223
224
225 /*
226  * These are local overrides for various environment variables in Emacs.
227  * Please do not remove this and leave it at the end of the file, where
228  * Emacs will automagically detect them.
229  * ---------------------------------------------------------------------
230  * Local variables:
231  * mode: c
232  * indent-tabs-mode: t
233  * c-basic-offset: 4
234  * tab-width: 4
235  * End:
236  */