diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2023-03-24 08:35:46 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2023-03-24 12:53:15 +0300 |
commit | 1d8ed2c5bb50d20c8903bb96f017b43a62b32ef2 (patch) | |
tree | 88c9cab5eaa62d7572de72f2673a48b0e0725ad8 /dbg_mlc.c | |
parent | d21d456b3abecb61ec8e5dfc6f06f48ba1eb4cc5 (diff) | |
download | bdwgc-1d8ed2c5bb50d20c8903bb96f017b43a62b32ef2.tar.gz |
Avoid code duplication in IGNORE_OFF_PAGE-specific malloc functions
(refactoring)
* alloc.c: Update comment regarding GC_generic_malloc_inner usage.
* alloc.c (GC_collect_or_expand): Replace ignore_off_page argument to
flags (check IGNORE_OFF_PAGE bit only in it); update comment.
* alloc.c (GC_allocobj): Pass 0 as flags to GC_collect_or_expand.
* dbg_mlc.c (GC_debug_generic_malloc,
GC_debug_generic_or_special_malloc): Rename knd argument to k.
* mallocx.c (GC_generic_or_special_malloc): Likewise.
* dbg_mlc.c (GC_debug_generic_malloc): Use GC_generic_malloc_aligned()
instead of GC_generic_malloc().
* dbg_mlc.c (GC_debug_generic_malloc_inner): Add flags argument.
* gcj_mlc.c [GC_GCJ_SUPPORT] (GC_core_gcj_malloc): Likewise.
* include/private/gc_priv.h (C_generic_malloc_aligned,
GC_generic_malloc_inner): Likewise.
* include/private/gc_priv.h [THREAD_LOCAL_ALLOC && GC_GCJ_SUPPORT]
(GC_core_gcj_malloc): Likewise.
* include/private/gc_priv.h [DBG_HDRS_ALL]
(GC_debug_generic_malloc_inner): Likewise.
* malloc.c (GC_generic_malloc_inner, GC_generic_malloc_aligned):
Likewise.
* dbg_mlc.c (GC_debug_generic_malloc_inner): Use
GC_generic_malloc_inner() instead of
GC_generic_malloc_inner_ignore_off_page().
* dbg_mlc.c [DBG_HDRS_ALL]
(GC_debug_generic_malloc_inner_ignore_off_page): Remove GC_INNER
function.
* include/private/gc_priv.h [DBG_HDRS_ALL || GC_GCJ_SUPPORT
|| !GC_NO_FINALIZATION] (GC_generic_malloc_inner_ignore_off_page):
Likewise.
* include/private/gc_priv.h [DBG_HDRS_ALL]
(GC_debug_generic_malloc_inner_ignore_off_page): Likewise.
* malloc.c [DBG_HDRS_ALL || GC_GCJ_SUPPORT
|| !GC_NO_FINALIZATION] (GC_generic_malloc_inner_ignore_off_page):
Likewise.
* gcj_mlc.c [GC_GCJ_SUPPORT && !THREAD_LOCAL_ALLOC]
(GC_gcj_malloc): Define as STATIC GC_core_gcj_malloc.
* gcj_mlc.c [GC_GCJ_SUPPORT] (GC_core_gcj_malloc): Reformat comment;
pass flags to GC_generic_malloc_inner().
* gcj_mlc.c [GC_GCJ_SUPPORT && !THREAD_LOCAL_ALLOC]
(GC_gcj_malloc): Redirect to GC_core_gcj_malloc() passing 0 to flags
argument.
* thread_local_alloc.c [THREAD_LOCAL_ALLOC && GC_GCJ_SUPPORT]
(GC_gcj_malloc): Likewise.
* gcj_mlc.c [GC_GCJ_SUPPORT] (GC_gcj_malloc_ignore_off_page): Redirect
to GC_core_gcj_malloc() passing IGNORE_OFF_PAGE.
* gcj_mlc.c [GC_GCJ_SUPPORT] (GC_debug_gcj_malloc): Pass 0 as flags to
GC_generic_malloc_inner().
* include/private/gc_priv.h (GC_generic_malloc_inner): Update comment.
* mallocx.c (GC_generic_malloc_many): Likewise.
* include/private/gc_priv.h (GC_collect_or_expand): Replace
GC_bool ignore_off_page argument to unsigned flags.
* include/private/gc_priv.h (GC_INTERNAL_MALLOC,
GC_INTERNAL_MALLOC_IGNORE_OFF_PAGE): Specify macro arguments.
* include/private/gc_priv.h (GC_INTERNAL_MALLOC): Pass 0 as flags
argument to GC_[debug_]generic_malloc_inner().
* include/private/gc_priv.h (GC_INTERNAL_MALLOC_IGNORE_OFF_PAGE): Pass
IGNORE_OFF_PAGE to GC_[debug_]generic_malloc_inner().
* malloc.c (GC_alloc_large): Pass flags (instead of flags!=0) to
GC_collect_or_expand().
* malloc.c (GC_generic_malloc_inner_small): New STATIC function (move
most of code from GC_generic_malloc_inner).
* malloc.c (GC_generic_malloc_inner): Move comment to gc_priv.h; call
GC_generic_malloc_inner_small().
* malloc.c (GC_generic_malloc_aligned): Call
GC_generic_malloc_inner_small() instead of GC_generic_malloc_inner();
pass flags (instead of 0) to GC_alloc_large(); do not cast result of
GC_alloc_large() to ptr_t.
* malloc.c (GC_generic_malloc): Pass 0 as flags to
GC_generic_malloc_aligned().
* malloc.c (GC_memalign): Likewise.
* malloc.c (GC_malloc_kind_global, GC_generic_malloc_uncollectable):
Call GC_generic_malloc_aligned() instead of GC_generic_malloc().
* mallocx.c (GC_generic_malloc_many): Likewise.
* malloc.c (free_internal): Rename knd local variable to k.
* mallocx.c (GC_generic_malloc_ignore_off_page,
GC_malloc_ignore_off_page, GC_malloc_atomic_ignore_off_page): Redirect
to GC_generic_malloc_aligned() passing IGNORE_OFF_PAGE.
* typd_mlc.c (GC_generic_malloc_ignore_off_page): Likewise.
* tests/gctest.c (run_one_test): Call
GC_generic_malloc_ignore_off_page() (with size larger than HBLKSIZE);
increment collectable_count.
Diffstat (limited to 'dbg_mlc.c')
-rw-r--r-- | dbg_mlc.c | 37 |
1 files changed, 10 insertions, 27 deletions
@@ -572,9 +572,11 @@ GC_API GC_ATTR_MALLOC void * GC_CALL OPT_RA s, i); } -STATIC void * GC_debug_generic_malloc(size_t lb, int knd, GC_EXTRA_PARAMS) +STATIC void * GC_debug_generic_malloc(size_t lb, int k, GC_EXTRA_PARAMS) { - void * result = GC_generic_malloc(SIZET_SAT_ADD(lb, DEBUG_BYTES), knd); + void * result = GC_generic_malloc_aligned(SIZET_SAT_ADD(lb, DEBUG_BYTES), + k, 0 /* flags */, + 0 /* align_m1 */); return store_debug_info(result, lb, "GC_debug_generic_malloc", OPT_RA s, i); @@ -584,32 +586,13 @@ STATIC void * GC_debug_generic_malloc(size_t lb, int knd, GC_EXTRA_PARAMS) /* An allocation function for internal use. Normally internally */ /* allocated objects do not have debug information. But in this */ /* case, we need to make sure that all objects have debug headers. */ - GC_INNER void * GC_debug_generic_malloc_inner(size_t lb, int k) + GC_INNER void * GC_debug_generic_malloc_inner(size_t lb, int k, + unsigned flags) { void * result; GC_ASSERT(I_HOLD_LOCK()); - result = GC_generic_malloc_inner(SIZET_SAT_ADD(lb, DEBUG_BYTES), k); - if (NULL == result) { - GC_err_printf("GC internal allocation (%lu bytes) returning NULL\n", - (unsigned long) lb); - return NULL; - } - if (!GC_debugging_started) { - GC_start_debugging_inner(); - } - ADD_CALL_CHAIN(result, GC_RETURN_ADDR); - return GC_store_debug_info_inner(result, (word)lb, "INTERNAL", 0); - } - - GC_INNER void * GC_debug_generic_malloc_inner_ignore_off_page(size_t lb, - int k) - { - void * result; - - GC_ASSERT(I_HOLD_LOCK()); - result = GC_generic_malloc_inner_ignore_off_page( - SIZET_SAT_ADD(lb, DEBUG_BYTES), k); + result = GC_generic_malloc_inner(SIZET_SAT_ADD(lb, DEBUG_BYTES), k, flags); if (NULL == result) { GC_err_printf("GC internal allocation (%lu bytes) returning NULL\n", (unsigned long) lb); @@ -921,9 +904,9 @@ GC_API void * GC_CALL GC_debug_realloc(void * p, size_t lb, GC_EXTRA_PARAMS) } GC_API GC_ATTR_MALLOC void * GC_CALL - GC_debug_generic_or_special_malloc(size_t lb, int knd, GC_EXTRA_PARAMS) + GC_debug_generic_or_special_malloc(size_t lb, int k, GC_EXTRA_PARAMS) { - switch (knd) { + switch (k) { case PTRFREE: return GC_debug_malloc_atomic(lb, OPT_RA s, i); case NORMAL: @@ -935,7 +918,7 @@ GC_API GC_ATTR_MALLOC void * GC_CALL return GC_debug_malloc_atomic_uncollectable(lb, OPT_RA s, i); # endif default: - return GC_debug_generic_malloc(lb, knd, OPT_RA s, i); + return GC_debug_generic_malloc(lb, k, OPT_RA s, i); } } |