/* src/vm/jit/mips/patcher.c - MIPS 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 3518 2005-10-28 14:47:11Z twisti $
+ $Id: patcher.c 5319 2006-09-05 12:54:10Z twisti $
*/
-#include <sys/cachectl.h>
-
#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/jit/patcher.h"
-/* patcher_get_putstatic *******************************************************
+/* patcher_wrapper *************************************************************
- Machine code:
+ Wrapper for all patchers. It also creates the stackframe info
+ structure.
- <patched call position>
- dfc1ffb8 ld at,-72(s8)
- fc250000 sd a1,0(at)
+ 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;
-#if SIZEOF_VOID_P == 8
- u8 mcode;
-#else
- u4 mcode[2];
-#endif
- 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));
- o = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
-#if SIZEOF_VOID_P == 8
- mcode = *((u8 *) (sp + 3 * 8));
-#else
- mcode[0] = *((u4 *) (sp + 3 * 8));
- mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
-#endif
- uf = (unresolved_field *) *((ptrint *) (sp + 2 * 8));
- disp = *((s4 *) (sp + 1 * 8));
- pv = (u1 *) *((ptrint *) (sp + 0 * 8));
+ xpc = (u1 *) *((ptrint *) (sp + 5 * 8));
+ o = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
+ f = (functionptr) *((ptrint *) (sp + 0 * 8));
- PATCHER_MONITORENTER;
+ /* store PV into the patcher function position */
- /* get the fieldinfo */
+ *((ptrint *) (sp + 0 * 8)) = (ptrint) pv;
- if (!(fi = resolve_field_eager(uf))) {
- PATCHER_MONITOREXIT;
+ /* cast the passed function to a patcher function */
- return false;
- }
+ patcher_function = (bool (*)(u1 *)) (ptrint) f;
- /* check if the field's class is initialized */
+ /* enter a monitor on the patching position */
- if (!fi->class->initialized) {
- if (!initialize_class(fi->class)) {
- PATCHER_MONITOREXIT;
+ PATCHER_MONITORENTER;
- return false;
- }
- }
+ /* create the stackframeinfo */
- /* patch back original code */
+ stacktrace_create_extern_stackframeinfo(&sfi, pv, sp + 6 * 8, ra, xpc);
-#if SIZEOF_VOID_P == 8
- *((u4 *) (ra + 0 * 4)) = mcode;
- *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
- *((u4 *) (ra + 0 * 4)) = mcode[0];
- *((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
+ /* call the proper patcher function */
- /* synchronize instruction cache */
+ result = (patcher_function)(sp);
- cacheflush(ra, 2 * 4, ICACHE);
+ /* remove the stackframeinfo */
- /* patch the field value's address */
+ stacktrace_remove_stackframeinfo(&sfi);
- *((ptrint *) (pv + disp)) = (ptrint) &(fi->value);
+ /* check for return value and exit accordingly */
- /* synchronize data cache */
+ if (result == false) {
+ e = exceptions_get_and_clear_exception();
- cacheflush(pv + disp, SIZEOF_VOID_P, DCACHE);
+ PATCHER_MONITOREXIT;
+
+ return e;
+ }
PATCHER_MARK_PATCHED_MONITOREXIT;
- return true;
+ return NULL;
}
-/* patcher_get_putfield ********************************************************
+/* patcher_get_putstatic *******************************************************
Machine code:
<patched call position>
- 8ee90020 lw a5,32(s7)
+ dfc1ffb8 ld at,-72(s8)
+ fc250000 sd a1,0(at)
*******************************************************************************/
-bool patcher_get_putfield(u1 *sp)
+bool patcher_get_putstatic(u1 *sp)
{
- u1 *ra;
- java_objectheader *o;
-#if SIZEOF_VOID_P == 8
- u8 mcode;
-#else
- u4 mcode[2];
-#endif
- unresolved_field *uf;
- fieldinfo *fi;
+ u1 *ra;
+ u4 mcode[2];
+ unresolved_field *uf;
+ s4 disp;
+ u1 *pv;
+ fieldinfo *fi;
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
- o = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
-#if SIZEOF_VOID_P == 8
- mcode = *((u8 *) (sp + 3 * 8));
-#else
- mcode[0] = *((u4 *) (sp + 3 * 8));
- mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
-#endif
- uf = (unresolved_field *) *((ptrint *) (sp + 2 * 8));
+ /* get stuff from the stack */
- PATCHER_MONITORENTER;
+ ra = (u1 *) *((ptrint *) (sp + 5 * 8));
+ mcode[0] = *((u4 *) (sp + 3 * 8));
+ mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
+ uf = (unresolved_field *) *((ptrint *) (sp + 2 * 8));
+ disp = *((s4 *) (sp + 1 * 8));
+ pv = (u1 *) *((ptrint *) (sp + 0 * 8));
/* get the fieldinfo */
- if (!(fi = resolve_field_eager(uf))) {
- PATCHER_MONITOREXIT;
-
+ if (!(fi = resolve_field_eager(uf)))
return false;
- }
+
+ /* check if the field's class is initialized */
+
+ if (!(fi->class->state & CLASS_INITIALIZED))
+ if (!initialize_class(fi->class))
+ return false;
/* patch back original code */
-#if SIZEOF_VOID_P == 8
- *((u4 *) (ra + 0 * 4)) = mcode;
- *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
*((u4 *) (ra + 0 * 4)) = mcode[0];
*((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
- /* if we show disassembly, we have to skip the nop's */
+ /* synchronize instruction cache */
- if (opt_showdisassemble)
- ra = ra + 2 * 4;
+ md_icacheflush(ra, 2 * 4);
- /* patch the field's offset */
+ /* patch the field value's address */
- *((u4 *) ra) |= (s2) (fi->offset & 0x0000ffff);
+ *((ptrint *) (pv + disp)) = (ptrint) &(fi->value);
- /* synchronize instruction cache */
+ /* synchronize data cache */
- if (opt_showdisassemble)
- cacheflush(ra - 2 * 4, 3 * 4, ICACHE);
- else
- cacheflush(ra, 2 * 4, ICACHE);
-
- PATCHER_MARK_PATCHED_MONITOREXIT;
+ md_dcacheflush(pv + disp, SIZEOF_VOID_P);
return true;
}
-/* patcher_builtin_new *********************************************************
+/* patcher_get_putfield ********************************************************
Machine code:
- dfc4ff98 ld a0,-104(s8)
- <patched call postition>
- dfd9ff90 ld t9,-112(s8)
- 0320f809 jalr t9
- 00000000 nop
-
- 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.
+ <patched call position>
+ 8ee90020 lw a5,32(s7)
*******************************************************************************/
-bool patcher_builtin_new(u1 *sp)
+bool patcher_get_putfield(u1 *sp)
{
- u1 *ra;
- java_objectheader *o;
-#if SIZEOF_VOID_P == 8
- u8 mcode;
-#else
- u4 mcode[2];
-#endif
- constant_classref *cr;
- s4 disp;
- u1 *pv;
- classinfo *c;
+ u1 *ra;
+ u4 mcode[2];
+ unresolved_field *uf;
+ fieldinfo *fi;
- /* get stuff from the stack */
+ ra = (u1 *) *((ptrint *) (sp + 5 * 8));
+ mcode[0] = *((u4 *) (sp + 3 * 8));
+ mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
+ uf = (unresolved_field *) *((ptrint *) (sp + 2 * 8));
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
- o = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
-#if SIZEOF_VOID_P == 8
- mcode = *((u8 *) (sp + 3 * 8));
-#else
- mcode[0] = *((u4 *) (sp + 3 * 8));
- mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
-#endif
- 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 classinfo */
-
- if (!(c = resolve_classref_eager_nonabstract(cr))) {
- PATCHER_MONITOREXIT;
+ /* get the fieldinfo */
+ if (!(fi = resolve_field_eager(uf)))
return false;
- }
/* patch back original code */
-#if SIZEOF_VOID_P == 8
- *((u4 *) (ra + 1 * 4)) = mcode;
- *((u4 *) (ra + 2 * 4)) = mcode >> 32;
-#else
- *((u4 *) (ra + 1 * 4)) = mcode[0];
- *((u4 *) (ra + 2 * 4)) = mcode[1];
-#endif
-
- /* synchronize instruction cache */
+ *((u4 *) (ra + 0 * 4)) = mcode[0];
+ *((u4 *) (ra + 1 * 4)) = mcode[1];
- cacheflush(ra + 1 * 4, 2 * 4, ICACHE);
+ /* if we show disassembly, we have to skip the nop's */
- /* patch the classinfo pointer */
+ if (opt_showdisassemble)
+ ra = ra + 2 * 4;
- *((ptrint *) (pv + (disp + SIZEOF_VOID_P))) = (ptrint) c;
+ /* patch the field's offset */
- /* patch new function address */
+#if SIZEOF_VOID_P == 4
+ if (fi->type == TYPE_LNG) {
+# if WORDS_BIGENDIAN == 1
+ /* ATTENTION: order of these instructions depend on M_LLD_INTERN */
+ *((u4 *) (ra + 0 * 4)) |= (s2) ((fi->offset + 0) & 0x0000ffff);
+ *((u4 *) (ra + 1 * 4)) |= (s2) ((fi->offset + 4) & 0x0000ffff);
+# else
+ /* ATTENTION: order of these instructions depend on M_LLD_INTERN */
+ *((u4 *) (ra + 0 * 4)) |= (s2) ((fi->offset + 4) & 0x0000ffff);
+ *((u4 *) (ra + 1 * 4)) |= (s2) ((fi->offset + 0) & 0x0000ffff);
+# endif
+ } else
+#endif
+ *((u4 *) ra) |= (s2) (fi->offset & 0x0000ffff);
- *((ptrint *) (pv + disp)) = (ptrint) BUILTIN_new;
+ /* synchronize instruction cache */
- PATCHER_MARK_PATCHED_MONITOREXIT;
+ if (opt_showdisassemble) {
+#if SIZEOF_VOID_P == 4
+ if (fi->type == TYPE_LNG)
+ md_icacheflush(ra - 2 * 4, 4 * 4);
+ else
+#endif
+ md_icacheflush(ra - 2 * 4, 3 * 4);
+ }
+ else {
+ md_icacheflush(ra, 2 * 4);
+ }
return true;
}
-/* patcher_builtin_newarray ****************************************************
+/* patcher_aconst **************************************************************
Machine code:
- dfc5ffa0 ld a1,-96(s8)
- <patched call position>
- dfd9ff98 ld t9,-104(s8)
- 0320f809 jalr t9
- 00000000 nop
-
- 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.
+ <patched call postition>
+ dfc4ff98 ld a0,-104(s8)
*******************************************************************************/
-bool patcher_builtin_newarray(u1 *sp)
+bool patcher_aconst(u1 *sp)
{
u1 *ra;
- java_objectheader *o;
-#if SIZEOF_VOID_P == 8
- u8 mcode;
-#else
u4 mcode[2];
-#endif
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));
-#if SIZEOF_VOID_P == 8
- mcode = *((u8 *) (sp + 3 * 8));
-#else
mcode[0] = *((u4 *) (sp + 3 * 8));
mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
-#endif
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 classinfo */
- if (!(c = resolve_classref_eager(cr))) {
- PATCHER_MONITOREXIT;
-
+ if (!(c = resolve_classref_eager(cr)))
return false;
- }
/* patch back original code */
-#if SIZEOF_VOID_P == 8
- *((u4 *) (ra + 1 * 4)) = mcode;
- *((u4 *) (ra + 2 * 4)) = mcode >> 32;
-#else
- *((u4 *) (ra + 1 * 4)) = mcode[0];
- *((u4 *) (ra + 2 * 4)) = mcode[1];
-#endif
+ *((u4 *) (ra + 0 * 4)) = mcode[0];
+ *((u4 *) (ra + 1 * 4)) = mcode[1];
/* synchronize instruction cache */
- cacheflush(ra + 1 * 4, 2 * 4, ICACHE);
-
- /* patch the class' vftbl pointer */
+ md_icacheflush(ra, 2 * 4);
- *((ptrint *) (pv + (disp + SIZEOF_VOID_P))) = (ptrint) c->vftbl;
+ /* patch the classinfo pointer */
- /* patch new function address */
+ *((ptrint *) (pv + disp)) = (ptrint) c;
- *((ptrint *) (pv + disp)) = (ptrint) BUILTIN_newarray;
+ /* synchronize data cache */
- PATCHER_MARK_PATCHED_MONITOREXIT;
+ md_dcacheflush(pv + disp, SIZEOF_VOID_P);
return true;
}
bool patcher_builtin_multianewarray(u1 *sp)
{
u1 *ra;
- java_objectheader *o;
-#if SIZEOF_VOID_P == 8
- u8 mcode;
-#else
u4 mcode[2];
-#endif
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));
-#if SIZEOF_VOID_P == 8
- mcode = *((u8 *) (sp + 3 * 8));
-#else
mcode[0] = *((u4 *) (sp + 3 * 8));
mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
-#endif
cr = (constant_classref *) *((ptrint *) (sp + 2 * 8));
disp = *((s4 *) (sp + 1 * 8));
pv = (u1 *) *((ptrint *) (sp + 0 * 8));
- PATCHER_MONITORENTER;
-
/* get the classinfo */
- if (!(c = resolve_classref_eager(cr))) {
- PATCHER_MONITOREXIT;
-
+ if (!(c = resolve_classref_eager(cr)))
return false;
- }
/* patch back original code */
-#if SIZEOF_VOID_P == 8
- *((u4 *) (ra + 0 * 4)) = mcode;
- *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
*((u4 *) (ra + 0 * 4)) = mcode[0];
*((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
/* synchronize instruction cache */
- cacheflush(ra, 2 * 4, ICACHE);
+ md_icacheflush(ra, 2 * 4);
- /* patch the class' vftbl pointer */
+ /* patch the classinfo pointer */
- *((ptrint *) (pv + disp)) = (ptrint) c->vftbl;
+ *((ptrint *) (pv + disp)) = (ptrint) c;
- PATCHER_MARK_PATCHED_MONITOREXIT;
+ /* synchronize data cache */
+
+ md_dcacheflush(pv + disp, SIZEOF_VOID_P);
return true;
}
0320f809 jalr t9
00000000 nop
- 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.
-
*******************************************************************************/
bool patcher_builtin_arraycheckcast(u1 *sp)
{
u1 *ra;
- java_objectheader *o;
-#if SIZEOF_VOID_P == 8
- u8 mcode;
-#else
u4 mcode[2];
-#endif
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));
-#if SIZEOF_VOID_P == 8
- mcode = *((u8 *) (sp + 3 * 8));
-#else
mcode[0] = *((u4 *) (sp + 3 * 8));
mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
-#endif
cr = (constant_classref *) *((ptrint *) (sp + 2 * 8));
disp = *((s4 *) (sp + 1 * 8));
pv = (u1 *) *((ptrint *) (sp + 0 * 8));
- PATCHER_MONITORENTER;
-
/* get the classinfo */
- if (!(c = resolve_classref_eager(cr))) {
- PATCHER_MONITOREXIT;
-
+ if (!(c = resolve_classref_eager(cr)))
return false;
- }
/* patch back original code */
-#if SIZEOF_VOID_P == 8
- *((u4 *) (ra + 0 * 4)) = mcode;
- *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
*((u4 *) (ra + 0 * 4)) = mcode[0];
*((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
/* synchronize instruction cache */
- cacheflush(ra, 2 * 4, ICACHE);
-
- /* patch the class' vftbl pointer */
-
- *((ptrint *) (pv + disp)) = (ptrint) c->vftbl;
-
- /* patch new function address */
-
- *((ptrint *) (pv + (disp - SIZEOF_VOID_P))) =
- (ptrint) BUILTIN_arraycheckcast;
+ md_icacheflush(ra, 2 * 4);
- PATCHER_MARK_PATCHED_MONITOREXIT;
-
- return true;
-}
-
-
-/* patcher_builtin_arrayinstanceof *********************************************
-
- Machine code:
-
- dfc5fe98 ld a1,-360(s8)
- <patched call position>
- dfd9fe90 ld t9,-368(s8)
- 0320f809 jalr t9
- 00000000 nop
-
- 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)
-{
- u1 *ra;
- java_objectheader *o;
-#if SIZEOF_VOID_P == 8
- u8 mcode;
-#else
- u4 mcode[2];
-#endif
- 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));
-#if SIZEOF_VOID_P == 8
- mcode = *((u8 *) (sp + 3 * 8));
-#else
- mcode[0] = *((u4 *) (sp + 3 * 8));
- mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
-#endif
- 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 classinfo */
-
- if (!(c = resolve_classref_eager(cr))) {
- PATCHER_MONITOREXIT;
-
- return false;
- }
-
- /* patch back original code */
-
-#if SIZEOF_VOID_P == 8
- *((u4 *) (ra + 1 * 4)) = mcode;
- *((u4 *) (ra + 2 * 4)) = mcode >> 32;
-#else
- *((u4 *) (ra + 1 * 4)) = mcode[0];
- *((u4 *) (ra + 2 * 4)) = mcode[1];
-#endif
-
- /* synchronize instruction cache */
-
- cacheflush(ra + 1 * 4, 2 * 4, ICACHE);
-
- /* patch the class' vftbl pointer */
-
- *((ptrint *) (pv + (disp + SIZEOF_VOID_P))) = (ptrint) c->vftbl;
+ /* patch the classinfo pointer */
- /* patch new function address */
+ *((ptrint *) (pv + disp)) = (ptrint) c;
- *((ptrint *) (pv + disp)) = (ptrint) BUILTIN_arrayinstanceof;
+ /* synchronize data cache */
- PATCHER_MARK_PATCHED_MONITOREXIT;
+ md_dcacheflush(pv + disp, SIZEOF_VOID_P);
return true;
}
bool patcher_invokestatic_special(u1 *sp)
{
u1 *ra;
- java_objectheader *o;
-#if SIZEOF_VOID_P == 8
- u8 mcode;
-#else
u4 mcode[2];
-#endif
unresolved_method *um;
s4 disp;
u1 *pv;
/* get stuff from the stack */
ra = (u1 *) *((ptrint *) (sp + 5 * 8));
- o = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
-#if SIZEOF_VOID_P == 8
- mcode = *((u8 *) (sp + 3 * 8));
-#else
mcode[0] = *((u4 *) (sp + 3 * 8));
mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
-#endif
um = (unresolved_method *) *((ptrint *) (sp + 2 * 8));
disp = *((s4 *) (sp + 1 * 8));
pv = (u1 *) *((ptrint *) (sp + 0 * 8));
- 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 */
-#if SIZEOF_VOID_P == 8
- *((u4 *) (ra + 0 * 4)) = mcode;
- *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
*((u4 *) (ra + 0 * 4)) = mcode[0];
*((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
/* synchronize instruction cache */
- cacheflush(ra, 2 * 4, ICACHE);
+ md_icacheflush(ra, 2 * 4);
/* patch stubroutine */
*((ptrint *) (pv + disp)) = (ptrint) m->stubroutine;
- PATCHER_MARK_PATCHED_MONITOREXIT;
+ /* synchronize data cache */
+
+ md_dcacheflush(pv + disp, SIZEOF_VOID_P);
return true;
}
bool patcher_invokevirtual(u1 *sp)
{
u1 *ra;
- java_objectheader *o;
-#if SIZEOF_VOID_P == 8
- u8 mcode;
-#else
u4 mcode[2];
-#endif
unresolved_method *um;
methodinfo *m;
/* get stuff from the stack */
ra = (u1 *) *((ptrint *) (sp + 5 * 8));
- o = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
-#if SIZEOF_VOID_P == 8
- mcode = *((u8 *) (sp + 3 * 8));
-#else
mcode[0] = *((u4 *) (sp + 3 * 8));
mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
-#endif
um = (unresolved_method *) *((ptrint *) (sp + 2 * 8));
- 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 */
-#if SIZEOF_VOID_P == 8
- *((u4 *) (ra + 0 * 4)) = mcode;
- *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
*((u4 *) (ra + 0 * 4)) = mcode[0];
*((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
/* if we show disassembly, we have to skip the nop's */
/* synchronize instruction cache */
if (opt_showdisassemble)
- cacheflush(ra - 2 * 4, 4 * 4, ICACHE);
+ md_icacheflush(ra - 2 * 4, 4 * 4);
else
- cacheflush(ra, 2 * 4, ICACHE);
-
- PATCHER_MARK_PATCHED_MONITOREXIT;
+ md_icacheflush(ra, 2 * 4);
return true;
}
bool patcher_invokeinterface(u1 *sp)
{
u1 *ra;
- java_objectheader *o;
-#if SIZEOF_VOID_P == 8
- u8 mcode;
-#else
u4 mcode[2];
-#endif
unresolved_method *um;
methodinfo *m;
/* get stuff from the stack */
ra = (u1 *) *((ptrint *) (sp + 5 * 8));
- o = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
-#if SIZEOF_VOID_P == 8
- mcode = *((u8 *) (sp + 3 * 8));
-#else
mcode[0] = *((u4 *) (sp + 3 * 8));
mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
-#endif
um = (unresolved_method *) *((ptrint *) (sp + 2 * 8));
- 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 */
-#if SIZEOF_VOID_P == 8
- *((u4 *) (ra + 0 * 4)) = mcode;
- *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
*((u4 *) (ra + 0 * 4)) = mcode[0];
*((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
/* if we show disassembly, we have to skip the nop's */
/* synchronize instruction cache */
if (opt_showdisassemble)
- cacheflush(ra - 2 * 4, 5 * 4, ICACHE);
+ md_icacheflush(ra - 2 * 4, 5 * 4);
else
- cacheflush(ra, 3 * 4, ICACHE);
-
- PATCHER_MARK_PATCHED_MONITOREXIT;
+ md_icacheflush(ra, 3 * 4);
return true;
}
bool patcher_checkcast_instanceof_flags(u1 *sp)
{
u1 *ra;
- java_objectheader *o;
-#if SIZEOF_VOID_P == 8
- u8 mcode;
-#else
u4 mcode[2];
-#endif
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));
-#if SIZEOF_VOID_P == 8
- mcode = *((u8 *) (sp + 3 * 8));
-#else
mcode[0] = *((u4 *) (sp + 3 * 8));
mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
-#endif
cr = (constant_classref *) *((ptrint *) (sp + 2 * 8));
disp = *((s4 *) (sp + 1 * 8));
pv = (u1 *) *((ptrint *) (sp + 0 * 8));
- 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 */
-#if SIZEOF_VOID_P == 8
- *((u4 *) (ra + 0 * 4)) = mcode;
- *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
*((u4 *) (ra + 0 * 4)) = mcode[0];
*((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
/* synchronize instruction cache */
- cacheflush(ra, 2 * 4, ICACHE);
+ md_icacheflush(ra, 2 * 4);
/* patch class flags */
*((s4 *) (pv + disp)) = (s4) c->flags;
- PATCHER_MARK_PATCHED_MONITOREXIT;
+ /* synchronize data cache */
+
+ md_dcacheflush(pv + disp, sizeof(s4));
return true;
}
bool patcher_checkcast_instanceof_interface(u1 *sp)
{
u1 *ra;
- java_objectheader *o;
-#if SIZEOF_VOID_P == 8
- u8 mcode;
-#else
u4 mcode[2];
-#endif
constant_classref *cr;
classinfo *c;
/* get stuff from the stack */
ra = (u1 *) *((ptrint *) (sp + 5 * 8));
- o = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
-#if SIZEOF_VOID_P == 8
- mcode = *((u8 *) (sp + 3 * 8));
-#else
mcode[0] = *((u4 *) (sp + 3 * 8));
mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
-#endif
cr = (constant_classref *) *((ptrint *) (sp + 2 * 8));
- 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 */
-#if SIZEOF_VOID_P == 8
- *((u4 *) (ra + 0 * 4)) = mcode;
- *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
*((u4 *) (ra + 0 * 4)) = mcode[0];
*((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
/* if we show disassembly, we have to skip the nop's */
/* synchronize instruction cache */
if (opt_showdisassemble)
- cacheflush(ra - 2 * 4, 8 * 4, ICACHE);
+ md_icacheflush(ra - 2 * 4, 8 * 4);
else
- cacheflush(ra, 6 * 4, ICACHE);
-
- PATCHER_MARK_PATCHED_MONITOREXIT;
+ md_icacheflush(ra, 6 * 4);
return true;
}
bool patcher_checkcast_instanceof_class(u1 *sp)
{
u1 *ra;
- java_objectheader *o;
-#if SIZEOF_VOID_P == 8
- u8 mcode;
-#else
u4 mcode[2];
-#endif
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));
-#if SIZEOF_VOID_P == 8
- mcode = *((u8 *) (sp + 3 * 8));
-#else
mcode[0] = *((u4 *) (sp + 3 * 8));
mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
-#endif
cr = (constant_classref *) *((ptrint *) (sp + 2 * 8));
disp = *((s4 *) (sp + 1 * 8));
pv = (u1 *) *((ptrint *) (sp + 0 * 8));
- 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 */
-#if SIZEOF_VOID_P == 8
- *((u4 *) (ra + 0 * 4)) = mcode;
- *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
*((u4 *) (ra + 0 * 4)) = mcode[0];
*((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
/* synchronize instruction cache */
- cacheflush(ra, 2 * 4, ICACHE);
+ md_icacheflush(ra, 2 * 4);
/* patch super class' vftbl */
*((ptrint *) (pv + disp)) = (ptrint) c->vftbl;
- PATCHER_MARK_PATCHED_MONITOREXIT;
+ /* synchronize data cache */
+
+ md_dcacheflush(pv + disp, SIZEOF_VOID_P);
return true;
}
bool patcher_clinit(u1 *sp)
{
- u1 *ra;
- java_objectheader *o;
-#if SIZEOF_VOID_P == 8
- u8 mcode;
-#else
- u4 mcode[2];
-#endif
- classinfo *c;
+ u1 *ra;
+ u4 mcode[2];
+ classinfo *c;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
- o = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
-#if SIZEOF_VOID_P == 8
- mcode = *((u8 *) (sp + 3 * 8));
-#else
- mcode[0] = *((u4 *) (sp + 3 * 8));
- mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
-#endif
- c = (classinfo *) *((ptrint *) (sp + 2 * 8));
-
- PATCHER_MONITORENTER;
+ ra = (u1 *) *((ptrint *) (sp + 5 * 8));
+ mcode[0] = *((u4 *) (sp + 3 * 8));
+ mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
+ c = (classinfo *) *((ptrint *) (sp + 2 * 8));
/* check if the class is initialized */
- if (!c->initialized) {
- if (!initialize_class(c)) {
- PATCHER_MONITOREXIT;
-
+ if (!(c->state & CLASS_INITIALIZED))
+ if (!initialize_class(c))
return false;
- }
- }
/* patch back original code */
-#if SIZEOF_VOID_P == 8
- *((u4 *) (ra + 0 * 4)) = mcode;
- *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
*((u4 *) (ra + 0 * 4)) = mcode[0];
*((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
/* synchronize instruction cache */
- cacheflush(ra, 2 * 4, ICACHE);
-
- PATCHER_MARK_PATCHED_MONITOREXIT;
+ md_icacheflush(ra, 2 * 4);
return true;
}
*******************************************************************************/
+#ifdef ENABLE_VERIFIER
bool patcher_athrow_areturn(u1 *sp)
{
- u1 *ra;
- java_objectheader *o;
-#if SIZEOF_VOID_P == 8
- u8 mcode;
-#else
- u4 mcode[2];
-#endif
- unresolved_class *uc;
- classinfo *c;
+ u1 *ra;
+ u4 mcode[2];
+ unresolved_class *uc;
+ classinfo *c;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
- o = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
-#if SIZEOF_VOID_P == 8
- mcode = *((u8 *) (sp + 3 * 8));
-#else
- mcode[0] = *((u4 *) (sp + 3 * 8));
- mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
-#endif
- uc = (unresolved_class *) *((ptrint *) (sp + 2 * 8));
-
- PATCHER_MONITORENTER;
+ ra = (u1 *) *((ptrint *) (sp + 5 * 8));
+ mcode[0] = *((u4 *) (sp + 3 * 8));
+ mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
+ uc = (unresolved_class *) *((ptrint *) (sp + 2 * 8));
/* resolve the class */
- if (!resolve_class(uc, resolveEager, false, &c)) {
- PATCHER_MONITOREXIT;
-
+ if (!resolve_class(uc, resolveEager, false, &c))
return false;
- }
/* patch back original code */
-#if SIZEOF_VOID_P == 8
- *((u4 *) (ra + 0 * 4)) = mcode;
- *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
*((u4 *) (ra + 0 * 4)) = mcode[0];
*((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
/* synchronize instruction cache */
- cacheflush(ra, 2 * 4, ICACHE);
-
- PATCHER_MARK_PATCHED_MONITOREXIT;
+ md_icacheflush(ra, 2 * 4);
return true;
}
+#endif /* ENABLE_VERIFIER */
/* patcher_resolve_native ******************************************************
*******************************************************************************/
-#if !defined(ENABLE_STATICVM)
+#if !defined(WITH_STATIC_CLASSPATH)
bool patcher_resolve_native(u1 *sp)
{
- u1 *ra;
- java_objectheader *o;
-#if SIZEOF_VOID_P == 8
- u8 mcode;
-#else
- u4 mcode[2];
-#endif
- methodinfo *m;
- s4 disp;
- u1 *pv;
- functionptr f;
+ u1 *ra;
+ u4 mcode[2];
+ 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));
-#if SIZEOF_VOID_P == 8
- mcode = *((u8 *) (sp + 3 * 8));
-#else
- mcode[0] = *((u4 *) (sp + 3 * 8));
- mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
-#endif
- 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 - 2 * 4;
- *((ptrint *) (sp + 5 * 8)) = (ptrint) ra;
-
- PATCHER_MONITORENTER;
+ ra = (u1 *) *((ptrint *) (sp + 5 * 8));
+ mcode[0] = *((u4 *) (sp + 3 * 8));
+ mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
+ m = (methodinfo *) *((ptrint *) (sp + 2 * 8));
+ disp = *((s4 *) (sp + 1 * 8));
+ pv = (u1 *) *((ptrint *) (sp + 0 * 8));
/* resolve native function */
- if (!(f = native_resolve_function(m))) {
- PATCHER_MONITOREXIT;
-
+ if (!(f = native_resolve_function(m)))
return false;
- }
/* patch back original code */
-#if SIZEOF_VOID_P == 8
- *((u4 *) (ra + 0 * 4)) = mcode;
- *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
*((u4 *) (ra + 0 * 4)) = mcode[0];
*((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
/* synchronize instruction cache */
- cacheflush(ra, 2 * 4, ICACHE);
+ md_icacheflush(ra, 2 * 4);
/* patch native function pointer */
*((ptrint *) (pv + disp)) = (ptrint) f;
- PATCHER_MARK_PATCHED_MONITOREXIT;
+ /* synchronize data cache */
+
+ md_dcacheflush(pv + disp, SIZEOF_VOID_P);
return true;
}
-#endif /* !defined(ENABLE_STATICVM) */
+#endif /* !defined(WITH_STATIC_CLASSPATH) */
/*