Lazy checkcast and instanceof.
[cacao.git] / src / vm / jit / helper.c
1 /* src/vm/jit/asmhelper.c - code patching helper functions
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: Christian Thalinger
28
29    Changes:
30
31    $Id: helper.c 2266 2005-04-11 10:00:51Z twisti $
32
33 */
34
35
36 #include "vm/class.h"
37 #include "vm/exceptions.h"
38 #include "vm/initialize.h"
39 #include "vm/method.h"
40 #include "vm/references.h"
41 #include "vm/resolve.h"
42
43 /* XXX class_resolveclassmethod */
44 #include "vm/loader.h"
45
46
47 /* helper_resolve_classinfo ****************************************************
48
49    This function returns the loaded and resolved class.
50
51 *******************************************************************************/
52
53 classinfo *helper_resolve_classinfo(constant_classref *cr)
54 {
55         classinfo *c;
56
57         /* resolve and load the class */
58
59         if (!resolve_classref(NULL, cr, resolveEager, true, &c))
60                 return NULL;
61
62         /* return the classinfo pointer */
63
64         return c;
65 }
66
67
68 /* helper_resolve_classinfo_flags **********************************************
69
70    This function returns the flags of the passed class.
71
72 *******************************************************************************/
73
74 s4 helper_resolve_classinfo_flags(constant_classref *cr)
75 {
76         classinfo *c;
77
78         /* resolve and load the class */
79
80         if (!resolve_classref(NULL, cr, resolveEager, true, &c))
81                 return -1;
82
83         /* return the flags */
84
85         return c->flags;
86 }
87
88
89 /* helper_resolve_classinfo_vftbl **********************************************
90
91    This function return the vftbl pointer of the passed class.
92
93 *******************************************************************************/
94
95 vftbl_t *helper_resolve_classinfo_vftbl(constant_classref *cr)
96 {
97         classinfo *c;
98
99         /* resolve the method */
100
101         if (!resolve_classref(NULL, cr, resolveEager, true, &c))
102                 return NULL;
103
104         /* return the virtual function table pointer */
105
106         return c->vftbl;
107 }
108
109
110 /* helper_resolve_classinfo_index **********************************************
111
112    This function returns the index of the passed class.
113
114 *******************************************************************************/
115
116 s4 helper_resolve_classinfo_index(constant_classref *cr)
117 {
118         classinfo *c;
119
120         /* resolve and load the class */
121
122         if (!resolve_classref(NULL, cr, resolveEager, true, &c))
123                 return -1;
124
125         /* return the class' index */
126
127         return c->index;
128 }
129
130
131 /* helper_resolve_methodinfo ***************************************************
132
133    This function returns the loaded and resolved methodinfo of the
134    passed method.
135
136 *******************************************************************************/
137
138 methodinfo *helper_resolve_methodinfo(unresolved_method *um)
139 {
140         methodinfo *m;
141
142         /* resolve the method */
143
144         if (!resolve_method(um, resolveEager, &m))
145                 return NULL;
146
147         /* return the methodinfo pointer */
148
149         return m;
150 }
151
152
153 /* helper_resolve_methodinfo_vftblindex ****************************************
154
155    This function returns the virtual function table index (vftblindex)
156    of the passed method.
157
158 *******************************************************************************/
159
160 s4 helper_resolve_methodinfo_vftblindex(unresolved_method *um)
161 {
162         methodinfo *m;
163
164         /* resolve the method */
165
166         if (!resolve_method(um, resolveEager, &m))
167                 return -1;
168
169         /* return the virtual function table index */
170
171         return m->vftblindex;
172 }
173
174
175 /* helper_resolve_methodinfo_stubroutine ***************************************
176
177    This function returns the stubroutine of the passed method.
178
179 *******************************************************************************/
180
181 u1 *helper_resolve_methodinfo_stubroutine(unresolved_method *um)
182 {
183         methodinfo *m;
184
185         /* resolve the method */
186
187         if (!resolve_method(um, resolveEager, &m))
188                 return NULL;
189
190         /* return the method pointer */
191
192         return m->stubroutine;
193 }
194
195
196 /* helper_resolve_fieldinfo_value_address **************************************
197
198    This function returns the value address of the passed field.
199
200 *******************************************************************************/
201
202 void *helper_resolve_fieldinfo_value_address(unresolved_field *uf)
203 {
204         fieldinfo *fi;
205
206         /* resolve the field */
207
208         if (!resolve_field(uf, resolveEager, &fi))
209                 return NULL;
210
211         /* check if class is initialized */
212
213         if (!fi->class->initialized)
214                 if (!initialize_class(fi->class))
215                         return NULL;
216
217         /* return the field value's address */
218
219         return &(fi->value);
220 }
221
222
223 /* helper_resolve_fieldinfo_offset *********************************************
224
225    This function returns the offset value of the passed field.
226
227 *******************************************************************************/
228
229 s4 helper_resolve_fieldinfo_offset(unresolved_field *uf)
230 {
231         fieldinfo *fi;
232
233         /* resolve the field */
234
235         if (!resolve_field(uf, resolveEager, &fi))
236                 return -1;
237
238         /* return the field value's offset */
239
240         return fi->offset;
241 }
242
243
244 /*
245  * These are local overrides for various environment variables in Emacs.
246  * Please do not remove this and leave it at the end of the file, where
247  * Emacs will automagically detect them.
248  * ---------------------------------------------------------------------
249  * Local variables:
250  * mode: c
251  * indent-tabs-mode: t
252  * c-basic-offset: 4
253  * tab-width: 4
254  * End:
255  * vim:noexpandtab:sw=4:ts=4:
256  */