]> gitweb.factorcode.org Git - factor.git/commitdiff
VM: free_list_allocator::first_block, last_block and next_block_after can be refactor...
authorBjörn Lindqvist <bjourne@gmail.com>
Tue, 6 Jan 2015 18:38:53 +0000 (19:38 +0100)
committerBjörn Lindqvist <bjourne@gmail.com>
Thu, 15 Jan 2015 09:29:13 +0000 (09:29 +0000)
vm/compaction.cpp
vm/free_list_allocator.hpp
vm/image.cpp
vm/tenured_space.hpp

index 74328dff143cd3a815a26ff05b2d524572d9245e..3cdd0070cee00d347ee61921b571cec6989cc9f1 100644 (file)
@@ -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);
index 5d3d04b6c962eaa8b94312c5b7309f95e1b503a8..57b132b06be9f06774e7ff1a24964aa42528c116 100644 (file)
@@ -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);
index f102c1ba23736a6e5bfae2e0da38e7c4b84a0765..c0f78b9608090b6c7b22c26c1da1fda9859193be 100644 (file)
@@ -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);
 
index 444e0a02ce3bea94bfcd1666b7c04f86f0a110c9..c163e9c0c2c9e78aab976a45be69fceeb5b2d104 100644 (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) {