diff --git a/base/timing.jl b/base/timing.jl index 1de3727756829..3e3cce22155fb 100644 --- a/base/timing.jl +++ b/base/timing.jl @@ -106,9 +106,12 @@ function gc_page_utilization_data() return Base.unsafe_wrap(Array, page_utilization_raw, JL_GC_N_MAX_POOLS, own=false) end +# Full sweep reasons are currently only available for the stock GC +@static if occursin("stock", unsafe_string(ccall(:jl_gc_active_impl, Ptr{UInt8}, ()))) # 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] +end """ Base.full_sweep_reasons() @@ -124,11 +127,15 @@ The reasons are: Note that the set of reasons is not guaranteed to be stable across minor versions of Julia. """ function full_sweep_reasons() - reason = cglobal(:jl_full_sweep_reasons, UInt64) - reasons_as_array = Base.unsafe_wrap(Vector{UInt64}, reason, length(FULL_SWEEP_REASONS), own=false) d = Dict{Symbol, Int64}() - for (i, r) in enumerate(FULL_SWEEP_REASONS) - d[r] = reasons_as_array[i] + # populate the dictionary according to the reasons above for the stock GC + # otherwise return an empty dictionary for now + @static if occursin("stock", unsafe_string(ccall(:jl_gc_active_impl, Ptr{UInt8}, ()))) + 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) + d[r] = reasons_as_array[i] + end end return d end diff --git a/src/gc-interface.h b/src/gc-interface.h index 4a0d144295fbe..e4a27782f7520 100644 --- a/src/gc-interface.h +++ b/src/gc-interface.h @@ -101,8 +101,8 @@ JL_DLLEXPORT int gc_is_collector_thread(int tid) JL_NOTSAFEPOINT; // Returns which GC implementation is being used and possibly its version according to the list of supported GCs // NB: it should clearly identify the GC by including e.g. ‘stock’ or ‘mmtk’ as a substring. JL_DLLEXPORT const char* jl_gc_active_impl(void); -// Sweep Julia's stack pools and mtarray buffers. Note that this function has been added to the interface since -// each GC should implement this but this function will most likely not be used by other code in the runtime. +// Sweep Julia's stack pools and mtarray buffers. Note that this function has been added to the interface as +// each GC should implement it but it will most likely not be used by other code in the runtime. // It still needs to be annotated with JL_DLLEXPORT since it is called from Rust by MMTk. JL_DLLEXPORT void jl_gc_sweep_stack_pools_and_mtarraylist_buffers(jl_ptls_t ptls) JL_NOTSAFEPOINT; @@ -145,7 +145,6 @@ JL_DLLEXPORT uint64_t jl_gc_total_hrtime(void); // **must** also set the type of the returning object to be `ty`. The type `ty` may also be used to record // an allocation of that type in the allocation profiler. struct _jl_value_t *jl_gc_alloc_(struct _jl_tls_states_t * ptls, size_t sz, void *ty); - // Allocates small objects and increments Julia allocation counterst. Size of the object // header must be included in the object size. The (possibly unused in some implementations) // offset to the arena in which we're allocating is passed in the second parameter, and the @@ -205,7 +204,6 @@ JL_DLLEXPORT void *jl_gc_perm_alloc(size_t sz, int zero, unsigned align, // the allocated object. All objects stored in fields of this object // must be either permanently allocated or have other roots. struct _jl_value_t *jl_gc_permobj(size_t sz, void *ty) JL_NOTSAFEPOINT; - // This function notifies the GC about memory addresses that are set when loading the boot image. // The GC may use that information to, for instance, determine that such objects should // be treated as marked and belonged to the old generation in nursery collections. diff --git a/src/gc-mmtk.c b/src/gc-mmtk.c index 36ef4aebcc182..b0fe4341eba8b 100644 --- a/src/gc-mmtk.c +++ b/src/gc-mmtk.c @@ -1,4 +1,5 @@ #include "gc-common.h" +#include "gc-tls-mmtk.h" #include "mmtkMutator.h" #include "threading.h" @@ -17,19 +18,6 @@ extern jl_value_t *cmpswap_names JL_GLOBALLY_ROOTED; extern const unsigned pool_sizes[]; extern jl_mutex_t finalizers_lock; -// FIXME: Does it make sense for MMTk to implement something similar -// for now, just ignoring this. - -// Must be kept in sync with `base/timing.jl` -#define FULL_SWEEP_REASON_SWEEP_ALWAYS_FULL (0) -#define FULL_SWEEP_REASON_FORCED_FULL_SWEEP (1) -#define FULL_SWEEP_REASON_USER_MAX_EXCEEDED (2) -#define FULL_SWEEP_REASON_LARGE_PROMOTION_RATE (3) -#define FULL_SWEEP_NUM_REASONS (4) - -// Table recording number of full GCs due to each reason -JL_DLLEXPORT uint64_t jl_full_sweep_reasons[FULL_SWEEP_NUM_REASONS]; - // FIXME: Should the values below be shared between both GC's? // Note that MMTk uses a hard max heap limit, which is set by default // as 70% of the free available memory. The min heap is set as the diff --git a/src/gc-tls-mmtk.h b/src/gc-tls-mmtk.h index 01791345b6984..5b69aef5d55fb 100644 --- a/src/gc-tls-mmtk.h +++ b/src/gc-tls-mmtk.h @@ -1,7 +1,11 @@ // This file is a part of Julia. License is MIT: https://julialang.org/license +#ifndef JL_GC_TLS_H +#define JL_GC_TLS_H + #include #include "mmtkMutator.h" +#include "julia_atomics.h" #ifdef __cplusplus extern "C" { @@ -9,9 +13,11 @@ extern "C" { typedef struct { MMTkMutatorContext mmtk_mutator; - size_t malloc_sz_since_last_poll; + _Atomic(size_t) malloc_sz_since_last_poll; } jl_gc_tls_states_t; #ifdef __cplusplus } #endif + +#endif // JL_GC_TLS_H