from data segment now.
* src/vm/jit/patcher-common.c (patcher_resolve_native_function): Implemented
generalized version.
* src/vm/jit/alpha/patcher.c (patcher_resolve_native_function): Removed
obsolete function.
* src/vm/jit/arm/patcher.c: Likewise.
* src/vm/jit/i386/patcher.c: Likewise.
* src/vm/jit/mips/patcher.c: Likewise.
* src/vm/jit/powerpc/patcher.c: Likewise.
* src/vm/jit/powerpc64/patcher.c: Likewise.
* src/vm/jit/s390/patcher.c: Likewise.
}
-/* patcher_resolve_native_function *********************************************
-
- XXX
-
-*******************************************************************************/
-
-bool patcher_resolve_native_function(patchref_t *pr)
-{
- methodinfo *m;
- u1 *datap;
- functionptr f;
-
- /* get stuff from the stack */
-
- 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 *) datap) = (ptrint) f;
-
- return true;
-}
-
-
/* patcher_get_putstatic *******************************************************
Machine code:
}
-/* patcher_resolve_native_function *********************************************
-
- XXX
-
-*******************************************************************************/
-
-bool patcher_resolve_native_function(patchref_t *pr)
-{
- methodinfo *m;
- u1 *datap;
- functionptr f;
-
- /* get stuff from the stack */
-
- 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 *) datap) = (ptrint) f;
-
- return true;
-}
-
-
/*
* These are local overrides for various environment variables in Emacs.
* Please do not remove this and leave it at the end of the file, where
s4 i, j; /* count variables */
s4 t;
s4 s1, s2;
- s4 disp;
+ s4 disp;
+ s4 funcdisp;
/* get required compiler data */
/* get function address (this must happen before the stackframeinfo) */
- if (f == NULL)
- patcher_add_patch_ref(jd, PATCHER_resolve_native_function, m, 0);
+ funcdisp = dseg_add_functionptr(cd, f);
- M_AST_IMM((ptrint) f, REG_SP, 4 * 4);
+ if (f == NULL)
+ patcher_add_patch_ref(jd, PATCHER_resolve_native_function, m, funcdisp);
/* Mark the whole fpu stack as free for native functions (only for saved */
/* register count == 0). */
if (m->flags & ACC_STATIC)
M_MOV(REG_RESULT, REG_ITMP2);
- M_ALD(REG_ITMP3, REG_SP, 4 * 4);
-
/* copy arguments into new stackframe */
for (i = md->paramcount - 1, j = i + nativeparams; i >= 0; i--, j--) {
/* call the native function */
+ emit_mov_imm_reg(cd, 0, REG_ITMP3);
+ dseg_adddata(cd);
+ M_ALD(REG_ITMP3, REG_ITMP3, funcdisp);
M_CALL(REG_ITMP3);
/* save return value */
}
-/* patcher_resolve_native_function *********************************************
-
- Is used in native stub.
-
- Machine code:
-
- <patched call position>
- c7 44 24 04 28 90 01 40 movl $0x40019028,0x4(%esp)
-
-*******************************************************************************/
-
-bool patcher_resolve_native_function(patchref_t *pr)
-{
- u1 *ra;
- methodinfo *m;
- functionptr f;
-
- /* get stuff from the stack */
-
- ra = (u1 *) pr->mpc;
- m = (methodinfo *) pr->ref;
-
- /* resolve native function */
-
- if (!(f = native_resolve_function(m)))
- return false;
-
- PATCH_BACK_ORIGINAL_MCODE;
-
- /* if we show disassembly, we have to skip the nop's */
-
- if (opt_shownops)
- ra = ra + PATCHER_CALL_SIZE;
-
- /* patch native function pointer */
-
- *((ptrint *) (ra + 4)) = (ptrint) f;
-
- return true;
-}
-
-
/*
* These are local overrides for various environment variables in Emacs.
* Please do not remove this and leave it at the end of the file, where
}
-/* patcher_resolve_native ******************************************************
-
- XXX
-
-*******************************************************************************/
-
-bool patcher_resolve_native_function(patchref_t *pr)
-{
- methodinfo *m;
- u1 *datap;
- functionptr f;
-
- /* get stuff from the stack */
-
- 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 *) datap) = (ptrint) f;
-
- /* synchronize data cache */
-
- md_dcacheflush(datap, SIZEOF_VOID_P);
-
- return true;
-}
-
-
/* patcher_invokestatic_special ************************************************
Machine code:
#include "mm/memory.h"
+#include "native/native.h"
+
#include "threads/lock-common.h"
#include "toolbox/list.h"
#include "vm/jit/code.h"
#include "vm/jit/jit.h"
+#include "vm/jit/md.h"
#include "vm/jit/patcher-common.h"
#include "vmcore/options.h"
static patcher_function_list_t patcher_function_list[] = {
{ PATCHER_initialize_class, "initialize_class" },
{ PATCHER_resolve_class, "resolve_class" },
+ { PATCHER_resolve_native_function, "resolve_native_function" },
{ PATCHER_invokestatic_special, "invokestatic_special" },
{ PATCHER_invokevirtual, "invokevirtual" },
{ PATCHER_invokeinterface, "invokeinterface" },
#endif /* ENABLE_VERIFIER */
+/* patcher_resolve_native_function *********************************************
+
+ Resolves the native function for a given methodinfo.
+ This function patches one data segment word.
+
+*******************************************************************************/
+
+bool patcher_resolve_native_function(patchref_t *pr)
+{
+ methodinfo *m;
+ uint8_t *datap;
+ functionptr f;
+
+ /* get stuff from the patcher reference */
+
+ m = (methodinfo *) pr->ref;
+ datap = (uint8_t *) pr->datap;
+
+ /* resolve native function */
+
+ if (!(f = native_resolve_function(m)))
+ return false;
+
+ /* patch native function pointer */
+
+ *((intptr_t *) datap) = (intptr_t) f;
+
+ /* synchronize data cache */
+
+ md_dcacheflush(datap, SIZEOF_VOID_P);
+
+ /* patch back original code */
+
+ patcher_patch_code(pr);
+
+ return true;
+}
+
+
/*
* These are local overrides for various environment variables in Emacs.
* Please do not remove this and leave it at the end of the file, where
}
-/* patcher_resolve_native_function *********************************************
-
- XXX
-
-*******************************************************************************/
-
-bool patcher_resolve_native_function(patchref_t *pr)
-{
- methodinfo *m;
- u1 *datap;
- functionptr f;
-
- /* get stuff from the stack */
-
- 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 *) datap) = (ptrint) f;
-
- /* synchronize data cache */
-
- md_dcacheflush(datap, SIZEOF_VOID_P);
-
- return true;
-}
-
-
/* patcher_get_putstatic *******************************************************
Machine code:
}
-/* patcher_resolve_native_function *********************************************
-
- XXX
-
-*******************************************************************************/
-
-bool patcher_resolve_native_function(patchref_t *pr)
-{
- u1 *ra;
- u4 mcode;
- methodinfo *m;
- u1 *datap;
- functionptr f;
-
- /* get stuff from the stack */
-
-
- ra = (u1 *) pr->mpc;
- mcode = pr->mcode;
- m = (methodinfo *) pr->ref;
- datap = (u1 *) pr->datap;
-
- /* resolve native function */
-
- if (!(f = native_resolve_function(m)))
- return false;
-
- /* patch back original code */
-
- *((u4 *) ra) = mcode;
-
- /* synchronize instruction cache */
-
- md_icacheflush(ra, 4);
-
- /* patch native function pointer */
-
- *((ptrint *) datap) = (ptrint) f;
-
- /* synchronize data cache */
-
- md_dcacheflush(datap, SIZEOF_VOID_P);
-
- return true;
-}
-
-
/*
* These are local overrides for various environment variables in Emacs.
* Please do not remove this and leave it at the end of the file, where
}
-/* patcher_resolve_native ******************************************************
-
-*******************************************************************************/
-
-bool patcher_resolve_native_function(patchref_t *pr)
-{
- methodinfo *m;
- u1 *datap;
- functionptr f;
-
- PATCHER_TRACE;
-
- /* get stuff from the stack */
-
- 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 *) datap) = (ptrint) f;
-
- return true;
-}
-
-
/*
* These are local overrides for various environment variables in Emacs.
* Please do not remove this and leave it at the end of the file, where