Skip to content

Commit

Permalink
Putting everything that is common GC tls into gc-tls-common.h
Browse files Browse the repository at this point in the history
  • Loading branch information
udesou committed Oct 8, 2024
1 parent ae8f3d4 commit bc9e77e
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 116 deletions.
10 changes: 5 additions & 5 deletions src/gc-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,16 +587,16 @@ size_t jl_genericmemory_nbytes(jl_genericmemory_t *m) JL_NOTSAFEPOINT
void jl_gc_track_malloced_genericmemory(jl_ptls_t ptls, jl_genericmemory_t *m, int isaligned){
// This is **NOT** a GC safe point.
mallocmemory_t *ma;
if (ptls->gc_tls.heap.mafreelist == NULL) {
if (ptls->gc_tls_common.heap.mafreelist == NULL) {
ma = (mallocmemory_t*)malloc_s(sizeof(mallocmemory_t));
}
else {
ma = ptls->gc_tls.heap.mafreelist;
ptls->gc_tls.heap.mafreelist = ma->next;
ma = ptls->gc_tls_common.heap.mafreelist;
ptls->gc_tls_common.heap.mafreelist = ma->next;
}
ma->a = (jl_genericmemory_t*)((uintptr_t)m | !!isaligned);
ma->next = ptls->gc_tls.heap.mallocarrays;
ptls->gc_tls.heap.mallocarrays = ma;
ma->next = ptls->gc_tls_common.heap.mallocarrays;
ptls->gc_tls_common.heap.mallocarrays = ma;
}

// =========================================================================== //
Expand Down
18 changes: 9 additions & 9 deletions src/gc-stacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void _jl_free_stack(jl_ptls_t ptls, void *stkbuf, size_t bufsz) JL_NOTSAFEPOINT
if (bufsz <= pool_sizes[JL_N_STACK_POOLS - 1]) {
unsigned pool_id = select_pool(bufsz);
if (pool_sizes[pool_id] == bufsz) {
small_arraylist_push(&ptls->gc_tls.heap.free_stacks[pool_id], stkbuf);
small_arraylist_push(&ptls->gc_tls_common.heap.free_stacks[pool_id], stkbuf);
return;
}
}
Expand Down Expand Up @@ -160,7 +160,7 @@ void jl_release_task_stack(jl_ptls_t ptls, jl_task_t *task)
#ifdef _COMPILER_ASAN_ENABLED_
__asan_unpoison_stack_memory((uintptr_t)stkbuf, bufsz);
#endif
small_arraylist_push(&ptls->gc_tls.heap.free_stacks[pool_id], stkbuf);
small_arraylist_push(&ptls->gc_tls_common.heap.free_stacks[pool_id], stkbuf);
}
}
}
Expand All @@ -175,7 +175,7 @@ JL_DLLEXPORT void *jl_malloc_stack(size_t *bufsz, jl_task_t *owner) JL_NOTSAFEPO
if (ssize <= pool_sizes[JL_N_STACK_POOLS - 1]) {
unsigned pool_id = select_pool(ssize);
ssize = pool_sizes[pool_id];
small_arraylist_t *pool = &ptls->gc_tls.heap.free_stacks[pool_id];
small_arraylist_t *pool = &ptls->gc_tls_common.heap.free_stacks[pool_id];
if (pool->len > 0) {
stk = small_arraylist_pop(pool);
}
Expand All @@ -196,7 +196,7 @@ JL_DLLEXPORT void *jl_malloc_stack(size_t *bufsz, jl_task_t *owner) JL_NOTSAFEPO
}
*bufsz = ssize;
if (owner) {
small_arraylist_t *live_tasks = &ptls->gc_tls.heap.live_tasks;
small_arraylist_t *live_tasks = &ptls->gc_tls_common.heap.live_tasks;
mtarraylist_push(live_tasks, owner);
}
return stk;
Expand All @@ -223,7 +223,7 @@ void sweep_stack_pools(void) JL_NOTSAFEPOINT

// free half of stacks that remain unused since last sweep
for (int p = 0; p < JL_N_STACK_POOLS; p++) {
small_arraylist_t *al = &ptls2->gc_tls.heap.free_stacks[p];
small_arraylist_t *al = &ptls2->gc_tls_common.heap.free_stacks[p];
size_t n_to_free;
if (jl_atomic_load_relaxed(&ptls2->current_task) == NULL) {
n_to_free = al->len; // not alive yet or dead, so it does not need these anymore
Expand All @@ -245,10 +245,10 @@ void sweep_stack_pools(void) JL_NOTSAFEPOINT
}
}
if (jl_atomic_load_relaxed(&ptls2->current_task) == NULL) {
small_arraylist_free(ptls2->gc_tls.heap.free_stacks);
small_arraylist_free(ptls2->gc_tls_common.heap.free_stacks);
}

small_arraylist_t *live_tasks = &ptls2->gc_tls.heap.live_tasks;
small_arraylist_t *live_tasks = &ptls2->gc_tls_common.heap.live_tasks;
size_t n = 0;
size_t ndel = 0;
size_t l = live_tasks->len;
Expand Down Expand Up @@ -299,7 +299,7 @@ JL_DLLEXPORT jl_array_t *jl_live_tasks(void)
jl_ptls_t ptls2 = allstates[i];
if (ptls2 == NULL)
continue;
small_arraylist_t *live_tasks = &ptls2->gc_tls.heap.live_tasks;
small_arraylist_t *live_tasks = &ptls2->gc_tls_common.heap.live_tasks;
size_t n = mtarraylist_length(live_tasks);
l += n + (ptls2->root_task->ctx.stkbuf != NULL);
}
Expand All @@ -318,7 +318,7 @@ JL_DLLEXPORT jl_array_t *jl_live_tasks(void)
goto restart;
jl_array_data(a,void*)[j++] = t;
}
small_arraylist_t *live_tasks = &ptls2->gc_tls.heap.live_tasks;
small_arraylist_t *live_tasks = &ptls2->gc_tls_common.heap.live_tasks;
size_t n = mtarraylist_length(live_tasks);
for (size_t i = 0; i < n; i++) {
jl_task_t *t = (jl_task_t*)mtarraylist_get(live_tasks, i);
Expand Down
Loading

0 comments on commit bc9e77e

Please sign in to comment.