]> gitweb.factorcode.org Git - factor.git/commitdiff
vm: debugging mark and sweep
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Thu, 22 Oct 2009 04:24:35 +0000 (23:24 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Thu, 22 Oct 2009 04:24:35 +0000 (23:24 -0500)
vm/arrays.hpp
vm/free_list_allocator.hpp
vm/gc.cpp
vm/image.cpp
vm/local_roots.hpp
vm/mark_bits.hpp
vm/vm.hpp

index 48be881230a35672c2c8ba9771704e5c52cc032c..6063269e7f944c68475667853e10cf56f868b3a6 100755 (executable)
@@ -15,7 +15,6 @@ inline void factor_vm::set_array_nth(array *array, cell slot, cell value)
 #ifdef FACTOR_DEBUG
        assert(slot < array_capacity(array));
        assert(array->h.hi_tag() == ARRAY_TYPE);
-       check_tagged_pointer(value);
 #endif
        cell *slot_ptr = &array->data()[slot];
        *slot_ptr = value;
index efdad508cb91b273d3ff67634bd71fedaeca6022..8332399279ae1a85a379c6195388b9f01453f982 100644 (file)
@@ -22,7 +22,7 @@ template<typename Block> struct free_list_allocator {
        Block *next_block_after(Block *block);
        void clear_free_list();
        void add_to_free_list(free_heap_block *block);
-       void build_free_list(cell size);
+       void initial_free_list(cell size);
        void assert_free_block(free_heap_block *block);
        free_heap_block *find_free_block(cell size);
        free_heap_block *split_free_block(free_heap_block *block, cell size);
@@ -40,7 +40,7 @@ template<typename Block>
 free_list_allocator<Block>::free_list_allocator(cell size_, cell start_) :
        size(size_), start(start_), end(start_ + size_), state(mark_bits<Block>(size_,start_))
 {
-       clear_free_list();
+       initial_free_list(0);
 }
 
 template<typename Block> void free_list_allocator<Block>::clear_free_list()
@@ -85,7 +85,7 @@ template<typename Block> void free_list_allocator<Block>::add_to_free_list(free_
 
 /* Called after reading the heap from the image file, and after heap compaction.
 Makes a free list consisting of one free block, at the very end. */
-template<typename Block> void free_list_allocator<Block>::build_free_list(cell size)
+template<typename Block> void free_list_allocator<Block>::initial_free_list(cell size)
 {
        clear_free_list();
        if(size != this->size)
@@ -345,7 +345,7 @@ void free_list_allocator<Block>::compact(Iterator &iter)
 
        /* Now update the free list; there will be a single free block at
        the end */
-       this->build_free_list((cell)compactor.address - this->start);
+       this->initial_free_list((cell)compactor.address - this->start);
 }
 
 template<typename Block>
index 706831136b92722b9ddd3572af1c62c9a5c6e971..6b3ec8048168d531efdd31ff900aa0213f011309 100755 (executable)
--- a/vm/gc.cpp
+++ b/vm/gc.cpp
@@ -60,12 +60,12 @@ void factor_vm::gc(gc_op op,
                        current_gc->op = collect_growing_heap_op;
                        break;
                default:
-                       critical_error("Bad GC op\n",op);
+                       critical_error("Bad GC op",current_gc->op);
                        break;
                }
 
                if(verbosegc)
-                       std::cout << "GC rewind, op=" << op << std::endl;
+                       std::cout << "GC rewind, op=" << current_gc->op << std::endl;
        }
 
        switch(current_gc->op)
@@ -91,20 +91,20 @@ void factor_vm::gc(gc_op op,
                record_gc_stats(&gc_stats.full_stats);
                break;
        default:
-               critical_error("Bad GC op\n",op);
+               critical_error("Bad GC op\n",current_gc->op);
                break;
        }
 
+       if(verbosegc)
+               std::cout << "GC done, op=" << current_gc->op << std::endl;
+
        delete current_gc;
        current_gc = NULL;
-
-       if(verbosegc)
-               std::cout << "GC done, op=" << op << std::endl;
 }
 
 void factor_vm::primitive_minor_gc()
 {
-       gc(collect_full_op,
+       gc(collect_nursery_op,
                0, /* requested size */
                true, /* trace contexts? */
                false /* compact code heap? */);
index 845ca6c1bc0faef9733c3ec3869fb001a7c21575..f5879e7a321b981e232c8f0431b59913c946aac5 100755 (executable)
@@ -36,7 +36,7 @@ void factor_vm::load_data_heap(FILE *file, image_header *h, vm_parameters *p)
                fatal_error("load_data_heap failed",0);
        }
 
-       data->tenured->build_free_list(h->data_size);
+       data->tenured->initial_free_list(h->data_size);
 }
 
 void factor_vm::load_code_heap(FILE *file, image_header *h, vm_parameters *p)
@@ -57,7 +57,7 @@ void factor_vm::load_code_heap(FILE *file, image_header *h, vm_parameters *p)
                }
        }
 
-       code->allocator->build_free_list(h->code_size);
+       code->allocator->initial_free_list(h->code_size);
 }
 
 void factor_vm::data_fixup(cell *handle, cell data_relocation_base)
index 6ae059f4c4d3e8c92c3df8321161f270bb1390fb..58142be8f2892d0c807a665fe35150421d4ce10d 100644 (file)
@@ -6,7 +6,7 @@ struct gc_root : public tagged<Type>
 {
        factor_vm *parent;
 
-       void push() { parent->check_tagged_pointer(tagged<Type>::value()); parent->gc_locals.push_back((cell)this); }
+       void push() { parent->gc_locals.push_back((cell)this); }
        
        explicit gc_root(cell value_,factor_vm *vm) : tagged<Type>(value_),parent(vm) { push(); }
        explicit gc_root(Type *value_, factor_vm *vm) : tagged<Type>(value_),parent(vm) { push(); }
index 161a7fd755de1154a9f8428ebab565f003757f52..279c04a23a441d1b786d7d82b37fc87307c230d2 100644 (file)
@@ -81,12 +81,21 @@ template<typename Block> struct mark_bits {
                        bits[start.first] |= start_mask ^ end_mask;
                else
                {
+#ifdef FACTOR_DEBUG
+                       assert(start.first < bits_size);
+#endif
                        bits[start.first] |= ~start_mask;
 
                        for(cell index = start.first + 1; index < end.first; index++)
                                bits[index] = (u64)-1;
 
-                       bits[end.first] |= end_mask;
+                       if(end_mask != 0)
+                       {
+#ifdef FACTOR_DEBUG
+                               assert(end.first < bits_size);
+#endif
+                               bits[end.first] |= end_mask;
+                       }
                }
        }
 
index 86ed092ff737677a6ade6882ab71c755b3f72e28..40dcb4f3bc05567f46d0aad17fd52c8fb14582f1 100755 (executable)
--- a/vm/vm.hpp
+++ b/vm/vm.hpp
@@ -280,18 +280,6 @@ struct factor_vm
        #endif
        }
 
-       inline void check_tagged_pointer(cell tagged)
-       {
-       #ifdef FACTOR_DEBUG
-               if(!immediate_p(tagged))
-               {
-                       object *obj = untag<object>(tagged);
-                       check_data_pointer(obj);
-                       obj->h.hi_tag();
-               }
-       #endif
-       }
-
        // generic arrays
        template<typename Array> Array *allot_uninitialized_array(cell capacity);
        template<typename Array> bool reallot_array_in_place_p(Array *array, cell capacity);