Skip to content

Commit d069692

Browse files
committed
Handle gcanalyzer
1 parent 0546798 commit d069692

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
@@ -700,21 +700,22 @@ void jl_init_threading(void)
700700
gc_first_tid = nthreads;
701701
}
702702

703-
int jl_process_events_locked(void);
704-
void jl_utility_io_threadfun(void *arg) {
705-
703+
int jl_process_events_locked(void) JL_NOTSAFEPOINT;
704+
void jl_utility_io_threadfun(void *arg)
705+
{
706706
jl_adopt_thread();
707707
jl_ptls_t ptls = jl_current_task->ptls;
708-
jl_gc_safe_enter(ptls);
708+
int8_t gc_state = jl_gc_safe_enter(ptls);
709709
while (1) {
710-
// Only reader of the rwlock, according to libuv lock is writer-biased
711710
if (jl_atomic_load_relaxed(&jl_uv_n_waiters) == 0)
712711
if (JL_UV_TRYLOCK_NOGC())
713712
{
714713
jl_process_events_locked();
715714
JL_UV_UNLOCK_NOGC();
716715
}
716+
// TODO: jl_fence(); // [^store_buffering_2]
717717
}
718+
jl_gc_safe_leave(ptls, gc_state);
718719
return;
719720
}
720721

@@ -779,10 +780,11 @@ void jl_start_threads(void)
779780
}
780781
uv_thread_detach(&uvtid);
781782
}
783+
uv_barrier_wait(&thread_init_done);
784+
785+
// utility thread uses jl_adopt_thread
782786
uv_thread_create(&uvtid, jl_utility_io_threadfun, NULL);
783787
uv_thread_detach(&uvtid);
784-
785-
uv_barrier_wait(&thread_init_done);
786788
}
787789

788790
// Profiling stubs

0 commit comments

Comments
 (0)