Merging 8179.
[cacao.git] / src / vm / jit / jit.c
index 09fc0c08919144dd114f29db14fd0780f6f2fcce..eaf8672745da0ed93dbe229dee54e41bec022c4c 100644 (file)
@@ -39,7 +39,6 @@
 #include "toolbox/logging.h"
 
 #include "threads/lock-common.h"
-#include "threads/threads-common.h"
 
 #include "vm/global.h"
 #include "vm/initialize.h"
@@ -176,6 +175,8 @@ icmdtable_entry_t icmd_table[256] = {
 
 void jit_init(void)
 {
+       TRACESUBSYSTEMINITIALIZATION("jit_init");
+
 #if defined(ENABLE_JIT)
        /* initialize stack analysis subsystem */
 
@@ -308,13 +309,13 @@ u1 *jit_compile(methodinfo *m)
           otherwise we could run into a deadlock with <clinit>'s that
           call static methods of it's own class. */
 
-       if ((m->flags & ACC_STATIC) && !(m->class->state & CLASS_INITIALIZED)) {
+       if ((m->flags & ACC_STATIC) && !(m->clazz->state & CLASS_INITIALIZED)) {
 #if !defined(NDEBUG)
                if (initverbose)
-                       log_message_class("Initialize class ", m->class);
+                       log_message_class("Initialize class ", m->clazz);
 #endif
 
-               if (!initialize_class(m->class))
+               if (!initialize_class(m->clazz))
                        return NULL;
 
                /* check if the method has been compiled during initialization */
@@ -375,7 +376,7 @@ u1 *jit_compile(methodinfo *m)
 #endif
 
 #if defined(ENABLE_INLINING) && defined(ENABLE_INLINING_DEBUG)
-       if (opt_inlining && opt_inline_debug_all)
+       if (opt_Inline && opt_InlineAll)
                jd->flags |= JITDATA_FLAG_INLINE;
 #endif
 
@@ -389,7 +390,7 @@ u1 *jit_compile(methodinfo *m)
                jd->flags |= JITDATA_FLAG_VERBOSECALL;
 
 #if defined(ENABLE_REPLACEMENT) && defined(ENABLE_INLINING)
-       if (opt_inlining)
+       if (opt_Inline)
                jd->flags |= JITDATA_FLAG_COUNTDOWN;
 #endif
 
@@ -513,7 +514,7 @@ u1 *jit_recompile(methodinfo *m)
                jd->flags |= JITDATA_FLAG_VERBOSECALL;
 
 #if defined(ENABLE_INLINING)
-       if (opt_inlining)
+       if (opt_Inline)
                jd->flags |= JITDATA_FLAG_INLINE;
 #endif
 
@@ -560,6 +561,9 @@ u1 *jit_recompile(methodinfo *m)
        return r;
 }
 
+#if defined(ENABLE_PM_HACKS)
+#include "vm/jit/jit_pm_1.inc"
+#endif
 
 /* jit_compile_intern **********************************************************
 
@@ -636,14 +640,14 @@ 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
           dynamically-generated bytecodes. */
 
 # if defined(ENABLE_VERIFIER)
-       if (class_issubclass(m->class, class_sun_reflect_MagicAccessorImpl))
+       if (class_issubclass(m->clazz, class_sun_reflect_MagicAccessorImpl))
                jd->flags &= ~JITDATA_FLAG_VERIFY;
 # endif
 #endif
@@ -680,12 +684,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: ");
@@ -702,6 +700,16 @@ static u1 *jit_compile_intern(jitdata *jd)
 #endif
                RT_TIMING_GET_TIME(time_typecheck);
 
+#if defined(ENABLE_SSA)
+               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_LOOP)
                if (opt_loops) {
                        depthFirst(jd);
@@ -730,12 +738,6 @@ static u1 *jit_compile_intern(jitdata *jd)
                }
 #endif
 
-#if defined(ENABLE_PYTHON)
-               if (!pythonpass_run(jd, "langauer_tarjan", "main")) {
-                       /*return NULL;*/
-               }
-#endif
-
 #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
@@ -748,6 +750,9 @@ static u1 *jit_compile_intern(jitdata *jd)
                }
 #endif
 
+#if defined(ENABLE_PM_HACKS)
+#include "vm/jit/jit_pm_2.inc"
+#endif
                DEBUG_JIT_COMPILEVERBOSE("Allocating registers: ");
 
 #if defined(ENABLE_LSRA) && !defined(ENABLE_SSA)
@@ -762,11 +767,17 @@ static u1 *jit_compile_intern(jitdata *jd)
 # endif /* defined(ENABLE_LSRA) && !defined(ENABLE_SSA) */
 #if defined(ENABLE_SSA)
                /* allocate registers */
-               if ((opt_lsra) && (jd->exceptiontablelength == 0)) {
+               if (
+                       (opt_lsra) 
+                       /*&& strncmp(jd->m->name->text, "banana", 6) == 0*/
+                       /*&& jd->exceptiontablelength == 0*/
+               ) {
+                       /* printf("=== %s ===\n", jd->m->name->text); */
                        jd->ls = DNEW(lsradata);
+                       jd->ls = NULL;
                        ssa(jd);
-                       lsra(jd);
-
+                       /*lsra(jd);*/ regalloc(jd);
+                       eliminate_subbasicblocks(jd);
                        STATISTICS(count_methods_allocated_by_lsra++);
 
                } else
@@ -1177,6 +1188,15 @@ void jit_check_basicblock_numbers(jitdata *jd)
 }
 #endif /* !defined(NDEBUG) */
 
+methoddesc *instruction_call_site(const instruction *iptr) {
+       if (iptr->opc == ICMD_BUILTIN) {
+               return iptr->sx.s23.s3.bte->md;
+       } else if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
+               return iptr->sx.s23.s3.um->methodref->parseddesc.md;
+       } else {
+               return iptr->sx.s23.s3.fmiref->p.method->parseddesc;
+       }
+}
 
 /*
  * These are local overrides for various environment variables in Emacs.