VM: prettier and more detailed output when dumping generations

db4
Björn Lindqvist 2015-10-08 16:25:35 +02:00
parent 77f0d0042e
commit cb55fcf20f
3 changed files with 32 additions and 25 deletions

View File

@ -264,26 +264,39 @@ void factor_vm::dump_memory(ostream& out, cell from, cell to) {
dump_cell(out, from); dump_cell(out, from);
} }
template <typename Generation> void dump_memory_range(ostream& out, const char* name, cell name_w,
void factor_vm::dump_generation(ostream& out, const char* name, Generation* gen) { cell start, cell end) {
out << name << ": "; out << setw(name_w) << left << name << ": ";
out << "Start=" << gen->start;
out << ", size=" << gen->size; out << "[" << (void*)start << " -> " << (void*)end << "] ";
out << ", end=" << gen->end; out << setw(10) << right << (end - start) << " bytes" << endl;
out << endl;
} }
void factor_vm::dump_generations(ostream& out) { template <typename Generation>
out << hex; void dump_generation(ostream& out, const char* name, Generation* gen) {
dump_memory_range(out, name, 10, gen->start, gen->end);
}
dump_generation(out, "Nursery", &nursery); void factor_vm::dump_memory_layout(ostream& out) {
dump_generation(out, "Nursery", data->nursery);
dump_generation(out, "Aging", data->aging); dump_generation(out, "Aging", data->aging);
dump_generation(out, "Tenured", data->tenured); dump_generation(out, "Tenured", data->tenured);
dump_memory_range(out, "Cards", 10, (cell)data->cards, (cell)data->cards_end);
out << "Cards:"; out << endl << "Contexts:" << endl << endl;
out << "base=" << (cell)data->cards << ", "; FACTOR_FOR_EACH(active_contexts) {
out << "size=" << (cell)(data->cards_end - data->cards) << endl; context* the_ctx = *iter;
out << dec; segment* ds = the_ctx->datastack_seg;
segment* rs = the_ctx->retainstack_seg;
segment* cs = the_ctx->callstack_seg;
if (the_ctx == ctx) {
out << " Active:" << endl;
}
dump_memory_range(out, " Datastack", 14, ds->start, ds->end);
dump_memory_range(out, " Retainstack", 14, rs->start, rs->end);
dump_memory_range(out, " Callstack", 14, cs->start, cs->end);
out << endl;
}
} }
void factor_vm::dump_objects(ostream& out, cell type) { void factor_vm::dump_objects(ostream& out, cell type) {
@ -382,7 +395,7 @@ void factor_vm::factorbug_usage(bool advanced_p) {
<< endl; << endl;
cout << " . <addr> -- print object at tagged <addr>" cout << " . <addr> -- print object at tagged <addr>"
<< endl; << endl;
cout << " g -- dump generations" << endl; cout << " g -- dump memory layout" << endl;
cout << " ds dr -- dump data, retain stacks" << endl; cout << " ds dr -- dump data, retain stacks" << endl;
cout << " trim -- toggle output trimming" << endl; cout << " trim -- toggle output trimming" << endl;
cout << " data -- data heap dump" << endl; cout << " data -- data heap dump" << endl;
@ -498,7 +511,7 @@ void factor_vm::factorbug() {
for (cell i = 0; i < special_object_count; i++) for (cell i = 0; i < special_object_count; i++)
dump_cell(cout, (cell)&special_objects[i]); dump_cell(cout, (cell)&special_objects[i]);
} else if (cmd == "g") } else if (cmd == "g")
dump_generations(cout); dump_memory_layout(cout);
else if (cmd == "c") { else if (cmd == "c") {
exit_fep(this); exit_fep(this);
return; return;
@ -542,11 +555,7 @@ void factor_vm::factorbug() {
} }
void factor_vm::primitive_die() { void factor_vm::primitive_die() {
cout << "The die word was called by the library. Unless you called it " critical_error("The die word was called by the library.", 0);
"yourself," << endl;
cout << "you have triggered a bug in Factor. Please report."
<< endl;
factorbug();
} }
} }

View File

@ -32,7 +32,7 @@ void critical_error(const char* msg, cell tagged) {
void out_of_memory(const char *msg) { void out_of_memory(const char *msg) {
std::cout << "Out of memory: " << msg << "\n\n"; std::cout << "Out of memory: " << msg << "\n\n";
current_vm()->dump_generations(std::cout); current_vm()->dump_memory_layout(std::cout);
abort(); abort();
} }

View File

@ -410,9 +410,7 @@ struct factor_vm {
void print_callstack_object(ostream& out, callstack* obj); void print_callstack_object(ostream& out, callstack* obj);
void dump_cell(ostream& out, cell x); void dump_cell(ostream& out, cell x);
void dump_memory(ostream& out, cell from, cell to); void dump_memory(ostream& out, cell from, cell to);
template <typename Generation> void dump_memory_layout(ostream& out);
void dump_generation(ostream& out, const char* name, Generation* gen);
void dump_generations(ostream& out);
void dump_objects(ostream& out, cell type); void dump_objects(ostream& out, cell type);
void dump_edges(ostream& out); void dump_edges(ostream& out);
void find_data_references(ostream& out, cell look_for_); void find_data_references(ostream& out, cell look_for_);