Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: asmpart.S 7678 2007-04-09 17:23:55Z twisti $
+ $Id: asmpart.S 8186 2007-07-05 23:48:16Z michi $
*/
.globl asm_abstractmethoderror
- .globl asm_patcher_wrapper
-
#if defined(ENABLE_REPLACEMENT)
.globl asm_replacement_out
.globl asm_replacement_in
.end asm_abstractmethoderror
-/* asm_patcher_wrapper *********************************************************
-
- XXX
-
- Stack layout:
- 40 return address into JIT code (patch position)
- 32 pointer to virtual java_objectheader
- 24 machine code (which is patched back later)
- 16 unresolved class/method/field reference
- 8 data segment displacement from load instructions
- 0 patcher function pointer to call (pv afterwards)
-
- ATTENTION: itmp3 == gp! But we don't need gp do call the patcher function.
-
-*******************************************************************************/
-
- .ent asm_patcher_wrapper
-
-asm_patcher_wrapper:
- lda sp,-((2+12+27+4)*8)(sp) /* create stack frame */
-
- SAVE_RETURN_REGISTERS(0) /* save 1 int/1 float return registers */
- SAVE_ARGUMENT_REGISTERS(2) /* save 6 int/6 float argument registers */
- SAVE_TEMPORARY_REGISTERS(14) /* save 11 int/16 float temporary registers */
-
- stq itmp1,(2+12+27+0)*8(sp) /* save itmp1 */
- stq itmp2,(2+12+27+1)*8(sp) /* save itmp2 */
- stq ra,(2+12+27+2)*8(sp) /* save method return address (for leafs) */
- stq pv,(2+12+27+3)*8(sp) /* save pv of calling java function */
-
- br ra,L_asm_patcher_wrapper_load_gp
-L_asm_patcher_wrapper_load_gp:
- ldgp gp,0(ra) /* load gp (it's not set correctly in jit) */
-
- lda a0,(2+12+27+4)*8(sp) /* pass SP of patcher stub */
- mov pv,a1 /* pass PV */
- ldq a2,(2+12+27+2)*8(sp) /* pass RA (correct for leafs) */
- jsr ra,patcher_wrapper
- ldgp gp,0(ra)
- stq v0,(0+2+12+27+4)*8(sp) /* save return value */
-
- RESTORE_RETURN_REGISTERS(0) /* restore 1 int/1 float return registers */
- RESTORE_ARGUMENT_REGISTERS(2) /* restore 6 int/6 float argument registers */
- RESTORE_TEMPORARY_REGISTERS(14) /* restore 11 integer temporary registers */
-
- ldq itmp1,(2+12+27+0)*8(sp) /* restore itmp1 */
- ldq itmp2,(2+12+27+1)*8(sp) /* restore itmp2 */
- ldq ra,(2+12+27+2)*8(sp) /* restore method return address (for leafs)*/
- ldq pv,(2+12+27+3)*8(sp) /* restore pv of calling java function */
-
- ldq itmp3,(0+2+12+27+4)*8(sp) /* get return value */
- bne itmp3,L_asm_patcher_wrapper_exception
-
- ldq itmp3,(5+2+12+27+4)*8(sp) /* get RA to JIT */
- lda sp,(6+2+12+27+4)*8(sp) /* remove stack frame */
-
- jmp zero,(itmp3) /* jump to new patched code */
-
-L_asm_patcher_wrapper_exception:
- mov itmp3,xptr /* get exception */
- ldq xpc,(5+2+12+27+4)*8(sp) /* RA is xpc */
- lda sp,(6+2+12+27+4)*8(sp) /* remove stack frame */
- br L_asm_handle_exception
-
- .end asm_patcher_wrapper
-
-
#if defined(ENABLE_REPLACEMENT)
/* asm_replacement_out *********************************************************
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: codegen.c 8123 2007-06-20 23:50:55Z michi $
+ $Id: codegen.c 8187 2007-07-05 23:52:19Z michi $
*/
#include "vm/jit/emit-common.h"
#include "vm/jit/jit.h"
#include "vm/jit/parse.h"
-#include "vm/jit/patcher.h"
+#include "vm/jit/patcher-common.h"
#include "vm/jit/reg.h"
#include "vm/jit/replace.h"
#include "vm/jit/stacktrace.h"
resolved the same class, the returned displacement
of dseg_add_address is ok to use. */
- codegen_add_patch_ref(cd, PATCHER_resolve_classref_to_classinfo,
+ patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
cr, disp);
M_ALD(d, REG_PV, disp);
fieldtype = uf->fieldref->parseddesc.fd->type;
disp = dseg_add_unique_address(cd, uf);
- codegen_add_patch_ref(cd, PATCHER_get_putstatic, uf, disp);
+ patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
}
else {
fi = iptr->sx.s23.s3.fmiref->p.field;
disp = dseg_add_address(cd, &(fi->value));
if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class))
- codegen_add_patch_ref(cd, PATCHER_initialize_class, fi->class,
+ patcher_add_patch_ref(jd, PATCHER_initialize_class, fi->class,
0);
}
fieldtype = uf->fieldref->parseddesc.fd->type;
disp = dseg_add_unique_address(cd, uf);
- codegen_add_patch_ref(cd, PATCHER_get_putstatic, uf, disp);
+ patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
}
else {
fi = iptr->sx.s23.s3.fmiref->p.field;
disp = dseg_add_address(cd, &(fi->value));
if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class))
- codegen_add_patch_ref(cd, PATCHER_initialize_class, fi->class,
+ patcher_add_patch_ref(jd, PATCHER_initialize_class, fi->class,
0);
}
fieldtype = uf->fieldref->parseddesc.fd->type;
disp = dseg_add_unique_address(cd, uf);
- codegen_add_patch_ref(cd, PATCHER_get_putstatic, uf, disp);
+ patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
}
else {
fi = iptr->sx.s23.s3.fmiref->p.field;
disp = dseg_add_address(cd, &(fi->value));
if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class))
- codegen_add_patch_ref(cd, PATCHER_initialize_class, fi->class,
+ patcher_add_patch_ref(jd, PATCHER_initialize_class, fi->class,
0);
}
fieldtype = uf->fieldref->parseddesc.fd->type;
disp = 0;
- codegen_add_patch_ref(cd, PATCHER_get_putfield, uf, 0);
+ patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
}
else {
fi = iptr->sx.s23.s3.fmiref->p.field;
s2 = emit_load_s2(jd, iptr, REG_FTMP2);
if (INSTRUCTION_IS_UNRESOLVED(iptr))
- codegen_add_patch_ref(cd, PATCHER_get_putfield, uf, 0);
+ patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
/* implicit null-pointer check */
switch (fieldtype) {
fieldtype = uf->fieldref->parseddesc.fd->type;
disp = 0;
- codegen_add_patch_ref(cd, PATCHER_get_putfield, uf, 0);
+ patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
}
else {
fi = iptr->sx.s23.s3.fmiref->p.field;
if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
unresolved_class *uc = iptr->sx.s23.s2.uc;
- codegen_add_patch_ref(cd, PATCHER_resolve_class, uc, 0);
+ patcher_add_patch_ref(jd, PATCHER_resolve_class, uc, 0);
}
#endif /* ENABLE_VERIFIER */
if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
unresolved_class *uc = iptr->sx.s23.s2.uc;
- codegen_add_patch_ref(cd, PATCHER_resolve_class, uc, 0);
+ patcher_add_patch_ref(jd, PATCHER_resolve_class, uc, 0);
}
#endif /* ENABLE_VERIFIER */
goto nowperformreturn;
if (lm == NULL) {
disp = dseg_add_unique_address(cd, um);
- codegen_add_patch_ref(cd, PATCHER_invokestatic_special,
+ patcher_add_patch_ref(jd, PATCHER_invokestatic_special,
um, disp);
}
else
case ICMD_INVOKEVIRTUAL:
if (lm == NULL) {
- codegen_add_patch_ref(cd, PATCHER_invokevirtual, um, 0);
+ patcher_add_patch_ref(jd, PATCHER_invokevirtual, um, 0);
s1 = 0;
}
case ICMD_INVOKEINTERFACE:
if (lm == NULL) {
- codegen_add_patch_ref(cd, PATCHER_invokeinterface, um, 0);
+ patcher_add_patch_ref(jd, PATCHER_invokeinterface, um, 0);
s1 = 0;
s2 = 0;
disp = dseg_add_unique_s4(cd, 0); /* super->flags */
- codegen_add_patch_ref(cd, PATCHER_resolve_classref_to_flags,
+ patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
iptr->sx.s23.s3.c.ref,
disp);
if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
if (super == NULL) {
- codegen_add_patch_ref(cd,
+ patcher_add_patch_ref(jd,
PATCHER_checkcast_interface,
iptr->sx.s23.s3.c.ref,
0);
disp = dseg_add_unique_address(cd, NULL);
- codegen_add_patch_ref(cd,
+ patcher_add_patch_ref(jd,
PATCHER_resolve_classref_to_vftbl,
iptr->sx.s23.s3.c.ref,
disp);
if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
disp = dseg_add_unique_address(cd, NULL);
- codegen_add_patch_ref(cd,
+ patcher_add_patch_ref(jd,
PATCHER_resolve_classref_to_classinfo,
iptr->sx.s23.s3.c.ref,
disp);
disp = dseg_add_unique_s4(cd, 0); /* super->flags */
- codegen_add_patch_ref(cd, PATCHER_resolve_classref_to_flags,
+ patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
iptr->sx.s23.s3.c.ref, disp);
M_ILD(REG_ITMP3, REG_PV, disp);
if (d == REG_ITMP2)
M_CLR(d);
- codegen_add_patch_ref(cd,
+ patcher_add_patch_ref(jd,
PATCHER_instanceof_interface,
iptr->sx.s23.s3.c.ref, 0);
}
disp = dseg_add_unique_address(cd, NULL);
- codegen_add_patch_ref(cd, PATCHER_resolve_classref_to_vftbl,
+ patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
iptr->sx.s23.s3.c.ref,
disp);
}
if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
disp = dseg_add_unique_address(cd, 0);
- codegen_add_patch_ref(cd, PATCHER_resolve_classref_to_classinfo,
+ patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
iptr->sx.s23.s3.c.ref,
disp);
}
/* generate stubs */
- emit_patcher_stubs(jd);
+ emit_patcher_traps(jd);
REPLACEMENT_EMIT_STUBS(jd);
/* everything's ok */
#if !defined(WITH_STATIC_CLASSPATH)
if (f == NULL)
- codegen_add_patch_ref(cd, PATCHER_resolve_native_function, m, funcdisp);
+ patcher_add_patch_ref(jd, PATCHER_resolve_native_function, m, funcdisp);
#endif
#if defined(ENABLE_GC_CACAO)
/* generate patcher stubs */
- emit_patcher_stubs(jd);
+ emit_patcher_traps(jd);
}
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: emit.c 8123 2007-06-20 23:50:55Z michi $
+ $Id: emit.c 8186 2007-07-05 23:48:16Z michi $
*/
#include "vm/jit/dseg.h"
#include "vm/jit/emit-common.h"
#include "vm/jit/jit.h"
+#include "vm/jit/patcher-common.h"
#include "vm/jit/replace.h"
#include "vmcore/options.h"
}
-/* emit_patcher_stubs **********************************************************
+/* emit_patcher_traps **********************************************************
- Generates the code for the patcher stubs.
+ Generates the code for the patcher traps.
*******************************************************************************/
-void emit_patcher_stubs(jitdata *jd)
+void emit_patcher_traps(jitdata *jd)
{
codegendata *cd;
- patchref *pref;
- u4 mcode;
+ codeinfo *code;
+ patchref_t *pr;
u1 *savedmcodeptr;
u1 *tmpmcodeptr;
- s4 targetdisp;
- s4 disp;
/* get required compiler data */
- cd = jd->cd;
-
- /* generate code patching stub call code */
-
- targetdisp = 0;
+ cd = jd->cd;
+ code = jd->code;
- for (pref = cd->patchrefs; pref != NULL; pref = pref->next) {
- /* check code segment size */
+ /* generate patcher traps code */
- MCODECHECK(100);
+ for (pr = list_first_unsynced(code->patchers); pr != NULL; pr = list_next_unsynced(code->patchers, pr)) {
/* Get machine code which is patched back in later. The
- call is 1 instruction word long. */
-
- tmpmcodeptr = (u1 *) (cd->mcodebase + pref->branchpos);
+ trap is 1 instruction word long. */
- mcode = *((u4 *) tmpmcodeptr);
+ tmpmcodeptr = (u1 *) (cd->mcodebase + pr->mpc);
+ pr->mcode = *((u4 *) tmpmcodeptr);
- /* Patch in the call to call the following code (done at
+ /* Patch in the trap to call the signal handler (done at
compile time). */
savedmcodeptr = cd->mcodeptr; /* save current mcodeptr */
cd->mcodeptr = tmpmcodeptr; /* set mcodeptr to patch position */
- disp = ((u4 *) savedmcodeptr) - (((u4 *) tmpmcodeptr) + 1);
- M_BSR(REG_ITMP3, disp);
+ M_ALD_INTERN(REG_RESULT, REG_ZERO, EXCEPTION_HARDWARE_PATCHER);
cd->mcodeptr = savedmcodeptr; /* restore the current mcodeptr */
-
- /* create stack frame */
-
- M_LSUB_IMM(REG_SP, 6 * 8, REG_SP);
-
- /* move return address onto stack */
-
- M_AST(REG_ITMP3, REG_SP, 5 * 8);
-
- /* move pointer to java_objectheader onto stack */
-
-#if defined(ENABLE_THREADS)
- /* create a virtual java_objectheader */
-
- (void) dseg_add_unique_address(cd, NULL); /* flcword */
- (void) dseg_add_unique_address(cd, lock_get_initial_lock_word());
- disp = dseg_add_unique_address(cd, NULL); /* vftbl */
-
- M_LDA(REG_ITMP3, REG_PV, disp);
- M_AST(REG_ITMP3, REG_SP, 4 * 8);
-#else
- /* nothing to do */
-#endif
-
- /* move machine code onto stack */
-
- disp = dseg_add_s4(cd, mcode);
- M_ILD(REG_ITMP3, REG_PV, disp);
- M_IST(REG_ITMP3, REG_SP, 3 * 8);
-
- /* move class/method/field reference onto stack */
-
- disp = dseg_add_address(cd, pref->ref);
- M_ALD(REG_ITMP3, REG_PV, disp);
- M_AST(REG_ITMP3, REG_SP, 2 * 8);
-
- /* move data segment displacement onto stack */
-
- disp = dseg_add_s4(cd, pref->disp);
- M_ILD(REG_ITMP3, REG_PV, disp);
- M_IST(REG_ITMP3, REG_SP, 1 * 8);
-
- /* move patcher function pointer onto stack */
-
- disp = dseg_add_functionptr(cd, pref->patcher);
- M_ALD(REG_ITMP3, REG_PV, disp);
- M_AST(REG_ITMP3, REG_SP, 0 * 8);
-
- if (targetdisp == 0) {
- targetdisp = ((u4 *) cd->mcodeptr) - ((u4 *) cd->mcodebase);
-
- disp = dseg_add_functionptr(cd, asm_patcher_wrapper);
- M_ALD(REG_ITMP3, REG_PV, disp);
- M_JMP(REG_ZERO, REG_ITMP3);
- }
- else {
- disp = (((u4 *) cd->mcodebase) + targetdisp) -
- (((u4 *) cd->mcodeptr) + 1);
-
- M_BR(disp);
- }
}
}
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: md-os.c 8178 2007-07-05 11:13:20Z michi $
+ $Id: md-os.c 8186 2007-07-05 23:48:16Z michi $
*/
/* set registers */
- _mc->sc_regs[REG_ITMP1_XPTR] = (ptrint) e;
- _mc->sc_regs[REG_ITMP2_XPC] = (ptrint) xpc;
- _mc->sc_pc = (ptrint) asm_handle_exception;
+ if (e != NULL) {
+ _mc->sc_regs[REG_ITMP1_XPTR] = (ptrint) e;
+ _mc->sc_regs[REG_ITMP2_XPC] = (ptrint) xpc;
+ _mc->sc_pc = (ptrint) asm_handle_exception;
+ }
}
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: patcher.c 7596 2007-03-28 21:05:53Z twisti $
+ $Id: patcher.c 8186 2007-07-05 23:48:16Z michi $
*/
#include "vm/initialize.h"
#include "vm/jit/asmpart.h"
-#include "vm/jit/patcher.h"
+#include "vm/jit/patcher-common.h"
#include "vm/jit/md.h"
#include "vm/jit/methodheader.h"
#include "vm/jit/stacktrace.h"
#include "vm/resolve.h"
-/* patcher_wrapper *************************************************************
+#define PATCH_BACK_ORIGINAL_MCODE \
+ *((u4 *) pr->mpc) = (u4) pr->mcode; \
+ md_icacheflush(NULL, 0);
- Wrapper for all patchers. It also creates the stackframe info
- structure.
-
- If the return value of the patcher function is false, it gets the
- exception object, clears the exception pointer and returns the
- exception.
-
-*******************************************************************************/
-
-java_objectheader *patcher_wrapper(u1 *sp, u1 *pv, u1 *ra)
-{
- stackframeinfo sfi;
- u1 *xpc;
- java_objectheader *o;
- u4 mcode;
- functionptr f;
- bool result;
- java_objectheader *e;
-
- /* define the patcher function */
-
- bool (*patcher_function)(u1 *);
-
- assert(pv != NULL);
-
- /* get stuff from the stack */
-
- xpc = (u1 *) *((ptrint *) (sp + 5 * 8));
- o = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
- f = (functionptr) *((ptrint *) (sp + 0 * 8));
-
- /* calculate and set the new return address */
-
- 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;
-
- /* create the stackframeinfo */
-
- stacktrace_create_extern_stackframeinfo(&sfi, pv, sp + 6 * 8, ra, xpc);
-
- /* call the proper patcher function */
-
- result = (patcher_function)(sp);
-
- /* remove the stackframeinfo */
-
- 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 */
-
- mcode = *((u4 *) (sp + 3 * 8));
-
- *((u4 *) xpc) = mcode;
-
- /* synchronize instruction cache */
-
- md_icacheflush(NULL, 0);
-
- PATCHER_MARK_PATCHED_MONITOREXIT;
-
- return NULL;
-}
/* patcher_initialize_class ****************************************************
*******************************************************************************/
-bool patcher_initialize_class(u1 *sp)
+bool patcher_initialize_class(patchref_t *pr)
{
classinfo *c;
/* get stuff from the stack */
- c = (classinfo *) *((ptrint *) (sp + 2 * 8));
+ c = (classinfo *) pr->ref;
/* check if the class is initialized */
if (!initialize_class(c))
return false;
+ PATCH_BACK_ORIGINAL_MCODE;
+
return true;
}
*******************************************************************************/
#ifdef ENABLE_VERIFIER
-bool patcher_resolve_class(u1 *sp)
+bool patcher_resolve_class(patchref_t *pr)
{
unresolved_class *uc;
/* get stuff from the stack */
- uc = (unresolved_class *) *((ptrint *) (sp + 2 * 8));
+ uc = (unresolved_class *) pr->ref;
/* resolve the class and check subtype constraints */
if (!resolve_class_eager_no_access_check(uc))
return false;
+ PATCH_BACK_ORIGINAL_MCODE;
+
return true;
}
#endif /* ENABLE_VERIFIER */
*******************************************************************************/
-bool patcher_resolve_classref_to_classinfo(u1 *sp)
+bool patcher_resolve_classref_to_classinfo(patchref_t *pr)
{
constant_classref *cr;
- s4 disp;
- u1 *pv;
+ u1 *datap;
classinfo *c;
/* get stuff from the stack */
- cr = (constant_classref *) *((ptrint *) (sp + 2 * 8));
- disp = *((s4 *) (sp + 1 * 8));
- pv = (u1 *) *((ptrint *) (sp + 0 * 8));
+ cr = (constant_classref *) pr->ref;
+ datap = (u1 *) pr->datap;
/* get the classinfo */
if (!(c = resolve_classref_eager(cr)))
return false;
+ PATCH_BACK_ORIGINAL_MCODE;
+
/* patch the classinfo pointer */
- *((ptrint *) (pv + disp)) = (ptrint) c;
+ *((ptrint *) datap) = (ptrint) c;
return true;
}
*******************************************************************************/
-bool patcher_resolve_classref_to_vftbl(u1 *sp)
+bool patcher_resolve_classref_to_vftbl(patchref_t *pr)
{
constant_classref *cr;
- s4 disp;
- u1 *pv;
+ u1 *datap;
classinfo *c;
/* get stuff from the stack */
- cr = (constant_classref *) *((ptrint *) (sp + 2 * 8));
- disp = *((s4 *) (sp + 1 * 8));
- pv = (u1 *) *((ptrint *) (sp + 0 * 8));
+ cr = (constant_classref *) pr->ref;
+ datap = (u1 *) pr->datap;
/* get the fieldinfo */
if (!(c = resolve_classref_eager(cr)))
return false;
+ PATCH_BACK_ORIGINAL_MCODE;
+
/* patch super class' vftbl */
- *((ptrint *) (pv + disp)) = (ptrint) c->vftbl;
+ *((ptrint *) datap) = (ptrint) c->vftbl;
return true;
}
*******************************************************************************/
-bool patcher_resolve_classref_to_flags(u1 *sp)
+bool patcher_resolve_classref_to_flags(patchref_t *pr)
{
constant_classref *cr;
- s4 disp;
- u1 *pv;
+ u1 *datap;
classinfo *c;
/* get stuff from the stack */
- cr = (constant_classref *) *((ptrint *) (sp + 2 * 8));
- disp = *((s4 *) (sp + 1 * 8));
- pv = (u1 *) *((ptrint *) (sp + 0 * 8));
+ cr = (constant_classref *) pr->ref;
+ datap = (u1 *) pr->datap;
/* get the fieldinfo */
if (!(c = resolve_classref_eager(cr)))
return false;
+ PATCH_BACK_ORIGINAL_MCODE;
+
/* patch class flags */
- *((s4 *) (pv + disp)) = (s4) c->flags;
+ *((s4 *) datap) = (s4) c->flags;
return true;
}
*******************************************************************************/
#if !defined(WITH_STATIC_CLASSPATH)
-bool patcher_resolve_native_function(u1 *sp)
+bool patcher_resolve_native_function(patchref_t *pr)
{
methodinfo *m;
- s4 disp;
- u1 *pv;
+ u1 *datap;
functionptr f;
/* get stuff from the stack */
- m = (methodinfo *) *((ptrint *) (sp + 2 * 8));
- disp = *((s4 *) (sp + 1 * 8));
- pv = (u1 *) *((ptrint *) (sp + 0 * 8));
+ m = (methodinfo *) pr->ref;
+ datap = (u1 *) pr->datap;
/* resolve native function */
if (!(f = native_resolve_function(m)))
return false;
+ PATCH_BACK_ORIGINAL_MCODE;
+
/* patch native function pointer */
- *((ptrint *) (pv + disp)) = (ptrint) f;
+ *((ptrint *) datap) = (ptrint) f;
return true;
}
*******************************************************************************/
-bool patcher_get_putstatic(u1 *sp)
+bool patcher_get_putstatic(patchref_t *pr)
{
unresolved_field *uf;
- s4 disp;
- u1 *pv;
+ u1 *datap;
fieldinfo *fi;
/* get stuff from the stack */
- uf = (unresolved_field *) *((ptrint *) (sp + 2 * 8));
- disp = *((s4 *) (sp + 1 * 8));
- pv = (u1 *) *((ptrint *) (sp + 0 * 8));
+ uf = (unresolved_field *) pr->ref;
+ datap = (u1 *) pr->datap;
/* get the fieldinfo */
if (!initialize_class(fi->class))
return false;
+ PATCH_BACK_ORIGINAL_MCODE;
+
/* patch the field value's address */
- *((ptrint *) (pv + disp)) = (ptrint) &(fi->value);
+ *((ptrint *) datap) = (ptrint) &(fi->value);
return true;
}
*******************************************************************************/
-bool patcher_get_putfield(u1 *sp)
+bool patcher_get_putfield(patchref_t *pr)
{
u1 *ra;
unresolved_field *uf;
fieldinfo *fi;
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
- uf = (unresolved_field *) *((ptrint *) (sp + 2 * 8));
+ ra = (u1 *) pr->mpc;
+ uf = (unresolved_field *) pr->ref;
/* get the fieldinfo */
if (!(fi = resolve_field_eager(uf)))
return false;
+ PATCH_BACK_ORIGINAL_MCODE;
+
/* if we show disassembly, we have to skip the nop */
- if (opt_shownops) {
- /* patch the field's offset into the instruction */
+ if (opt_shownops)
+ ra = ra + 4;
+
+ /* 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 *) ra) |= (s2) (fi->offset & 0x0000ffff);
- *((u4 *) (sp + 3 * 8)) |= (s2) (fi->offset & 0x0000ffff);
- }
+ md_icacheflush(NULL, 0);
return true;
}
******************************************************************************/
-bool patcher_invokestatic_special(u1 *sp)
+bool patcher_invokestatic_special(patchref_t *pr)
{
unresolved_method *um;
- s4 disp;
- u1 *pv;
+ u1 *datap;
methodinfo *m;
/* get stuff from the stack */
- um = (unresolved_method *) *((ptrint *) (sp + 2 * 8));
- disp = *((s4 *) (sp + 1 * 8));
- pv = (u1 *) *((ptrint *) (sp + 0 * 8));
+ um = (unresolved_method *) pr->ref;
+ datap = (u1 *) pr->datap;
/* get the fieldinfo */
if (!(m = resolve_method_eager(um)))
return false;
+ PATCH_BACK_ORIGINAL_MCODE;
+
/* patch stubroutine */
- *((ptrint *) (pv + disp)) = (ptrint) m->stubroutine;
+ *((ptrint *) datap) = (ptrint) m->stubroutine;
return true;
}
*******************************************************************************/
-bool patcher_invokevirtual(u1 *sp)
+bool patcher_invokevirtual(patchref_t *pr)
{
u1 *ra;
unresolved_method *um;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
- um = (unresolved_method *) *((ptrint *) (sp + 2 * 8));
+ ra = (u1 *) pr->mpc;
+ um = (unresolved_method *) pr->ref;
/* get the fieldinfo */
if (!(m = resolve_method_eager(um)))
return false;
+ PATCH_BACK_ORIGINAL_MCODE;
+
/* if we show disassembly, we have to skip the nop */
if (opt_shownops)
*((s4 *) (ra + 4)) |= (s4) ((OFFSET(vftbl_t, table[0]) +
sizeof(methodptr) * m->vftblindex) & 0x0000ffff);
+ md_icacheflush(NULL, 0);
+
return true;
}
*******************************************************************************/
-bool patcher_invokeinterface(u1 *sp)
+bool patcher_invokeinterface(patchref_t *pr)
{
u1 *ra;
unresolved_method *um;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
- um = (unresolved_method *) *((ptrint *) (sp + 2 * 8));
+ ra = (u1 *) pr->mpc;
+ um = (unresolved_method *) pr->ref;
/* get the fieldinfo */
if (!(m = resolve_method_eager(um)))
return false;
+ PATCH_BACK_ORIGINAL_MCODE;
+
/* if we show disassembly, we have to skip the nop */
if (opt_shownops)
*((s4 *) (ra + 4 + 4)) |=
(s4) ((sizeof(methodptr) * (m - m->class->methods)) & 0x0000ffff);
+ md_icacheflush(NULL, 0);
+
return true;
}
*******************************************************************************/
-bool patcher_checkcast_interface(u1 *sp)
+bool patcher_checkcast_interface(patchref_t *pr)
{
u1 *ra;
constant_classref *cr;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
- cr = (constant_classref *) *((ptrint *) (sp + 2 * 8));
+ ra = (u1 *) pr->mpc;
+ cr = (constant_classref *) pr->ref;
/* get the fieldinfo */
if (!(c = resolve_classref_eager(cr)))
return false;
+ PATCH_BACK_ORIGINAL_MCODE;
+
/* if we show disassembly, we have to skip the nop */
if (opt_shownops)
*((s4 *) (ra + 5 * 4)) |= (s4) ((OFFSET(vftbl_t, interfacetable[0]) -
c->index * sizeof(methodptr*)) & 0x0000ffff);
+ md_icacheflush(NULL, 0);
+
return true;
}
*******************************************************************************/
-bool patcher_instanceof_interface(u1 *sp)
+bool patcher_instanceof_interface(patchref_t *pr)
{
u1 *ra;
constant_classref *cr;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
- cr = (constant_classref *) *((ptrint *) (sp + 2 * 8));
+ ra = (u1 *) pr->mpc;
+ cr = (constant_classref *) pr->ref;
/* get the fieldinfo */
if (!(c = resolve_classref_eager(cr)))
return false;
+ PATCH_BACK_ORIGINAL_MCODE;
+
/* if we show disassembly, we have to skip the nop */
if (opt_shownops)
*((s4 *) (ra + 4 * 4)) |= (s4) ((OFFSET(vftbl_t, interfacetable[0]) -
c->index * sizeof(methodptr*)) & 0x0000ffff);
+ md_icacheflush(NULL, 0);
+
return true;
}
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: md.c 7653 2007-04-03 14:34:23Z twisti $
+ $Id: md.c 8185 2007-07-05 21:34:47Z michi $
*/
assert((mcode & 0x00800000) == 0x00800000);
+ /* return NULL if no mptr was specified (used for replacement) */
+
+ if (mptr == NULL)
+ return NULL;
+
/* we loaded from REG_METHODPTR */
pa = mptr + offset;
#endif /* defined(ENABLE_REPLACEMENT) */
-/* code_get_stack_frame_size ***************************************************
-
- Return the number of stack slots that the stack frame of the given code
- comprises.
-
- IMPORTANT: The return value does *not* include the saved return address
- slot, although it is part of non-leaf stack frames on RISC
- architectures. The rationale behind this is that the saved
- return address is never moved or changed by replacement, and
- this way CISC and RISC architectures can be treated the same.
- (See also doc/stack_frames.txt.)
-
- IN:
- code.............the codeinfo of the code in question
- (must be != NULL)
-
- RETURN VALUE:
- the number of stack slots
-
-*******************************************************************************/
-
-#if defined(ENABLE_REPLACEMENT)
-int code_get_stack_frame_size(codeinfo *code)
-{
-#if 0
- int count;
-
- assert(code);
-
- /* slots allocated by register allocator plus saved registers */
-
-#ifdef HAS_4BYTE_STACKSLOT
- count = code->memuse + code->savedintcount + 2*code->savedfltcount;
-#else
- count = code->memuse + code->savedintcount + code->savedfltcount;
-#endif
-
- /* add slots needed in synchronized methods */
-
- count += code_get_sync_slot_count(code);
-
- /* keep stack aligned */
-
-#if defined(__X86_64__)
- /* the x86_64 codegen only aligns the stack in non-leaf methods */
- if (!code->isleafmethod || opt_verbosecall)
- count |= 1; /* even when return address is added */
-#endif
-
- /* XXX align stack on alpha */
-#if defined(__MIPS__)
- if (code->isleafmethod)
- count = (count + 1) & ~1;
- else
- count |= 1; /* even when return address is added */
-#endif
-
-#if defined(__POWERPC__)
- /* keep stack 16-byte aligned */
- count = (count + 3) & ~3;
-#endif
-
- return count;
-#endif
-
- return code->stackframesize;
-}
-#endif /* defined(ENABLE_REPLACEMENT) */
-
-
/* code_codeinfo_free **********************************************************
Free the memory used by a codeinfo.
#if defined(ENABLE_REPLACEMENT)
int code_get_sync_slot_count(codeinfo *code);
-int code_get_stack_frame_size(codeinfo *code);
#endif /* defined(ENABLE_REPLACEMENT) */
void code_free_code_of_method(methodinfo *m);
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: patcher.h 8160 2007-06-28 01:52:19Z michi $
+ $Id: patcher.h 8186 2007-07-05 23:48:16Z michi $
*/
#include "vm/global.h"
-#if defined(__ARM__)
+#if defined(__ALPHA__) || defined(__ARM__)
# error "you should no longer include this file"
#else
/* calculate base stack pointer */
- basesp = sp + code_get_stack_frame_size(code);
+ basesp = sp + code->stackframesize;
/* create the source frame */
sp = (stackslot_t *) es->sp;
- basesp = sp + code_get_stack_frame_size(code);
+ basesp = sp + code->stackframesize;
/* in some cases the top stack slot is passed in REG_ITMP1 */
if (es->code) {
methoddesc *md = es->code->m->parseddesc;
- slots = code_get_stack_frame_size(es->code);
+ slots = es->code->stackframesize;
extraslots = 1 + md->memuse;
}
else