]> gitweb.factorcode.org Git - factor.git/commitdiff
VM: move allot_code_block() to the allot.hpp file
authorBjörn Lindqvist <bjourne@gmail.com>
Thu, 13 Oct 2016 01:01:28 +0000 (03:01 +0200)
committerBjörn Lindqvist <bjourne@gmail.com>
Mon, 17 Oct 2016 06:03:48 +0000 (08:03 +0200)
vm/allot.hpp
vm/code_blocks.cpp

index e24629f7efbe484cac5d8ae38527ed99c78e852c..da4a69913b4845757fdbc1eb23438b19e15d0d77 100644 (file)
@@ -3,6 +3,39 @@ namespace factor {
 // It is up to the caller to fill in the object's fields in a
 // meaningful fashion!
 
+// Allocates memory
+inline code_block* factor_vm::allot_code_block(cell size,
+                                               code_block_type type) {
+  cell block_size = size + sizeof(code_block);
+  code_block* block = code->allocator->allot(block_size);
+
+  // If allocation failed, do a full GC and compact the code heap.
+  // A full GC that occurs as a result of the data heap filling up does not
+  // trigger a compaction. This setup ensures that most GCs do not compact
+  // the code heap, but if the code fills up, it probably means it will be
+  // fragmented after GC anyway, so its best to compact.
+  if (block == NULL) {
+    primitive_compact_gc();
+    block = code->allocator->allot(block_size);
+
+    // Insufficient room even after code GC, give up
+    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 << "Request       : " << block_size << "\n";
+      fatal_error("Out of memory in allot_code_block", 0);
+    }
+  }
+
+  // next time we do a minor GC, we have to trace this code block, since
+  // the fields of the code_block struct might point into nursery or aging
+  this->code->write_barrier(block);
+
+  block->set_type(type);
+  return block;
+}
+
 // Allocates memory
 inline object* factor_vm::allot_large_object(cell type, cell size) {
   // If tenured space does not have enough room, collect and compact
index ebabffcf16cf41f9fcbb4b2a7f5c8358ec31915f..89ea0a3605837adda15e71187806b2a4d464cd8c 100644 (file)
@@ -283,33 +283,6 @@ void factor_vm::fixup_labels(array* labels, code_block* compiled) {
   }
 }
 
-// Might GC
-// Allocates memory
-code_block* factor_vm::allot_code_block(cell size, code_block_type type) {
-  code_block* block = code->allocator->allot(size + sizeof(code_block));
-
-  // If allocation failed, do a full GC and compact the code heap.
-  // A full GC that occurs as a result of the data heap filling up does not
-  // trigger a compaction. This setup ensures that most GCs do not compact
-  // the code heap, but if the code fills up, it probably means it will be
-  // fragmented after GC anyway, so its best to compact.
-  if (block == NULL) {
-    primitive_compact_gc();
-    block = code->allocator->allot(size + sizeof(code_block));
-
-    // Insufficient room even after code GC, give up
-    if (block == NULL) {
-      std::cout << "Code heap used: " << code->allocator->occupied_space()
-                << "\n";
-      std::cout << "Code heap free: " << code->allocator->free_space << "\n";
-      fatal_error("Out of memory in allot_code_block", 0);
-    }
-  }
-
-  block->set_type(type);
-  return block;
-}
-
 // Might GC
 // Allocates memory
 code_block* factor_vm::add_code_block(code_block_type type, cell code_,
@@ -359,10 +332,6 @@ code_block* factor_vm::add_code_block(code_block_type type, cell code_,
       std::make_pair(compiled, literals.value()));
   this->code->all_blocks.insert((cell)compiled);
 
-  // next time we do a minor GC, we have to trace this code block, since
-  // the fields of the code_block struct might point into nursery or aging
-  this->code->write_barrier(compiled);
-
   return compiled;
 }