From: Ivan Maidanski Date: Wed, 29 Jun 2016 22:03:54 +0000 (+0300) Subject: Replace GC_freelists usage with GC_obj_kinds[].ok_freelist X-Git-Tag: gc7_6_0~25^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f478a1e75bf722c7f8ef2029c28c7f0a0d06c479;p=gc Replace GC_freelists usage with GC_obj_kinds[].ok_freelist * malloc.c (GC_malloc_kind_global, GC_generic_malloc_uncollectable): Use GC_obj_kinds[k].ok_freelist instead of GC_freelists[k]. * thread_local_alloc.c (GC_destroy_thread_local): Likewise. * thread_local_alloc.c (GC_destroy_thread_local): Stop iteration when an uninitialized kind reached. --- diff --git a/malloc.c b/malloc.c index 083704cf..8df86cf5 100644 --- a/malloc.c +++ b/malloc.c @@ -236,6 +236,7 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_generic_malloc(size_t lb, int k) GC_API GC_ATTR_MALLOC void * GC_CALL GC_malloc_kind_global(size_t lb, int k) { void *op; + void **opp; size_t lg; DCL_LOCK_STATE; @@ -245,17 +246,18 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_malloc_kind_global(size_t lb, int k) GC_DBG_COLLECT_AT_MALLOC(lb); lg = GC_size_map[lb]; LOCK(); - op = GC_freelists[k][lg]; + opp = &GC_obj_kinds[k].ok_freelist[lg]; + op = *opp; if (EXPECT(op != NULL, TRUE)) { if (k == PTRFREE) { - GC_freelists[k][lg] = obj_link(op); + *opp = obj_link(op); } else { GC_ASSERT(0 == obj_link(op) || ((word)obj_link(op) <= (word)GC_greatest_plausible_heap_addr && (word)obj_link(op) >= (word)GC_least_plausible_heap_addr)); - GC_freelists[k][lg] = obj_link(op); + *opp = obj_link(op); obj_link(op) = 0; } GC_bytes_allocd += GRANULES_TO_BYTES(lg); @@ -290,6 +292,7 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_generic_malloc_uncollectable( size_t lb, int k) { void *op; + void **opp; size_t lg; DCL_LOCK_STATE; @@ -301,9 +304,10 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_generic_malloc_uncollectable( /* collected anyway. */ lg = GC_size_map[lb]; LOCK(); - op = GC_freelists[k][lg]; + opp = &GC_obj_kinds[k].ok_freelist[lg]; + op = *opp; if (EXPECT(op != NULL, TRUE)) { - GC_freelists[k][lg] = obj_link(op); + *opp = obj_link(op); obj_link(op) = 0; GC_bytes_allocd += GRANULES_TO_BYTES(lg); /* Mark bit was already set on free list. It will be */ diff --git a/thread_local_alloc.c b/thread_local_alloc.c index 9b194a78..ab4382b6 100644 --- a/thread_local_alloc.c +++ b/thread_local_alloc.c @@ -134,13 +134,15 @@ GC_INNER void GC_init_thread_local(GC_tlfs p) /* We hold the allocator lock. */ GC_INNER void GC_destroy_thread_local(GC_tlfs p) { - int i; + int k; /* We currently only do this from the thread itself or from */ /* the fork handler for a child process. */ GC_STATIC_ASSERT(PREDEFINED_KINDS >= THREAD_FREELISTS_KINDS); - for (i = 0; i < THREAD_FREELISTS_KINDS; ++i) { - return_freelists(p -> _freelists[i], GC_freelists[i]); + for (k = 0; k < THREAD_FREELISTS_KINDS; ++k) { + if (k == (int)GC_n_kinds) + break; /* kind is not created */ + return_freelists(p -> _freelists[k], GC_obj_kinds[k].ok_freelist); } # ifdef GC_GCJ_SUPPORT return_freelists(p -> gcj_freelists, (void **)GC_gcjobjfreelist);