@@ -107,7 +107,7 @@ export class GC {
107
107
}
108
108
109
109
/**
110
- * Heap alloactes a physical copy of the given closure.
110
+ * Heap allocates a physical copy of the given closure.
111
111
* Used during evacuation by {@link GC#evacuateClosure}.
112
112
* @param c The source address of the closure
113
113
* @param bytes The size in bytes of the closure
@@ -252,7 +252,7 @@ export class GC {
252
252
// a forwarding address: just follow it
253
253
return Memory . setDynTag ( info , tag ) ;
254
254
} else if ( this . nonMovedObjects . has ( untagged_c ) ) {
255
- // The closure is eiter pinned or static, and has
255
+ // The closure is either pinned or static, and has
256
256
// already been enqueued for scavenging: just return it
257
257
return c ;
258
258
} else if ( ! this . memory . heapAlloced ( untagged_c ) ) {
@@ -467,6 +467,33 @@ export class GC {
467
467
for ( let i = 0 ; i < ptrs ; ++ i ) this . scavengeClosureAt ( payload + ( i << 3 ) ) ;
468
468
}
469
469
470
+
471
+ /**
472
+ * Scavenge the pointers of a MUT_ARR, but only
473
+ * the areas that are marked as dirty in the
474
+ * card table.
475
+ * @param p The address of the array payload
476
+ * @param ptrs The number of pointers in the array
477
+ */
478
+ scavengeMutArrPtrsMarked ( p , ptrs ) {
479
+ // `cards` is the pointer to the card table
480
+ const cards = p + ( ptrs << 3 ) ;
481
+ const c = 1 << rtsConstants . MUT_ARR_PTRS_CARD_BITS ;
482
+ // The length (in bytes) of the card table
483
+ const mutArrPtrsCards = ( ( ptrs + c - 1 ) >> rtsConstants . MUT_ARR_PTRS_CARD_BITS ) ;
484
+ for ( let m = 0 ; m < mutArrPtrsCards ; m ++ ) {
485
+ if ( this . memory . i8Load ( cards + m ) != 0 ) {
486
+ this . memory . i8Store ( cards + m , 0 ) ; // clean up
487
+ const q = Math . min ( p + c , cards ) ;
488
+ for ( ; p < q ; p += 8 ) {
489
+ this . scavengeClosureAt ( p ) ;
490
+ }
491
+ } else {
492
+ p += c ;
493
+ }
494
+ }
495
+ }
496
+
470
497
scavengeSmallBitmap ( payload , bitmap , size ) {
471
498
for ( let i = 0 ; i < size ; ++ i )
472
499
if ( ! ( Number ( bitmap >> BigInt ( i ) ) & 1 ) )
@@ -736,9 +763,16 @@ export class GC {
736
763
this . scavengePointersFirst ( c + 8 , ptrs ) ;
737
764
break ;
738
765
}
766
+ case ClosureTypes . MUT_VAR_CLEAN : {
767
+ this . scavengeClosureAt ( c + rtsConstants . offset_StgMutVar_var ) ;
768
+ break ;
769
+ }
770
+ case ClosureTypes . MUT_VAR_DIRTY : {
771
+ this . memory . i64Store ( c , this . symbolTable [ "stg_MUT_VAR_CLEAN_info" ] ) ;
772
+ this . scavengeClosureAt ( c + rtsConstants . offset_StgMutVar_var ) ;
773
+ break ;
774
+ }
739
775
case ClosureTypes . BLACKHOLE :
740
- case ClosureTypes . MUT_VAR_CLEAN :
741
- case ClosureTypes . MUT_VAR_DIRTY :
742
776
case ClosureTypes . PRIM :
743
777
case ClosureTypes . MUT_PRIM :
744
778
case ClosureTypes . COMPACT_NFDATA : {
@@ -814,8 +848,14 @@ export class GC {
814
848
this . scavengeClosureAt ( c + rtsConstants . offset_StgIndStatic_indirectee ) ;
815
849
break ;
816
850
}
817
- case ClosureTypes . MVAR_CLEAN :
851
+ case ClosureTypes . MVAR_CLEAN : {
852
+ this . scavengeClosureAt ( c + rtsConstants . offset_StgMVar_head ) ;
853
+ this . scavengeClosureAt ( c + rtsConstants . offset_StgMVar_tail ) ;
854
+ this . scavengeClosureAt ( c + rtsConstants . offset_StgMVar_value ) ;
855
+ break ;
856
+ }
818
857
case ClosureTypes . MVAR_DIRTY : {
858
+ this . memory . i64Store ( c , this . symbolTable [ "stg_MVAR_CLEAN_info" ] ) ;
819
859
this . scavengeClosureAt ( c + rtsConstants . offset_StgMVar_head ) ;
820
860
this . scavengeClosureAt ( c + rtsConstants . offset_StgMVar_tail ) ;
821
861
this . scavengeClosureAt ( c + rtsConstants . offset_StgMVar_value ) ;
@@ -825,8 +865,6 @@ export class GC {
825
865
break ;
826
866
}
827
867
case ClosureTypes . MUT_ARR_PTRS_CLEAN :
828
- case ClosureTypes . MUT_ARR_PTRS_DIRTY :
829
- case ClosureTypes . MUT_ARR_PTRS_FROZEN_DIRTY :
830
868
case ClosureTypes . MUT_ARR_PTRS_FROZEN_CLEAN : {
831
869
const ptrs = Number (
832
870
this . memory . i64Load ( c + rtsConstants . offset_StgMutArrPtrs_ptrs )
@@ -837,6 +875,28 @@ export class GC {
837
875
) ;
838
876
break ;
839
877
}
878
+ case ClosureTypes . MUT_ARR_PTRS_DIRTY : {
879
+ this . memory . i64Store ( c , this . symbolTable [ "stg_MUT_ARR_PTRS_CLEAN_info" ] ) ;
880
+ const ptrs = Number (
881
+ this . memory . i64Load ( c + rtsConstants . offset_StgMutArrPtrs_ptrs )
882
+ ) ;
883
+ this . scavengeMutArrPtrsMarked (
884
+ c + rtsConstants . offset_StgMutArrPtrs_payload ,
885
+ ptrs
886
+ ) ;
887
+ break ;
888
+ }
889
+ case ClosureTypes . MUT_ARR_PTRS_FROZEN_DIRTY : {
890
+ this . memory . i64Store ( c , this . symbolTable [ "stg_MUT_ARR_PTRS_FROZEN_CLEAN_info" ] ) ;
891
+ const ptrs = Number (
892
+ this . memory . i64Load ( c + rtsConstants . offset_StgMutArrPtrs_ptrs )
893
+ ) ;
894
+ this . scavengeMutArrPtrsMarked (
895
+ c + rtsConstants . offset_StgMutArrPtrs_payload ,
896
+ ptrs
897
+ ) ;
898
+ break ;
899
+ }
840
900
case ClosureTypes . WEAK : {
841
901
this . scavengeClosureAt ( c + rtsConstants . offset_StgWeak_cfinalizers ) ;
842
902
this . scavengeClosureAt ( c + rtsConstants . offset_StgWeak_key ) ;
@@ -845,10 +905,12 @@ export class GC {
845
905
break ;
846
906
}
847
907
case ClosureTypes . TSO : {
908
+ this . memory . i32Store ( c + rtsConstants . offset_StgTSO_dirty , 0 ) ;
848
909
this . scavengeClosureAt ( c + rtsConstants . offset_StgTSO_stackobj ) ;
849
910
break ;
850
911
}
851
912
case ClosureTypes . STACK : {
913
+ this . memory . i32Store ( c + rtsConstants . offset_StgStack_dirty , 0 ) ;
852
914
const stack_size = this . memory . i32Load (
853
915
c + rtsConstants . offset_StgStack_stack_size
854
916
) ,
@@ -858,14 +920,35 @@ export class GC {
858
920
break ;
859
921
}
860
922
case ClosureTypes . SMALL_MUT_ARR_PTRS_CLEAN :
861
- case ClosureTypes . SMALL_MUT_ARR_PTRS_DIRTY :
862
- case ClosureTypes . SMALL_MUT_ARR_PTRS_FROZEN_DIRTY :
863
923
case ClosureTypes . SMALL_MUT_ARR_PTRS_FROZEN_CLEAN : {
924
+ const ptrs = Number (
925
+ this . memory . i64Load ( c + rtsConstants . offset_StgSmallMutArrPtrs_ptrs )
926
+ ) ;
864
927
this . scavengePointersFirst (
865
928
c + rtsConstants . offset_StgSmallMutArrPtrs_payload ,
866
- Number (
867
- this . memory . i64Load ( c + rtsConstants . offset_StgSmallMutArrPtrs_ptrs )
868
- )
929
+ ptrs
930
+ ) ;
931
+ break ;
932
+ }
933
+ case ClosureTypes . SMALL_MUT_ARR_PTRS_DIRTY : {
934
+ this . memory . i64Store ( c , this . symbolTable [ "stg_SMALL_MUT_ARR_PTRS_CLEAN_info" ] ) ;
935
+ const ptrs = Number (
936
+ this . memory . i64Load ( c + rtsConstants . offset_StgSmallMutArrPtrs_ptrs )
937
+ ) ;
938
+ this . scavengePointersFirst (
939
+ c + rtsConstants . offset_StgSmallMutArrPtrs_payload ,
940
+ ptrs
941
+ ) ;
942
+ break ;
943
+ }
944
+ case ClosureTypes . SMALL_MUT_ARR_PTRS_FROZEN_DIRTY : {
945
+ this . memory . i64Store ( c , this . symbolTable [ "stg_SMALL_MUT_ARR_PTRS_FROZEN_CLEAN_info" ] ) ;
946
+ const ptrs = Number (
947
+ this . memory . i64Load ( c + rtsConstants . offset_StgSmallMutArrPtrs_ptrs )
948
+ ) ;
949
+ this . scavengePointersFirst (
950
+ c + rtsConstants . offset_StgSmallMutArrPtrs_payload ,
951
+ ptrs
869
952
) ;
870
953
break ;
871
954
}
0 commit comments