1 /* src/vm/loader.h - class loader header
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
8 This file is part of CACAO.
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.
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.
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
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Reinhard Grafl
29 $Id: loader.h 2154 2005-03-30 20:03:06Z twisti $
39 /* forward typedefs ***********************************************************/
41 typedef struct classbuffer classbuffer;
42 typedef struct classpath_info classpath_info;
48 #include "vm/descriptor.h"
49 #include "vm/global.h"
50 #include "vm/method.h"
54 # include "vm/unzip.h"
58 /* signed suck defines ********************************************************/
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))
66 /* constant pool entries *******************************************************
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:
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
87 *******************************************************************************/
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 */
98 typedef struct { /* Integer */
103 typedef struct { /* Float */
108 typedef struct { /* Long */
113 typedef struct { /* Double */
118 typedef struct { /* NameAndType (Field or Method) */
119 utf *name; /* field/method name */
120 utf *descriptor; /* field/method type descriptor string */
121 } constant_nameandtype;
124 /* 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 */
134 /* classpath_info *************************************************************/
136 #define CLASSPATH_PATH 0
137 #define CLASSPATH_ARCHIVE 1
139 struct classpath_info {
140 #if defined(USE_THREADS)
141 /* Required for monitor locking on zip/jar files. */
142 java_objectheader header;
147 #if defined(USE_ZLIB)
150 classpath_info *next;
154 /* export variables ***********************************************************/
156 #if defined(USE_THREADS)
157 extern int blockInts;
160 extern classpath_info *classpath_entries;
163 /* function prototypes ********************************************************/
165 /* initialize loader, load important systemclasses */
166 bool loader_init(u1 *stackbottom);
168 void suck_init(char *cpath);
169 void create_all_classes(void);
170 void suck_stop(classbuffer *cb);
172 inline bool check_classbuffer_size(classbuffer *cb, s4 len);
174 inline u1 suck_u1(classbuffer *cb);
175 inline u2 suck_u2(classbuffer *cb);
176 inline u4 suck_u4(classbuffer *cb);
179 void loader_close(void);
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);
187 /* retrieve constantpool element */
188 voidptr class_getconstant(classinfo *class, u4 pos, u4 ctype);
190 /* determine type of a constantpool element */
191 u4 class_constanttype(classinfo *class, u4 pos);
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);
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);
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);
208 bool class_issubclass(classinfo *sub, classinfo *super);
210 /* call initializer of class */
211 classinfo *class_init(classinfo *c);
214 void class_showmethods(classinfo *c);
215 void class_showconstantpool(classinfo *c);
216 void print_arraydescriptor(FILE *file, arraydescriptor *desc);
218 /* return the primitive class inidicated by the given signature character */
219 classinfo *class_primitive_from_sig(char sig);
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
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);
239 /* (used by class_new, don't use directly) */
240 void class_new_array(classinfo *c);
242 #endif /* _LOADER_H */
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 * ---------------------------------------------------------------------
252 * indent-tabs-mode: t