3e30e4a278335bbac03f62261085155852ae7131
[cacao.git] / src / vm / loader.hpp
1 /* src/vm/loader.hpp - class loader header
2
3    Copyright (C) 1996-2005, 2006, 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #ifndef _LOADER_HPP
27 #define _LOADER_HPP
28
29 /* forward typedefs ***********************************************************/
30
31 typedef struct classbuffer classbuffer;
32
33
34 #include "config.h"
35
36 #include <stdio.h>
37
38 #include "vm/types.h"
39
40 #include "vm/descriptor.h"
41 #include "vm/class.hpp"
42 #include "vm/global.h"
43 #include "vm/method.hpp"
44 #include "vm/references.h"
45 #include "vm/utf8.h"
46
47
48 /* constant pool entries *******************************************************
49
50         All constant pool entries need a data structure which contain the entrys
51         value. In some cases this structure exist already, in the remaining cases
52         this structure must be generated:
53
54                 kind                      structure                     generated?
55         ----------------------------------------------------------------------
56     CONSTANT_Class               constant_classref                  yes
57     CONSTANT_Fieldref            constant_FMIref                    yes
58     CONSTANT_Methodref           constant_FMIref                    yes
59     CONSTANT_InterfaceMethodref  constant_FMIref                    yes
60     CONSTANT_String              unicode                             no
61     CONSTANT_Integer             constant_integer                   yes
62     CONSTANT_Float               constant_float                     yes
63     CONSTANT_Long                constant_long                      yes
64     CONSTANT_Double              constant_double                    yes
65     CONSTANT_NameAndType         constant_nameandtype               yes
66     CONSTANT_Utf8                unicode                             no
67     CONSTANT_UNUSED              -
68
69 *******************************************************************************/
70
71 typedef struct {            /* Integer                                        */
72         s4 value;
73 } constant_integer;
74
75         
76 typedef struct {            /* Float                                          */
77         float value;
78 } constant_float;
79
80
81 typedef struct {            /* Long                                           */
82         s8 value;
83 } constant_long;
84         
85
86 typedef struct {            /* Double                                         */
87         double value;
88 } constant_double;
89
90
91 typedef struct {            /* NameAndType (Field or Method)                  */
92         utf *name;              /* field/method name                              */
93         utf *descriptor;        /* field/method type descriptor string            */
94 } constant_nameandtype;
95
96
97 /* classbuffer ****************************************************************/
98
99 struct classbuffer {
100         classinfo *clazz;                   /* pointer to classinfo structure     */
101         uint8_t   *data;                    /* pointer to byte code               */
102         int32_t    size;                    /* size of the byte code              */
103         uint8_t   *pos;                     /* current read position              */
104         char      *path;                    /* path to file (for debugging)       */
105 };
106
107
108 /* hashtable_classloader_entry *************************************************
109
110    ATTENTION: The pointer to the classloader object needs to be the
111    first field of the entry, so that it can be used as an indirection
112    cell. This is checked by gc_init() during startup.
113
114 *******************************************************************************/
115
116 typedef struct hashtable_classloader_entry hashtable_classloader_entry;
117
118 struct hashtable_classloader_entry {
119         java_object_t               *object;
120         hashtable_classloader_entry *hashlink;
121 };
122
123
124 /* classloader *****************************************************************
125
126    [!ENABLE_HANDLES]: The classloader is a Java Object which cannot move.
127    [ENABLE_HANDLES] : The classloader entry itself is a static handle for a
128                       given classloader (use loader_hashtable_classloader_foo).
129
130 *******************************************************************************/
131
132 #if defined(ENABLE_HANDLES)
133 typedef hashtable_classloader_entry classloader_t;
134 #else
135 typedef java_object_t               classloader_t;
136 #endif
137
138
139 /* function prototypes ********************************************************/
140
141 #ifdef __cplusplus
142 extern "C" {
143 #endif
144
145 void loader_preinit(void);
146 void loader_init(void);
147
148 /* classloader management functions */
149 classloader_t *loader_hashtable_classloader_add(java_handle_t *cl);
150 classloader_t *loader_hashtable_classloader_find(java_handle_t *cl);
151
152 void loader_load_all_classes(void);
153
154 bool loader_skip_attribute_body(classbuffer *cb);
155
156 #if defined(ENABLE_JAVASE)
157 bool loader_load_attribute_signature(classbuffer *cb, utf **signature);
158 #endif
159
160 /* free resources */
161 void loader_close(void);
162
163 /* class loading functions */
164 classinfo *load_class_from_sysloader(utf *name);
165 classinfo *load_class_from_classloader(utf *name, classloader_t *cl);
166 classinfo *load_class_bootstrap(utf *name);
167
168 /* (don't use the following directly) */
169 classinfo *load_class_from_classbuffer(classbuffer *cb);
170 classinfo *load_newly_created_array(classinfo *c, classloader_t *loader);
171
172 #ifdef __cplusplus
173 }
174 #endif
175
176 #endif // _LOADER_HPP
177
178
179 /*
180  * These are local overrides for various environment variables in Emacs.
181  * Please do not remove this and leave it at the end of the file, where
182  * Emacs will automagically detect them.
183  * ---------------------------------------------------------------------
184  * Local variables:
185  * mode: c++
186  * indent-tabs-mode: t
187  * c-basic-offset: 4
188  * tab-width: 4
189  * End:
190  * vim:noexpandtab:sw=4:ts=4:
191  */