Skip to content

Commit

Permalink
Redirect GC_gcj_malloc_ignore_off_page to GC_gcj_malloc for small obj…
Browse files Browse the repository at this point in the history
…ects

(refactoring)

* gcj_mlc.c (GENERAL_MALLOC_INNER_IOP): Remove.
* gcj_mlc.c (GC_core_gcj_malloc): Do not cast lb to word when passed
to GENERAL_MALLOC_INNER_IOP().
* gcj_mlc.c (GC_gcj_malloc_ignore_off_page): Remove function title
comment; add comment about small objects; redirect to GC_gcj_malloc()
if SMALL_OBJ(lb); replace GENERAL_MALLOC_INNER_IOP() call to
GC_clear_stack(GC_generic_malloc_inner_ignore_off_page()) one.
  • Loading branch information
ivmai committed Jan 30, 2023
1 parent bfad0eb commit 462d1c8
Showing 1 changed file with 15 additions and 33 deletions.
48 changes: 15 additions & 33 deletions gcj_mlc.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,6 @@ GC_API void GC_CALL GC_init_gcj_malloc(int mp_index,
#define GENERAL_MALLOC_INNER(lb,k) \
GC_clear_stack(GC_generic_malloc_inner(lb, k))

#define GENERAL_MALLOC_INNER_IOP(lb,k) \
GC_clear_stack(GC_generic_malloc_inner_ignore_off_page(lb, k))

/* We need a mechanism to release the lock and invoke finalizers. */
/* We don't really have an opportunity to do this on a rarely executed */
/* path on which the lock is not held. Thus we check at a */
Expand Down Expand Up @@ -159,7 +156,7 @@ static void maybe_finalize(void)
op = GC_gcjobjfreelist[lg];
if(EXPECT(0 == op, FALSE)) {
maybe_finalize();
op = (ptr_t)GENERAL_MALLOC_INNER((word)lb, GC_gcj_kind);
op = (ptr_t)GENERAL_MALLOC_INNER(lb, GC_gcj_kind);
if (0 == op) {
GC_oom_func oom_fn = GC_oom_fn;
UNLOCK();
Expand All @@ -173,7 +170,7 @@ static void maybe_finalize(void)
} else {
LOCK();
maybe_finalize();
op = (ptr_t)GENERAL_MALLOC_INNER((word)lb, GC_gcj_kind);
op = (ptr_t)GENERAL_MALLOC_INNER(lb, GC_gcj_kind);
if (0 == op) {
GC_oom_func oom_fn = GC_oom_fn;
UNLOCK();
Expand Down Expand Up @@ -219,40 +216,25 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_debug_gcj_malloc(size_t lb,
return result;
}

/* There is no THREAD_LOCAL_ALLOC for GC_gcj_malloc_ignore_off_page(). */
GC_API GC_ATTR_MALLOC void * GC_CALL GC_gcj_malloc_ignore_off_page(size_t lb,
void * ptr_to_struct_containing_descr)
{
ptr_t op;

GC_DBG_COLLECT_AT_MALLOC(lb);
if(SMALL_OBJ(lb)) {
word lg;
/* For small objects, the ignore_off_page variant of */
/* GC_generic_malloc_inner does not differ from the ordinary one. */
if (SMALL_OBJ(lb))
return GC_gcj_malloc(lb, ptr_to_struct_containing_descr);

LOCK();
lg = GC_size_map[lb];
op = GC_gcjobjfreelist[lg];
if (EXPECT(0 == op, FALSE)) {
maybe_finalize();
op = (ptr_t)GENERAL_MALLOC_INNER_IOP(lb, GC_gcj_kind);
if (0 == op) {
GC_oom_func oom_fn = GC_oom_fn;
UNLOCK();
return (*oom_fn)(lb);
}
} else {
GC_gcjobjfreelist[lg] = (ptr_t)obj_link(op);
GC_bytes_allocd += GRANULES_TO_BYTES((word)lg);
}
} else {
LOCK();
maybe_finalize();
op = (ptr_t)GENERAL_MALLOC_INNER_IOP(lb, GC_gcj_kind);
if (0 == op) {
GC_oom_func oom_fn = GC_oom_fn;
UNLOCK();
return (*oom_fn)(lb);
}
GC_DBG_COLLECT_AT_MALLOC(lb);
LOCK();
maybe_finalize();
op = (ptr_t)GC_clear_stack(GC_generic_malloc_inner_ignore_off_page(lb,
GC_gcj_kind));
if (NULL == op) {
GC_oom_func oom_fn = GC_oom_fn;
UNLOCK();
return (*oom_fn)(lb);
}
*(void **)op = ptr_to_struct_containing_descr;
UNLOCK();
Expand Down

0 comments on commit 462d1c8

Please sign in to comment.