Skip to content

Commit 899d2f5

Browse files
authored
Skip some stock GC-specific tests when using MMTk (JuliaLang#57104)
As noted in JuliaLang#57103, there are a few tests that are specific to the stock GC and will fail for MMTk. For now, this PR simply skips those tests when not using the stock GC until we agree on how to approach the incompatibilities described in the issue.
1 parent bcddc65 commit 899d2f5

File tree

9 files changed

+75
-33
lines changed

9 files changed

+75
-33
lines changed

base/Base.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ include("sysinfo.jl")
128128
include("libc.jl")
129129
using .Libc: getpid, gethostname, time, memcpy, memset, memmove, memcmp
130130

131+
const USING_STOCK_GC = occursin("stock", GC.gc_active_impl())
132+
131133
# These used to be in build_h.jl and are retained for backwards compatibility.
132134
# NOTE: keep in sync with `libblastrampoline_jll.libblastrampoline`.
133135
const libblas_name = "libblastrampoline" * (Sys.iswindows() ? "-5" : "")

base/gcutils.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,4 +281,15 @@ function logging_enabled()
281281
ccall(:jl_is_gc_logging_enabled, Cint, ()) != 0
282282
end
283283

284+
"""
285+
GC.gc_active_impl()
286+
287+
Return a string stating which GC implementation is being used and possibly
288+
its version according to the list of supported GCs
289+
"""
290+
function gc_active_impl()
291+
unsafe_string(ccall(:jl_gc_active_impl, Ptr{UInt8}, ()))
292+
end
293+
294+
284295
end # module GC

base/timing.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,8 @@ function gc_page_utilization_data()
109109
return Base.unsafe_wrap(Array, page_utilization_raw, JL_GC_N_MAX_POOLS, own=false)
110110
end
111111

112-
113-
const USING_STOCK_GC = occursin("stock", unsafe_string(ccall(:jl_gc_active_impl, Ptr{UInt8}, ())))
114112
# Full sweep reasons are currently only available for the stock GC
115-
@static if USING_STOCK_GC
113+
@static if Base.USING_STOCK_GC
116114
# must be kept in sync with `src/gc-stock.h``
117115
const FULL_SWEEP_REASONS = [:FULL_SWEEP_REASON_SWEEP_ALWAYS_FULL, :FULL_SWEEP_REASON_FORCED_FULL_SWEEP,
118116
:FULL_SWEEP_REASON_USER_MAX_EXCEEDED, :FULL_SWEEP_REASON_LARGE_PROMOTION_RATE]
@@ -135,7 +133,7 @@ function full_sweep_reasons()
135133
d = Dict{Symbol, Int64}()
136134
# populate the dictionary according to the reasons above for the stock GC
137135
# otherwise return an empty dictionary for now
138-
@static if USING_STOCK_GC
136+
@static if Base.USING_STOCK_GC
139137
reason = cglobal(:jl_full_sweep_reasons, UInt64)
140138
reasons_as_array = Base.unsafe_wrap(Vector{UInt64}, reason, length(FULL_SWEEP_REASONS), own=false)
141139
for (i, r) in enumerate(FULL_SWEEP_REASONS)

stdlib/Profile/test/allocs.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,14 @@ end
7373
@test length(first_alloc.stacktrace) > 0
7474
@test length(string(first_alloc.type)) > 0
7575

76-
@testset for type in (Task, Vector{Float64},)
77-
@test length(filter(a->a.type <: type, profile.allocs)) >= NUM_TASKS
76+
# Issue #57103: This test does not work with MMTk because of fastpath
77+
# allocation which never calls the allocation profiler.
78+
# TODO: We should port these observability tools (e.g. allocation
79+
# profiler and heap snapshot) to MMTk
80+
@static if Base.USING_STOCK_GC
81+
@testset for type in (Task, Vector{Float64},)
82+
@test length(filter(a->a.type <: type, profile.allocs)) >= NUM_TASKS
83+
end
7884
end
7985

8086
# TODO: it would be nice to assert that these tasks
@@ -143,6 +149,8 @@ end
143149
@test length([a for a in prof.allocs if a.type == String]) >= 1
144150
end
145151

152+
# FIXME: Issue #57103 disabling test for MMTk.
153+
@static if Base.USING_STOCK_GC
146154
@testset "alloc profiler catches allocs from codegen" begin
147155
@eval begin
148156
struct MyType x::Int; y::Int end
@@ -162,6 +170,7 @@ end
162170
@test length(prof.allocs) >= 1
163171
@test length([a for a in prof.allocs if a.type == MyType]) >= 1
164172
end
173+
end
165174

166175
@testset "alloc profiler catches allocs from buffer resize" begin
167176
f(a) = for _ in 1:100; push!(a, 1); end

stdlib/Profile/test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ end
344344
@test only(node.down).first == lidict[8]
345345
end
346346

347+
# FIXME: Issue #57103: heap snapshots are currently not supported in MMTk
348+
@static if Base.USING_STOCK_GC
347349
@testset "HeapSnapshot" begin
348350
tmpdir = mktempdir()
349351

@@ -374,6 +376,7 @@ end
374376
rm(fname)
375377
rm(tmpdir, force = true, recursive = true)
376378
end
379+
end
377380

378381
@testset "PageProfile" begin
379382
fname = "$(getpid())_$(time_ns())"

test/checked.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,12 @@ end
331331
@test checked_pow(BigInt(2), 2) == BigInt(4)
332332
@test checked_pow(BigInt(2), 100) == BigInt(1267650600228229401496703205376)
333333

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

338342
@testset "Additional tests" begin

test/cmdlineargs.jl

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -383,29 +383,33 @@ let exename = `$(Base.julia_cmd()) --startup-file=no --color=no`
383383
@test p.exitcode == 1 && p.termsignal == 0
384384
end
385385

386-
# --gcthreads
387-
code = "print(Threads.ngcthreads())"
388-
cpu_threads = ccall(:jl_effective_threads, Int32, ())
389-
@test string(cpu_threads) ==
390-
read(`$exename --threads auto -e $code`, String) ==
391-
read(`$exename --threads=auto -e $code`, String) ==
392-
read(`$exename -tauto -e $code`, String) ==
393-
read(`$exename -t auto -e $code`, String)
394-
for nt in (nothing, "1")
395-
withenv("JULIA_NUM_GC_THREADS" => nt) do
396-
@test read(`$exename --gcthreads=2 -e $code`, String) == "2"
397-
end
398-
withenv("JULIA_NUM_GC_THREADS" => nt) do
399-
@test read(`$exename --gcthreads=2,1 -e $code`, String) == "3"
386+
# FIXME: Issue #57103 --gcthreads does not have the same semantics
387+
# for Stock GC and MMTk, so the tests below are specific to the Stock GC
388+
@static if Base.USING_STOCK_GC
389+
# --gcthreads
390+
code = "print(Threads.ngcthreads())"
391+
cpu_threads = ccall(:jl_effective_threads, Int32, ())
392+
@test string(cpu_threads) ==
393+
read(`$exename --threads auto -e $code`, String) ==
394+
read(`$exename --threads=auto -e $code`, String) ==
395+
read(`$exename -tauto -e $code`, String) ==
396+
read(`$exename -t auto -e $code`, String)
397+
for nt in (nothing, "1")
398+
withenv("JULIA_NUM_GC_THREADS" => nt) do
399+
@test read(`$exename --gcthreads=2 -e $code`, String) == "2"
400+
end
401+
withenv("JULIA_NUM_GC_THREADS" => nt) do
402+
@test read(`$exename --gcthreads=2,1 -e $code`, String) == "3"
403+
end
400404
end
401-
end
402405

403-
withenv("JULIA_NUM_GC_THREADS" => 2) do
404-
@test read(`$exename -e $code`, String) == "2"
405-
end
406+
withenv("JULIA_NUM_GC_THREADS" => 2) do
407+
@test read(`$exename -e $code`, String) == "2"
408+
end
406409

407-
withenv("JULIA_NUM_GC_THREADS" => "2,1") do
408-
@test read(`$exename -e $code`, String) == "3"
410+
withenv("JULIA_NUM_GC_THREADS" => "2,1") do
411+
@test read(`$exename -e $code`, String) == "3"
412+
end
409413
end
410414

411415
# --machine-file
@@ -1182,6 +1186,10 @@ end
11821186
end
11831187
end
11841188

1189+
# FIXME: Issue #57103: MMTK currently does not use --heap-size-hint since it only
1190+
# supports setting up a hard limit unlike the Stock GC
1191+
# which takes it as a soft limit. For now, we skip the tests below for MMTk
1192+
@static if Base.USING_STOCK_GC
11851193
@testset "heap size hint" begin
11861194
#heap-size-hint, we reserve 250 MB for non GC memory (llvm, etc.)
11871195
@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)"
@@ -1201,6 +1209,7 @@ end
12011209

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

