factor/vm/allot.hpp

30 lines
769 B
C++
Raw Normal View History

2013-05-11 22:32:45 -04:00
namespace factor {
/*
* It is up to the caller to fill in the object's fields in a meaningful
* fashion!
*/
/* Allocates memory */
2013-05-11 22:32:45 -04:00
inline object* factor_vm::allot_object(cell type, cell size) {
FACTOR_ASSERT(!current_gc);
bump_allocator *nursery = data->nursery;
2013-05-11 22:32:45 -04:00
/* If the object is smaller than the nursery, allocate it in the nursery,
after a GC if needed */
if (nursery->size > size) {
2013-05-11 22:32:45 -04:00
/* If there is insufficient room, collect the nursery */
if (nursery->here + size > nursery->end)
2013-05-11 22:32:45 -04:00
primitive_minor_gc();
object* obj = nursery->allot(size);
2013-05-11 22:32:45 -04:00
obj->initialize(type);
return obj;
} /* If the object is bigger than the nursery, allocate it in
tenured space */
else
return allot_large_object(type, size);
}
}