1 /* src/vm/jit/intrp/patcher.c - Interpreter code patching functions
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
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.
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.
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
29 #include "mm/memory.h"
31 #include "native/native.h"
33 #include "vm/builtin.h"
34 #include "vm/initialize.h"
36 #include "vm/jit/asmpart.h"
37 #include "vm/jit/patcher.h"
39 #include "vmcore/class.h"
40 #include "vmcore/field.h"
41 #include "vmcore/options.h"
42 #include "vm/resolve.h"
43 #include "vmcore/references.h"
46 /* patcher_get_putstatic *******************************************************
50 *******************************************************************************/
52 bool intrp_patcher_get_putstatic(u1 *sp)
59 uf = (unresolved_field *) ip[2];
61 /* get the fieldinfo */
63 if (!(fi = resolve_field_eager(uf)))
66 /* check if the field's class is initialized */
68 if (!(fi->clazz->state & CLASS_INITIALIZED))
69 if (!initialize_class(fi->clazz))
72 /* patch the field's address */
74 ip[1] = (ptrint) &(fi->value);
80 /* patcher_get_putstatic_clinit ************************************************
82 This patcher is used if we already have the resolved fieldinfo but the
83 class of the field has not been initialized, yet.
87 *******************************************************************************/
89 bool intrp_patcher_get_putstatic_clinit(u1 *sp)
94 /* get the fieldinfo */
97 fi = (fieldinfo *) ip[2];
99 /* check if the field's class is initialized */
101 if (!(fi->clazz->state & CLASS_INITIALIZED))
102 if (!initialize_class(fi->clazz))
105 /* patch the field's address */
107 ip[1] = (ptrint) &(fi->value);
113 /* patcher_get_putfield ********************************************************
117 *******************************************************************************/
119 bool intrp_patcher_get_putfield(u1 *sp)
122 unresolved_field *uf;
126 uf = (unresolved_field *) ip[2];
128 /* get the fieldinfo */
130 if (!(fi = resolve_field_eager(uf)))
133 /* patch the field's offset */
141 /* patcher_aconst **************************************************************
145 *******************************************************************************/
147 bool intrp_patcher_aconst(u1 *sp)
150 constant_classref *cr;
154 cr = (constant_classref *) ip[2];
156 /* get the classinfo */
158 if (!(c = resolve_classref_eager(cr)))
161 /* patch the classinfo pointer */
169 /* patcher_builtin_multianewarray **********************************************
173 *******************************************************************************/
175 bool intrp_patcher_builtin_multianewarray(u1 *sp)
178 constant_classref *cr;
182 cr = (constant_classref *) ip[3];
184 /* get the classinfo */
186 if (!(c = resolve_classref_eager(cr)))
189 /* patch the classinfo pointer */
197 /* patcher_builtin_arraycheckcast **********************************************
201 *******************************************************************************/
203 bool intrp_patcher_builtin_arraycheckcast(u1 *sp)
206 constant_classref *cr;
210 cr = (constant_classref *) ip[2];
212 /* get the classinfo */
214 if (!(c = resolve_classref_eager(cr)))
217 /* patch the classinfo pointer */
225 /* patcher_invokestatic_special ************************************************
229 ******************************************************************************/
231 bool intrp_patcher_invokestatic_special(u1 *sp)
234 unresolved_method *um;
238 um = (unresolved_method *) ip[3];
240 /* get the fieldinfo */
242 if (!(m = resolve_method_eager(um)))
245 /* patch methodinfo and stubroutine */
248 ip[1] = (ptrint) m->stubroutine;
254 /* patcher_invokevirtual *******************************************************
258 *******************************************************************************/
260 bool intrp_patcher_invokevirtual(u1 *sp)
263 unresolved_method *um;
267 um = (unresolved_method *) ip[3];
269 /* get the fieldinfo */
271 if (!(m = resolve_method_eager(um)))
274 /* patch methodinfo and vftbl index */
277 ip[1] = (OFFSET(vftbl_t, table[0]) + sizeof(methodptr) * m->vftblindex);
283 /* patcher_invokeinterface *****************************************************
287 *******************************************************************************/
289 bool intrp_patcher_invokeinterface(u1 *sp)
292 unresolved_method *um;
296 um = (unresolved_method *) ip[4];
298 /* get the methodinfo */
300 if (!(m = resolve_method_eager(um)))
303 /* patch interfacetable index */
305 ip[1] = (OFFSET(vftbl_t, interfacetable[0]) -
306 sizeof(methodptr*) * m->clazz->index);
308 /* patch methodinfo and method offset */
311 ip[2] = (sizeof(methodptr) * (m - m->clazz->methods));
317 /* patcher_checkcast_instanceof ************************************************
321 *******************************************************************************/
323 bool intrp_patcher_checkcast_instanceof(u1 *sp)
326 constant_classref *cr;
330 cr = (constant_classref *) ip[2];
332 /* get the classinfo */
334 if (!(c = resolve_classref_eager(cr)))
337 /* patch super class pointer */
345 /* patcher_resolve_native ******************************************************
349 *******************************************************************************/
351 bool intrp_patcher_resolve_native(u1 *sp)
358 m = (methodinfo *) ip[1];
360 /* resolve native function */
362 if (!(f = native_resolve_function(m)))
365 /* patch native function pointer */
374 * These are local overrides for various environment variables in Emacs.
375 * Please do not remove this and leave it at the end of the file, where
376 * Emacs will automagically detect them.
377 * ---------------------------------------------------------------------
380 * indent-tabs-mode: t
384 * vim:noexpandtab:sw=4:ts=4: