* src/toolbox/list.hpp (DumpList): Made sort function accessible.
[cacao.git] / src / vm / jit / jit.cpp
index a664dd42e57b4c0572481848685a579385b81060..a8ac2b160a196c7f7c1873db3e80bf196fab7e86 100644 (file)
 
 #include "md.h"
 
-#include "mm/memory.h"
+#include "mm/memory.hpp"
 
-#include "native/native.h"
+#include "native/native.hpp"
 
-#include "toolbox/logging.h"
+#include "toolbox/logging.hpp"
 
 #include "threads/mutex.hpp"
 
-#include "vm/class.h"
+#include "vm/class.hpp"
 #include "vm/global.h"
 #include "vm/globals.hpp"
-#include "vm/initialize.h"
+#include "vm/initialize.hpp"
 #include "vm/loader.hpp"
-#include "vm/method.h"
+#include "vm/method.hpp"
 #include "vm/options.h"
 #include "vm/rt-timing.h"
 #include "vm/statistics.h"
 
 #include "vm/jit/cfg.h"
 
-#include "vm/jit/codegen-common.h"
+#include "vm/jit/codegen-common.hpp"
 #include "vm/jit/disass.h"
 #include "vm/jit/dseg.h"
 #include "vm/jit/jit.hpp"
-#include "vm/jit/parse.h"
+#include "vm/jit/parse.hpp"
 #include "vm/jit/reg.h"
 
-#include "vm/jit/show.h"
+#include "vm/jit/show.hpp"
 #include "vm/jit/stack.h"
 #include "vm/jit/stubs.hpp"
 
@@ -80,7 +80,7 @@
 #endif
 
 #if defined(ENABLE_INLINING)
-# include "vm/jit/inline/inline.h"
+# include "vm/jit/inline/inline.hpp"
 #endif
 
 #include "vm/jit/ir/bytecode.h"
@@ -99,7 +99,7 @@
 # include "vm/jit/python.h"
 #endif
 
-#include "vm/jit/verify/typecheck.h"
+#include "vm/jit/verify/typecheck.hpp"
 
 
 /* debug macros ***************************************************************/
@@ -176,7 +176,7 @@ void jit_init(void)
 
 #if defined(ENABLE_OPAGENT)
        if (opt_EnableOpagent)
-               OprofileAgent_initialize();
+               OprofileAgent::initialize();
 #endif
 }
 
@@ -191,7 +191,7 @@ void jit_close(void)
 {
 #if defined(ENABLE_OPAGENT)
        if (opt_EnableOpagent)
-               OprofileAgent_close();
+               OprofileAgent::close();
 #endif
 }
 
@@ -217,13 +217,13 @@ jitdata *jit_jitdata_new(methodinfo *m)
 
        /* allocate jitdata structure and fill it */
 
-       jd = DNEW(jitdata);
+       jd = (jitdata*) DumpMemory::allocate(sizeof(jitdata));
 
        jd->m     = m;
-       jd->cd    = DNEW(codegendata);
-       jd->rd    = DNEW(registerdata);
+       jd->cd    = (codegendata*) DumpMemory::allocate(sizeof(codegendata));
+       jd->rd    = (registerdata*) DumpMemory::allocate(sizeof(registerdata));
 #if defined(ENABLE_LOOP)
-       jd->ld    = DNEW(loopdata);
+       jd->ld    = (loopdata*) DumpMemory::allocate(sizeof(loopdata));
 #endif
 
        /* Allocate codeinfo memory from the heap as we need to keep them. */
@@ -271,7 +271,6 @@ u1 *jit_compile(methodinfo *m)
 {
        u1      *r;
        jitdata *jd;
-       int32_t  dumpmarker;
 
        STATISTICS(count_jit_calls++);
 
@@ -320,9 +319,8 @@ u1 *jit_compile(methodinfo *m)
                compilingtime_start();
 #endif
 
-       /* mark start of dump memory area */
-
-       DMARKER;
+       // Create new dump memory area.
+       DumpMemoryArea dma;
 
        /* create jitdata structure */
 
@@ -391,23 +389,11 @@ u1 *jit_compile(methodinfo *m)
                /* release codeinfo */
 
                code_codeinfo_free(jd->code);
-
-#if defined(ENABLE_PROFILING)
-               /* Release memory for basic block profiling information. */
-
-               if (JITDATA_HAS_FLAG_INSTRUMENT(jd))
-                       if (jd->code->bbfrequency != NULL)
-                               MFREE(jd->code->bbfrequency, u4, jd->code->basicblockcount);
-#endif
        }
        else {
                DEBUG_JIT_COMPILEVERBOSE("Running: ");
        }
 
-       /* release dump area */
-
-       DRELEASE;
-
 #if defined(ENABLE_STATISTICS)
        /* measure time */
 
@@ -417,7 +403,7 @@ u1 *jit_compile(methodinfo *m)
 
 #if defined(ENABLE_OPAGENT)
        if (opt_EnableOpagent)
