[heap] Prevent direct access to StoreBuffer.
authormstarzinger <mstarzinger@chromium.org>
Tue, 25 Aug 2015 13:38:45 +0000 (06:38 -0700)
committerCommit bot <commit-bot@chromium.org>
Tue, 25 Aug 2015 13:38:52 +0000 (13:38 +0000)
R=mlippautz@chromium.org

Review URL: https://codereview.chromium.org/1317553002

Cr-Commit-Position: refs/heads/master@{#30355}

src/assembler.cc
src/heap/heap.h
src/heap/mark-compact.cc
src/heap/mark-compact.h
src/heap/store-buffer-inl.h
src/heap/store-buffer.cc
src/heap/store-buffer.h

index b7550bb..fa7c26b 100644 (file)
@@ -1141,7 +1141,7 @@ ExternalReference ExternalReference::new_space_start(Isolate* isolate) {
 
 
 ExternalReference ExternalReference::store_buffer_top(Isolate* isolate) {
-  return ExternalReference(isolate->heap()->store_buffer()->TopAddress());
+  return ExternalReference(isolate->heap()->store_buffer_top_address());
 }
 
 
index 5401857..fd74ff2 100644 (file)
@@ -994,10 +994,6 @@ class Heap {
     roots_[kEmptyScriptRootIndex] = script;
   }
 
-  void public_set_store_buffer_top(Address* top) {
-    roots_[kStoreBufferTopRootIndex] = reinterpret_cast<Smi*>(top);
-  }
-
   void public_set_materialized_objects(FixedArray* objects) {
     roots_[kMaterializedObjectsRootIndex] = objects;
   }
@@ -1005,10 +1001,6 @@ class Heap {
   // Generated code can embed this address to get access to the roots.
   Object** roots_array_start() { return roots_; }
 
-  Address* store_buffer_top_address() {
-    return reinterpret_cast<Address*>(&roots_[kStoreBufferTopRootIndex]);
-  }
-
   void CheckHandleCount();
 
   // Number of "runtime allocations" done so far.
@@ -1029,12 +1021,6 @@ class Heap {
     return index < OBJECT_STATS_COUNT ? object_sizes_last_time_[index] : 0;
   }
 
-  // Write barrier support for address[offset] = o.
-  INLINE(void RecordWrite(Address address, int offset));
-
-  // Write barrier support for address[start : start + len[ = o.
-  INLINE(void RecordWrites(Address address, int start, int len));
-
   inline HeapState gc_state() { return gc_state_; }
 
   inline bool IsInGCPostProcessing() { return gc_post_processing_depth_ > 0; }
@@ -1094,10 +1080,6 @@ class Heap {
 
   void IncrementDeferredCount(v8::Isolate::UseCounterFeature feature);
 
-  ExternalStringTable* external_string_table() {
-    return &external_string_table_;
-  }
-
   bool concurrent_sweeping_enabled() { return concurrent_sweeping_enabled_; }
 
   inline bool OldGenerationAllocationLimitReached();
@@ -1307,7 +1289,9 @@ class Heap {
     return &mark_compact_collector_;
   }
 
-  StoreBuffer* store_buffer() { return &store_buffer_; }
+  ExternalStringTable* external_string_table() {
+    return &external_string_table_;
+  }
 
   // ===========================================================================
   // Inline allocation. ========================================================
@@ -1365,6 +1349,20 @@ class Heap {
                                          ObjectSlotCallback callback);
 
   // ===========================================================================
+  // Store buffer API. =========================================================
+  // ===========================================================================
+
+  // Write barrier support for address[offset] = o.
+  INLINE(void RecordWrite(Address address, int offset));
+
+  // Write barrier support for address[start : start + len[ = o.
+  INLINE(void RecordWrites(Address address, int start, int len));
+
+  Address* store_buffer_top_address() {
+    return reinterpret_cast<Address*>(&roots_[kStoreBufferTopRootIndex]);
+  }
+
+  // ===========================================================================
   // Incremental marking API. ==================================================
   // ===========================================================================
 
@@ -1683,6 +1681,8 @@ class Heap {
   ROOT_LIST(ROOT_ACCESSOR)
 #undef ROOT_ACCESSOR
 
+  StoreBuffer* store_buffer() { return &store_buffer_; }
+
   void set_current_gc_flags(int flags) {
     current_gc_flags_ = flags;
     DCHECK(!ShouldFinalizeIncrementalMarking() ||
@@ -2411,6 +2411,7 @@ class Heap {
   friend class MarkCompactMarkingVisitor;
   friend class MapCompact;
   friend class Page;
+  friend class StoreBuffer;
 
   // Used in cctest.
   friend class HeapTester;
index 4c8db42..202f4db 100644 (file)
@@ -303,17 +303,17 @@ static void VerifyValidSlotsBufferEntries(Heap* heap, PagedSpace* space) {
 }
 
 
-static void VerifyValidStoreAndSlotsBufferEntries(Heap* heap) {
-  heap->store_buffer()->VerifyValidStoreBufferEntries();
+void MarkCompactCollector::VerifyValidStoreAndSlotsBufferEntries() {
+  heap()->store_buffer()->VerifyValidStoreBufferEntries();
 
-  VerifyValidSlotsBufferEntries(heap, heap->old_space());
-  VerifyValidSlotsBufferEntries(heap, heap->code_space());
-  VerifyValidSlotsBufferEntries(heap, heap->map_space());
+  VerifyValidSlotsBufferEntries(heap(), heap()->old_space());
+  VerifyValidSlotsBufferEntries(heap(), heap()->code_space());
+  VerifyValidSlotsBufferEntries(heap(), heap()->map_space());
 
-  LargeObjectIterator it(heap->lo_space());
+  LargeObjectIterator it(heap()->lo_space());
   for (HeapObject* object = it.Next(); object != NULL; object = it.Next()) {
     MemoryChunk* chunk = MemoryChunk::FromAddress(object->address());
-    SlotsBuffer::VerifySlots(heap, chunk->slots_buffer());
+    SlotsBuffer::VerifySlots(heap(), chunk->slots_buffer());
   }
 }
 #endif
@@ -349,7 +349,7 @@ void MarkCompactCollector::CollectGarbage() {
 
 #ifdef VERIFY_HEAP
   if (FLAG_verify_heap) {
-    VerifyValidStoreAndSlotsBufferEntries(heap_);
+    VerifyValidStoreAndSlotsBufferEntries();
   }
 #endif
 
index 843e73d..7e62012 100644 (file)
@@ -559,6 +559,7 @@ class MarkCompactCollector {
   enum SweepingParallelism { SWEEP_ON_MAIN_THREAD, SWEEP_IN_PARALLEL };
 
 #ifdef VERIFY_HEAP
+  void VerifyValidStoreAndSlotsBufferEntries();
   void VerifyMarkbitsAreClean();
   static void VerifyMarkbitsAreClean(PagedSpace* space);
   static void VerifyMarkbitsAreClean(NewSpace* space);
index 90f5476..230384a 100644 (file)
 namespace v8 {
 namespace internal {
 
-Address StoreBuffer::TopAddress() {
-  return reinterpret_cast<Address>(heap_->store_buffer_top_address());
-}
-
-
 void StoreBuffer::Mark(Address addr) {
   DCHECK(!heap_->code_space()->Contains(addr));
   Address* top = reinterpret_cast<Address*>(heap_->store_buffer_top());
   *top++ = addr;
-  heap_->public_set_store_buffer_top(top);
+  heap_->set_store_buffer_top(reinterpret_cast<Smi*>(top));
   if ((reinterpret_cast<uintptr_t>(top) & kStoreBufferOverflowBit) != 0) {
     DCHECK(top == limit_);
     Compact();
index 1c1676a..cb46ede 100644 (file)
@@ -88,7 +88,7 @@ void StoreBuffer::SetUp() {
                                false)) {  // Not executable.
     V8::FatalProcessOutOfMemory("StoreBuffer::SetUp");
   }
-  heap_->public_set_store_buffer_top(start_);
+  heap_->set_store_buffer_top(reinterpret_cast<Smi*>(start_));
 
   hash_set_1_ = new uintptr_t[kHashSetLength];
   hash_set_2_ = new uintptr_t[kHashSetLength];
@@ -105,7 +105,7 @@ void StoreBuffer::TearDown() {
   delete[] hash_set_2_;
   old_start_ = old_top_ = old_limit_ = old_reserved_limit_ = NULL;
   start_ = limit_ = NULL;
-  heap_->public_set_store_buffer_top(start_);
+  heap_->set_store_buffer_top(reinterpret_cast<Smi*>(start_));
 }
 
 
@@ -536,7 +536,7 @@ void StoreBuffer::Compact() {
   // There's no check of the limit in the loop below so we check here for
   // the worst case (compaction doesn't eliminate any pointers).
   DCHECK(top <= limit_);
-  heap_->public_set_store_buffer_top(start_);
+  heap_->set_store_buffer_top(reinterpret_cast<Smi*>(start_));
   EnsureSpace(top - start_);
   DCHECK(may_move_store_buffer_entries_);
   // Goes through the addresses in the store buffer attempting to remove
index 158c725..cb96fa9 100644 (file)
@@ -30,8 +30,6 @@ class StoreBuffer {
 
   static void StoreBufferOverflow(Isolate* isolate);
 
-  inline Address TopAddress();
-
   void SetUp();
   void TearDown();