summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rts/sm/Storage.c7
-rw-r--r--testsuite/tests/rts/all.T7
-rw-r--r--testsuite/tests/rts/nursery-chunks1.hs12
3 files changed, 24 insertions, 2 deletions
diff --git a/rts/sm/Storage.c b/rts/sm/Storage.c
index 9174646899..52dab73709 100644
--- a/rts/sm/Storage.c
+++ b/rts/sm/Storage.c
@@ -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
diff --git a/testsuite/tests/rts/all.T b/testsuite/tests/rts/all.T
index a2783887af..8fa2257b1c 100644
--- a/testsuite/tests/rts/all.T
+++ b/testsuite/tests/rts/all.T
@@ -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,
+ [''])
diff --git a/testsuite/tests/rts/nursery-chunks1.hs b/testsuite/tests/rts/nursery-chunks1.hs
new file mode 100644
index 0000000000..f8f9f6a7fa
--- /dev/null
+++ b/testsuite/tests/rts/nursery-chunks1.hs
@@ -0,0 +1,12 @@
+-- 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')