]> gitweb.factorcode.org Git - factor.git/commitdiff
VM: new function visit_object to replace trace_object
authorBjörn Lindqvist <bjourne@gmail.com>
Sat, 28 Feb 2015 20:43:48 +0000 (20:43 +0000)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sat, 28 Feb 2015 22:14:30 +0000 (14:14 -0800)
vm/collector.hpp
vm/copying_collector.hpp
vm/slot_visitor.hpp

index 626ae2b6b519f4c417161ecdd0b445e1678c6437..ce8b6445b8d5ab0ae92524ffd9d2067c67cd3688 100644 (file)
@@ -25,23 +25,24 @@ struct gc_workhorse : no_fixup {
       return obj;
     }
 
-    object* untagged = obj;
     /* is there another forwarding pointer? */
-    while (untagged->forwarding_pointer_p())
-      untagged = untagged->forwarding_pointer();
+    while (obj->forwarding_pointer_p()) {
+      object* dest = obj->forwarding_pointer();
+      obj = dest;
+    }
 
-    if (!policy.should_copy_p(untagged)) {
-      policy.visited_object(untagged);
-      return untagged;
+    if (!policy.should_copy_p(obj)) {
+      policy.visited_object(obj);
+      return obj;
     }
 
-    cell size = untagged->size();
+    cell size = obj->size();
     object* newpointer = target->allot(size);
     if (!newpointer)
       throw must_start_gc_again();
 
-    memcpy(newpointer, untagged, size);
-    untagged->forward_to(newpointer);
+    memcpy(newpointer, obj, size);
+    obj->forward_to(newpointer);
 
     policy.promoted_object(newpointer);
 
@@ -80,12 +81,6 @@ template <typename TargetGeneration, typename Policy> struct collector {
         decks_scanned(0),
         code_blocks_scanned(0) {}
 
-  void trace_object(object* ptr) {
-    visitor.visit_slots(ptr);
-    if (ptr->type() == ALIEN_TYPE)
-      ((alien*)ptr)->update_address();
-  }
-
   void trace_code_heap_roots(std::set<code_block*>* remembered_set) {
     std::set<code_block*>::const_iterator iter = remembered_set->begin();
     std::set<code_block*>::const_iterator end = remembered_set->end();
index 4493ecbb5ba2498d4ea08959e4e5f132a7833d86..911363f97fed965086121d114117c1b5b92724ef 100644 (file)
@@ -11,7 +11,7 @@ struct copying_collector : collector<TargetGeneration, Policy> {
 
   void cheneys_algorithm() {
     while (scan && scan < this->target->here) {
-      this->trace_object((object*)scan);
+      this->visitor.visit_object((object*)scan);
       scan = this->target->next_object_after(scan);
     }
   }
index 9dfee053a34592015616fc0abe94ebf0bd74c895..09a4b5fd220bb1058a573ac3a4f6f698698fd2ba 100644 (file)
@@ -144,6 +144,7 @@ template <typename Fixup> struct slot_visitor {
   void visit_context_code_blocks();
   void visit_uninitialized_code_blocks();
   void visit_embedded_code_pointers(code_block* compiled);
+  void visit_object(object* obj);
   void visit_mark_stack(std::vector<cell>* mark_stack);
 };
 
@@ -536,6 +537,13 @@ void slot_visitor<Fixup>::visit_embedded_code_pointers(code_block* compiled) {
   }
 }
 
+template <typename Fixup>
+void slot_visitor<Fixup>::visit_object(object *ptr) {
+  visit_slots(ptr);
+  if (ptr->type() == ALIEN_TYPE)
+    ((alien*)ptr)->update_address();
+}
+
 /* Pops items from the mark stack and visits them until the stack is
    empty. Used when doing a full collection and when collecting to
    tenured space. */
@@ -553,9 +561,7 @@ void slot_visitor<Fixup>::visit_mark_stack(std::vector<cell>* mark_stack) {
       visit_embedded_code_pointers(compiled);
     } else {
       object* obj = (object*)ptr;
-      visit_slots(obj);
-      if (obj->type() == ALIEN_TYPE)
-        ((alien*)obj)->update_address();
+      visit_object(obj);
       visit_object_code_block(obj);
     }
   }