1 /* src/vm/jit/intrp/patcher.c - Interpreter code patching functions
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
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., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Christian Thalinger
31 $Id: patcher.c 3176 2005-09-14 08:51:23Z twisti $
36 #include "vm/jit/intrp/types.h"
38 #include "mm/memory.h"
39 #include "native/native.h"
40 #include "vm/builtin.h"
42 #include "vm/initialize.h"
43 #include "vm/options.h"
44 #include "vm/references.h"
45 #include "vm/jit/asmpart.h"
46 #include "vm/jit/helper.h"
47 #include "vm/jit/patcher.h"
50 /* patcher_get_putstatic *******************************************************
54 *******************************************************************************/
56 bool patcher_get_putstatic(u1 *sp)
63 uf = (unresolved_field *) ip[2];
65 /* get the fieldinfo */
67 if (!(fi = helper_resolve_fieldinfo(uf))) {
71 /* check if the field's class is initialized */
73 if (!fi->class->initialized) {
74 if (!initialize_class(fi->class)) {
79 /* patch the field's address */
81 ip[1] = (ptrint) &(fi->value);
87 /* patcher_get_putfield ********************************************************
91 *******************************************************************************/
93 bool patcher_get_putfield(u1 *sp)
100 uf = (unresolved_field *) ip[2];
102 /* get the fieldinfo */
104 if (!(fi = helper_resolve_fieldinfo(uf))) {
108 /* patch the field's offset */
116 /* patcher_builtin_new *********************************************************
120 *******************************************************************************/
122 bool patcher_builtin_new(u1 *sp)
125 constant_classref *cr;
129 cr = (constant_classref *) ip[-1];
131 /* get the classinfo */
133 if (!(c = helper_resolve_classinfo(cr))) {
137 /* intialize the class */
139 if (!initialize_class(c)) {
143 /* patch the classinfo pointer */
151 /* patcher_builtin_newarray ****************************************************
155 INFO: This one is also used for arrayinstanceof!
157 *******************************************************************************/
159 bool patcher_builtin_newarray(u1 *sp)
162 constant_classref *cr;
166 cr = (constant_classref *) ip[-1];
168 /* get the classinfo */
170 if (!(c = helper_resolve_classinfo(cr))) {
174 /* patch the class' vftbl pointer */
176 ip[1] = (ptrint) c->vftbl;
182 bool patcher_builtin_arrayinstanceof(u1 *sp)
184 return patcher_builtin_newarray(sp);
188 /* patcher_builtin_multianewarray **********************************************
192 *******************************************************************************/
194 bool patcher_builtin_multianewarray(u1 *sp)
197 constant_classref *cr;
201 cr = (constant_classref *) ip[3];
203 /* get the classinfo */
205 if (!(c = helper_resolve_classinfo(cr))) {
209 /* patch the class' vftbl pointer */
211 ip[1] = (ptrint) c->vftbl;
217 /* patcher_builtin_arraycheckcast **********************************************
221 *******************************************************************************/
223 bool patcher_builtin_arraycheckcast(u1 *sp)
226 constant_classref *cr;
230 cr = (constant_classref *) ip[2];
232 /* get the classinfo */
234 if (!(c = helper_resolve_classinfo(cr))) {
238 /* patch the class' vftbl pointer */
240 ip[1] = (ptrint) c->vftbl;
246 /* patcher_invokestatic_special ************************************************
250 ******************************************************************************/
252 bool patcher_invokestatic_special(u1 *sp)
255 unresolved_method *um;
259 um = (unresolved_method *) ip[3];
261 /* get the fieldinfo */
263 if (!(m = helper_resolve_methodinfo(um))) {
267 /* patch stubroutine */
269 ip[1] = (ptrint) m->stubroutine;
275 /* patcher_invokevirtual *******************************************************
279 *******************************************************************************/
281 bool patcher_invokevirtual(u1 *sp)
284 unresolved_method *um;
288 um = (unresolved_method *) ip[3];
290 /* get the fieldinfo */
292 if (!(m = helper_resolve_methodinfo(um))) {
296 /* patch vftbl index */
298 ip[1] = (OFFSET(vftbl_t, table[0]) + sizeof(methodptr) * m->vftblindex);
304 /* patcher_invokeinterface *****************************************************
308 *******************************************************************************/
310 bool patcher_invokeinterface(u1 *sp)
313 unresolved_method *um;
317 um = (unresolved_method *) ip[4];
319 /* get the methodinfo */
321 if (!(m = helper_resolve_methodinfo(um))) {
325 /* patch interfacetable index */
327 ip[1] = (OFFSET(vftbl_t, interfacetable[0]) -
328 sizeof(methodptr*) * m->class->index);
330 /* patch method offset */
332 ip[2] = (sizeof(methodptr) * (m - m->class->methods));
338 /* patcher_checkcast_instanceof ************************************************
342 *******************************************************************************/
344 bool patcher_checkcast_instanceof(u1 *sp)
347 constant_classref *cr;
351 cr = (constant_classref *) ip[2];
353 /* get the classinfo */
355 if (!(c = helper_resolve_classinfo(cr))) {
359 /* patch super class pointer */
367 /* patcher_resolve_native ******************************************************
371 *******************************************************************************/
373 #if !defined(ENABLE_STATICVM)
374 bool patcher_resolve_native(u1 *sp)
381 m = (methodinfo *) ip[1];
383 /* resolve native function */
385 if (!(f = native_resolve_function(m))) {
389 /* patch native function pointer */
395 #endif /* !defined(ENABLE_STATICVM) */
399 * These are local overrides for various environment variables in Emacs.
400 * Please do not remove this and leave it at the end of the file, where
401 * Emacs will automagically detect them.
402 * ---------------------------------------------------------------------
405 * indent-tabs-mode: t
409 * vim:noexpandtab:sw=4:ts=4: