Improve logging. Treat the result of an LDIND.REF as a ref. Treat methods with finall...
authorZoltan Varga <vargaz@gmail.com>
Sun, 26 Sep 2010 18:25:53 +0000 (20:25 +0200)
committerZoltan Varga <vargaz@gmail.com>
Mon, 3 Jan 2011 14:42:36 +0000 (15:42 +0100)
mono/mini/gc-test.cs
mono/mini/method-to-ir.c
mono/mini/mini-codegen.c
mono/mini/mini-gc.c

index 3da42741b0aed6c6018602b51b939ad8b2dd3135..b71b0185d9b1f68ecf5011c953c5aa25f432c158 100644 (file)
@@ -1,6 +1,7 @@
 using System;
 using System.Reflection;
 using System.Runtime.CompilerServices;
+using System.Collections;
 
 /*
  * Regression tests for the GC support in the JIT
@@ -551,4 +552,16 @@ class Tests {
                liveness_12_inner (1, 2, 3, 4, 5, 6, new object ());
                return 0;
        }
+
+       public static void liveness_13_inner (ref ArrayList arr) {
+               // The value of arr will be stored in a spill slot
+               arr.Add (alloc_obj_and_gc ());
+       }
+
+       // Liveness for byref arguments in spill slots
+       public static int test_0_liveness_13 () {
+               var arr = new ArrayList ();
+               liveness_13_inner (ref arr);
+               return 0;
+       }
 }
\ No newline at end of file
index fceafa4fb84951a8d00ec7d85f21ef627b9f23b4..b2d28ffd061749161a247ef285f6ad12ad38c31d 100644 (file)
@@ -7497,6 +7497,9 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
                        case CEE_LDIND_I8:
                                dreg = alloc_lreg (cfg);
                                break;
+                       case CEE_LDIND_REF:
+                               dreg = alloc_ireg_ref (cfg);
+                               break;
                        default:
                                dreg = alloc_preg (cfg);
                        }
index 2d5143b89384e811ecc04fe0a55543b5b5a7bb45..2a948d261bd6ca8079f712cd33b8922385c8d51a 100644 (file)
@@ -1140,7 +1140,7 @@ mono_local_regalloc (MonoCompile *cfg, MonoBasicBlock *bb)
                local_copy_prop (cfg, ins);*/
 
        i = 1;
-       DEBUG (printf ("\nLOCAL REGALLOC: BASIC BLOCK %d:\n", bb->block_num));
+       DEBUG (printf ("\nLOCAL REGALLOC BLOCK %d:\n", bb->block_num));
        /* forward pass on the instructions to collect register liveness info */
        MONO_BB_FOR_EACH_INS (bb, ins) {
                spec = ins_get_spec (ins->opcode);
index 78d384b8ed4ab77fd67d92085998c3920e690ca2..6f98a4058925073388ed4d779e33cf91eb2b62a6 100644 (file)
@@ -1261,7 +1261,7 @@ process_spill_slots (MonoCompile *cfg)
                        set_slot_in_range (gcfg, slot, def->backend.pc_offset, bb->native_offset + bb->native_length, type);
 
                        if (cfg->verbose_level > 1)
-                               printf ("\t%s spill slot at %s0x%x(fp) (slot = %d)\n", slot_type_to_string (type), offset >= 0 ? "+" : "-", ABS (offset), slot);
+                               printf ("\t%s spill slot at %s0x%x(fp) (slot = %d)\n", slot_type_to_string (type), offset >= 0 ? "" : "-", ABS (offset), slot);
                }
        }
 
@@ -1293,7 +1293,7 @@ process_spill_slots (MonoCompile *cfg)
 
                set_slot_everywhere (gcfg, slot, SLOT_NOREF);
                if (cfg->verbose_level > 1)
-                       printf ("\tint spill slot at fp+0x%x (slot = %d)\n", offset, slot);
+                       printf ("\tint spill slot at %s0x%x(fp) (slot = %d)\n", offset >= 0 ? "" : "-", ABS (offset), slot);
        }
 }
 
@@ -1482,7 +1482,7 @@ process_variables (MonoCompile *cfg)
                        set_slot_everywhere (gcfg, pos, SLOT_NOREF);
 
                        if (cfg->verbose_level > 1) {
-                               printf ("\tdead arg at fp%s0x%x (slot=%d): %s\n", ins->inst_offset < 0 ? "-" : "+", (ins->inst_offset < 0) ? -(int)ins->inst_offset : (int)ins->inst_offset, pos, mono_type_full_name (ins->inst_vtype));
+                               printf ("\tdead arg at fp%s0x%x (slot = %d): %s\n", ins->inst_offset < 0 ? "-" : "+", (ins->inst_offset < 0) ? -(int)ins->inst_offset : (int)ins->inst_offset, pos, mono_type_full_name (ins->inst_vtype));
                        }
                        continue;
                }
