/* src/vm/jit/alpha/patcher.c - Alpha 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 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
This file is part of CACAO.
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.
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
- Contact: cacao@complang.tuwien.ac.at
+ Contact: cacao@cacaojvm.org
Authors: Christian Thalinger
Changes:
- $Id: patcher.c 3463 2005-10-20 10:07:16Z edwin $
+ $Id: patcher.c 5290 2006-09-04 17:12:48Z christian $
*/
#include "config.h"
+
+#include <assert.h>
+
#include "vm/types.h"
#include "mm/memory.h"
#include "native/native.h"
#include "vm/builtin.h"
+#include "vm/class.h"
+#include "vm/exceptions.h"
#include "vm/field.h"
#include "vm/initialize.h"
#include "vm/options.h"
#include "vm/references.h"
+#include "vm/resolve.h"
#include "vm/jit/asmpart.h"
#include "vm/jit/patcher.h"
+#include "vm/jit/methodheader.h"
-/* patcher_get_putstatic *******************************************************
+/* patcher_wrapper *************************************************************
- Machine code:
+ Wrapper for all patchers. It also creates the stackframe info
+ structure.
- <patched call position>
- a73bff98 ldq t11,-104(pv)
- a2590000 ldl a2,0(t11)
+ If the return value of the patcher function is false, it gets the
+ exception object, clears the exception pointer and returns the
+ exception.
*******************************************************************************/
-bool patcher_get_putstatic(u1 *sp)
+java_objectheader *patcher_wrapper(u1 *sp, u1 *pv, u1 *ra)
{
- u1 *ra;
+ stackframeinfo sfi;
+ u1 *xpc;
java_objectheader *o;
u4 mcode;
- unresolved_field *uf;
- s4 disp;
- u1 *pv;
- fieldinfo *fi;
+ functionptr f;
+ bool result;
+ java_objectheader *e;
+
+ /* define the patcher function */
+
+ bool (*patcher_function)(u1 *);
+
+ assert(pv != NULL);
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
+ xpc = (u1 *) *((ptrint *) (sp + 5 * 8));
o = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
- mcode = *((u4 *) (sp + 3 * 8));
- uf = (unresolved_field *) *((ptrint *) (sp + 2 * 8));
- disp = *((s4 *) (sp + 1 * 8));
- pv = (u1 *) *((ptrint *) (sp + 0 * 8));
+ f = (functionptr) *((ptrint *) (sp + 0 * 8));
/* calculate and set the new return address */
- ra = ra - 1 * 4;
- *((ptrint *) (sp + 5 * 8)) = (ptrint) ra;
+ xpc = xpc - 1 * 4;
+
+ *((ptrint *) (sp + 5 * 8)) = (ptrint) xpc;
+
+ /* store PV into the patcher function position */
+
+ *((ptrint *) (sp + 0 * 8)) = (ptrint) pv;
+
+ /* cast the passed function to a patcher function */
+
+ patcher_function = (bool (*)(u1 *)) (ptrint) f;
+
+ /* enter a monitor on the patching position */
PATCHER_MONITORENTER;
- /* get the fieldinfo */
+ /* create the stackframeinfo */
- if (!(fi = resolve_field_eager(uf))) {
- PATCHER_MONITOREXIT;
+ stacktrace_create_extern_stackframeinfo(&sfi, pv, sp + 6 * 8, ra, xpc);
- return false;
- }
+ /* call the proper patcher function */
- /* check if the field's class is initialized */
+ result = (patcher_function)(sp);
- if (!fi->class->initialized) {
- if (!initialize_class(fi->class)) {
- PATCHER_MONITOREXIT;
+ /* remove the stackframeinfo */
- return false;
- }
+ stacktrace_remove_stackframeinfo(&sfi);
+
+ /* check for an error, get the exception and return it */
+
+ if (result == false) {
+ e = exceptions_get_and_clear_exception();
+
+ PATCHER_MONITOREXIT;
+
+ return e;
}
/* patch back original code */
- *((u4 *) ra) = mcode;
-
- /* synchronize instruction cache */
+ mcode = *((u4 *) (sp + 3 * 8));
- asm_sync_instruction_cache();
+ *((u4 *) xpc) = mcode;
- /* patch the field value's address */
+ /* synchronize instruction cache */
- *((ptrint *) (pv + disp)) = (ptrint) &(fi->value);
+ md_icacheflush(NULL, 0);
PATCHER_MARK_PATCHED_MONITOREXIT;
- return true;
+ return NULL;
}
+/* patcher_initialize_class ****************************************************
-/* patcher_get_putfield ********************************************************
-
- Machine code:
-
- <patched call position>
- a2af0020 ldl a5,32(s6)
+ Initalizes a given classinfo pointer. This function does not patch
+ any data.
*******************************************************************************/
-bool patcher_get_putfield(u1 *sp)
+bool patcher_initialize_class(u1 *sp)
{
- u1 *ra;
- java_objectheader *o;
- u4 mcode;
- unresolved_field *uf;
- fieldinfo *fi;
-
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
- o = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
- mcode = *((u4 *) (sp + 3 * 8));
- uf = (unresolved_field *) *((ptrint *) (sp + 2 * 8));
-
- /* calculate and set the new return address */
+ classinfo *c;
- ra = ra - 1 * 4;
- *((ptrint *) (sp + 5 * 8)) = (ptrint) ra;
-
- PATCHER_MONITORENTER;
+ /* get stuff from the stack */
- /* get the fieldinfo */
+ c = (classinfo *) *((ptrint *) (sp + 2 * 8));
- if (!(fi = resolve_field_eager(uf))) {
- PATCHER_MONITOREXIT;
+ /* check if the class is initialized */
- return false;
- }
+ if (!(c->state & CLASS_INITIALIZED))
+ if (!initialize_class(c))
+ return false;
- /* patch back original code */
+ return true;
+}
- *((u4 *) ra) = mcode;
+/* patcher_resolve_class *****************************************************
- /* if we show disassembly, we have to skip the nop */
+ Initalizes a given classinfo pointer. This function does not patch
+ any data.
- if (opt_showdisassemble)
- ra = ra + 4;
+*******************************************************************************/
- /* patch the field's offset */
+#ifdef ENABLE_VERIFIER
+bool patcher_resolve_class(u1 *sp)
+{
+ unresolved_class *uc;
+ classinfo *c;
- *((u4 *) ra) |= (s2) (fi->offset & 0x0000ffff);
+ /* get stuff from the stack */
- /* synchronize instruction cache */
+ uc = (unresolved_class *) *((ptrint *) (sp + 2 * 8));
- asm_sync_instruction_cache();
+ /* resolve the class */
- PATCHER_MARK_PATCHED_MONITOREXIT;
+ if (!resolve_class(uc, resolveEager, false, &c))
+ return false;
return true;
}
+#endif /* ENABLE_VERIFIER */
-/* patcher_builtin_new *********************************************************
+/* patcher_resolve_classref_to_classinfo ***************************************
- Machine code:
+ ACONST:
- a61bff80 ldq a0,-128(pv)
<patched call postition>
+ a61bff80 ldq a0,-128(pv)
+
+ MULTIANEWARRAY:
+
+ <patched call position>
+ a63bff80 ldq a1,-128(pv)
+ 47de0412 mov sp,a2
a77bff78 ldq pv,-136(pv)
6b5b4000 jsr (pv)
- NOTICE: Only the displacement for the function address is passed,
- but the address of the classinfo pointer is one below (above, in
- addresses speaking). This is for sure.
+ ARRAYCHECKCAST:
+
+ <patched call position>
+ a63bfe60 ldq a1,-416(pv)
+ a77bfe58 ldq pv,-424(pv)
+ 6b5b4000 jsr (pv)
*******************************************************************************/
-bool patcher_builtin_new(u1 *sp)
+bool patcher_resolve_classref_to_classinfo(u1 *sp)
{
- u1 *ra;
- java_objectheader *o;
- u4 mcode;
constant_classref *cr;
s4 disp;
u1 *pv;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
- o = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
- mcode = *((u4 *) (sp + 3 * 8));
cr = (constant_classref *) *((ptrint *) (sp + 2 * 8));
disp = *((s4 *) (sp + 1 * 8));
pv = (u1 *) *((ptrint *) (sp + 0 * 8));
- /* calculate and set the new return address */
-
- ra = ra - 2 * 4;
- *((ptrint *) (sp + 5 * 8)) = (ptrint) ra;
-
- PATCHER_MONITORENTER;
-
/* get the classinfo */
- if (!(c = resolve_classref_eager_nonabstract(cr))) {
- PATCHER_MONITOREXIT;
-
+ if (!(c = resolve_classref_eager(cr)))
return false;
- }
-
- /* patch back original code */
-
- *((u4 *) (ra + 4)) = mcode;
-
- /* synchronize instruction cache */
-
- asm_sync_instruction_cache();
/* patch the classinfo pointer */
- *((ptrint *) (pv + (disp + SIZEOF_VOID_P))) = (ptrint) c;
-
- /* patch new function address */
-
- *((ptrint *) (pv + disp)) = (ptrint) BUILTIN_new;
-
- PATCHER_MARK_PATCHED_MONITOREXIT;
+ *((ptrint *) (pv + disp)) = (ptrint) c;
return true;
}
-/* patcher_builtin_newarray ****************************************************
+/* patcher_resolve_classref_to_vftbl *******************************************
- Machine code:
+ CHECKCAST (class):
+ INSTANCEOF (class):
- a63bff88 ldq a1,-120(pv)
<patched call position>
- a77bff80 ldq pv,-128(pv)
- 6b5b4000 jsr (pv)
-
- NOTICE: Only the displacement for the function address is passed,
- but the address of the classinfo pointer is one below (above, in
- addresses speaking). This is for sure.
+ a7940000 ldq at,0(a4)
+ a7bbff28 ldq gp,-216(pv)
*******************************************************************************/
-bool patcher_builtin_newarray(u1 *sp)
+bool patcher_resolve_classref_to_vftbl(u1 *sp)
{
- u1 *ra;
- java_objectheader *o;
- u4 mcode;
constant_classref *cr;
s4 disp;
u1 *pv;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
- o = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
- mcode = *((u4 *) (sp + 3 * 8));
cr = (constant_classref *) *((ptrint *) (sp + 2 * 8));
disp = *((s4 *) (sp + 1 * 8));
pv = (u1 *) *((ptrint *) (sp + 0 * 8));
- /* calculate and set the new return address */
-
- ra = ra - 2 * 4;
- *((ptrint *) (sp + 5 * 8)) = (ptrint) ra;
-
- PATCHER_MONITORENTER;
-
- /* get the classinfo */
-
- if (!(c = resolve_classref_eager(cr))) {
- PATCHER_MONITOREXIT;
+ /* get the fieldinfo */
+ if (!(c = resolve_classref_eager(cr)))
return false;
- }
-
- /* patch back original code */
-
- *((u4 *) (ra + 4)) = mcode;
- /* synchronize instruction cache */
-
- asm_sync_instruction_cache();
-
- /* patch the class' vftbl pointer */
-
- *((ptrint *) (pv + (disp + SIZEOF_VOID_P))) = (ptrint) c->vftbl;
-
- /* patch new function address */
-
- *((ptrint *) (pv + disp)) = (ptrint) BUILTIN_newarray;
+ /* patch super class' vftbl */
- PATCHER_MARK_PATCHED_MONITOREXIT;
+ *((ptrint *) (pv + disp)) = (ptrint) c->vftbl;
return true;
}
-/* patcher_builtin_multianewarray **********************************************
+/* patcher_resolve_classref_to_flags *******************************************
- Machine code:
+ CHECKCAST/INSTANCEOF:
<patched call position>
- a63bff80 ldq a1,-128(pv)
- 47de0412 mov sp,a2
- a77bff78 ldq pv,-136(pv)
- 6b5b4000 jsr (pv)
*******************************************************************************/
-bool patcher_builtin_multianewarray(u1 *sp)
+bool patcher_resolve_classref_to_flags(u1 *sp)
{
- u1 *ra;
- java_objectheader *o;
- u4 mcode;
constant_classref *cr;
s4 disp;
u1 *pv;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
- o = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
- mcode = *((u4 *) (sp + 3 * 8));
cr = (constant_classref *) *((ptrint *) (sp + 2 * 8));
disp = *((s4 *) (sp + 1 * 8));
pv = (u1 *) *((ptrint *) (sp + 0 * 8));
- /* calculate and set the new return address */
+ /* get the fieldinfo */
- ra = ra - 1 * 4;
- *((ptrint *) (sp + 5 * 8)) = (ptrint) ra;
+ if (!(c = resolve_classref_eager(cr)))
+ return false;
- PATCHER_MONITORENTER;
+ /* patch class flags */
- /* get the classinfo */
+ *((s4 *) (pv + disp)) = (s4) c->flags;
- if (!(c = resolve_classref_eager(cr))) {
- PATCHER_MONITOREXIT;
+ return true;
+}
- return false;
- }
- /* patch back original code */
+/* patcher_resolve_native_function *********************************************
- *((u4 *) ra) = mcode;
+ XXX
- /* synchronize instruction cache */
+*******************************************************************************/
- asm_sync_instruction_cache();
+#if !defined(WITH_STATIC_CLASSPATH)
+bool patcher_resolve_native_function(u1 *sp)
+{
+ methodinfo *m;
+ s4 disp;
+ u1 *pv;
+ functionptr f;
- /* patch the class' vftbl pointer */
+ /* get stuff from the stack */
- *((ptrint *) (pv + disp)) = (ptrint) c->vftbl;
+ m = (methodinfo *) *((ptrint *) (sp + 2 * 8));
+ disp = *((s4 *) (sp + 1 * 8));
+ pv = (u1 *) *((ptrint *) (sp + 0 * 8));
- PATCHER_MARK_PATCHED_MONITOREXIT;
+ /* resolve native function */
+
+ if (!(f = native_resolve_function(m)))
+ return false;
+
+ /* patch native function pointer */
+
+ *((ptrint *) (pv + disp)) = (ptrint) f;
return true;
}
+#endif /* !defined(WITH_STATIC_CLASSPATH) */
-/* patcher_builtin_arraycheckcast **********************************************
+/* patcher_get_putstatic *******************************************************
Machine code:
<patched call position>
- a63bfe60 ldq a1,-416(pv)
- a77bfe58 ldq pv,-424(pv)
- 6b5b4000 jsr (pv)
-
- NOTICE: Only the displacement of the vftbl pointer address is
- passed, but the address of the function pointer is one above
- (below, in addresses speaking). This is for sure.
+ a73bff98 ldq t11,-104(pv)
+ a2590000 ldl a2,0(t11)
*******************************************************************************/
-bool patcher_builtin_arraycheckcast(u1 *sp)
+bool patcher_get_putstatic(u1 *sp)
{
- u1 *ra;
- java_objectheader *o;
- u4 mcode;
- constant_classref *cr;
- s4 disp;
- u1 *pv;
- classinfo *c;
+ unresolved_field *uf;
+ s4 disp;
+ u1 *pv;
+ fieldinfo *fi;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
- o = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
- mcode = *((u4 *) (sp + 3 * 8));
- cr = (constant_classref *) *((ptrint *) (sp + 2 * 8));
- disp = *((s4 *) (sp + 1 * 8));
- pv = (u1 *) *((ptrint *) (sp + 0 * 8));
+ uf = (unresolved_field *) *((ptrint *) (sp + 2 * 8));
+ disp = *((s4 *) (sp + 1 * 8));
+ pv = (u1 *) *((ptrint *) (sp + 0 * 8));
- /* calculate and set the new return address */
+ /* get the fieldinfo */
- ra = ra - 1 * 4;
- *((ptrint *) (sp + 5 * 8)) = (ptrint) ra;
+ if (!(fi = resolve_field_eager(uf)))
+ return false;
- PATCHER_MONITORENTER;
+ /* check if the field's class is initialized */
- /* get the classinfo */
+ if (!(fi->class->state & CLASS_INITIALIZED))
+ if (!initialize_class(fi->class))
+ return false;
- if (!(c = resolve_classref_eager(cr))) {
- PATCHER_MONITOREXIT;
+ /* patch the field value's address */
- return false;
- }
+ *((ptrint *) (pv + disp)) = (ptrint) &(fi->value);
- /* patch back original code */
+ return true;
+}
- *((u4 *) ra) = mcode;
- /* synchronize instruction cache */
+/* patcher_get_putfield ********************************************************
- asm_sync_instruction_cache();
+ Machine code:
- /* patch the class' vftbl pointer */
+ <patched call position>
+ a2af0020 ldl a5,32(s6)
- *((ptrint *) (pv + disp)) = (ptrint) c->vftbl;
+*******************************************************************************/
- /* patch new function address */
+bool patcher_get_putfield(u1 *sp)
+{
+ u1 *ra;
+ unresolved_field *uf;
+ fieldinfo *fi;
- *((ptrint *) (pv + (disp - SIZEOF_VOID_P))) =
- (ptrint) BUILTIN_arraycheckcast;
+ ra = (u1 *) *((ptrint *) (sp + 5 * 8));
+ uf = (unresolved_field *) *((ptrint *) (sp + 2 * 8));
- PATCHER_MARK_PATCHED_MONITOREXIT;
+ /* get the fieldinfo */
+
+ if (!(fi = resolve_field_eager(uf)))
+ return false;
+
+ /* if we show disassembly, we have to skip the nop */
+
+ if (opt_showdisassemble) {
+ /* patch the field's offset into the instruction */
+
+ *((u4 *) (ra + 4)) |= (s2) (fi->offset & 0x0000ffff);
+ }
+ else {
+ /* otherwise store the patched instruction on the stack */
+
+ *((u4 *) (sp + 3 * 8)) |= (s2) (fi->offset & 0x0000ffff);
+ }
return true;
}
-/* patcher_builtin_arrayinstanceof *********************************************
+/* patcher_invokestatic_special ************************************************
Machine code:
- a63bfeb0 ldq a1,-336(pv)
<patched call position>
- a77bfea8 ldq pv,-344(pv)
+ a77bffa8 ldq pv,-88(pv)
6b5b4000 jsr (pv)
- NOTICE: Only the displacement for the function address is passed,
- but the address of the vftbl pointer is one below (above, in
- addresses speaking). This is for sure.
-
-*******************************************************************************/
+******************************************************************************/
-bool patcher_builtin_arrayinstanceof(u1 *sp)
+bool patcher_invokestatic_special(u1 *sp)
{
- u1 *ra;
- java_objectheader *o;
- u4 mcode;
- constant_classref *cr;
+ unresolved_method *um;
s4 disp;
u1 *pv;
- classinfo *c;
+ methodinfo *m;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
- o = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
- mcode = *((u4 *) (sp + 3 * 8));
- cr = (constant_classref *) *((ptrint *) (sp + 2 * 8));
+ um = (unresolved_method *) *((ptrint *) (sp + 2 * 8));
disp = *((s4 *) (sp + 1 * 8));
pv = (u1 *) *((ptrint *) (sp + 0 * 8));
- /* calculate and set the new return address */
-
- ra = ra - 2 * 4;
- *((ptrint *) (sp + 5 * 8)) = (ptrint) ra;
-
- PATCHER_MONITORENTER;
-
- /* get the classinfo */
-
- if (!(c = resolve_classref_eager(cr))) {
- PATCHER_MONITOREXIT;
+ /* get the fieldinfo */
+ if (!(m = resolve_method_eager(um)))
return false;
- }
-
- /* patch back original code */
-
- *((u4 *) (ra + 4)) = mcode;
-
- /* synchronize instruction cache */
-
- asm_sync_instruction_cache();
-
- /* patch the class' vftbl pointer */
-
- *((ptrint *) (pv + (disp + SIZEOF_VOID_P))) = (ptrint) c->vftbl;
-
- /* patch new function address */
-
- *((ptrint *) (pv + disp)) = (ptrint) BUILTIN_arrayinstanceof;
-
- PATCHER_MARK_PATCHED_MONITOREXIT;
-
- return true;
-}
-
-
-/* patcher_invokestatic_special ************************************************
-
- Machine code:
-
- <patched call position>
- a77bffa8 ldq pv,-88(pv)
- 6b5b4000 jsr (pv)
-
-******************************************************************************/
-
-bool patcher_invokestatic_special(u1 *sp)
-{
- u1 *ra;
- java_objectheader *o;
- u4 mcode;
- unresolved_method *um;
- s4 disp;
- u1 *pv;
- methodinfo *m;
-
- /* get stuff from the stack */
-
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
- o = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
- mcode = *((u4 *) (sp + 3 * 8));
- um = (unresolved_method *) *((ptrint *) (sp + 2 * 8));
- disp = *((s4 *) (sp + 1 * 8));
- pv = (u1 *) *((ptrint *) (sp + 0 * 8));
-
- /* calculate and set the new return address */
-
- ra = ra - 1 * 4;
- *((ptrint *) (sp + 5 * 8)) = (ptrint) ra;
-
- PATCHER_MONITORENTER;
-
- /* get the fieldinfo */
-
- if (!(m = resolve_method_eager(um))) {
- PATCHER_MONITOREXIT;
-
- return false;
- }
-
- /* patch back original code */
-
- *((u4 *) ra) = mcode;
-
- /* synchronize instruction cache */
-
- asm_sync_instruction_cache();
/* patch stubroutine */
*((ptrint *) (pv + disp)) = (ptrint) m->stubroutine;
- PATCHER_MARK_PATCHED_MONITOREXIT;
-
return true;
}
bool patcher_invokevirtual(u1 *sp)
{
u1 *ra;
- java_objectheader *o;
- u4 mcode;
unresolved_method *um;
methodinfo *m;
/* get stuff from the stack */
ra = (u1 *) *((ptrint *) (sp + 5 * 8));
- o = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
- mcode = *((u4 *) (sp + 3 * 8));
um = (unresolved_method *) *((ptrint *) (sp + 2 * 8));
- /* calculate and set the new return address */
-
- ra = ra - 1 * 4;
- *((ptrint *) (sp + 5 * 8)) = (ptrint) ra;
-
- PATCHER_MONITORENTER;
-
/* get the fieldinfo */
- if (!(m = resolve_method_eager(um))) {
- PATCHER_MONITOREXIT;
-
+ if (!(m = resolve_method_eager(um)))
return false;
- }
-
- /* patch back original code */
-
- *((u4 *) ra) = mcode;
/* if we show disassembly, we have to skip the nop */
*((s4 *) (ra + 4)) |= (s4) ((OFFSET(vftbl_t, table[0]) +
sizeof(methodptr) * m->vftblindex) & 0x0000ffff);
- /* synchronize instruction cache */
-
- asm_sync_instruction_cache();
-
- PATCHER_MARK_PATCHED_MONITOREXIT;
-
return true;
}
bool patcher_invokeinterface(u1 *sp)
{
u1 *ra;
- java_objectheader *o;
- u4 mcode;
unresolved_method *um;
methodinfo *m;
/* get stuff from the stack */
ra = (u1 *) *((ptrint *) (sp + 5 * 8));
- o = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
- mcode = *((u4 *) (sp + 3 * 8));
um = (unresolved_method *) *((ptrint *) (sp + 2 * 8));
- /* calculate and set the new return address */
-
- ra = ra - 1 * 4;
- *((ptrint *) (sp + 5 * 8)) = (ptrint) ra;
-
- PATCHER_MONITORENTER;
-
/* get the fieldinfo */
- if (!(m = resolve_method_eager(um))) {
- PATCHER_MONITOREXIT;
-
+ if (!(m = resolve_method_eager(um)))
return false;
- }
-
- /* patch back original code */
-
- *((u4 *) ra) = mcode;
/* if we show disassembly, we have to skip the nop */
*((s4 *) (ra + 4 + 4)) |=
(s4) ((sizeof(methodptr) * (m - m->class->methods)) & 0x0000ffff);
- /* synchronize instruction cache */
-
- asm_sync_instruction_cache();
-
- PATCHER_MARK_PATCHED_MONITOREXIT;
-
- return true;
-}
-
-
-/* patcher_checkcast_instanceof_flags ******************************************
-
- Machine code:
-
- <patched call position>
-
-*******************************************************************************/
-
-bool patcher_checkcast_instanceof_flags(u1 *sp)
-{
- u1 *ra;
- java_objectheader *o;
- u4 mcode;
- constant_classref *cr;
- s4 disp;
- u1 *pv;
- classinfo *c;
-
- /* get stuff from the stack */
-
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
- o = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
- mcode = *((u4 *) (sp + 3 * 8));
- cr = (constant_classref *) *((ptrint *) (sp + 2 * 8));
- disp = *((s4 *) (sp + 1 * 8));
- pv = (u1 *) *((ptrint *) (sp + 0 * 8));
-
- /* calculate and set the new return address */
-
- ra = ra - 1 * 4;
- *((ptrint *) (sp + 5 * 8)) = (ptrint) ra;
-
- PATCHER_MONITORENTER;
-
- /* get the fieldinfo */
-
- if (!(c = resolve_classref_eager(cr))) {
- PATCHER_MONITOREXIT;
-
- return false;
- }
-
- /* patch back original code */
-
- *((u4 *) ra) = mcode;
-
- /* synchronize instruction cache */
-
- asm_sync_instruction_cache();
-
- /* patch class flags */
-
- *((s4 *) (pv + disp)) = (s4) c->flags;
-
- PATCHER_MARK_PATCHED_MONITOREXIT;
-
return true;
}
bool patcher_checkcast_instanceof_interface(u1 *sp)
{
u1 *ra;
- java_objectheader *o;
- u4 mcode;
constant_classref *cr;
classinfo *c;
/* get stuff from the stack */
ra = (u1 *) *((ptrint *) (sp + 5 * 8));
- o = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
- mcode = *((u4 *) (sp + 3 * 8));
cr = (constant_classref *) *((ptrint *) (sp + 2 * 8));
- /* calculate and set the new return address */
-
- ra = ra - 1 * 4;
- *((ptrint *) (sp + 5 * 8)) = (ptrint) ra;
-
- PATCHER_MONITORENTER;
-
/* get the fieldinfo */
- if (!(c = resolve_classref_eager(cr))) {
- PATCHER_MONITOREXIT;
-
+ if (!(c = resolve_classref_eager(cr)))
return false;
- }
-
- /* patch back original code */
-
- *((u4 *) ra) = mcode;
/* if we show disassembly, we have to skip the nop */
*((s4 *) (ra + 4 * 4)) |= (s4) ((OFFSET(vftbl_t, interfacetable[0]) -
c->index * sizeof(methodptr*)) & 0x0000ffff);
- /* synchronize instruction cache */
-
- asm_sync_instruction_cache();
-
- PATCHER_MARK_PATCHED_MONITOREXIT;
-
- return true;
-}
-
-
-/* patcher_checkcast_instanceof_class ******************************************
-
- Machine code:
-
- <patched call position>
- a7940000 ldq at,0(a4)
- a7bbff28 ldq gp,-216(pv)
-
-*******************************************************************************/
-
-bool patcher_checkcast_instanceof_class(u1 *sp)
-{
- u1 *ra;
- java_objectheader *o;
- u4 mcode;
- constant_classref *cr;
- s4 disp;
- u1 *pv;
- classinfo *c;
-
- /* get stuff from the stack */
-
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
- o = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
- mcode = *((u4 *) (sp + 3 * 8));
- cr = (constant_classref *) *((ptrint *) (sp + 2 * 8));
- disp = *((s4 *) (sp + 1 * 8));
- pv = (u1 *) *((ptrint *) (sp + 0 * 8));
-
- /* calculate and set the new return address */
-
- ra = ra - 1 * 4;
- *((ptrint *) (sp + 5 * 8)) = (ptrint) ra;
-
- PATCHER_MONITORENTER;
-
- /* get the fieldinfo */
-
- if (!(c = resolve_classref_eager(cr))) {
- PATCHER_MONITOREXIT;
-
- return false;
- }
-
- /* patch back original code */
-
- *((u4 *) ra) = mcode;
-
- /* synchronize instruction cache */
-
- asm_sync_instruction_cache();
-
- /* patch super class' vftbl */
-
- *((ptrint *) (pv + disp)) = (ptrint) c->vftbl;
-
- PATCHER_MARK_PATCHED_MONITOREXIT;
-
- return true;
-}
-
-
-/* patcher_clinit **************************************************************
-
- XXX
-
-*******************************************************************************/
-
-bool patcher_clinit(u1 *sp)
-{
- u1 *ra;
- java_objectheader *o;
- u4 mcode;
- classinfo *c;
-
- /* get stuff from the stack */
-
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
- o = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
- mcode = *((u4 *) (sp + 3 * 8));
- c = (classinfo *) *((ptrint *) (sp + 2 * 8));
-
- /* calculate and set the new return address */
-
- ra = ra - 1 * 4;
- *((ptrint *) (sp + 5 * 8)) = (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) = mcode;
-
- /* synchronize instruction cache */
-
- asm_sync_instruction_cache();
-
- PATCHER_MARK_PATCHED_MONITOREXIT;
-
- return true;
-}
-
-
-/* patcher_resolve_native ******************************************************
-
- XXX
-
-*******************************************************************************/
-
-#if !defined(ENABLE_STATICVM)
-bool patcher_resolve_native(u1 *sp)
-{
- u1 *ra;
- java_objectheader *o;
- u4 mcode;
- methodinfo *m;
- s4 disp;
- u1 *pv;
- functionptr f;
-
- /* get stuff from the stack */
-
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
- o = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
- mcode = *((u4 *) (sp + 3 * 8));
- m = (methodinfo *) *((ptrint *) (sp + 2 * 8));
- disp = *((s4 *) (sp + 1 * 8));
- pv = (u1 *) *((ptrint *) (sp + 0 * 8));
-
- /* calculate and set the new return address */
-
- ra = ra - 1 * 4;
- *((ptrint *) (sp + 5 * 8)) = (ptrint) ra;
-
- PATCHER_MONITORENTER;
-
- /* resolve native function */
-
- if (!(f = native_resolve_function(m))) {
- PATCHER_MONITOREXIT;
-
- return false;
- }
-
- /* patch back original code */
-
- *((u4 *) ra) = mcode;
-
- /* synchronize instruction cache */
-
- asm_sync_instruction_cache();
-
- /* patch native function pointer */
-
- *((ptrint *) (pv + disp)) = (ptrint) f;
-
- PATCHER_MARK_PATCHED_MONITOREXIT;
-
return true;
}
-#endif /* !defined(ENABLE_STATICVM) */
/*