Skip to content

Use relaxed atomics to load/update jl_lineno and jl_filename #58939

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/interpreter.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ static jl_value_t *eval_body(jl_array_t *stmts, interpreter_state *s, size_t ip,
s->locals[n - 1] = NULL;
}
else if (toplevel && jl_is_linenode(stmt)) {
jl_lineno = jl_linenode_line(stmt);
jl_atomic_store_relaxed(&jl_lineno, jl_linenode_line(stmt));
}
else {
eval_stmt_value(stmt, s);
Expand Down
4 changes: 2 additions & 2 deletions src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,8 @@ extern _Atomic(jl_typemap_entry_t*) call_cache[N_CALL_CACHE] JL_GLOBALLY_ROOTED;

void free_stack(void *stkbuf, size_t bufsz) JL_NOTSAFEPOINT;

JL_DLLEXPORT extern int jl_lineno;
JL_DLLEXPORT extern const char *jl_filename;
JL_DLLEXPORT extern _Atomic(int) jl_lineno;
JL_DLLEXPORT extern _Atomic(const char *) jl_filename;

jl_value_t *jl_gc_small_alloc_noinline(jl_ptls_t ptls, int offset,
int osize);
Expand Down
6 changes: 3 additions & 3 deletions src/method.c
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ JL_DLLEXPORT jl_code_info_t *jl_code_for_staged(jl_method_instance_t *mi, size_t
jl_code_instance_t *ci = NULL;
JL_GC_PUSH5(&ex, &func, &uninferred, &ci, &kind);
jl_task_t *ct = jl_current_task;
int last_lineno = jl_lineno;
int last_lineno = jl_atomic_load_relaxed(&jl_lineno);
int last_in = ct->ptls->in_pure_callback;
size_t last_age = ct->world_age;

Expand Down Expand Up @@ -818,12 +818,12 @@ JL_DLLEXPORT jl_code_info_t *jl_code_for_staged(jl_method_instance_t *mi, size_t
}

ct->ptls->in_pure_callback = last_in;
jl_lineno = last_lineno;
jl_atomic_store_relaxed(&jl_lineno, last_lineno);
ct->world_age = last_age;
}
JL_CATCH {
ct->ptls->in_pure_callback = last_in;
jl_lineno = last_lineno;
jl_atomic_store_relaxed(&jl_lineno, last_lineno);
jl_rethrow();
}
JL_GC_POP();
Expand Down
8 changes: 4 additions & 4 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -1145,8 +1145,8 @@ JL_DLLEXPORT int jl_is_imported(jl_module_t *m, jl_sym_t *var)
return b && jl_binding_kind(bpart) == PARTITION_KIND_IMPORTED;
}

extern const char *jl_filename;
extern int jl_lineno;
extern _Atomic(const char *) jl_filename;
extern _Atomic(int) jl_lineno;

static char const dep_message_prefix[] = "_dep_message_";

Expand Down Expand Up @@ -1868,8 +1868,8 @@ void jl_binding_deprecation_warning(jl_binding_t *b)
jl_binding_dep_message(b);

