* Removed all Id tags.
[cacao.git] / src / vm / jit / jit.c
index 2e044fd08c70de6478c57e7314081e16a15a2262..b8d8cdc2e36c6080ff19684e74aff8934b453390 100644 (file)
@@ -1,6 +1,6 @@
 /* src/vm/jit/jit.c - calls the code generation functions
 
-   Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+   Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
    J. Wenninger, Institut f. Computersprachen - TU Wien
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Contact: cacao@cacaojvm.org
-
-   Authors: Andreas Krall
-            Reinhard Grafl
-
-   Changes: Edwin Steiner
-            Christian Thalinger
-            Christian Ullrich
-
-   $Id: jit.c 7210 2007-01-13 22:37:26Z edwin $
-
 */
 
 
 #include "config.h"
-#include "vm/types.h"
 
 #include <assert.h>
 
+#include "vm/types.h"
+
 #include "mm/memory.h"
+
 #include "native/native.h"
+
 #include "toolbox/logging.h"
 
-#if defined(ENABLE_THREADS)
-# include "threads/native/lock.h"
-#else
-# include "threads/none/lock.h"
-#endif
+#include "threads/lock-common.h"
+#include "threads/threads-common.h"
 
-#include "vm/class.h"
 #include "vm/global.h"
 #include "vm/initialize.h"
-#include "vm/loader.h"
-#include "vm/method.h"
-#include "vm/options.h"
-#include "vm/statistics.h"
+
 #include "vm/jit/asmpart.h"
 
 # include "vm/jit/cfg.h"
@@ -66,6 +51,7 @@
 #include "vm/jit/disass.h"
 #include "vm/jit/dseg.h"
 #include "vm/jit/jit.h"
+#include "vm/jit/md.h"
 #include "vm/jit/parse.h"
 #include "vm/jit/reg.h"
 
 # include "vm/jit/optimizing/ssa.h"
 #endif
 
+#if defined(ENABLE_INLINING)
+# include "vm/jit/inline/inline.h"
+#endif
+
 #include "vm/jit/loop/analyze.h"
 #include "vm/jit/loop/graph.h"
 #include "vm/jit/loop/loop.h"
 #include "vm/jit/optimizing/reorder.h"
 
 #include "vm/jit/verify/typecheck.h"
-#include "vm/rt-timing.h"
 
-#if defined(ENABLE_THREADS)
-# include "threads/native/threads.h"
-#endif
+#include "vmcore/class.h"
+#include "vmcore/loader.h"
+#include "vmcore/method.h"
+#include "vmcore/options.h"
+#include "vmcore/rt-timing.h"
+#include "vmcore/statistics.h"
 
 
 /* debug macros ***************************************************************/
@@ -962,15 +954,15 @@ jitdata *jit_jitdata_new(methodinfo *m)
 
        /* initialize variables */
 
-       jd->flags = 0;
-       jd->exceptiontable = NULL;
+       jd->flags                = 0;
+       jd->exceptiontable       = NULL;
        jd->exceptiontablelength = 0;
-       jd->returncount = 0;
-       jd->branchtoentry = false;
-       jd->branchtoend = false;
-       jd->returncount = 0;
-       jd->returnblock = NULL;
-       jd->maxlocals = m->maxlocals;
+       jd->returncount          = 0;
+       jd->branchtoentry        = false;
+       jd->branchtoend          = false;
+       jd->returncount          = 0;
+       jd->returnblock          = NULL;
+       jd->maxlocals            = m->maxlocals;
 
 #if defined(ENABLE_THREADS)
        if (checksync && (m->flags & ACC_SYNCHRONIZED))
@@ -1069,6 +1061,11 @@ u1 *jit_compile(methodinfo *m)
                jd->flags |= JITDATA_FLAG_IFCONV;
 #endif
 
+#if defined(ENABLE_INLINING) && defined(ENABLE_INLINING_DEBUG)
+       if (opt_inlining && opt_inline_debug_all)
+               jd->flags |= JITDATA_FLAG_INLINE;
+#endif
+
        if (opt_showintermediate)
                jd->flags |= JITDATA_FLAG_SHOWINTERMEDIATE;
 
@@ -1078,6 +1075,11 @@ u1 *jit_compile(methodinfo *m)
        if (opt_verbosecall)
                jd->flags |= JITDATA_FLAG_VERBOSECALL;
 
