* src/vm/jit/i386/codegen.c (codegen_emit_stub_native): Loads function pointer
authorMichael Starzinger <michi@complang.tuwien.ac.at>
Fri, 7 Sep 2007 23:09:48 +0000 (01:09 +0200)
committerMichael Starzinger <michi@complang.tuwien.ac.at>
Fri, 7 Sep 2007 23:09:48 +0000 (01:09 +0200)
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.

src/vm/jit/alpha/patcher.c
src/vm/jit/arm/patcher.c
src/vm/jit/i386/codegen.c
src/vm/jit/i386/patcher.c
src/vm/jit/mips/patcher.c
src/vm/jit/patcher-common.c
src/vm/jit/powerpc/patcher.c
src/vm/jit/powerpc64/patcher.c
src/vm/jit/s390/patcher.c

index e55761bc5caa1ca8ed0465287a6f30c09e6ab8b6..a8ec011797b3e6c95ea32700fc1fffe547f4a439 100644 (file)
@@ -190,38 +190,6 @@ bool patcher_resolve_classref_to_flags(patchref_t *pr)
 }
 
 
-/* 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:
index a4aebdf929b971e1c0b1a4eb522a5b5a209f2c6b..c8cbd55d2f99d01d4d0a54c8a1d1fbb49ffcfc5d 100644 (file)
@@ -481,38 +481,6 @@ bool patcher_resolve_classref_to_vftbl(patchref_t *pr)
 }
 
 
-/* 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
index d889f74ac93a5abbf7b9dcda373113b35b6c9263..adfd947375c9dc240ff5790bb48092ea1831c18b 100644 (file)
@@ -3678,7 +3678,8 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
        s4           i, j;                 /* count variables                    */
        s4           t;
        s4           s1, s2;
-       s4            disp;
+       s4           disp;
+       s4           funcdisp;
 
        /* get required compiler data */
 
@@ -3736,10 +3737,10 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
 
        /* 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).                                                  */
@@ -3779,8 +3780,6 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
        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--) {
@@ -3815,6 +3814,9 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
 
        /* 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 */
index 75f7f1c10b4206b048e65013032952b9d395e81d..c1d6b5b9d0c232e438ac4dab72ba530a5be3d8ba 100644 (file)
@@ -752,48 +752,6 @@ bool patcher_instanceof_class(patchref_t *pr)
 }
 
 
-/* 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
index 296b878b504fd9409dfde4db1c1d0dab0f78296f..11265f4ddb8e72d83af87cf676456b7b34688d29 100644 (file)
@@ -311,42 +311,6 @@ bool patcher_resolve_classref_to_flags(patchref_t *pr)
 }
 
 
-/* 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:
index ad40ad9ef9282c668c00d71104ff79e301dd8216..22ccc6a1b4d66857db299f8d328b2c2d11b57a67 100644 (file)
@@ -34,6 +34,8 @@
 
 #include "mm/memory.h"
 
+#include "native/native.h"
+
 #include "threads/lock-common.h"
 
 #include "toolbox/list.h"
@@ -46,6 +48,7 @@
 
 #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"
@@ -209,6 +212,7 @@ typedef struct patcher_function_list_t {
 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" },
@@ -360,6 +364,45 @@ bool patcher_resolve_class(patchref_t *pr)
 #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
index 0b6b3c520b2a073d35460d6fa0e4c0015f0968a3..a543d00a25592ac27efb00ad8639375e3faa9e4c 100644 (file)
@@ -217,42 +217,6 @@ bool patcher_resolve_classref_to_flags(patchref_t *pr)
 }
 
 
-/* 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:
index 6c874634a489a20da19659294da5461bafbe6404..e61b3627aa9de50d3446d44eb253eb8429c1eed6 100644 (file)
@@ -652,53 +652,6 @@ bool patcher_resolve_classref_to_flags(patchref_t *pr)
 }
 
 
-/* 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
index 78f7182ef1621ba0cfac93fcf6b7055f52e6a782..b3fdb897be554b8c60984fa20eae9f36893f2684 100644 (file)
@@ -475,38 +475,6 @@ bool patcher_checkcast_instanceof_interface(patchref_t *pr)
 }
 
 
-/* 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