configure.ac: Added AC_CHECK_ENABLE_OPAGENT.
[cacao.git] / src / vm / jit / jit.c
index ea9faea507a78b555716ad3f6522c667b906743f..295cebda93b41283476ea3970e5f34bd9a76f803 100644 (file)
 #include "vm/jit/show.h"
 #include "vm/jit/stack.h"
 
+#if defined(ENABLE_OPAGENT)
+#include "vm/jit/oprofile-agent.hpp"
+#endif
+
 #include "vm/jit/allocator/simplereg.h"
 #if defined(ENABLE_LSRA) && !defined(ENABLE_SSA)
 # include "vm/jit/allocator/lsra.h"
@@ -90,6 +94,7 @@
 #include "vm/jit/verify/typecheck.h"
 
 #include "vmcore/class.h"
+#include "vmcore/globals.hpp"
 #include "vmcore/loader.h"
 #include "vmcore/method.h"
 #include "vmcore/options.h"
@@ -209,6 +214,11 @@ void jit_init(void)
 #else
        intrp_md_init();
 #endif
+
+#if defined(ENABLE_OPAGENT)
+       if (opt_EnableOpagent)
+               OprofileAgent_initialize();
+#endif
 }
 
 
@@ -220,7 +230,10 @@ void jit_init(void)
 
 void jit_close(void)
 {
-       /* do nothing */
+#if defined(ENABLE_OPAGENT)
+       if (opt_EnableOpagent)
+               OprofileAgent_close();
+#endif
 }
 
 
@@ -390,8 +403,9 @@ u1 *jit_compile(methodinfo *m)
                jd->flags |= JITDATA_FLAG_VERBOSECALL;
 
 #if defined(ENABLE_REPLACEMENT) && defined(ENABLE_INLINING)
-       if (opt_Inline)
+       if (opt_Inline && (jd->m->hitcountdown > 0) && (jd->code->optlevel == 0)) {
                jd->flags |= JITDATA_FLAG_COUNTDOWN;
+       }
 #endif
 
 #if defined(ENABLE_JIT)
@@ -442,6 +456,11 @@ u1 *jit_compile(methodinfo *m)
                compilingtime_stop();
 #endif
 
+#if defined(ENABLE_OPAGENT)
+       if (opt_EnableOpagent)
+               OprofileAgent_newmethod(m);
+#endif
+
        /* leave the monitor */
 
        LOCK_MONITOR_EXIT(m);
@@ -554,6 +573,11 @@ u1 *jit_recompile(methodinfo *m)
                compilingtime_stop();
 #endif
 
+#if defined(ENABLE_OPAGENT)
+       if (opt_EnableOpagent)
+               OprofileAgent_newmethod(m);
+#endif
+
        DEBUG_JIT_COMPILEVERBOSE("Recompiling done: ");
 
        /* return pointer to the methods entry point */
@@ -640,7 +664,7 @@ static u1 *jit_compile_intern(jitdata *jd)
 
        RT_TIMING_GET_TIME(time_checks);
 
-#if defined(WITH_CLASSPATH_SUN)
+#if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
        /* Code for Sun's OpenJDK (see
           hotspot/src/share/vm/classfile/verifier.cpp
           (Verifier::is_eligible_for_verification)): Don't verify
@@ -684,12 +708,6 @@ static u1 *jit_compile_intern(jitdata *jd)
 
                DEBUG_JIT_COMPILEVERBOSE("Analysing done: ");
 
-               /* Build the CFG.  This has to be done after stack_analyse, as
-                  there happens the JSR elimination. */
-
-               if (!cfg_build(jd))
-                       return NULL;
-
 #ifdef ENABLE_VERIFIER
                if (JITDATA_HAS_FLAG_VERIFY(jd)) {
                        DEBUG_JIT_COMPILEVERBOSE("Typechecking: ");
@@ -727,13 +745,25 @@ static u1 *jit_compile_intern(jitdata *jd)
 
                /* inlining */
 
-#if defined(ENABLE_INLINING)
+#if defined(ENABLE_INLINING) && (!defined(ENABLE_ESCAPE) || 1)
                if (JITDATA_HAS_FLAG_INLINE(jd)) {
                        if (!inline_inline(jd))
                                return NULL;
                }
 #endif
 
+#if defined(ENABLE_SSA)
+               if (opt_lsra) {
+                       fix_exception_handlers(jd);
+               }
+#endif
+
+               /* Build the CFG.  This has to be done after stack_analyse, as
+                  there happens the JSR elimination. */
+
+               if (!cfg_build(jd))
+                       return NULL;
+
 #if defined(ENABLE_PROFILING)
                /* Basic block reordering.  I think this should be done after
                   if-conversion, as we could lose the ability to do the
@@ -763,12 +793,18 @@ static u1 *jit_compile_intern(jitdata *jd)
 # endif /* defined(ENABLE_LSRA) && !defined(ENABLE_SSA) */
 #if defined(ENABLE_SSA)
                /* allocate registers */
-               if ((opt_lsra) /*&& (strcmp(jd->m->name->text, "findClass") == 0 || jd->exceptiontablelength == 0)*/) {
+               if (
+                       (opt_lsra &&
+                       jd->code->optlevel > 0) 
+                       /* strncmp(jd->m->name->text, "hottie", 6) == 0*/
+                       /*&& jd->exceptiontablelength == 0*/
+               ) {
+                       /*printf("=== %s ===\n", jd->m->name->text);*/
                        jd->ls = DNEW(lsradata);
                        jd->ls = NULL;
                        ssa(jd);
                        /*lsra(jd);*/ regalloc(jd);
-                       eliminate_subbasicblocks(jd);
+                       /*eliminate_subbasicblocks(jd);*/
                        STATISTICS(count_methods_allocated_by_lsra++);
 
                } else