From e1828eb50dd03c7ded684246abe3651293ca2238 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 8 Sep 2017 15:34:45 +0200 Subject: [PATCH] deps: cherry-pick b6158eb6befae from V8 upstream MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Original commit message: [heap] Move gc callbacks from List to std::vector Bug: v8:6333 Change-Id: I4434c6cc59f886f1e37dfd315a3ad5fee28d3f63 Reviewed-on: https://chromium-review.googlesource.com/634907 Reviewed-by: Ulan Degenbaev Commit-Queue: Michael Lippautz Cr-Commit-Position: refs/heads/master@{#47601} PR-URL: https://github.com/nodejs/node/pull/15391 Reviewed-By: James M Snell Reviewed-By: Michaƫl Zasso --- deps/v8/src/heap/heap.cc | 68 +++++++++++++++++++++++++--------------- deps/v8/src/heap/heap.h | 9 +++--- 2 files changed, 46 insertions(+), 31 deletions(-) diff --git a/deps/v8/src/heap/heap.cc b/deps/v8/src/heap/heap.cc index 399117ca3220aa..c391683844d3bb 100644 --- a/deps/v8/src/heap/heap.cc +++ b/deps/v8/src/heap/heap.cc @@ -57,6 +57,18 @@ namespace v8 { namespace internal { +bool Heap::GCCallbackPair::operator==(const Heap::GCCallbackPair& other) const { + return other.callback == callback; +} + +Heap::GCCallbackPair& Heap::GCCallbackPair::operator=( + const Heap::GCCallbackPair& other) { + callback = other.callback; + gc_type = other.gc_type; + pass_isolate = other.pass_isolate; + return *this; +} + struct Heap::StrongRootsList { Object** start; Object** end; @@ -1501,15 +1513,15 @@ bool Heap::PerformGarbageCollection( void Heap::CallGCPrologueCallbacks(GCType gc_type, GCCallbackFlags flags) { RuntimeCallTimerScope runtime_timer(isolate(), &RuntimeCallStats::GCPrologueCallback); - for (int i = 0; i < gc_prologue_callbacks_.length(); ++i) { - if (gc_type & gc_prologue_callbacks_[i].gc_type) { - if (!gc_prologue_callbacks_[i].pass_isolate) { - v8::GCCallback callback = reinterpret_cast( - gc_prologue_callbacks_[i].callback); + for (const GCCallbackPair& info : gc_prologue_callbacks_) { + if (gc_type & info.gc_type) { + if (!info.pass_isolate) { + v8::GCCallback callback = + reinterpret_cast(info.callback); callback(gc_type, flags); } else { v8::Isolate* isolate = reinterpret_cast(this->isolate()); - gc_prologue_callbacks_[i].callback(isolate, gc_type, flags); + info.callback(isolate, gc_type, flags); } } } @@ -1520,15 +1532,15 @@ void Heap::CallGCEpilogueCallbacks(GCType gc_type, GCCallbackFlags gc_callback_flags) { RuntimeCallTimerScope runtime_timer(isolate(), &RuntimeCallStats::GCEpilogueCallback); - for (int i = 0; i < gc_epilogue_callbacks_.length(); ++i) { - if (gc_type & gc_epilogue_callbacks_[i].gc_type) { - if (!gc_epilogue_callbacks_[i].pass_isolate) { - v8::GCCallback callback = reinterpret_cast( - gc_epilogue_callbacks_[i].callback); + for (const GCCallbackPair& info : gc_epilogue_callbacks_) { + if (gc_type & info.gc_type) { + if (!info.pass_isolate) { + v8::GCCallback callback = + reinterpret_cast(info.callback); callback(gc_type, gc_callback_flags); } else { v8::Isolate* isolate = reinterpret_cast(this->isolate()); - gc_epilogue_callbacks_[i].callback(isolate, gc_type, gc_callback_flags); + info.callback(isolate, gc_type, gc_callback_flags); } } } @@ -5954,18 +5966,20 @@ void Heap::TearDown() { void Heap::AddGCPrologueCallback(v8::Isolate::GCCallback callback, GCType gc_type, bool pass_isolate) { - DCHECK(callback != NULL); - GCCallbackPair pair(callback, gc_type, pass_isolate); - DCHECK(!gc_prologue_callbacks_.Contains(pair)); - return gc_prologue_callbacks_.Add(pair); + DCHECK_NOT_NULL(callback); + DCHECK(gc_prologue_callbacks_.end() == + std::find(gc_prologue_callbacks_.begin(), gc_prologue_callbacks_.end(), + GCCallbackPair(callback, gc_type, pass_isolate))); + gc_prologue_callbacks_.emplace_back(callback, gc_type, pass_isolate); } void Heap::RemoveGCPrologueCallback(v8::Isolate::GCCallback callback) { - DCHECK(callback != NULL); - for (int i = 0; i < gc_prologue_callbacks_.length(); ++i) { + DCHECK_NOT_NULL(callback); + for (size_t i = 0; i < gc_prologue_callbacks_.size(); i++) { if (gc_prologue_callbacks_[i].callback == callback) { - gc_prologue_callbacks_.Remove(i); + gc_prologue_callbacks_[i] = gc_prologue_callbacks_.back(); + gc_prologue_callbacks_.pop_back(); return; } } @@ -5975,18 +5989,20 @@ void Heap::RemoveGCPrologueCallback(v8::Isolate::GCCallback callback) { void Heap::AddGCEpilogueCallback(v8::Isolate::GCCallback callback, GCType gc_type, bool pass_isolate) { - DCHECK(callback != NULL); - GCCallbackPair pair(callback, gc_type, pass_isolate); - DCHECK(!gc_epilogue_callbacks_.Contains(pair)); - return gc_epilogue_callbacks_.Add(pair); + DCHECK_NOT_NULL(callback); + DCHECK(gc_epilogue_callbacks_.end() == + std::find(gc_epilogue_callbacks_.begin(), gc_epilogue_callbacks_.end(), + GCCallbackPair(callback, gc_type, pass_isolate))); + gc_epilogue_callbacks_.emplace_back(callback, gc_type, pass_isolate); } void Heap::RemoveGCEpilogueCallback(v8::Isolate::GCCallback callback) { - DCHECK(callback != NULL); - for (int i = 0; i < gc_epilogue_callbacks_.length(); ++i) { + DCHECK_NOT_NULL(callback); + for (size_t i = 0; i < gc_epilogue_callbacks_.size(); i++) { if (gc_epilogue_callbacks_[i].callback == callback) { - gc_epilogue_callbacks_.Remove(i); + gc_epilogue_callbacks_[i] = gc_epilogue_callbacks_.back(); + gc_epilogue_callbacks_.pop_back(); return; } } diff --git a/deps/v8/src/heap/heap.h b/deps/v8/src/heap/heap.h index 9beea144eb9b21..44ef96b064597f 100644 --- a/deps/v8/src/heap/heap.h +++ b/deps/v8/src/heap/heap.h @@ -1585,9 +1585,8 @@ class Heap { bool pass_isolate) : callback(callback), gc_type(gc_type), pass_isolate(pass_isolate) {} - bool operator==(const GCCallbackPair& other) const { - return other.callback == callback; - } + bool operator==(const GCCallbackPair& other) const; + GCCallbackPair& operator=(const GCCallbackPair& other); v8::Isolate::GCCallback callback; GCType gc_type; @@ -2255,8 +2254,8 @@ class Heap { Object* encountered_transition_arrays_; - List gc_epilogue_callbacks_; - List gc_prologue_callbacks_; + std::vector gc_epilogue_callbacks_; + std::vector gc_prologue_callbacks_; GetExternallyAllocatedMemoryInBytesCallback external_memory_callback_;