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

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

Issue 2105273002: Revert of [heap] Optimize ArrayBuffer tracking (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 5 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/array-buffer-tracker-inl.h » ('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 8
9 namespace v8 { 9 namespace v8 {
10 namespace internal { 10 namespace internal {
11 11
12 LocalArrayBufferTracker::~LocalArrayBufferTracker() { 12 LocalArrayBufferTracker::~LocalArrayBufferTracker() {
13 CHECK(array_buffers_.empty()); 13 CHECK(array_buffers_.empty());
14 } 14 }
15 15
16 template <LocalArrayBufferTracker::FreeMode free_mode> 16 template <LocalArrayBufferTracker::FreeMode free_mode>
17 void LocalArrayBufferTracker::Free() { 17 void LocalArrayBufferTracker::Free() {
18 size_t freed_memory = 0; 18 size_t freed_memory = 0;
19 for (TrackingData::iterator it = array_buffers_.begin(); 19 for (TrackingMap::iterator it = array_buffers_.begin();
20 it != array_buffers_.end();) { 20 it != array_buffers_.end();) {
21 JSArrayBuffer* buffer = reinterpret_cast<JSArrayBuffer*>(*it);
22 if ((free_mode == kFreeAll) || 21 if ((free_mode == kFreeAll) ||
23 Marking::IsWhite(Marking::MarkBitFrom(buffer))) { 22 Marking::IsWhite(Marking::MarkBitFrom(it->first))) {
24 const size_t len = NumberToSize(heap_->isolate(), buffer->byte_length()); 23 heap_->isolate()->array_buffer_allocator()->Free(it->second.first,
25 heap_->isolate()->array_buffer_allocator()->Free(buffer->backing_store(), 24 it->second.second);
26 len); 25 freed_memory += it->second.second;
27 freed_memory += len;
28 it = array_buffers_.erase(it); 26 it = array_buffers_.erase(it);
29 } else { 27 } else {
30 ++it; 28 it++;
31 } 29 }
32 } 30 }
33 if (freed_memory > 0) { 31 if (freed_memory > 0) {
34 heap_->update_external_memory_concurrently_freed( 32 heap_->update_external_memory_concurrently_freed(
35 static_cast<intptr_t>(freed_memory)); 33 static_cast<intptr_t>(freed_memory));
36 } 34 }
37 } 35 }
38 36
39 template <typename Callback> 37 template <typename Callback>
40 void LocalArrayBufferTracker::Process(Callback callback) { 38 void LocalArrayBufferTracker::Process(Callback callback) {
41 JSArrayBuffer* new_buffer = nullptr; 39 JSArrayBuffer* new_buffer = nullptr;
42 size_t freed_memory = 0; 40 size_t freed_memory = 0;
43 for (TrackingData::iterator it = array_buffers_.begin(); 41 for (TrackingMap::iterator it = array_buffers_.begin();
44 it != array_buffers_.end();) { 42 it != array_buffers_.end();) {
45 const CallbackResult result = callback(*it, &new_buffer); 43 const CallbackResult result = callback(it->first, &new_buffer);
46 if (result == kKeepEntry) { 44 if (result == kKeepEntry) {
47 ++it; 45 it++;
48 } else if (result == kUpdateEntry) { 46 } else if (result == kUpdateEntry) {
49 DCHECK_NOT_NULL(new_buffer); 47 DCHECK_NOT_NULL(new_buffer);
50 Page* target_page = Page::FromAddress(new_buffer->address()); 48 Page* target_page = Page::FromAddress(new_buffer->address());
51 // We need to lock the target page because we cannot guarantee 49 // We need to lock the target page because we cannot guarantee
52 // exclusive access to new space pages. 50 // exclusive access to new space pages.
53 if (target_page->InNewSpace()) target_page->mutex()->Lock(); 51 if (target_page->InNewSpace()) target_page->mutex()->Lock();
54 LocalArrayBufferTracker* tracker = target_page->local_tracker(); 52 LocalArrayBufferTracker* tracker = target_page->local_tracker();
55 if (tracker == nullptr) { 53 if (tracker == nullptr) {
56 target_page->AllocateLocalTracker(); 54 target_page->AllocateLocalTracker();
57 tracker = target_page->local_tracker(); 55 tracker = target_page->local_tracker();
58 } 56 }
59 DCHECK_NOT_NULL(tracker); 57 DCHECK_NOT_NULL(tracker);
60 tracker->Add(new_buffer); 58 tracker->Add(new_buffer, it->second);
61 if (target_page->InNewSpace()) target_page->mutex()->Unlock(); 59 if (target_page->InNewSpace()) target_page->mutex()->Unlock();
62 it = array_buffers_.erase(it); 60 it = array_buffers_.erase(it);
63 } else if (result == kRemoveEntry) { 61 } else if (result == kRemoveEntry) {
64 const size_t len = NumberToSize(heap_->isolate(), (*it)->byte_length()); 62 heap_->isolate()->array_buffer_allocator()->Free(it->second.first,
65 heap_->isolate()->array_buffer_allocator()->Free((*it)->backing_store(), 63 it->second.second);
66 len); 64 freed_memory += it->second.second;
67 freed_memory += len;
68 it = array_buffers_.erase(it); 65 it = array_buffers_.erase(it);
69 } else { 66 } else {
70 UNREACHABLE(); 67 UNREACHABLE();
71 } 68 }
72 } 69 }
73 if (freed_memory > 0) { 70 if (freed_memory > 0) {
74 heap_->update_external_memory_concurrently_freed( 71 heap_->update_external_memory_concurrently_freed(
75 static_cast<intptr_t>(freed_memory)); 72 static_cast<intptr_t>(freed_memory));
76 } 73 }
77 } 74 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 { 127 {
131 base::LockGuard<base::Mutex> guard(page->mutex()); 128 base::LockGuard<base::Mutex> guard(page->mutex());
132 LocalArrayBufferTracker* tracker = page->local_tracker(); 129 LocalArrayBufferTracker* tracker = page->local_tracker();
133 if (tracker == nullptr) return false; 130 if (tracker == nullptr) return false;
134 return tracker->IsTracked(buffer); 131 return tracker->IsTracked(buffer);
135 } 132 }
136 } 133 }
137 134
138 } // namespace internal 135 } // namespace internal
139 } // namespace v8 136 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/array-buffer-tracker.h ('k') | src/heap/array-buffer-tracker-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698