@@ -623,10 +623,9 @@ void jl_gc_reset_alloc_count(void) JL_NOTSAFEPOINT
623
623
reset_thread_gc_counts ();
624
624
}
625
625
626
- static void jl_gc_free_memory (jl_value_t * v , int isaligned ) JL_NOTSAFEPOINT
626
+ static void jl_gc_free_memory (jl_genericmemory_t * m , int isaligned ) JL_NOTSAFEPOINT
627
627
{
628
- assert (jl_is_genericmemory (v ));
629
- jl_genericmemory_t * m = (jl_genericmemory_t * )v ;
628
+ assert (jl_is_genericmemory (m ));
630
629
assert (jl_genericmemory_how (m ) == 1 || jl_genericmemory_how (m ) == 2 );
631
630
char * d = (char * )m -> ptr ;
632
631
size_t freed_bytes = memory_block_usable_size (d , isaligned );
@@ -648,25 +647,23 @@ static void sweep_malloced_memory(void) JL_NOTSAFEPOINT
648
647
for (int t_i = 0 ; t_i < gc_n_threads ; t_i ++ ) {
649
648
jl_ptls_t ptls2 = gc_all_tls_states [t_i ];
650
649
if (ptls2 != NULL ) {
651
- mallocmemory_t * ma = ptls2 -> gc_tls_common . heap . mallocarrays ;
652
- mallocmemory_t * * pma = & ptls2 -> gc_tls_common .heap .mallocarrays ;
653
- while ( ma != NULL ) {
654
- mallocmemory_t * nxt = ma -> next ;
655
- jl_value_t * a = ( jl_value_t * )(( uintptr_t ) ma -> a & ~ 1 );
656
- int bits = jl_astaggedvalue ( a ) -> bits . gc ;
657
- if (gc_marked (bits )) {
658
- pma = & ma -> next ;
650
+ size_t n = 0 ;
651
+ size_t l = ptls2 -> gc_tls_common .heap .mallocarrays . len ;
652
+ void * * lst = ptls2 -> gc_tls_common . heap . mallocarrays . items ;
653
+ // filter without preserving order
654
+ while ( n < l ) {
655
+ jl_genericmemory_t * m = ( jl_genericmemory_t * )(( uintptr_t ) lst [ n ] & ~ 1 ) ;
656
+ if (gc_marked (jl_astaggedvalue ( m ) -> bits . gc )) {
657
+ n ++ ;
659
658
}
660
659
else {
661
- * pma = nxt ;
662
- int isaligned = (uintptr_t )ma -> a & 1 ;
663
- jl_gc_free_memory (a , isaligned );
664
- ma -> next = ptls2 -> gc_tls_common .heap .mafreelist ;
665
- ptls2 -> gc_tls_common .heap .mafreelist = ma ;
660
+ int isaligned = (uintptr_t )lst [n ] & 1 ;
661
+ jl_gc_free_memory (m , isaligned );
662
+ l -- ;
663
+ lst [n ] = lst [l ];
666
664
}
667
- gc_time_count_mallocd_memory (bits );
668
- ma = nxt ;
669
665
}
666
+ ptls2 -> gc_tls_common .heap .mallocarrays .len = l ;
670
667
}
671
668
}
672
669
gc_time_mallocd_memory_end ();
@@ -3433,8 +3430,7 @@ void jl_init_thread_heap(jl_ptls_t ptls)
3433
3430
small_arraylist_new (& common_heap -> live_tasks , 0 );
3434
3431
for (int i = 0 ; i < JL_N_STACK_POOLS ; i ++ )
3435
3432
small_arraylist_new (& common_heap -> free_stacks [i ], 0 );
3436
- common_heap -> mallocarrays = NULL ;
3437
- common_heap -> mafreelist = NULL ;
3433
+ small_arraylist_new (& common_heap -> mallocarrays , 0 );
3438
3434
heap -> young_generation_of_bigvals = (bigval_t * )calloc_s (sizeof (bigval_t )); // sentinel
3439
3435
assert (gc_bigval_sentinel_tag != 0 ); // make sure the sentinel is initialized
3440
3436
heap -> young_generation_of_bigvals -> header = gc_bigval_sentinel_tag ;
0 commit comments