Skip to content

Commit

Permalink
Adding GC.gc_active_impl
Browse files Browse the repository at this point in the history
  • Loading branch information
udesou authored and Luis Eduardo de Souza Amorim committed Jan 24, 2025
1 parent fb9029d commit c332104
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
2 changes: 1 addition & 1 deletion base/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ include("sysinfo.jl")
include("libc.jl")
using .Libc: getpid, gethostname, time, memcpy, memset, memmove, memcmp

const USING_STOCK_GC = occursin("stock", unsafe_string(ccall(:jl_gc_active_impl, Ptr{UInt8}, ())))
const USING_STOCK_GC = occursin("stock", GC.gc_active_impl())

# These used to be in build_h.jl and are retained for backwards compatibility.
# NOTE: keep in sync with `libblastrampoline_jll.libblastrampoline`.
Expand Down
11 changes: 11 additions & 0 deletions base/gcutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,15 @@ function logging_enabled()
ccall(:jl_is_gc_logging_enabled, Cint, ()) != 0
end

"""
GC.gc_active_impl()
Return a string stating which GC implementation is being used and possibly
its version according to the list of supported GCs
"""
function gc_active_impl()
unsafe_string(ccall(:jl_gc_active_impl, Ptr{UInt8}, ()))
end


end # module GC
8 changes: 6 additions & 2 deletions test/checked.jl
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,12 @@ end
@test checked_pow(BigInt(2), 2) == BigInt(4)
@test checked_pow(BigInt(2), 100) == BigInt(1267650600228229401496703205376)

# Perf test: Make sure BigInts allocs don't scale with the power:
@test @allocations(checked_pow(BigInt(2), 2)) @allocations(checked_pow(BigInt(2), 10000)) rtol=0.9
# FIXME: Issue #57103: the following test may fail because
# allocation may not be logged via MMTk's fastpath allocation
@static if Base.USING_STOCK_GC
# Perf test: Make sure BigInts allocs don't scale with the power:
@test @allocations(checked_pow(BigInt(2), 2)) @allocations(checked_pow(BigInt(2), 10000)) rtol=0.9
end
end

@testset "Additional tests" begin
Expand Down
36 changes: 18 additions & 18 deletions test/gc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,23 @@ function run_gctest(file)
end
end

#FIXME: Issue #57103 disabling tests for MMTk, since
# they rely on information that is specific to the stock GC.
@static if Base.USING_STOCK_GC
function run_nonzero_page_utilization_test()
GC.gc()
page_utilization = Base.gc_page_utilization_data()
# at least one of the pools should have nonzero page_utilization
@test any(page_utilization .> 0)
end

function run_pg_size_test()
page_size = @ccall jl_get_pg_size()::UInt64
# supported page sizes: 4KB and 16KB
@test page_size == (1 << 12) || page_size == (1 << 14)
end

function issue_54275_alloc_string()
String(UInt8['a' for i in 1:10000000])
end

function issue_54275_test()
GC.gc(true)
baseline = Base.gc_live_bytes()
Expand All @@ -48,17 +55,6 @@ function full_sweep_reasons_test()
@test reasons[:FULL_SWEEP_REASON_FORCED_FULL_SWEEP] >= 1
@test keys(reasons) == Set(Base.FULL_SWEEP_REASONS)
end
end

function run_pg_size_test()
page_size = @ccall jl_get_pg_size()::UInt64
# supported page sizes: 4KB and 16KB
@test page_size == (1 << 12) || page_size == (1 << 14)
end

function issue_54275_alloc_string()
String(UInt8['a' for i in 1:10000000])
end

# !!! note:
# Since we run our tests on 32bit OS as well we confine ourselves
Expand All @@ -71,6 +67,9 @@ end
run_gctest("gc/chunks.jl")
end

#FIXME: Issue #57103 disabling tests for MMTk, since
# they rely on information that is specific to the stock GC.
@static if Base.USING_STOCK_GC
@testset "GC page metrics" begin
run_nonzero_page_utilization_test()
run_pg_size_test()
Expand All @@ -80,13 +79,14 @@ end
issue_54275_test()
end

@testset "Base.GC docstrings" begin
@test isempty(Docs.undocumented_names(GC))
end

@testset "Full GC reasons" begin
full_sweep_reasons_test()
end
end

@testset "Base.GC docstrings" begin
@test isempty(Docs.undocumented_names(GC))
end

#testset doesn't work here because this needs to run in top level
#Check that we ensure objects in toplevel exprs are rooted
Expand Down

0 comments on commit c332104

Please sign in to comment.