Commit b6158eb6 authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

[heap] Move gc callbacks from List to std::vector

Bug: v8:6333
Change-Id: I4434c6cc59f886f1e37dfd315a3ad5fee28d3f63
Reviewed-on: https://chromium-review.googlesource.com/634907Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47601}
parent c693c818
...@@ -59,6 +59,18 @@ ...@@ -59,6 +59,18 @@
namespace v8 { namespace v8 {
namespace internal { 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 { struct Heap::StrongRootsList {
Object** start; Object** start;
Object** end; Object** end;
...@@ -1603,15 +1615,15 @@ bool Heap::PerformGarbageCollection( ...@@ -1603,15 +1615,15 @@ bool Heap::PerformGarbageCollection(
void Heap::CallGCPrologueCallbacks(GCType gc_type, GCCallbackFlags flags) { void Heap::CallGCPrologueCallbacks(GCType gc_type, GCCallbackFlags flags) {
RuntimeCallTimerScope runtime_timer(isolate(), RuntimeCallTimerScope runtime_timer(isolate(),
&RuntimeCallStats::GCPrologueCallback); &RuntimeCallStats::GCPrologueCallback);
for (int i = 0; i < gc_prologue_callbacks_.length(); ++i) { for (const GCCallbackPair& info : gc_prologue_callbacks_) {
if (gc_type & gc_prologue_callbacks_[i].gc_type) { if (gc_type & info.gc_type) {
if (!gc_prologue_callbacks_[i].pass_isolate) { if (!info.pass_isolate) {
v8::GCCallback callback = reinterpret_cast<v8::GCCallback>( v8::GCCallback callback =
gc_prologue_callbacks_[i].callback); reinterpret_cast<v8::GCCallback>(info.callback);
callback(gc_type, flags); callback(gc_type, flags);
} else { } else {
v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(this->isolate()); v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(this->isolate());
gc_prologue_callbacks_[i].callback(isolate, gc_type, flags); info.callback(isolate, gc_type, flags);
} }
} }
} }
...@@ -1622,15 +1634,15 @@ void Heap::CallGCEpilogueCallbacks(GCType gc_type, ...@@ -1622,15 +1634,15 @@ void Heap::CallGCEpilogueCallbacks(GCType gc_type,
GCCallbackFlags gc_callback_flags) { GCCallbackFlags gc_callback_flags) {
RuntimeCallTimerScope runtime_timer(isolate(), RuntimeCallTimerScope runtime_timer(isolate(),
&RuntimeCallStats::GCEpilogueCallback); &RuntimeCallStats::GCEpilogueCallback);
for (int i = 0; i < gc_epilogue_callbacks_.length(); ++i) { for (const GCCallbackPair& info : gc_epilogue_callbacks_) {
if (gc_type & gc_epilogue_callbacks_[i].gc_type) { if (gc_type & info.gc_type) {
if (!gc_epilogue_callbacks_[i].pass_isolate) { if (!info.pass_isolate) {
v8::GCCallback callback = reinterpret_cast<v8::GCCallback>( v8::GCCallback callback =
gc_epilogue_callbacks_[i].callback); reinterpret_cast<v8::GCCallback>(info.callback);
callback(gc_type, gc_callback_flags); callback(gc_type, gc_callback_flags);
} else { } else {
v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(this->isolate()); v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(this->isolate());
gc_epilogue_callbacks_[i].callback(isolate, gc_type, gc_callback_flags); info.callback(isolate, gc_type, gc_callback_flags);
} }
} }
} }
...@@ -6189,18 +6201,20 @@ void Heap::TearDown() { ...@@ -6189,18 +6201,20 @@ void Heap::TearDown() {
void Heap::AddGCPrologueCallback(v8::Isolate::GCCallback callback, void Heap::AddGCPrologueCallback(v8::Isolate::GCCallback callback,
GCType gc_type, bool pass_isolate) { GCType gc_type, bool pass_isolate) {
DCHECK(callback != NULL); DCHECK_NOT_NULL(callback);
GCCallbackPair pair(callback, gc_type, pass_isolate); DCHECK(gc_prologue_callbacks_.end() ==
DCHECK(!gc_prologue_callbacks_.Contains(pair)); std::find(gc_prologue_callbacks_.begin(), gc_prologue_callbacks_.end(),
return gc_prologue_callbacks_.Add(pair); GCCallbackPair(callback, gc_type, pass_isolate)));
gc_prologue_callbacks_.emplace_back(callback, gc_type, pass_isolate);
} }
void Heap::RemoveGCPrologueCallback(v8::Isolate::GCCallback callback) { void Heap::RemoveGCPrologueCallback(v8::Isolate::GCCallback callback) {
DCHECK(callback != NULL); DCHECK_NOT_NULL(callback);
for (int i = 0; i < gc_prologue_callbacks_.length(); ++i) { for (size_t i = 0; i < gc_prologue_callbacks_.size(); i++) {
if (gc_prologue_callbacks_[i].callback == callback) { 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; return;
} }
} }
...@@ -6210,18 +6224,20 @@ void Heap::RemoveGCPrologueCallback(v8::Isolate::GCCallback callback) { ...@@ -6210,18 +6224,20 @@ void Heap::RemoveGCPrologueCallback(v8::Isolate::GCCallback callback) {
void Heap::AddGCEpilogueCallback(v8::Isolate::GCCallback callback, void Heap::AddGCEpilogueCallback(v8::Isolate::GCCallback callback,
GCType gc_type, bool pass_isolate) { GCType gc_type, bool pass_isolate) {
DCHECK(callback != NULL); DCHECK_NOT_NULL(callback);
GCCallbackPair pair(callback, gc_type, pass_isolate); DCHECK(gc_epilogue_callbacks_.end() ==
DCHECK(!gc_epilogue_callbacks_.Contains(pair)); std::find(gc_epilogue_callbacks_.begin(), gc_epilogue_callbacks_.end(),
return gc_epilogue_callbacks_.Add(pair); GCCallbackPair(callback, gc_type, pass_isolate)));
gc_epilogue_callbacks_.emplace_back(callback, gc_type, pass_isolate);
} }
void Heap::RemoveGCEpilogueCallback(v8::Isolate::GCCallback callback) { void Heap::RemoveGCEpilogueCallback(v8::Isolate::GCCallback callback) {
DCHECK(callback != NULL); DCHECK_NOT_NULL(callback);
for (int i = 0; i < gc_epilogue_callbacks_.length(); ++i) { for (size_t i = 0; i < gc_epilogue_callbacks_.size(); i++) {
if (gc_epilogue_callbacks_[i].callback == callback) { 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; return;
} }
} }
......
...@@ -1613,9 +1613,8 @@ class Heap { ...@@ -1613,9 +1613,8 @@ class Heap {
bool pass_isolate) bool pass_isolate)
: callback(callback), gc_type(gc_type), pass_isolate(pass_isolate) {} : callback(callback), gc_type(gc_type), pass_isolate(pass_isolate) {}
bool operator==(const GCCallbackPair& other) const { bool operator==(const GCCallbackPair& other) const;
return other.callback == callback; GCCallbackPair& operator=(const GCCallbackPair& other);
}
v8::Isolate::GCCallback callback; v8::Isolate::GCCallback callback;
GCType gc_type; GCType gc_type;
...@@ -2302,8 +2301,8 @@ class Heap { ...@@ -2302,8 +2301,8 @@ class Heap {
// contains Smi(0) while marking is not active. // contains Smi(0) while marking is not active.
Object* encountered_weak_collections_; Object* encountered_weak_collections_;
List<GCCallbackPair> gc_epilogue_callbacks_; std::vector<GCCallbackPair> gc_epilogue_callbacks_;
List<GCCallbackPair> gc_prologue_callbacks_; std::vector<GCCallbackPair> gc_prologue_callbacks_;
GetExternallyAllocatedMemoryInBytesCallback external_memory_callback_; GetExternallyAllocatedMemoryInBytesCallback external_memory_callback_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment