Commit 4cb5595e authored by Simon Marlow's avatar Simon Marlow Committed by Simon Marlow

storageAddCapabilities: fix bug in updating nursery pointers

Summary:
We were unconditionally updating the nursery pointers to be
`nurseries[cap->no]`, but when using nursery chunks this might be
wrong. This manifested as a later assertion failure in allocate().

Test Plan: new test case

Reviewers: bgamari, niteria, erikd

Subscribers: thomie, carter

Differential Revision: https://phabricator.haskell.org/D4649
parent dc655bf0
......@@ -220,6 +220,7 @@ initStorage (void)
void storageAddCapabilities (uint32_t from, uint32_t to)
{
uint32_t n, g, i, new_n_nurseries;
nursery *old_nurseries;
if (RtsFlags.GcFlags.nurseryChunkSize == 0) {
new_n_nurseries = to;
......@@ -229,6 +230,7 @@ void storageAddCapabilities (uint32_t from, uint32_t to)
stg_max(to, total_alloc / RtsFlags.GcFlags.nurseryChunkSize);
}
old_nurseries = nurseries;
if (from > 0) {
nurseries = stgReallocBytes(nurseries,
new_n_nurseries * sizeof(struct nursery_),
......@@ -240,8 +242,9 @@ void storageAddCapabilities (uint32_t from, uint32_t to)
// we've moved the nurseries, so we have to update the rNursery
// pointers from the Capabilities.
for (i = 0; i < to; i++) {
capabilities[i]->r.rNursery = &nurseries[i];
for (i = 0; i < from; i++) {
uint32_t index = capabilities[i]->r.rNursery - old_nurseries;
capabilities[i]->r.rNursery = &nurseries[index];
}
/* The allocation area. Policy: keep the allocation area
......
......@@ -402,3 +402,10 @@ test('alloccounter1', normal, compile_and_run,
# allocation and messes up the results:
'-with-rtsopts=-k1m'
])
test('nursery-chunks1',
[ extra_run_opts('4 100 +RTS -n32k -A1m -RTS')
, only_ways(['threaded1','threaded2'])
],
compile_and_run,
[''])
-- Test for a bug that provoked the following assertion failure:
-- nursery-chunks1: internal error: ASSERTION FAILED: file rts/sm/Sanity.c, line 903
module Main (main) where
import Control.Monad
import System.Environment
import GHC.Conc
main = do
[n,m] <- fmap read <$> getArgs
forM_ [1..n] $ \n' ->
when (sum [1.. m::Integer] > 0) $ setNumCapabilities (fromIntegral n')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment