NonMoving: Introduce nonmovingSegmentLogBlockSize acccessor
authorBen Gamari <ben@smart-cactus.org>
Fri, 17 May 2019 17:18:48 +0000 (13:18 -0400)
committerBen Gamari <ben@smart-cactus.org>
Wed, 19 Jun 2019 01:42:57 +0000 (21:42 -0400)
This will allow us to easily move the block size elsewhere.

rts/sm/NonMoving.c
rts/sm/NonMoving.h
rts/sm/NonMovingMark.c

index 9d8bbc9..45f4e1e 100644 (file)
@@ -203,13 +203,13 @@ static void* nonmovingConcurrentMark(void *mark_queue);
 static void nonmovingClearBitmap(struct NonmovingSegment *seg);
 static void nonmovingMark_(MarkQueue *mark_queue, StgWeak **dead_weaks, StgTSO **resurrected_threads);
 
-static void nonmovingInitSegment(struct NonmovingSegment *seg, uint8_t block_size)
+static void nonmovingInitSegment(struct NonmovingSegment *seg, uint8_t log_block_size)
 {
     seg->link = NULL;
     seg->todo_link = NULL;
     seg->next_free = 0;
     seg->next_free_snap = 0;
-    seg->block_size = block_size;
+    seg->log_block_size = log_block_size;
     nonmovingClearBitmap(seg);
     Bdescr((P_)seg)->u.scan = nonmovingSegmentGetBlock(seg, 0);
 }
