void allocator_object_write_barrier(Partial_Reveal_Object* p_object, Collector* allocator) { if( addr_belongs_to_nos(p_object)) return; REF* p_slot; /* scan array object */ if (object_is_array((Partial_Reveal_Object*)p_object)) { Partial_Reveal_Object* array = p_object; assert(!obj_is_primitive_array(array)); I_32 array_length = vector_get_length((Vector_Handle) array); for (int i = 0; i < array_length; i++) { p_slot = (REF *)vector_get_element_address_ref((Vector_Handle)array, i); if( read_slot(p_slot) != NULL && addr_belongs_to_nos(read_slot(p_slot))){ collector_remset_add_entry(allocator, (Partial_Reveal_Object**)p_slot); } } return; } /* scan non-array object */ Partial_Reveal_Object* p_obj = (Partial_Reveal_Object*)p_object; unsigned int num_refs = object_ref_field_num(p_obj); int *ref_iterator = object_ref_iterator_init(p_obj); for(unsigned int i=0; i<num_refs; i++){ p_slot = object_ref_iterator_get(ref_iterator+i, p_obj); if( addr_belongs_to_nos(read_slot(p_slot))){ collector_remset_add_entry(allocator, (Partial_Reveal_Object**)p_slot); } } return; }
static FORCE_INLINE void scan_object(Collector* collector, Partial_Reveal_Object *p_obj) { assert((((POINTER_SIZE_INT)p_obj) % GC_OBJECT_ALIGNMENT) == 0); if (!object_has_ref_field(p_obj)) return; REF *p_ref; /* scan array object */ if (object_is_array(p_obj)) { Partial_Reveal_Object* array = p_obj; assert(!obj_is_primitive_array(array)); I_32 array_length = vector_get_length((Vector_Handle) array); for (int i = 0; i < array_length; i++) { p_ref= (REF *)vector_get_element_address_ref((Vector_Handle) array, i); scan_slot(collector, p_ref); } return; /* array can't be a reference object, directly return. */ } /* scan non-array object */ unsigned int num_refs = object_ref_field_num(p_obj); int *ref_iterator = object_ref_iterator_init(p_obj); for(unsigned int i=0; i<num_refs; i++){ REF* p_ref = object_ref_iterator_get(ref_iterator+i, p_obj); scan_slot(collector, p_ref); } #ifndef BUILD_IN_REFERENT scan_weak_reference(collector, p_obj, scan_slot); #endif return; }
/*<--------all (live and dead) objects scanner begin-------->*/ static FORCE_INLINE void verifier_scan_object_slots(Partial_Reveal_Object *p_obj, Heap_Verifier* heap_verifier) { verifier_allocation_update_info(p_obj, heap_verifier); verify_object_header(p_obj, heap_verifier); if (!object_has_ref_field(p_obj)) return; REF* p_ref; if (object_is_array(p_obj)){ Partial_Reveal_Array* array = (Partial_Reveal_Array*)p_obj; unsigned int array_length = array->array_len; p_ref = (REF*)((POINTER_SIZE_INT)array + (int)array_first_element_offset(array)); for (unsigned int i = 0; i < array_length; i++) { verify_write_barrier(p_ref+i, heap_verifier); if( read_slot(p_ref+i) != NULL) verify_all_object_slot(p_ref+i, heap_verifier); // if(!is_unreachable_obj(p_obj)){ // verify_write_barrier(p_ref+i, heap_verifier); // if( read_slot(p_ref+i) != NULL) verify_live_object_slot(p_ref+i, heap_verifier); // }else{ // if( read_slot(p_ref+i) != NULL) verify_all_object_slot(p_ref+i, heap_verifier); // } } }else{ unsigned int num_refs = object_ref_field_num(p_obj); int* ref_iterator = object_ref_iterator_init(p_obj); for(unsigned int i=0; i<num_refs; i++){ p_ref = object_ref_iterator_get(ref_iterator+i, p_obj); verify_write_barrier(p_ref, heap_verifier); if( read_slot(p_ref) != NULL) verify_all_object_slot(p_ref, heap_verifier); //if(!is_unreachable_obj(p_obj)){ // verify_write_barrier(p_ref, heap_verifier); // if( read_slot(p_ref) != NULL) verify_live_object_slot(p_ref, heap_verifier); //}else{ // if( read_slot(p_ref) != NULL) verify_all_object_slot(p_ref, heap_verifier); //} } #ifndef BUILD_IN_REFERENT WeakReferenceType type = special_reference_type(p_obj); if(type == NOT_REFERENCE) return; //if(type != SOFT_REFERENCE && verifier_collect_is_minor(heap_verifier->gc_verifier)){ { p_ref = obj_get_referent_field(p_obj); verify_write_barrier(p_ref, heap_verifier); if( read_slot(p_ref) != NULL) verify_all_object_slot(p_ref, heap_verifier); //if(!is_unreachable_obj(p_obj)){ // verify_write_barrier(p_ref, heap_verifier); // if( read_slot(p_ref) != NULL) verify_live_object_slot(p_ref, heap_verifier); //}else{ // if( read_slot(p_ref) != NULL) verify_all_object_slot(p_ref, heap_verifier); //} } #endif } return; }
static FORCE_INLINE void scan_object(Collector* collector, Partial_Reveal_Object *p_obj) { vm_notify_obj_alive( (void *)p_obj); assert((((POINTER_SIZE_INT)p_obj) % GC_OBJECT_ALIGNMENT) == 0); Partial_Reveal_VTable *vtable = decode_vt(obj_get_vt(p_obj)); if(TRACE_JLC_VIA_VTABLE) if(vtable->vtmark == VT_UNMARKED) { vtable->vtmark = VT_MARKED; if(obj_mark_in_vt(vtable->jlC)) collector_tracestack_push(collector, vtable->jlC); } if( !object_has_ref_field(p_obj) ) return; REF *p_ref; if (object_is_array(p_obj)) { /* scan array object */ Partial_Reveal_Array* array = (Partial_Reveal_Array*)p_obj; unsigned int array_length = array->array_len; p_ref = (REF *)((POINTER_SIZE_INT)array + (int)array_first_element_offset(array)); for (unsigned int i = 0; i < array_length; i++) { scan_slot(collector, p_ref+i); } }else{ /* scan non-array object */ unsigned int num_refs = object_ref_field_num(p_obj); int* ref_iterator = object_ref_iterator_init(p_obj); for(unsigned int i=0; i<num_refs; i++){ p_ref = object_ref_iterator_get(ref_iterator+i, p_obj); scan_slot(collector, p_ref); } #ifndef BUILD_IN_REFERENT scan_weak_reference(collector, p_obj, scan_slot); #endif } return; }
/*This function is for concurrent mark.*/ static void write_barrier_rem_obj_snapshot(Managed_Object_Handle p_obj_holding_ref) { Mutator *mutator = (Mutator *)gc_get_tls(); REF* p_obj_slot; if(obj_need_take_snapshot((Partial_Reveal_Object*)p_obj_holding_ref)){ if (object_is_array((Partial_Reveal_Object*)p_obj_holding_ref)) { Partial_Reveal_Object* array = (Partial_Reveal_Object*)p_obj_holding_ref; assert(!obj_is_primitive_array(array)); Partial_Reveal_Object* obj_to_snapshot; I_32 array_length = vector_get_length((Vector_Handle) array); for (int i = 0; i < array_length; i++) { p_obj_slot = (REF*)vector_get_element_address_ref((Vector_Handle) array, i); obj_to_snapshot = (Partial_Reveal_Object*)read_slot(p_obj_slot); if (obj_to_snapshot != NULL) mutator_dirtyset_add_entry(mutator, obj_to_snapshot); } }else{ /* scan non-array object */ Partial_Reveal_Object* p_obj = (Partial_Reveal_Object*)p_obj_holding_ref; unsigned int num_refs = object_ref_field_num(p_obj); int *ref_iterator = object_ref_iterator_init(p_obj); Partial_Reveal_Object* obj_to_snapshot; for(unsigned int i=0; i<num_refs; i++){ p_obj_slot = object_ref_iterator_get(ref_iterator+i, p_obj); obj_to_snapshot = (Partial_Reveal_Object*)read_slot(p_obj_slot); if (obj_to_snapshot != NULL) mutator_dirtyset_add_entry(mutator, obj_to_snapshot); } if(is_reference_obj(p_obj)){ REF* p_referent_field = obj_get_referent_field(p_obj); obj_to_snapshot = (Partial_Reveal_Object*)read_slot(p_referent_field); if (obj_to_snapshot != NULL) mutator_dirtyset_add_entry(mutator, obj_to_snapshot); } } obj_mark_gray_in_table((Partial_Reveal_Object *) p_obj_holding_ref); // now, the black-only obj (no gray bit been set) will also be scaned by marker, here mark it to gray to prevent this, just a workaround obj_mark_black_in_table((Partial_Reveal_Object *) p_obj_holding_ref, mutator); obj_dirty_in_table((Partial_Reveal_Object *) p_obj_holding_ref); } }
static FORCE_INLINE void scan_object(Conclctor* marker, Partial_Reveal_Object *p_obj) { assert((((POINTER_SIZE_INT)p_obj) % GC_OBJECT_ALIGNMENT) == 0); if(obj_is_dirty_in_table(p_obj)){ assert(obj_is_mark_black_in_table(p_obj)); return; } if(!object_has_ref_field(p_obj)) return; REF *p_ref; if(object_is_array(p_obj)){ /* scan array object */ Partial_Reveal_Array *array = (Partial_Reveal_Array*)p_obj; unsigned int array_length = array->array_len; p_ref = (REF *)((POINTER_SIZE_INT)array + (int)array_first_element_offset(array)); for (unsigned int i = 0; i < array_length; i++) scan_slot((Collector*)marker, p_ref+i); return; } /* scan non-array object */ unsigned int num_refs = object_ref_field_num(p_obj); int *ref_iterator = object_ref_iterator_init(p_obj); for(unsigned int i=0; i<num_refs; i++){ p_ref = object_ref_iterator_get(ref_iterator+i, p_obj); scan_slot((Collector*)marker, p_ref); } #ifndef BUILD_IN_REFERENT scan_weak_reference_direct((Collector*)marker, p_obj, scan_slot); #endif }
static FORCE_INLINE void scan_object(Heap_Verifier* heap_verifier, Partial_Reveal_Object *p_obj) { GC_Verifier* gc_verifier = heap_verifier->gc_verifier; #if !defined(USE_UNIQUE_MARK_SWEEP_GC) && !defined(USE_UNIQUE_MOVE_COMPACT_GC) if(gc_verifier->is_before_fallback_collection) { if(obj_belongs_to_nos(p_obj) && obj_is_fw_in_oi(p_obj)){ assert(obj_get_vt(p_obj) == obj_get_vt(obj_get_fw_in_oi(p_obj))); p_obj = obj_get_fw_in_oi(p_obj); assert(p_obj); } } #endif if(!obj_mark_in_vt(p_obj)) return; if( !major_is_marksweep() && p_obj >= los_boundary ){ Block_Header* block = GC_BLOCK_HEADER(p_obj); if( heap_verifier->is_before_gc) block->num_live_objs++; /* we can't set block->num_live_objs = 0 if !is_before_gc, because the some blocks may be freed hence not visited after GC. So we should reset it in GC space reset functions. */ } verify_object_header(p_obj, heap_verifier); verifier_update_verify_info(p_obj, heap_verifier); /*FIXME: */ if (!object_has_ref_field(p_obj)) return; REF* p_ref; if (object_is_array(p_obj)) { Partial_Reveal_Array* array = (Partial_Reveal_Array*)p_obj; unsigned int array_length = array->array_len; p_ref = (REF*)((POINTER_SIZE_INT)array + (int)array_first_element_offset(array)); for (unsigned int i = 0; i < array_length; i++) { scan_slot(heap_verifier, p_ref+i); } }else{ unsigned int num_refs = object_ref_field_num(p_obj); int* ref_iterator = object_ref_iterator_init(p_obj); for(unsigned int i=0; i<num_refs; i++){ p_ref = object_ref_iterator_get(ref_iterator+i, p_obj); scan_slot(heap_verifier, p_ref); } #ifndef BUILD_IN_REFERENT WeakReferenceType type = special_reference_type(p_obj); if(type == SOFT_REFERENCE && verifier_collect_is_minor(gc_verifier)){ p_ref = obj_get_referent_field(p_obj); scan_slot(heap_verifier, p_ref); } #endif } return; }