@@ -1121,17 +1121,8 @@ static void sweep_big(jl_ptls_t ptls, int sweep_full) JL_NOTSAFEPOINT
11211121
11221122void jl_gc_track_malloced_genericmemory (jl_ptls_t ptls , jl_genericmemory_t * m , int isaligned ){
11231123 // This is **NOT** a GC safe point.
1124- mallocarray_t * ma ;
1125- if (ptls -> heap .mafreelist == NULL ) {
1126- ma = (mallocarray_t * )malloc_s (sizeof (mallocarray_t ));
1127- }
1128- else {
1129- ma = ptls -> heap .mafreelist ;
1130- ptls -> heap .mafreelist = ma -> next ;
1131- }
1132- ma -> a = (jl_value_t * )((uintptr_t )m | !!isaligned );
1133- ma -> next = ptls -> heap .mallocarrays ;
1134- ptls -> heap .mallocarrays = ma ;
1124+ void * a = (void * )((uintptr_t )m | !!isaligned );
1125+ small_arraylist_push (& ptls -> heap .mallocarrays , a );
11351126}
11361127
11371128
@@ -1245,24 +1236,23 @@ static void sweep_malloced_memory(void) JL_NOTSAFEPOINT
12451236 for (int t_i = 0 ; t_i < gc_n_threads ; t_i ++ ) {
12461237 jl_ptls_t ptls2 = gc_all_tls_states [t_i ];
12471238 if (ptls2 != NULL ) {
1248- mallocarray_t * ma = ptls2 -> heap . mallocarrays ;
1249- mallocarray_t * * pma = & ptls2 -> heap .mallocarrays ;
1250- while ( ma != NULL ) {
1251- mallocarray_t * nxt = ma -> next ;
1252- jl_value_t * a = ( jl_value_t * )(( uintptr_t ) ma -> a & ~ 1 );
1253- int bits = jl_astaggedvalue ( a ) -> bits . gc ;
1254- if (gc_marked (bits )) {
1255- pma = & ma -> next ;
1239+ size_t n = 0 ;
1240+ size_t l = ptls2 -> heap .mallocarrays . len ;
1241+ void * * lst = ptls2 -> heap . mallocarrays . items ;
1242+ // filter without preserving order
1243+ while ( n < l ) {
1244+ jl_genericmemory_t * m = ( jl_genericmemory_t * )(( uintptr_t ) lst [ n ] & ~ 1 ) ;
1245+ if (gc_marked (jl_astaggedvalue ( m ) -> bits . gc )) {
1246+ n ++ ;
12561247 }
12571248 else {
1258- * pma = nxt ;
1259- int isaligned = ( uintptr_t ) ma -> a & 1 ;
1260- jl_gc_free_memory ( a , isaligned ) ;
1261- free ( ma ) ;
1249+ int isaligned = ( uintptr_t ) lst [ n ] & 1 ;
1250+ jl_gc_free_memory ( m , isaligned ) ;
1251+ l -- ;
1252+ lst [ n ] = lst [ l ] ;
12621253 }
1263- gc_time_count_mallocd_memory (bits );
1264- ma = nxt ;
12651254 }
1255+ ptls2 -> heap .mallocarrays .len = l ;
12661256 }
12671257 }
12681258 gc_time_mallocd_memory_end ();
@@ -3968,8 +3958,7 @@ void jl_init_thread_heap(jl_ptls_t ptls)
39683958 small_arraylist_new (& heap -> live_tasks , 0 );
39693959 for (int i = 0 ; i < JL_N_STACK_POOLS ; i ++ )
39703960 small_arraylist_new (& heap -> free_stacks [i ], 0 );
3971- heap -> mallocarrays = NULL ;
3972- heap -> mafreelist = NULL ;
3961+ small_arraylist_new (& heap -> mallocarrays , 0 );
39733962 heap -> big_objects = NULL ;
39743963 heap -> remset = & heap -> _remset [0 ];
39753964 heap -> last_remset = & heap -> _remset [1 ];
0 commit comments