]> gitweb.factorcode.org Git - factor.git/commitdiff
vm: callstack_reversed in code_block_visitor
authorJoe Groff <arcata@gmail.com>
Mon, 5 Dec 2011 22:18:42 +0000 (14:18 -0800)
committerJoe Groff <arcata@gmail.com>
Wed, 14 Dec 2011 17:56:48 +0000 (09:56 -0800)
vm/callstack.hpp
vm/code_block_visitor.hpp
vm/cpu-x86.hpp
vm/debug.cpp
vm/mark_bits.hpp
vm/slot_visitor.hpp
vm/vm.hpp

index ccddba117a659d29f446219e11e79490e90deff1..bd16117b40b10bb8519a84ac4161fc634199eeef 100755 (executable)
@@ -40,7 +40,8 @@ void factor_vm::iterate_callstack_object_reversed(callstack *stack_,
        }
 }
 
-template<typename Iterator> void factor_vm::iterate_callstack_object(callstack *stack_, Iterator &iterator)
+template<typename Iterator> void factor_vm::iterate_callstack_object(callstack *stack_,
+       Iterator &iterator)
 {
        data_root<callstack> stack(stack_,this);
        fixnum frame_offset = factor::untag_fixnum(stack->length) - sizeof(stack_frame);
@@ -53,6 +54,39 @@ template<typename Iterator> void factor_vm::iterate_callstack_object(callstack *
        }
 }
 
+template<typename Iterator, typename Fixup>
+void factor_vm::iterate_callstack_reversed(context *ctx, Iterator &iterator, Fixup &fixup)
+{
+       if (ctx->callstack_top == ctx->callstack_bottom)
+               return;
+
+       char *frame_top = (char*)ctx->callstack_top;
+
+       while (frame_top < (char*)ctx->callstack_bottom)
+       {
+               void *addr = frame_return_address((void*)frame_top);
+               FACTOR_ASSERT(addr != 0);
+
+               void *fixed_addr = (void*)fixup.translate_code((code_block*)addr);
+
+               code_block *owner = code->code_block_for_address((cell)fixed_addr);
+               cell frame_size = owner->stack_frame_size_for_address((cell)fixed_addr);
+
+#ifdef FACTOR_DEBUG
+               // check our derived owner and frame size against the ones stored in the frame
+               // by the function prolog
+               stack_frame *frame = (stack_frame*)(frame_top + frame_size) - 1;
+               void *fixed_entry_point =
+                       (void*)fixup.translate_code((code_block*)frame->entry_point);
+               FACTOR_ASSERT(owner->entry_point() == fixed_entry_point);
+               FACTOR_ASSERT(frame_size == frame->size);
+#endif
+
+               iterator(frame_top, owner, fixed_addr);
+               frame_top += frame_size;
+       }
+}
+
 template<typename Iterator>
 void factor_vm::iterate_callstack_reversed(context *ctx, Iterator &iterator)
 {
index 2421ace669657b6565939e9d0c31181dc880807e..96881ed37f74009d4e74a6c5033afd72d033487a 100644 (file)
@@ -42,12 +42,13 @@ struct call_frame_code_block_visitor {
        explicit call_frame_code_block_visitor(factor_vm *parent_, Fixup fixup_) :
                parent(parent_), fixup(fixup_) {}
 
-       void operator()(stack_frame *frame)
+       void operator()(void *frame_top, code_block *owner, void *addr)
        {
-               cell offset = parent->frame_offset(frame);
-               code_block *compiled = fixup.fixup_code(parent->frame_code(frame));
-               frame->entry_point = compiled->entry_point();
-               parent->set_frame_offset(frame,offset);
+               set_frame_return_address(frame_top, addr);
+               // XXX remove this when prolog data is removed
+               cell frame_size = owner->stack_frame_size_for_address((cell)addr);
+               stack_frame *frame = (stack_frame*)((char*)frame_top + frame_size) - 1;
+               frame->entry_point = owner->entry_point();
        }
 };
 
@@ -74,7 +75,7 @@ void code_block_visitor<Fixup>::visit_object_code_block(object *obj)
                {
                        callstack *stack = (callstack *)obj;
                        call_frame_code_block_visitor<Fixup> call_frame_visitor(parent,fixup);
-                       parent->iterate_callstack_object(stack,call_frame_visitor);
+                       parent->iterate_callstack_object_reversed(stack,call_frame_visitor,fixup);
                        break;
                }
        }
@@ -110,7 +111,7 @@ template<typename Fixup>
 void code_block_visitor<Fixup>::visit_context_code_blocks()
 {
        call_frame_code_block_visitor<Fixup> call_frame_visitor(parent,fixup);
-       parent->iterate_active_callstacks(call_frame_visitor);
+       parent->iterate_active_callstacks_reversed(call_frame_visitor,fixup);
 }
 
 template<typename Fixup>
