Skip to content

Commit 833c1b9

Browse files
committed
Skipping some tests that are currently incompatible with MMTk
1 parent f91436e commit 833c1b9

File tree

7 files changed

+137
-107
lines changed

7 files changed

+137
-107
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", unsafe_string(ccall(:jl_gc_active_impl, Ptr{UInt8}, ())))
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/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: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,12 @@ 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+
# This test does not work with MMTk because of fastpath allocation
77+
# which never calls the allocation profiler.
78+
if Base.USING_STOCK_GC
79+
@testset for type in (Task, Vector{Float64},)
80+
@test length(filter(a->a.type <: type, profile.allocs)) >= NUM_TASKS
81+
end
7882
end
7983

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

150+
# FIXME: We currently do not call the allocation profiler
151+
# in the fastpath allocation for MMTk in codegen. Therefore, this
152+
# test has been disabled for MMTk.
146153
@testset "alloc profiler catches allocs from codegen" begin
147-
@eval begin
148-
struct MyType x::Int; y::Int end
149-
Base.:(+)(n::Number, x::MyType) = n + x.x + x.y
150-
foo(a, x) = a[1] + x
151-
wrapper(a) = foo(a, MyType(0,1))
152-
end
153-
a = Any[1,2,3]
154-
# warmup
155-
wrapper(a)
154+
if Base.USING_STOCK_GC
155+
@eval begin
156+
struct MyType x::Int; y::Int end
157+
Base.:(+)(n::Number, x::MyType) = n + x.x + x.y
158+
foo(a, x) = a[1] + x
159+
wrapper(a) = foo(a, MyType(0,1))
160+
end
161+
a = Any[1,2,3]
162+
# warmup
163+
wrapper(a)
156164

157-
@eval Allocs.@profile sample_rate=1 wrapper($a)
165+
@eval Allocs.@profile sample_rate=1 wrapper($a)
158166

159-
prof = Allocs.fetch()
160-
Allocs.clear()
167+
prof = Allocs.fetch()
168+
Allocs.clear()
161169

162-
@test length(prof.allocs) >= 1
163-
@test length([a for a in prof.allocs if a.type == MyType]) >= 1
170+
@test length(prof.allocs) >= 1
171+
@test length([a for a in prof.allocs if a.type == MyType]) >= 1
172+
end
164173
end
165174

166175
@testset "alloc profiler catches allocs from buffer resize" begin

stdlib/Profile/test/runtests.jl

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

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

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

355-
@test isfile(fname)
358+
@test isfile(fname)
356359

357-
sshot = read(fname, String)
358-
@test sshot != ""
359-
@test contains(sshot, "redact_this")
360+
sshot = read(fname, String)
361+
@test sshot != ""
362+
@test contains(sshot, "redact_this")
360363

361-
rm(fname)
364+
rm(fname)
362365

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

368-
@test isfile(fname)
371+
@test isfile(fname)
369372

370-
sshot = read(fname, String)
371-
@test sshot != ""
372-
@test !contains(sshot, "redact_this")
373+
sshot = read(fname, String)
374+
@test sshot != ""
375+
@test !contains(sshot, "redact_this")
373376

374-
rm(fname)
375-
rm(tmpdir, force = true, recursive = true)
377+
rm(fname)
378+
rm(tmpdir, force = true, recursive = true)
379+
end
376380
end
377381

378382
@testset "PageProfile" begin

test/cmdlineargs.jl

Lines changed: 44 additions & 35 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: --gc-threads does not have the same semantics
387+
# for Stock GC and MMTk, so the tests below are specific to the Stock GC
388+
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,24 +1186,29 @@ end
11821186
end
11831187
end
11841188

1189+
# FIXME: 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
11851192
@testset "heap size hint" begin
1186-
#heap-size-hint, we reserve 250 MB for non GC memory (llvm, etc.)
1187-
@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)"
1193+
if Base.USING_STOCK_GC
1194+
#heap-size-hint, we reserve 250 MB for non GC memory (llvm, etc.)
1195+
@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)"
1196+
1197+
mem = ccall(:uv_get_total_memory, UInt64, ())
1198+
cmem = ccall(:uv_get_constrained_memory, UInt64, ())
1199+
if cmem > 0 && cmem < mem
1200+
mem = cmem
1201+
end
1202+
maxmem = parse(UInt64, readchomp(`$(Base.julia_cmd()) --startup-file=no --heap-size-hint=25% -e "println(@ccall jl_gc_get_max_memory()::UInt64)"`))
1203+
hint = max(mem÷4, 251*1024*1024) - 250*1024*1024
1204+
MAX32HEAP = 1536 * 1024 * 1024
1205+
if Int === Int32 && hint > MAX32HEAP
1206+
hint = MAX32HEAP
1207+
end
1208+
@test abs(Float64(maxmem) - hint)/maxmem < 0.05
11881209

