Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Commit

Permalink
Scavenge & dirty closures
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Condoluci committed Apr 3, 2020
1 parent b1604e5 commit e3a7897
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 7 deletions.
3 changes: 3 additions & 0 deletions asterius/rts/rts.constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,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;
Expand Down Expand Up @@ -78,11 +79,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;
Expand Down
69 changes: 62 additions & 7 deletions asterius/rts/rts.gc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -823,11 +823,18 @@ export class GC {
this.scavengePointersFirst(c + 8, ptrs);
return (1 + ptrs + non_ptrs) << 3;
}
case ClosureTypes.MUT_VAR_CLEAN: {
this.scavengeClosureAt(c + rtsConstants.offset_StgMutVar_var);
return rtsConstants.offset_StgMutVar_var + 8;
}
case ClosureTypes.MUT_VAR_DIRTY: {
this.memory.i64Store(c, this.symbolTable["stg_MUT_VAR_CLEAN_info"]);
this.scavengeClosureAt(c + rtsConstants.offset_StgMutVar_var);
return rtsConstants.offset_StgMutVar_var + 8;
}
case ClosureTypes.CONSTR:
case ClosureTypes.CONSTR_NOCAF:
case ClosureTypes.BLACKHOLE:
case ClosureTypes.MUT_VAR_CLEAN:
case ClosureTypes.MUT_VAR_DIRTY:
case ClosureTypes.PRIM:
case ClosureTypes.MUT_PRIM:
case ClosureTypes.COMPACT_NFDATA: {
Expand Down Expand Up @@ -917,8 +924,14 @@ export class GC {
this.scavengeClosureAt(c + rtsConstants.offset_StgIndStatic_indirectee);
return; // size not important, this object won't be moved
}
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);
return rtsConstants.offset_StgMVar_value + 8;
}
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);
Expand All @@ -936,8 +949,6 @@ export class GC {
);
}
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)
Expand All @@ -948,6 +959,28 @@ export class GC {
);
return rtsConstants.sizeof_StgMutArrPtrs + (ptrs << 3);
}
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
);
return rtsConstants.sizeof_StgMutArrPtrs + (ptrs << 3);
}
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
);
return rtsConstants.sizeof_StgMutArrPtrs + (ptrs << 3);
}
case ClosureTypes.WEAK: {
this.scavengeClosureAt(c + rtsConstants.offset_StgWeak_cfinalizers);
this.scavengeClosureAt(c + rtsConstants.offset_StgWeak_key);
Expand All @@ -956,10 +989,12 @@ export class GC {
return rtsConstants.offset_StgWeak_link + 8;
}
case ClosureTypes.TSO: {
this.memory.i32Store(c + rtsConstants.offset_StgTSO_dirty, 0);
this.scavengeClosureAt(c + rtsConstants.offset_StgTSO_stackobj);
return; // size not important, this object won't be moved
}
case ClosureTypes.STACK: {
this.memory.i32Store(c + rtsConstants.offset_StgStack_dirty, 0);
const
stack_size =
this.memory.i32Load(c + rtsConstants.offset_StgStack_stack_size) << 3,
Expand All @@ -969,8 +1004,6 @@ export class GC {
return rtsConstants.offset_StgStack_stack + stack_size;
}
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)
Expand All @@ -981,6 +1014,28 @@ export class GC {
);
return rtsConstants.offset_StgSmallMutArrPtrs_payload + (ptrs << 3);
}
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
);
return rtsConstants.offset_StgSmallMutArrPtrs_payload + (ptrs << 3);
}
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
);
return rtsConstants.offset_StgSmallMutArrPtrs_payload + (ptrs << 3);
}
default:
throw new WebAssembly.RuntimeError();
}
Expand Down
3 changes: 3 additions & 0 deletions asterius/src/Asterius/JSGen/Constants.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,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),
Expand Down Expand Up @@ -128,11 +129,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),
Expand Down
6 changes: 6 additions & 0 deletions asterius/src/Asterius/Ld.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions ghc-toolkit/cbits/ghc_constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,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); }
Expand Down
2 changes: 2 additions & 0 deletions ghc-toolkit/src/Language/Haskell/GHC/Toolkit/Constants.hs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,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
Expand Down

0 comments on commit e3a7897

Please sign in to comment.