Permalink
Browse files

VM: merge of the free_list and free_list_allocator classes

Seem simpler to have all the free list stuff in one class rather than
split it over two classes.
  • Loading branch information...
1 parent f0eec26 commit c2f4fdb172102c4f32c44ded2fc7067ad8dcd521 @bjourne bjourne committed Oct 3, 2016
Showing with 157 additions and 178 deletions.
  1. +0 −1 GNUmakefile
  2. +0 −1 Nmakefile
  3. +1 −1 vm/code_blocks.cpp
  4. +3 −3 vm/data_heap.cpp
  5. +0 −118 vm/free_list.cpp
  6. +153 −54 vm/free_list.hpp
View
@@ -43,7 +43,6 @@ ifdef CONFIG
vm/entry_points.o \
vm/errors.o \
vm/factor.o \
- vm/free_list.o \
vm/full_collector.o \
vm/gc.o \
vm/image.o \
View
@@ -67,7 +67,6 @@ DLL_OBJS = $(PLAF_DLL_OBJS) \
vm\entry_points.obj \
vm\errors.obj \
vm\factor.obj \
- vm\free_list.obj \
vm\full_collector.obj \
vm\gc.obj \
vm\image.obj \
View
@@ -301,7 +301,7 @@ code_block* factor_vm::allot_code_block(cell size, code_block_type type) {
if (block == NULL) {
std::cout << "Code heap used: " << code->allocator->occupied_space()
<< "\n";
- std::cout << "Code heap free: " << code->allocator->free_space() << "\n";
+ std::cout << "Code heap free: " << code->allocator->free_space << "\n";
fatal_error("Out of memory in add-compiled-block", 0);
}
}
View
@@ -93,7 +93,7 @@ bool data_heap::high_fragmentation_p() {
}
bool data_heap::low_memory_p() {
- return tenured->free_space() <= high_water_mark();
+ return tenured->free_space <= high_water_mark();
}
void data_heap::mark_all_cards() {
@@ -123,9 +123,9 @@ data_heap_room factor_vm::data_room() {
room.aging_free = data->aging->free_space();
room.tenured_size = data->tenured->size;
room.tenured_occupied = data->tenured->occupied_space();
- room.tenured_total_free = data->tenured->free_space();
+ room.tenured_total_free = data->tenured->free_space;
room.tenured_contiguous_free = data->tenured->largest_free_block();
- room.tenured_free_block_count = data->tenured->free_block_count();
+ room.tenured_free_block_count = data->tenured->free_block_count;
room.cards = data->cards_end - data->cards;
room.decks = data->decks_end - data->decks;
room.mark_stack = mark_stack.capacity() * sizeof(cell);
View
@@ -1,118 +0,0 @@
-#include "master.hpp"
-
-namespace factor {
-
-void free_list::clear_free_list() {
- for (cell i = 0; i < free_list_count; i++)
- small_blocks[i].clear();
- large_blocks.clear();
- free_block_count = 0;
- free_space = 0;
-}
-
-void free_list::initial_free_list(cell start, cell end, cell occupied) {
- clear_free_list();
- if (occupied != end - start) {
- free_heap_block* last_block = (free_heap_block*)(start + occupied);
- last_block->make_free(end - (cell)last_block);
- add_to_free_list(last_block);
- }
-}
-
-void free_list::add_to_free_list(free_heap_block* block) {
- cell size = block->size();
-
- free_block_count++;
- free_space += size;
-
- if (size < free_list_count * data_alignment)
- small_blocks[size / data_alignment].push_back(block);
- else
- large_blocks.insert(block);
-}
-
-free_heap_block* free_list::find_free_block(cell size) {
- // Check small free lists
- cell bucket = size / data_alignment;
- if (bucket < free_list_count) {
- std::vector<free_heap_block*>& blocks = small_blocks[bucket];
- if (blocks.size() == 0) {
- // Round up to a multiple of 'size'
- cell large_block_size = ((allocation_page_size + size - 1) / size) * size;
-
- // Allocate a block this big
- free_heap_block* large_block = find_free_block(large_block_size);
- if (!large_block)
- return NULL;
-
- large_block = split_free_block(large_block, large_block_size);
-
- // Split it up into pieces and add each piece back to the free list
- for (cell offset = 0; offset < large_block_size; offset += size) {
- free_heap_block* small_block = large_block;
- large_block = (free_heap_block*)((cell)large_block + size);
- small_block->make_free(size);
- add_to_free_list(small_block);
- }
- }
-
- free_heap_block* block = blocks.back();
- blocks.pop_back();
-
- free_block_count--;
- free_space -= block->size();
-
- return block;
- } else {
- // Check large free list
- free_heap_block key;
- key.make_free(size);
- large_block_set::iterator iter = large_blocks.lower_bound(&key);
- large_block_set::iterator end = large_blocks.end();
-
- if (iter != end) {
- free_heap_block* block = *iter;
- large_blocks.erase(iter);
-
- free_block_count--;
- free_space -= block->size();
-
- return block;
- }
-
- return NULL;
- }
-}
-
-free_heap_block* free_list::split_free_block(free_heap_block* block,
- cell size) {
- if (block->size() != size) {
- // split the block in two
- free_heap_block* split = (free_heap_block*)((cell)block + size);
- split->make_free(block->size() - size);
- block->make_free(size);
- add_to_free_list(split);
- }
-
- return block;
-}
-
-bool free_list::can_allot_p(cell size) {
- return largest_free_block() >= std::max(size, allocation_page_size);
-}
-
-cell free_list::largest_free_block() {
- if (large_blocks.size()) {
- large_block_set::reverse_iterator last = large_blocks.rbegin();
- return (*last)->size();
- } else {
- for (int i = free_list_count - 1; i >= 0; i--) {
- if (small_blocks[i].size())
- return small_blocks[i].back()->size();
- }
-
- return 0;
- }
-}
-
-}
Oops, something went wrong.

0 comments on commit c2f4fdb

Please sign in to comment.