if (jl_options.depwarn != JL_OPTIONS_DEPWARN_ERROR) {
if (jl_lineno != 0) {
jl_printf(JL_STDERR, " likely near %s:%d\n", jl_filename, jl_lineno);
if (jl_atomic_load_relaxed(&jl_lineno) != 0) {
jl_printf(JL_STDERR, " likely near %s:%d\n", jl_atomic_load_relaxed(&jl_filename), jl_atomic_load_relaxed(&jl_lineno));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/signal-handling.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ void jl_critical_error(int sig, int si_code, bt_context_t *context, jl_task_t *c
else
jl_safe_printf("\n[%d] signal %d: %s\n", getpid(), sig, strsignal(sig));
}
jl_safe_printf("in expression starting at %s:%d\n", jl_filename, jl_lineno);
jl_safe_printf("in expression starting at %s:%d\n", jl_atomic_load_relaxed(&jl_filename), jl_atomic_load_relaxed(&jl_lineno));
if (context && ct) {
// Must avoid extended backtrace frames here unless we're sure bt_data
// is properly rooted.
Expand Down
46 changes: 23 additions & 23 deletions src/toplevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ extern "C" {
#endif

// current line number in a file
JL_DLLEXPORT int jl_lineno = 0; // need to update jl_critical_error if this is TLS
JL_DLLEXPORT _Atomic(int) jl_lineno = 0; // need to update jl_critical_error if this is TLS
// current file name
JL_DLLEXPORT const char *jl_filename = "none"; // need to update jl_critical_error if this is TLS
JL_DLLEXPORT _Atomic(const char *) jl_filename = "none"; // need to update jl_critical_error if this is TLS

htable_t jl_current_modules;
jl_mutex_t jl_modules_mutex;
Expand Down Expand Up @@ -619,8 +619,8 @@ JL_DLLEXPORT jl_value_t *jl_toplevel_eval_flex(jl_module_t *JL_NONNULL m, jl_val
*toplevel_filename = jl_symbol_name((jl_sym_t*)file);
}
// Not thread safe. For debugging and last resort error messages (jl_critical_error) only.
jl_filename = *toplevel_filename;
jl_lineno = *toplevel_lineno;
jl_atomic_store_relaxed(&jl_filename, *toplevel_filename);
jl_atomic_store_relaxed(&jl_lineno, *toplevel_lineno);
return jl_nothing;
}
return jl_interpret_toplevel_expr_in(m, e, NULL, NULL);
Expand Down Expand Up @@ -780,8 +780,8 @@ JL_DLLEXPORT jl_value_t *jl_toplevel_eval_flex(jl_module_t *JL_NONNULL m, jl_val

JL_DLLEXPORT jl_value_t *jl_toplevel_eval(jl_module_t *m, jl_value_t *v)
{
const char *filename = jl_filename;
int lineno = jl_lineno;
const char *filename = jl_atomic_load_relaxed(&jl_filename);
int lineno = jl_atomic_load_relaxed(&jl_lineno);
return jl_toplevel_eval_flex(m, v, 1, 0, &filename, &lineno);
}

Expand Down Expand Up @@ -819,23 +819,23 @@ JL_DLLEXPORT jl_value_t *jl_toplevel_eval_in(jl_module_t *m, jl_value_t *ex)
{
jl_check_top_level_effect(m, "eval");
jl_value_t *v = NULL;
int last_lineno = jl_lineno;
const char *last_filename = jl_filename;
int last_lineno = jl_atomic_load_relaxed(&jl_lineno);
const char *last_filename = jl_atomic_load_relaxed(&jl_filename);
jl_task_t *ct = jl_current_task;
jl_lineno = 1;
jl_filename = "none";
jl_atomic_store_relaxed(&jl_lineno, 1);
jl_atomic_store_relaxed(&jl_filename, "none");
size_t last_age = ct->world_age;
JL_TRY {
ct->world_age = jl_atomic_load_acquire(&jl_world_counter);
v = jl_toplevel_eval(m, ex);
}
JL_CATCH {
jl_lineno = last_lineno;
jl_filename = last_filename;
jl_atomic_store_relaxed(&jl_lineno, last_lineno);
jl_atomic_store_relaxed(&jl_filename, last_filename);
jl_rethrow();
}
jl_lineno = last_lineno;
jl_filename = last_filename;
jl_atomic_store_relaxed(&jl_lineno, last_lineno);
jl_atomic_store_relaxed(&jl_filename, last_filename);
ct->world_age = last_age;
assert(v);
return v;
Expand Down Expand Up @@ -867,12 +867,12 @@ static jl_value_t *jl_parse_eval_all(jl_module_t *module, jl_value_t *text,
}

jl_task_t *ct = jl_current_task;
int last_lineno = jl_lineno;
const char *last_filename = jl_filename;
int last_lineno = jl_atomic_load_relaxed(&jl_lineno);
const char *last_filename = jl_atomic_load_relaxed(&jl_filename);
int lineno = 0;
jl_lineno = 0;
jl_atomic_store_relaxed(&jl_lineno, 0);
const char *filename_str = jl_string_data(filename);
jl_filename = filename_str;
jl_atomic_store_relaxed(&jl_filename, filename_str);

JL_TRY {
size_t last_age = ct->world_age;
Expand All @@ -882,7 +882,7 @@ static jl_value_t *jl_parse_eval_all(jl_module_t *module, jl_value_t *text,
if (jl_is_linenode(expression)) {
// filename is already set above.
lineno = jl_linenode_line(expression);
jl_lineno = lineno;
jl_atomic_store_relaxed(&jl_lineno, lineno);
continue;
}
expression = jl_svecref(jl_lower(expression, module, jl_string_data(filename), lineno, ~(size_t)0, 1), 0);
Expand All @@ -893,16 +893,16 @@ static jl_value_t *jl_parse_eval_all(jl_module_t *module, jl_value_t *text,
}
JL_CATCH {
result = jl_box_long(lineno); // (ab)use result to root error line
jl_lineno = last_lineno;
jl_filename = last_filename;
jl_atomic_store_relaxed(&jl_lineno, last_lineno);
jl_atomic_store_relaxed(&jl_filename, last_filename);
if (jl_loaderror_type == NULL)
jl_rethrow();
else
jl_rethrow_other(jl_new_struct(jl_loaderror_type, filename, result,
jl_current_exception(ct)));
}
jl_lineno = last_lineno;
jl_filename = last_filename;
jl_atomic_store_relaxed(&jl_lineno, last_lineno);
jl_atomic_store_relaxed(&jl_filename, last_filename);
JL_GC_POP();
return result;
}
Expand Down