GC笔记--fast/slow allocator比较
p_obj = gc_alloc_fast(size, vt); if(p_obj == null){ prepare_for_native_call(); gc_alloc(size, vt); clean_after_native_call(); }
//this routine does not deal with any slow path operations, //but returns null if unsuccessful. Object* gc_alloc_fast(unsigned size, Vtable* vt) { //return if object to be allocated has finalizer if(type_has_finalizer(vt)) return NULL; //return if it is large object if ( size > GC_OBJ_SIZE_THRESHOLD ) return NULL; Object* p_obj = null; Allocator* allocator = thread_get_allocator(); int free = (int)allocator->free; int ceiling = (int)allocator->ceiling; int new_free = free + size; if (new_free <= ceiling){ p_obj = (Object*)free; allocator->free= (void*)new_free; }else{ return null; } //install vtable pointer to the object header obj_set_vt(p_obj, vt); return p_obj; }
这是在thread local上的实现bump-the-pointer。因为需要找线程私有的allocator,这一部分一般通过thread_local_top寻找。thread_local_top可以固定放在某一个寄存器。
fast和普通的slow模式相差非常大。如果fast失败,中间还要插入safepoint点。这一段就会有上百的instruction,开销远远大于fast的allocator。
浙公网安备 33010602011771号