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 Mar 28, 2020
1 parent e90382f commit 9c10e0d
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 12 deletions.
3 changes: 3 additions & 0 deletions asterius/rts/rts.constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
80 changes: 68 additions & 12 deletions asterius/rts/rts.gc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand All @@ -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);
Expand All @@ -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
),
Expand All @@ -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;
}
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 @@ -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),
Expand Down Expand Up @@ -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),
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 @@ -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); }
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 @@ -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
Expand Down

0 comments on commit 9c10e0d

Please sign in to comment.