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

GC/Parallel marking #44643

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ typedef jl_gcframe_t ***(*jl_pgcstack_key_t)(void) JL_NOTSAFEPOINT;
#endif
JL_DLLEXPORT void jl_pgcstack_getkey(jl_get_pgcstack_func **f, jl_pgcstack_key_t *k);

#if !defined(__clang_gcanalyzer__) && !defined(_OS_DARWIN_)
#if !defined(__clang_gcanalyzer__)
static inline void jl_set_gc_and_wait(void)
{
jl_task_t *ct = jl_current_task;
Expand Down
2 changes: 1 addition & 1 deletion src/safepoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void jl_safepoint_end_gc(void)

void jl_safepoint_wait_gc(void)
{
jl_ptls_t ptls = jl_current_task->ptls;
jl_ptls_t ptls = jl_current_task->ptls;
// Use normal volatile load in the loop for speed until GC finishes.
// Then use an acquire load to make sure the GC result is visible on this thread.
while (jl_atomic_load_relaxed(&jl_gc_running) || jl_atomic_load_acquire(&jl_gc_running)) {
Expand Down
32 changes: 17 additions & 15 deletions src/signals-mach.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#endif

#include "julia_assert.h"
#include "julia_internal.h"

// private keymgr stuff
#define KEYMGR_GCC3_DW2_OBJ_LIST 302
Expand Down Expand Up @@ -60,19 +61,7 @@ static int jl_mach_gc_wait(jl_ptls_t ptls2,
mach_port_t thread, int16_t tid)
{
uv_mutex_lock(&safepoint_lock);
if (!jl_atomic_load_relaxed(&jl_gc_running)) {
// relaxed, since gets set to zero only while the safepoint_lock was held
// this means we can tell if GC is done before we got the message or
// the safepoint was enabled for SIGINT.
uv_mutex_unlock(&safepoint_lock);
return 0;
}
// Otherwise, set the gc state of the thread, suspend and record it
int8_t gc_state = ptls2->gc_state;
jl_atomic_store_release(&ptls2->gc_state, JL_GC_STATE_WAITING);
uintptr_t item = tid | (((uintptr_t)gc_state) << 16);
arraylist_push(&suspended_threads, (void*)item);
thread_suspend(thread);
int gc_running = jl_atomic_load_relaxed(&jl_gc_running);
uv_mutex_unlock(&safepoint_lock);
return 1;
}
Expand Down Expand Up @@ -229,11 +218,24 @@ static void jl_throw_in_thread(int tid, mach_port_t thread, jl_value_t *exceptio
static void segv_handler(int sig, siginfo_t *info, void *context)
{
assert(sig == SIGSEGV || sig == SIGBUS);
jl_task_t *ct = jl_get_current_task();
if (jl_get_safe_restore()) { // restarting jl_ or jl_unwind_stepn
jl_task_t *ct = jl_get_current_task();
jl_ptls_t ptls = ct == NULL ? NULL : ct->ptls;
jl_call_in_state(ptls, (host_thread_state_t*)jl_to_bt_context(context), &jl_sig_throw);
}
else if (jl_addr_is_safepoint((uintptr_t)info->si_addr)) {
jl_set_gc_and_wait();
// Do not raise sigint on worker thread
if (jl_atomic_load_relaxed(&ct->tid) != 0)
return;
if (ct->ptls->defer_signal) {
jl_safepoint_defer_sigint();
}
else if (jl_safepoint_consume_sigint()) {
jl_clear_force_sigint();
jl_throw_in_ctx(ct, jl_interrupt_exception, sig, context);
}
}
else {
sigdie_handler(sig, info, context);
}
Expand Down Expand Up @@ -285,7 +287,7 @@ kern_return_t catch_exception_raise(mach_port_t exception_port,
#endif
if (jl_addr_is_safepoint(fault_addr)) {
if (jl_mach_gc_wait(ptls2, thread, tid))
return KERN_SUCCESS;
return KERN_FAILURE;
if (ptls2->tid != 0)
return KERN_SUCCESS;
if (ptls2->defer_signal) {
Expand Down