index 542d3a8c088c7f487ae1fafd60ba1ff397ed5ce9..45731976b9166d398b1701077e01c8701d54c5e1 100755 (executable)
@@ -8,9 +8,9 @@ inline static void* frame_return_address(void *frame_top)
        return *(void**)frame_top;
 }
 
-inline static void set_frame_return_address(void *frame_top, cell return_address)
+inline static void set_frame_return_address(void *frame_top, void *return_address)
 {
-       *(cell*)frame_top = return_address;
+       *(void**)frame_top = return_address;
 }
 
 #define CALLSTACK_BOTTOM(ctx) (stack_frame *)(ctx->callstack_seg->end - sizeof(cell) * 5)
index 10b99fccf5d5027fd34290c7702e12b3e9498194..026ac7fd5ec7e87dd94d56f016214665dcb2059d 100755 (executable)
@@ -614,6 +614,8 @@ void factor_vm::factorbug()
                }
                else if(strcmp(cmd,"code") == 0)
                        dump_code_heap();
+               else if(strcmp(cmd,"compact-gc") == 0)
+                       primitive_compact_gc();
                else if(strcmp(cmd,"gc") == 0)
                        primitive_full_gc();
                else if(strcmp(cmd,"compact-gc") == 0)
index e721342975e52d852369bd7d9241745d15f1067a..b546f69d6a393eb22574c0a5fd6ddaf3426febfc 100644 (file)
@@ -130,12 +130,13 @@ template<typename Block> struct mark_bits {
                //FACTOR_ASSERT(marked_p(original));
 #endif
                std::pair<cell,cell> position = bitmap_deref(original);
+               cell offset = (cell)original & (data_alignment - 1);
 
                cell approx_popcount = forwarding[position.first];
                cell mask = ((cell)1 << position.second) - 1;
 
                cell new_line_number = approx_popcount + popcount(marked[position.first] & mask);
-               Block *new_block = line_block(new_line_number);
+               Block *new_block = (Block*)((char*)line_block(new_line_number) + offset);
 #ifdef FACTOR_DEBUG
                FACTOR_ASSERT(new_block <= original);
 #endif
index 131fcd6ea58503b2cbf3732d5503a767862e3431..85f5b4fe11cbdcf516f4f386673ad0dbbf01cf9d 100755 (executable)
@@ -373,7 +373,7 @@ template<typename Fixup>
 void slot_visitor<Fixup>::visit_callstack(context *ctx)
 {
        call_frame_slot_visitor<Fixup> call_frame_visitor(parent,this);
-       parent->iterate_callstack_reversed(ctx,call_frame_visitor);
+       parent->iterate_callstack_reversed(ctx,call_frame_visitor,fixup);
 }
 
 template<typename Fixup>
index c7e762e1afdb2880cb2a7ced8322630320e0d773..6770fa20b80d032adfaa43eb474463f816b81edc 100755 (executable)
--- a/vm/vm.hpp
+++ b/vm/vm.hpp
@@ -178,7 +178,8 @@ struct factor_vm
        void primitive_check_datastack();
        void primitive_load_locals();
 
-       template<typename Iterator> void iterate_active_callstacks(Iterator &iter)
+       template<typename Iterator>
+       void iterate_active_callstacks(Iterator &iter)
        {
                std::set<context *>::const_iterator begin = active_contexts.begin();
                std::set<context *>::const_iterator end = active_contexts.end();
@@ -188,6 +189,17 @@ struct factor_vm
                }
        }
 
+       template<typename Iterator, typename Fixup>
+       void iterate_active_callstacks_reversed(Iterator &iter, Fixup &fixup)
+       {
+               std::set<context *>::const_iterator begin = active_contexts.begin();
+               std::set<context *>::const_iterator end = active_contexts.end();
+               while(begin != end)
+               {
+                       iterate_callstack_reversed(*begin++,iter,fixup);
+               }
+       }
+
        // run
        void primitive_exit();
        void primitive_nano_count();
@@ -648,8 +660,15 @@ struct factor_vm
        void primitive_innermost_stack_frame_scan();
        void primitive_set_innermost_stack_frame_quot();
        void primitive_callstack_bounds();
-       template<typename Iterator> void iterate_callstack_reversed(context *ctx, Iterator &iterator);
-       template<typename Iterator> void iterate_callstack(context *ctx, Iterator &iterator);
+
+       template<typename Iterator>
+       void iterate_callstack_reversed(context *ctx, Iterator &iterator);
+
+       template<typename Iterator, typename Fixup>
+       void iterate_callstack_reversed(context *ctx, Iterator &iterator, Fixup &fixup);
+
+       template<typename Iterator>
+       void iterate_callstack(context *ctx, Iterator &iterator);
 
        // cpu-*
        void dispatch_signal_handler(cell *sp, cell *pc, cell newpc);