1189-
mem = ccall(:uv_get_total_memory, UInt64, ())
1190-
cmem = ccall(:uv_get_constrained_memory, UInt64, ())
1191-
if cmem > 0 && cmem < mem
1192-
mem = cmem
1193-
end
1194-
maxmem = parse(UInt64, readchomp(`$(Base.julia_cmd()) --startup-file=no --heap-size-hint=25% -e "println(@ccall jl_gc_get_max_memory()::UInt64)"`))
1195-
hint = max(mem÷4, 251*1024*1024) - 250*1024*1024
1196-
MAX32HEAP = 1536 * 1024 * 1024
1197-
if Int === Int32 && hint > MAX32HEAP
1198-
hint = MAX32HEAP
1210+
@test readchomp(`$(Base.julia_cmd()) --startup-file=no --heap-size-hint=10M -e "println(@ccall jl_gc_get_max_memory()::UInt64)"`) == "$(1*1024*1024)"
11991211
end
1200-
@test abs(Float64(maxmem) - hint)/maxmem < 0.05
1201-
1202-
@test readchomp(`$(Base.julia_cmd()) --startup-file=no --heap-size-hint=10M -e "println(@ccall jl_gc_get_max_memory()::UInt64)"`) == "$(1*1024*1024)"
12031212
end
12041213

12051214
## `Main.main` entrypoint

test/gc.jl

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ function run_gctest(file)
1818
end
1919

2020
function run_nonzero_page_utilization_test()
21-
GC.gc()
22-
page_utilization = Base.gc_page_utilization_data()
23-
# at least one of the pools should have nonzero page_utilization
24-
@test any(page_utilization .> 0)
21+
if Base.USING_STOCK_GC
22+
GC.gc()
23+
page_utilization = Base.gc_page_utilization_data()
24+
# at least one of the pools should have nonzero page_utilization
25+
@test any(page_utilization .> 0)
26+
end
2527
end
2628

2729
function run_pg_size_test()
@@ -35,25 +37,29 @@ function issue_54275_alloc_string()
3537
end
3638

3739
function issue_54275_test()
38-
GC.gc(true)
39-
baseline = Base.gc_live_bytes()
40-
live_bytes_has_grown_too_much = false
41-
for _ in 1:10
42-
issue_54275_alloc_string()
40+
if Base.USING_STOCK_GC
4341
GC.gc(true)
44-
if Base.gc_live_bytes() - baseline > 1_000_000
45-
live_bytes_has_grown_too_much = true
46-
break
42+
baseline = Base.gc_live_bytes()
43+
live_bytes_has_grown_too_much = false
44+
for _ in 1:10
45+
issue_54275_alloc_string()
46+
GC.gc(true)
47+
if Base.gc_live_bytes() - baseline > 1_000_000
48+
live_bytes_has_grown_too_much = true
49+
break
50+
end
4751
end
52+
@test !live_bytes_has_grown_too_much
4853
end
49-
@test !live_bytes_has_grown_too_much
5054
end
5155

5256
function full_sweep_reasons_test()
53-
GC.gc()
54-
reasons = Base.full_sweep_reasons()
55-
@test reasons[:FULL_SWEEP_REASON_FORCED_FULL_SWEEP] >= 1
56-
@test keys(reasons) == Set(Base.FULL_SWEEP_REASONS)
57+
if Base.USING_STOCK_GC
58+
GC.gc()
59+
reasons = Base.full_sweep_reasons()
60+
@test reasons[:FULL_SWEEP_REASON_FORCED_FULL_SWEEP] >= 1
61+
@test keys(reasons) == Set(Base.FULL_SWEEP_REASONS)
62+
end
5763
end
5864

5965
# !!! note:

test/misc.jl

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,24 +1453,26 @@ end
14531453
@test_throws ErrorException finalizer(x->nothing, 1)
14541454
@test_throws ErrorException finalizer(C_NULL, 1)
14551455

1456-
14571456
@testset "GC utilities" begin
1458-
GC.gc()
1459-
GC.gc(true); GC.gc(false)
1460-
1461-
GC.safepoint()
1462-
1463-
mktemp() do tmppath, _
1464-
open(tmppath, "w") do tmpio
1465-
redirect_stderr(tmpio) do
1466-
GC.enable_logging(true)
1467-
@test GC.logging_enabled()
1468-
GC.gc()
1469-
GC.enable_logging(false)
1470-
@test !GC.logging_enabled()
1457+
# Test is specific to Stock GC
1458+
if Base.USING_STOCK_GC
1459+
GC.gc()
1460+
GC.gc(true); GC.gc(false)
1461+
1462+
GC.safepoint()
1463+
1464+
mktemp() do tmppath, _
1465+
open(tmppath, "w") do tmpio
1466+
redirect_stderr(tmpio) do
1467+
GC.enable_logging(true)
1468+
@test GC.logging_enabled()
1469+
GC.gc()
1470+
GC.enable_logging(false)
1471+
@test !GC.logging_enabled()
1472+
end
14711473
end
1474+
@test occursin("GC: pause", read(tmppath, String))
14721475
end
1473-
@test occursin("GC: pause", read(tmppath, String))
14741476
end
14751477
end
14761478

0 commit comments

Comments
 (0)