* src/threads/thread.c: Moved to .cpp.
[cacao.git] / src / vm / jit / show.c
index 449288e4f10e398334eaff39fc945ff01e32c3d5..6cd12f0f7c2e7365c9f58598ce388020d5f50894 100644 (file)
@@ -1,9 +1,7 @@
 /* src/vm/jit/show.c - showing the intermediate representation
 
-   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
+   Copyright (C) 1996-2005, 2006, 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id$
-
 */
 
 
 #include "config.h"
 
 #include <assert.h>
+#include <stdint.h>
 
 #include "vm/types.h"
 
@@ -40,6 +37,7 @@
 #include "vm/global.h"
 #include "vm/builtin.h"
 #include "vm/stringlocal.h"
+#include "vm/vm.hpp"
 
 #include "vm/jit/abi.h"
 #include "vm/jit/jit.h"
 #include "vmcore/options.h"
 
 #if defined(ENABLE_DEBUG_FILTER)
-#      include <sys/types.h>
-#      include <regex.h>
-#      if defined(ENABLE_THREADS)
-#              include "threads/native/threads.h"
-#      else
-#              include "threads/none/threads.h"
-#      endif
+# include <sys/types.h>
+# include <regex.h>
+# include "threads/thread.hpp"
 #endif
 
+
 /* global variables ***********************************************************/
 
 #if defined(ENABLE_THREADS) && !defined(NDEBUG)
-static java_objectheader *show_global_lock;
+static java_object_t *show_global_lock;
 #endif
 
 
@@ -86,7 +81,7 @@ bool show_init(void)
 #if defined(ENABLE_THREADS)
        /* initialize the show lock */
 
-       show_global_lock = NEW(java_objectheader);
+       show_global_lock = NEW(java_object_t);
 
        LOCK_INIT_OBJECT_LOCK(show_global_lock);
 #endif
@@ -180,7 +175,7 @@ void show_method(jitdata *jd, int stage)
 
        method_println(m);
 
-       if (jd->isleafmethod)
+       if (code_is_leafmethod(code))
                printf("LEAFMETHOD\n");
 
        printf("\nBasic blocks: %d\n", jd->basicblockcount);
@@ -377,10 +372,10 @@ void show_method(jitdata *jd, int stage)
        for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next)
                show_basicblock(jd, bptr, stage);
 
-#if defined(ENABLE_DISASSEMBLER)
-       /* show stubs code */
+#if 0 && defined(ENABLE_DISASSEMBLER)
+       /* show code after last basic block */
 
