ruby-changes:29947
From: ko1 <ko1@a...>
Date: Tue, 16 Jul 2013 17:32:43 +0900 (JST)
Subject: [ruby-changes:29947] ko1:r41999 (trunk): * gc.c (assign_heap_slot): refactoring variable names.
ko1 2013-07-16 17:32:32 +0900 (Tue, 16 Jul 2013) New Revision: 41999 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41999 Log: * gc.c (assign_heap_slot): refactoring variable names. * gc.c (slot_add_freeobj): added. * gc.c (heaps_add_freeslot): added. * gc.c (finalize_list, rb_gc_force_recycle, slot_sweep): use `slot_add_freeobj' instead of modifying linked list directly. Modified files: trunk/ChangeLog trunk/gc.c Index: ChangeLog =================================================================== --- ChangeLog (revision 41998) +++ ChangeLog (revision 41999) @@ -1,3 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Jul 16 17:21:39 2013 Koichi Sasada <ko1@a...> + + * gc.c (assign_heap_slot): refactoring variable names. + + * gc.c (slot_add_freeobj): added. + + * gc.c (heaps_add_freeslot): added. + + * gc.c (finalize_list, rb_gc_force_recycle, slot_sweep): use + `slot_add_freeobj' instead of modifying linked list directly. + Tue Jul 16 16:30:58 2013 Koichi Sasada <ko1@a...> * gc.c (lazy_sweep): refactoring. Index: gc.c =================================================================== --- gc.c (revision 41998) +++ gc.c (revision 41999) @@ -746,18 +746,37 @@ unlink_free_heap_slot(rb_objspace_t *obj https://github.com/ruby/ruby/blob/trunk/gc.c#L746 slot->free_next = NULL; } +static inline void +slot_add_freeobj(rb_objspace_t *objspace, struct heaps_slot *slot, VALUE obj) +{ + RVALUE *p = (RVALUE *)obj; + p->as.free.flags = 0; + p->as.free.next = slot->freelist; + slot->freelist = p; + rgengc_report(3, objspace, "slot_add_freeobj: %p (%s) is added to freelist\n", p, obj_type_name(obj)); +} + +static inline void +heaps_add_freeslot(rb_objspace_t *objspace, struct heaps_slot *slot) +{ + if (slot->freelist) { + slot->free_next = objspace->heap.free_slots; + objspace->heap.free_slots = slot; + } +} + static void assign_heap_slot(rb_objspace_t *objspace) { - RVALUE *p, *pend, *membase; + RVALUE *start, *end, *p; struct heaps_slot *slot; + struct heaps_header *header = 0; size_t hi, lo, mid; - size_t objs; - - objs = HEAP_OBJ_LIMIT; + size_t limit = HEAP_OBJ_LIMIT; - p = (RVALUE*)aligned_malloc(HEAP_ALIGN, HEAP_SIZE); - if (p == 0) { + /* assign heaps_header entry (with RVALUEs area) */ + header = (struct heaps_header *)aligned_malloc(HEAP_ALIGN, HEAP_SIZE); + if (header == 0) { during_gc = 0; rb_memerror(); } @@ -765,66 +784,64 @@ assign_heap_slot(rb_objspace_t *objspace https://github.com/ruby/ruby/blob/trunk/gc.c#L784 /* assign heaps_slot entry */ slot = (struct heaps_slot *)malloc(sizeof(struct heaps_slot)); if (slot == 0) { - aligned_free(p); - during_gc = 0; - rb_memerror(); + aligned_free(header); + during_gc = 0; + rb_memerror(); } MEMZERO((void*)slot, struct heaps_slot, 1); - slot->next = heaps; - if (heaps) heaps->prev = slot; - heaps = slot; - - /* adjust objs (object number available in this slot) */ - membase = p; - p = (RVALUE*)((VALUE)p + sizeof(struct heaps_header)); - if ((VALUE)p % sizeof(RVALUE) != 0) { - p = (RVALUE*)((VALUE)p + sizeof(RVALUE) - ((VALUE)p % sizeof(RVALUE))); - objs = (HEAP_SIZE - (size_t)((VALUE)p - (VALUE)membase))/sizeof(RVALUE); + slot->header = header; + slot->next = objspace->heap.ptr; + + if (objspace->heap.ptr) objspace->heap.ptr->prev = slot; + objspace->heap.ptr = slot; + + /* adjust obj_limit (object number available in this slot) */ + start = (RVALUE*)((VALUE)header + sizeof(struct heaps_header)); + if ((VALUE)start % sizeof(RVALUE) != 0) { + start = (RVALUE*)((VALUE)start + sizeof(RVALUE) - ((VALUE)start % sizeof(RVALUE))); + limit = (HEAP_SIZE - (size_t)((VALUE)start - (VALUE)header))/sizeof(RVALUE); } /* setup objspace->heap.sorted */ lo = 0; hi = heaps_used; while (lo < hi) { - register RVALUE *mid_membase; + struct heaps_header *mid_header; + mid = (lo + hi) / 2; - mid_membase = (RVALUE *)objspace->heap.sorted[mid]; - if (mid_membase < membase) { + mid_header = objspace->heap.sorted[mid]; + if (mid_header < header) { lo = mid + 1; } - else if (mid_membase > membase) { + else if (mid_header > header) { hi = mid; } else { - rb_bug("same heap slot is allocated: %p at %"PRIuVALUE, (void *)membase, (VALUE)mid); + rb_bug("same heap slot is allocated: %p at %"PRIuVALUE, (void *)header, (VALUE)mid); } } if (hi < heaps_used) { MEMMOVE(&objspace->heap.sorted[hi+1], &objspace->heap.sorted[hi], struct heaps_header*, heaps_used - hi); } + objspace->heap.sorted[hi] = header; /* setup header */ - heaps->header = (struct heaps_header *)membase; - objspace->heap.sorted[hi] = heaps->header; - objspace->heap.sorted[hi]->start = p; - objspace->heap.sorted[hi]->end = (p + objs); - objspace->heap.sorted[hi]->base = heaps; - objspace->heap.sorted[hi]->limit = objs; - pend = p + objs; - if (lomem == 0 || lomem > p) lomem = p; - if (himem < pend) himem = pend; + header->start = start; + header->end = end = start + limit; + header->base = heaps; + header->limit = limit; + + if (lomem == 0 || lomem > start) lomem = start; + if (himem < end) himem = end; heaps_used++; - while (p < pend) { - p->as.free.flags = 0; + for (p = start; p != end; p++) { rgengc_report(3, objspace, "assign_heap_slot: %p (%s) is added to freelist\n", p, obj_type_name((VALUE)p)); - p->as.free.next = heaps->freelist; - heaps->freelist = p; - p++; + slot_add_freeobj(objspace, slot, (VALUE)p); } - link_free_heap_slot(objspace, heaps); + heaps_add_freeslot(objspace, heaps); } static void @@ -1732,7 +1749,7 @@ finalize_list(rb_objspace_t *objspace, R https://github.com/ruby/ruby/blob/trunk/gc.c#L1749 run_final(objspace, (VALUE)p); objspace->total_freed_object_num++; if (!FL_TEST(p, FL_SINGLETON)) { /* not freeing page */ - add_slot_local_freelist(objspace, p); + slot_add_freeobj(objspace, GET_HEAP_SLOT(p), (VALUE)p); objspace->heap.free_num++; } else { @@ -2240,9 +2257,7 @@ slot_sweep(rb_objspace_t *objspace, stru https://github.com/ruby/ruby/blob/trunk/gc.c#L2257 } else { (void)VALGRIND_MAKE_MEM_UNDEFINED((void*)p, sizeof(RVALUE)); - p->as.free.flags = 0; - p->as.free.next = sweep_slot->freelist; - sweep_slot->freelist = p; + slot_add_freeobj(objspace, sweep_slot, (VALUE)p); rgengc_report(3, objspace, "slot_sweep: %p (%s) is added to freelist\n", p, obj_type_name((VALUE)p)); freed_num++; } @@ -3987,7 +4002,6 @@ void https://github.com/ruby/ruby/blob/trunk/gc.c#L4002 rb_gc_force_recycle(VALUE p) { rb_objspace_t *objspace = &rb_objspace; - struct heaps_slot *slot; #if USE_RGENGC CLEAR_IN_BITMAP(GET_HEAP_REMEMBERSET_BITS(p), p); @@ -3998,15 +4012,10 @@ rb_gc_force_recycle(VALUE p) https://github.com/ruby/ruby/blob/trunk/gc.c#L4012 #endif objspace->total_freed_object_num++; - if (MARKED_IN_BITMAP(GET_HEAP_MARK_BITS(p), p)) { - add_slot_local_freelist(objspace, (RVALUE *)p); - } - else { + slot_add_freeobj(objspace, GET_HEAP_SLOT(p), p); + + if (!MARKED_IN_BITMAP(GET_HEAP_MARK_BITS(p), p)) { objspace->heap.free_num++; - slot = add_slot_local_freelist(objspace, (RVALUE *)p); - if (slot->free_next == NULL) { - link_free_heap_slot(objspace, slot); - } } } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/