VM: Refactor vm.cpp/hpp to Factor style
parent
8522265169
commit
5614985c3d
19
vm/vm.cpp
19
vm/vm.cpp
|
@ -1,10 +1,9 @@
|
|||
#include "master.hpp"
|
||||
|
||||
namespace factor
|
||||
{
|
||||
namespace factor {
|
||||
|
||||
factor_vm::factor_vm(THREADHANDLE thread) :
|
||||
nursery(0,0),
|
||||
factor_vm::factor_vm(THREADHANDLE thread)
|
||||
: nursery(0, 0),
|
||||
faulting_p(false),
|
||||
thread(thread),
|
||||
callback_id(0),
|
||||
|
@ -23,23 +22,19 @@ factor_vm::factor_vm(THREADHANDLE thread) :
|
|||
full_output(false),
|
||||
last_nano_count(0),
|
||||
signal_callstack_seg(NULL),
|
||||
safepoint()
|
||||
{
|
||||
safepoint() {
|
||||
primitive_reset_dispatch_stats();
|
||||
}
|
||||
|
||||
factor_vm::~factor_vm()
|
||||
{
|
||||
factor_vm::~factor_vm() {
|
||||
delete_contexts();
|
||||
if(signal_callstack_seg)
|
||||
{
|
||||
if (signal_callstack_seg) {
|
||||
delete signal_callstack_seg;
|
||||
signal_callstack_seg = NULL;
|
||||
}
|
||||
std::list<void**>::const_iterator iter = function_descriptors.begin();
|
||||
std::list<void**>::const_iterator end = function_descriptors.end();
|
||||
while(iter != end)
|
||||
{
|
||||
while (iter != end) {
|
||||
delete[] * iter;
|
||||
iter++;
|
||||
}
|
||||
|
|
119
vm/vm.hpp
119
vm/vm.hpp
|
@ -1,11 +1,9 @@
|
|||
namespace factor
|
||||
{
|
||||
namespace factor {
|
||||
|
||||
struct growable_array;
|
||||
struct code_root;
|
||||
|
||||
struct factor_vm
|
||||
{
|
||||
struct factor_vm {
|
||||
//
|
||||
// vvvvvv
|
||||
// THESE FIELDS ARE ACCESSED DIRECTLY FROM FACTOR. See:
|
||||
|
@ -138,8 +136,7 @@ struct factor_vm
|
|||
/* Incrementing object counter for identity hashing */
|
||||
cell object_counter;
|
||||
|
||||
/* Sanity check to ensure that monotonic counter doesn't
|
||||
decrease */
|
||||
/* Sanity check to ensure that monotonic counter doesn't decrease */
|
||||
u64 last_nano_count;
|
||||
|
||||
/* Stack for signal handlers, only used on Unix */
|
||||
|
@ -155,7 +152,8 @@ struct factor_vm
|
|||
context* new_context();
|
||||
void init_context(context* ctx);
|
||||
void delete_context(context* old_context);
|
||||
void init_contexts(cell datastack_size_, cell retainstack_size_, cell callstack_size_);
|
||||
void init_contexts(cell datastack_size_, cell retainstack_size_,
|
||||
cell callstack_size_);
|
||||
void delete_contexts();
|
||||
cell begin_callback(cell quot);
|
||||
void end_callback();
|
||||
|
@ -179,12 +177,10 @@ struct factor_vm
|
|||
void primitive_load_locals();
|
||||
|
||||
template <typename Iterator, typename Fixup>
|
||||
void iterate_active_callstacks(Iterator &iter, Fixup &fixup)
|
||||
{
|
||||
void iterate_active_callstacks(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)
|
||||
{
|
||||
while (begin != end) {
|
||||
iterate_callstack(*begin++, iter, fixup);
|
||||
}
|
||||
}
|
||||
|
@ -237,7 +233,8 @@ struct factor_vm
|
|||
bignum* bignum_add(bignum* x, bignum* y);
|
||||
bignum* bignum_subtract(bignum* x, bignum* y);
|
||||
bignum* bignum_multiply(bignum* x, bignum* y);
|
||||
void bignum_divide(bignum * numerator, bignum * denominator, bignum * * quotient, bignum * * remainder);
|
||||
void bignum_divide(bignum* numerator, bignum* denominator, bignum** quotient,
|
||||
bignum** remainder);
|
||||
bignum* bignum_quotient(bignum* numerator, bignum* denominator);
|
||||
bignum* bignum_remainder(bignum* numerator, bignum* denominator);
|
||||
cell bignum_to_cell(bignum* bignum);
|
||||
|
@ -250,26 +247,39 @@ struct factor_vm
|
|||
bignum* bignum_add_unsigned(bignum* x, bignum* y, int negative_p);
|
||||
bignum* bignum_subtract_unsigned(bignum* x, bignum* y);
|
||||
bignum* bignum_multiply_unsigned(bignum* x, bignum* y, int negative_p);
|
||||
bignum *bignum_multiply_unsigned_small_factor(bignum * x, bignum_digit_type y,int negative_p);
|
||||
bignum* bignum_multiply_unsigned_small_factor(bignum* x, bignum_digit_type y,
|
||||
int negative_p);
|
||||
void bignum_destructive_add(bignum* bignum, bignum_digit_type n);
|
||||
void bignum_destructive_scale_up(bignum* bignum, bignum_digit_type factor);
|
||||
void bignum_divide_unsigned_large_denominator(bignum * numerator, bignum * denominator,
|
||||
bignum * * quotient, bignum * * remainder, int q_negative_p, int r_negative_p);
|
||||
void bignum_divide_unsigned_large_denominator(
|
||||
bignum* numerator, bignum* denominator, bignum** quotient,
|
||||
bignum** remainder, int q_negative_p, int r_negative_p);
|
||||
void bignum_divide_unsigned_normalized(bignum* u, bignum* v, bignum* q);
|
||||
bignum_digit_type bignum_divide_subtract(bignum_digit_type * v_start, bignum_digit_type * v_end,
|
||||
bignum_digit_type guess, bignum_digit_type * u_start);
|
||||
void bignum_divide_unsigned_medium_denominator(bignum * numerator,bignum_digit_type denominator,
|
||||
bignum * * quotient, bignum * * remainder,int q_negative_p, int r_negative_p);
|
||||
void bignum_destructive_normalization(bignum * source, bignum * target, int shift_left);
|
||||
bignum_digit_type bignum_divide_subtract(bignum_digit_type* v_start,
|
||||
bignum_digit_type* v_end,
|
||||
bignum_digit_type guess,
|
||||
bignum_digit_type* u_start);
|
||||
void bignum_divide_unsigned_medium_denominator(
|
||||
bignum* numerator, bignum_digit_type denominator, bignum** quotient,
|
||||
bignum** remainder, int q_negative_p, int r_negative_p);
|
||||
void bignum_destructive_normalization(bignum* source, bignum* target,
|
||||
int shift_left);
|
||||
void bignum_destructive_unnormalization(bignum* bignum, int shift_right);
|
||||
bignum_digit_type bignum_digit_divide(bignum_digit_type uh, bignum_digit_type ul,
|
||||
bignum_digit_type v, bignum_digit_type * q) /* return value */;
|
||||
bignum_digit_type bignum_digit_divide_subtract(bignum_digit_type v1, bignum_digit_type v2,
|
||||
bignum_digit_type guess, bignum_digit_type * u);
|
||||
void bignum_divide_unsigned_small_denominator(bignum * numerator, bignum_digit_type denominator,
|
||||
bignum * * quotient, bignum * * remainder,int q_negative_p, int r_negative_p);
|
||||
bignum_digit_type bignum_destructive_scale_down(bignum * bignum, bignum_digit_type denominator);
|
||||
bignum * bignum_remainder_unsigned_small_denominator(bignum * n, bignum_digit_type d, int negative_p);
|
||||
bignum_digit_type bignum_digit_divide(
|
||||
bignum_digit_type uh, bignum_digit_type ul, bignum_digit_type v,
|
||||
bignum_digit_type* q) /* return value */;
|
||||
bignum_digit_type bignum_digit_divide_subtract(bignum_digit_type v1,
|
||||
bignum_digit_type v2,
|
||||
bignum_digit_type guess,
|
||||
bignum_digit_type* u);
|
||||
void bignum_divide_unsigned_small_denominator(
|
||||
bignum* numerator, bignum_digit_type denominator, bignum** quotient,
|
||||
bignum** remainder, int q_negative_p, int r_negative_p);
|
||||
bignum_digit_type bignum_destructive_scale_down(
|
||||
bignum* bignum, bignum_digit_type denominator);
|
||||
bignum* bignum_remainder_unsigned_small_denominator(bignum* n,
|
||||
bignum_digit_type d,
|
||||
int negative_p);
|
||||
bignum* bignum_digit_to_bignum(bignum_digit_type digit, int negative_p);
|
||||
bignum* allot_bignum(bignum_length_type length, int negative_p);
|
||||
bignum* allot_bignum_zeroed(bignum_length_type length, int negative_p);
|
||||
|
@ -306,18 +316,15 @@ struct factor_vm
|
|||
void primitive_all_instances();
|
||||
|
||||
template <typename Generation, typename Iterator>
|
||||
inline void each_object(Generation *gen, Iterator &iterator)
|
||||
{
|
||||
inline void each_object(Generation* gen, Iterator& iterator) {
|
||||
cell obj = gen->first_object();
|
||||
while(obj)
|
||||
{
|
||||
while (obj) {
|
||||
iterator((object*)obj);
|
||||
obj = gen->next_object_after(obj);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Iterator> inline void each_object(Iterator &iterator)
|
||||
{
|
||||
template <typename Iterator> inline void each_object(Iterator& iterator) {
|
||||
gc_off = true;
|
||||
|
||||
each_object(data->tenured, iterator);
|
||||
|
@ -329,14 +336,12 @@ struct factor_vm
|
|||
|
||||
/* the write barrier must be called any time we are potentially storing a
|
||||
pointer from an older generation to a younger one */
|
||||
inline void write_barrier(cell *slot_ptr)
|
||||
{
|
||||
inline void write_barrier(cell* slot_ptr) {
|
||||
*(char*)(cards_offset + ((cell) slot_ptr >> card_bits)) = card_mark_mask;
|
||||
*(char*)(decks_offset + ((cell) slot_ptr >> deck_bits)) = card_mark_mask;
|
||||
}
|
||||
|
||||
inline void write_barrier(object *obj, cell size)
|
||||
{
|
||||
inline void write_barrier(object* obj, cell size) {
|
||||
cell start = (cell) obj & (~card_size + 1);
|
||||
cell end = ((cell) obj + size + card_size - 1) & (~card_size + 1);
|
||||
|
||||
|
@ -376,13 +381,11 @@ struct factor_vm
|
|||
object* allot_large_object(cell type, cell size);
|
||||
|
||||
/* Allocates memory */
|
||||
template<typename Type> Type *allot(cell size)
|
||||
{
|
||||
template <typename Type> Type* allot(cell size) {
|
||||
return (Type*)allot_object(Type::type_number, size);
|
||||
}
|
||||
|
||||
inline void check_data_pointer(object *pointer)
|
||||
{
|
||||
inline void check_data_pointer(object* pointer) {
|
||||
#ifdef FACTOR_DEBUG
|
||||
if (!(current_gc && current_gc->op == collect_growing_heap_op))
|
||||
FACTOR_ASSERT(data->seg->in_segment_p((cell) pointer));
|
||||
|
@ -391,7 +394,8 @@ struct factor_vm
|
|||
|
||||
// generic arrays
|
||||
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>
|
||||
bool reallot_array_in_place_p(Array* array, cell capacity);
|
||||
template <typename Array> Array* reallot_array(Array* array_, cell capacity);
|
||||
|
||||
// debug
|
||||
|
@ -411,7 +415,8 @@ struct factor_vm
|
|||
void print_callstack_object(callstack* obj);
|
||||
void dump_cell(cell x);
|
||||
void dump_memory(cell from, cell to);
|
||||
template<typename Generation> void dump_generation(const char *name, Generation *gen);
|
||||
template <typename Generation>
|
||||
void dump_generation(const char* name, Generation* gen);
|
||||
void dump_generations();
|
||||
void dump_objects(cell type);
|
||||
void dump_edges();
|
||||
|
@ -442,8 +447,7 @@ struct factor_vm
|
|||
void primitive_set_string_nth_fast();
|
||||
|
||||
// booleans
|
||||
cell tag_boolean(cell untagged)
|
||||
{
|
||||
cell tag_boolean(cell untagged) {
|
||||
return (untagged ? true_object : false_object);
|
||||
}
|
||||
|
||||
|
@ -587,14 +591,13 @@ struct factor_vm
|
|||
void fixup_labels(array* labels, code_block* compiled);
|
||||
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 parameters_, cell literals_,
|
||||
cell frame_size_untagged);
|
||||
cell owner_, cell relocation_, cell parameters_,
|
||||
cell literals_, cell frame_size_untagged);
|
||||
|
||||
//code heap
|
||||
inline void check_code_pointer(cell ptr) {}
|
||||
|
||||
template<typename Iterator> void each_code_block(Iterator &iter)
|
||||
{
|
||||
template <typename Iterator> void each_code_block(Iterator& iter) {
|
||||
code->allocator->iterate(iter);
|
||||
}
|
||||
|
||||
|
@ -700,7 +703,9 @@ struct factor_vm
|
|||
void deallocate_inline_cache(cell return_address);
|
||||
cell determine_inline_cache_type(array* cache_entries);
|
||||
void update_pic_count(cell type);
|
||||
code_block *compile_inline_cache(fixnum index,cell generic_word_,cell methods_,cell cache_entries_,bool tail_call_p);
|
||||
code_block* compile_inline_cache(fixnum index, cell generic_word_,
|
||||
cell methods_, cell cache_entries_,
|
||||
bool tail_call_p);
|
||||
void* megamorphic_call_stub(cell generic_word);
|
||||
cell inline_cache_size(cell cache_entries);
|
||||
cell add_inline_cache_entry(cell cache_entries_, cell klass_, cell method_);
|
||||
|
@ -759,10 +764,12 @@ struct factor_vm
|
|||
|
||||
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);
|
||||
void windows_image_path(vm_char* full_path, vm_char* temp_path,
|
||||
unsigned int length);
|
||||
BOOL windows_stat(vm_char* path);
|
||||
|
||||
LONG exception_handler(PEXCEPTION_RECORD e, void *frame, PCONTEXT c, void *dispatch);
|
||||
LONG exception_handler(PEXCEPTION_RECORD e, void* frame, PCONTEXT c,
|
||||
void* dispatch);
|
||||
|
||||
#else // UNIX
|
||||
void dispatch_signal(void* uap, void(handler)());
|
||||
|
@ -770,7 +777,11 @@ struct factor_vm
|
|||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
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);
|
||||
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(THREADHANDLE thread_id);
|
||||
|
|
Loading…
Reference in New Issue