VM: use a function update_relocation to replace the
code_block_compaction_relocation_visitor structdb4
parent
abb8bd74b9
commit
a5a7232b8f
|
@ -30,28 +30,57 @@ struct compaction_fixup {
|
||||||
object* translate_data(const object* obj) {
|
object* translate_data(const object* obj) {
|
||||||
if (obj < *data_finger)
|
if (obj < *data_finger)
|
||||||
return fixup_data((object*)obj);
|
return fixup_data((object*)obj);
|
||||||
else
|
|
||||||
return (object*)obj;
|
return (object*)obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
code_block* translate_code(const code_block* compiled) {
|
code_block* translate_code(const code_block* compiled) {
|
||||||
if (compiled < *code_finger)
|
if (compiled < *code_finger)
|
||||||
return fixup_code((code_block*)compiled);
|
return fixup_code((code_block*)compiled);
|
||||||
else
|
|
||||||
return (code_block*)compiled;
|
return (code_block*)compiled;
|
||||||
}
|
}
|
||||||
|
|
||||||
cell size(object* obj) {
|
cell size(object* obj) {
|
||||||
if (data_forwarding_map->marked_p((cell)obj))
|
if (data_forwarding_map->marked_p((cell)obj))
|
||||||
return obj->size(*this);
|
return obj->size(*this);
|
||||||
else
|
|
||||||
return data_forwarding_map->unmarked_block_size((cell)obj);
|
return data_forwarding_map->unmarked_block_size((cell)obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
cell size(code_block* compiled) {
|
cell size(code_block* compiled) {
|
||||||
if (code_forwarding_map->marked_p((cell)compiled))
|
if (code_forwarding_map->marked_p((cell)compiled))
|
||||||
return compiled->size(*this);
|
return compiled->size(*this);
|
||||||
else
|
return code_forwarding_map->unmarked_block_size((cell)compiled);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct code_compaction_fixup {
|
||||||
|
static const bool translated_code_block_map = false;
|
||||||
|
|
||||||
|
mark_bits* code_forwarding_map;
|
||||||
|
const code_block** code_finger;
|
||||||
|
|
||||||
|
code_compaction_fixup(mark_bits* code_forwarding_map,
|
||||||
|
const code_block** code_finger)
|
||||||
|
: code_forwarding_map(code_forwarding_map), code_finger(code_finger) {}
|
||||||
|
|
||||||
|
object* fixup_data(object* obj) { return obj; }
|
||||||
|
|
||||||
|
code_block* fixup_code(code_block* compiled) {
|
||||||
|
return (code_block*)code_forwarding_map->forward_block((cell)compiled);
|
||||||
|
}
|
||||||
|
|
||||||
|
object* translate_data(const object* obj) { return fixup_data((object*)obj); }
|
||||||
|
|
||||||
|
code_block* translate_code(const code_block* compiled) {
|
||||||
|
if (compiled < *code_finger)
|
||||||
|
return fixup_code((code_block*)compiled);
|
||||||
|
return (code_block*)compiled;
|
||||||
|
}
|
||||||
|
|
||||||
|
cell size(object* obj) { return obj->size(); }
|
||||||
|
|
||||||
|
cell size(code_block* compiled) {
|
||||||
|
if (code_forwarding_map->marked_p((cell)compiled))
|
||||||
|
return compiled->size(*this);
|
||||||
return code_forwarding_map->unmarked_block_size((cell)compiled);
|
return code_forwarding_map->unmarked_block_size((cell)compiled);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -74,18 +103,12 @@ struct object_compaction_updater {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Fixup> struct code_block_compaction_relocation_visitor {
|
template <typename Fixup>
|
||||||
factor_vm* parent;
|
void update_relocation(factor_vm* parent,
|
||||||
code_block* old_address;
|
cell old_entry_point,
|
||||||
Fixup fixup;
|
Fixup fixup,
|
||||||
|
instruction_operand op) {
|
||||||
code_block_compaction_relocation_visitor(factor_vm* parent,
|
cell old_offset = op.rel_offset() + old_entry_point;
|
||||||
code_block* old_address,
|
|
||||||
Fixup fixup)
|
|
||||||
: parent(parent), old_address(old_address), fixup(fixup) {}
|
|
||||||
|
|
||||||
void operator()(instruction_operand op) {
|
|
||||||
cell old_offset = op.rel_offset() + old_address->entry_point();
|
|
||||||
|
|
||||||
switch (op.rel_type()) {
|
switch (op.rel_type()) {
|
||||||
case RT_LITERAL: {
|
case RT_LITERAL: {
|
||||||
|
@ -116,8 +139,7 @@ template <typename Fixup> struct code_block_compaction_relocation_visitor {
|
||||||
op.store_value(op.load_value(old_offset));
|
op.store_value(op.load_value(old_offset));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Fixup> struct code_block_compaction_updater {
|
template <typename Fixup> struct code_block_compaction_updater {
|
||||||
factor_vm* parent;
|
factor_vm* parent;
|
||||||
|
@ -133,9 +155,11 @@ template <typename Fixup> struct code_block_compaction_updater {
|
||||||
void operator()(code_block* old_address, code_block* new_address, cell size) {
|
void operator()(code_block* old_address, code_block* new_address, cell size) {
|
||||||
forwarder.visit_code_block_objects(new_address);
|
forwarder.visit_code_block_objects(new_address);
|
||||||
|
|
||||||
code_block_compaction_relocation_visitor<Fixup> visitor(parent, old_address,
|
cell old_entry_point = old_address->entry_point();
|
||||||
fixup);
|
auto update_func = [&](instruction_operand op) {
|
||||||
new_address->each_instruction_operand(visitor);
|
update_relocation(parent, old_entry_point, fixup, op);
|
||||||
|
};
|
||||||
|
new_address->each_instruction_operand(update_func);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -222,41 +246,6 @@ void factor_vm::collect_compact_impl() {
|
||||||
event->ended_compaction();
|
event->ended_compaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct code_compaction_fixup {
|
|
||||||
static const bool translated_code_block_map = false;
|
|
||||||
|
|
||||||
mark_bits* code_forwarding_map;
|
|
||||||
const code_block** code_finger;
|
|
||||||
|
|
||||||
code_compaction_fixup(mark_bits* code_forwarding_map,
|
|
||||||
const code_block** code_finger)
|
|
||||||
: code_forwarding_map(code_forwarding_map), code_finger(code_finger) {}
|
|
||||||
|
|
||||||
object* fixup_data(object* obj) { return obj; }
|
|
||||||
|
|
||||||
code_block* fixup_code(code_block* compiled) {
|
|
||||||
return (code_block*)code_forwarding_map->forward_block((cell)compiled);
|
|
||||||
}
|
|
||||||
|
|
||||||
object* translate_data(const object* obj) { return fixup_data((object*)obj); }
|
|
||||||
|
|
||||||
code_block* translate_code(const code_block* compiled) {
|
|
||||||
if (compiled < *code_finger)
|
|
||||||
return fixup_code((code_block*)compiled);
|
|
||||||
else
|
|
||||||
return (code_block*)compiled;
|
|
||||||
}
|
|
||||||
|
|
||||||
cell size(object* obj) { return obj->size(); }
|
|
||||||
|
|
||||||
cell size(code_block* compiled) {
|
|
||||||
if (code_forwarding_map->marked_p((cell)compiled))
|
|
||||||
return compiled->size(*this);
|
|
||||||
else
|
|
||||||
return code_forwarding_map->unmarked_block_size((cell)compiled);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Compact just the code heap, after growing the data heap */
|
/* Compact just the code heap, after growing the data heap */
|
||||||
void factor_vm::collect_compact_code_impl() {
|
void factor_vm::collect_compact_code_impl() {
|
||||||
/* Figure out where blocks are going to go */
|
/* Figure out where blocks are going to go */
|
||||||
|
|
Loading…
Reference in New Issue