VM: new iteration method each_object_each_slot()
used by find_data_references() and dump_edges() instead of the functor structsdb4
parent
59b7a50567
commit
7f545271f4
66
vm/debug.cpp
66
vm/debug.cpp
|
@ -298,64 +298,26 @@ void factor_vm::dump_objects(ostream& out, cell type) {
|
||||||
each_object(object_dumper);
|
each_object(object_dumper);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct find_data_reference_slot_visitor {
|
void factor_vm::find_data_references(ostream& out, cell look_for) {
|
||||||
cell look_for;
|
auto find_data_ref_func = [&](object* obj, cell* slot) {
|
||||||
object* obj;
|
if (look_for == *slot) {
|
||||||
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) {
|
|
||||||
out << padded_address((cell)obj) << " ";
|
out << padded_address((cell)obj) << " ";
|
||||||
parent->print_nested_obj(out, tag_dynamic(obj), 2);
|
print_nested_obj(out, tag_dynamic(obj), 2);
|
||||||
out << endl;
|
out << endl;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
};
|
each_object_each_slot(find_data_ref_func);
|
||||||
|
|
||||||
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 <typename SlotVisitor> 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<find_data_reference_slot_visitor>
|
|
||||||
visitor(look_for, this, out);
|
|
||||||
each_object(visitor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void factor_vm::dump_edges(ostream& out) {
|
void factor_vm::dump_edges(ostream& out) {
|
||||||
data_reference_object_visitor<dump_edges_slot_visitor> visitor(0, this, out);
|
auto dump_edges_func = [&](object* obj, cell* scan) {
|
||||||
each_object(visitor);
|
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 {
|
struct code_block_printer {
|
||||||
|
|
11
vm/vm.hpp
11
vm/vm.hpp
|
@ -330,6 +330,17 @@ struct factor_vm {
|
||||||
gc_off = false;
|
gc_off = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Iterator>
|
||||||
|
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
|
/* the write barrier must be called any time we are potentially storing a
|
||||||
pointer from an older generation to a younger one */
|
pointer from an older generation to a younger one */
|
||||||
inline void write_barrier(cell* slot_ptr) {
|
inline void write_barrier(cell* slot_ptr) {
|
||||||
|
|
Loading…
Reference in New Issue