-               OprofileAgent_newmethod(m);
+               OprofileAgent::newmethod(m);
 #endif
 
        /* leave the monitor */
@@ -441,7 +427,6 @@ u1 *jit_recompile(methodinfo *m)
        u1      *r;
        jitdata *jd;
        u1       optlevel;
-       int32_t  dumpmarker;
 
        /* check for max. optimization level */
 
@@ -465,9 +450,8 @@ u1 *jit_recompile(methodinfo *m)
                compilingtime_start();
 #endif
 
-       /* mark start of dump memory area */
-
-       DMARKER;
+       // Create new dump memory area.
+       DumpMemoryArea dma;
 
        /* create jitdata structure */
 
@@ -521,10 +505,6 @@ u1 *jit_recompile(methodinfo *m)
                code_codeinfo_free(jd->code);
        }
 
-       /* release dump area */
-
-       DRELEASE;
-
 #if defined(ENABLE_STATISTICS)
        /* measure time */
 
@@ -534,7 +514,7 @@ u1 *jit_recompile(methodinfo *m)
 
 #if defined(ENABLE_OPAGENT)
        if (opt_EnableOpagent)
-               OprofileAgent_newmethod(m);
+               OprofileAgent::newmethod(m);
 #endif
 
        DEBUG_JIT_COMPILEVERBOSE("Recompiling done: ");
@@ -581,17 +561,15 @@ static u1 *jit_compile_intern(jitdata *jd)
        show_filters_apply(jd->m);
 #endif
 
-       /* Handle native methods and create a native stub. */
-
+       // Handle native methods and create a native stub.
        if (m->flags & ACC_NATIVE) {
-               functionptr f;
-
-               f = native_method_resolve(m);
+               NativeMethods& nm = VM::get_current()->get_nativemethods();
+               void* f = nm.resolve_method(m);
 
                if (f == NULL)
                        return NULL;
 
-               code = NativeStub::generate(m, f);
+               code = NativeStub::generate(m, (functionptr) f);
 
                /* Native methods are never recompiled. */
                
@@ -759,7 +737,7 @@ static u1 *jit_compile_intern(jitdata *jd)
                        /*&& jd->exceptiontablelength == 0*/
                ) {
                        /*printf("=== %s ===\n", jd->m->name->text);*/
-                       jd->ls = DNEW(lsradata);
+                       jd->ls = (lsradata*) DumpMemory::allocate(sizeof(lsradata));
                        jd->ls = NULL;
                        ssa(jd);
                        /*lsra(jd);*/ regalloc(jd);
@@ -788,8 +766,10 @@ static u1 *jit_compile_intern(jitdata *jd)
           _must_ be done after loop optimization and register allocation,
           since they can change the basic block count. */
 
-       if (JITDATA_HAS_FLAG_INSTRUMENT(jd))
+       if (JITDATA_HAS_FLAG_INSTRUMENT(jd)) {
+               code->basicblockcount = jd->basicblockcount;
                code->bbfrequency = MNEW(u4, jd->basicblockcount);
+       }
 #endif
 
        DEBUG_JIT_COMPILEVERBOSE("Generating code: ");
@@ -989,17 +969,18 @@ codeinfo *jit_get_current_code(methodinfo *m)
 
 #if defined(ENABLE_JIT)
 #if !defined(JIT_COMPILER_VIA_SIGNAL)
-u1 *jit_asm_compile(methodinfo *m, u1 *mptr, u1 *sp, u1 *ra)
+extern "C" {
+void* jit_asm_compile(methodinfo *m, void* mptr, void* sp, void* ra)
 {
        stackframeinfo_t  sfi;
-       u1               *entrypoint;
-       u1               *pa;
-       ptrint           *p;
+       void             *entrypoint;
+       void             *pa;
+       uintptr_t        *p;
 
        /* create the stackframeinfo (subtract 1 from RA as it points to the */
        /* instruction after the call)                                       */
 
-       stacktrace_stackframeinfo_add(&sfi, NULL, sp, ra, ra-1);
+       stacktrace_stackframeinfo_add(&sfi, NULL, sp, ra, ((uint8_t*) ra) - 1);
 
        /* actually compile the method */
 
@@ -1020,9 +1001,9 @@ u1 *jit_asm_compile(methodinfo *m, u1 *mptr, u1 *sp, u1 *ra)
 
        /* patch the method entry point */
 
-       p = (ptrint *) pa;
+       p = (uintptr_t*) pa;
 
-       *p = (ptrint) entrypoint;
+       *p = (uintptr_t) entrypoint;
 
        /* flush the instruction cache */
 
@@ -1030,6 +1011,7 @@ u1 *jit_asm_compile(methodinfo *m, u1 *mptr, u1 *sp, u1 *ra)
 
        return entrypoint;
 }
+}
 #endif
 
 /* jit_compile_handle **********************************************************