VM: free_list_allocator::first_block, last_block and next_block_after can be refactored away
parent
1beac119d8
commit
f0bf693beb
|
@ -188,8 +188,8 @@ void factor_vm::collect_compact_impl(bool trace_contexts_p) {
|
|||
data_forwarding_map->compute_forwarding();
|
||||
code_forwarding_map->compute_forwarding();
|
||||
|
||||
const object* data_finger = tenured->first_block();
|
||||
const code_block* code_finger = code->allocator->first_block();
|
||||
const object* data_finger = (object*)tenured->start;
|
||||
const code_block* code_finger = (code_block*)code->allocator->start;
|
||||
|
||||
{
|
||||
compaction_fixup fixup(data_forwarding_map, code_forwarding_map, &data_finger,
|
||||
|
@ -285,7 +285,7 @@ void factor_vm::collect_compact_code_impl(bool trace_contexts_p) {
|
|||
mark_bits* code_forwarding_map = &code->allocator->state;
|
||||
code_forwarding_map->compute_forwarding();
|
||||
|
||||
const code_block* code_finger = code->allocator->first_block();
|
||||
const code_block* code_finger = (code_block*)code->allocator->start;
|
||||
|
||||
code_compaction_fixup fixup(code_forwarding_map, &code_finger);
|
||||
slot_visitor<code_compaction_fixup> data_forwarder(this, fixup);
|
||||
|
|
|
@ -18,9 +18,6 @@ template <typename Block> struct free_list_allocator {
|
|||
free_list_allocator(cell size, cell start);
|
||||
void initial_free_list(cell occupied);
|
||||
bool contains_p(Block* block);
|
||||
Block* first_block();
|
||||
Block* last_block();
|
||||
Block* next_block_after(Block* block);
|
||||
Block* next_allocated_block_after(Block* block);
|
||||
bool can_allot_p(cell size);
|
||||
Block* allot(cell size);
|
||||
|
@ -58,27 +55,14 @@ bool free_list_allocator<Block>::contains_p(Block* block) {
|
|||
return ((cell)block - start) < size;
|
||||
}
|
||||
|
||||
template <typename Block> Block* free_list_allocator<Block>::first_block() {
|
||||
return (Block*)start;
|
||||
}
|
||||
|
||||
template <typename Block> Block* free_list_allocator<Block>::last_block() {
|
||||
return (Block*)end;
|
||||
}
|
||||
|
||||
template <typename Block>
|
||||
Block* free_list_allocator<Block>::next_block_after(Block* block) {
|
||||
return (Block*)((cell)block + block->size());
|
||||
}
|
||||
|
||||
template <typename Block>
|
||||
Block* free_list_allocator<Block>::next_allocated_block_after(Block* block) {
|
||||
while (block != this->last_block() && block->free_p()) {
|
||||
while ((cell)block != this->end && block->free_p()) {
|
||||
free_heap_block* free_block = (free_heap_block*)block;
|
||||
block = (object*)((cell)free_block + free_block->size());
|
||||
}
|
||||
|
||||
if (block == this->last_block())
|
||||
if ((cell)block == this->end)
|
||||
return NULL;
|
||||
else
|
||||
return block;
|
||||
|
@ -128,8 +112,8 @@ template <typename Iterator>
|
|||
void free_list_allocator<Block>::sweep(Iterator& iter) {
|
||||
free_blocks.clear_free_list();
|
||||
|
||||
cell start = (cell)this->first_block();
|
||||
cell end = (cell)this->last_block();
|
||||
cell start = this->start;
|
||||
cell end = this->end;
|
||||
|
||||
while (start != end) {
|
||||
/* find next unmarked block */
|
||||
|
@ -185,8 +169,7 @@ template <typename Block>
|
|||
template <typename Iterator, typename Fixup>
|
||||
void free_list_allocator<Block>::compact(Iterator& iter, Fixup fixup,
|
||||
const Block** finger) {
|
||||
heap_compactor<Block, Iterator> compactor(&state, first_block(), iter,
|
||||
finger);
|
||||
heap_compactor<Block, Iterator> compactor(&state, (Block*)start, iter, finger);
|
||||
iterate(compactor, fixup);
|
||||
|
||||
/* Now update the free list; there will be a single free block at
|
||||
|
@ -199,8 +182,8 @@ void free_list_allocator<Block>::compact(Iterator& iter, Fixup fixup,
|
|||
template <typename Block>
|
||||
template <typename Iterator, typename Fixup>
|
||||
void free_list_allocator<Block>::iterate(Iterator& iter, Fixup fixup) {
|
||||
Block* scan = first_block();
|
||||
Block* end = last_block();
|
||||
Block* scan = (Block*)this->start;
|
||||
Block* end = (Block*)this->end;
|
||||
|
||||
while (scan != end) {
|
||||
cell size = fixup.size(scan);
|
||||
|
|
|
@ -37,7 +37,7 @@ void factor_vm::load_code_heap(FILE* file, image_header* h, vm_parameters* p) {
|
|||
|
||||
if (h->code_size != 0) {
|
||||
size_t bytes_read =
|
||||
safe_fread(code->allocator->first_block(), 1, h->code_size, file);
|
||||
safe_fread((void*)code->allocator->start, 1, h->code_size, file);
|
||||
if (bytes_read != h->code_size) {
|
||||
std::cout << "truncated image: " << bytes_read << " bytes read, ";
|
||||
std::cout << h->code_size << " bytes expected\n";
|
||||
|
@ -306,7 +306,7 @@ bool factor_vm::save_image(const vm_char* saving_filename,
|
|||
ok = false;
|
||||
if (safe_fwrite((void*)data->tenured->start, h.data_size, 1, file) != 1)
|
||||
ok = false;
|
||||
if (safe_fwrite(code->allocator->first_block(), h.code_size, 1, file) != 1)
|
||||
if (safe_fwrite((void*)code->allocator->start, h.code_size, 1, file) != 1)
|
||||
ok = false;
|
||||
safe_fclose(file);
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ struct tenured_space : free_list_allocator<object> {
|
|||
}
|
||||
|
||||
cell first_object() {
|
||||
return (cell)next_allocated_block_after(this->first_block());
|
||||
return (cell)next_allocated_block_after((object*)this->start);
|
||||
}
|
||||
|
||||
cell next_object_after(cell scan) {
|
||||
|
|
Loading…
Reference in New Issue