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

Unified Diff: src/heap/heap.cc

Issue 1114563002: Remove the weak list of array buffers (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 5 years, 8 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/heap.h ('k') | src/heap/mark-compact.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/heap/heap.cc
diff --git a/src/heap/heap.cc b/src/heap/heap.cc
index 8d34738dae81757b9e5918875d6adf41cecf98bb..fac9535a6a6eeab7506cdaae951bd9051ddf5295 100644
--- a/src/heap/heap.cc
+++ b/src/heap/heap.cc
@@ -154,8 +154,6 @@ Heap::Heap()
memset(roots_, 0, sizeof(roots_[0]) * kRootListLength);
set_native_contexts_list(NULL);
- set_array_buffers_list(Smi::FromInt(0));
- set_last_array_buffer_in_list(Smi::FromInt(0));
set_allocation_sites_list(Smi::FromInt(0));
set_encountered_weak_collections(Smi::FromInt(0));
set_encountered_weak_cells(Smi::FromInt(0));
@@ -1705,64 +1703,67 @@ void Heap::UpdateReferencesInExternalStringTable(
void Heap::ProcessAllWeakReferences(WeakObjectRetainer* retainer) {
- ProcessArrayBuffers(retainer, false);
ProcessNativeContexts(retainer);
ProcessAllocationSites(retainer);
}
void Heap::ProcessYoungWeakReferences(WeakObjectRetainer* retainer) {
- ProcessArrayBuffers(retainer, true);
ProcessNativeContexts(retainer);
}
void Heap::ProcessNativeContexts(WeakObjectRetainer* retainer) {
- Object* head = VisitWeakList<Context>(this, native_contexts_list(), retainer,
- false, NULL);
+ Object* head = VisitWeakList<Context>(this, native_contexts_list(), retainer);
// Update the head of the list of contexts.
set_native_contexts_list(head);
}
-void Heap::ProcessArrayBuffers(WeakObjectRetainer* retainer,
- bool stop_after_young) {
- Object* last_array_buffer = undefined_value();
- Object* array_buffer_obj =
- VisitWeakList<JSArrayBuffer>(this, array_buffers_list(), retainer,
- stop_after_young, &last_array_buffer);
- set_array_buffers_list(array_buffer_obj);
- set_last_array_buffer_in_list(last_array_buffer);
-
- // Verify invariant that young array buffers come before old array buffers
- // in array buffers list if there was no promotion failure.
- Object* undefined = undefined_value();
- Object* next = array_buffers_list();
- bool old_objects_recorded = false;
- while (next != undefined) {
- if (!old_objects_recorded) {
- old_objects_recorded = !InNewSpace(next);
- }
- CHECK((InNewSpace(next) && !old_objects_recorded) || !InNewSpace(next));
- next = JSArrayBuffer::cast(next)->weak_next();
+void Heap::RegisterNewArrayBuffer(void* data, size_t length) {
+ live_array_buffers_[data] = length;
+ reinterpret_cast<v8::Isolate*>(isolate_)
+ ->AdjustAmountOfExternalAllocatedMemory(length);
+}
+
+
+void Heap::UnregisterArrayBuffer(void* data) {
+ DCHECK(live_array_buffers_.count(data) > 0);
+ live_array_buffers_.erase(data);
+ not_yet_discovered_array_buffers_.erase(data);
+}
+
+
+void Heap::RegisterLiveArrayBuffer(void* data) {
+ not_yet_discovered_array_buffers_.erase(data);
+}
+
+
+void Heap::FreeDeadArrayBuffers() {
+ for (auto buffer = not_yet_discovered_array_buffers_.begin();
+ buffer != not_yet_discovered_array_buffers_.end(); ++buffer) {
+ isolate_->array_buffer_allocator()->Free(buffer->first, buffer->second);
+ // Don't use the API method here since this could trigger another GC.
+ amount_of_external_allocated_memory_ -= buffer->second;
+ live_array_buffers_.erase(buffer->first);
}
+ not_yet_discovered_array_buffers_ = live_array_buffers_;
}
void Heap::TearDownArrayBuffers() {
- Object* undefined = undefined_value();
- for (Object* o = array_buffers_list(); o != undefined;) {
- JSArrayBuffer* buffer = JSArrayBuffer::cast(o);
- Runtime::FreeArrayBuffer(isolate(), buffer);
- o = buffer->weak_next();
+ for (auto buffer = live_array_buffers_.begin();
+ buffer != live_array_buffers_.end(); ++buffer) {
+ isolate_->array_buffer_allocator()->Free(buffer->first, buffer->second);
}
- set_array_buffers_list(undefined);
+ live_array_buffers_.clear();
+ not_yet_discovered_array_buffers_.clear();
}
void Heap::ProcessAllocationSites(WeakObjectRetainer* retainer) {
- Object* allocation_site_obj = VisitWeakList<AllocationSite>(
- this, allocation_sites_list(), retainer, false, NULL);
+ Object* allocation_site_obj =
+ VisitWeakList<AllocationSite>(this, allocation_sites_list(), retainer);
set_allocation_sites_list(allocation_site_obj);
}
@@ -5407,8 +5408,6 @@ bool Heap::CreateHeapObjects() {
CHECK_EQ(0u, gc_count_);
set_native_contexts_list(undefined_value());
- set_array_buffers_list(undefined_value());
- set_last_array_buffer_in_list(undefined_value());
set_allocation_sites_list(undefined_value());
return true;
}
« no previous file with comments | « src/heap/heap.h ('k') | src/heap/mark-compact.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698