cleanups from code review

db4
Joe Groff 2011-10-27 20:24:51 -07:00
parent 9eee44ce4a
commit 2d5360778f
11 changed files with 58 additions and 72 deletions

View File

@ -96,7 +96,6 @@ IN: bootstrap.x86
: signal-handler-save-regs ( -- regs ) volatile-regs R12 suffix ; : signal-handler-save-regs ( -- regs ) volatile-regs R12 suffix ;
:: jit-signal-handler-prolog ( -- frame-size ) :: jit-signal-handler-prolog ( -- frame-size )
! do we also need to save XMM?
signal-handler-save-regs :> save-regs signal-handler-save-regs :> save-regs
save-regs length bootstrap-cells 16 align stack-frame-size + :> frame-size save-regs length bootstrap-cells 16 align stack-frame-size + :> frame-size
RSP frame-size bootstrap-cell - SUB ! minus a cell for return address RSP frame-size bootstrap-cell - SUB ! minus a cell for return address

View File

@ -102,11 +102,6 @@ void factor_vm::init_code_heap(cell size)
code = new code_heap(size); code = new code_heap(size);
} }
bool factor_vm::in_code_heap_p(cell ptr)
{
return (ptr >= code->seg->start && ptr <= code->seg->end);
}
struct word_updater { struct word_updater {
factor_vm *parent; factor_vm *parent;
bool reset_inline_caches; bool reset_inline_caches;

View File

@ -7,10 +7,10 @@ void factor_vm::dispatch_signal_handler(cell *sp, cell *pc, cell handler)
{ {
if (!code->seg->in_segment_p(*pc) || *sp < ctx->callstack_seg->start + stack_reserved) if (!code->seg->in_segment_p(*pc) || *sp < ctx->callstack_seg->start + stack_reserved)
{ {
/* Fault came from foreign code, a callstack overflow, or we would probably /* Fault came from foreign code or a callstack overflow, or we don't
overflow if we tried the resumable handler. We can't resume, so cut the have enough callstack room to try the resumable handler. Cut the
callstack down to the shallowest Factor stack frame that leaves room for callstack down to the shallowest Factor stack frame that leaves room for
the signal handler to do its thing and launch the handler without going the signal handler to do its thing, and launch the handler without going
through the resumable subprimitive. */ through the resumable subprimitive. */
signal_resumable = false; signal_resumable = false;
stack_frame *frame = ctx->callstack_bottom - 1; stack_frame *frame = ctx->callstack_bottom - 1;
@ -61,9 +61,7 @@ void factor_vm::dispatch_signal_handler(cell *sp, cell *pc, cell handler)
handler_word = tagged<word>(special_objects[LEAF_SIGNAL_HANDLER_WORD]); handler_word = tagged<word>(special_objects[LEAF_SIGNAL_HANDLER_WORD]);
} }
else else
{ assert(false);
fatal_error("Invalid stack frame during signal handler", *sp);
}
*pc = (cell)handler_word->code->entry_point(); *pc = (cell)handler_word->code->entry_point();
} }

View File

@ -144,13 +144,13 @@ void factor_vm::print_objects(cell *start, cell *end)
void factor_vm::print_datastack() void factor_vm::print_datastack()
{ {
std::cout << "==== DATA STACK:\n"; std::cout << "==== DATA STACK:" << std::endl;
print_objects((cell *)ctx->datastack_seg->start,(cell *)ctx->datastack); print_objects((cell *)ctx->datastack_seg->start,(cell *)ctx->datastack);
} }
void factor_vm::print_retainstack() void factor_vm::print_retainstack()
{ {
std::cout << "==== RETAIN STACK:\n"; std::cout << "==== RETAIN STACK:" << std::endl;
print_objects((cell *)ctx->retainstack_seg->start,(cell *)ctx->retainstack); print_objects((cell *)ctx->retainstack_seg->start,(cell *)ctx->retainstack);
} }
@ -181,7 +181,7 @@ struct stack_frame_printer {
void factor_vm::print_callstack() void factor_vm::print_callstack()
{ {
std::cout << "==== CALL STACK:\n"; std::cout << "==== CALL STACK:" << std::endl;
stack_frame_printer printer(this); stack_frame_printer printer(this);
iterate_callstack(ctx,printer); iterate_callstack(ctx,printer);
} }
@ -339,41 +339,41 @@ void factor_vm::dump_code_heap()
{ {
code_block_printer printer(this); code_block_printer printer(this);
code->allocator->iterate(printer); code->allocator->iterate(printer);
std::cout << printer.reloc_size << " bytes used by relocation tables\n"; std::cout << printer.reloc_size << " bytes used by relocation tables" << std::endl;
std::cout << printer.parameter_size << " bytes used by parameter tables\n"; std::cout << printer.parameter_size << " bytes used by parameter tables" << std::endl;
} }
void factor_vm::factorbug() void factor_vm::factorbug()
{ {
if(fep_disabled) if(fep_disabled)
{ {
std::cout << "Low level debugger disabled\n"; std::cout << "Low level debugger disabled" << std::endl;
exit(1); exit(1);
} }
fep_p = true; fep_p = true;
std::cout << "Starting low level debugger...\n"; std::cout << "Starting low level debugger..." << std::endl;
std::cout << "Basic commands:\n"; std::cout << "Basic commands:" << std::endl;
std::cout << " q ^D -- quit Factor\n"; std::cout << " q ^D -- quit Factor" << std::endl;
std::cout << " c -- continue executing Factor - NOT SAFE\n"; std::cout << " c -- continue executing Factor - NOT SAFE" << std::endl;
std::cout << " t -- throw exception in Factor - NOT SAFE\n"; std::cout << " t -- throw exception in Factor - NOT SAFE" << std::endl;
std::cout << " .s .r .c -- print data, retain, call stacks\n"; std::cout << " .s .r .c -- print data, retain, call stacks" << std::endl;
std::cout << "Advanced commands:\n"; std::cout << "Advanced commands:" << std::endl;
std::cout << " e -- dump environment\n"; std::cout << " e -- dump environment" << std::endl;
std::cout << " d <addr> <count> -- dump memory\n"; std::cout << " d <addr> <count> -- dump memory" << std::endl;
std::cout << " u <addr> -- dump object at tagged <addr>\n"; std::cout << " u <addr> -- dump object at tagged <addr>" << std::endl;
std::cout << " . <addr> -- print object at tagged <addr>\n"; std::cout << " . <addr> -- print object at tagged <addr>" << std::endl;
std::cout << " g -- dump generations\n"; std::cout << " g -- dump generations" << std::endl;
std::cout << " ds dr -- dump data, retain stacks\n"; std::cout << " ds dr -- dump data, retain stacks" << std::endl;
std::cout << " trim -- toggle output trimming\n"; std::cout << " trim -- toggle output trimming" << std::endl;
std::cout << " data -- data heap dump\n"; std::cout << " data -- data heap dump" << std::endl;
std::cout << " words -- words dump\n"; std::cout << " words -- words dump" << std::endl;
std::cout << " tuples -- tuples dump\n"; std::cout << " tuples -- tuples dump" << std::endl;
std::cout << " refs <addr> -- find data heap references to object\n"; std::cout << " refs <addr> -- find data heap references to object" << std::endl;
std::cout << " push <addr> -- push object on data stack - NOT SAFE\n"; std::cout << " push <addr> -- push object on data stack - NOT SAFE" << std::endl;
std::cout << " gc -- trigger full GC - NOT SAFE\n"; std::cout << " gc -- trigger full GC - NOT SAFE" << std::endl;
std::cout << " code -- code heap dump\n"; std::cout << " code -- code heap dump" << std::endl;
bool seen_command = false; bool seen_command = false;
@ -381,7 +381,7 @@ void factor_vm::factorbug()
{ {
char cmd[1024]; char cmd[1024];
std::cout << "READY\n"; std::cout << "READY" << std::endl;
std::cout.flush(); std::cout.flush();
std::cin >> std::setw(1024) >> cmd >> std::setw(0); std::cin >> std::setw(1024) >> cmd >> std::setw(0);
@ -464,7 +464,7 @@ void factor_vm::factorbug()
else if(strcmp(cmd,"refs") == 0) else if(strcmp(cmd,"refs") == 0)
{ {
cell addr = read_cell_hex(); cell addr = read_cell_hex();
std::cout << "Data heap references:\n"; std::cout << "Data heap references:" << std::endl;
find_data_references(addr); find_data_references(addr);
std::cout << std::endl; std::cout << std::endl;
} }
@ -482,14 +482,14 @@ void factor_vm::factorbug()
else if(strcmp(cmd,"gc") == 0) else if(strcmp(cmd,"gc") == 0)
primitive_full_gc(); primitive_full_gc();
else else
std::cout << "unknown command\n"; std::cout << "unknown command" << std::endl;
} }
} }
void factor_vm::primitive_die() void factor_vm::primitive_die()
{ {
std::cout << "The die word was called by the library. Unless you called it yourself,\n"; std::cout << "The die word was called by the library. Unless you called it yourself," << std::endl;
std::cout << "you have triggered a bug in Factor. Please report.\n"; std::cout << "you have triggered a bug in Factor. Please report." << std::endl;
factorbug(); factorbug();
} }

View File

@ -172,15 +172,15 @@ void factor_vm::enqueue_safepoint_fep()
void factor_vm::enqueue_safepoint_sample() void factor_vm::enqueue_safepoint_sample()
{ {
if (!sampling_p) if (sampling_profiler_p)
fatal_error("Received sampling signal while not sampling!", 0);
++safepoint_sample_count; ++safepoint_sample_count;
} }
void factor_vm::handle_safepoint() void factor_vm::handle_safepoint()
{ {
code->unguard_safepoint(); code->unguard_safepoint();
if (safepoint_fep) { if (safepoint_fep)
{
std::cout << "Interrupted\n"; std::cout << "Interrupted\n";
factorbug(); factorbug();
safepoint_fep = false; safepoint_fep = false;

View File

@ -5,7 +5,7 @@ namespace factor
void factor_vm::init_profiler() void factor_vm::init_profiler()
{ {
profiling_p = false; counting_profiler_p = false;
} }
/* Allocates memory */ /* Allocates memory */
@ -22,7 +22,7 @@ code_block *factor_vm::compile_profiling_stub(cell word_)
/* Allocates memory */ /* Allocates memory */
void factor_vm::set_profiling(bool profiling) void factor_vm::set_profiling(bool profiling)
{ {
if(profiling == profiling_p) if(profiling == counting_profiler_p)
return; return;
/* Push everything to tenured space so that we can heap scan /* Push everything to tenured space so that we can heap scan
@ -31,7 +31,7 @@ void factor_vm::set_profiling(bool profiling)
data_root<array> words(find_all_words(),this); data_root<array> words(find_all_words(),this);
profiling_p = profiling; counting_profiler_p = profiling;
cell length = array_capacity(words.untagged()); cell length = array_capacity(words.untagged());
for(cell i = 0; i < length; i++) for(cell i = 0; i < length; i++)

View File

@ -7,8 +7,8 @@ factor_vm::factor_vm() :
nursery(0,0), nursery(0,0),
callback_id(0), callback_id(0),
c_to_factor_func(NULL), c_to_factor_func(NULL),
profiling_p(false), counting_profiler_p(false),
sampling_p(false), sampling_profiler_p(false),
safepoint_fep(false), safepoint_fep(false),
safepoint_sample_count(0), safepoint_sample_count(0),
gc_off(false), gc_off(false),

View File

@ -61,9 +61,9 @@ struct factor_vm
c_to_factor_func_type c_to_factor_func; c_to_factor_func_type c_to_factor_func;
/* Is call counting enabled? */ /* Is call counting enabled? */
bool profiling_p; bool counting_profiler_p;
/* Is sampling profiler enabled? */ /* Is sampling profiler enabled? */
bool sampling_p; bool sampling_profiler_p;
/* Global variables used to pass fault handler state from signal handler /* Global variables used to pass fault handler state from signal handler
to VM */ to VM */
@ -350,16 +350,11 @@ struct factor_vm
return (Type *)allot_object(Type::type_number,size); 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) inline void check_data_pointer(object *pointer)
{ {
#ifdef FACTOR_DEBUG #ifdef FACTOR_DEBUG
if(!(current_gc && current_gc->op == collect_growing_heap_op)) 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 #endif
} }
@ -566,7 +561,6 @@ struct factor_vm
} }
void init_code_heap(cell size); void init_code_heap(cell size);
bool in_code_heap_p(cell ptr);
void update_code_heap_words(bool reset_inline_caches); void update_code_heap_words(bool reset_inline_caches);
void initialize_code_blocks(); void initialize_code_blocks();
void primitive_modify_code_heap(); void primitive_modify_code_heap();

View File

@ -62,7 +62,7 @@ word *factor_vm::allot_word(cell name_, cell vocab_, cell hashcode_)
new_word->code = NULL; new_word->code = NULL;
jit_compile_word(new_word.value(),new_word->def,true); jit_compile_word(new_word.value(),new_word->def,true);
if(profiling_p) if(counting_profiler_p)
{ {
code_block *profiling_block = compile_profiling_stub(new_word.value()); code_block *profiling_block = compile_profiling_stub(new_word.value());
new_word->profiling = profiling_block; new_word->profiling = profiling_block;
@ -89,7 +89,7 @@ void factor_vm::primitive_word_code()
data_root<word> w(ctx->pop(),this); data_root<word> w(ctx->pop(),this);
w.untag_check(this); w.untag_check(this);
if(profiling_p) if(counting_profiler_p)
{ {
ctx->push(from_unsigned_cell((cell)w->profiling->entry_point())); ctx->push(from_unsigned_cell((cell)w->profiling->entry_point()));
ctx->push(from_unsigned_cell((cell)w->profiling + w->profiling->size())); ctx->push(from_unsigned_cell((cell)w->profiling + w->profiling->size()));
@ -103,7 +103,7 @@ void factor_vm::primitive_word_code()
void factor_vm::update_word_entry_point(word *w) void factor_vm::update_word_entry_point(word *w)
{ {
if(profiling_p && w->profiling) if(counting_profiler_p && w->profiling)
w->entry_point = w->profiling->entry_point(); w->entry_point = w->profiling->entry_point();
else else
w->entry_point = w->code->entry_point(); w->entry_point = w->code->entry_point();