GC笔记--fastslow allocator比较

it2022-05-09  32

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。

 

转载于:https://www.cnblogs.com/simpleminds/p/6594200.html

相关资源:数据结构—成绩单生成器

最新回复(0)