diff --git a/vm/debug.cpp b/vm/debug.cpp index 43ec2795ad..da00e76f87 100644 --- a/vm/debug.cpp +++ b/vm/debug.cpp @@ -298,64 +298,26 @@ void factor_vm::dump_objects(ostream& out, cell type) { each_object(object_dumper); } -struct find_data_reference_slot_visitor { - cell look_for; - object* obj; - factor_vm* parent; - ostream& out; - - find_data_reference_slot_visitor(cell look_for, - object* obj, - factor_vm* parent, - ostream& out) - : look_for(look_for), obj(obj), parent(parent), out(out) {} - - void operator()(cell* scan) { - if (look_for == *scan) { +void factor_vm::find_data_references(ostream& out, cell look_for) { + auto find_data_ref_func = [&](object* obj, cell* slot) { + if (look_for == *slot) { out << padded_address((cell)obj) << " "; - parent->print_nested_obj(out, tag_dynamic(obj), 2); + print_nested_obj(out, tag_dynamic(obj), 2); out << endl; } - } -}; - -struct dump_edges_slot_visitor { - object* obj; - factor_vm* parent; - ostream& out; - - dump_edges_slot_visitor(cell, object* obj, factor_vm* parent, ostream& out) - : obj(obj), parent(parent), out(out) {} - - void operator()(cell* scan) { - if (TAG(*scan) > F_TYPE) - out << (void*)tag_dynamic(obj) << " ==> " << (void*)*scan << endl; - } -}; - -template struct data_reference_object_visitor { - cell look_for; - factor_vm* parent; - ostream& out; - - data_reference_object_visitor(cell look_for, factor_vm* parent, ostream& out) - : look_for(look_for), parent(parent), out(out) {} - - void operator()(object* obj) { - SlotVisitor visitor(look_for, obj, parent, out); - obj->each_slot(visitor); - } -}; - -void factor_vm::find_data_references(ostream& out, cell look_for) { - data_reference_object_visitor - visitor(look_for, this, out); - each_object(visitor); + }; + each_object_each_slot(find_data_ref_func); } void factor_vm::dump_edges(ostream& out) { - data_reference_object_visitor visitor(0, this, out); - each_object(visitor); + auto dump_edges_func = [&](object* obj, cell* scan) { + if (TAG(*scan) > F_TYPE) { + out << (void*)tag_dynamic(obj); + out << " ==> "; + out << (void*)*scan << endl; + } + }; + each_object_each_slot(dump_edges_func); } struct code_block_printer { diff --git a/vm/vm.hpp b/vm/vm.hpp index 3d47484f3a..545cab10c1 100644 --- a/vm/vm.hpp +++ b/vm/vm.hpp @@ -330,6 +330,17 @@ struct factor_vm { gc_off = false; } + template + inline void each_object_each_slot(Iterator& iterator) { + auto each_object_func = [&](object* obj) { + auto each_slot_func = [&](cell* slot) { + iterator(obj, slot); + }; + obj->each_slot(each_slot_func); + }; + each_object(each_object_func); + } + /* 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) {