Skip to content

Commit

Permalink
Skipping some tests that are currently incompatible with MMTk
Browse files Browse the repository at this point in the history
  • Loading branch information
udesou committed Jan 22, 2025
1 parent f91436e commit 833c1b9
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 107 deletions.
2 changes: 2 additions & 0 deletions base/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ 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}, ())))

# These used to be in build_h.jl and are retained for backwards compatibility.
# NOTE: keep in sync with `libblastrampoline_jll.libblastrampoline`.
const libblas_name = "libblastrampoline" * (Sys.iswindows() ? "-5" : "")
Expand Down
6 changes: 2 additions & 4 deletions base/timing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,8 @@ function gc_page_utilization_data()
return Base.unsafe_wrap(Array, page_utilization_raw, JL_GC_N_MAX_POOLS, own=false)
end


const USING_STOCK_GC = occursin("stock", unsafe_string(ccall(:jl_gc_active_impl, Ptr{UInt8}, ())))
# Full sweep reasons are currently only available for the stock GC
@static if USING_STOCK_GC
@static if Base.USING_STOCK_GC
# must be kept in sync with `src/gc-stock.h``
const FULL_SWEEP_REASONS = [:FULL_SWEEP_REASON_SWEEP_ALWAYS_FULL, :FULL_SWEEP_REASON_FORCED_FULL_SWEEP,
:FULL_SWEEP_REASON_USER_MAX_EXCEEDED, :FULL_SWEEP_REASON_LARGE_PROMOTION_RATE]
Expand All @@ -135,7 +133,7 @@ function full_sweep_reasons()
d = Dict{Symbol, Int64}()
# populate the dictionary according to the reasons above for the stock GC
# otherwise return an empty dictionary for now
@static if USING_STOCK_GC
@static if Base.USING_STOCK_GC
reason = cglobal(:jl_full_sweep_reasons, UInt64)
reasons_as_array = Base.unsafe_wrap(Vector{UInt64}, reason, length(FULL_SWEEP_REASONS), own=false)
for (i, r) in enumerate(FULL_SWEEP_REASONS)
Expand Down
41 changes: 25 additions & 16 deletions stdlib/Profile/test/allocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,12 @@ end
@test length(first_alloc.stacktrace) > 0
@test length(string(first_alloc.type)) > 0

@testset for type in (Task, Vector{Float64},)
@test length(filter(a->a.type <: type, profile.allocs)) >= NUM_TASKS
# This test does not work with MMTk because of fastpath allocation
# which never calls the allocation profiler.
if Base.USING_STOCK_GC
@testset for type in (Task, Vector{Float64},)
@test length(filter(a->a.type <: type, profile.allocs)) >= NUM_TASKS
end
end

# TODO: it would be nice to assert that these tasks
Expand Down Expand Up @@ -143,24 +147,29 @@ end
@test length([a for a in prof.allocs if a.type == String]) >= 1
end

# FIXME: We currently do not call the allocation profiler
# in the fastpath allocation for MMTk in codegen. Therefore, this
# test has been disabled for MMTk.
@testset "alloc profiler catches allocs from codegen" begin
@eval begin
struct MyType x::Int; y::Int end
Base.:(+)(n::Number, x::MyType) = n + x.x + x.y
foo(a, x) = a[1] + x
wrapper(a) = foo(a, MyType(0,1))
end
a = Any[1,2,3]
# warmup
wrapper(a)
if Base.USING_STOCK_GC
@eval begin
struct MyType x::Int; y::Int end
Base.:(+)(n::Number, x::MyType) = n + x.x + x.y
foo(a, x) = a[1] + x
wrapper(a) = foo(a, MyType(0,1))
end
a = Any[1,2,3]
# warmup
wrapper(a)

@eval Allocs.@profile sample_rate=1 wrapper($a)
@eval Allocs.@profile sample_rate=1 wrapper($a)

prof = Allocs.fetch()
Allocs.clear()
prof = Allocs.fetch()
Allocs.clear()

@test length(prof.allocs) >= 1
@test length([a for a in prof.allocs if a.type == MyType]) >= 1
@test length(prof.allocs) >= 1
@test length([a for a in prof.allocs if a.type == MyType]) >= 1
end
end

@testset "alloc profiler catches allocs from buffer resize" begin
Expand Down
44 changes: 24 additions & 20 deletions stdlib/Profile/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -344,35 +344,39 @@ end
@test only(node.down).first == lidict[8]
end

# FIXME: This test that expects specific information from
# heap snapshots, which is currently supported in MMTk
@testset "HeapSnapshot" begin
tmpdir = mktempdir()
if Base.USING_STOCK_GC
tmpdir = mktempdir()

