* src/vm/jit/parse.cpp,
[cacao.git] / src / vm / jit / jit.cpp
index baada57fef79badded260c7f1e14953d491ba8aa..1dbb5c695c52c1b33d816289d32d55769d8767f9 100644 (file)
 
 #include "mm/memory.h"
 
-#include "native/native.h"
+#include "native/native.hpp"
 
 #include "toolbox/logging.h"
 
 #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/options.h"
 #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"
 
+#if defined(ENABLE_JITCACHE)
+# include "vm/jit/jitcache.hpp"
+#endif
+
 #if defined(ENABLE_OPAGENT)
 #include "vm/jit/oprofile-agent.hpp"
 #endif
@@ -176,7 +180,7 @@ void jit_init(void)
 
 #if defined(ENABLE_OPAGENT)
        if (opt_EnableOpagent)
-               OprofileAgent_initialize();
+               OprofileAgent::initialize();
 #endif
 }
 
@@ -191,7 +195,7 @@ void jit_close(void)
 {
 #if defined(ENABLE_OPAGENT)
        if (opt_EnableOpagent)
-               OprofileAgent_close();
+               OprofileAgent::close();
 #endif
 }
 
@@ -312,6 +316,17 @@ u1 *jit_compile(methodinfo *m)
 
        STATISTICS(count_methods++);
 
+#if defined (ENABLE_JITCACHE)
+
+       if (jitcache_load (m))
+       {
+               m->mutex->unlock();
+
+               return m->code->entrypoint;
+       }
+
+#endif
+
 #if defined(ENABLE_STATISTICS)
        /* measure time */
 
@@ -402,6 +417,10 @@ u1 *jit_compile(methodinfo *m)
                DEBUG_JIT_COMPILEVERBOSE("Running: ");
        }
 
+#if defined (ENABLE_JITCACHE)
+       jitcache_store(m);
+#endif
+
 #if defined(ENABLE_STATISTICS)
        /* measure time */
 
@@ -411,7 +430,7 @@ u1 *jit_compile(methodinfo *m)
 
 #if defined(ENABLE_OPAGENT)
        if (opt_EnableOpagent)
-               OprofileAgent_newmethod(m);
+               OprofileAgent::newmethod(m);
 #endif
 
        /* leave the monitor */
@@ -522,7 +541,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: ");
@@ -569,17 +588,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. */