]> gitweb.factorcode.org Git - factor.git/blob - vm/allot.hpp
VM: allot_large_object fits better in the allot.hpp file
[factor.git] / vm / allot.hpp
1 namespace factor {
2
3 // It is up to the caller to fill in the object's fields in a
4 // meaningful fashion!
5
6 // Allocates memory
7 inline object* factor_vm::allot_large_object(cell type, cell size) {
8   // If tenured space does not have enough room, collect and compact
9   cell requested_size = size + data->high_water_mark();
10   if (!data->tenured->can_allot_p(requested_size)) {
11     primitive_compact_gc();
12
13     // If it still won't fit, grow the heap
14     if (!data->tenured->can_allot_p(requested_size)) {
15       gc(collect_growing_heap_op, size);
16     }
17   }
18
19   object* obj = data->tenured->allot(size);
20
21   // Allows initialization code to store old->new pointers
22   // without hitting the write barrier in the common case of
23   // a nursery allocation
24   write_barrier(obj, size);
25
26   obj->initialize(type);
27   return obj;
28 }
29
30 // Allocates memory
31 inline object* factor_vm::allot_object(cell type, cell size) {
32   FACTOR_ASSERT(!current_gc);
33
34   bump_allocator *nursery = data->nursery;
35
36   // If the object is bigger than the nursery, allocate it in tenured space
37   if (size >= nursery->size)
38     return allot_large_object(type, size);
39
40   // If the object is smaller than the nursery, allocate it in the nursery,
41   // after a GC if needed
42   if (nursery->here + size > nursery->end)
43     primitive_minor_gc();
44
45   object* obj = nursery->allot(size);
46   obj->initialize(type);
47
48   return obj;
49 }
50
51 }