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) {
9 cell block_size = size + sizeof(code_block);
10 code_block* block = code->allocator->allot(block_size);
13 // If allocation failed, do a full GC and compact the code heap.
14 // A full GC that occurs as a result of the data heap filling up does not
15 // trigger a compaction. This setup ensures that most GCs do not compact
16 // the code heap, but if the code fills up, it probably means it will be
17 // fragmented after GC anyway, so its best to compact.
18 primitive_compact_gc();
19 block = code->allocator->allot(block_size);
21 // Insufficient room even after code GC, give up
23 std::cout << "Code heap used: " << code->allocator->occupied_space() << "\n";
24 std::cout << "Code heap free: " << code->allocator->free_space << "\n";
25 std::cout << "Code heap free_block_count: " << code->allocator->free_block_count << "\n";
26 std::cout << "Code heap largest_free_block: " << code->allocator->largest_free_block() << "\n";
27 std::cout << "Request : " << block_size << "\n";
28 fatal_error("Out of memory in allot_code_block", 0);
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);