VM: refactoring that removes data_root_ranges

instead of storing data_root_ranges in data_roots, you can just store
cell pointers directly. the advantage with doing it that way is that
registration and traversal code becomes simpler (and slightly faster).
db4
Björn Lindqvist 2014-06-11 20:33:33 +02:00 committed by John Benediktsson
parent 77d4d5179c
commit 0c9e61ca99
5 changed files with 17 additions and 18 deletions

View File

@ -42,14 +42,18 @@ void factor_vm::primitive_resize_array() {
/* Allocates memory */
cell factor_vm::std_vector_to_array(std::vector<cell>& elements) {
cell element_count = elements.size();
data_roots.push_back(data_root_range(&elements[0], element_count));
cell orig_size = data_roots.size();
data_roots.reserve(orig_size + element_count);
for (cell n = 0; n < element_count; n++) {
data_roots.push_back(&elements[n]);
}
tagged<array> objects(allot_uninitialized_array<array>(element_count));
memcpy(objects->data(), &elements[0], element_count * sizeof(cell));
data_roots.pop_back();
data_roots.resize(orig_size);
return objects.value();
}

View File

@ -4,7 +4,7 @@ template <typename Type> struct data_root : public tagged<Type> {
factor_vm* parent;
void push() {
parent->data_roots.push_back(data_root_range(&this->value_, 1));
parent->data_roots.push_back(&this->value_);
}
data_root(cell value, factor_vm* parent)

View File

@ -323,12 +323,4 @@ struct tuple : public object {
cell* data() const { return (cell*)(this + 1); }
};
struct data_root_range {
cell* start;
cell len;
data_root_range(cell* start, cell len)
: start(start), len(len) {}
};
}

View File

@ -175,12 +175,14 @@ void slot_visitor<Fixup>::visit_stack_elements(segment* region, cell* top) {
}
template <typename Fixup> void slot_visitor<Fixup>::visit_data_roots() {
std::vector<data_root_range>::const_iterator iter =
std::vector<cell*>::const_iterator iter =
parent->data_roots.begin();
std::vector<data_root_range>::const_iterator end = parent->data_roots.end();
std::vector<cell*>::const_iterator end =
parent->data_roots.end();
for (; iter < end; iter++)
visit_object_array(iter->start, iter->start + iter->len);
for (; iter < end; iter++) {
visit_handle(*iter);
}
}
template <typename Fixup> void slot_visitor<Fixup>::visit_bignum_roots() {

View File

@ -112,7 +112,8 @@ struct factor_vm {
allocates memory, it must wrap any references to the data and code
heaps with data_root and code_root smart pointers, which register
themselves here. See data_roots.hpp and code_roots.hpp */
std::vector<data_root_range> data_roots;
std::vector<cell*> data_roots;
std::vector<cell> bignum_roots;
std::vector<code_root*> code_roots;