[Git][ghc/ghc][master] rts: Fix barriers of IND and IND_STATIC

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Sat Mar 25 04:05:00 UTC 2023



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
c421bbbb by Ben Gamari at 2023-03-25T00:04:41-04:00
rts: Fix barriers of IND and IND_STATIC

Previously IND and IND_STATIC lacked the acquire barriers enjoyed by
BLACKHOLE. As noted in the (now updated) Note [Heap memory barriers],
this barrier is critical to ensure that the indirectee is visible to the
entering core.

Fixes #22872.

- - - - -


2 changed files:

- rts/StgMiscClosures.cmm
- rts/include/stg/SMP.h


Changes:

=====================================
rts/StgMiscClosures.cmm
=====================================
@@ -521,6 +521,7 @@ INFO_TABLE(stg_IND,1,0,IND,"IND","IND")
     (P_ node)
 {
     TICK_ENT_DYN_IND(); /* tick */
+    ACQUIRE_FENCE;
     node = UNTAG(StgInd_indirectee(node));
     TICK_ENT_VIA_NODE();
     jump %GET_ENTRY(node) (node);
@@ -529,6 +530,7 @@ INFO_TABLE(stg_IND,1,0,IND,"IND","IND")
     /* explicit stack */
 {
     TICK_ENT_DYN_IND(); /* tick */
+    ACQUIRE_FENCE;
     R1 = UNTAG(StgInd_indirectee(R1));
     TICK_ENT_VIA_NODE();
     jump %GET_ENTRY(R1) [R1];
@@ -539,6 +541,7 @@ INFO_TABLE(stg_IND_STATIC,1,0,IND_STATIC,"IND_STATIC","IND_STATIC")
     /* explicit stack */
 {
     TICK_ENT_STATIC_IND(); /* tick */
+    ACQUIRE_FENCE;
     R1 = UNTAG(StgInd_indirectee(R1));
     TICK_ENT_VIA_NODE();
     jump %GET_ENTRY(R1) [R1];


=====================================
rts/include/stg/SMP.h
=====================================
@@ -214,23 +214,22 @@ EXTERN_INLINE void load_load_barrier(void);
  * examining a thunk being updated can see the indirectee. Consequently, a
  * thunk update (see rts/Updates.h) does the following:
  *
- *  1. Use a release-fence to ensure that the indirectee is visible
- *  2. Use a relaxed-store to place the new indirectee into the thunk's
+ *  1. Use a relaxed-store to place the new indirectee into the thunk's
  *     indirectee field
- *  3. use a release-store to set the info table to stg_BLACKHOLE (which
+ *  2. use a release-store to set the info table to stg_BLACKHOLE (which
  *     represents an indirection)
  *
  * Blackholing a thunk (either eagerly, by GHC.StgToCmm.Bind.emitBlackHoleCode,
  * or lazily, by ThreadPaused.c:threadPaused) is done similarly.
  *
- * Conversely, thunk entry (see the entry code of stg_BLACKHOLE in
- * rts/StgMiscClosure) does the following:
+ * Conversely, indirection entry (see the entry code of stg_BLACKHOLE, stg_IND,
+ * and stg_IND_STATIC in rts/StgMiscClosure.cmm) does the following:
  *
- *  1. We jump into the entry code for stg_BLACKHOLE; this of course implies
- *     that we have already read the thunk's info table pointer, which is done
- *     with a relaxed load.
+ *  1. We jump into the entry code for, e.g., stg_BLACKHOLE; this of course
+ *     implies that we have already read the thunk's info table pointer, which
+ *     is done with a relaxed load.
  *  2. use an acquire-fence to ensure that our view on the thunk is
- *     up-to-date. This synchronizes with step (3) in the update
+ *     up-to-date. This synchronizes with step (2) in the update
  *     procedure.
  *  3. relaxed-load the indirectee. Since thunks are updated at most
  *     once we know that the fence in the last step has given us



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c421bbbbf2a353858dda8f998d4997cce5977c03

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c421bbbbf2a353858dda8f998d4997cce5977c03
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230325/78685cd7/attachment-0001.html>


More information about the ghc-commits mailing list