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 3245 2005-09-21 14:59:08Z twisti $
39 #include "mm/memory.h"
40 #include "native/native.h"
41 #include "vm/builtin.h"
43 #include "vm/initialize.h"
44 #include "vm/options.h"
45 #include "vm/references.h"
46 #include "vm/jit/asmpart.h"
47 #include "vm/jit/helper.h"
48 #include "vm/jit/patcher.h"
51 /* patcher_get_putstatic *******************************************************
55 *******************************************************************************/
57 bool patcher_get_putstatic(u1 *sp)
64 uf = (unresolved_field *) ip[2];
66 /* get the fieldinfo */
68 if (!(fi = helper_resolve_fieldinfo(uf))) {
72 /* check if the field's class is initialized */
74 if (!fi->class->initialized) {
75 if (!initialize_class(fi->class)) {
80 /* patch the field's address */
82 ip[1] = (ptrint) &(fi->value);
88 /* patcher_get_putfield ********************************************************
92 *******************************************************************************/
94 bool patcher_get_putfield(u1 *sp)
101 uf = (unresolved_field *) ip[2];
103 /* get the fieldinfo */
105 if (!(fi = helper_resolve_fieldinfo(uf))) {
109 /* patch the field's offset */
117 /* patcher_builtin_new *********************************************************
121 *******************************************************************************/
123 bool patcher_builtin_new(u1 *sp)
126 constant_classref *cr;
130 cr = (constant_classref *) ip[-1];
132 /* get the classinfo */
134 if (!(c = helper_resolve_classinfo(cr))) {
138 /* intialize the class */
140 if (!initialize_class(c)) {
144 /* patch the classinfo pointer */
152 /* patcher_builtin_newarray ****************************************************
156 INFO: This one is also used for arrayinstanceof!
158 *******************************************************************************/
160 bool patcher_builtin_newarray(u1 *sp)
163 constant_classref *cr;
167 cr = (constant_classref *) ip[-1];
169 /* get the classinfo */
171 if (!(c = helper_resolve_classinfo(cr))) {
175 /* patch the class' vftbl pointer */
177 ip[1] = (ptrint) c->vftbl;
183 bool patcher_builtin_arrayinstanceof(u1 *sp)
185 return patcher_builtin_newarray(sp);
189 /* patcher_builtin_multianewarray **********************************************
193 *******************************************************************************/
195 bool patcher_builtin_multianewarray(u1 *sp)
198 constant_classref *cr;
202 cr = (constant_classref *) ip[3];
204 /* get the classinfo */
206 if (!(c = helper_resolve_classinfo(cr))) {
210 /* patch the class' vftbl pointer */
212 ip[1] = (ptrint) c->vftbl;
218 /* patcher_builtin_arraycheckcast **********************************************
222 *******************************************************************************/
224 bool patcher_builtin_arraycheckcast(u1 *sp)
227 constant_classref *cr;
231 cr = (constant_classref *) ip[2];
233 /* get the classinfo */
235 if (!(c = helper_resolve_classinfo(cr))) {
239 /* patch the class' vftbl pointer */
241 ip[1] = (ptrint) c->vftbl;
247 /* patcher_invokestatic_special ************************************************
251 ******************************************************************************/
253 bool patcher_invokestatic_special(u1 *sp)
256 unresolved_method *um;
260 um = (unresolved_method *) ip[3];
262 /* get the fieldinfo */
264 if (!(m = helper_resolve_methodinfo(um))) {
268 /* patch stubroutine */
270 ip[1] = (ptrint) m->stubroutine;
276 /* patcher_invokevirtual *******************************************************
280 *******************************************************************************/
282 bool patcher_invokevirtual(u1 *sp)
285 unresolved_method *um;
289 um = (unresolved_method *) ip[3];
291 /* get the fieldinfo */
293 if (!(m = helper_resolve_methodinfo(um))) {
297 /* patch vftbl index */
299 ip[1] = (OFFSET(vftbl_t, table[0]) + sizeof(methodptr) * m->vftblindex);
305 /* patcher_invokeinterface *****************************************************
309 *******************************************************************************/
311 bool patcher_invokeinterface(u1 *sp)
314 unresolved_method *um;
318 um = (unresolved_method *) ip[4];
320 /* get the methodinfo */
322 if (!(m = helper_resolve_methodinfo(um))) {
326 /* patch interfacetable index */
328 ip[1] = (OFFSET(vftbl_t, interfacetable[0]) -
329 sizeof(methodptr*) * m->class->index);
331 /* patch method offset */
333 ip[2] = (sizeof(methodptr) * (m - m->class->methods));
339 /* patcher_checkcast_instanceof ************************************************
343 *******************************************************************************/
345 bool patcher_checkcast_instanceof(u1 *sp)
348 constant_classref *cr;
352 cr = (constant_classref *) ip[2];
354 /* get the classinfo */
356 if (!(c = helper_resolve_classinfo(cr))) {
360 /* patch super class pointer */
368 /* patcher_resolve_native ******************************************************
372 *******************************************************************************/
374 #if !defined(ENABLE_STATICVM)
375 bool patcher_resolve_native(u1 *sp)
382 m = (methodinfo *) ip[1];
384 /* resolve native function */
386 if (!(f = native_resolve_function(m))) {
390 /* patch native function pointer */
396 #endif /* !defined(ENABLE_STATICVM) */
400 * These are local overrides for various environment variables in Emacs.
401 * Please do not remove this and leave it at the end of the file, where
402 * Emacs will automagically detect them.
403 * ---------------------------------------------------------------------
406 * indent-tabs-mode: t
410 * vim:noexpandtab:sw=4:ts=4: