Skip to content

Commit 7e5508a

Browse files
committed
Move locking to C
1 parent 39d9e56 commit 7e5508a

File tree

5 files changed

+34
-17
lines changed

5 files changed

+34
-17
lines changed

Compiler/src/typeinfer.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,13 +1557,10 @@ function add_codeinsts_to_jit!(interp::AbstractInterpreter, ci, source_mode::UIn
15571557
return ci
15581558
end
15591559

1560-
const collect_dispatch_backtrace = fill(false)
1561-
function store_dispatch_backtrace end
1562-
15631560
function typeinf_ext_toplevel(interp::AbstractInterpreter, mi::MethodInstance, source_mode::UInt8)
15641561
ci = typeinf_ext(interp, mi, source_mode)
1565-
if isa(ci, CodeInstance) && collect_dispatch_backtrace[]
1566-
Core.invokelatest(store_dispatch_backtrace, ci)
1562+
if isa(ci, CodeInstance) && ccall(:jl_recording_inference_entrance_backtraces, Cint, ()) != 0
1563+
ccall(:jl_push_inference_entrance_backtraces, Cvoid, (Any,), ci => backtrace())
15671564
end
15681565
ci = add_codeinsts_to_jit!(interp, ci, source_mode)
15691566
return ci

base/loading.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4246,4 +4246,3 @@ precompile(include_package_for_output, (PkgId, String, Vector{String}, Vector{St
42464246
precompile(include_package_for_output, (PkgId, String, Vector{String}, Vector{String}, Vector{String}, typeof(_concrete_dependencies), String)) || @assert false
42474247
precompile(create_expr_cache, (PkgId, String, String, String, typeof(_concrete_dependencies), Cmd, CacheFlags, IO, IO)) || @assert false
42484248
precompile(create_expr_cache, (PkgId, String, String, Nothing, typeof(_concrete_dependencies), Cmd, CacheFlags, IO, IO)) || @assert false
4249-
precompile(Compiler.store_dispatch_backtrace, (Core.CodeInstance,))

base/stacktraces.jl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -376,14 +376,3 @@ function from(frame::StackFrame, m::Module)
376376
end
377377

378378
end # module StackTraces
379-
380-
# Back to Base
381-
# Implement locking for Compiler.store_dispatch_backtrace
382-
const dispatch_backtrace = IdDict{Core.CodeInstance,Any}()
383-
const dispatch_backtrace_lock = ReentrantLock()
384-
385-
function Compiler.store_dispatch_backtrace(ci::Core.CodeInstance)
386-
lock(dispatch_backtrace_lock) do
387-
dispatch_backtrace[ci] = backtrace()
388-
end
389-
end

src/julia.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2245,6 +2245,9 @@ JL_DLLEXPORT jl_value_t *jl_object_top_module(jl_value_t* v) JL_NOTSAFEPOINT;
22452245

22462246
JL_DLLEXPORT void jl_set_newly_inferred(jl_value_t *newly_inferred);
22472247
JL_DLLEXPORT void jl_push_newly_inferred(jl_value_t *ci);
2248+
JL_DLLEXPORT void jl_set_inference_entrance_backtraces(jl_value_t *inference_entrance_backtraces);
2249+
JL_DLLEXPORT int jl_recording_inference_entrance_backtraces(void);
2250+
JL_DLLEXPORT void jl_push_inference_entrance_backtraces(jl_value_t *ci_bt_pair);
22482251
JL_DLLEXPORT void jl_write_compiler_output(void);
22492252

22502253
// parsing

src/staticdata_utils.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,35 @@ JL_DLLEXPORT void jl_push_newly_inferred(jl_value_t* ci)
131131
JL_UNLOCK(&newly_inferred_mutex);
132132
}
133133

134+
135+
static jl_array_t *inference_entrance_backtraces JL_GLOBALLY_ROOTED /*FIXME*/ = NULL;
136+
// Mutex for inference_entrance_backtraces
137+
jl_mutex_t inference_entrance_backtraces_mutex;
138+
139+
// Register array of inference entrance backtraces
140+
JL_DLLEXPORT void jl_set_inference_entrance_backtraces(jl_value_t* _inference_entrance_backtraces)
141+
{
142+
assert(_inference_entrance_backtraces == NULL || _inference_entrance_backtraces == jl_nothing || jl_is_array(_inference_entrance_backtraces));
143+
if (_inference_entrance_backtraces == jl_nothing)
144+
_inference_entrance_backtraces = NULL;
145+
inference_entrance_backtraces = (jl_array_t*) _inference_entrance_backtraces;
146+
}
147+
148+
JL_DLLEXPORT int jl_recording_inference_entrance_backtraces(void)
149+
{
150+
return inference_entrance_backtraces != NULL;
151+
}
152+
153+
JL_DLLEXPORT void jl_push_inference_entrance_backtraces(jl_value_t* ci_bt_pair)
154+
{
155+
assert(inference_entrance_backtraces);
156+
JL_LOCK(&inference_entrance_backtraces_mutex);
157+
size_t end = jl_array_nrows(inference_entrance_backtraces);
158+
jl_array_grow_end(inference_entrance_backtraces, 1);
159+
jl_array_ptr_set(inference_entrance_backtraces, end, ci_bt_pair);
160+
JL_UNLOCK(&inference_entrance_backtraces_mutex);
161+
}
162+
134163
// compute whether a type references something internal to worklist
135164
// and thus could not have existed before deserialize
136165
// and thus does not need delayed unique-ing

0 commit comments

Comments
 (0)