X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=src%2Fvm%2Fjit%2Fi386%2Fpatcher.c;h=fb04b86c4e1e2ac8a88bad0f5f35d963862e2383;hb=8c6bb03b79a31fcdb02e2331a91a928d558c2845;hp=75f7f1c10b4206b048e65013032952b9d395e81d;hpb=7398e58348d86cd22f5b8a995bb1f7a0e5b1c6cf;p=cacao.git diff --git a/src/vm/jit/i386/patcher.c b/src/vm/jit/i386/patcher.c index 75f7f1c10..fb04b86c4 100644 --- a/src/vm/jit/i386/patcher.c +++ b/src/vm/jit/i386/patcher.c @@ -1,9 +1,7 @@ /* src/vm/jit/i386/patcher.c - i386 code patching functions - Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel, - C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring, - E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, - J. Wenninger, Institut f. Computersprachen - TU Wien + Copyright (C) 1996-2005, 2006, 2007, 2008 + CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO This file is part of CACAO. @@ -32,26 +30,28 @@ #include "vm/types.h" #include "vm/jit/i386/codegen.h" +#include "vm/jit/i386/md.h" -#include "mm/memory.h" +#include "mm/memory.hpp" -#include "native/native.h" +#include "native/native.hpp" -#include "vm/builtin.h" -#include "vm/exceptions.h" -#include "vm/initialize.h" +#include "vm/jit/builtin.hpp" +#include "vm/class.hpp" +#include "vm/field.hpp" +#include "vm/initialize.hpp" +#include "vm/options.h" +#include "vm/references.h" +#include "vm/resolve.hpp" -#include "vm/jit/patcher-common.h" -#include "vm/jit/stacktrace.h" +#include "vm/jit/patcher-common.hpp" -#include "vmcore/class.h" -#include "vmcore/field.h" -#include "vmcore/options.h" -#include "vm/resolve.h" -#include "vmcore/references.h" - -#define PATCH_BACK_ORIGINAL_MCODE *((u2 *) pr->mpc) = (u2) pr->mcode +#define PATCH_BACK_ORIGINAL_MCODE \ + do { \ + *((uint16_t*) pr->mpc) = (uint16_t) pr->mcode; \ + md_icacheflush((void*) pr->mpc, PATCHER_CALL_SIZE); \ + } while (0) /* patcher_patch_code ********************************************************** @@ -93,17 +93,12 @@ bool patcher_get_putstatic(patchref_t *pr) /* check if the field's class is initialized */ - if (!(fi->class->state & CLASS_INITIALIZED)) - if (!initialize_class(fi->class)) + if (!(fi->clazz->state & CLASS_INITIALIZED)) + if (!initialize_class(fi->clazz)) return false; PATCH_BACK_ORIGINAL_MCODE; - /* if we show disassembly, we have to skip the nop's */ - - if (opt_shownops) - ra = ra + PATCHER_CALL_SIZE; - /* patch the field value's address */ *((intptr_t *) (ra + 1)) = (intptr_t) fi->value; @@ -139,11 +134,6 @@ bool patcher_getfield(patchref_t *pr) PATCH_BACK_ORIGINAL_MCODE; - /* if we show disassembly, we have to skip the nop's */ - - if (opt_shownops) - ra = ra + PATCHER_CALL_SIZE; - /* patch the field's offset */ *((u4 *) (ra + 2)) = (u4) (fi->offset); @@ -184,11 +174,6 @@ bool patcher_putfield(patchref_t *pr) PATCH_BACK_ORIGINAL_MCODE; - /* if we show disassembly, we have to skip the nop's */ - - if (opt_shownops) - ra = ra + PATCHER_CALL_SIZE; - /* patch the field's offset */ if (fi->type != TYPE_LNG) { @@ -236,11 +221,6 @@ bool patcher_putfieldconst(patchref_t *pr) PATCH_BACK_ORIGINAL_MCODE; - /* if we show disassembly, we have to skip the nop's */ - - if (opt_shownops) - ra = ra + PATCHER_CALL_SIZE; - /* patch the field's offset */ if (!IS_2_WORD_TYPE(fi->type)) { @@ -289,11 +269,6 @@ bool patcher_aconst(patchref_t *pr) PATCH_BACK_ORIGINAL_MCODE; - /* if we show disassembly, we have to skip the nop's */ - - if (opt_shownops) - ra = ra + PATCHER_CALL_SIZE; - /* patch the classinfo pointer */ *((ptrint *) (ra + 1)) = (ptrint) c; @@ -335,11 +310,6 @@ bool patcher_builtin_multianewarray(patchref_t *pr) PATCH_BACK_ORIGINAL_MCODE; - /* if we show disassembly, we have to skip the nop's */ - - if (opt_shownops) - ra = ra + PATCHER_CALL_SIZE; - /* patch the classinfo pointer */ *((ptrint *) (ra + 7 + 4)) = (ptrint) c; @@ -377,11 +347,6 @@ bool patcher_builtin_arraycheckcast(patchref_t *pr) PATCH_BACK_ORIGINAL_MCODE; - /* if we show disassembly, we have to skip the nop's */ - - if (opt_shownops) - ra = ra + PATCHER_CALL_SIZE; - /* patch the classinfo pointer */ *((ptrint *) (ra + 4)) = (ptrint) c; @@ -422,11 +387,6 @@ bool patcher_invokestatic_special(patchref_t *pr) PATCH_BACK_ORIGINAL_MCODE; - /* if we show disassembly, we have to skip the nop's */ - - if (opt_shownops) - ra = ra + PATCHER_CALL_SIZE; - /* patch stubroutine */ *((ptrint *) (ra + 1)) = (ptrint) m->stubroutine; @@ -464,11 +424,6 @@ bool patcher_invokevirtual(patchref_t *pr) PATCH_BACK_ORIGINAL_MCODE; - /* if we show disassembly, we have to skip the nop's */ - - if (opt_shownops) - ra = ra + PATCHER_CALL_SIZE; - /* patch vftbl index */ *((s4 *) (ra + 2 + 2)) = (s4) (OFFSET(vftbl_t, table[0]) + @@ -508,20 +463,15 @@ bool patcher_invokeinterface(patchref_t *pr) PATCH_BACK_ORIGINAL_MCODE; - /* if we show disassembly, we have to skip the nop's */ - - if (opt_shownops) - ra = ra + PATCHER_CALL_SIZE; - /* patch interfacetable index */ *((s4 *) (ra + 2 + 2)) = (s4) (OFFSET(vftbl_t, interfacetable[0]) - - sizeof(methodptr) * m->class->index); + sizeof(methodptr) * m->clazz->index); /* patch method offset */ *((s4 *) (ra + 2 + 6 + 2)) = - (s4) (sizeof(methodptr) * (m - m->class->methods)); + (s4) (sizeof(methodptr) * (m - m->clazz->methods)); return true; } @@ -554,11 +504,6 @@ bool patcher_checkcast_instanceof_flags(patchref_t *pr) PATCH_BACK_ORIGINAL_MCODE; - /* if we show disassembly, we have to skip the nop's */ - - if (opt_shownops) - ra = ra + PATCHER_CALL_SIZE; - /* patch class flags */ *((s4 *) (ra + 1)) = (s4) c->flags; @@ -599,11 +544,6 @@ bool patcher_checkcast_interface(patchref_t *pr) PATCH_BACK_ORIGINAL_MCODE; - /* if we show disassembly, we have to skip the nop's */ - - if (opt_shownops) - ra = ra + PATCHER_CALL_SIZE; - /* patch super class index */ *((s4 *) (ra + 6 + 2)) = (s4) c->index; @@ -647,11 +587,6 @@ bool patcher_instanceof_interface(patchref_t *pr) PATCH_BACK_ORIGINAL_MCODE; - /* if we show disassembly, we have to skip the nop's */ - - if (opt_shownops) - ra = ra + PATCHER_CALL_SIZE; - /* patch super class index */ *((s4 *) (ra + 6 + 2)) = (s4) c->index; @@ -695,15 +630,9 @@ bool patcher_checkcast_class(patchref_t *pr) PATCH_BACK_ORIGINAL_MCODE; - /* if we show disassembly, we have to skip the nop's */ - - if (opt_shownops) - ra = ra + PATCHER_CALL_SIZE; - /* patch super class' vftbl */ *((ptrint *) (ra + 1)) = (ptrint) c->vftbl; - *((ptrint *) (ra + 5 + 6 + 6 + 2 + 1)) = (ptrint) c->vftbl; return true; } @@ -739,11 +668,6 @@ bool patcher_instanceof_class(patchref_t *pr) PATCH_BACK_ORIGINAL_MCODE; - /* if we show disassembly, we have to skip the nop's */ - - if (opt_shownops) - ra = ra + PATCHER_CALL_SIZE; - /* patch super class' vftbl */ *((ptrint *) (ra + 1)) = (ptrint) c->vftbl; @@ -752,48 +676,6 @@ bool patcher_instanceof_class(patchref_t *pr) } -/* patcher_resolve_native_function ********************************************* - - Is used in native stub. - - Machine code: - - - c7 44 24 04 28 90 01 40 movl $0x40019028,0x4(%esp) - -*******************************************************************************/ - -bool patcher_resolve_native_function(patchref_t *pr) -{ - u1 *ra; - methodinfo *m; - functionptr f; - - /* get stuff from the stack */ - - ra = (u1 *) pr->mpc; - m = (methodinfo *) pr->ref; - - /* resolve native function */ - - if (!(f = native_resolve_function(m))) - return false; - - PATCH_BACK_ORIGINAL_MCODE; - - /* if we show disassembly, we have to skip the nop's */ - - if (opt_shownops) - ra = ra + PATCHER_CALL_SIZE; - - /* patch native function pointer */ - - *((ptrint *) (ra + 4)) = (ptrint) f; - - return true; -} - - /* * These are local overrides for various environment variables in Emacs. * Please do not remove this and leave it at the end of the file, where