Skip to content

Commit bbb4403

Browse files
authored
refactor mallocarray_t to reflect it should carry jl_genericmemory_t (#55237)
Seems like this `mallocarray_t` container is only carrying objects of type `jl_genericmemory_t` after the memory work. Let's: * Rename the container type to `mallocmemory_t`. * Make the payload type a bit more strict to ensure a bit more type safety (i.e. change the `a` field from `jl_value_t *` to `jl_genericmemory_t *`). * Add a comment to indicate the pointer tagging in the lowest bit of the payload.
1 parent 1129e82 commit bbb4403

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

src/gc-debug.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ void gc_stats_big_obj(void)
10091009
v = v->next;
10101010
}
10111011

1012-
mallocarray_t *ma = ptls2->gc_tls.heap.mallocarrays;
1012+
mallocmemory_t *ma = ptls2->gc_tls.heap.mallocarrays;
10131013
while (ma != NULL) {
10141014
if (gc_marked(jl_astaggedvalue(ma->a)->bits.gc)) {
10151015
nused++;

src/gc-tls.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ typedef struct {
2828
small_arraylist_t live_tasks;
2929

3030
// variables for tracking malloc'd arrays
31-
struct _mallocarray_t *mallocarrays;
32-
struct _mallocarray_t *mafreelist;
31+
struct _mallocmemory_t *mallocarrays;
32+
struct _mallocmemory_t *mafreelist;
3333

3434
// variable for tracking young (i.e. not in `GC_OLD_MARKED`/last generation) large objects
3535
struct _bigval_t *young_generation_of_bigvals;

src/gc.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,15 +1069,15 @@ static void sweep_big(jl_ptls_t ptls) JL_NOTSAFEPOINT
10691069

10701070
void jl_gc_track_malloced_genericmemory(jl_ptls_t ptls, jl_genericmemory_t *m, int isaligned){
10711071
// This is **NOT** a GC safe point.
1072-
mallocarray_t *ma;
1072+
mallocmemory_t *ma;
10731073
if (ptls->gc_tls.heap.mafreelist == NULL) {
1074-
ma = (mallocarray_t*)malloc_s(sizeof(mallocarray_t));
1074+
ma = (mallocmemory_t*)malloc_s(sizeof(mallocmemory_t));
10751075
}
10761076
else {
10771077
ma = ptls->gc_tls.heap.mafreelist;
10781078
ptls->gc_tls.heap.mafreelist = ma->next;
10791079
}
1080-
ma->a = (jl_value_t*)((uintptr_t)m | !!isaligned);
1080+
ma->a = (jl_genericmemory_t*)((uintptr_t)m | !!isaligned);
10811081
ma->next = ptls->gc_tls.heap.mallocarrays;
10821082
ptls->gc_tls.heap.mallocarrays = ma;
10831083
}
@@ -1193,10 +1193,10 @@ static void sweep_malloced_memory(void) JL_NOTSAFEPOINT
11931193
for (int t_i = 0; t_i < gc_n_threads; t_i++) {
11941194
jl_ptls_t ptls2 = gc_all_tls_states[t_i];
11951195
if (ptls2 != NULL) {
1196-
mallocarray_t *ma = ptls2->gc_tls.heap.mallocarrays;
1197-
mallocarray_t **pma = &ptls2->gc_tls.heap.mallocarrays;
1196+
mallocmemory_t *ma = ptls2->gc_tls.heap.mallocarrays;
1197+
mallocmemory_t **pma = &ptls2->gc_tls.heap.mallocarrays;
11981198
while (ma != NULL) {
1199-
mallocarray_t *nxt = ma->next;
1199+
mallocmemory_t *nxt = ma->next;
12001200
jl_value_t *a = (jl_value_t*)((uintptr_t)ma->a & ~1);
12011201
int bits = jl_astaggedvalue(a)->bits.gc;
12021202
if (gc_marked(bits)) {

src/gc.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,11 @@ JL_EXTENSION typedef struct _bigval_t {
145145
// must be 64-byte aligned here, in 32 & 64 bit modes
146146
} bigval_t;
147147

148-
// data structure for tracking malloc'd arrays and genericmemory.
149-
150-
typedef struct _mallocarray_t {
151-
jl_value_t *a;
152-
struct _mallocarray_t *next;
153-
} mallocarray_t;
148+
// data structure for tracking malloc'd genericmemory.
149+
typedef struct _mallocmemory_t {
150+
jl_genericmemory_t *a; // lowest bit is tagged if this is aligned memory
151+
struct _mallocmemory_t *next;
152+
} mallocmemory_t;
154153

155154
// pool page metadata
156155
typedef struct _jl_gc_pagemeta_t {

0 commit comments

Comments
 (0)