Reviewers: Michael Lippautz,

Description:
[heap] Prevent direct access to StoreBuffer.

[email protected]

Please review this at https://codereview.chromium.org/1317553002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+34, -39 lines):
  M src/assembler.cc
  M src/heap/heap.h
  M src/heap/mark-compact.h
  M src/heap/mark-compact.cc
  M src/heap/store-buffer.h
  M src/heap/store-buffer.cc
  M src/heap/store-buffer-inl.h


Index: src/assembler.cc
diff --git a/src/assembler.cc b/src/assembler.cc
index b7550bb79594f04ef715289096030ecb20334802..fa7c26b17b8ab51d3ce441a4771607b3678751bb 100644
--- a/src/assembler.cc
+++ b/src/assembler.cc
@@ -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: src/heap/heap.h
diff --git a/src/heap/heap.h b/src/heap/heap.h
index 5c825e77804ad06cd30b1f3ae3ae6b4d562bcd86..c65397b11afa8f11bc6b3e1e0d12eb13b8b9f007 100644
--- a/src/heap/heap.h
+++ b/src/heap/heap.h
@@ -982,10 +982,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;
   }
@@ -993,10 +989,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.
@@ -1017,12 +1009,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; }
@@ -1082,10 +1068,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();
@@ -1295,7 +1277,9 @@ class Heap {
     return &mark_compact_collector_;
   }

-  StoreBuffer* store_buffer() { return &store_buffer_; }
+  ExternalStringTable* external_string_table() {
+    return &external_string_table_;
+  }

// =========================================================================== // Inline allocation. ========================================================
@@ -1353,6 +1337,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. ================================================== // ===========================================================================

@@ -1670,6 +1668,8 @@ class Heap {
   ROOT_LIST(ROOT_ACCESSOR)
 #undef ROOT_ACCESSOR

+  StoreBuffer* store_buffer() { return &store_buffer_; }
+
   int current_gc_flags() { return current_gc_flags_; }

   void set_current_gc_flags(int flags) {
@@ -2396,6 +2396,7 @@ class Heap {
   friend class MarkCompactMarkingVisitor;
   friend class MapCompact;
   friend class Page;
+  friend class StoreBuffer;

   // Used in cctest.
   friend class HeapTester;
Index: src/heap/mark-compact.cc
diff --git a/src/heap/mark-compact.cc b/src/heap/mark-compact.cc
index 4c8db42035bb8c5722fe9b2fbe73b35d87f43f54..202f4db575516b75235d1ddf9cb3154da8a3b1c7 100644
--- a/src/heap/mark-compact.cc
+++ b/src/heap/mark-compact.cc
@@ -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: src/heap/mark-compact.h
diff --git a/src/heap/mark-compact.h b/src/heap/mark-compact.h
index 843e73d8e7dfa7d026036e70a8c80d9cd206204f..7e62012537905b35a22942abefad1782ffff4a7c 100644
--- a/src/heap/mark-compact.h
+++ b/src/heap/mark-compact.h
@@ -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: src/heap/store-buffer-inl.h
diff --git a/src/heap/store-buffer-inl.h b/src/heap/store-buffer-inl.h
index 90f54766d2ba1bae3434f3ce6dbfc866548356b7..230384af7a34f74ce42281308512b74af0df68e7 100644
--- a/src/heap/store-buffer-inl.h
+++ b/src/heap/store-buffer-inl.h
@@ -12,16 +12,11 @@
 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: src/heap/store-buffer.cc
diff --git a/src/heap/store-buffer.cc b/src/heap/store-buffer.cc
index 1c1676a229fc00d21c0f8634b1bc0d5da99f6ef1..cb46edeb468ef1c605800becb1720f0d1e5a0724 100644
--- a/src/heap/store-buffer.cc
+++ b/src/heap/store-buffer.cc
@@ -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: src/heap/store-buffer.h
diff --git a/src/heap/store-buffer.h b/src/heap/store-buffer.h
index 158c7258153450ce5554aed051a8c1e35c6b294d..cb96fa9720a64909fbd1dcf04917f0018f095a08 100644
--- a/src/heap/store-buffer.h
+++ b/src/heap/store-buffer.h
@@ -30,8 +30,6 @@ class StoreBuffer {

   static void StoreBufferOverflow(Isolate* isolate);

-  inline Address TopAddress();
-
   void SetUp();
   void TearDown();



--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to