]> gitweb.factorcode.org Git - factor.git/blobdiff - vm/vm.hpp
Merge branch 'master' into new_gc
[factor.git] / vm / vm.hpp
index 2c85b8ec490dd15f626cf009972e79de29e7e49d..78efc915d71b5d938e5b72ea7d61d3e7cb75cded 100755 (executable)
--- a/vm/vm.hpp
+++ b/vm/vm.hpp
@@ -11,7 +11,7 @@ struct factor_vm
        context *ctx;
        
        /* New objects are allocated here */
-       zone nursery;
+       nursery_space nursery;
 
        /* Add this to a shifted address to compute write barrier offsets */
        cell cards_offset;
@@ -39,9 +39,6 @@ struct factor_vm
        unsigned int signal_fpu_status;
        stack_frame *signal_callstack_top;
 
-       /* Zeroes out deallocated memory; set by the -securegc command line argument */
-       bool secure_gc;
-
        /* A heap walk allows useful things to be done, like finding all
           references to an object for debugging purposes. */
        cell heap_scan_ptr;
@@ -49,6 +46,9 @@ struct factor_vm
        /* GC is off during heap walking */
        bool gc_off;
 
+       /* GC logging */
+       bool verbosegc;
+
        /* Data heap */
        data_heap *data;
 
@@ -220,13 +220,8 @@ struct factor_vm
 
        //data heap
        void init_card_decks();
-       void clear_cards(old_space *gen);
-       void clear_decks(old_space *gen);
-       void reset_generation(old_space *gen);
        void set_data_heap(data_heap *data_);
-       void init_data_heap(cell young_size, cell aging_size, cell tenured_size, bool secure_gc_);
-       cell untagged_object_size(object *pointer);
-       cell unaligned_object_size(object *pointer);
+       void init_data_heap(cell young_size, cell aging_size, cell tenured_size);
        void primitive_size();
        cell binary_payload_start(object *pointer);
        void primitive_data_room();
@@ -285,20 +280,8 @@ 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_array_internal(cell capacity);
+       template<typename Array> Array *allot_uninitialized_array(cell capacity);
        template<typename Array> bool reallot_array_in_place_p(Array *array, cell capacity);
        template<typename Array> Array *reallot_array(Array *array_, cell capacity);
 
@@ -316,7 +299,7 @@ struct factor_vm
        void print_callstack();
        void dump_cell(cell x);
        void dump_memory(cell from, cell to);
-       void dump_zone(const char *name, zone *z);
+       template<typename Generation> void dump_generation(const char *name, Generation *gen);
        void dump_generations();
        void dump_objects(cell type);
        void find_data_references_step(cell *scan);
@@ -335,7 +318,7 @@ struct factor_vm
        inline void set_array_nth(array *array, cell slot, cell value);
 
        //strings
-       cell string_nth(string* str, cell index);
+       cell string_nth(const string *str, cell index);
        void set_string_nth_fast(string *str, cell index, cell ch);
        void set_string_nth_slow(string *str_, cell index, cell ch);
        void set_string_nth(string *str, cell index, cell ch);
@@ -458,8 +441,9 @@ struct factor_vm
        inline double untag_float_check(cell tagged);
        inline fixnum float_to_fixnum(cell tagged);
        inline double fixnum_to_float(cell tagged);
+
+       // tagged
        template<typename Type> Type *untag_check(cell value);
-       template<typename Type> Type *untag(cell value);
 
        //io
        void init_c_io();
@@ -494,12 +478,12 @@ struct factor_vm
        void update_literal_references(code_block *compiled);
        void relocate_code_block_step(relocation_entry rel, cell index, code_block *compiled);
        void update_word_references(code_block *compiled);
-       void update_code_block_for_full_gc(code_block *compiled);
+       void update_code_block_words_and_literals(code_block *compiled);
        void check_code_address(cell address);
        void relocate_code_block(code_block *compiled);
        void fixup_labels(array *labels, code_block *compiled);
-       code_block *allot_code_block(cell size, cell type);
-       code_block *add_code_block(cell type, cell code_, cell labels_, cell owner_, cell relocation_, cell literals_);
+       code_block *allot_code_block(cell size, code_block_type type);
+       code_block *add_code_block(code_block_type type, cell code_, cell labels_, cell owner_, cell relocation_, cell literals_);
 
        //code heap
        inline void check_code_pointer(cell ptr)
@@ -513,6 +497,8 @@ struct factor_vm
        bool in_code_heap_p(cell ptr);
        void jit_compile_word(cell word_, cell def_, bool relocate);
        void update_code_heap_words();
+       void update_code_heap_words_and_literals();
+       void relocate_code_heap();
        void primitive_modify_code_heap();
        void primitive_code_room();
        void forward_object_xts();
@@ -522,16 +508,19 @@ struct factor_vm
        void primitive_strip_stack_traces();
 
        /* Apply a function to every code block */
-       template<typename Iterator> void iterate_code_heap(Iterator &iter)
-       {
-               heap_block *scan = code->first_block();
-
-               while(scan)
+       template<typename Iterator> struct code_heap_iterator {
+               Iterator &iter;
+               explicit code_heap_iterator(Iterator &iter_) : iter(iter_) {}
+               void operator()(heap_block *block, cell size)
                {
-                       if(scan->type() != FREE_BLOCK_TYPE)
-                               iter((code_block *)scan);
-                       scan = code->next_block(scan);
+                       iter((code_block *)block,size);
                }
+       };
+
+       template<typename Iterator> void iterate_code_heap(Iterator &iter_)
+       {
+               code_heap_iterator<Iterator> iter(iter_);
+               code->allocator->iterate(iter);
        }
 
        //callbacks
@@ -566,7 +555,7 @@ struct factor_vm
        void primitive_callstack();
        void primitive_set_callstack();
        code_block *frame_code(stack_frame *frame);
-       cell frame_type(stack_frame *frame);
+       code_block_type frame_type(stack_frame *frame);
        cell frame_executing(stack_frame *frame);
        stack_frame *frame_successor(stack_frame *frame);
        cell frame_scan(stack_frame *frame);
@@ -705,6 +694,6 @@ struct factor_vm
 
 };
 
-extern unordered_map<THREADHANDLE, factor_vm *> thread_vms;
+extern std::map<THREADHANDLE, factor_vm *> thread_vms;
 
 }