@@ -107,6 +107,39 @@ function gc_page_utilization_data()
107107 return Base. unsafe_wrap (Array, page_utilization_raw, JL_GC_N_MAX_POOLS, own= false )
108108end
109109
110+ # must be kept in sync with `src/gc.h``
111+ const FULL_SWEEP_REASONS = [:FULL_SWEEP_REASON_SWEEP_ALWAYS_FULL , :FULL_SWEEP_REASON_FORCED_FULL_SWEEP ,
112+ :FULL_SWEEP_REASON_ALLOCATION_INTERVAL_ABOVE_MAXMEM , :FULL_SWEEP_REASON_LIVE_BYTES_ABOVE_MAX_TOTAL_MEMORY ,
113+ :FULL_SWEEP_REASON_LARGE_INTERGEN_FRONTIER ]
114+
115+ """
116+ Base.full_sweep_reasons()
117+
118+ Return a dictionary of the number of times each full sweep reason has occurred.
119+
120+ The reasons are:
121+ - `:FULL_SWEEP_REASON_SWEEP_ALWAYS_FULL`: Full sweep was caused due to `always_full` being set in the GC debug environment
122+ - `:FULL_SWEEP_REASON_FORCED_FULL_SWEEP`: Full sweep was forced by `GC.gc(true)`
123+ - `:FULL_SWEEP_REASON_ALLOCATION_INTERVAL_ABOVE_MAXMEM`: Full sweep was forced by the allocation interval being above the total
124+ memory in the machine (as returned by LibUV) divided by the number of mutator threads
125+ - `:FULL_SWEEP_REASON_LIVE_BYTES_ABOVE_MAX_TOTAL_MEMORY`: Full sweep was caused due to live bytes being above the
126+ soft heap limit size (which is either automatically computed at initialization based on the total memory provided by LibUV,
127+ or set by the user via `--heap-size-hint`)
128+ - `:FULL_SWEEP_REASON_LARGE_INTERGEN_FRONTIER`: Full sweep was forced by the intergenerational frontier being too large
129+ (i.e. too many pointers in the remembered set)
130+
131+ Note that the set of reasons is not guaranteed to be stable across minor versions of Julia.
132+ """
133+ function full_sweep_reasons ()
134+ reason = cglobal (:jl_full_sweep_reasons , UInt64)
135+ reasons_as_array = Base. unsafe_wrap (Vector{UInt64}, reason, length (FULL_SWEEP_REASONS), own= false )
136+ d = Dict {Symbol, Int64} ()
137+ for (i, r) in enumerate (FULL_SWEEP_REASONS)
138+ d[r] = reasons_as_array[i]
139+ end
140+ return d
141+ end
142+
110143"""
111144 Base.jit_total_bytes()
112145
0 commit comments