Skip to content

Commit b7de63c

Browse files
vchuravygbaraldi
andauthored
Allow for :foreigncall to transition to GC safe automatically (JuliaLang#49933)
This has been bouncing around as a idea for a while. One of the challenges around time-to-safepoint has been Julia code that is calling libraries. Since foreign code will not include safepoints we see increased latency when one thread is running a foreign-call and another wants to trigger GC. The open design question here is: - Do we expose this as an option the user must "opt-in", e.g. by using a keyword arg to `@ccall` or a specific calling-convetion. - Or do we turn this on for all ccall, except for Julia runtime calls. There is relativly little code outside the Julia runtime that needs to be "GC unsafe", exception are programs that directly use the Julia C-API. Incidentially `jl_adopt_thread` and `@cfunction`/`@ccallable` do the right thing and transition to "GC unsafe", regardless of what state the thread currently is in. I still need to figure out how to reliably detect Julia runtime calls, but I think we can switch all other calls to "GC safe". We should also consider optimizations that mark large regions of code without Julia runtime interactions as "GC safe" in particular numeric for-loops. Closes JuliaLang#57057 --------- Co-authored-by: Gabriel Baraldi <baraldigabriel@gmail.com>
1 parent d2ad808 commit b7de63c

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/abstractinterpretation.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3421,7 +3421,7 @@ function abstract_eval_foreigncall(interp::AbstractInterpreter, e::Expr, sstate:
34213421
abstract_eval_value(interp, x, sstate, sv)
34223422
end
34233423
cconv = e.args[5]
3424-
if isa(cconv, QuoteNode) && (v = cconv.value; isa(v, Tuple{Symbol, UInt16}))
3424+
if isa(cconv, QuoteNode) && (v = cconv.value; isa(v, Tuple{Symbol, UInt16, Bool}))
34253425
override = decode_effects_override(v[2])
34263426
effects = override_effects(effects, override)
34273427
end

src/validation.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const VALID_EXPR_HEADS = IdDict{Symbol,UnitRange{Int}}(
2323
:meta => 0:typemax(Int),
2424
:global => 1:1,
2525
:globaldecl => 1:2,
26-
:foreigncall => 5:typemax(Int), # name, RT, AT, nreq, (cconv, effects), args..., roots...
26+
:foreigncall => 5:typemax(Int), # name, RT, AT, nreq, (cconv, effects, gc_safe), args..., roots...
2727
:cfunction => 5:5,
2828
:isdefined => 1:2,
2929
:code_coverage_effect => 0:0,

0 commit comments

Comments
 (0)