09c233d3ecbe045174dec17dc7a6bbe0b029c0b7
[cacao.git] / src / vmcore / loader.h
1 /* src/vmcore/loader.h - class loader header
2
3    Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, 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., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25 */
26
27
28 #ifndef _LOADER_H
29 #define _LOADER_H
30
31 /* forward typedefs ***********************************************************/
32
33 typedef struct classbuffer classbuffer;
34
35
36 #include "config.h"
37
38 #include <stdio.h>
39
40 #include "vm/types.h"
41
42 #include "vm/global.h"
43
44 #include "vmcore/descriptor.h"
45 #include "vmcore/class.h"
46 #include "vmcore/method.h"
47 #include "vmcore/references.h"
48 #include "vmcore/utf8.h"
49
50
51 /* constant pool entries *******************************************************
52
53         All constant pool entries need a data structure which contain the entrys
54         value. In some cases this structure exist already, in the remaining cases
55         this structure must be generated:
56
57                 kind                      structure                     generated?
58         ----------------------------------------------------------------------
59     CONSTANT_Class               constant_classref                  yes
60     CONSTANT_Fieldref            constant_FMIref                    yes
61     CONSTANT_Methodref           constant_FMIref                    yes
62     CONSTANT_InterfaceMethodref  constant_FMIref                    yes
63     CONSTANT_String              unicode                             no
64     CONSTANT_Integer             constant_integer                   yes
65     CONSTANT_Float               constant_float                     yes
66     CONSTANT_Long                constant_long                      yes
67     CONSTANT_Double              constant_double                    yes
68     CONSTANT_NameAndType         constant_nameandtype               yes
69     CONSTANT_Utf8                unicode                             no
70     CONSTANT_UNUSED              -
71
72 *******************************************************************************/
73
74 typedef struct {            /* Integer                                        */
75         s4 value;
76 } constant_integer;
77
78         
79 typedef struct {            /* Float                                          */
80         float value;
81 } constant_float;
82
83
84 typedef struct {            /* Long                                           */
85         s8 value;
86 } constant_long;
87         
88
89 typedef struct {            /* Double                                         */
90         double value;
91 } constant_double;
92
93
94 typedef struct {            /* NameAndType (Field or Method)                  */
95         utf *name;              /* field/method name                              */
96         utf *descriptor;        /* field/method type descriptor string            */
97 } constant_nameandtype;
98
99
100 /* classbuffer ****************************************************************/
101
102 struct classbuffer {
103         classinfo *class;                   /* pointer to classinfo structure     */
104         u1        *data;                    /* pointer to byte code               */
105         s4         size;                    /* size of the byte code              */
106         u1        *pos;                     /* current read position              */
107         char      *path;                    /* path to file (for debugging)       */
108 };
109
110
111 /* hashtable_classloader_entry *************************************************
112
113    ATTENTION: The pointer to the classloader object needs to be the
114    first field of the entry, so that it can be used as an indirection
115    cell. This is checked by gc_init() during startup.
116
117 *******************************************************************************/
118
119 typedef struct hashtable_classloader_entry hashtable_classloader_entry;
120
121 struct hashtable_classloader_entry {
122         java_object_t               *object;
123         hashtable_classloader_entry *hashlink;
124 };
125
126
127 /* classloader *****************************************************************
128
129    [!ENABLE_HANDLES]: The classloader is a Java Object which cannot move.
130    [ENABLE_HANDLES] : The classloader entry itself is a static handle for a
131                       given classloader (use loader_hashtable_classloader_foo).
132
133 *******************************************************************************/
134
135 #if defined(ENABLE_HANDLES)
136 typedef hashtable_classloader_entry classloader;
137 #else
138 typedef java_object_t classloader;
139 #endif
140
141
142 /* function prototypes ********************************************************/
143
144 void loader_preinit(void);
145 void loader_init(void);
146
147 /* classloader management functions */
148 classloader *loader_hashtable_classloader_add(java_handle_t *cl);
149 classloader *loader_hashtable_classloader_find(java_handle_t *cl);
150
151 void loader_load_all_classes(void);
152
153 bool loader_skip_attribute_body(classbuffer *cb);
154
155 #if defined(ENABLE_JAVASE)
156 bool loader_load_attribute_signature(classbuffer *cb, utf **signature);
157 #endif
158
159 /* free resources */
160 void loader_close(void);
161
162 /* class loading functions */
163 classinfo *load_class_from_sysloader(utf *name);
164 classinfo *load_class_from_classloader(utf *name, classloader *cl);
165 classinfo *load_class_bootstrap(utf *name);
166
167 /* (don't use the following directly) */
168 classinfo *load_class_from_classbuffer(classbuffer *cb);
169 classinfo *load_newly_created_array(classinfo *c, classloader *loader);
170
171 #endif /* _LOADER_H */
172
173 /*
174  * These are local overrides for various environment variables in Emacs.
175  * Please do not remove this and leave it at the end of the file, where
176  * Emacs will automagically detect them.
177  * ---------------------------------------------------------------------
178  * Local variables:
179  * mode: c
180  * indent-tabs-mode: t
181  * c-basic-offset: 4
182  * tab-width: 4
183  * End:
184  * vim:noexpandtab:sw=4:ts=4:
185  */