Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: src/heap/array-buffer-tracker.cc

Issue 2870683003: [heap] Factor out marking state of array buffer tracker (Closed)
Patch Set: Get MarkingState out of thin air Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/heap/array-buffer-tracker.h ('k') | src/heap/mark-compact.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/heap/array-buffer-tracker.h" 5 #include "src/heap/array-buffer-tracker.h"
6 #include "src/heap/array-buffer-tracker-inl.h" 6 #include "src/heap/array-buffer-tracker-inl.h"
7 #include "src/heap/heap.h" 7 #include "src/heap/heap.h"
8 #include "src/heap/spaces.h"
8 9
9 namespace v8 { 10 namespace v8 {
10 namespace internal { 11 namespace internal {
11 12
12 LocalArrayBufferTracker::~LocalArrayBufferTracker() { 13 LocalArrayBufferTracker::~LocalArrayBufferTracker() {
13 CHECK(array_buffers_.empty()); 14 CHECK(array_buffers_.empty());
14 } 15 }
15 16
16 template <LocalArrayBufferTracker::FreeMode free_mode> 17 template <typename Callback>
17 void LocalArrayBufferTracker::Free() { 18 void LocalArrayBufferTracker::Free(Callback should_free) {
18 size_t freed_memory = 0; 19 size_t freed_memory = 0;
19 for (TrackingData::iterator it = array_buffers_.begin(); 20 for (TrackingData::iterator it = array_buffers_.begin();
20 it != array_buffers_.end();) { 21 it != array_buffers_.end();) {
21 JSArrayBuffer* buffer = reinterpret_cast<JSArrayBuffer*>(it->first); 22 JSArrayBuffer* buffer = reinterpret_cast<JSArrayBuffer*>(it->first);
22 // TODO(mlippautz): Create a dependency on the collector to avoid getting 23 if (should_free(buffer)) {
23 // the marking state out of thin air.
24 if ((free_mode == kFreeAll) ||
25 ObjectMarking::IsWhite(buffer, MarkingState::Internal(buffer))) {
26 const size_t len = it->second; 24 const size_t len = it->second;
27 heap_->isolate()->array_buffer_allocator()->Free(buffer->backing_store(), 25 heap_->isolate()->array_buffer_allocator()->Free(buffer->backing_store(),
28 len); 26 len);
29 freed_memory += len; 27 freed_memory += len;
30 it = array_buffers_.erase(it); 28 it = array_buffers_.erase(it);
31 } else { 29 } else {
32 ++it; 30 ++it;
33 } 31 }
34 } 32 }
35 if (freed_memory > 0) { 33 if (freed_memory > 0) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 void ArrayBufferTracker::FreeDeadInNewSpace(Heap* heap) { 79 void ArrayBufferTracker::FreeDeadInNewSpace(Heap* heap) {
82 DCHECK_EQ(heap->gc_state(), Heap::HeapState::SCAVENGE); 80 DCHECK_EQ(heap->gc_state(), Heap::HeapState::SCAVENGE);
83 for (Page* page : PageRange(heap->new_space()->FromSpaceStart(), 81 for (Page* page : PageRange(heap->new_space()->FromSpaceStart(),
84 heap->new_space()->FromSpaceEnd())) { 82 heap->new_space()->FromSpaceEnd())) {
85 bool empty = ProcessBuffers(page, kUpdateForwardedRemoveOthers); 83 bool empty = ProcessBuffers(page, kUpdateForwardedRemoveOthers);
86 CHECK(empty); 84 CHECK(empty);
87 } 85 }
88 heap->account_external_memory_concurrently_freed(); 86 heap->account_external_memory_concurrently_freed();
89 } 87 }
90 88
91 void ArrayBufferTracker::FreeDead(Page* page) { 89 void ArrayBufferTracker::FreeDead(Page* page,
90 const MarkingState& marking_state) {
92 // Callers need to ensure having the page lock. 91 // Callers need to ensure having the page lock.
93 LocalArrayBufferTracker* tracker = page->local_tracker(); 92 LocalArrayBufferTracker* tracker = page->local_tracker();
94 if (tracker == nullptr) return; 93 if (tracker == nullptr) return;
95 DCHECK(!page->SweepingDone()); 94 tracker->Free([&marking_state](JSArrayBuffer* buffer) {
96 tracker->Free<LocalArrayBufferTracker::kFreeDead>(); 95 return ObjectMarking::IsWhite(buffer, marking_state);
96 });
97 if (tracker->IsEmpty()) { 97 if (tracker->IsEmpty()) {
98 page->ReleaseLocalTracker(); 98 page->ReleaseLocalTracker();
99 } 99 }
100 } 100 }
101 101
102 void ArrayBufferTracker::FreeAll(Page* page) { 102 void ArrayBufferTracker::FreeAll(Page* page) {
103 LocalArrayBufferTracker* tracker = page->local_tracker(); 103 LocalArrayBufferTracker* tracker = page->local_tracker();
104 if (tracker == nullptr) return; 104 if (tracker == nullptr) return;
105 tracker->Free<LocalArrayBufferTracker::kFreeAll>(); 105 tracker->Free([](JSArrayBuffer* buffer) { return true; });
106 if (tracker->IsEmpty()) { 106 if (tracker->IsEmpty()) {
107 page->ReleaseLocalTracker(); 107 page->ReleaseLocalTracker();
108 } 108 }
109 } 109 }
110 110
111 bool ArrayBufferTracker::ProcessBuffers(Page* page, ProcessingMode mode) { 111 bool ArrayBufferTracker::ProcessBuffers(Page* page, ProcessingMode mode) {
112 LocalArrayBufferTracker* tracker = page->local_tracker(); 112 LocalArrayBufferTracker* tracker = page->local_tracker();
113 if (tracker == nullptr) return true; 113 if (tracker == nullptr) return true;
114 114
115 DCHECK(page->SweepingDone()); 115 DCHECK(page->SweepingDone());
(...skipping 16 matching lines...) Expand all
132 { 132 {
133 base::LockGuard<base::RecursiveMutex> guard(page->mutex()); 133 base::LockGuard<base::RecursiveMutex> guard(page->mutex());
134 LocalArrayBufferTracker* tracker = page->local_tracker(); 134 LocalArrayBufferTracker* tracker = page->local_tracker();
135 if (tracker == nullptr) return false; 135 if (tracker == nullptr) return false;
136 return tracker->IsTracked(buffer); 136 return tracker->IsTracked(buffer);
137 } 137 }
138 } 138 }
139 139
140 } // namespace internal 140 } // namespace internal
141 } // namespace v8 141 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/array-buffer-tracker.h ('k') | src/heap/mark-compact.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698