@@ -25,10 +25,12 @@ _Atomic(int) gc_master_tid;
2525uv_mutex_t gc_threads_lock ;
2626uv_cond_t gc_threads_cond ;
2727
28+ #ifdef GC_FIXED_HEAP
2829// Globally allocated bytes by malloc - used for fixed heap size
2930_Atomic(uint64_t ) malloc_bytes ;
3031// Globally allocated pool pages - used for fixed heap size
3132extern uint64_t jl_current_pg_count (void );
33+ #endif
3234
3335// Linked list of callback functions
3436
@@ -580,6 +582,7 @@ void gc_setmark_buf(jl_ptls_t ptls, void *o, uint8_t mark_mode, size_t minsz) JL
580582
581583inline void maybe_collect (jl_ptls_t ptls )
582584{
585+ #ifdef GC_FIXED_HEAP
583586 if (jl_options .fixed_heap_size ) {
584587 uint64_t current_heap_size = ((uint64_t )jl_current_pg_count ()) << (uint64_t )14 ;
585588 current_heap_size += jl_atomic_load_relaxed (& malloc_bytes );
@@ -588,13 +591,14 @@ inline void maybe_collect(jl_ptls_t ptls)
588591 } else {
589592 jl_gc_safepoint_ (ptls );
590593 }
591- } else {
592- if (jl_atomic_load_relaxed (& ptls -> gc_num .allocd ) >= 0 || jl_gc_debug_check_other ()) {
593- jl_gc_collect (JL_GC_AUTO );
594- }
595- else {
596- jl_gc_safepoint_ (ptls );
597- }
594+ return ;
595+ }
596+ #endif
597+ if (jl_atomic_load_relaxed (& ptls -> gc_num .allocd ) >= 0 || jl_gc_debug_check_other ()) {
598+ jl_gc_collect (JL_GC_AUTO );
599+ }
600+ else {
601+ jl_gc_safepoint_ (ptls );
598602 }
599603}
600604
@@ -2848,12 +2852,14 @@ static int _jl_gc_collect(jl_ptls_t ptls, jl_gc_collection_t collection)
28482852 }
28492853 }
28502854
2855+ #ifdef GC_FIXED_HEAP
28512856 if (jl_options .fixed_heap_size ) {
28522857 uint64_t current_heap_size = ((uint64_t )jl_current_pg_count ()) << ((uint64_t )14 );
28532858 if (current_heap_size > (jl_options .fixed_heap_size * 4 / 5 )) {
28542859 next_sweep_full = 1 ;
28552860 }
28562861 }
2862+ #endif
28572863
28582864 gc_time_summary (sweep_full , t_start , gc_end_time , gc_num .freed ,
28592865 live_bytes , gc_num .interval , pause ,
@@ -3061,10 +3067,12 @@ void jl_gc_init(void)
30613067 if (jl_options .heap_size_hint )
30623068 jl_gc_set_max_memory (jl_options .heap_size_hint );
30633069
3070+ #ifdef GC_FIXED_HEAP
30643071 if (jl_options .fixed_heap_size ) {
30653072 // This guarantees that we will not trigger a GC before reaching heap limit
30663073 gc_num .interval = jl_options .fixed_heap_size ;
30673074 }
3075+ #endif
30683076
30693077 t_start = jl_hrtime ();
30703078}
@@ -3082,7 +3090,9 @@ JL_DLLEXPORT void *jl_gc_counted_malloc(size_t sz)
30823090 jl_atomic_load_relaxed (& ptls -> gc_num .allocd ) + sz );
30833091 jl_atomic_store_relaxed (& ptls -> gc_num .malloc ,
30843092 jl_atomic_load_relaxed (& ptls -> gc_num .malloc ) + 1 );
3093+ #ifdef GC_FIXED_HEAP
30853094 jl_atomic_fetch_add_relaxed (& malloc_bytes , sz );
3095+ #endif
30863096 }
30873097 return malloc (sz );
30883098}
@@ -3098,7 +3108,9 @@ JL_DLLEXPORT void *jl_gc_counted_calloc(size_t nm, size_t sz)
30983108 jl_atomic_load_relaxed (& ptls -> gc_num .allocd ) + nm * sz );
30993109 jl_atomic_store_relaxed (& ptls -> gc_num .malloc ,
31003110 jl_atomic_load_relaxed (& ptls -> gc_num .malloc ) + 1 );
3111+ #ifdef GC_FIXED_HEAP
31013112 jl_atomic_fetch_add_relaxed (& malloc_bytes , nm * sz );
3113+ #endif
31023114 }
31033115 return calloc (nm , sz );
31043116}
@@ -3114,7 +3126,9 @@ JL_DLLEXPORT void jl_gc_counted_free_with_size(void *p, size_t sz)
31143126 jl_atomic_load_relaxed (& ptls -> gc_num .freed ) + sz );
31153127 jl_atomic_store_relaxed (& ptls -> gc_num .freecall ,
31163128 jl_atomic_load_relaxed (& ptls -> gc_num .freecall ) + 1 );
3129+ #ifdef GC_FIXED_HEAP
31173130 jl_atomic_fetch_add_relaxed (& malloc_bytes , - sz );
3131+ #endif
31183132 }
31193133}
31203134
@@ -3128,11 +3142,15 @@ JL_DLLEXPORT void *jl_gc_counted_realloc_with_old_size(void *p, size_t old, size
31283142 if (sz < old ) {
31293143 jl_atomic_store_relaxed (& ptls -> gc_num .freed ,
31303144 jl_atomic_load_relaxed (& ptls -> gc_num .freed ) + (old - sz ));
3145+ #ifdef GC_FIXED_HEAP
31313146 jl_atomic_fetch_add_relaxed (& malloc_bytes , old - sz );
3147+ #endif
31323148 } else {
31333149 jl_atomic_store_relaxed (& ptls -> gc_num .allocd ,
31343150 jl_atomic_load_relaxed (& ptls -> gc_num .allocd ) + (sz - old ));
3151+ #ifdef GC_FIXED_HEAP
31353152 jl_atomic_fetch_add_relaxed (& malloc_bytes , sz - old );
3153+ #endif
31363154 }
31373155 jl_atomic_store_relaxed (& ptls -> gc_num .realloc ,
31383156 jl_atomic_load_relaxed (& ptls -> gc_num .realloc ) + 1 );
0 commit comments