Skip to content

Commit

Permalink
deps: cherry-pick b6158eb6befae from V8 upstream
Browse files Browse the repository at this point in the history
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 <ulan@chromium.org>
    Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#47601}

PR-URL: #15391
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
  • Loading branch information
addaleax authored and MylesBorins committed Oct 3, 2017
1 parent aa1a3ea commit e1828eb
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 31 deletions.
68 changes: 42 additions & 26 deletions deps/v8/src/heap/heap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<v8::GCCallback>(
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<v8::GCCallback>(info.callback);
callback(gc_type, flags);
} else {
v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(this->isolate());
gc_prologue_callbacks_[i].callback(isolate, gc_type, flags);
info.callback(isolate, gc_type, flags);
}
}
}
Expand All @@ -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<v8::GCCallback>(
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<v8::GCCallback>(info.callback);
callback(gc_type, gc_callback_flags);
} else {
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);
}
}
}
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down
9 changes: 4 additions & 5 deletions deps/v8/src/heap/heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -2255,8 +2254,8 @@ class Heap {

Object* encountered_transition_arrays_;

List<GCCallbackPair> gc_epilogue_callbacks_;
List<GCCallbackPair> gc_prologue_callbacks_;
std::vector<GCCallbackPair> gc_epilogue_callbacks_;
std::vector<GCCallbackPair> gc_prologue_callbacks_;

GetExternallyAllocatedMemoryInBytesCallback external_memory_callback_;

Expand Down

0 comments on commit e1828eb

Please sign in to comment.