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
31 #include "mm/memory.h"
33 #include "native/native.h"
35 #include "vm/builtin.h"
36 #include "vm/initialize.h"
38 #include "vm/jit/asmpart.h"
39 #include "vm/jit/patcher.h"
41 #include "vmcore/class.h"
42 #include "vmcore/field.h"
43 #include "vmcore/options.h"
44 #include "vm/resolve.h"
45 #include "vmcore/references.h"
48 /* patcher_get_putstatic *******************************************************
52 *******************************************************************************/
54 bool intrp_patcher_get_putstatic(u1 *sp)
61 uf = (unresolved_field *) ip[2];
63 /* get the fieldinfo */
65 if (!(fi = resolve_field_eager(uf)))
68 /* check if the field's class is initialized */
70 if (!(fi->class->state & CLASS_INITIALIZED))
71 if (!initialize_class(fi->class))
74 /* patch the field's address */
76 ip[1] = (ptrint) &(fi->value);
82 /* patcher_get_putstatic_clinit ************************************************
84 This patcher is used if we already have the resolved fieldinfo but the
85 class of the field has not been initialized, yet.
89 *******************************************************************************/
91 bool intrp_patcher_get_putstatic_clinit(u1 *sp)
96 /* get the fieldinfo */
99 fi = (fieldinfo *) ip[2];
101 /* check if the field's class is initialized */
103 if (!(fi->class->state & CLASS_INITIALIZED))
104 if (!initialize_class(fi->class))
107 /* patch the field's address */
109 ip[1] = (ptrint) &(fi->value);
115 /* patcher_get_putfield ********************************************************
119 *******************************************************************************/
121 bool intrp_patcher_get_putfield(u1 *sp)
124 unresolved_field *uf;
128 uf = (unresolved_field *) ip[2];
130 /* get the fieldinfo */
132 if (!(fi = resolve_field_eager(uf)))
135 /* patch the field's offset */
143 /* patcher_aconst **************************************************************
147 *******************************************************************************/
149 bool intrp_patcher_aconst(u1 *sp)
152 constant_classref *cr;
156 cr = (constant_classref *) ip[2];
158 /* get the classinfo */
160 if (!(c = resolve_classref_eager(cr)))
163 /* patch the classinfo pointer */
171 /* patcher_builtin_multianewarray **********************************************
175 *******************************************************************************/
177 bool intrp_patcher_builtin_multianewarray(u1 *sp)
180 constant_classref *cr;
184 cr = (constant_classref *) ip[3];
186 /* get the classinfo */
188 if (!(c = resolve_classref_eager(cr)))
191 /* patch the classinfo pointer */
199 /* patcher_builtin_arraycheckcast **********************************************
203 *******************************************************************************/
205 bool intrp_patcher_builtin_arraycheckcast(u1 *sp)
208 constant_classref *cr;
212 cr = (constant_classref *) ip[2];
214 /* get the classinfo */
216 if (!(c = resolve_classref_eager(cr)))
219 /* patch the classinfo pointer */
227 /* patcher_invokestatic_special ************************************************
231 ******************************************************************************/
233 bool intrp_patcher_invokestatic_special(u1 *sp)
236 unresolved_method *um;
240 um = (unresolved_method *) ip[3];
242 /* get the fieldinfo */
244 if (!(m = resolve_method_eager(um)))
247 /* patch methodinfo and stubroutine */
250 ip[1] = (ptrint) m->stubroutine;
256 /* patcher_invokevirtual *******************************************************
260 *******************************************************************************/
262 bool intrp_patcher_invokevirtual(u1 *sp)
265 unresolved_method *um;
269 um = (unresolved_method *) ip[3];
271 /* get the fieldinfo */
273 if (!(m = resolve_method_eager(um)))
276 /* patch methodinfo and vftbl index */
279 ip[1] = (OFFSET(vftbl_t, table[0]) + sizeof(methodptr) * m->vftblindex);
285 /* patcher_invokeinterface *****************************************************
289 *******************************************************************************/
291 bool intrp_patcher_invokeinterface(u1 *sp)
294 unresolved_method *um;
298 um = (unresolved_method *) ip[4];
300 /* get the methodinfo */
302 if (!(m = resolve_method_eager(um)))
305 /* patch interfacetable index */
307 ip[1] = (OFFSET(vftbl_t, interfacetable[0]) -
308 sizeof(methodptr*) * m->class->index);
310 /* patch methodinfo and method offset */
313 ip[2] = (sizeof(methodptr) * (m - m->class->methods));
319 /* patcher_checkcast_instanceof ************************************************
323 *******************************************************************************/
325 bool intrp_patcher_checkcast_instanceof(u1 *sp)
328 constant_classref *cr;
332 cr = (constant_classref *) ip[2];
334 /* get the classinfo */
336 if (!(c = resolve_classref_eager(cr)))
339 /* patch super class pointer */
347 /* patcher_resolve_native ******************************************************
351 *******************************************************************************/
353 #if !defined(WITH_STATIC_CLASSPATH)
354 bool intrp_patcher_resolve_native(u1 *sp)
361 m = (methodinfo *) ip[1];
363 /* resolve native function */
365 if (!(f = native_resolve_function(m)))
368 /* patch native function pointer */
374 #endif /* !defined(WITH_STATIC_CLASSPATH) */
378 * These are local overrides for various environment variables in Emacs.
379 * Please do not remove this and leave it at the end of the file, where
380 * Emacs will automagically detect them.
381 * ---------------------------------------------------------------------
384 * indent-tabs-mode: t
388 * vim:noexpandtab:sw=4:ts=4: