Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init: avoid an undesirable compiler optimization #42377

Merged
merged 1 commit into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,8 @@ static void restore_fp_env(void)
}
}

static NOINLINE void _finish_julia_init(JL_IMAGE_SEARCH rel, jl_ptls_t ptls, jl_task_t *ct);

JL_DLLEXPORT void julia_init(JL_IMAGE_SEARCH rel)
{
jl_init_timing();
Expand Down Expand Up @@ -722,9 +724,14 @@ JL_DLLEXPORT void julia_init(JL_IMAGE_SEARCH rel)
jl_init_threading();

jl_ptls_t ptls = jl_init_threadtls(0);
jl_init_root_task(ptls, stack_lo, stack_hi);
jl_task_t *ct = jl_current_task;
// warning: this changes `jl_current_task`, so be careful not to call that from this function
jl_task_t *ct = jl_init_root_task(ptls, stack_lo, stack_hi);
JL_GC_PROMISE_ROOTED(ct);
_finish_julia_init(rel, ptls, ct);
}

static NOINLINE void _finish_julia_init(JL_IMAGE_SEARCH rel, jl_ptls_t ptls, jl_task_t *ct)
{
jl_init_threadinginfra();

jl_resolve_sysimg_location(rel);
Expand Down
2 changes: 1 addition & 1 deletion src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ void jl_init_intrinsic_functions(void);
void jl_init_intrinsic_properties(void);
void jl_init_tasks(void) JL_GC_DISABLED;
void jl_init_stack_limits(int ismaster, void **stack_hi, void **stack_lo);
void jl_init_root_task(jl_ptls_t ptls, void *stack_lo, void *stack_hi);
jl_task_t *jl_init_root_task(jl_ptls_t ptls, void *stack_lo, void *stack_hi);
void jl_init_serializer(void);
void jl_gc_init(void);
void jl_init_uv(void);
Expand Down
6 changes: 4 additions & 2 deletions src/partr.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ void jl_threadfun(void *arg)
jl_ptls_t ptls = jl_init_threadtls(targ->tid);
void *stack_lo, *stack_hi;
jl_init_stack_limits(0, &stack_lo, &stack_hi);
jl_init_root_task(ptls, stack_lo, stack_hi);
// warning: this changes `jl_current_task`, so be careful not to call that from this function
jl_task_t *ct = jl_init_root_task(ptls, stack_lo, stack_hi);
JL_GC_PROMISE_ROOTED(ct);
jl_install_thread_signal_handler(ptls);

// set up sleep mechanism for this thread
Expand All @@ -262,7 +264,7 @@ void jl_threadfun(void *arg)
free(targ);

(void)jl_gc_unsafe_enter(ptls);
jl_finish_task(jl_current_task); // noreturn
jl_finish_task(ct); // noreturn
}


Expand Down
5 changes: 3 additions & 2 deletions src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ static char *jl_alloc_fiber(jl_ucontext_t *t, size_t *ssize, jl_task_t *owner) J
#endif

// Initialize a root task using the given stack.
void jl_init_root_task(jl_ptls_t ptls, void *stack_lo, void *stack_hi)
jl_task_t *jl_init_root_task(jl_ptls_t ptls, void *stack_lo, void *stack_hi)
{
assert(ptls->root_task == NULL);
// We need `gcstack` in `Task` to allocate Julia objects; *including* the `Task` type.
Expand Down Expand Up @@ -1327,13 +1327,14 @@ void jl_init_root_task(jl_ptls_t ptls, void *stack_lo, void *stack_hi)
#endif
if (jl_setjmp(ptls->copy_stack_ctx.uc_mcontext, 0))
start_task(); // sanitizer_finish_switch_fiber is part of start_task
return;
return ct;
}
ssize = JL_STACK_SIZE;
char *stkbuf = jl_alloc_fiber(&ptls->base_ctx, &ssize, NULL);
ptls->stackbase = stkbuf + ssize;
ptls->stacksize = ssize;
#endif
return ct;
}

JL_DLLEXPORT int jl_is_task_started(jl_task_t *t) JL_NOTSAFEPOINT
Expand Down