Skip to content

Commit

Permalink
Mark GC API functions as non-allocating
Browse files Browse the repository at this point in the history
These might enable/disable garbage collection, but they don't themselves
trigger a safepoint or allocate objects (in most cases).

This does raise an interesting point: What should we do with
`GC.safepoint()` and `GC.gc()`? They are technically not allocating,
but many users may want to prohibit it anyway since they can trigger
a GC pause.
  • Loading branch information
topolarity committed Oct 26, 2023
1 parent e62fa4f commit d87f6ad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/allocfunc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ const known_nonalloc_funcs = (
"jl_pop_handler", "ijl_pop_handler",
"jl_f_typeof", "ijl_f_typeof",
"jl_clock_now", "ijl_clock_now",
"jl_gc_enable", "ijl_gc_enable",
"jl_gc_disable_finalizers_internal", "ijl_gc_disable_finalizers_internal",
"jl_gc_is_in_finalizer", "ijl_gc_is_in_finalizer",
"jl_enable_gc_logging", "ijl_enable_gc_logging",
)

const known_alloc_with_throw_funcs = (
Expand All @@ -27,6 +31,7 @@ const known_alloc_with_throw_funcs = (
"jl_f_is", "ijl_f_is",
"jl_f_throw", "ijl_f_throw",
"jl_f__svec_ref", "ijl_f__svec_ref",
"jl_gc_enable_finalizers_internal", "ijl_gc_enable_finalizers_internal",
)

function is_alloc_function(name, ignore_throw)
Expand Down
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ function same_ccall()
a,b
end

function toggle_gc()
GC.enable(false)
GC.enable(true)
end

@testset "AllocCheck.jl" begin
@test length(check_allocs(mod, (Float64,Float64))) == 0
@test length(check_allocs(sin, (Float64,); ignore_throw=false)) > 0
Expand All @@ -31,4 +36,6 @@ end
@test length(check_allocs(first, (Core.SimpleVector,); ignore_throw = false)) == 3
@test length(check_allocs(first, (Core.SimpleVector,); ignore_throw = true)) == 0
@test length(check_allocs(time, ())) == 0

@test length(check_allocs(toggle_gc, (); ignore_throw=false)) == 0
end

0 comments on commit d87f6ad

Please sign in to comment.