-       if (stage >= SHOW_CODE && opt_showdisassemble && opt_showexceptionstubs) {
+       if (stage >= SHOW_CODE && opt_showdisassemble) {
                printf("\nStubs code:\n");
                printf("Length: %d\n\n", (s4) (code->mcodelength -
                                                                           ((ptrint) cd->dseglen + lastbptr->mpc)));
@@ -454,7 +449,7 @@ void show_basicblock(jitdata *jd, basicblock *bptr, int stage)
        int          irstage;
 #if defined(ENABLE_DISASSEMBLER)
        methodinfo  *m;                     /* this is only a dummy               */
-       u1          *pc;
+       void        *pc;
        s4           linenumber;
        s4           currentlinenumber;
 #endif
@@ -526,11 +521,23 @@ void show_basicblock(jitdata *jd, basicblock *bptr, int stage)
 
                printf("\n");
 
+               if (irstage >= SHOW_CFG) {
+                       printf("succs: %d [ ", bptr->successorcount);
+
+                       for (i = 0; i < bptr->successorcount; i++)
+                               printf("%d ", bptr->successors[i]->nr);
+
+                       printf("]\n");
+               }
+
                if (irstage >= SHOW_STACK) {
                        printf("IN:  ");
                        show_variable_array(jd, bptr->invars, bptr->indepth, irstage);
                        printf(" javalocals: ");
-                       show_javalocals_array(jd, bptr->javalocals, bptr->method->maxlocals, irstage);
+                       if (bptr->javalocals)
+                               show_javalocals_array(jd, bptr->javalocals, bptr->method->maxlocals, irstage);
+                       else
+                               printf("null");
                        printf("\n");
                }
 
@@ -542,6 +549,18 @@ void show_basicblock(jitdata *jd, basicblock *bptr, int stage)
                }
 #endif /* defined(ENABLE_INLINING) */
 
+#if defined(ENABLE_SSA)
+       
+               iptr = bptr->phis;
+
+               for (i = 0; i < bptr->phicount; i++, iptr++) {
+                       printf("%4d:%4d:  ", iptr->line, iptr->flags.bits >> INS_FLAG_ID_SHIFT);
+
+                       show_icmd(jd, iptr, deadcode, irstage);
+                       printf("\n");
+               }
+#endif
+
                iptr = bptr->iinstr;
 
                for (i = 0; i < bptr->icount; i++, iptr++) {
@@ -562,13 +581,13 @@ void show_basicblock(jitdata *jd, basicblock *bptr, int stage)
                        (!deadcode)) 
                {
                        printf("\n");
-                       pc         = (u1 *) (code->mcode + cd->dseglen + bptr->mpc);
+                       pc         = (void *) (code->mcode + cd->dseglen + bptr->mpc);
                        linenumber = 0;
 
                        if (bptr->next != NULL) {
-                               for (; pc < (u1 *) (code->mcode + cd->dseglen + bptr->next->mpc);) {
+                               for (; pc < (void *) (code->mcode + cd->dseglen + bptr->next->mpc);) {
                                        currentlinenumber =
-                                               dseg_get_linenumber_from_pc(&m, code->entrypoint, pc);
+                                               linenumbertable_linenumber_for_pc(&m, code, pc);
 
                                        if (currentlinenumber != linenumber) {
                                                linenumber = currentlinenumber;
@@ -579,9 +598,9 @@ void show_basicblock(jitdata *jd, basicblock *bptr, int stage)
                                }
                        }
                        else {
-                               for (; pc < (u1 *) (code->mcode + code->mcodelength);) {
+                               for (; pc < (void *) (code->mcode + code->mcodelength);) {
                                        currentlinenumber =
-                                               dseg_get_linenumber_from_pc(&m, code->entrypoint, pc);
+                                               linenumbertable_linenumber_for_pc(&m, code, pc);
 
                                        if (currentlinenumber != linenumber) {
                                                linenumber = currentlinenumber;
@@ -619,7 +638,7 @@ void show_basicblock(jitdata *jd, basicblock *bptr, int stage)
 
 #define SHOW_INT_CONST(val)                                          \
         if (stage >= SHOW_PARSE) {                                   \
-            printf("%d (0x%08x) ", (val), (val));                    \
+            printf("%d (0x%08x) ", (int32_t) (val), (int32_t) (val)); \
         }                                                            \
         else {                                                       \
             printf("iconst ");                                       \
@@ -695,7 +714,7 @@ void show_basicblock(jitdata *jd, basicblock *bptr, int stage)
         if (stage >= SHOW_PARSE) {                                   \
             putchar('"');                                            \
             utf_display_printable_ascii(                             \
-               javastring_toutf((java_objectheader *)(val), false)); \
+               javastring_toutf((java_handle_t *)(val), false));     \
             printf("\" ");                                           \
         }                                                            \
         else {                                                       \
@@ -1234,13 +1253,15 @@ void show_icmd(jitdata *jd, instruction *iptr, bool deadcode, int stage)
                else {
                        printf("argcount=%d ", iptr->s1.argcount);
                }
+               class_classref_or_classinfo_print(iptr->sx.s23.s3.c);
+               putchar(' ');
                SHOW_DST(iptr);
                break;
 
        case ICMD_CHECKCAST:
                SHOW_S1(iptr);
-               putchar(' ');
                class_classref_or_classinfo_print(iptr->sx.s23.s3.c);
+               putchar(' ');
                SHOW_DST(iptr);
                break;
 
@@ -1350,32 +1371,6 @@ void show_icmd(jitdata *jd, instruction *iptr, bool deadcode, int stage)
        case ICMD_IF_LCMPGT:
        case ICMD_IF_LCMPLE:
 
-       case ICMD_IF_FCMPEQ:
-       case ICMD_IF_FCMPNE:
-
-       case ICMD_IF_FCMPL_LT:
-       case ICMD_IF_FCMPL_GE:
-       case ICMD_IF_FCMPL_GT:
-       case ICMD_IF_FCMPL_LE:
-
-       case ICMD_IF_FCMPG_LT:
-       case ICMD_IF_FCMPG_GE:
-       case ICMD_IF_FCMPG_GT:
-       case ICMD_IF_FCMPG_LE:
-
-       case ICMD_IF_DCMPEQ:
-       case ICMD_IF_DCMPNE:
-
-       case ICMD_IF_DCMPL_LT:
-       case ICMD_IF_DCMPL_GE:
-       case ICMD_IF_DCMPL_GT:
-       case ICMD_IF_DCMPL_LE:
-
-       case ICMD_IF_DCMPG_LT:
-       case ICMD_IF_DCMPG_GE:
-       case ICMD_IF_DCMPG_GT:
-       case ICMD_IF_DCMPG_LE:
-
        case ICMD_IF_ACMPEQ:
        case ICMD_IF_ACMPNE:
                SHOW_S1(iptr);
@@ -1439,6 +1434,22 @@ void show_icmd(jitdata *jd, instruction *iptr, bool deadcode, int stage)
                SHOW_S1(iptr);
                SHOW_DST(iptr);
                break;
+       case ICMD_GETEXCEPTION:
+               SHOW_DST(iptr);
+               break;
+#if defined(ENABLE_SSA)        
+       case ICMD_PHI:
+               printf("[ ");
+               for (i = 0; i < iptr->s1.argcount; ++i) {
+                       SHOW_VARIABLE(iptr->sx.s23.s2.iargs[i]->dst.varindex);
+               }
+               printf("] ");
+               SHOW_DST(iptr);
+               if (iptr->flags.bits & (1 << 0)) printf("used ");
+               if (iptr->flags.bits & (1 << 1)) printf("redundantAll ");
+               if (iptr->flags.bits & (1 << 2)) printf("redundantOne ");
+               break;
+#endif
        }
        fflush(stdout);
 }
@@ -1449,7 +1460,7 @@ void show_icmd(jitdata *jd, instruction *iptr, bool deadcode, int stage)
 #if defined(ENABLE_DEBUG_FILTER)
 
 #if !defined(ENABLE_THREADS)
-u4 _no_threads_filterverbosecallctr[2] = { 0, 0 };
+u2 _no_threads_filterverbosecallctr[2] = { 0, 0 };
 #endif
 
 struct show_filter {
@@ -1550,22 +1561,22 @@ void show_filters_apply(methodinfo *m) {
        int res;
        char *method_name;
        s4 len;
-       s4 dumpsize;
+       int32_t dumpmarker;
 
        /* compose full name of method */
 
        len = 
-               utf_bytes(m->class->name) +
+               utf_bytes(m->clazz->name) +
                1 +
                utf_bytes(m->name) +
                utf_bytes(m->descriptor) +
                1;
 
-       dumpsize = dump_size(); /* allocate memory */
+       DMARKER;
 
        method_name = DMNEW(char, len);
 
-       utf_cat_classname(method_name, m->class->name);
+       utf_cat_classname(method_name, m->clazz->name);
        strcat(method_name, ".");
        utf_cat(method_name, m->name);
        utf_cat(method_name, m->descriptor);
@@ -1590,8 +1601,7 @@ void show_filters_apply(methodinfo *m) {
 
        /* release memory */
 
-       dump_release(dumpsize); 
-
+       DRELEASE; 
 }
 
 #define STATE_IS_INITIAL() ((FILTERVERBOSECALLCTR[0] == 0) && (FILTERVERBOSECALLCTR[1] == 0))