@@ -1563,9 +1563,15 @@ process_variables (MonoCompile *cfg)
                        continue;
 
                if (t->byref) {
-                       for (cindex = 0; cindex < gcfg->ncallsites; ++cindex)
-                               if (gcfg->callsites [cindex]->liveness [i / 8] & (1 << (i % 8)))
-                                       set_slot (gcfg, pos, cindex, SLOT_PIN);
+                       if (is_arg) {
+                               set_slot_everywhere (gcfg, pos, SLOT_PIN);
+                       } else {
+                               for (cindex = 0; cindex < gcfg->ncallsites; ++cindex)
+                                       if (gcfg->callsites [cindex]->liveness [i / 8] & (1 << (i % 8)))
+                                               set_slot (gcfg, pos, cindex, SLOT_PIN);
+                       }
+                       if (cfg->verbose_level > 1)
+                               printf ("\tbyref at %s0x%x(fp) (R%d, slot = %d): %s\n", ins->inst_offset < 0 ? "-" : "", (ins->inst_offset < 0) ? -(int)ins->inst_offset : (int)ins->inst_offset, vmv->vreg, pos, mono_type_full_name (ins->inst_vtype));
                        continue;
                }
 
@@ -1589,7 +1595,7 @@ process_variables (MonoCompile *cfg)
                if (!MONO_TYPE_IS_REFERENCE (t)) {
                        set_slot_everywhere (gcfg, pos, SLOT_NOREF);
                        if (cfg->verbose_level > 1)
-                               printf ("\tnoref at %s0x%x(fp) (R%d, slot=%d): %s\n", ins->inst_offset < 0 ? "-" : "", (ins->inst_offset < 0) ? -(int)ins->inst_offset : (int)ins->inst_offset, vmv->vreg, pos, mono_type_full_name (ins->inst_vtype));
+                               printf ("\tnoref at %s0x%x(fp) (R%d, slot = %d): %s\n", ins->inst_offset < 0 ? "-" : "", (ins->inst_offset < 0) ? -(int)ins->inst_offset : (int)ins->inst_offset, vmv->vreg, pos, mono_type_full_name (ins->inst_vtype));
                        continue;
                }
 
@@ -1608,7 +1614,7 @@ process_variables (MonoCompile *cfg)
                                set_slot_everywhere (gcfg, pos, SLOT_PIN);
                        }
                        if (cfg->verbose_level > 1)
-                               printf ("\tvolatile ref at %s0x%x(fp) (R%d, slot=%d): %s\n", ins->inst_offset < 0 ? "-" : "", (ins->inst_offset < 0) ? -(int)ins->inst_offset : (int)ins->inst_offset, vmv->vreg, pos, mono_type_full_name (ins->inst_vtype));
+                               printf ("\tvolatile ref at %s0x%x(fp) (R%d, slot = %d): %s\n", ins->inst_offset < 0 ? "-" : "", (ins->inst_offset < 0) ? -(int)ins->inst_offset : (int)ins->inst_offset, vmv->vreg, pos, mono_type_full_name (ins->inst_vtype));
                        continue;
                }
 
@@ -1622,7 +1628,7 @@ process_variables (MonoCompile *cfg)
                }
 
                if (cfg->verbose_level > 1) {
-                       printf ("\tref at %s0x%x(fp) (R%d, slot=%d): %s\n", ins->inst_offset < 0 ? "-" : "", (ins->inst_offset < 0) ? -(int)ins->inst_offset : (int)ins->inst_offset, vmv->vreg, pos, mono_type_full_name (ins->inst_vtype));
+                       printf ("\tref at %s0x%x(fp) (R%d, slot = %d): %s\n", ins->inst_offset < 0 ? "-" : "", (ins->inst_offset < 0) ? -(int)ins->inst_offset : (int)ins->inst_offset, vmv->vreg, pos, mono_type_full_name (ins->inst_vtype));
                }
        }
 
@@ -1900,33 +1906,14 @@ create_map (MonoCompile *cfg)
                }
        }
        if (has_finally) {
-               /* Treat every slot which has a ref somewhere as pin outside its live range */
+               /* Treat every slot as pin everywhere */
                DEBUG (printf ("\tMethod has finally clauses, pessimizing live ranges.\n"));
                for (i = 0; i < nslots; ++i) {
-                       for (j = 0; j < ncallsites; ++j) {
-                               if (get_bit (gcfg->stack_ref_bitmap, gcfg->stack_bitmap_width, j, i))
-                                       break;
-                       }
-                       if (j < ncallsites) {
-                               for (j = 0; j < ncallsites; ++j) {
-                                       if (!get_bit (gcfg->stack_ref_bitmap, gcfg->stack_bitmap_width, j, i))
-                                               set_slot (gcfg, i, j, SLOT_PIN);
-                               }
-                               //set_slot_everywhere (gcfg, i, SLOT_PIN);
-                       }
+                       set_slot_everywhere (gcfg, i, SLOT_PIN);
                }
                for (i = 0; i < nregs; ++i) {
-                       for (j = 0; j < ncallsites; ++j) {
-                               if (get_bit (gcfg->reg_ref_bitmap, gcfg->reg_bitmap_width, j, i))
-                                       break;
-                       }
-                       if (j < ncallsites) {
-                               for (j = 0; j < ncallsites; ++j) {
-                                       if (!get_bit (gcfg->reg_ref_bitmap, gcfg->reg_bitmap_width, j, i))
-                                               set_reg_slot (gcfg, i, j, SLOT_PIN);
-                               }
-                               //set_reg_slot_everywhere (gcfg, i, SLOT_PIN);
-                       }
+                       if (cfg->used_int_regs & (1 << i))
+                               set_reg_slot_everywhere (gcfg, i, SLOT_PIN);
                }
        }