diff --git a/asterius/rts/rts.constants.mjs b/asterius/rts/rts.constants.mjs index a6a3376a62..300b5bb50a 100644 --- a/asterius/rts/rts.constants.mjs +++ b/asterius/rts/rts.constants.mjs @@ -47,6 +47,7 @@ export const offset_StgLargeBitmap_bitmap = 0x8; export const sizeof_StgMutArrPtrs = 0x18; export const offset_StgMutArrPtrs_ptrs = 0x8; export const offset_StgMutArrPtrs_payload = 0x18; +export const offset_StgMutVar_var = 0x8; export const offset_StgMVar_head = 0x8; export const offset_StgMVar_tail = 0x10; export const offset_StgMVar_value = 0x18; @@ -77,11 +78,13 @@ export const offset_StgThunk_payload = 0x10; export const offset_StgThunkInfoTable_i = 0x0; export const offset_StgThunkInfoTable_srt = 0x18; export const offset_StgTSO_id = 0x30; +export const offset_StgTSO_dirty = 0x38; export const offset_StgTSO_stackobj = 0x18; export const offset_StgTSO_what_next = 0x20; export const offset_StgTSO_why_blocked = 0x22; export const offset_StgTSO_block_info = 0x28; export const offset_StgStack_stack_size = 0x8; +export const offset_StgStack_dirty = 0xc; export const offset_StgStack_sp = 0x10; export const offset_StgStack_stack = 0x18; export const offset_StgUpdateFrame_updatee = 0x8; diff --git a/asterius/rts/rts.gc.mjs b/asterius/rts/rts.gc.mjs index 3b1a8887de..2e7a1781d7 100644 --- a/asterius/rts/rts.gc.mjs +++ b/asterius/rts/rts.gc.mjs @@ -105,7 +105,7 @@ export class GC { } /** - * Heap alloactes a physical copy of the given closure. + * Heap allocates a physical copy of the given closure. * Used during evacuation by {@link GC#evacuateClosure}. * @param c The source address of the closure * @param bytes The size in bytes of the closure @@ -250,7 +250,7 @@ export class GC { // a forwarding address: just follow it return Memory.setDynTag(info, tag); } else if (this.nonMovedObjects.has(untagged_c)) { - // The closure is eiter pinned or static, and has + // The closure is either pinned or static, and has // already been enqueued for scavenging: just return it return c; } else if (!this.memory.heapAlloced(untagged_c)) { @@ -734,9 +734,16 @@ export class GC { this.scavengePointersFirst(c + 8, ptrs); break; } + case ClosureTypes.MUT_VAR_CLEAN: { + this.scavengeClosureAt(c + rtsConstants.offset_StgMutVar_var); + break; + } + case ClosureTypes.MUT_VAR_DIRTY: { + this.memory.i64Store(c, this.symbolTable["stg_MUT_VAR_CLEAN_info"]); + this.scavengeClosureAt(c + rtsConstants.offset_StgMutVar_var); + break; + } case ClosureTypes.BLACKHOLE: - case ClosureTypes.MUT_VAR_CLEAN: - case ClosureTypes.MUT_VAR_DIRTY: case ClosureTypes.PRIM: case ClosureTypes.MUT_PRIM: case ClosureTypes.COMPACT_NFDATA: { @@ -812,8 +819,14 @@ export class GC { this.scavengeClosureAt(c + rtsConstants.offset_StgIndStatic_indirectee); break; } - case ClosureTypes.MVAR_CLEAN: + case ClosureTypes.MVAR_CLEAN: { + this.scavengeClosureAt(c + rtsConstants.offset_StgMVar_head); + this.scavengeClosureAt(c + rtsConstants.offset_StgMVar_tail); + this.scavengeClosureAt(c + rtsConstants.offset_StgMVar_value); + break; + } case ClosureTypes.MVAR_DIRTY: { + this.memory.i64Store(c, this.symbolTable["stg_MVAR_CLEAN_info"]); this.scavengeClosureAt(c + rtsConstants.offset_StgMVar_head); this.scavengeClosureAt(c + rtsConstants.offset_StgMVar_tail); this.scavengeClosureAt(c + rtsConstants.offset_StgMVar_value); @@ -823,8 +836,6 @@ export class GC { break; } case ClosureTypes.MUT_ARR_PTRS_CLEAN: - case ClosureTypes.MUT_ARR_PTRS_DIRTY: - case ClosureTypes.MUT_ARR_PTRS_FROZEN_DIRTY: case ClosureTypes.MUT_ARR_PTRS_FROZEN_CLEAN: { const ptrs = Number( this.memory.i64Load(c + rtsConstants.offset_StgMutArrPtrs_ptrs) @@ -835,6 +846,28 @@ export class GC { ); break; } + case ClosureTypes.MUT_ARR_PTRS_DIRTY: { + this.memory.i64Store(c, this.symbolTable["stg_MUT_ARR_PTRS_CLEAN_info"]); + const ptrs = Number( + this.memory.i64Load(c + rtsConstants.offset_StgMutArrPtrs_ptrs) + ); + this.scavengePointersFirst( + c + rtsConstants.offset_StgMutArrPtrs_payload, + ptrs + ); + break; + } + case ClosureTypes.MUT_ARR_PTRS_FROZEN_DIRTY: { + this.memory.i64Store(c, this.symbolTable["stg_MUT_ARR_PTRS_FROZEN_CLEAN_info"]); + const ptrs = Number( + this.memory.i64Load(c + rtsConstants.offset_StgMutArrPtrs_ptrs) + ); + this.scavengePointersFirst( + c + rtsConstants.offset_StgMutArrPtrs_payload, + ptrs + ); + break; + } case ClosureTypes.WEAK: { this.scavengeClosureAt(c + rtsConstants.offset_StgWeak_cfinalizers); this.scavengeClosureAt(c + rtsConstants.offset_StgWeak_key); @@ -843,10 +876,12 @@ export class GC { break; } case ClosureTypes.TSO: { + this.memory.i32Store(c + rtsConstants.offset_StgTSO_dirty, 0); this.scavengeClosureAt(c + rtsConstants.offset_StgTSO_stackobj); break; } case ClosureTypes.STACK: { + this.memory.i32Store(c + rtsConstants.offset_StgStack_dirty, 0); const stack_size = this.memory.i32Load( c + rtsConstants.offset_StgStack_stack_size ), @@ -856,14 +891,35 @@ export class GC { break; } case ClosureTypes.SMALL_MUT_ARR_PTRS_CLEAN: - case ClosureTypes.SMALL_MUT_ARR_PTRS_DIRTY: - case ClosureTypes.SMALL_MUT_ARR_PTRS_FROZEN_DIRTY: case ClosureTypes.SMALL_MUT_ARR_PTRS_FROZEN_CLEAN: { + const ptrs = Number( + this.memory.i64Load(c + rtsConstants.offset_StgSmallMutArrPtrs_ptrs) + ); this.scavengePointersFirst( c + rtsConstants.offset_StgSmallMutArrPtrs_payload, - Number( - this.memory.i64Load(c + rtsConstants.offset_StgSmallMutArrPtrs_ptrs) - ) + ptrs + ); + break; + } + case ClosureTypes.SMALL_MUT_ARR_PTRS_DIRTY: { + this.memory.i64Store(c, this.symbolTable["stg_SMALL_MUT_ARR_PTRS_CLEAN_info"]); + const ptrs = Number( + this.memory.i64Load(c + rtsConstants.offset_StgSmallMutArrPtrs_ptrs) + ); + this.scavengePointersFirst( + c + rtsConstants.offset_StgSmallMutArrPtrs_payload, + ptrs + ); + break; + } + case ClosureTypes.SMALL_MUT_ARR_PTRS_FROZEN_DIRTY: { + this.memory.i64Store(c, this.symbolTable["stg_SMALL_MUT_ARR_PTRS_FROZEN_CLEAN_info"]); + const ptrs = Number( + this.memory.i64Load(c + rtsConstants.offset_StgSmallMutArrPtrs_ptrs) + ); + this.scavengePointersFirst( + c + rtsConstants.offset_StgSmallMutArrPtrs_payload, + ptrs ); break; } diff --git a/asterius/src/Asterius/JSGen/Constants.hs b/asterius/src/Asterius/JSGen/Constants.hs index ba363cd806..77f635669e 100644 --- a/asterius/src/Asterius/JSGen/Constants.hs +++ b/asterius/src/Asterius/JSGen/Constants.hs @@ -92,6 +92,7 @@ rtsConstants = ("sizeof_StgMutArrPtrs", sizeof_StgMutArrPtrs), ("offset_StgMutArrPtrs_ptrs", offset_StgMutArrPtrs_ptrs), ("offset_StgMutArrPtrs_payload", offset_StgMutArrPtrs_payload), + ("offset_StgMutVar_var", offset_StgMutVar_var), ("offset_StgMVar_head", offset_StgMVar_head), ("offset_StgMVar_tail", offset_StgMVar_tail), ("offset_StgMVar_value", offset_StgMVar_value), @@ -126,11 +127,13 @@ rtsConstants = ("offset_StgThunkInfoTable_i", offset_StgThunkInfoTable_i), ("offset_StgThunkInfoTable_srt", offset_StgThunkInfoTable_srt), ("offset_StgTSO_id", offset_StgTSO_id), + ("offset_StgTSO_dirty", offset_StgTSO_dirty), ("offset_StgTSO_stackobj", offset_StgTSO_stackobj), ("offset_StgTSO_what_next", offset_StgTSO_what_next), ("offset_StgTSO_why_blocked", offset_StgTSO_why_blocked), ("offset_StgTSO_block_info", offset_StgTSO_block_info), ("offset_StgStack_stack_size", offset_StgStack_stack_size), + ("offset_StgStack_dirty", offset_StgStack_dirty), ("offset_StgStack_sp", offset_StgStack_sp), ("offset_StgStack_stack", offset_StgStack_stack), ("offset_StgUpdateFrame_updatee", offset_StgUpdateFrame_updatee), diff --git a/asterius/src/Asterius/Ld.hs b/asterius/src/Asterius/Ld.hs index aef2384b86..036d2c7c05 100644 --- a/asterius/src/Asterius/Ld.hs +++ b/asterius/src/Asterius/Ld.hs @@ -66,6 +66,12 @@ rtsUsedSymbols = "stg_BLACKHOLE_info", "stg_WHITEHOLE_info", "stg_IND_info", + "stg_MVAR_CLEAN_info", + "stg_MUT_ARR_PTRS_CLEAN_info", + "stg_MUT_ARR_PTRS_FROZEN_CLEAN_info", + "stg_MUT_VAR_CLEAN_info", + "stg_SMALL_MUT_ARR_PTRS_CLEAN_info", + "stg_SMALL_MUT_ARR_PTRS_FROZEN_CLEAN_info", "stg_DEAD_WEAK_info", "stg_marked_upd_frame_info", "stg_NO_FINALIZER_closure", diff --git a/ghc-toolkit/cbits/ghc_constants.c b/ghc-toolkit/cbits/ghc_constants.c index 39975c7496..4d4db95a0e 100644 --- a/ghc-toolkit/cbits/ghc_constants.c +++ b/ghc-toolkit/cbits/ghc_constants.c @@ -255,6 +255,8 @@ HsInt offset_StgMutArrPtrs_payload() { return offsetof(StgMutArrPtrs, payload); } +HsInt offset_StgMutVar_var() { return offsetof(StgMutVar, var); } + HsInt offset_StgMVar_head() { return offsetof(StgMVar, head); } HsInt offset_StgMVar_tail() { return offsetof(StgMVar, tail); } diff --git a/ghc-toolkit/src/Language/Haskell/GHC/Toolkit/Constants.hs b/ghc-toolkit/src/Language/Haskell/GHC/Toolkit/Constants.hs index ae1e342215..0898a51663 100644 --- a/ghc-toolkit/src/Language/Haskell/GHC/Toolkit/Constants.hs +++ b/ghc-toolkit/src/Language/Haskell/GHC/Toolkit/Constants.hs @@ -241,6 +241,8 @@ foreign import ccall unsafe "offset_StgMutArrPtrs_size" foreign import ccall unsafe "offset_StgMutArrPtrs_payload" offset_StgMutArrPtrs_payload :: Int +foreign import ccall unsafe "offset_StgMutVar_var" offset_StgMutVar_var :: Int + foreign import ccall unsafe "offset_StgMVar_head" offset_StgMVar_head :: Int foreign import ccall unsafe "offset_StgMVar_tail" offset_StgMVar_tail :: Int