@@ -42,6 +42,8 @@ static jl_gc_callback_list_t *gc_cblist_pre_gc;
42
42
static jl_gc_callback_list_t * gc_cblist_post_gc ;
43
43
static jl_gc_callback_list_t * gc_cblist_notify_external_alloc ;
44
44
static jl_gc_callback_list_t * gc_cblist_notify_external_free ;
45
+ static jl_gc_callback_list_t * gc_cblist_notify_gc_pressure ;
46
+ typedef void (* jl_gc_cb_notify_gc_pressure_t )(void );
45
47
46
48
#define gc_invoke_callbacks (ty , list , args ) \
47
49
do { \
@@ -128,6 +130,14 @@ JL_DLLEXPORT void jl_gc_set_cb_notify_external_free(jl_gc_cb_notify_external_fre
128
130
jl_gc_deregister_callback (& gc_cblist_notify_external_free , (jl_gc_cb_func_t )cb );
129
131
}
130
132
133
+ JL_DLLEXPORT void jl_gc_set_cb_notify_gc_pressure (jl_gc_cb_notify_gc_pressure_t cb , int enable )
134
+ {
135
+ if (enable )
136
+ jl_gc_register_callback (& gc_cblist_notify_gc_pressure , (jl_gc_cb_func_t )cb );
137
+ else
138
+ jl_gc_deregister_callback (& gc_cblist_notify_gc_pressure , (jl_gc_cb_func_t )cb );
139
+ }
140
+
131
141
// Protect all access to `finalizer_list_marked` and `to_finalize`.
132
142
// For accessing `ptls->finalizers`, the lock is needed if a thread
133
143
// is going to realloc the buffer (of its own list) or accessing the
@@ -739,6 +749,7 @@ static int mark_reset_age = 0;
739
749
static int64_t scanned_bytes ; // young bytes scanned while marking
740
750
static int64_t perm_scanned_bytes ; // old bytes scanned while marking
741
751
int prev_sweep_full = 1 ;
752
+ int under_pressure = 0 ;
742
753
743
754
// Full collection heuristics
744
755
static int64_t live_bytes = 0 ;
@@ -3338,6 +3349,8 @@ static int _jl_gc_collect(jl_ptls_t ptls, jl_gc_collection_t collection)
3338
3349
next_sweep_full = 1 ;
3339
3350
else
3340
3351
next_sweep_full = 0 ;
3352
+ if (heap_size > max_total_memory * 0.8 || thrashing )
3353
+ under_pressure = 1 ;
3341
3354
// sweeping is over
3342
3355
// 7. if it is a quick sweep, put back the remembered objects in queued state
3343
3356
// so that we don't trigger the barrier again on them.
@@ -3487,6 +3500,10 @@ JL_DLLEXPORT void jl_gc_collect(jl_gc_collection_t collection)
3487
3500
3488
3501
gc_invoke_callbacks (jl_gc_cb_post_gc_t ,
3489
3502
gc_cblist_post_gc , (collection ));
3503
+ if (under_pressure )
3504
+ gc_invoke_callbacks (jl_gc_cb_notify_gc_pressure_t ,
3505
+ gc_cblist_notify_gc_pressure , ( ));
3506
+ under_pressure = 0 ;
3490
3507
#ifdef _OS_WINDOWS_
3491
3508
SetLastError (last_error );
3492
3509
#endif
0 commit comments