@@ -957,12 +957,13 @@ void assert_in_nonmoving_heap(StgPtr p)
 void nonmovingPrintSegment(struct NonmovingSegment *seg)
 {
     int num_blocks = nonmovingSegmentBlockCount(seg);
+    uint8_t log_block_size = nonmovingSegmentLogBlockSize(seg);
 
     debugBelch("Segment with %d blocks of size 2^%d (%d bytes, %lu words, scan: %p)\n",
                num_blocks,
-               seg->block_size,
-               1 << seg->block_size,
-               ROUNDUP_BYTES_TO_WDS(1 << seg->block_size),
+               log_block_size,
+               1 << log_block_size,
+               ROUNDUP_BYTES_TO_WDS(1 << log_block_size),
                (void*)Bdescr((P_)seg)->u.scan);
 
     for (nonmoving_block_idx p_idx = 0; p_idx < seg->next_free; ++p_idx) {
index cbc8040..3143d72 100644 (file)
@@ -39,7 +39,7 @@ struct NonmovingSegment {
     struct NonmovingSegment *todo_link; // NULL when not in todo list
     nonmoving_block_idx next_free;      // index of the next unallocated block
     nonmoving_block_idx next_free_snap; // snapshot of next_free
-    uint8_t block_size;                 // log2 of block size in bytes
+    uint8_t log_block_size;             // log2 of block size in bytes
     uint8_t bitmap[];                   // liveness bitmap
     // After the liveness bitmap comes the data blocks. Note that we need to
     // ensure that the size of this struct (including the bitmap) is a multiple
@@ -121,11 +121,15 @@ void *nonmovingAllocate(Capability *cap, StgWord sz);
 void nonmovingAddCapabilities(uint32_t new_n_caps);
 void nonmovingPushFreeSegment(struct NonmovingSegment *seg);
 
+INLINE_HEADER uint8_t nonmovingSegmentLogBlockSize(struct NonmovingSegment *seg) {
+    return seg->log_block_size;
+}
+
 // Add a segment to the appropriate active list.
 INLINE_HEADER void nonmovingPushActiveSegment(struct NonmovingSegment *seg)
 {
     struct NonmovingAllocator *alloc =
-        nonmovingHeap.allocators[seg->block_size - NONMOVING_ALLOCA0];
+        nonmovingHeap.allocators[nonmovingSegmentLogBlockSize(seg) - NONMOVING_ALLOCA0];
     while (true) {
         struct NonmovingSegment *current_active = (struct NonmovingSegment*)VOLATILE_LOAD(&alloc->active);
         seg->link = current_active;
@@ -139,7 +143,7 @@ INLINE_HEADER void nonmovingPushActiveSegment(struct NonmovingSegment *seg)
 INLINE_HEADER void nonmovingPushFilledSegment(struct NonmovingSegment *seg)
 {
     struct NonmovingAllocator *alloc =
-        nonmovingHeap.allocators[seg->block_size - NONMOVING_ALLOCA0];
+        nonmovingHeap.allocators[nonmovingSegmentLogBlockSize(seg) - NONMOVING_ALLOCA0];
     while (true) {
         struct NonmovingSegment *current_filled = (struct NonmovingSegment*)VOLATILE_LOAD(&alloc->filled);
         seg->link = current_filled;
@@ -160,7 +164,7 @@ void assert_in_nonmoving_heap(StgPtr p);
 // The block size of a given segment in bytes.
 INLINE_HEADER unsigned int nonmovingSegmentBlockSize(struct NonmovingSegment *seg)
 {
-    return 1 << seg->block_size;
+    return 1 << nonmovingSegmentLogBlockSize(seg);
 }
 
 // How many blocks does a segment with the given block size have?
@@ -178,7 +182,7 @@ unsigned int nonmovingBlockCountFromSize(uint8_t log_block_size);
 // How many blocks does the given segment contain? Also the size of the bitmap.
 INLINE_HEADER unsigned int nonmovingSegmentBlockCount(struct NonmovingSegment *seg)
 {
-  return nonmovingBlockCountFromSize(seg->block_size);
+  return nonmovingBlockCountFromSize(nonmovingSegmentLogBlockSize(seg));
 }
 
 // Get a pointer to the given block index assuming that the block size is as
@@ -186,7 +190,7 @@ INLINE_HEADER unsigned int nonmovingSegmentBlockCount(struct NonmovingSegment *s
 // available). The log_block_size argument must be equal to seg->block_size.
 INLINE_HEADER void *nonmovingSegmentGetBlock_(struct NonmovingSegment *seg, uint8_t log_block_size, nonmoving_block_idx i)
 {
-  ASSERT(log_block_size == seg->block_size);
+  ASSERT(log_block_size == nonmovingSegmentLogBlockSize(seg));
   // Block size in bytes
   unsigned int blk_size = 1 << log_block_size;
   // Bitmap size in bytes
@@ -202,7 +206,7 @@ INLINE_HEADER void *nonmovingSegmentGetBlock_(struct NonmovingSegment *seg, uint
 // Get a pointer to the given block index.
 INLINE_HEADER void *nonmovingSegmentGetBlock(struct NonmovingSegment *seg, nonmoving_block_idx i)
 {
-  return nonmovingSegmentGetBlock_(seg, seg->block_size, i);
+  return nonmovingSegmentGetBlock_(seg, nonmovingSegmentLogBlockSize(seg), i);
 }
 
 // Get the segment which a closure resides in. Assumes that pointer points into
@@ -225,7 +229,7 @@ INLINE_HEADER nonmoving_block_idx nonmovingGetBlockIdx(StgPtr p)
     struct NonmovingSegment *seg = nonmovingGetSegment(p);
     ptrdiff_t blk0 = (ptrdiff_t)nonmovingSegmentGetBlock(seg, 0);
     ptrdiff_t offset = (ptrdiff_t)p - blk0;
-    return (nonmoving_block_idx) (offset >> seg->block_size);
+    return (nonmoving_block_idx) (offset >> nonmovingSegmentLogBlockSize(seg));
 }
 
 // TODO: Eliminate this
index e6e34fe..4997de1 100644 (file)
@@ -769,7 +769,7 @@ static MarkQueueEnt markQueuePop (MarkQueue *q)
         // MarkQueueEnt encoding always places the pointer to the object to be
         // marked first.
         prefetchForRead(&new.mark_closure.p->header.info);
-        prefetchForRead(&nonmovingGetSegment_unchecked((StgPtr) new.mark_closure.p)->block_size);
+        prefetchForRead(&nonmovingGetSegment_unchecked((StgPtr) new.mark_closure.p)->log_block_size);
         q->prefetch_queue[i] = new;
         i = (i + 1) % MARK_PREFETCH_QUEUE_DEPTH;
     }