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

Unified Diff: src/heap/array-buffer-tracker-inl.h

Issue 2024063002: Reland "[heap] Fine-grained JSArrayBuffer tracking" (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: bugfix and test added Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/heap/array-buffer-tracker.cc ('k') | src/heap/heap.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/heap/array-buffer-tracker-inl.h
diff --git a/src/heap/array-buffer-tracker-inl.h b/src/heap/array-buffer-tracker-inl.h
new file mode 100644
index 0000000000000000000000000000000000000000..0c74215d8d29ce38cfd4dd41a0dae4527b2526cc
--- /dev/null
+++ b/src/heap/array-buffer-tracker-inl.h
@@ -0,0 +1,93 @@
+// Copyright 2016 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "src/heap/array-buffer-tracker.h"
+#include "src/heap/heap.h"
+#include "src/heap/mark-compact.h"
+#include "src/isolate.h"
+
+namespace v8 {
+namespace internal {
+
+template <typename Callback>
+void LocalArrayBufferTracker::Process(Callback callback) {
+ JSArrayBuffer* new_buffer = nullptr;
+ size_t freed_memory = 0;
+ for (TrackingMap::iterator it = live_.begin(); it != live_.end();) {
+ switch (callback(it->first, &new_buffer)) {
+ case kKeepEntry:
+ it++;
+ break;
+ case kKeepAndUpdateEntry:
+ DCHECK_NOT_NULL(new_buffer);
+ if (Marking::IsBlack(Marking::MarkBitFrom(new_buffer))) {
Hannes Payer (out of office) 2016/05/31 08:03:50 Is Black or Grey?
Michael Lippautz 2016/05/31 08:17:07 As discussed offline: Grey means it's on the marki
+ Page::FromAddress(new_buffer->address())
+ ->local_tracker<Page::kCreateIfNotPresent>()
+ ->AddLive(new_buffer, it->second);
+ } else {
+ Page::FromAddress(new_buffer->address())
+ ->local_tracker<Page::kCreateIfNotPresent>()
+ ->Add(new_buffer, it->second);
+ }
+ live_.erase(it++);
+ break;
+ case kRemoveEntry:
+ heap_->isolate()->array_buffer_allocator()->Free(it->second.first,
+ it->second.second);
+ freed_memory += it->second.second;
+ live_.erase(it++);
+ break;
+ default:
+ UNREACHABLE();
+ }
+ }
+ if (freed_memory > 0) {
+ heap_->update_amount_of_external_allocated_freed_memory(
+ static_cast<intptr_t>(freed_memory));
+ }
+ not_yet_discovered_.clear();
+ started_ = false;
+}
+
+template <LocalArrayBufferTracker::LivenessIndicator liveness_indicator>
+void LocalArrayBufferTracker::ScanAndFreeDead() {
+ switch (liveness_indicator) {
+ case kForwardingPointer:
+ Process([](JSArrayBuffer* old_buffer, JSArrayBuffer** new_buffer) {
+ MapWord map_word = old_buffer->map_word();
+ if (map_word.IsForwardingAddress()) {
+ *new_buffer = JSArrayBuffer::cast(map_word.ToForwardingAddress());
+ return LocalArrayBufferTracker::kKeepAndUpdateEntry;
+ }
+ return LocalArrayBufferTracker::kRemoveEntry;
+ });
+ break;
+ case kMarkBit:
+ Process([](JSArrayBuffer* old_buffer, JSArrayBuffer**) {
+ if (Marking::IsBlackOrGrey(Marking::MarkBitFrom(old_buffer))) {
+ return LocalArrayBufferTracker::kKeepEntry;
+ }
+ return LocalArrayBufferTracker::kRemoveEntry;
+ });
+ break;
+ case kForwardingPointerOrMarkBit:
+ Process([](JSArrayBuffer* old_buffer, JSArrayBuffer** new_buffer) {
+ if (Marking::IsBlackOrGrey(Marking::MarkBitFrom(old_buffer))) {
+ return LocalArrayBufferTracker::kKeepEntry;
+ }
+ MapWord map_word = old_buffer->map_word();
+ if (map_word.IsForwardingAddress()) {
+ *new_buffer = JSArrayBuffer::cast(map_word.ToForwardingAddress());
+ return LocalArrayBufferTracker::kKeepAndUpdateEntry;
+ }
+ return LocalArrayBufferTracker::kRemoveEntry;
+ });
+ break;
+ default:
+ UNREACHABLE();
+ }
+}
+
+} // namespace internal
+} // namespace v8
« no previous file with comments | « src/heap/array-buffer-tracker.cc ('k') | src/heap/heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698