Skip to content

Commit 78a817d

Browse files
committed
Handle gcanalyzer
1 parent d958458 commit 78a817d

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

src/jl_uv.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static void jl_uv_cb_walk_print(uv_handle_t *h, void *arg)
5656
jl_safe_printf(" %s[%zd] %s@%p->%p\n", type, (size_t)fd, pad, (void*)h, (void*)h->data);
5757
}
5858

59-
static void jl_uv_cb_wait_empty(uv_timer_t *t)
59+
static void jl_uv_cb_wait_empty(uv_timer_t *t) JL_NOTSAFEPOINT_ENTER
6060
{
6161
// make sure this is hidden now, since we would auto-unref it later
6262
uv_unref((uv_handle_t*)&signal_async);
@@ -69,7 +69,7 @@ static void jl_uv_cb_wait_empty(uv_timer_t *t)
6969
jl_ptls_t ptls = jl_current_task->ptls;
7070
int old_state = jl_gc_unsafe_enter(ptls);
7171
jl_gc_collect(JL_GC_FULL);
72-
jl_gc_unsafe_leave(ptls,old_state);
72+
jl_gc_unsafe_leave(ptls, old_state);
7373
}
7474

7575
void jl_wait_empty_begin(void)
@@ -154,7 +154,7 @@ JL_DLLEXPORT void jl_iolock_end(void)
154154
}
155155

156156

157-
static void jl_uv_call_hook_close(jl_value_t *val)
157+
static void jl_uv_call_hook_close(jl_value_t *val) JL_NOTSAFEPOINT_ENTER
158158
{
159159
jl_ptls_t ptls = jl_current_task->ptls;
160160
int old_state = jl_gc_unsafe_enter(ptls);
@@ -166,7 +166,7 @@ static void jl_uv_call_hook_close(jl_value_t *val)
166166
assert(args[0]);
167167
jl_apply(args, 2); // TODO: wrap in try-catch?
168168
JL_GC_POP();
169-
jl_gc_unsafe_leave(ptls,old_state);
169+
jl_gc_unsafe_leave(ptls, old_state);
170170
}
171171

172172
static void jl_uv_cb_close_handle(uv_handle_t *handle)
@@ -282,7 +282,10 @@ JL_DLLEXPORT void *jl_uv_handle_data(uv_handle_t *handle) { return handle->data;
282282
JL_DLLEXPORT void *jl_uv_write_handle(uv_write_t *req) { return req->handle; }
283283

284284

285-
int jl_process_events_locked(void) {
285+
// This is JL_NOTSAFEPOINT, but the analyzer complains about uv_run.
286+
// Callabacks need to handle their GC transitions themselves.
287+
int jl_process_events_locked(void) // JL_NOTSAFEPOINT
288+
{
286289
uv_loop_t *loop = jl_io_loop;
287290
loop->stop_flag = 0;
288291
uv_ref((uv_handle_t*)&signal_async); // force the loop alive

src/julia_internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ static uv_loop_t *const unused_uv_loop_arg = (uv_loop_t *)0xBAD10;
181181
extern jl_mutex_t jl_uv_mutex;
182182
extern _Atomic(int) jl_uv_n_waiters;
183183
void JL_UV_LOCK(void);
184-
int JL_UV_TRYLOCK_NOGC(void);
185-
void JL_UV_UNLOCK_NOGC(void);
184+
int JL_UV_TRYLOCK_NOGC(void) JL_NOTSAFEPOINT;
185+
void JL_UV_UNLOCK_NOGC(void) JL_NOTSAFEPOINT;
186186
#define JL_UV_UNLOCK() JL_UNLOCK(&jl_uv_mutex)
187187

188188
#ifdef __cplusplus

src/threading.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -702,21 +702,22 @@ void jl_init_threading(void)
702702
gc_first_tid = nthreads;
703703
}
704704

705-
int jl_process_events_locked(void);
706-
void jl_utility_io_threadfun(void *arg) {
707-
705+
int jl_process_events_locked(void) JL_NOTSAFEPOINT;
706+
void jl_utility_io_threadfun(void *arg)
707+
{
708708
jl_adopt_thread();
709709
jl_ptls_t ptls = jl_current_task->ptls;
710-
jl_gc_safe_enter(ptls);
710+
int8_t gc_state = jl_gc_safe_enter(ptls);
711711
while (1) {
712-
// Only reader of the rwlock, according to libuv lock is writer-biased
713712
if (jl_atomic_load_relaxed(&jl_uv_n_waiters) == 0)
714713
if (JL_UV_TRYLOCK_NOGC())
715714
{
716715
jl_process_events_locked();
717716
JL_UV_UNLOCK_NOGC();
718717
}
718+
// TODO: jl_fence(); // [^store_buffering_2]
719719
}
720+
jl_gc_safe_leave(ptls, gc_state);
720721
return;
721722
}
722723

@@ -781,10 +782,11 @@ void jl_start_threads(void)
781782
}
782783
uv_thread_detach(&uvtid);
783784
}
785+
uv_barrier_wait(&thread_init_done);
786+
787+
// utility thread uses jl_adopt_thread
784788
uv_thread_create(&uvtid, jl_utility_io_threadfun, NULL);
785789
uv_thread_detach(&uvtid);
786-
787-
uv_barrier_wait(&thread_init_done);
788790
}
789791

790792
// Profiling stubs

0 commit comments

Comments
 (0)