* src/vm/jit/codegen-common.c (vm/builtin.h): Added.
authortwisti <none@none>
Thu, 19 Apr 2007 12:50:37 +0000 (12:50 +0000)
committertwisti <none@none>
Thu, 19 Apr 2007 12:50:37 +0000 (12:50 +0000)
(codegen_generate_stub_builtin): New function.
(codegen_generate_stub_native): Moved codegen_finish before statistics
generation, otherwise the numbers are wrong.
(codegen_stub_builtin_enter): New function.
(codegen_stub_builtin_exit): Likewise.

* src/vm/jit/codegen-common.h (vm/builtin.h): Added.
(codegen_generate_stub_builtin): Likewise.
(codegen_emit_stub_builtin): Likewise.
(codegen_stub_builtin_enter): Likewise.
(codegen_stub_builtin_exit): Likewise.

* src/vm/builtin.c (builtintable_init): Call
codegen_generate_stub_builtin when required.

--HG--
branch : exact-gc

src/vm/builtin.c
src/vm/jit/arm/asmpart.S
src/vm/jit/codegen-common.c
src/vm/jit/codegen-common.h

index 51a01df89274c789c9a7e342a8f8621f9229d44d..562c301192dda23c3a20fa2f1fc33d260b9541ee 100644 (file)
@@ -28,7 +28,7 @@
    calls instead of machine instructions, using the C calling
    convention.
 
-   $Id: builtin.c 7723 2007-04-16 18:03:08Z michi $
+   $Id: builtin.c 7764 2007-04-19 12:50:37Z twisti $
 
 */
 
@@ -171,6 +171,11 @@ static bool builtintable_init(void)
                bte->md = descriptor_pool_parse_method_descriptor(descpool,
                                                                                                                  bte->descriptor,
                                                                                                                  ACC_STATIC, NULL);
+
+               /* generate a builtin stub if we need one */
+
+               if (bte->flags & BUILTINTABLE_FLAG_STUB)
+                       codegen_generate_stub_builtin(bte);
        }
 
        for (bte = builtintable_automatic; bte->fp != NULL; bte++) {
index fae35ce6df7dc5499cfdff46ed2b20a7203295d3..99aac721406cb7a789bb6f69165cd1d7f543d9df 100644 (file)
@@ -22,7 +22,7 @@
    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 7688 2007-04-12 09:05:12Z michi $
 
 */
 
index 829625d72d1fed753a3737ca8b14807971dd9aa1..3504e0b68b8128b9cab8994e637ae6e101b7640e 100644 (file)
@@ -39,7 +39,7 @@
    memory. All functions writing values into the data area return the offset
    relative the begin of the code area (start of procedure).   
 
-   $Id: codegen-common.c 7732 2007-04-16 22:32:50Z michi $
+   $Id: codegen-common.c 7764 2007-04-19 12:50:37Z twisti $
 
 */
 
@@ -72,6 +72,7 @@
 
 #include "threads/threads-common.h"
 
+#include "vm/builtin.h"
 #include "vm/exceptions.h"
 #include "vm/stringlocal.h"
 
@@ -1017,6 +1018,72 @@ u1 *codegen_generate_stub_compiler(methodinfo *m)
 }
 
 
+/* codegen_generate_stub_builtin ***********************************************
+
+   Wrapper for codegen_emit_stub_builtin.
+
+   Returns:
+       Pointer to the entrypoint of the stub.
+
+*******************************************************************************/
+
+void codegen_generate_stub_builtin(builtintable_entry *bte)
+{
+       jitdata  *jd;
+       codeinfo *code;
+       s4        dumpsize;
+
+       /* mark dump memory */
+
+       dumpsize = dump_size();
+
+       jd = DNEW(jitdata);
+
+       jd->m     = NULL;
+       jd->cd    = DNEW(codegendata);
+       jd->rd    = NULL;
+       jd->flags = 0;
+
+       /* Allocate codeinfo memory from the heap as we need to keep them. */
+
+       jd->code  = code_codeinfo_new(NULL);
+
+       /* get required compiler data */
+
+       code = jd->code;
+
+       /* setup code generation stuff */
+
+       codegen_setup(jd);
+
+       /* generate the code */
+
+#if defined(ENABLE_JIT)
+# if defined(ENABLE_INTRP)
+       if (!opt_intrp)
+# endif
+               codegen_emit_stub_builtin(jd, bte);
+#endif
+
+       /* reallocate the memory and finish the code generation */
+
+       codegen_finish(jd);
+
+       /* set the stub entry point in the builtin table */
+
+       bte->stub = code->entrypoint;
+
+#if defined(ENABLE_STATISTICS)
+       if (opt_stat)
+               count_nstub_len += code->mcodelength;
+#endif
+
+       /* release memory */
+
+       dump_release(dumpsize);
+}
+
+
 /* codegen_generate_stub_native ************************************************
 
    Wrapper for codegen_emit_stub_native.
@@ -1118,15 +1185,15 @@ codeinfo *codegen_generate_stub_native(methodinfo *m, functionptr f)
        intrp_createnativestub(f, jd, nmd);
 #endif
 
+       /* reallocate the memory and finish the code generation */
+
+       codegen_finish(jd);
+
 #if defined(ENABLE_STATISTICS)
        if (opt_stat)
                count_nstub_len += code->mcodelength;
 #endif
 
