]> gitweb.factorcode.org Git - factor.git/commitdiff
VM: use the check_d and check_r to trace the overinitialized stack locations
authorBjörn Lindqvist <bjourne@gmail.com>
Wed, 27 Aug 2014 02:22:20 +0000 (04:22 +0200)
committerDoug Coleman <doug.coleman@gmail.com>
Mon, 8 Sep 2014 21:54:18 +0000 (14:54 -0700)
vm/gc_info.hpp
vm/slot_visitor.hpp

index 84ae69ccfe41064838c9c3c61c417a5b8232112f..60794a79a0009e459e54b97fe95ababb9f0af9b6 100644 (file)
@@ -39,13 +39,31 @@ struct gc_info {
     return (uint8_t*)base_pointer_map() - total_bitmap_bytes();
   }
 
-  cell callsite_scrub_d(cell index) { return index * scrub_d_count; }
+  cell callsite_scrub_d(cell index) {
+    cell base = 0;
+    return base + index * scrub_d_count;
+  }
 
   cell callsite_scrub_r(cell index) {
     cell base = return_address_count * scrub_d_count;
     return base + index * scrub_r_count;
   }
 
+  cell callsite_check_d(cell index) {
+    cell base =
+        return_address_count * scrub_d_count +
+        return_address_count * scrub_r_count;
+    return base + index * check_d_count;
+  }
+
+  cell callsite_check_r(cell index) {
+    cell base =
+        return_address_count * scrub_d_count +
+        return_address_count * scrub_r_count +
+        return_address_count * check_d_count;
+    return base + index + check_r_count;
+  }
+
   cell callsite_gc_roots(cell index) {
     cell base =
         return_address_count * scrub_d_count +
index ca126feecccf8070e40bd5c68817944dec9b6509..e288739d77e5060eafb8e1fa40049c01d12b59f0 100644 (file)
@@ -264,10 +264,12 @@ template <typename Fixup> void slot_visitor<Fixup>::visit_roots() {
 template <typename Fixup> struct call_frame_slot_visitor {
   factor_vm* parent;
   slot_visitor<Fixup>* visitor;
+  context* ctx;
 
   call_frame_slot_visitor(factor_vm* parent,
-                          slot_visitor<Fixup>* visitor)
-      : parent(parent), visitor(visitor) {}
+                          slot_visitor<Fixup>* visitor,
+                          context* ctx)
+      : parent(parent), visitor(visitor), ctx(ctx) {}
 
   /*
        frame top -> [return address]
@@ -310,6 +312,29 @@ template <typename Fixup> struct call_frame_slot_visitor {
       }
     }
 
+    /* Trace all overinitialized stack locations. */
+    cell callsite_check_d = info->callsite_check_d(callsite);
+    for (uint32_t loc = 0; loc < info->check_d_count; loc++) {
+      if (bitmap_p(bitmap, callsite_check_d + loc)) {
+#ifdef DEBUG_GC_MAPS
+        std::cout << "checking datastack location " << loc << std::endl;
+#endif
+        cell* value_ptr = ((cell*)ctx->datastack + loc + 1);
+        visitor->visit_handle(value_ptr);
+      }
+    }
+
+    cell callsite_check_r = info->callsite_check_r(callsite);
+    for (uint32_t loc = 0; loc < info->check_r_count; loc++) {
+      if (bitmap_p(bitmap, callsite_check_r + loc)) {
+#ifdef DEBUG_GC_MAPS
+        std::cout << "checking retainstack location " << loc << std::endl;
+#endif
+        cell* value_ptr = ((cell*)ctx->retainstack + loc + 1);
+        visitor->visit_handle(value_ptr);
+      }
+    }
+
     /* Update all GC roots, including base pointers. */
     cell callsite_gc_roots = info->callsite_gc_roots(callsite);
 
@@ -334,13 +359,14 @@ template <typename Fixup> struct call_frame_slot_visitor {
 
 template <typename Fixup>
 void slot_visitor<Fixup>::visit_callstack_object(callstack* stack) {
-  call_frame_slot_visitor<Fixup> call_frame_visitor(parent, this);
+  /* TODO: is parent->ctx right? */
+  call_frame_slot_visitor<Fixup> call_frame_visitor(parent, this, parent->ctx);
   parent->iterate_callstack_object(stack, call_frame_visitor, fixup);
 }
 
 template <typename Fixup>
 void slot_visitor<Fixup>::visit_callstack(context* ctx) {
-  call_frame_slot_visitor<Fixup> call_frame_visitor(parent, this);
+  call_frame_slot_visitor<Fixup> call_frame_visitor(parent, this, ctx);
   parent->iterate_callstack(ctx, call_frame_visitor, fixup);
 }