1 /* src/vm/jit/intrp/patcher.c - Interpreter code patching functions
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
8 This file is part of CACAO.
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.
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.
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
25 $Id: patcher.c 7486 2007-03-08 13:50:07Z twisti $
33 #include "mm/memory.h"
35 #include "native/native.h"
37 #include "vm/builtin.h"
38 #include "vm/initialize.h"
40 #include "vm/jit/asmpart.h"
41 #include "vm/jit/patcher.h"
43 #include "vmcore/class.h"
44 #include "vmcore/field.h"
45 #include "vmcore/options.h"
46 #include "vm/resolve.h"
47 #include "vmcore/references.h"
50 /* patcher_get_putstatic *******************************************************
54 *******************************************************************************/
56 bool intrp_patcher_get_putstatic(u1 *sp)
63 uf = (unresolved_field *) ip[2];
65 /* get the fieldinfo */
67 if (!(fi = resolve_field_eager(uf)))
70 /* check if the field's class is initialized */
72 if (!(fi->class->state & CLASS_INITIALIZED))
73 if (!initialize_class(fi->class))
76 /* patch the field's address */
78 ip[1] = (ptrint) &(fi->value);
84 /* patcher_get_putstatic_clinit ************************************************
86 This patcher is used if we already have the resolved fieldinfo but the
87 class of the field has not been initialized, yet.
91 *******************************************************************************/
93 bool intrp_patcher_get_putstatic_clinit(u1 *sp)
98 /* get the fieldinfo */
101 fi = (fieldinfo *) ip[2];
103 /* check if the field's class is initialized */
105 if (!(fi->class->state & CLASS_INITIALIZED))
106 if (!initialize_class(fi->class))
109 /* patch the field's address */
111 ip[1] = (ptrint) &(fi->value);
117 /* patcher_get_putfield ********************************************************
121 *******************************************************************************/
123 bool intrp_patcher_get_putfield(u1 *sp)
126 unresolved_field *uf;
130 uf = (unresolved_field *) ip[2];
132 /* get the fieldinfo */
134 if (!(fi = resolve_field_eager(uf)))
137 /* patch the field's offset */
145 /* patcher_aconst **************************************************************
149 *******************************************************************************/
151 bool intrp_patcher_aconst(u1 *sp)
154 constant_classref *cr;
158 cr = (constant_classref *) ip[2];
160 /* get the classinfo */
162 if (!(c = resolve_classref_eager(cr)))
165 /* patch the classinfo pointer */
173 /* patcher_builtin_multianewarray **********************************************
177 *******************************************************************************/
179 bool intrp_patcher_builtin_multianewarray(u1 *sp)
182 constant_classref *cr;
186 cr = (constant_classref *) ip[3];
188 /* get the classinfo */
190 if (!(c = resolve_classref_eager(cr)))
193 /* patch the classinfo pointer */
201 /* patcher_builtin_arraycheckcast **********************************************
205 *******************************************************************************/
207 bool intrp_patcher_builtin_arraycheckcast(u1 *sp)
210 constant_classref *cr;
214 cr = (constant_classref *) ip[2];
216 /* get the classinfo */
218 if (!(c = resolve_classref_eager(cr)))
221 /* patch the classinfo pointer */
229 /* patcher_invokestatic_special ************************************************
233 ******************************************************************************/
235 bool intrp_patcher_invokestatic_special(u1 *sp)
238 unresolved_method *um;
242 um = (unresolved_method *) ip[3];
244 /* get the fieldinfo */
246 if (!(m = resolve_method_eager(um)))
249 /* patch methodinfo and stubroutine */
252 ip[1] = (ptrint) m->stubroutine;
258 /* patcher_invokevirtual *******************************************************
262 *******************************************************************************/
264 bool intrp_patcher_invokevirtual(u1 *sp)
267 unresolved_method *um;
271 um = (unresolved_method *) ip[3];
273 /* get the fieldinfo */
275 if (!(m = resolve_method_eager(um)))
278 /* patch methodinfo and vftbl index */
281 ip[1] = (OFFSET(vftbl_t, table[0]) + sizeof(methodptr) * m->vftblindex);
287 /* patcher_invokeinterface *****************************************************
291 *******************************************************************************/
293 bool intrp_patcher_invokeinterface(u1 *sp)
296 unresolved_method *um;
300 um = (unresolved_method *) ip[4];
302 /* get the methodinfo */
304 if (!(m = resolve_method_eager(um)))
307 /* patch interfacetable index */
309 ip[1] = (OFFSET(vftbl_t, interfacetable[0]) -
310 sizeof(methodptr*) * m->class->index);
312 /* patch methodinfo and method offset */
315 ip[2] = (sizeof(methodptr) * (m - m->class->methods));
321 /* patcher_checkcast_instanceof ************************************************
325 *******************************************************************************/
327 bool intrp_patcher_checkcast_instanceof(u1 *sp)
330 constant_classref *cr;
334 cr = (constant_classref *) ip[2];
336 /* get the classinfo */
338 if (!(c = resolve_classref_eager(cr)))
341 /* patch super class pointer */
349 /* patcher_resolve_native ******************************************************
353 *******************************************************************************/
355 #if !defined(WITH_STATIC_CLASSPATH)
356 bool intrp_patcher_resolve_native(u1 *sp)
363 m = (methodinfo *) ip[1];
365 /* resolve native function */
367 if (!(f = native_resolve_function(m)))
370 /* patch native function pointer */
376 #endif /* !defined(WITH_STATIC_CLASSPATH) */
380 * These are local overrides for various environment variables in Emacs.
381 * Please do not remove this and leave it at the end of the file, where
382 * Emacs will automagically detect them.
383 * ---------------------------------------------------------------------
386 * indent-tabs-mode: t
390 * vim:noexpandtab:sw=4:ts=4: