* src/vm/jit/show.c (new_show_method): Fix display of local table.
[cacao.git] / src / vm / jit / show.c
index ff99415cebd0b887d4478089e14cd4bc313bdfa3..1489a462a394d244b98b102bac1e5c920fc0ba4a 100644 (file)
@@ -69,6 +69,8 @@ static java_objectheader *show_global_lock;
 
 #if !defined(NDEBUG)
 static void new_show_variable_array(jitdata *jd, s4 *vars, int n, int stage);
+static void show_allocation(s4 type, s4 flags, s4 regoff);
+static void show_variable(jitdata *jd, s4 index, int stage);
 #endif
 
 
@@ -150,6 +152,8 @@ void new_show_method(jitdata *jd, int stage)
        method_println(m);
 
        printf("\n(NEW INSTRUCTION FORMAT)\n");
+       if (jd->isleafmethod)
+               printf("LEAFMETHOD\n");
        printf("\nBasic blocks: %d\n", jd->new_basicblockcount);
        if (stage >= SHOW_CODE) {
                printf("Code length:  %d\n", (lastbptr->mpc - jd->new_basicblocks[0].mpc));
@@ -179,50 +183,25 @@ void new_show_method(jitdata *jd, int stage)
                }
        }
        
-       if (stage >= SHOW_PARSE && rd) {
-       printf("Local Table:\n");
-       for (i = 0; i < cd->maxlocals; i++) {
-               printf("   %3d: ", i);
+       if (stage >= SHOW_PARSE && rd && jd->localcount > 0) {
+               printf("Local Table:\n");
+               for (i = 0; i < jd->localcount; i++) {
+                       printf("   %3d: ", i);
 
 #if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
-/*             for (j = TYPE_INT; j <= TYPE_ADR; j++) { */
 # if defined(ENABLE_INTRP)
                        if (!opt_intrp) {
 # endif
-/*                             if (rd->locals[i][j].type >= 0) { */
-                                       printf("   (%s) ", jit_type[jd->var[i].type]);
-                                       if (stage >= SHOW_REGS) {
-                                               if (jd->var[i].flags & INMEMORY)
-                                                       printf("m%2d", jd->var[i].regoff);
-# ifdef HAS_ADDRESS_REGISTER_FILE
-                                               else if (jd->var[i].type == TYPE_ADR)
-                                                       printf("r%02d", jd->var[i].regoff);
-# endif
-                                               else if ((jd->var[i].type == TYPE_FLT) ||
-                                                                (jd->var[i].type == TYPE_DBL))
-                                                       printf("f%02d", jd->var[i].regoff);
-                                               else {
-# if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
-                                                       if (IS_2_WORD_TYPE(j))
-                                                               printf(" %3s/%3s",
-                                                                          regs[GET_LOW_REG(jd->var[i].regoff)],
-                                                                          regs[GET_HIGH_REG(jd->var[i].regoff)]);
-                                                       else
-# endif
-                                                               printf("%3s", regs[jd->var[i].regoff]);
-                                               }
-                                       }
-/*                             } */
+                               printf("   (%s) ", jit_type[jd->var[i].type]);
+                               show_allocation(jd->var[i].type, jd->var[i].flags, jd->var[i].regoff);
+                               printf("\n");
 # if defined(ENABLE_INTRP)
                        }
 # endif
-/*             } */
 #endif /* defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER) */
-
+               }
                printf("\n");
        }
-       printf("\n");
-       }
 
        if (cd->maxlocals > 0) {
                printf("Local Map:\n");
@@ -244,29 +223,56 @@ void new_show_method(jitdata *jd, int stage)
                printf("\n");
        }
 
-       if (cd->maxstack > 0 && jd->interface_map) {
+       if (cd->maxstack > 0 && jd->interface_map && stage >= SHOW_STACK) {
                bool exist = false;
-               s4 *mapptr = jd->interface_map;
+               interface_info *mapptr = jd->interface_map;
                
                /* look if there exist any IN/OUTVARS */
                for (i = 0; (i < (5 * cd->maxstack)) && !exist; i++, mapptr++)
-                       exist = (*mapptr != UNUSED);
+                       exist = (mapptr->flags != UNUSED);
 
                if (exist) {
                        printf("Interface Table: (In/Outvars)\n");
                        printf("    depth ");
                        for (j = 0; j < cd->maxstack; j++) {
-                               printf(" [%2d]", j);
+                               printf("      [%2d]", j);
                        }
                        printf("\n");
 
                        for (i = 0; i < 5; i++) {
-                               printf("    %5s ",jit_type[i]);
+                               printf("    %5s      ",jit_type[i]);
                                for (j = 0; j < cd->maxstack; j++) {
-                                       if (jd->interface_map[j*5+i] == UNUSED)
-                                               printf("  -- ");
-                                       else
-                                               printf("%4i ", jd->interface_map[j*5+i]);
+                                       s4 flags  = jd->interface_map[j*5+i].flags;
+                                       s4 regoff = jd->interface_map[j*5+i].regoff;
+                                       if (flags == UNUSED)
+                                               printf("  --      ");
+                                       else {
+                                               int ch;
+
+                                               if (stage >= SHOW_REGS) {
+                                                       if (flags & SAVEDVAR) {
+                                                               if (flags & INMEMORY)
+                                                                       ch = 'M';
+                                                               else
+                                                                       ch = 'R';
+                                                       }
+                                                       else {
+                                                               if (flags & INMEMORY)
+                                                                       ch = 'm';
+                                                               else
+                                                                       ch = 'r';
+                                                       }
+                                                       printf("%c%03d(", ch, regoff);
+                                                       show_allocation(i, flags, regoff);
+                                                       printf(") ");
+                                               }
+                                               else {
+                                                       if (flags & SAVEDVAR)
+                                                               printf("  I       ");
+                                                       else
+                                                               printf("  i       ");
+                                               }
+                                       }
                                }
                                printf("\n");
                        }
@@ -274,6 +280,24 @@ void new_show_method(jitdata *jd, int stage)
                }
        }
 
+       if (rd->memuse && stage >= SHOW_REGS) {
+               printf("Stack slots: (memuse=%d)\n", rd->memuse);
+               for (i=0; i<rd->memuse; ++i) {
+                       printf("    M%02d: ", i);
+                       for (j=0; j<jd->varcount; ++j) {
+                               varinfo *v = jd->var + j;
+                               if ((v->flags & INMEMORY) && (v->regoff == i)) {
+                                       show_variable(jd, j, stage);
+                                       putchar(' ');
+                               }
+                       }
+
+                       printf("\n");
+
+               }
+               printf("\n");
+       }
+
        if (code->rplpoints) {
                printf("Replacement Points:\n");
                replace_show_replacement_points(code);
@@ -551,6 +575,56 @@ void new_show_basicblock(jitdata *jd, basicblock *bptr, int stage)
         printf("=> L%d ", iptr->dst.varindex);                       \
     }
 
+static void show_allocation(s4 type, s4 flags, s4 regoff)
+{
+       if (flags & INMEMORY) {
+               printf("M%02d", regoff);
+               return;
+       }
+
+#ifdef HAS_ADDRESS_REGISTER_FILE
+       if (type == TYPE_ADR) {
+               printf("R%02d", regoff);
+               return;
+       }
+#endif
+
+       if (IS_FLT_DBL_TYPE(type)) {
+               printf("F%02d", regoff);
+               return;
+       }
+
+#if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
+       if (IS_2_WORD_TYPE(type)) {
+# if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
+#  if defined(ENABLE_INTRP)
+               if (opt_intrp)
+                       printf("%3d/%3d", GET_LOW_REG(regoff),
+                                       GET_HIGH_REG(regoff));
+               else
+#  endif
+                       printf("%3s/%3s", regs[GET_LOW_REG(regoff)],
+                                       regs[GET_HIGH_REG(regoff)]);
+# else
+               printf("%3d/%3d", GET_LOW_REG(regoff),
+                               GET_HIGH_REG(regoff));
+# endif
+               return;
+       } 
+#endif /* defined(SUPPORT_COMBINE_INTEGER_REGISTERS) */
+
+#if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
+# if defined(ENABLE_INTRP)
+       if (opt_intrp)
+               printf("%3d", regoff);
+       else
+# endif
+               printf("%3s", regs[regoff]);
+#else
+       printf("%3d", regoff);
+#endif
+}
+
 static void show_variable(jitdata *jd, s4 index, int stage)
 {
        char type;
@@ -568,62 +642,31 @@ static void show_variable(jitdata *jd, s4 index, int stage)
                default:       type = '?';
        }
 
-       if (v->flags & PREALLOC)
-               kind = 'A';
-       else if (v->flags & OUTVAR)
-               kind = 'I';
-       else if (index < jd->localcount)
+       if (index < jd->localcount) {
                kind = 'L';
-       else
-               kind = 'T';
+               if (v->flags & (PREALLOC | OUTVAR))
+                               printf("<INVALID FLAGS!>");
+       }
+       else {
+               if (v->flags & PREALLOC) {
+                       kind = 'A';
+                       if (v->flags & OUTVAR)
+                               printf("<INVALID FLAGS!>");
+               }
+               else if (v->flags & OUTVAR)
+                       kind = 'I';
+               else
+                       kind = 'T';
+       }
 
        printf("%c%c%d", kind, type, index);
 
+       if (v->flags & SAVEDVAR)
+               putchar('!');
+
        if (stage >= SHOW_REGS) {
                putchar('(');
-
-               if (v->flags & INMEMORY)
-                       printf("M%02d", v->regoff);
-#ifdef HAS_ADDRESS_REGISTER_FILE
-               else if (v->type == TYPE_ADR)
-                       printf("R%02d", v->regoff);
-#endif
-               else if (IS_FLT_DBL_TYPE(v->type))
-                       printf("F%02d", v->regoff);
-               else {
-#if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
-                       if (IS_2_WORD_TYPE(v->type)) {
-# if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
-#  if defined(ENABLE_INTRP)
-                               if (opt_intrp)
-                                       printf("%3d/%3d", GET_LOW_REG(v->regoff),
-                                                  GET_HIGH_REG(v->regoff));
-                               else
-#  endif
-                                       printf("%3s/%3s", regs[GET_LOW_REG(v->regoff)],
-                                                  regs[GET_HIGH_REG(v->regoff)]);
-# else
-                               printf("%3d/%3d", GET_LOW_REG(v->regoff),
-                                          GET_HIGH_REG(v->regoff));
-# endif
-                       } 
-                       else 
-#endif /* defined(SUPPORT_COMBINE_INTEGER_REGISTERS) */
-                               {
-#if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
-# if defined(ENABLE_INTRP)
-                                       if (opt_intrp)
-                                               printf("%3d", v->regoff);
-                                       else
-# endif
-                                               printf("%3s", regs[v->regoff]);
-#else
-                                       printf("%3d", v->regoff);
-#endif
-                               }
-               }
-
-
+               show_allocation(v->type, v->flags, v->regoff);
                putchar(')');
        }
        putchar(' ');