2013-05-11 22:32:45 -04:00
|
|
|
namespace factor {
|
2009-10-31 03:30:48 -04:00
|
|
|
|
2016-09-22 07:13:55 -04:00
|
|
|
// It is up to the caller to fill in the object's fields in a
|
|
|
|
|
// meaningful fashion!
|
|
|
|
|
|
|
|
|
|
// Allocates memory
|
|
|
|
|
inline object* factor_vm::allot_large_object(cell type, cell size) {
|
|
|
|
|
// If tenured space does not have enough room, collect and compact
|
|
|
|
|
cell requested_size = size + data->high_water_mark();
|
|
|
|
|
if (!data->tenured->can_allot_p(requested_size)) {
|
|
|
|
|
primitive_compact_gc();
|
|
|
|
|
|
|
|
|
|
// If it still won't fit, grow the heap
|
|
|
|
|
if (!data->tenured->can_allot_p(requested_size)) {
|
|
|
|
|
gc(collect_growing_heap_op, size);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
object* obj = data->tenured->allot(size);
|
|
|
|
|
|
|
|
|
|
// Allows initialization code to store old->new pointers
|
|
|
|
|
// without hitting the write barrier in the common case of
|
|
|
|
|
// a nursery allocation
|
|
|
|
|
write_barrier(obj, size);
|
|
|
|
|
|
|
|
|
|
obj->initialize(type);
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
2016-08-21 10:26:04 -04:00
|
|
|
|
|
|
|
|
// Allocates memory
|
2013-05-11 22:32:45 -04:00
|
|
|
inline object* factor_vm::allot_object(cell type, cell size) {
|
|
|
|
|
FACTOR_ASSERT(!current_gc);
|
2009-12-02 01:48:41 -05:00
|
|
|
|
2014-11-21 04:34:23 -05:00
|
|
|
bump_allocator *nursery = data->nursery;
|
2015-08-14 18:19:44 -04:00
|
|
|
|
2016-08-21 10:26:04 -04:00
|
|
|
// If the object is bigger than the nursery, allocate it in tenured space
|
2015-08-14 18:19:44 -04:00
|
|
|
if (size >= nursery->size)
|
|
|
|
|
return allot_large_object(type, size);
|
|
|
|
|
|
2016-08-21 10:26:04 -04:00
|
|
|
// If the object is smaller than the nursery, allocate it in the nursery,
|
|
|
|
|
// after a GC if needed
|
2015-08-14 18:19:44 -04:00
|
|
|
if (nursery->here + size > nursery->end)
|
|
|
|
|
primitive_minor_gc();
|
2009-10-31 03:30:48 -04:00
|
|
|
|
2015-08-14 18:19:44 -04:00
|
|
|
object* obj = nursery->allot(size);
|
|
|
|
|
obj->initialize(type);
|
2016-09-22 07:13:55 -04:00
|
|
|
|
2015-08-14 18:19:44 -04:00
|
|
|
return obj;
|
2009-10-31 03:30:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|