2 new icmds, new exception table ordering for inlining, exception handler fix for...
[cacao.git] / src / vm / jit / jit.c
index b5e423bcfb4fd0f8cbc4b5305b9e2786275658c0..455b2abf9dd920a42e4ea51dc276dae831fb0de5 100644 (file)
@@ -29,7 +29,7 @@
 
    Changes: Edwin Steiner
 
-   $Id: jit.c 1420 2004-10-27 16:05:14Z twisti $
+   $Id: jit.c 1506 2004-11-14 14:48:49Z jowenn $
 
 */
 
@@ -923,7 +923,9 @@ char *icmd_names[256] = {
        "UNDEF236","UNDEF237","UNDEF238","UNDEF239","UNDEF240",
        "UNDEF","UNDEF","UNDEF","UNDEF","UNDEF",
        "UNDEF246","UNDEF247","UNDEF248","UNDEF249","UNDEF250",
-       "UNDEF251","UNDEF252",
+
+       "INLINE_START", /*          251 */
+        "INLINE_END", /*            252"*/
 
        "BUILTIN3     ", /*             253 */
        "BUILTIN2     ", /*             254 */
@@ -1152,8 +1154,9 @@ char *opcode_names[256] = {
        "UNDEF236","UNDEF237","UNDEF238","UNDEF239","UNDEF240",
        "UNDEF","UNDEF","UNDEF","UNDEF","UNDEF",
        "UNDEF246","UNDEF247","UNDEF248","UNDEF249","UNDEF250",
-       "UNDEF251","UNDEF252",
 
+       "INLINE_START", /*              251 */
+        "INLINE_END",  /*               252 */
        "BUILTIN3     ", /*             253 */
        "BUILTIN2     ", /*             254 */
        "BUILTIN1     "  /*             255 */
@@ -1340,17 +1343,23 @@ static void* do_nothing_function()
 
 /* jit_compile *****************************************************************
 
-       jit_compile, new version of compiler, translates one method to machine code
+   jit_compile, new version of compiler, translates one method to machine code
 
 *******************************************************************************/
 
-static methodptr jit_compile_intern(methodinfo *m);
+static functionptr jit_compile_intern(methodinfo *m, codegendata *cd,
+                                                                         registerdata *rd, loopdata *ld,
+                                                                         t_inlining_globals *id);
 
-methodptr jit_compile(methodinfo *m)
+functionptr jit_compile(methodinfo *m)
 {
        static bool jitrunning;
-       methodptr r;
+       functionptr r;
        s4 dumpsize;
+       codegendata *cd;
+       registerdata *rd;
+       loopdata *ld;
+       t_inlining_globals *id;
 
        if (opt_stat)
                count_jit_calls++;
@@ -1362,7 +1371,7 @@ methodptr jit_compile(methodinfo *m)
        /* if method has been already compiled return immediately */
 
        if (m->entrypoint) {
-               builtin_monitorexit((java_objectheader *) m );
+               builtin_monitorexit((java_objectheader *) m);
 
                return m->entrypoint;
        }
@@ -1370,32 +1379,69 @@ methodptr jit_compile(methodinfo *m)
        if (opt_stat)
                count_methods++;
 
+       /* if there is no javacode, print error message and return empty method   */
+
+       if (!m->jcode) {
+               if (compileverbose)
+                       log_message_method("No code given for: ", m);
+
+               /*m->entrypoint = (methodptr) do_nothing_function;*/
+               m->entrypoint = (functionptr) do_nothing_function;
+
+               return m->entrypoint;    /* return empty method     */
+       }
+
+#if 0
        if (jitrunning) {
                printf("JITRUNNING!!! new method=");
                utf_display_classname(m->class->name);printf(".");utf_display(m->name);
                printf("\n");
        }
+
        /* now the jit is running */
 
        jitrunning = true;
+#endif
+
+       /* measure time */
+
+       if (getcompilingtime)
+               compilingtime_start();
 
        /* mark start of dump memory area */
 
        dumpsize = dump_size();
 
-       /* measure time */
+       /* allocate memory */
 
-       if (getcompilingtime)
-               compilingtime_start();
+       cd = DNEW(codegendata);
+       rd = DNEW(registerdata);
+       ld = DNEW(loopdata);
+       id = DNEW(t_inlining_globals);
+
+       /* RTA static analysis must be called before inlining */
+       if (opt_rt)
+               RT_jit_parse(m); /* will be called just once */
+                            /* return value ignored for now */
+
+       /* must be called before reg_setup, because it can change maxlocals */
+       /* init reqd to initialize for parse even in no inlining */
+       inlining_setup(m, id);
+
+       /* initialize the register allocator */
+       reg_setup(m, rd, id);
+
+       /* setup the codegendata memory */
+       codegen_setup(m, cd, id);
 
        /* now call internal compile function */
 
-       r = jit_compile_intern(m);
+       r = jit_compile_intern(m, cd, rd, ld, id);
 
-       if (r) {
-               if (compileverbose)
-                       log_message_method("Running: ", m);
-       }
+       /* free some memory */
+
+       reg_free(m, rd);
+       codegen_free(m, cd);
 
        /* clear pointers to dump memory area */
 
@@ -1416,28 +1462,37 @@ methodptr jit_compile(methodinfo *m)
 
        jitrunning = false;
 
+        /* define in options.h; Used in main.c, jit.c & inline.c */
+       #ifdef INAFTERMAIN
+       if ((utf_new_char("main") == m->name) && (useinliningm))
+               useinlining = false;
+       #endif
+
        /* leave the monitor */
 
        builtin_monitorexit((java_objectheader *) m );
 
+       if (r) {
+               if (compileverbose)
+                       log_message_method("Running: ", m);
+       }
+
        /* return pointer to the methods entry point */
 
        return r;
 }
 
 
-static methodptr jit_compile_intern(methodinfo *m)
-{
-t_inlining_globals *inline_env = NULL;
-       /* if there is no javacode, print error message and return empty method   */
+/* jit_compile_intern **********************************************************
 
-       if (!m->jcode) {
-               if (compileverbose)
-                       log_message_method("No code given for: ", m);
+   Static internal function which does the actual compilation.
 
-               return (methodptr) do_nothing_function;    /* return empty method     */
-       }
+*******************************************************************************/
 
+static functionptr jit_compile_intern(methodinfo *m, codegendata *cd,
+                                                                         registerdata *rd, loopdata *ld,
+                                                                         t_inlining_globals *id)
+{
        /* print log message for compiled method */
 
        if (compileverbose)
@@ -1487,31 +1542,11 @@ t_inlining_globals *inline_env = NULL;
 
        /* call the compiler passes ***********************************************/
 
-       EXTABLEN
-       /* first of all initialize the register allocator */
-       reg_init(m);
-
-       /* RTA static analysis must be called before inlining */
-        if (opt_rt) RT_jit_parse(m); // will be called just once
-                                /* return value ignored for now */
-
-       /* must be called before reg_setup, because it can change maxlocals */
-        /* init reqd to initialize for parse even in no inlining */
-       inline_env = inlining_init(m);
-
-       EXTABLEN
-
-       reg_setup(m);
-
-       /* setup the codegendata memory */
-       codegen_setup(m,inline_env);
-
-       EXTABLEN
-
        if (compileverbose)
                log_message_method("Parsing: ", m);
 
-       if (!parse(m, inline_env)) {
+       /* call parse pass */
+       if (!parse(m, cd, id)) {
                if (compileverbose)
                        log_message_method("Exception while parsing: ", m);
 
@@ -1523,8 +1558,8 @@ t_inlining_globals *inline_env = NULL;
                log_message_method("Analysing: ", m);
        }
 
-
-       if (!analyse_stack(m->codegendata)) {
+       /* call stack analysis pass */
+       if (!analyse_stack(m, cd, rd)) {
                if (compileverbose)
                        log_message_method("Exception while analysing: ", m);
 
@@ -1539,7 +1574,8 @@ t_inlining_globals *inline_env = NULL;
                if (compileverbose)
                        log_message_method("Typechecking: ", m);
 
-               if (!typecheck(m->codegendata)) {
+               /* call typecheck pass */
+               if (!typecheck(m, cd, rd)) {
                        if (compileverbose)
                                log_message_method("Exception while typechecking: ", m);
 
@@ -1550,20 +1586,22 @@ t_inlining_globals *inline_env = NULL;
                        log_message_method("Typechecking done: ", m);
        }
 #endif
+
        if (opt_loops) {
-               depthFirst(m);
-               analyseGraph(m);
-               optimize_loops(m);
+               depthFirst(m, ld);
+               analyseGraph(m, ld);
+               optimize_loops(m, ld);
        }
    
 #ifdef SPECIALMEMUSE
-       preregpass(m);
+       preregpass(m, rd);
 #endif
 
        if (compileverbose)
                log_message_method("Allocating registers: ", m);
 
-       regalloc(m);
+       /* allocate registers */
+       regalloc(m, cd, rd);
 
        if (compileverbose) {
                log_message_method("Allocating registers done: ", m);
@@ -1571,7 +1609,7 @@ t_inlining_globals *inline_env = NULL;
        }
 
        /* now generate the machine code */
-       codegen(m);
+       codegen(m, cd, rd);
 
        if (compileverbose)
                log_message_method("Generating code done: ", m);
@@ -1579,20 +1617,15 @@ t_inlining_globals *inline_env = NULL;
        /* intermediate and assembly code listings */
                
        if (showintermediate) {
-               show_icmd_method(m);
+               show_icmd_method(m, cd, rd);
 
        } else if (showdisassemble) {
-               disassemble((void *) (m->mcode + m->codegendata->dseglen),
-                                       m->mcodelength - m->codegendata->dseglen);
+               disassemble((void *) ((long) m->mcode + cd->dseglen), 
+                                       m->mcodelength - cd->dseglen);
        }
 
        if (showddatasegment)
-               dseg_display(m);
-
-       /* free some memory */
-
-       reg_close(m);
-       codegen_close(m);
+               dseg_display(m, cd);
 
        if (compileverbose)
                log_message_method("Compiling done: ", m);