-       /* reallocate the memory and finish the code generation */
-
-       codegen_finish(jd);
-
 #if !defined(NDEBUG)
        /* disassemble native stub */
 
@@ -1175,6 +1242,77 @@ void codegen_disassemble_nativestub(methodinfo *m, u1 *start, u1 *end)
 #endif
 
 
+/* codegen_stub_builtin_enter **************************************************
+
+   Prepares the stuff required for a builtin function call:
+
+   - adds a stackframe info structure to the chain, for stacktraces
+
+   The layout of the builtin stub stackframe should look like this:
+
+   +---------------------------+ <- SP (of parent Java function)
+   | return address            |
+   +---------------------------+
+   |                           |
+   | stackframe info structure |
+   |                           |
+   +---------------------------+
+   |                           |
+   | arguments (if any)        |
+   |                           |
+   +---------------------------+ <- SP (native stub)
+
+*******************************************************************************/
+
+void codegen_stub_builtin_enter(u1 *datasp, u1 *pv, u1 *sp, u1 *ra)
+{
+       stackframeinfo *sfi;
+
+       /* get data structures from stack */
+
+       sfi = (stackframeinfo *) (datasp - sizeof(stackframeinfo));
+
+       /* add a stackframeinfo to the chain */
+
+       stacktrace_create_native_stackframeinfo(sfi, pv, sp, ra);
+
+#if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
+       /* set the native world flag */
+
+       THREADOBJECT->flags |= THREAD_FLAG_IN_NATIVE;
+#endif
+}
+
+
+/* codegen_stub_builtin_exit ***************************************************
+
+   Removes the stuff required for a builtin function call.
+
+*******************************************************************************/
+
+void codegen_stub_builtin_exit(u1 *datasp)
+{
+       stackframeinfo     *sfi;
+       stackframeinfo    **psfi;
+
+       /* get data structures from stack */
+
+       sfi = (stackframeinfo *) (datasp - sizeof(stackframeinfo));
+
+       /* remove current stackframeinfo from chain */
+
+       psfi = &STACKFRAMEINFO;
+
+       *psfi = sfi->prev;
+
+#if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
+       /* clear the native world flag */
+
+       THREADOBJECT->flags &= ~THREAD_FLAG_IN_NATIVE;
+#endif
+}
+
+
 /* codegen_start_native_call ***************************************************
 
    Prepares the stuff required for a native (JNI) function call:
index d4d1e9b0609b72a5ea12889a1e98b15b966448b5..e07cb22e35063e0d61da8ec0b93e2d462625e4c0 100644 (file)
@@ -22,7 +22,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: codegen-common.h 7731 2007-04-16 22:24:30Z twisti $
+   $Id: codegen-common.h 7764 2007-04-19 12:50:37Z twisti $
 
 */
 
@@ -46,6 +46,7 @@ typedef struct linenumberref              linenumberref;
 #include "config.h"
 #include "vm/types.h"
 
+#include "vm/builtin.h"
 #include "vm/global.h"
 
 #include "vm/jit/dseg.h"
@@ -315,9 +316,11 @@ void codegen_disassemble_nativestub(methodinfo *m, u1 *start, u1 *end);
 /* stub functions */
 
 u1       *codegen_generate_stub_compiler(methodinfo *m);
+void      codegen_generate_stub_builtin(builtintable_entry *bte);
 codeinfo *codegen_generate_stub_native(methodinfo *m, functionptr f);
 
 void      codegen_emit_stub_compiler(jitdata *jd);
+void      codegen_emit_stub_builtin(jitdata *jd, builtintable_entry *bte);
 void      codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f);
 
 #if defined(ENABLE_INTRP)
@@ -328,6 +331,9 @@ u1 *intrp_createnativestub(functionptr f, jitdata *jd, methoddesc *md);
 void removecompilerstub(u1 *stub);
 void removenativestub(u1 *stub);
 
+void codegen_stub_builtin_enter(u1 *datasp, u1 *pv, u1 *sp, u1 *ra);
+void codegen_stub_builtin_exit(u1 *datasp);
+
 void codegen_start_native_call(u1 *datasp, u1 *pv, u1 *sp, u1 *ra);
 java_objectheader *codegen_finish_native_call(u1 *datasp);