removed "class" field in constant_FMIref
[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 2186 2005-04-02 00:43:25Z edwin $
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 "vm/global.h"
46 #include "vm/utf8.h"
47 #include "vm/references.h"
48 #include "vm/descriptor.h"
49 #include "vm/method.h"
50
51 #if defined(USE_ZLIB)
52 # include "vm/unzip.h"
53 #endif
54
55
56 /* signed suck defines ********************************************************/
57
58 #define suck_s8(a)    (s8) suck_u8((a))
59 #define suck_s2(a)    (s2) suck_u2((a))
60 #define suck_s4(a)    (s4) suck_u4((a))
61 #define suck_s1(a)    (s1) suck_u1((a))
62
63
64 /* constant pool entries *******************************************************
65
66         All constant pool entries need a data structure which contain the entrys
67         value. In some cases this structure exist already, in the remaining cases
68         this structure must be generated:
69
70                 kind                      structure                     generated?
71         ----------------------------------------------------------------------
72     CONSTANT_Class               classinfo                           no   XXX this will change
73     CONSTANT_Fieldref            constant_FMIref                    yes
74     CONSTANT_Methodref           constant_FMIref                    yes
75     CONSTANT_InterfaceMethodref  constant_FMIref                    yes
76     CONSTANT_String              unicode                             no
77     CONSTANT_Integer             constant_integer                   yes
78     CONSTANT_Float               constant_float                     yes
79     CONSTANT_Long                constant_long                      yes
80     CONSTANT_Double              constant_double                    yes
81     CONSTANT_NameAndType         constant_nameandtype               yes
82     CONSTANT_Utf8                unicode                             no
83     CONSTANT_UNUSED              -
84
85 *******************************************************************************/
86
87 typedef struct {            /* Integer                                        */
88         s4 value;
89 } constant_integer;
90
91         
92 typedef struct {            /* Float                                          */
93         float value;
94 } constant_float;
95
96
97 typedef struct {            /* Long                                           */
98         s8 value;
99 } constant_long;
100         
101
102 typedef struct {            /* Double                                         */
103         double value;
104 } constant_double;
105
106
107 typedef struct {            /* NameAndType (Field or Method)                  */
108         utf *name;              /* field/method name                              */
109         utf *descriptor;        /* field/method type descriptor string            */
110 } constant_nameandtype;
111
112
113 /* classbuffer ****************************************************************/
114
115 struct classbuffer {
116         classinfo *class;                   /* pointer to classinfo structure     */
117         u1        *data;                    /* pointer to byte code               */
118         s4         size;                    /* size of the byte code              */
119         u1        *pos;                     /* current read position              */
120 };
121
122
123 /* classpath_info *************************************************************/
124
125 #define CLASSPATH_PATH       0
126 #define CLASSPATH_ARCHIVE    1
127
128 struct classpath_info {
129 #if defined(USE_THREADS)
130         /* Required for monitor locking on zip/jar files. */
131         java_objectheader  header;
132 #endif
133         s4                 type;
134         char              *path;
135         s4                 pathlen;
136 #if defined(USE_ZLIB)
137         unzFile            uf;
138 #endif
139         classpath_info    *next;
140 };
141
142
143 /* export variables ***********************************************************/
144
145 #if defined(USE_THREADS)
146 extern int blockInts;
147 #endif
148
149 extern classpath_info *classpath_entries;
150
151
152 /* function prototypes ********************************************************/
153
154 /* initialize loader, load important systemclasses */
155 bool loader_init(u1 *stackbottom);
156
157 void suck_init(char *cpath);
158 void create_all_classes(void);
159 void suck_stop(classbuffer *cb);
160
161 inline bool check_classbuffer_size(classbuffer *cb, s4 len);
162
163 inline u1 suck_u1(classbuffer *cb);
164 inline u2 suck_u2(classbuffer *cb);
165 inline u4 suck_u4(classbuffer *cb);
166
167 /* free resources */
168 void loader_close(void);
169
170 /* class loading functions */
171 classinfo *load_class_from_classloader(classinfo *c, java_objectheader *cl);
172 classinfo *load_class_bootstrap(classinfo *c);
173 classinfo *load_class_from_classbuffer(classbuffer *cb);
174
175
176 /* retrieve constantpool element */
177 voidptr class_getconstant(classinfo *class, u4 pos, u4 ctype);
178
179 /* determine type of a constantpool element */
180 u4 class_constanttype(classinfo *class, u4 pos);
181
182 /* search class for a field */
183 fieldinfo *class_findfield(classinfo *c, utf *name, utf *desc);
184 fieldinfo *class_resolvefield(classinfo *c, utf *name, utf *desc, classinfo *referer, bool except);
185
186 /* search for a method with a specified name and descriptor */
187 methodinfo *class_findmethod(classinfo *c, utf *name, utf *desc);
188 methodinfo *class_fetchmethod(classinfo *c, utf *name, utf *desc);
189 methodinfo *class_resolvemethod(classinfo *c, utf *name, utf *dest);
190 methodinfo *class_resolveclassmethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool except);
191 methodinfo *class_resolveinterfacemethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool except);
192
193 /* search for a method with specified name and arguments (returntype ignored) */
194 methodinfo *class_findmethod_approx(classinfo *c, utf *name, utf *desc);
195 methodinfo *class_resolvemethod_approx(classinfo *c, utf *name, utf *dest);
196
197 bool class_issubclass(classinfo *sub, classinfo *super);
198
199 /* call initializer of class */
200 classinfo *class_init(classinfo *c);
201
202 /* debug purposes */
203 void class_showmethods(classinfo *c);
204 void class_showconstantpool(classinfo *c);
205
206 /* return the primitive class inidicated by the given signature character */
207 classinfo *class_primitive_from_sig(char sig);
208
209 /* (used by class_new, don't use directly) */
210 void class_new_array(classinfo *c);
211
212 /* debug helpers */
213 void fprintflags(FILE *fp, u2 f);
214 void printflags(u2 f);
215
216 #endif /* _LOADER_H */
217
218
219 /*
220  * These are local overrides for various environment variables in Emacs.
221  * Please do not remove this and leave it at the end of the file, where
222  * Emacs will automagically detect them.
223  * ---------------------------------------------------------------------
224  * Local variables:
225  * mode: c
226  * indent-tabs-mode: t
227  * c-basic-offset: 4
228  * tab-width: 4
229  * End:
230  */