Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
-
cdb74049
by Cheng Shao at 2026-01-22T14:52:36-05:00
7 changed files:
- rts/AllocArray.c
- rts/AllocArray.h
- rts/ClosureTable.c
- rts/Heap.c
- rts/PrimOps.cmm
- rts/Threads.c
- rts/Weak.c
Changes:
| ... | ... | @@ -5,6 +5,7 @@ |
| 5 | 5 | |
| 6 | 6 | StgMutArrPtrs *allocateMutArrPtrs (Capability *cap,
|
| 7 | 7 | StgWord nelements,
|
| 8 | + StgClosure *init,
|
|
| 8 | 9 | CostCentreStack *ccs USED_IF_PROFILING)
|
| 9 | 10 | {
|
| 10 | 11 | /* All sizes in words */
|
| ... | ... | @@ -25,6 +26,12 @@ StgMutArrPtrs *allocateMutArrPtrs (Capability *cap, |
| 25 | 26 | arr->ptrs = nelements;
|
| 26 | 27 | arr->size = arrsize;
|
| 27 | 28 | |
| 29 | + if (init != NULL) {
|
|
| 30 | + for (StgWord i = 0; i < nelements; ++i) {
|
|
| 31 | + arr->payload[i] = init;
|
|
| 32 | + }
|
|
| 33 | + }
|
|
| 34 | + |
|
| 28 | 35 | /* Initialize the card array. Note that memset needs sizes in bytes. */
|
| 29 | 36 | memset(&(arr->payload[nelements]), 0, mutArrPtrsCards(nelements));
|
| 30 | 37 | |
| ... | ... | @@ -33,6 +40,7 @@ StgMutArrPtrs *allocateMutArrPtrs (Capability *cap, |
| 33 | 40 | |
| 34 | 41 | StgSmallMutArrPtrs *allocateSmallMutArrPtrs (Capability *cap,
|
| 35 | 42 | StgWord nelements,
|
| 43 | + StgClosure *init,
|
|
| 36 | 44 | CostCentreStack *ccs
|
| 37 | 45 | USED_IF_PROFILING)
|
| 38 | 46 | {
|
| ... | ... | @@ -47,6 +55,13 @@ StgSmallMutArrPtrs *allocateSmallMutArrPtrs (Capability *cap, |
| 47 | 55 | /* No write barrier needed since this is a new allocation. */
|
| 48 | 56 | SET_HDR(arr, &stg_SMALL_MUT_ARR_PTRS_DIRTY_info, ccs);
|
| 49 | 57 | arr->ptrs = nelements;
|
| 58 | + |
|
| 59 | + if (init != NULL) {
|
|
| 60 | + for (StgWord i = 0; i < nelements; ++i) {
|
|
| 61 | + arr->payload[i] = init;
|
|
| 62 | + }
|
|
| 63 | + }
|
|
| 64 | + |
|
| 50 | 65 | return arr;
|
| 51 | 66 | }
|
| 52 | 67 |
| ... | ... | @@ -21,16 +21,19 @@ |
| 21 | 21 | */
|
| 22 | 22 | |
| 23 | 23 | /* Allocate a StgMutArrPtrs for a given number of elements. It is allocated in
|
| 24 | - * the DIRTY state.
|
|
| 24 | + * the DIRTY state. If init is non-NULL, initialize payload elements to init.
|
|
| 25 | 25 | */
|
| 26 | 26 | StgMutArrPtrs *allocateMutArrPtrs (Capability *cap,
|
| 27 | 27 | StgWord nelements,
|
| 28 | + StgClosure *init,
|
|
| 28 | 29 | CostCentreStack *ccs);
|
| 29 | 30 | |
| 30 | -/* Allocate a StgSmallMutArrPtrs for a given number of elements.
|
|
| 31 | +/* Allocate a StgSmallMutArrPtrs for a given number of elements. If init is
|
|
| 32 | + * non-NULL, initialize payload elements to init.
|
|
| 31 | 33 | */
|
| 32 | 34 | StgSmallMutArrPtrs *allocateSmallMutArrPtrs (Capability *cap,
|
| 33 | 35 | StgWord nelements,
|
| 36 | + StgClosure *init,
|
|
| 34 | 37 | CostCentreStack *ccs);
|
| 35 | 38 | |
| 36 | 39 | /* Allocate a StgArrBytes for a given number of bytes.
|
| ... | ... | @@ -46,7 +46,7 @@ bool enlargeClosureTable(Capability *cap, ClosureTable *t, int newcapacity) |
| 46 | 46 | ASSERT(newcapacity > oldcapacity);
|
| 47 | 47 | |
| 48 | 48 | StgMutArrPtrs *newarr;
|
| 49 | - newarr = allocateMutArrPtrs(cap, newcapacity, CCS_SYSTEM_OR_NULL);
|
|
| 49 | + newarr = allocateMutArrPtrs(cap, newcapacity, NULL, CCS_SYSTEM_OR_NULL);
|
|
| 50 | 50 | if (RTS_UNLIKELY(newarr == NULL)) return false;
|
| 51 | 51 | |
| 52 | 52 | StgArrBytes *newfree;
|
| ... | ... | @@ -276,4 +276,3 @@ static bool isCompactClosureTable(ClosureTable *t) |
| 276 | 276 | }
|
| 277 | 277 | return isCompact;
|
| 278 | 278 | } |
| 279 | - |
| ... | ... | @@ -279,7 +279,7 @@ StgMutArrPtrs *heap_view_closurePtrs(Capability *cap, StgClosure *closure) { |
| 279 | 279 | StgClosure **ptrs = (StgClosure **) stgMallocBytes(sizeof(StgClosure *) * size, "heap_view_closurePtrs");
|
| 280 | 280 | StgWord nptrs = collect_pointers(closure, ptrs);
|
| 281 | 281 | |
| 282 | - StgMutArrPtrs *arr = allocateMutArrPtrs(cap, nptrs, cap->r.rCCCS);
|
|
| 282 | + StgMutArrPtrs *arr = allocateMutArrPtrs(cap, nptrs, NULL, cap->r.rCCCS);
|
|
| 283 | 283 | if (RTS_UNLIKELY(arr == NULL)) goto end;
|
| 284 | 284 | SET_INFO((StgClosure *) arr, &stg_MUT_ARR_PTRS_FROZEN_CLEAN_info);
|
| 285 | 285 |
| ... | ... | @@ -386,24 +386,11 @@ stg_newArrayzh ( W_ n /* words */, gcptr init ) |
| 386 | 386 | |
| 387 | 387 | again: MAYBE_GC(again);
|
| 388 | 388 | |
| 389 | - ("ptr" arr) = ccall allocateMutArrPtrs(MyCapability() "ptr", n, CCCS);
|
|
| 389 | + ("ptr" arr) = ccall allocateMutArrPtrs(MyCapability() "ptr", n, init "ptr", CCCS);
|
|
| 390 | 390 | if (arr == NULL) (likely: False) {
|
| 391 | 391 | jump stg_raisezh(HsIface_heapOverflow_closure(W_[ghc_hs_iface]));
|
| 392 | 392 | }
|
| 393 | 393 | |
| 394 | - // Initialise all elements of the array with the value init
|
|
| 395 | - W_ p;
|
|
| 396 | - p = arr + SIZEOF_StgMutArrPtrs;
|
|
| 397 | - // Avoid the shift for `WDS(n)` in the inner loop
|
|
| 398 | - W_ limit;
|
|
| 399 | - limit = arr + SIZEOF_StgMutArrPtrs + WDS(n);
|
|
| 400 | - for:
|
|
| 401 | - if (p < limit) (likely: True) {
|
|
| 402 | - W_[p] = init;
|
|
| 403 | - p = p + WDS(1);
|
|
| 404 | - goto for;
|
|
| 405 | - }
|
|
| 406 | - |
|
| 407 | 394 | return (arr);
|
| 408 | 395 | }
|
| 409 | 396 | |
| ... | ... | @@ -496,24 +483,11 @@ stg_newSmallArrayzh ( W_ n /* words */, gcptr init ) |
| 496 | 483 | |
| 497 | 484 | again: MAYBE_GC(again);
|
| 498 | 485 | |
| 499 | - ("ptr" arr) = ccall allocateSmallMutArrPtrs(MyCapability() "ptr", n, CCCS);
|
|
| 486 | + ("ptr" arr) = ccall allocateSmallMutArrPtrs(MyCapability() "ptr", n, init "ptr", CCCS);
|
|
| 500 | 487 | if (arr == NULL) (likely: False) {
|
| 501 | 488 | jump stg_raisezh(HsIface_heapOverflow_closure(W_[ghc_hs_iface]));
|
| 502 | 489 | }
|
| 503 | 490 | |
| 504 | - // Initialise all elements of the array with the value init
|
|
| 505 | - W_ p;
|
|
| 506 | - p = arr + SIZEOF_StgSmallMutArrPtrs;
|
|
| 507 | - // Avoid the shift for `WDS(n)` in the inner loop
|
|
| 508 | - W_ limit;
|
|
| 509 | - limit = arr + SIZEOF_StgSmallMutArrPtrs + WDS(n);
|
|
| 510 | - for:
|
|
| 511 | - if (p < limit) (likely: True) {
|
|
| 512 | - W_[p] = init;
|
|
| 513 | - p = p + WDS(1);
|
|
| 514 | - goto for;
|
|
| 515 | - }
|
|
| 516 | - |
|
| 517 | 491 | return (arr);
|
| 518 | 492 | }
|
| 519 | 493 |
| ... | ... | @@ -894,7 +894,7 @@ StgMutArrPtrs *listThreads(Capability *cap) |
| 894 | 894 | }
|
| 895 | 895 | |
| 896 | 896 | // Allocate a suitably-sized array...
|
| 897 | - StgMutArrPtrs *arr = allocateMutArrPtrs(cap, n_threads, cap->r.rCCCS);
|
|
| 897 | + StgMutArrPtrs *arr = allocateMutArrPtrs(cap, n_threads, NULL, cap->r.rCCCS);
|
|
| 898 | 898 | if (RTS_UNLIKELY(arr == NULL)) goto end;
|
| 899 | 899 | |
| 900 | 900 | // Populate it...
|
| ... | ... | @@ -146,7 +146,7 @@ scheduleFinalizers(Capability *cap, StgWeak *list) |
| 146 | 146 | |
| 147 | 147 | debugTrace(DEBUG_weak, "weak: batching %d finalizers", n);
|
| 148 | 148 | |
| 149 | - StgMutArrPtrs *arr = allocateMutArrPtrs(cap, n, CCS_SYSTEM_OR_NULL);
|
|
| 149 | + StgMutArrPtrs *arr = allocateMutArrPtrs(cap, n, NULL, CCS_SYSTEM_OR_NULL);
|
|
| 150 | 150 | if (RTS_UNLIKELY(arr == NULL)) exitHeapOverflow();
|
| 151 | 151 | // No write barrier needed here; this array is only going to referred to by this core.
|
| 152 | 152 | SET_INFO((StgClosure *) arr, &stg_MUT_ARR_PTRS_FROZEN_CLEAN_info);
|