Object* Class::allocate(STATE) { Object* obj = cNil; object_type obj_type = type_info()->type; if(obj_type == PackedObject::type) { obj = allocate_packed(state, this); } else if(!type_info()->allow_user_allocate || kind_of<SingletonClass>(this)) { std::ostringstream msg; msg << "direct allocation disabled for "; if(kind_of<SingletonClass>(this)) { msg << to_string(state); } else { msg << module_name()->debug_str(state); } Exception::raise_type_error(state, msg.str().c_str()); } else if(obj_type == Object::type) { auto_pack(state); obj = allocate_packed(state, this); } else { // type_info()->type is neither PackedObject nor Object, so use the // generic path. obj = state->memory()->new_object<Object>( state, this, type_info()->instance_size, obj_type); } #ifdef RBX_ALLOC_TRACKING if(unlikely(state->vm()->allocation_tracking())) { new_obj->setup_allocation_site(state); } #endif return obj; }
Object* Class::allocate(STATE, GCToken gct, CallFrame* calling_environment) { object_type obj_type = type_info_->type; if(obj_type == PackedObject::type) { Object* new_obj = allocate_packed(state, gct, this, calling_environment); #ifdef RBX_ALLOC_TRACKING if(unlikely(state->vm()->allocation_tracking())) { new_obj->setup_allocation_site(state, calling_environment); } #endif #ifdef RBX_GC_STRESS state->shared().gc_soon(); #endif return new_obj; } else if(!type_info_->allow_user_allocate || kind_of<SingletonClass>(this)) { std::ostringstream msg; msg << "direct allocation disabled for "; if(kind_of<SingletonClass>(this)) { msg << to_string(state); } else { msg << module_name()->debug_str(state); } Exception::type_error(state, msg.str().c_str()); return cNil; } else if(obj_type == Object::type) { // transition all normal object classes to PackedObject Class* self = this; OnStack<1> os(state, self); auto_pack(state, gct, calling_environment); Object* new_obj = allocate_packed(state, gct, self, calling_environment); #ifdef RBX_ALLOC_TRACKING if(unlikely(state->vm()->allocation_tracking())) { new_obj->setup_allocation_site(state, calling_environment); } #endif #ifdef RBX_GC_STRESS state->shared().gc_soon(); #endif return new_obj; } else { // type_info_->type is neither PackedObject nor Object, so use the // generic path. Object* new_obj = state->vm()->new_object_typed(this, type_info_->instance_size, obj_type); #ifdef RBX_ALLOC_TRACKING if(unlikely(state->vm()->allocation_tracking())) { new_obj->setup_allocation_site(state, calling_environment); } #endif #ifdef RBX_GC_STRESS state->shared().gc_soon(); #endif return new_obj; } }
Object* Class::allocate(STATE, GCToken gct, CallFrame* calling_environment) { if(type_info_->type == PackedObject::type) { Object* new_obj = allocate_packed(state, gct, this, calling_environment); #ifdef RBX_ALLOC_TRACKING if(unlikely(state->vm()->allocation_tracking())) { new_obj->setup_allocation_site(state, calling_environment); } #endif return new_obj; } else if(!type_info_->allow_user_allocate || kind_of<SingletonClass>(this)) { Exception::type_error(state, "direct allocation disabled"); return cNil; } else if(type_info_->type == Object::type) { // transition all normal object classes to PackedObject Class* self = this; OnStack<1> os(state, self); auto_pack(state, gct); Object* new_obj = allocate_packed(state, gct, this, calling_environment); #ifdef RBX_ALLOC_TRACKING if(unlikely(state->vm()->allocation_tracking())) { new_obj->setup_allocation_site(state, calling_environment); } #endif return new_obj; } else { // type_info_->type is neither PackedObject nor Object, so use the // generic path. Object* new_obj = state->vm()->new_object_typed(this, type_info_->instance_size, type_info_->type); #ifdef RBX_ALLOC_TRACKING if(unlikely(state->vm()->allocation_tracking())) { new_obj->setup_allocation_site(state, calling_environment); } #endif return new_obj; } }