@@ -26,6 +26,8 @@ static jl_gc_callback_list_t *gc_cblist_pre_gc;
26
26
static jl_gc_callback_list_t * gc_cblist_post_gc ;
27
27
static jl_gc_callback_list_t * gc_cblist_notify_external_alloc ;
28
28
static jl_gc_callback_list_t * gc_cblist_notify_external_free ;
29
+ static jl_gc_callback_list_t * gc_cblist_notify_gc_pressure ;
30
+ typedef void (* jl_gc_cb_notify_gc_pressure_t )(void );
29
31
30
32
#define gc_invoke_callbacks (ty , list , args ) \
31
33
do { \
@@ -112,6 +114,14 @@ JL_DLLEXPORT void jl_gc_set_cb_notify_external_free(jl_gc_cb_notify_external_fre
112
114
jl_gc_deregister_callback (& gc_cblist_notify_external_free , (jl_gc_cb_func_t )cb );
113
115
}
114
116
117
+ JL_DLLEXPORT void jl_gc_set_cb_notify_gc_pressure (jl_gc_cb_notify_gc_pressure_t cb , int enable )
118
+ {
119
+ if (enable )
120
+ jl_gc_register_callback (& gc_cblist_notify_gc_pressure , (jl_gc_cb_func_t )cb );
121
+ else
122
+ jl_gc_deregister_callback (& gc_cblist_notify_gc_pressure , (jl_gc_cb_func_t )cb );
123
+ }
124
+
115
125
// Save/restore local mark stack to/from thread-local storage.
116
126
117
127
STATIC_INLINE void export_gc_state (jl_ptls_t ptls , jl_gc_mark_sp_t * sp ) {
@@ -854,6 +864,7 @@ static int mark_reset_age = 0;
854
864
static int64_t scanned_bytes ; // young bytes scanned while marking
855
865
static int64_t perm_scanned_bytes ; // old bytes scanned while marking
856
866
int prev_sweep_full = 1 ;
867
+ int under_pressure = 0 ;
857
868
858
869
#define inc_sat (v ,s ) v = (v) >= s ? s : (v)+1
859
870
@@ -3600,6 +3611,8 @@ static int _jl_gc_collect(jl_ptls_t ptls, jl_gc_collection_t collection)
3600
3611
next_sweep_full = 1 ;
3601
3612
else
3602
3613
next_sweep_full = 0 ;
3614
+ if (heap_size > max_total_memory * 0.8 || thrashing )
3615
+ under_pressure = 1 ;
3603
3616
// sweeping is over
3604
3617
// 6. if it is a quick sweep, put back the remembered objects in queued state
3605
3618
// so that we don't trigger the barrier again on them.
@@ -3745,6 +3758,10 @@ JL_DLLEXPORT void jl_gc_collect(jl_gc_collection_t collection)
3745
3758
3746
3759
gc_invoke_callbacks (jl_gc_cb_post_gc_t ,
3747
3760
gc_cblist_post_gc , (collection ));
3761
+ if (under_pressure )
3762
+ gc_invoke_callbacks (jl_gc_cb_notify_gc_pressure_t ,
3763
+ gc_cblist_notify_gc_pressure , ( ));
3764
+ under_pressure = 0 ;
3748
3765
#ifdef _OS_WINDOWS_
3749
3766
SetLastError (last_error );
3750
3767
#endif
0 commit comments