[heap] Use CAS for incrementing MemoryChunk::live_byte_count_

Experimenting with incrementing live_byte_count_ using a relaxed CAS
operation. If no regression is found, we could get away with background
threads increasing that counter directly, instead of using separate
counters like concurrent markers.

Bug: v8:10315
Change-Id: I2e7a1f941a728f59d6e1fbd686d2eeb01ea4378a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2201765
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67809}
diff --git a/src/heap/mark-compact.h b/src/heap/mark-compact.h
index 31657a5..7e7d7f6 100644
--- a/src/heap/mark-compact.h
+++ b/src/heap/mark-compact.h
@@ -303,15 +303,15 @@
   // Concurrent marking uses local live bytes so we may do these accesses
   // non-atomically.
   void IncrementLiveBytes(MemoryChunk* chunk, intptr_t by) {
-    chunk->live_byte_count_ += by;
+    chunk->live_byte_count_.fetch_add(by, std::memory_order_relaxed);
   }
 
   intptr_t live_bytes(MemoryChunk* chunk) const {
-    return chunk->live_byte_count_;
+    return chunk->live_byte_count_.load(std::memory_order_relaxed);
   }
 
   void SetLiveBytes(MemoryChunk* chunk, intptr_t value) {
-    chunk->live_byte_count_ = value;
+    chunk->live_byte_count_.store(value, std::memory_order_relaxed);
   }
 };
 
@@ -328,8 +328,7 @@
   }
 
   void IncrementLiveBytes(MemoryChunk* chunk, intptr_t by) {
-    std::atomic_fetch_add(
-        reinterpret_cast<std::atomic<intptr_t>*>(&chunk->live_byte_count_), by);
+    chunk->live_byte_count_.fetch_add(by);
   }
 };
 
@@ -346,15 +345,15 @@
   }
 
   void IncrementLiveBytes(MemoryChunk* chunk, intptr_t by) {
-    chunk->live_byte_count_ += by;
+    chunk->live_byte_count_.fetch_add(by, std::memory_order_relaxed);
   }
 
   intptr_t live_bytes(MemoryChunk* chunk) const {
-    return chunk->live_byte_count_;
+    return chunk->live_byte_count_.load(std::memory_order_relaxed);
   }
 
   void SetLiveBytes(MemoryChunk* chunk, intptr_t value) {
-    chunk->live_byte_count_ = value;
+    chunk->live_byte_count_.store(value, std::memory_order_relaxed);
   }
 };
 
diff --git a/src/heap/memory-chunk.h b/src/heap/memory-chunk.h
index 37dd25c..f80107c 100644
--- a/src/heap/memory-chunk.h
+++ b/src/heap/memory-chunk.h
@@ -410,7 +410,7 @@
   std::atomic<size_t> progress_bar_;
 
   // Count of bytes marked black on page.
-  intptr_t live_byte_count_;
+  std::atomic<intptr_t> live_byte_count_;
 
   // A single slot set for small pages (of size kPageSize) or an array of slot
   // set for large pages. In the latter case the number of entries in the array