@@ -623,10 +623,9 @@ void jl_gc_reset_alloc_count(void) JL_NOTSAFEPOINT
623623 reset_thread_gc_counts ();
624624}
625625
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
627627{
628- assert (jl_is_genericmemory (v ));
629- jl_genericmemory_t * m = (jl_genericmemory_t * )v ;
628+ assert (jl_is_genericmemory (m ));
630629 assert (jl_genericmemory_how (m ) == 1 || jl_genericmemory_how (m ) == 2 );
631630 char * d = (char * )m -> ptr ;
632631 size_t freed_bytes = memory_block_usable_size (d , isaligned );
@@ -648,25 +647,23 @@ static void sweep_malloced_memory(void) JL_NOTSAFEPOINT
648647 for (int t_i = 0 ; t_i < gc_n_threads ; t_i ++ ) {
649648 jl_ptls_t ptls2 = gc_all_tls_states [t_i ];
650649 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 ++ ;
659658 }
660659 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 ];
666664 }
667- gc_time_count_mallocd_memory (bits );
668- ma = nxt ;
669665 }
666+ ptls2 -> gc_tls_common .heap .mallocarrays .len = l ;
670667 }
671668 }
672669 gc_time_mallocd_memory_end ();
@@ -3433,8 +3430,7 @@ void jl_init_thread_heap(jl_ptls_t ptls)
34333430 small_arraylist_new (& common_heap -> live_tasks , 0 );
34343431 for (int i = 0 ; i < JL_N_STACK_POOLS ; i ++ )
34353432 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 );
34383434 heap -> young_generation_of_bigvals = (bigval_t * )calloc_s (sizeof (bigval_t )); // sentinel
34393435 assert (gc_bigval_sentinel_tag != 0 ); // make sure the sentinel is initialized
34403436 heap -> young_generation_of_bigvals -> header = gc_bigval_sentinel_tag ;
0 commit comments