+#if defined(ENABLE_REPLACEMENT) && defined(ENABLE_INLINING)
+       if (opt_inlining)
+               jd->flags |= JITDATA_FLAG_COUNTDOWN;
+#endif
+
 #if defined(ENABLE_JIT)
 # if defined(ENABLE_INTRP)
        if (!opt_intrp)
@@ -1103,11 +1105,13 @@ u1 *jit_compile(methodinfo *m)
 
                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: ");
@@ -1195,6 +1199,11 @@ u1 *jit_recompile(methodinfo *m)
        if (opt_verbosecall)
                jd->flags |= JITDATA_FLAG_VERBOSECALL;
 
+#if defined(ENABLE_INLINING)
+       if (opt_inlining)
+               jd->flags |= JITDATA_FLAG_INLINE;
+#endif
+
 #if defined(ENABLE_JIT)
 # if defined(ENABLE_INTRP)
        if (!opt_intrp)
@@ -1272,6 +1281,10 @@ static u1 *jit_compile_intern(jitdata *jd)
 
        DEBUG_JIT_COMPILEVERBOSE("Compiling: ");
 
+#if defined(ENABLE_DEBUG_FILTER)
+       show_filters_apply(jd->m);
+#endif
+
        /* handle native methods and create a native stub */
 
        if (m->flags & ACC_NATIVE) {
@@ -1286,7 +1299,7 @@ static u1 *jit_compile_intern(jitdata *jd)
                f = NULL;
 #endif
 
-               code = codegen_createnativestub(f, m);
+               code = codegen_generate_stub_native(m, f);
 
                assert(!m->code); /* native methods are never recompiled */
                m->code = code;
@@ -1397,6 +1410,7 @@ static u1 *jit_compile_intern(jitdata *jd)
                }
 #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
                   if-conversion. */
@@ -1406,6 +1420,7 @@ static u1 *jit_compile_intern(jitdata *jd)
                                return NULL;
                        jit_renumber_basicblocks(jd);
                }
+#endif
 
                DEBUG_JIT_COMPILEVERBOSE("Allocating registers: ");
 
@@ -1444,12 +1459,14 @@ static u1 *jit_compile_intern(jitdata *jd)
 #endif /* defined(ENABLE_JIT) */
        RT_TIMING_GET_TIME(time_alloc);
 
+#if defined(ENABLE_PROFILING)
        /* Allocate memory for basic block profiling information. This
           _must_ be done after loop optimization and register allocation,
           since they can change the basic block count. */
 
        if (JITDATA_HAS_FLAG_INSTRUMENT(jd))
                code->bbfrequency = MNEW(u4, jd->basicblockcount);
+#endif
 
        DEBUG_JIT_COMPILEVERBOSE("Generating code: ");
 
@@ -1476,7 +1493,7 @@ static u1 *jit_compile_intern(jitdata *jd)
        } else
 # endif
                {
-                       if (!codegen(jd)) {
+                       if (!codegen_generate(jd)) {
                                DEBUG_JIT_COMPILEVERBOSE("Exception while generating code: ");
 
                                return NULL;
@@ -1494,20 +1511,25 @@ static u1 *jit_compile_intern(jitdata *jd)
        DEBUG_JIT_COMPILEVERBOSE("Generating code done: ");
 
 #if !defined(NDEBUG)
-       /* intermediate and assembly code listings */
+#if defined(ENABLE_DEBUG_FILTER)
+       if (jd->m->filtermatches & SHOW_FILTER_FLAG_SHOW_METHOD)
+#endif
+       {
+               /* intermediate and assembly code listings */
                
-       if (JITDATA_HAS_FLAG_SHOWINTERMEDIATE(jd)) {
-               show_method(jd, SHOW_CODE);
-       }
-       else if (JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd)) {
+               if (JITDATA_HAS_FLAG_SHOWINTERMEDIATE(jd)) {
+                       show_method(jd, SHOW_CODE);
+               }
+               else if (JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd)) {
 # if defined(ENABLE_DISASSEMBLER)
-               DISASSEMBLE(code->entrypoint,
-                                       code->entrypoint + (code->mcodelength - cd->dseglen));
+                       DISASSEMBLE(code->entrypoint,
+                                               code->entrypoint + (code->mcodelength - cd->dseglen));
 # endif
-       }
+               }
 
-       if (opt_showddatasegment)
-               dseg_display(jd);
+               if (opt_showddatasegment)
+                       dseg_display(jd);
+       }
 #endif
 
        DEBUG_JIT_COMPILEVERBOSE("Compiling done: ");