# ensure that we can prevent redacting data
fname = cd(tmpdir) do
read(`$(Base.julia_cmd()) --startup-file=no -e "using Profile; const x = \"redact_this\"; print(Profile.take_heap_snapshot(; redact_data=false))"`, String)
end
# ensure that we can prevent redacting data
fname = cd(tmpdir) do
read(`$(Base.julia_cmd()) --startup-file=no -e "using Profile; const x = \"redact_this\"; print(Profile.take_heap_snapshot(; redact_data=false))"`, String)
end

@test isfile(fname)
@test isfile(fname)

sshot = read(fname, String)
@test sshot != ""
@test contains(sshot, "redact_this")
sshot = read(fname, String)
@test sshot != ""
@test contains(sshot, "redact_this")

rm(fname)
rm(fname)

# ensure that string data is redacted by default
fname = cd(tmpdir) do
read(`$(Base.julia_cmd()) --startup-file=no -e "using Profile; const x = \"redact_this\"; print(Profile.take_heap_snapshot())"`, String)
end
# ensure that string data is redacted by default
fname = cd(tmpdir) do
read(`$(Base.julia_cmd()) --startup-file=no -e "using Profile; const x = \"redact_this\"; print(Profile.take_heap_snapshot())"`, String)
end

@test isfile(fname)
@test isfile(fname)

sshot = read(fname, String)
@test sshot != ""
@test !contains(sshot, "redact_this")
sshot = read(fname, String)
@test sshot != ""
@test !contains(sshot, "redact_this")

rm(fname)
rm(tmpdir, force = true, recursive = true)
rm(fname)
rm(tmpdir, force = true, recursive = true)
end
end

@testset "PageProfile" begin
Expand Down
79 changes: 44 additions & 35 deletions test/cmdlineargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -383,29 +383,33 @@ let exename = `$(Base.julia_cmd()) --startup-file=no --color=no`
@test p.exitcode == 1 && p.termsignal == 0
end

# --gcthreads
code = "print(Threads.ngcthreads())"
cpu_threads = ccall(:jl_effective_threads, Int32, ())
@test string(cpu_threads) ==
read(`$exename --threads auto -e $code`, String) ==
read(`$exename --threads=auto -e $code`, String) ==
read(`$exename -tauto -e $code`, String) ==
read(`$exename -t auto -e $code`, String)
for nt in (nothing, "1")
withenv("JULIA_NUM_GC_THREADS" => nt) do
@test read(`$exename --gcthreads=2 -e $code`, String) == "2"
end
withenv("JULIA_NUM_GC_THREADS" => nt) do
@test read(`$exename --gcthreads=2,1 -e $code`, String) == "3"
# FIXME: --gc-threads does not have the same semantics
# for Stock GC and MMTk, so the tests below are specific to the Stock GC
if Base.USING_STOCK_GC
# --gcthreads
code = "print(Threads.ngcthreads())"
cpu_threads = ccall(:jl_effective_threads, Int32, ())
@test string(cpu_threads) ==
read(`$exename --threads auto -e $code`, String) ==
read(`$exename --threads=auto -e $code`, String) ==
read(`$exename -tauto -e $code`, String) ==
read(`$exename -t auto -e $code`, String)
for nt in (nothing, "1")
withenv("JULIA_NUM_GC_THREADS" => nt) do
@test read(`$exename --gcthreads=2 -e $code`, String) == "2"
end
withenv("JULIA_NUM_GC_THREADS" => nt) do
@test read(`$exename --gcthreads=2,1 -e $code`, String) == "3"
end
end
end

withenv("JULIA_NUM_GC_THREADS" => 2) do
@test read(`$exename -e $code`, String) == "2"
end
withenv("JULIA_NUM_GC_THREADS" => 2) do
@test read(`$exename -e $code`, String) == "2"
end

withenv("JULIA_NUM_GC_THREADS" => "2,1") do
@test read(`$exename -e $code`, String) == "3"
withenv("JULIA_NUM_GC_THREADS" => "2,1") do
@test read(`$exename -e $code`, String) == "3"
end
end

# --machine-file
Expand Down Expand Up @@ -1182,24 +1186,29 @@ end
end
end

# FIXME: MMTK currently does not use --heap-size-hint since it only
# supports setting up a hard limit unlike the Stock GC
# which takes it as a soft limit. For now, we skip the tests below for MMTk
@testset "heap size hint" begin
#heap-size-hint, we reserve 250 MB for non GC memory (llvm, etc.)
@test readchomp(`$(Base.julia_cmd()) --startup-file=no --heap-size-hint=500M -e "println(@ccall jl_gc_get_max_memory()::UInt64)"`) == "$((500-250)*1024*1024)"
if Base.USING_STOCK_GC
#heap-size-hint, we reserve 250 MB for non GC memory (llvm, etc.)
@test readchomp(`$(Base.julia_cmd()) --startup-file=no --heap-size-hint=500M -e "println(@ccall jl_gc_get_max_memory()::UInt64)"`) == "$((500-250)*1024*1024)"

