X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fvm%2Fjit%2Fi386%2Fpatcher.c;h=19b91971803a6c59d1c2f0a9f04dac19662a7e9d;hb=f24e856e3c43a10dcc8581fd5ddbdda200d63aba;hp=36c431f521bd3f9b6183b4f27d6a910927a4f361;hpb=9de3f75c2cd0248293937d66f04d6791e622d069;p=cacao.git diff --git a/src/vm/jit/i386/patcher.c b/src/vm/jit/i386/patcher.c index 36c431f52..19b919718 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 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. @@ -19,32 +17,53 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. - - Contact: cacao@complang.tuwien.ac.at - - Authors: Christian Thalinger - - Changes: - - $Id: patcher.c 3392 2005-10-10 13:40:11Z twisti $ + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. */ #include "config.h" + +#include + #include "vm/types.h" +#include "vm/jit/i386/codegen.h" +#include "vm/jit/i386/md.h" + #include "mm/memory.h" -#include "native/native.h" -#include "vm/builtin.h" -#include "vm/field.h" + +#include "native/native.hpp" + +#include "vm/jit/builtin.hpp" +#include "vm/class.h" +#include "vm/field.hpp" #include "vm/initialize.h" #include "vm/options.h" #include "vm/references.h" -#include "vm/jit/helper.h" -#include "vm/jit/patcher.h" +#include "vm/resolve.h" + +#include "vm/jit/patcher-common.hpp" + + +#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 ********************************************************** + + Just patches back the original machine code. + +*******************************************************************************/ + +void patcher_patch_code(patchref_t *pr) +{ + PATCH_BACK_ORIGINAL_MCODE; +} /* patcher_get_putstatic ******************************************************* @@ -56,61 +75,33 @@ *******************************************************************************/ -bool patcher_get_putstatic(u1 *sp) +bool patcher_get_putstatic(patchref_t *pr) { - u1 *ra; - java_objectheader *o; - u8 mcode; - unresolved_field *uf; - fieldinfo *fi; + u1 *ra; + unresolved_field *uf; + fieldinfo *fi; /* get stuff from the stack */ - ra = (u1 *) *((ptrint *) (sp + 4 * 4)); - o = (java_objectheader *) *((ptrint *) (sp + 3 * 4)); - mcode = *((u8 *) (sp + 1 * 4)); - uf = (unresolved_field *) *((ptrint *) (sp + 0 * 4)); - - /* calculate and set the new return address */ - - ra = ra - 5; - *((ptrint *) (sp + 4 * 4)) = (ptrint) ra; - - PATCHER_MONITORENTER; + ra = (u1 *) pr->mpc; + uf = (unresolved_field *) pr->ref; /* get the fieldinfo */ - if (!(fi = helper_resolve_fieldinfo(uf))) { - PATCHER_MONITOREXIT; - + if (!(fi = resolve_field_eager(uf))) return false; - } /* check if the field's class is initialized */ - if (!fi->class->initialized) { - if (!initialize_class(fi->class)) { - PATCHER_MONITOREXIT; - + if (!(fi->clazz->state & CLASS_INITIALIZED)) + if (!initialize_class(fi->clazz)) return false; - } - } - - /* patch back original code */ - *((u4 *) (ra + 0)) = (u4) mcode; - *((u1 *) (ra + 4)) = (u1) (mcode >> 32); - - /* if we show disassembly, we have to skip the nop's */ - - if (opt_showdisassemble) - ra = ra + 5; + PATCH_BACK_ORIGINAL_MCODE; /* patch the field value's address */ - *((ptrint *) (ra + 1)) = (ptrint) &(fi->value); - - PATCHER_MARK_PATCHED_MONITOREXIT; + *((intptr_t *) (ra + 1)) = (intptr_t) fi->value; return true; } @@ -125,45 +116,23 @@ bool patcher_get_putstatic(u1 *sp) *******************************************************************************/ -bool patcher_getfield(u1 *sp) +bool patcher_getfield(patchref_t *pr) { - u1 *ra; - java_objectheader *o; - u8 mcode; - unresolved_field *uf; - fieldinfo *fi; + u1 *ra; + unresolved_field *uf; + fieldinfo *fi; /* get stuff from the stack */ - ra = (u1 *) *((ptrint *) (sp + 4 * 4)); - o = (java_objectheader *) *((ptrint *) (sp + 3 * 4)); - mcode = *((u8 *) (sp + 1 * 4)); - uf = (unresolved_field *) *((ptrint *) (sp + 0 * 4)); - - /* calculate and set the new return address */ - - ra = ra - 5; - *((ptrint *) (sp + 4 * 4)) = (ptrint) ra; - - PATCHER_MONITORENTER; + ra = (u1 *) pr->mpc; + uf = (unresolved_field *) pr->ref; /* get the fieldinfo */ - if (!(fi = helper_resolve_fieldinfo(uf))) { - PATCHER_MONITOREXIT; - + if (!(fi = resolve_field_eager(uf))) return false; - } - - /* patch back original code */ - - *((u4 *) (ra + 0)) = (u4) mcode; - *((u1 *) (ra + 4)) = (u1) (mcode >> 32); - /* if we show disassembly, we have to skip the nop's */ - - if (opt_showdisassemble) - ra = ra + 5; + PATCH_BACK_ORIGINAL_MCODE; /* patch the field's offset */ @@ -174,8 +143,6 @@ bool patcher_getfield(u1 *sp) if (fi->type == TYPE_LNG) *((u4 *) (ra + 6 + 2)) = (u4) (fi->offset + 4); - PATCHER_MARK_PATCHED_MONITOREXIT; - return true; } @@ -189,66 +156,40 @@ bool patcher_getfield(u1 *sp) *******************************************************************************/ -bool patcher_putfield(u1 *sp) +bool patcher_putfield(patchref_t *pr) { - u1 *ra; - java_objectheader *o; - u8 mcode; - unresolved_field *uf; - fieldinfo *fi; + u1 *ra; + unresolved_field *uf; + fieldinfo *fi; /* get stuff from the stack */ - ra = (u1 *) *((ptrint *) (sp + 4 * 4)); - o = (java_objectheader *) *((ptrint *) (sp + 3 * 4)); - mcode = *((u8 *) (sp + 1 * 4)); - uf = (unresolved_field *) *((ptrint *) (sp + 0 * 4)); - - /* calculate and set the new return address */ - - ra = ra - 5; - *((ptrint *) (sp + 4 * 4)) = (ptrint) ra; - - PATCHER_MONITORENTER; + ra = (u1 *) pr->mpc; + uf = (unresolved_field *) pr->ref; /* get the fieldinfo */ - if (!(fi = helper_resolve_fieldinfo(uf))) { - PATCHER_MONITOREXIT; - + if (!(fi = resolve_field_eager(uf))) return false; - } - - /* patch back original code */ - - *((u4 *) (ra + 0)) = (u4) mcode; - *((u1 *) (ra + 4)) = (u1) (mcode >> 32); - - /* if we show disassembly, we have to skip the nop's */ - if (opt_showdisassemble) - ra = ra + 5; + PATCH_BACK_ORIGINAL_MCODE; /* patch the field's offset */ if (fi->type != TYPE_LNG) { *((u4 *) (ra + 2)) = (u4) (fi->offset); - - } else { - /* long code is very special: + } + else { + /* The long code is special: * - * 8b 8c 24 00 00 00 00 mov 0x00000000(%esp),%ecx - * 8b 94 24 00 00 00 00 mov 0x00000000(%esp),%edx * 89 8d 00 00 00 00 mov %ecx,0x00000000(%ebp) * 89 95 00 00 00 00 mov %edx,0x00000000(%ebp) */ - *((u4 *) (ra + 7 + 7 + 2)) = (u4) (fi->offset); - *((u4 *) (ra + 7 + 7 + 6 + 2)) = (u4) (fi->offset + 4); + *((u4 *) (ra + 2)) = (u4) (fi->offset); + *((u4 *) (ra + 6 + 2)) = (u4) (fi->offset + 4); } - PATCHER_MARK_PATCHED_MONITOREXIT; - return true; } @@ -262,193 +203,75 @@ bool patcher_putfield(u1 *sp) *******************************************************************************/ -bool patcher_putfieldconst(u1 *sp) +bool patcher_putfieldconst(patchref_t *pr) { - u1 *ra; - java_objectheader *o; - u8 mcode; - unresolved_field *uf; - fieldinfo *fi; + u1 *ra; + unresolved_field *uf; + fieldinfo *fi; /* get stuff from the stack */ - ra = (u1 *) *((ptrint *) (sp + 4 * 4)); - o = (java_objectheader *) *((ptrint *) (sp + 3 * 4)); - mcode = *((u8 *) (sp + 1 * 4)); - uf = (unresolved_field *) *((ptrint *) (sp + 0 * 4)); - - /* calculate and set the new return address */ - - ra = ra - 5; - *((ptrint *) (sp + 4 * 4)) = (ptrint) ra; - - PATCHER_MONITORENTER; + ra = (u1 *) pr->mpc; + uf = (unresolved_field *) pr->ref; /* get the fieldinfo */ - if (!(fi = helper_resolve_fieldinfo(uf))) { - PATCHER_MONITOREXIT; - + if (!(fi = resolve_field_eager(uf))) return false; - } - - /* patch back original code */ - - *((u4 *) (ra + 0)) = (u4) mcode; - *((u1 *) (ra + 4)) = (u1) (mcode >> 32); - /* if we show disassembly, we have to skip the nop's */ - - if (opt_showdisassemble) - ra = ra + 5; + PATCH_BACK_ORIGINAL_MCODE; /* patch the field's offset */ if (!IS_2_WORD_TYPE(fi->type)) { *((u4 *) (ra + 2)) = (u4) (fi->offset); - - } else { + } + else { /* long/double code is different: * * c7 80 00 00 00 00 c8 01 00 00 movl $0x1c8,0x0(%eax) * c7 80 04 00 00 00 00 00 00 00 movl $0x0,0x4(%eax) */ - *((u4 *) (ra + 2)) = (u4) (fi->offset); + *((u4 *) (ra + 2)) = (u4) (fi->offset); *((u4 *) (ra + 10 + 2)) = (u4) (fi->offset + 4); } - PATCHER_MARK_PATCHED_MONITOREXIT; - return true; } -/* patcher_builtin_new ********************************************************* +/* patcher_aconst ************************************************************** Machine code: + c7 04 24 00 00 00 00 movl $0x0000000,(%esp) - b8 00 00 00 00 mov $0x0000000,%eax - ff d0 call *%eax *******************************************************************************/ -bool patcher_builtin_new(u1 *sp) +bool patcher_aconst(patchref_t *pr) { u1 *ra; - java_objectheader *o; - u8 mcode; constant_classref *cr; classinfo *c; /* get stuff from the stack */ - ra = (u1 *) *((ptrint *) (sp + 4 * 4)); - o = (java_objectheader *) *((ptrint *) (sp + 3 * 4)); - mcode = *((u8 *) (sp + 1 * 4)); - cr = (constant_classref *) *((ptrint *) (sp + 0 * 4)); - - /* calculate and set the new return address */ - - ra = ra - (7 + 5); - *((ptrint *) (sp + 4 * 4)) = (ptrint) ra; - - PATCHER_MONITORENTER; + ra = (u1 *) pr->mpc; + cr = (constant_classref *) pr->ref; /* get the classinfo */ - if (!(c = helper_resolve_classinfo_nonabstract(cr))) { - PATCHER_MONITOREXIT; - + if (!(c = resolve_classref_eager(cr))) return false; - } - - /* patch back original code */ - *((u4 *) (ra + 7 + 0)) = (u4) mcode; - *((u1 *) (ra + 7 + 4)) = (u1) (mcode >> 32); + PATCH_BACK_ORIGINAL_MCODE; /* patch the classinfo pointer */ - *((ptrint *) (ra + 3)) = (ptrint) c; - - /* if we show disassembly, we have to skip the nop's */ - - if (opt_showdisassemble) - ra = ra + 5; - - /* patch new function address */ - - *((ptrint *) (ra + 7 + 1)) = (ptrint) BUILTIN_new; - - PATCHER_MARK_PATCHED_MONITOREXIT; - - return true; -} - - -/* patcher_builtin_newarray **************************************************** - - Machine code: - - c7 44 24 08 00 00 00 00 movl $0x00000000,0x8(%esp) - - b8 00 00 00 00 mov $0x00000000,%eax - ff d0 call *%eax - -*******************************************************************************/ - -bool patcher_builtin_newarray(u1 *sp) -{ - u1 *ra; - java_objectheader *o; - u8 mcode; - constant_classref *cr; - classinfo *c; - - /* get stuff from the stack */ - - ra = (u1 *) *((ptrint *) (sp + 4 * 4)); - o = (java_objectheader *) *((ptrint *) (sp + 3 * 4)); - mcode = *((u8 *) (sp + 1 * 4)); - cr = (constant_classref *) *((ptrint *) (sp + 0 * 4)); - - /* calculate and set the new return address */ - - ra = ra - (8 + 5); - *((ptrint *) (sp + 4 * 4)) = (ptrint) ra; - - PATCHER_MONITORENTER; - - /* get the classinfo */ - - if (!(c = helper_resolve_classinfo(cr))) { - PATCHER_MONITOREXIT; - - return false; - } - - /* patch back original code */ - - *((u4 *) (ra + 8 + 0)) = (u4) mcode; - *((u1 *) (ra + 8 + 4)) = (u1) (mcode >> 32); - - /* patch the class' vftbl pointer */ - - *((ptrint *) (ra + 4)) = (ptrint) c->vftbl; - - /* if we show disassembly, we have to skip the nop's */ - - if (opt_showdisassemble) - ra = ra + 5; - - /* patch new function address */ - - *((ptrint *) (ra + 8 + 1)) = (ptrint) BUILTIN_newarray; - - PATCHER_MARK_PATCHED_MONITOREXIT; + *((ptrint *) (ra + 1)) = (ptrint) c; return true; } @@ -469,55 +292,27 @@ bool patcher_builtin_newarray(u1 *sp) *******************************************************************************/ -bool patcher_builtin_multianewarray(u1 *sp) +bool patcher_builtin_multianewarray(patchref_t *pr) { u1 *ra; - java_objectheader *o; - u8 mcode; constant_classref *cr; classinfo *c; /* get stuff from the stack */ - ra = (u1 *) *((ptrint *) (sp + 4 * 4)); - o = (java_objectheader *) *((ptrint *) (sp + 3 * 4)); - mcode = *((u8 *) (sp + 1 * 4)); - cr = (constant_classref *) *((ptrint *) (sp + 0 * 4)); - - /* calculate and set the new return address */ - - ra = ra - 5; - *((ptrint *) (sp + 4 * 4)) = (ptrint) ra; - - PATCHER_MONITORENTER; + ra = (u1 *) pr->mpc; + cr = (constant_classref *) pr->ref; /* get the classinfo */ - if (!(c = helper_resolve_classinfo(cr))) { - PATCHER_MONITOREXIT; - + if (!(c = resolve_classref_eager(cr))) return false; - } - - /* patch back original code */ - - *((u4 *) (ra + 0)) = (u4) mcode; - *((u1 *) (ra + 4)) = (u1) (mcode >> 32); - - /* if we show disassembly, we have to skip the nop's */ - if (opt_showdisassemble) - ra = ra + 5; + PATCH_BACK_ORIGINAL_MCODE; - /* patch the class' vftbl pointer */ - - *((ptrint *) (ra + 7 + 4)) = (ptrint) c->vftbl; - - /* patch new function address */ - - *((ptrint *) (ra + 7 + 8 + 2 + 3 + 4 + 1)) = (ptrint) BUILTIN_multianewarray; + /* patch the classinfo pointer */ - PATCHER_MARK_PATCHED_MONITOREXIT; + *((ptrint *) (ra + 7 + 4)) = (ptrint) c; return true; } @@ -534,121 +329,32 @@ bool patcher_builtin_multianewarray(u1 *sp) *******************************************************************************/ -bool patcher_builtin_arraycheckcast(u1 *sp) +bool patcher_builtin_arraycheckcast(patchref_t *pr) { u1 *ra; - java_objectheader *o; - u8 mcode; constant_classref *cr; classinfo *c; /* get stuff from the stack */ - ra = (u1 *) *((ptrint *) (sp + 4 * 4)); - o = (java_objectheader *) *((ptrint *) (sp + 3 * 4)); - mcode = *((u8 *) (sp + 1 * 4)); - cr = (constant_classref *) *((ptrint *) (sp + 0 * 4)); - - /* calculate and set the new return address */ - - ra = ra - 5; - *((ptrint *) (sp + 4 * 4)) = (ptrint) ra; - - PATCHER_MONITORENTER; + ra = (u1 *) pr->mpc; + cr = (constant_classref *) pr->ref; /* get the classinfo */ - if (!(c = helper_resolve_classinfo(cr))) { - PATCHER_MONITOREXIT; - + if (!(c = resolve_classref_eager(cr))) return false; - } - - /* patch back original code */ - *((u4 *) (ra + 0)) = (u4) mcode; - *((u1 *) (ra + 4)) = (u1) (mcode >> 32); + PATCH_BACK_ORIGINAL_MCODE; - /* if we show disassembly, we have to skip the nop's */ - - if (opt_showdisassemble) - ra = ra + 5; - - /* patch the class' vftbl pointer */ + /* patch the classinfo pointer */ - *((ptrint *) (ra + 4)) = (ptrint) c->vftbl; + *((ptrint *) (ra + 4)) = (ptrint) c; /* patch new function address */ *((ptrint *) (ra + 8 + 1)) = (ptrint) BUILTIN_arraycheckcast; - PATCHER_MARK_PATCHED_MONITOREXIT; - - return true; -} - - -/* patcher_builtin_arrayinstanceof ********************************************* - - Machine code: - - c7 44 24 08 00 00 00 00 movl $0x00000000,0x8(%esp) - - b8 00 00 00 00 mov $0x00000000,%eax - ff d0 call *%eax - -*******************************************************************************/ - -bool patcher_builtin_arrayinstanceof(u1 *sp) -{ - u1 *ra; - java_objectheader *o; - u8 mcode; - constant_classref *cr; - classinfo *c; - - /* get stuff from the stack */ - - ra = (u1 *) *((ptrint *) (sp + 4 * 4)); - o = (java_objectheader *) *((ptrint *) (sp + 3 * 4)); - mcode = *((u8 *) (sp + 1 * 4)); - cr = (constant_classref *) *((ptrint *) (sp + 0 * 4)); - - /* calculate and set the new return address */ - - ra = ra - (8 + 5); - *((ptrint *) (sp + 4 * 4)) = (ptrint) ra; - - PATCHER_MONITORENTER; - - /* get the classinfo */ - - if (!(c = helper_resolve_classinfo(cr))) { - PATCHER_MONITOREXIT; - - return false; - } - - /* patch back original code */ - - *((u4 *) (ra + 8 + 0)) = (u4) mcode; - *((u1 *) (ra + 8 + 4)) = (u1) (mcode >> 32); - - /* patch the class' vftbl pointer */ - - *((ptrint *) (ra + 4)) = (ptrint) c->vftbl; - - /* if we show disassembly, we have to skip the nop's */ - - if (opt_showdisassemble) - ra = ra + 5; - - /* patch new function address */ - - *((ptrint *) (ra + 8 + 1)) = (ptrint) BUILTIN_arrayinstanceof; - - PATCHER_MARK_PATCHED_MONITOREXIT; - return true; } @@ -663,52 +369,28 @@ bool patcher_builtin_arrayinstanceof(u1 *sp) *******************************************************************************/ -bool patcher_invokestatic_special(u1 *sp) +bool patcher_invokestatic_special(patchref_t *pr) { u1 *ra; - java_objectheader *o; - u8 mcode; unresolved_method *um; methodinfo *m; /* get stuff from the stack */ - ra = (u1 *) *((ptrint *) (sp + 4 * 4)); - o = (java_objectheader *) *((ptrint *) (sp + 3 * 4)); - mcode = *((u8 *) (sp + 1 * 4)); - um = (unresolved_method *) *((ptrint *) (sp + 0 * 4)); + ra = (u1 *) pr->mpc; + um = (unresolved_method *) pr->ref; - /* calculate and set the new return address */ - - ra = ra - 5; - *((ptrint *) (sp + 4 * 4)) = (ptrint) ra; - - PATCHER_MONITORENTER; - - /* get the fieldinfo */ - - if (!(m = helper_resolve_methodinfo(um))) { - PATCHER_MONITOREXIT; + /* get the methodinfo */ + if (!(m = resolve_method_eager(um))) return false; - } - /* patch back original code */ - - *((u4 *) (ra + 0)) = (u4) mcode; - *((u1 *) (ra + 4)) = (u1) (mcode >> 32); - - /* if we show disassembly, we have to skip the nop's */ - - if (opt_showdisassemble) - ra = ra + 5; + PATCH_BACK_ORIGINAL_MCODE; /* patch stubroutine */ *((ptrint *) (ra + 1)) = (ptrint) m->stubroutine; - PATCHER_MARK_PATCHED_MONITOREXIT; - return true; } @@ -724,53 +406,29 @@ bool patcher_invokestatic_special(u1 *sp) *******************************************************************************/ -bool patcher_invokevirtual(u1 *sp) +bool patcher_invokevirtual(patchref_t *pr) { u1 *ra; - java_objectheader *o; - u8 mcode; unresolved_method *um; methodinfo *m; /* get stuff from the stack */ - ra = (u1 *) *((ptrint *) (sp + 4 * 4)); - o = (java_objectheader *) *((ptrint *) (sp + 3 * 4)); - mcode = *((u8 *) (sp + 1 * 4)); - um = (unresolved_method *) *((ptrint *) (sp + 0 * 4)); - - /* calculate and set the new return address */ - - ra = ra - 5; - *((ptrint *) (sp + 4 * 4)) = (ptrint) ra; - - PATCHER_MONITORENTER; + ra = (u1 *) pr->mpc; + um = (unresolved_method *) pr->ref; /* get the fieldinfo */ - if (!(m = helper_resolve_methodinfo(um))) { - PATCHER_MONITOREXIT; - + if (!(m = resolve_method_eager(um))) return false; - } - - /* patch back original code */ - - *((u4 *) (ra + 0)) = (u4) mcode; - *((u1 *) (ra + 4)) = (u1) (mcode >> 32); - /* if we show disassembly, we have to skip the nop's */ - - if (opt_showdisassemble) - ra = ra + 5; + PATCH_BACK_ORIGINAL_MCODE; /* patch vftbl index */ *((s4 *) (ra + 2 + 2)) = (s4) (OFFSET(vftbl_t, table[0]) + sizeof(methodptr) * m->vftblindex); - PATCHER_MARK_PATCHED_MONITOREXIT; - return true; } @@ -787,57 +445,33 @@ bool patcher_invokevirtual(u1 *sp) *******************************************************************************/ -bool patcher_invokeinterface(u1 *sp) +bool patcher_invokeinterface(patchref_t *pr) { u1 *ra; - java_objectheader *o; - u8 mcode; unresolved_method *um; methodinfo *m; /* get stuff from the stack */ - ra = (u1 *) *((ptrint *) (sp + 4 * 4)); - o = (java_objectheader *) *((ptrint *) (sp + 3 * 4)); - mcode = *((u8 *) (sp + 1 * 4)); - um = (unresolved_method *) *((ptrint *) (sp + 0 * 4)); - - /* calculate and set the new return address */ - - ra = ra - 5; - *((ptrint *) (sp + 4 * 4)) = (ptrint) ra; - - PATCHER_MONITORENTER; + ra = (u1 *) pr->mpc; + um = (unresolved_method *) pr->ref; /* get the fieldinfo */ - if (!(m = helper_resolve_methodinfo(um))) { - PATCHER_MONITOREXIT; - + if (!(m = resolve_method_eager(um))) return false; - } - - /* patch back original code */ - - *((u4 *) (ra + 0)) = (u4) mcode; - *((u1 *) (ra + 4)) = (u1) (mcode >> 32); - /* if we show disassembly, we have to skip the nop's */ - - if (opt_showdisassemble) - ra = ra + 5; + PATCH_BACK_ORIGINAL_MCODE; /* 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)); - - PATCHER_MARK_PATCHED_MONITOREXIT; + (s4) (sizeof(methodptr) * (m - m->clazz->methods)); return true; } @@ -852,57 +486,33 @@ bool patcher_invokeinterface(u1 *sp) *******************************************************************************/ -bool patcher_checkcast_instanceof_flags(u1 *sp) +bool patcher_checkcast_instanceof_flags(patchref_t *pr) { u1 *ra; - java_objectheader *o; - u8 mcode; constant_classref *cr; classinfo *c; /* get stuff from the stack */ - ra = (u1 *) *((ptrint *) (sp + 4 * 4)); - o = (java_objectheader *) *((ptrint *) (sp + 3 * 4)); - mcode = *((u8 *) (sp + 1 * 4)); - cr = (constant_classref *) *((ptrint *) (sp + 0 * 4)); - - /* calculate and set the new return address */ - - ra = ra - 5; - *((ptrint *) (sp + 4 * 4)) = (ptrint) ra; - - PATCHER_MONITORENTER; + ra = (u1 *) pr->mpc; + cr = (constant_classref *) pr->ref; /* get the fieldinfo */ - if (!(c = helper_resolve_classinfo(cr))) { - PATCHER_MONITOREXIT; - + if (!(c = resolve_classref_eager(cr))) return false; - } - - /* patch back original code */ - *((u4 *) (ra + 0)) = (u4) mcode; - *((u1 *) (ra + 4)) = (u1) (mcode >> 32); - - /* if we show disassembly, we have to skip the nop's */ - - if (opt_showdisassemble) - ra = ra + 5; + PATCH_BACK_ORIGINAL_MCODE; /* patch class flags */ *((s4 *) (ra + 1)) = (s4) c->flags; - PATCHER_MARK_PATCHED_MONITOREXIT; - return true; } -/* patcher_checkcast_instanceof_interface ************************************** +/* patcher_checkcast_interface ************************************************* Machine code: @@ -910,353 +520,161 @@ bool patcher_checkcast_instanceof_flags(u1 *sp) 8b 91 00 00 00 00 mov 0x00000000(%ecx),%edx 81 ea 00 00 00 00 sub $0x00000000,%edx 85 d2 test %edx,%edx - 0f 8e 00 00 00 00 jle 0x00000000 + 0f 8f 06 00 00 00 jg 0x00000000 + 8b 35 03 00 00 00 mov 0x3,%esi 8b 91 00 00 00 00 mov 0x00000000(%ecx),%edx *******************************************************************************/ -bool patcher_checkcast_instanceof_interface(u1 *sp) +bool patcher_checkcast_interface(patchref_t *pr) { u1 *ra; - java_objectheader *o; - u8 mcode; constant_classref *cr; classinfo *c; /* get stuff from the stack */ - ra = (u1 *) *((ptrint *) (sp + 4 * 4)); - o = (java_objectheader *) *((ptrint *) (sp + 3 * 4)); - mcode = *((u8 *) (sp + 1 * 4)); - cr = (constant_classref *) *((ptrint *) (sp + 0 * 4)); - - /* calculate and set the new return address */ - - ra = ra - 5; - *((ptrint *) (sp + 4 * 4)) = (ptrint) ra; - - PATCHER_MONITORENTER; + ra = (u1 *) pr->mpc; + cr = (constant_classref *) pr->ref; /* get the fieldinfo */ - if (!(c = helper_resolve_classinfo(cr))) { - PATCHER_MONITOREXIT; - + if (!(c = resolve_classref_eager(cr))) return false; - } - - /* patch back original code */ - - *((u4 *) (ra + 0)) = (u4) mcode; - *((u1 *) (ra + 4)) = (u1) (mcode >> 32); - - /* if we show disassembly, we have to skip the nop's */ - if (opt_showdisassemble) - ra = ra + 5; + PATCH_BACK_ORIGINAL_MCODE; /* patch super class index */ *((s4 *) (ra + 6 + 2)) = (s4) c->index; - *((s4 *) (ra + 6 + 6 + 2 + 6 + 2)) = + *((s4 *) (ra + 6 + 6 + 2 + 6 + 6 + 2)) = (s4) (OFFSET(vftbl_t, interfacetable[0]) - c->index * sizeof(methodptr*)); - PATCHER_MARK_PATCHED_MONITOREXIT; - return true; } -/* patcher_checkcast_class ***************************************************** +/* patcher_instanceof_interface ************************************************ Machine code: - ba 00 00 00 00 mov $0x00000000,%edx - 8b 89 00 00 00 00 mov 0x00000000(%ecx),%ecx - 8b 92 00 00 00 00 mov 0x00000000(%edx),%edx - 29 d1 sub %edx,%ecx - ba 00 00 00 00 mov $0x00000000,%edx + 8b 91 00 00 00 00 mov 0x00000000(%ecx),%edx + 81 ea 00 00 00 00 sub $0x00000000,%edx + 85 d2 test %edx,%edx + 0f 8e 13 00 00 00 jle 0x00000000 + 8b 91 00 00 00 00 mov 0x00000000(%ecx),%edx *******************************************************************************/ -bool patcher_checkcast_class(u1 *sp) +bool patcher_instanceof_interface(patchref_t *pr) { u1 *ra; - java_objectheader *o; - u8 mcode; constant_classref *cr; classinfo *c; /* get stuff from the stack */ - ra = (u1 *) *((ptrint *) (sp + 4 * 4)); - o = (java_objectheader *) *((ptrint *) (sp + 3 * 4)); - mcode = *((u8 *) (sp + 1 * 4)); - cr = (constant_classref *) *((ptrint *) (sp + 0 * 4)); - - /* calculate and set the new return address */ - - ra = ra - 5; - *((ptrint *) (sp + 4 * 4)) = (ptrint) ra; - - PATCHER_MONITORENTER; + ra = (u1 *) pr->mpc; + cr = (constant_classref *) pr->ref; /* get the fieldinfo */ - if (!(c = helper_resolve_classinfo(cr))) { - PATCHER_MONITOREXIT; - + if (!(c = resolve_classref_eager(cr))) return false; - } - - /* patch back original code */ - - *((u4 *) (ra + 0)) = (u4) mcode; - *((u1 *) (ra + 4)) = (u1) (mcode >> 32); - /* if we show disassembly, we have to skip the nop's */ + PATCH_BACK_ORIGINAL_MCODE; - if (opt_showdisassemble) - ra = ra + 5; - - /* patch super class' vftbl */ + /* patch super class index */ - *((ptrint *) (ra + 1)) = (ptrint) c->vftbl; - *((ptrint *) (ra + 5 + 6 + 6 + 2 + 1)) = (ptrint) c->vftbl; + *((s4 *) (ra + 6 + 2)) = (s4) c->index; - PATCHER_MARK_PATCHED_MONITOREXIT; + *((s4 *) (ra + 6 + 6 + 2 + 6 + 2)) = + (s4) (OFFSET(vftbl_t, interfacetable[0]) - + c->index * sizeof(methodptr*)); return true; } -/* patcher_instanceof_class **************************************************** +/* patcher_checkcast_class ***************************************************** Machine code: - b9 00 00 00 00 mov $0x0,%ecx - 8b 40 14 mov 0x14(%eax),%eax - 8b 51 18 mov 0x18(%ecx),%edx - 8b 49 14 mov 0x14(%ecx),%ecx + ba 00 00 00 00 mov $0x00000000,%edx + 8b 89 00 00 00 00 mov 0x00000000(%ecx),%ecx + 8b 92 00 00 00 00 mov 0x00000000(%edx),%edx + 29 d1 sub %edx,%ecx + ba 00 00 00 00 mov $0x00000000,%edx *******************************************************************************/ -bool patcher_instanceof_class(u1 *sp) +bool patcher_checkcast_class(patchref_t *pr) { u1 *ra; - java_objectheader *o; - u8 mcode; constant_classref *cr; classinfo *c; /* get stuff from the stack */ - ra = (u1 *) *((ptrint *) (sp + 4 * 4)); - o = (java_objectheader *) *((ptrint *) (sp + 3 * 4)); - mcode = *((u8 *) (sp + 1 * 4)); - cr = (constant_classref *) *((ptrint *) (sp + 0 * 4)); - - /* calculate and set the new return address */ - - ra = ra - 5; - *((ptrint *) (sp + 4 * 4)) = (ptrint) ra; - - PATCHER_MONITORENTER; + ra = (u1 *) pr->mpc; + cr = (constant_classref *) pr->ref; /* get the fieldinfo */ - if (!(c = helper_resolve_classinfo(cr))) { - PATCHER_MONITOREXIT; - + if (!(c = resolve_classref_eager(cr))) return false; - } - /* patch back original code */ - - *((u4 *) (ra + 0)) = (u4) mcode; - *((u1 *) (ra + 4)) = (u1) (mcode >> 32); - - /* if we show disassembly, we have to skip the nop's */ - - if (opt_showdisassemble) - ra = ra + 5; + PATCH_BACK_ORIGINAL_MCODE; /* patch super class' vftbl */ *((ptrint *) (ra + 1)) = (ptrint) c->vftbl; - - PATCHER_MARK_PATCHED_MONITOREXIT; - - return true; -} - - -/* patcher_clinit ************************************************************** - - Is used int PUT/GETSTATIC and native stub. - - Machine code: - - - -*******************************************************************************/ - -bool patcher_clinit(u1 *sp) -{ - u1 *ra; - java_objectheader *o; - u8 mcode; - classinfo *c; - - /* get stuff from the stack */ - - ra = (u1 *) *((ptrint *) (sp + 4 * 4)); - o = (java_objectheader *) *((ptrint *) (sp + 3 * 4)); - mcode = *((u8 *) (sp + 1 * 4)); - c = (classinfo *) *((ptrint *) (sp + 0 * 4)); - - /* calculate and set the new return address */ - - ra = ra - 5; - *((ptrint *) (sp + 4 * 4)) = (ptrint) ra; - - PATCHER_MONITORENTER; - - /* check if the class is initialized */ - - if (!c->initialized) { - if (!initialize_class(c)) { - PATCHER_MONITOREXIT; - - return false; - } - } - - /* patch back original code */ - - *((u4 *) (ra + 0)) = (u4) mcode; - *((u1 *) (ra + 4)) = (u1) (mcode >> 32); - - PATCHER_MARK_PATCHED_MONITOREXIT; + *((ptrint *) (ra + 5 + 6 + 6 + 2 + 1)) = (ptrint) c->vftbl; return true; } -/* patcher_athrow_areturn ****************************************************** +/* patcher_instanceof_class **************************************************** Machine code: + b9 00 00 00 00 mov $0x0,%ecx + 8b 40 14 mov 0x14(%eax),%eax + 8b 51 18 mov 0x18(%ecx),%edx + 8b 49 14 mov 0x14(%ecx),%ecx *******************************************************************************/ -bool patcher_athrow_areturn(u1 *sp) +bool patcher_instanceof_class(patchref_t *pr) { u1 *ra; - java_objectheader *o; - u8 mcode; - unresolved_class *uc; + constant_classref *cr; classinfo *c; /* get stuff from the stack */ - ra = (u1 *) *((ptrint *) (sp + 4 * 4)); - o = (java_objectheader *) *((ptrint *) (sp + 3 * 4)); - mcode = *((u8 *) (sp + 1 * 4)); - uc = (unresolved_class *) *((ptrint *) (sp + 0 * 4)); - - /* calculate and set the new return address */ - - ra = ra - 5; - *((ptrint *) (sp + 4 * 4)) = (ptrint) ra; - - PATCHER_MONITORENTER; - - /* resolve the class */ - - if (!resolve_class(uc, resolveEager, false, &c)) { - PATCHER_MONITOREXIT; - - return false; - } - - /* patch back original code */ - - *((u4 *) (ra + 0)) = (u4) mcode; - *((u1 *) (ra + 4)) = (u1) (mcode >> 32); - - PATCHER_MARK_PATCHED_MONITOREXIT; - - return true; -} - - -/* patcher_resolve_native ****************************************************** - - Is used in native stub. - - Machine code: - - - c7 44 24 04 28 90 01 40 movl $0x40019028,0x4(%esp) - -*******************************************************************************/ - -#if !defined(ENABLE_STATICVM) -bool patcher_resolve_native(u1 *sp) -{ - u1 *ra; - java_objectheader *o; - u8 mcode; - methodinfo *m; - functionptr f; - - /* get stuff from the stack */ - - ra = (u1 *) *((ptrint *) (sp + 4 * 4)); - o = (java_objectheader *) *((ptrint *) (sp + 3 * 4)); - mcode = *((u8 *) (sp + 1 * 4)); - m = (methodinfo *) *((ptrint *) (sp + 0 * 4)); - - /* calculate and set the new return address */ + ra = (u1 *) pr->mpc; + cr = (constant_classref *) pr->ref; - ra = ra - 5; - *((ptrint *) (sp + 4 * 4)) = (ptrint) ra; - - PATCHER_MONITORENTER; - - /* resolve native function */ - - if (!(f = native_resolve_function(m))) { - PATCHER_MONITOREXIT; + /* get the fieldinfo */ + if (!(c = resolve_classref_eager(cr))) return false; - } - - /* patch back original code */ - *((u4 *) (ra + 0)) = (u4) mcode; - *((u1 *) (ra + 4)) = (u1) (mcode >> 32); + PATCH_BACK_ORIGINAL_MCODE; - /* if we show disassembly, we have to skip the nop's */ - - if (opt_showdisassemble) - ra = ra + 5; - - /* patch native function pointer */ - - *((ptrint *) (ra + 4)) = (ptrint) f; + /* patch super class' vftbl */ - PATCHER_MARK_PATCHED_MONITOREXIT; + *((ptrint *) (ra + 1)) = (ptrint) c->vftbl; return true; } -#endif /* !defined(ENABLE_STATICVM) */ /*