]> gitweb.factorcode.org Git - factor.git/blobdiff - vm/vm.hpp
vm: strip out call-counting profiler
[factor.git] / vm / vm.hpp
index 04946bea1d6d6e8aa5522f1e4333254cee74c2a5..6836bf11ab65dda6cb89f1b39a1bac5b67280b44 100755 (executable)
--- a/vm/vm.hpp
+++ b/vm/vm.hpp
@@ -36,6 +36,9 @@ struct factor_vm
        // ^^^^^^
        //
 
+       /* Handle to the main thread we run in */
+       THREADHANDLE thread;
+
        /* Data stack and retain stack sizes */
        cell datastack_size, retainstack_size, callstack_size;
 
@@ -60,20 +63,23 @@ struct factor_vm
        /* External entry points */
        c_to_factor_func_type c_to_factor_func;
 
-       /* Is call counting enabled? */
-       bool profiling_p;
-       /* Is sampling profiler enabled? */
-       bool sampling_p;
+       /* Is profiling enabled? */
+       volatile cell sampling_profiler_p;
+       fixnum samples_per_second;
 
        /* Global variables used to pass fault handler state from signal handler
        to VM */
-       bool signal_from_leaf;
+       bool signal_resumable;
        cell signal_number;
        cell signal_fault_addr;
        unsigned int signal_fpu_status;
-       bool safepoint_fep;
-       cell safepoint_sample_count;
-       sigset_t safepoint_signals;
+
+       /* Pipe used to notify Factor multiplexer of signals */
+       int signal_pipe_input, signal_pipe_output;
+
+       /* State kept by the sampling profiler */
+       std::vector<profiling_sample> samples;
+       std::vector<cell> sample_callstacks;
 
        /* GC is off during heap walking */
        bool gc_off;
@@ -89,6 +95,10 @@ struct factor_vm
 
        /* Only set if we're performing a GC */
        gc_state *current_gc;
+       volatile cell current_gc_p;
+
+       /* Set if we're in the jit */
+       volatile fixnum current_jit_count;
 
        /* Mark stack */
        std::vector<cell> mark_stack;
@@ -106,6 +116,7 @@ struct factor_vm
 
        /* Debugger */
        bool fep_p;
+       bool fep_help_was_shown;
        bool fep_disabled;
        bool full_output;
 
@@ -130,6 +141,12 @@ struct factor_vm
        /* Stack for signal handlers, only used on Unix */
        segment *signal_callstack_seg;
 
+       /* Are we already handling a fault? Used to catch double memory faults */
+       bool faulting_p;
+
+       /* Safepoint state */
+       volatile safepoint_state safepoint;
+
        // contexts
        context *new_context();
        void init_context(context *ctx);
@@ -181,11 +198,16 @@ struct factor_vm
        void primitive_clone();
        void primitive_become();
 
-       // profiler
-       void init_profiler();
-       code_block *compile_profiling_stub(cell word_);
-       void set_profiling(bool profiling);
-       void primitive_profiling();
+       // sampling_profiler
+       void clear_samples();
+       void record_sample();
+       void record_callstack_sample(cell *begin, cell *end);
+       void start_sampling_profiler(fixnum rate);
+       void end_sampling_profiler();
+       void set_sampling_profiler(fixnum rate);
+       void primitive_sampling_profiler();
+       void primitive_get_samples();
+       void primitive_clear_samples();
 
        // errors
        void general_error(vm_error_type error, cell arg1, cell arg2);
@@ -199,10 +221,6 @@ struct factor_vm
        void memory_signal_handler_impl();
        void synchronous_signal_handler_impl();
        void fp_signal_handler_impl();
-       void enqueue_safepoint_fep();
-       void enqueue_safepoint_sample();
-       void enqueue_safepoint_signal(cell signal);
-       void handle_safepoint();
 
        // bignum
        int bignum_equal_p(bignum * x, bignum * y);
@@ -352,16 +370,11 @@ struct factor_vm
                return (Type *)allot_object(Type::type_number,size);
        }
 
-       inline bool in_data_heap_p(cell pointer)
-       {
-               return (pointer >= data->seg->start && pointer < data->seg->end);
-       }
-
        inline void check_data_pointer(object *pointer)
        {
        #ifdef FACTOR_DEBUG
                if(!(current_gc && current_gc->op == collect_growing_heap_op))
-                       assert(in_data_heap_p((cell)pointer));
+                       assert(data->seg->in_segment_p((cell)pointer));
        #endif
        }
 
