diff --git a/src/gc-interface.h b/src/gc-interface.h index b3029e5da4797..5c64d7b7d367b 100644 --- a/src/gc-interface.h +++ b/src/gc-interface.h @@ -142,8 +142,15 @@ JL_DLLEXPORT void jl_gc_set_max_memory(uint64_t max_mem); JL_DLLEXPORT void jl_gc_collect(jl_gc_collection_t collection); // Returns whether the thread with `tid` is a collector thread JL_DLLEXPORT int gc_is_collector_thread(int tid) JL_NOTSAFEPOINT; +// Enables or disables automatic full (non-generational) collections. +// When disabled (on == 0), automatic collections will only be incremental +// (young generation only). Explicit full collections via jl_gc_collect(JL_GC_FULL) +// are still honored. Returns whether automatic full collections were previously enabled. +JL_DLLEXPORT int jl_gc_enable_auto_full_collection(int on); +// Returns whether automatic full (non-generational) collections are enabled. +JL_DLLEXPORT int jl_gc_auto_full_collection_is_enabled(void); // 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. +// 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 as // each GC should implement it but it will most likely not be used by other code in the runtime. diff --git a/src/gc-mmtk.c b/src/gc-mmtk.c index 7cbc56b1d98e9..28d12cdb25836 100644 --- a/src/gc-mmtk.c +++ b/src/gc-mmtk.c @@ -337,6 +337,18 @@ JL_DLLEXPORT const char* jl_gc_active_impl(void) { return mmtk_version; } +JL_DLLEXPORT int jl_gc_enable_auto_full_collection(int on) +{ + // MMTk does not currently support collection type control + return 1; +} + +JL_DLLEXPORT int jl_gc_auto_full_collection_is_enabled(void) +{ + return 1; +} + + int64_t last_gc_total_bytes = 0; int64_t last_live_bytes = 0; // live_bytes at last collection int64_t live_bytes = 0; diff --git a/src/gc-stock.c b/src/gc-stock.c index 9a62fb0657562..d1171c214086e 100644 --- a/src/gc-stock.c +++ b/src/gc-stock.c @@ -208,6 +208,7 @@ int prev_sweep_full = 1; int current_sweep_full = 0; int next_sweep_full = 0; int under_pressure = 0; +int gc_disable_auto_full_sweep = 0; // when set, automatic full collections are inhibited // Full collection heuristics static int64_t live_bytes = 0; @@ -3177,6 +3178,9 @@ static int _jl_gc_collect(jl_ptls_t ptls, jl_gc_collection_t collection) JL_NOTS recollect = 1; gc_record_full_sweep_reason(FULL_SWEEP_REASON_FORCED_FULL_SWEEP); } + if (gc_disable_auto_full_sweep && collection != JL_GC_FULL) { + sweep_full = 0; + } // 5. start sweeping uint64_t start_sweep_time = jl_hrtime(); JL_PROBE_GC_SWEEP_BEGIN(sweep_full); @@ -4151,6 +4155,18 @@ JL_DLLEXPORT const char* jl_gc_active_impl(void) { return "Built with stock GC"; } +JL_DLLEXPORT int jl_gc_enable_auto_full_collection(int on) +{ + int prev = !gc_disable_auto_full_sweep; + gc_disable_auto_full_sweep = (on == 0); + return prev; +} + +JL_DLLEXPORT int jl_gc_auto_full_collection_is_enabled(void) +{ + return !gc_disable_auto_full_sweep; +} + #ifdef __cplusplus } #endif