3 // It is up to the caller to fill in the object's fields in a
7 inline code_block* factor_vm::allot_code_block(cell size,
8 code_block_type type) {
10 cell block_size = size + sizeof(code_block);
11 cell required_free = block_size + code->high_water_mark();
12 if (!code->allocator->can_allot_p(required_free)) {
14 // If allocation failed, do a full GC and compact the code heap.
15 // A full GC that occurs as a result of the data heap filling up does not
16 // trigger a compaction. This setup ensures that most GCs do not compact
17 // the code heap, but if the code fills up, it probably means it will be
18 // fragmented after GC anyway, so its best to compact.
19 primitive_compact_gc();
21 // Insufficient room even after code GC, give up
22 if (!code->allocator->can_allot_p(required_free)) {
23 std::cout << "Code heap used: " << code->allocator->occupied_space()
25 std::cout << "Code heap free: " << code->allocator->free_space << "\n";
26 std::cout << "Request : " << block_size << "\n";
27 fatal_error("Out of memory in allot_code_block", 0);
30 code_block* block = code->allocator->allot(block_size);
32 // next time we do a minor GC, we have to trace this code block, since
33 // the fields of the code_block struct might point into nursery or aging
34 this->code->write_barrier(block);
36 block->set_type(type);
41 inline object* factor_vm::allot_large_object(cell type, cell size) {
42 // If tenured space does not have enough room, collect and compact
43 cell required_free = size + data->high_water_mark();
44 if (!data->tenured->can_allot_p(required_free)) {
45 primitive_compact_gc();
47 // If it still won't fit, grow the heap
48 if (!data->tenured->can_allot_p(required_free)) {
49 gc(COLLECT_GROWING_DATA_HEAP_OP, size);
52 object* obj = data->tenured->allot(size);
54 // Allows initialization code to store old->new pointers
55 // without hitting the write barrier in the common case of
56 // a nursery allocation
57 write_barrier(obj, size);
59 obj->initialize(type);
64 inline object* factor_vm::allot_object(cell type, cell size) {
65 FACTOR_ASSERT(!current_gc);
67 bump_allocator *nursery = data->nursery;
69 // If the object is bigger than the nursery, allocate it in tenured space
70 if (size >= nursery->size)
71 return allot_large_object(type, size);
73 // If the object is smaller than the nursery, allocate it in the nursery,
74 // after a GC if needed
75 if (nursery->here + size > nursery->end)
78 object* obj = nursery->allot(size);
79 obj->initialize(type);