@@ -375,7 +388,9 @@ struct factor_vm
        void print_word(word* word, cell nesting);
        void print_factor_string(string* str);
        void print_array(array* array, cell nesting);
+       void print_byte_array(byte_array *array, cell nesting);
        void print_tuple(tuple *tuple, cell nesting);
+       void print_alien(alien *alien, cell nesting);
        void print_nested_obj(cell obj, fixnum nesting);
        void print_obj(cell obj);
        void print_objects(cell *start, cell *end);
@@ -390,6 +405,7 @@ struct factor_vm
        void find_data_references_step(cell *scan);
        void find_data_references(cell look_for_);
        void dump_code_heap();
+       void factorbug_usage(bool advanced_p);
        void factorbug();
        void primitive_die();
 
@@ -435,7 +451,6 @@ struct factor_vm
        word *allot_word(cell name_, cell vocab_, cell hashcode_);
        void primitive_word();
        void primitive_word_code();
-       void update_word_entry_point(word *w_);
        void primitive_optimized_p();
        void primitive_wrapper();
        void jit_compile_word(cell word_, cell def_, bool relocating);
@@ -568,7 +583,6 @@ struct factor_vm
        }
 
        void init_code_heap(cell size);
-       bool in_code_heap_p(cell ptr);
        void update_code_heap_words(bool reset_inline_caches);
        void initialize_code_blocks();
        void primitive_modify_code_heap();
@@ -616,18 +630,9 @@ struct factor_vm
        void primitive_set_innermost_stack_frame_quot();
        void primitive_callstack_bounds();
        template<typename Iterator> void iterate_callstack(context *ctx, Iterator &iterator);
-       void dispatch_signal_handler(cell *sp, cell *pc, cell newpc);
-       void dispatch_signal_handler_from_leaf(cell *sp, cell *pc, cell newpc);
 
-       template<typename CellA, typename CellB, typename CellC>
-       void dispatch_signal_handler(CellA *sp, CellB *pc, CellC newpc)
-       {
-               dispatch_signal_handler(
-                       reinterpret_cast<cell*>(sp),
-                       reinterpret_cast<cell*>(pc),
-                       (cell)newpc
-               );
-       }
+       // cpu-*
+       void dispatch_signal_handler(cell *sp, cell *pc, cell newpc);
 
        // alien
        char *pinned_alien_offset(cell obj);
@@ -645,10 +650,9 @@ struct factor_vm
 
        // quotations
        void primitive_jit_compile();
-       code_block *lazy_jit_compile_block();
+       void *lazy_jit_compile_entry_point();
        void primitive_array_to_quotation();
        void primitive_quotation_code();
-       void set_quot_entry_point(quotation *quot, code_block *code);
        code_block *jit_compile_quot(cell owner_, cell quot_, bool relocating);
        void jit_compile_quot(cell quot_, bool relocating);
        fixnum quot_code_offset_to_scan(cell quot_, cell offset);
@@ -721,19 +725,23 @@ struct factor_vm
        void ffi_dlclose(dll *dll);
        void c_to_factor_toplevel(cell quot);
        void init_signals();
+       void start_sampling_profiler_timer();
+       void end_sampling_profiler_timer();
+       void open_console();
+       void lock_console();
+       void unlock_console();
 
        // os-windows
   #if defined(WINDOWS)
+       HANDLE sampler_thread;
+       void sampler_thread_loop();
+
        const vm_char *vm_executable_path();
        const vm_char *default_image_path();
        void windows_image_path(vm_char *full_path, vm_char *temp_path, unsigned int length);
        BOOL windows_stat(vm_char *path);
 
-  #if defined(WINNT)
-       void open_console();
        LONG exception_handler(PEXCEPTION_RECORD e, void *frame, PCONTEXT c, void *dispatch);
-       BOOL ctrl_handler(DWORD dwCtrlType);
-  #endif
 
   #else  // UNIX
        void dispatch_signal(void *uap, void (handler)());
@@ -744,7 +752,7 @@ struct factor_vm
        void call_fault_handler(exception_type_t exception, exception_data_type_t code, MACH_EXC_STATE_TYPE *exc_state, MACH_THREAD_STATE_TYPE *thread_state, MACH_FLOAT_STATE_TYPE *float_state);
   #endif
 
-       factor_vm();
+       factor_vm(THREADHANDLE thread_id);
        ~factor_vm();
 };