12051214
## `Main.main` entrypoint
12061215

test/gc.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ end
6767
run_gctest("gc/chunks.jl")
6868
end
6969

70+
#FIXME: Issue #57103 disabling tests for MMTk, since
71+
# they rely on information that is specific to the stock GC.
72+
@static if Base.USING_STOCK_GC
7073
@testset "GC page metrics" begin
7174
run_nonzero_page_utilization_test()
7275
run_pg_size_test()
@@ -76,13 +79,14 @@ end
7679
issue_54275_test()
7780
end
7881

79-
@testset "Base.GC docstrings" begin
80-
@test isempty(Docs.undocumented_names(GC))
81-
end
82-
8382
@testset "Full GC reasons" begin
8483
full_sweep_reasons_test()
8584
end
85+
end
86+
87+
@testset "Base.GC docstrings" begin
88+
@test isempty(Docs.undocumented_names(GC))
89+
end
8690

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

test/misc.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,8 @@ end
14531453
@test_throws ErrorException finalizer(x->nothing, 1)
14541454
@test_throws ErrorException finalizer(C_NULL, 1)
14551455

1456-
1456+
# FIXME: Issue #57103 Test is specific to Stock GC
1457+
@static if Base.USING_STOCK_GC
14571458
@testset "GC utilities" begin
14581459
GC.gc()
14591460
GC.gc(true); GC.gc(false)
@@ -1473,6 +1474,7 @@ end
14731474
@test occursin("GC: pause", read(tmppath, String))
14741475
end
14751476
end
1477+
end
14761478

14771479
@testset "fieldtypes Module" begin
14781480
@test fieldtypes(Module) === ()

0 commit comments

Comments
 (0)