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.hpp"
33 #include "vm/jit/builtin.hpp"
34 #include "vm/class.hpp"
35 #include "vm/field.hpp"
36 #include "vm/initialize.hpp"
37 #include "vm/options.h"
38 #include "vm/references.h"
39 #include "vm/resolve.hpp"
41 #include "vm/jit/asmpart.h"
42 #include "vm/jit/patcher.h"
45 /* patcher_get_putstatic *******************************************************
49 *******************************************************************************/
51 bool intrp_patcher_get_putstatic(u1 *sp)
58 uf = (unresolved_field *) ip[2];
60 /* get the fieldinfo */
62 if (!(fi = resolve_field_eager(uf)))
65 /* check if the field's class is initialized */
67 if (!(fi->clazz->state & CLASS_INITIALIZED))
68 if (!initialize_class(fi->clazz))
71 /* patch the field's address */
73 ip[1] = (ptrint) &(fi->value);
79 /* patcher_get_putstatic_clinit ************************************************
81 This patcher is used if we already have the resolved fieldinfo but the
82 class of the field has not been initialized, yet.
86 *******************************************************************************/
88 bool intrp_patcher_get_putstatic_clinit(u1 *sp)
93 /* get the fieldinfo */
96 fi = (fieldinfo *) ip[2];
98 /* check if the field's class is initialized */
100 if (!(fi->clazz->state & CLASS_INITIALIZED))
101 if (!initialize_class(fi->clazz))
104 /* patch the field's address */
106 ip[1] = (ptrint) &(fi->value);
112 /* patcher_get_putfield ********************************************************
116 *******************************************************************************/
118 bool intrp_patcher_get_putfield(u1 *sp)
121 unresolved_field *uf;
125 uf = (unresolved_field *) ip[2];
127 /* get the fieldinfo */
129 if (!(fi = resolve_field_eager(uf)))
132 /* patch the field's offset */
140 /* patcher_aconst **************************************************************
144 *******************************************************************************/
146 bool intrp_patcher_aconst(u1 *sp)
149 constant_classref *cr;
153 cr = (constant_classref *) ip[2];
155 /* get the classinfo */
157 if (!(c = resolve_classref_eager(cr)))
160 /* patch the classinfo pointer */
168 /* patcher_builtin_multianewarray **********************************************
172 *******************************************************************************/
174 bool intrp_patcher_builtin_multianewarray(u1 *sp)
177 constant_classref *cr;
181 cr = (constant_classref *) ip[3];
183 /* get the classinfo */
185 if (!(c = resolve_classref_eager(cr)))
188 /* patch the classinfo pointer */
196 /* patcher_builtin_arraycheckcast **********************************************
200 *******************************************************************************/
202 bool intrp_patcher_builtin_arraycheckcast(u1 *sp)
205 constant_classref *cr;
209 cr = (constant_classref *) ip[2];
211 /* get the classinfo */
213 if (!(c = resolve_classref_eager(cr)))
216 /* patch the classinfo pointer */
224 /* patcher_invokestatic_special ************************************************
228 ******************************************************************************/
230 bool intrp_patcher_invokestatic_special(u1 *sp)
233 unresolved_method *um;
237 um = (unresolved_method *) ip[3];
239 /* get the fieldinfo */
241 if (!(m = resolve_method_eager(um)))
244 /* patch methodinfo and stubroutine */
247 ip[1] = (ptrint) m->stubroutine;
253 /* patcher_invokevirtual *******************************************************
257 *******************************************************************************/
259 bool intrp_patcher_invokevirtual(u1 *sp)
262 unresolved_method *um;
266 um = (unresolved_method *) ip[3];
268 /* get the fieldinfo */
270 if (!(m = resolve_method_eager(um)))
273 /* patch methodinfo and vftbl index */
276 ip[1] = (OFFSET(vftbl_t, table[0]) + sizeof(methodptr) * m->vftblindex);
282 /* patcher_invokeinterface *****************************************************
286 *******************************************************************************/
288 bool intrp_patcher_invokeinterface(u1 *sp)
291 unresolved_method *um;
295 um = (unresolved_method *) ip[4];
297 /* get the methodinfo */
299 if (!(m = resolve_method_eager(um)))
302 /* patch interfacetable index */
304 ip[1] = (OFFSET(vftbl_t, interfacetable[0]) -
305 sizeof(methodptr*) * m->clazz->index);
307 /* patch methodinfo and method offset */
310 ip[2] = (sizeof(methodptr) * (m - m->clazz->methods));
316 /* patcher_checkcast_instanceof ************************************************
320 *******************************************************************************/
322 bool intrp_patcher_checkcast_instanceof(u1 *sp)
325 constant_classref *cr;
329 cr = (constant_classref *) ip[2];
331 /* get the classinfo */
333 if (!(c = resolve_classref_eager(cr)))
336 /* patch super class pointer */
344 /* patcher_resolve_native ******************************************************
348 *******************************************************************************/
350 bool intrp_patcher_resolve_native(u1 *sp)
357 m = (methodinfo *) ip[1];
359 /* resolve native function */
361 if (!(f = native_resolve_function(m)))
364 /* patch native function pointer */
373 * These are local overrides for various environment variables in Emacs.
374 * Please do not remove this and leave it at the end of the file, where
375 * Emacs will automagically detect them.
376 * ---------------------------------------------------------------------
379 * indent-tabs-mode: t
383 * vim:noexpandtab:sw=4:ts=4: