@@ -629,10 +629,9 @@ void jl_gc_reset_alloc_count(void) JL_NOTSAFEPOINT
629629 reset_thread_gc_counts ();
630630}
631631
632- static void jl_gc_free_memory (jl_value_t * v , int isaligned ) JL_NOTSAFEPOINT
632+ static void jl_gc_free_memory (jl_genericmemory_t * m , int isaligned ) JL_NOTSAFEPOINT
633633{
634- assert (jl_is_genericmemory (v ));
635- jl_genericmemory_t * m = (jl_genericmemory_t * )v ;
634+ assert (jl_is_genericmemory (m ));
636635 assert (jl_genericmemory_how (m ) == 1 || jl_genericmemory_how (m ) == 2 );
637636 char * d = (char * )m -> ptr ;
638637 size_t freed_bytes = memory_block_usable_size (d , isaligned );
@@ -654,25 +653,23 @@ static void sweep_malloced_memory(void) JL_NOTSAFEPOINT
654653 for (int t_i = 0 ; t_i < gc_n_threads ; t_i ++ ) {
655654 jl_ptls_t ptls2 = gc_all_tls_states [t_i ];
656655 if (ptls2 != NULL ) {
657- mallocmemory_t * ma = ptls2 -> gc_tls_common . heap . mallocarrays ;
658- mallocmemory_t * * pma = & ptls2 -> gc_tls_common .heap .mallocarrays ;
659- while ( ma != NULL ) {
660- mallocmemory_t * nxt = ma -> next ;
661- jl_value_t * a = ( jl_value_t * )(( uintptr_t ) ma -> a & ~ 1 );
662- int bits = jl_astaggedvalue ( a ) -> bits . gc ;
663- if (gc_marked (bits )) {
664- pma = & ma -> next ;
656+ size_t n = 0 ;
657+ size_t l = ptls2 -> gc_tls_common .heap .mallocarrays . len ;
658+ void * * lst = ptls2 -> gc_tls_common . heap . mallocarrays . items ;
659+ // filter without preserving order
660+ while ( n < l ) {
661+ jl_genericmemory_t * m = ( jl_genericmemory_t * )(( uintptr_t ) lst [ n ] & ~ 1 ) ;
662+ if (gc_marked (jl_astaggedvalue ( m ) -> bits . gc )) {
663+ n ++ ;
665664 }
666665 else {
667- * pma = nxt ;
668- int isaligned = (uintptr_t )ma -> a & 1 ;
669- jl_gc_free_memory (a , isaligned );
670- ma -> next = ptls2 -> gc_tls_common .heap .mafreelist ;
671- ptls2 -> gc_tls_common .heap .mafreelist = ma ;
666+ int isaligned = (uintptr_t )lst [n ] & 1 ;
667+ jl_gc_free_memory (m , isaligned );
668+ l -- ;
669+ lst [n ] = lst [l ];
672670 }
673- gc_time_count_mallocd_memory (bits );
674- ma = nxt ;
675671 }
672+ ptls2 -> gc_tls_common .heap .mallocarrays .len = l ;
676673 }
677674 }
678675 gc_time_mallocd_memory_end ();
@@ -3439,8 +3436,7 @@ void jl_init_thread_heap(jl_ptls_t ptls)
34393436 small_arraylist_new (& common_heap -> live_tasks , 0 );
34403437 for (int i = 0 ; i < JL_N_STACK_POOLS ; i ++ )
34413438 small_arraylist_new (& common_heap -> free_stacks [i ], 0 );
3442- common_heap -> mallocarrays = NULL ;
3443- common_heap -> mafreelist = NULL ;
3439+ small_arraylist_new (& common_heap -> mallocarrays , 0 );
34443440 heap -> young_generation_of_bigvals = (bigval_t * )calloc_s (sizeof (bigval_t )); // sentinel
34453441 assert (gc_bigval_sentinel_tag != 0 ); // make sure the sentinel is initialized
34463442 heap -> young_generation_of_bigvals -> header = gc_bigval_sentinel_tag ;
0 commit comments