mem = ccall(:uv_get_total_memory, UInt64, ())
cmem = ccall(:uv_get_constrained_memory, UInt64, ())
if cmem > 0 && cmem < mem
mem = cmem
end
maxmem = parse(UInt64, readchomp(`$(Base.julia_cmd()) --startup-file=no --heap-size-hint=25% -e "println(@ccall jl_gc_get_max_memory()::UInt64)"`))
hint = max(mem÷4, 251*1024*1024) - 250*1024*1024
MAX32HEAP = 1536 * 1024 * 1024
if Int === Int32 && hint > MAX32HEAP
hint = MAX32HEAP
end
@test abs(Float64(maxmem) - hint)/maxmem < 0.05

mem = ccall(:uv_get_total_memory, UInt64, ())
cmem = ccall(:uv_get_constrained_memory, UInt64, ())
if cmem > 0 && cmem < mem
mem = cmem
end
maxmem = parse(UInt64, readchomp(`$(Base.julia_cmd()) --startup-file=no --heap-size-hint=25% -e "println(@ccall jl_gc_get_max_memory()::UInt64)"`))
hint = max(mem÷4, 251*1024*1024) - 250*1024*1024
MAX32HEAP = 1536 * 1024 * 1024
if Int === Int32 && hint > MAX32HEAP
hint = MAX32HEAP
@test readchomp(`$(Base.julia_cmd()) --startup-file=no --heap-size-hint=10M -e "println(@ccall jl_gc_get_max_memory()::UInt64)"`) == "$(1*1024*1024)"
end
@test abs(Float64(maxmem) - hint)/maxmem < 0.05

@test readchomp(`$(Base.julia_cmd()) --startup-file=no --heap-size-hint=10M -e "println(@ccall jl_gc_get_max_memory()::UInt64)"`) == "$(1*1024*1024)"
end

## `Main.main` entrypoint
Expand Down
40 changes: 23 additions & 17 deletions test/gc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ function run_gctest(file)
end

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)
if Base.USING_STOCK_GC
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
end

function run_pg_size_test()
Expand All @@ -35,25 +37,29 @@ function issue_54275_alloc_string()
end

function issue_54275_test()
GC.gc(true)
baseline = Base.gc_live_bytes()
live_bytes_has_grown_too_much = false
for _ in 1:10
issue_54275_alloc_string()
if Base.USING_STOCK_GC
GC.gc(true)
if Base.gc_live_bytes() - baseline > 1_000_000
live_bytes_has_grown_too_much = true
break
baseline = Base.gc_live_bytes()
live_bytes_has_grown_too_much = false
for _ in 1:10
issue_54275_alloc_string()
GC.gc(true)
if Base.gc_live_bytes() - baseline > 1_000_000
live_bytes_has_grown_too_much = true
break
end
end
@test !live_bytes_has_grown_too_much
end
@test !live_bytes_has_grown_too_much
end

function full_sweep_reasons_test()
GC.gc()
reasons = Base.full_sweep_reasons()
@test reasons[:FULL_SWEEP_REASON_FORCED_FULL_SWEEP] >= 1
@test keys(reasons) == Set(Base.FULL_SWEEP_REASONS)
if Base.USING_STOCK_GC
GC.gc()
reasons = Base.full_sweep_reasons()
@test reasons[:FULL_SWEEP_REASON_FORCED_FULL_SWEEP] >= 1
@test keys(reasons) == Set(Base.FULL_SWEEP_REASONS)
end
end

# !!! note:
Expand Down
32 changes: 17 additions & 15 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1453,24 +1453,26 @@ end
@test_throws ErrorException finalizer(x->nothing, 1)
@test_throws ErrorException finalizer(C_NULL, 1)


@testset "GC utilities" begin
GC.gc()
GC.gc(true); GC.gc(false)

GC.safepoint()

mktemp() do tmppath, _
open(tmppath, "w") do tmpio
redirect_stderr(tmpio) do
GC.enable_logging(true)
@test GC.logging_enabled()
GC.gc()
GC.enable_logging(false)
@test !GC.logging_enabled()
# Test is specific to Stock GC
if Base.USING_STOCK_GC
GC.gc()
GC.gc(true); GC.gc(false)

GC.safepoint()

mktemp() do tmppath, _
open(tmppath, "w") do tmpio
redirect_stderr(tmpio) do
GC.enable_logging(true)
@test GC.logging_enabled()
GC.gc()
GC.enable_logging(false)
@test !GC.logging_enabled()
end
end
@test occursin("GC: pause", read(tmppath, String))
end
@test occursin("GC: pause", read(tmppath, String))
end
end

Expand Down

0 comments on commit 833c1b9

Please sign in to comment.