Skip to content

Commit 340f13f

Browse files
committed
gcext: add ptls argument to task scanner
Access to ptls is generally necessary when marking objects so it makes sense to pass it to the task scanner. We pass it as the last argument to the callback so that existing consumers of this API hopefully keep working, they will just ignore this new argument.
1 parent 4ecdc37 commit 340f13f

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

src/gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2726,7 +2726,7 @@ FORCE_INLINE void gc_mark_outrefs(jl_ptls_t ptls, jl_gc_markqueue_t *mq, void *_
27262726
if (gc_cblist_task_scanner) {
27272727
int16_t tid = jl_atomic_load_relaxed(&ta->tid);
27282728
gc_invoke_callbacks(jl_gc_cb_task_scanner_t, gc_cblist_task_scanner,
2729-
(ta, tid != -1 && ta == gc_all_tls_states[tid]->root_task));
2729+
(ta, tid != -1 && ta == gc_all_tls_states[tid]->root_task, ptls));
27302730
}
27312731
#ifdef COPY_STACKS
27322732
void *stkbuf = ta->stkbuf;

src/julia_gcext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extern "C" {
1515
// along with custom mark functions must not alter the GC state except
1616
// through calling jl_gc_mark_queue_obj() and jl_gc_mark_queue_objarray().
1717
typedef void (*jl_gc_cb_root_scanner_t)(int full) JL_NOTSAFEPOINT;
18-
typedef void (*jl_gc_cb_task_scanner_t)(jl_task_t *task, int full) JL_NOTSAFEPOINT;
18+
typedef void (*jl_gc_cb_task_scanner_t)(jl_task_t *task, int is_root_task, jl_ptls_t ptls) JL_NOTSAFEPOINT;
1919

2020
// Callbacks that are invoked before and after a collection.
2121
typedef void (*jl_gc_cb_pre_gc_t)(int full) JL_NOTSAFEPOINT;

test/gcext/gcext.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ typedef struct {
284284
static jl_datatype_t *datatype_stack_internal;
285285
static jl_datatype_t *datatype_stack_external;
286286
static jl_datatype_t *datatype_stack;
287-
static jl_ptls_t ptls;
288287

289288
static size_t gc_alloc_size(jl_value_t *val)
290289
{
@@ -333,7 +332,7 @@ int internal_obj_scan(jl_value_t *val)
333332
}
334333
}
335334

336-
dynstack_t *allocate_stack_mem(size_t capacity)
335+
dynstack_t *allocate_stack_mem(jl_ptls_t ptls, size_t capacity)
337336
{
338337
size_t size = offsetof(dynstack_t, data) + capacity * sizeof(jl_value_t *);
339338
jl_datatype_t *type = datatype_stack_internal;
@@ -377,13 +376,14 @@ jl_value_t *stk_type()
377376

378377
// Create a new stack object
379378

380-
jl_value_t *stk_make()
379+
jl_value_t *stk_make(void)
381380
{
381+
jl_ptls_t ptls = jl_get_ptls_states();
382382
jl_value_t *hdr =
383383
jl_gc_alloc_typed(ptls, sizeof(jl_value_t *), datatype_stack);
384384
JL_GC_PUSH1(hdr);
385385
*(dynstack_t **)hdr = NULL;
386-
dynstack_t *stk = allocate_stack_mem(8);
386+
dynstack_t *stk = allocate_stack_mem(ptls, 8);
387387
*(dynstack_t **)hdr = stk;
388388
jl_gc_schedule_foreign_sweepfunc(ptls, (jl_value_t *)(stk));
389389
JL_GC_POP();
@@ -408,7 +408,8 @@ void stk_push(jl_value_t *s, jl_value_t *v)
408408
jl_gc_wb((jl_value_t *)stk, v);
409409
}
410410
else {
411-
dynstack_t *newstk = allocate_stack_mem(stk->capacity * 3 / 2 + 1);
411+
jl_ptls_t ptls = jl_get_ptls_states();
412+
dynstack_t *newstk = allocate_stack_mem(ptls, stk->capacity * 3 / 2 + 1);
412413
newstk->size = stk->size;
413414
memcpy(newstk->data, stk->data, sizeof(jl_value_t *) * stk->size);
414415
*(dynstack_t **)s = newstk;
@@ -453,6 +454,7 @@ static jl_module_t *module;
453454

454455
void root_scanner(int full)
455456
{
457+
jl_ptls_t ptls = jl_get_ptls_states();
456458
for (int i = 0; i < NAUXROOTS; i++) {
457459
if (aux_roots[i])
458460
jl_gc_mark_queue_obj(ptls, aux_roots[i]);
@@ -477,7 +479,7 @@ static int stack_grows_down(void) {
477479
return is_lower_stack_frame_ptr(buf);
478480
}
479481

480-
void task_scanner(jl_task_t *task, int root_task)
482+
void task_scanner(jl_task_t *task, int root_task, jl_ptls_t ptls)
481483
{
482484
int var_on_frame;
483485

@@ -603,7 +605,6 @@ int main()
603605
jl_init();
604606
if (jl_gc_enable_conservative_gc_support() < 0)
605607
abort();
606-
ptls = jl_get_ptls_states();
607608
jl_gc_set_cb_root_scanner(root_scanner, 1);
608609
jl_gc_set_cb_task_scanner(task_scanner, 1);
609610
jl_gc_set_cb_pre_gc(pre_gc_func, 1);

0 commit comments

Comments
 (0)