Don't schedule second pass callbacks if there are no callbacks

BUG=none
R=haraken@chromium.org,hpayer@chromium.org
LOG=n

Review URL: https://codereview.chromium.org/1659433002

Cr-Commit-Position: refs/heads/master@{#33658}
This commit is contained in:
jochen 2016-02-02 00:58:28 -08:00 committed by Commit bot
parent c4d366fb0c
commit ae1f32a1cc
2 changed files with 10 additions and 7 deletions

View File

@ -432,7 +432,10 @@ class WeakCallbackInfo {
return internal_fields_[1];
}
bool IsFirstPass() const { return callback_ != nullptr; }
V8_DEPRECATED("Not realiable once SetSecondPassCallback() was used.",
bool IsFirstPass() const) {
return callback_ != nullptr;
}
// When first called, the embedder MUST Reset() the Global which triggered the
// callback. The Global itself is unusable for anything else. No v8 other api

View File

@ -817,8 +817,6 @@ void GlobalHandles::InvokeSecondPassPhantomCallbacks(
while (callbacks->length() != 0) {
auto callback = callbacks->RemoveLast();
DCHECK(callback.node() == nullptr);
// No second pass callback required.
if (callback.callback() == nullptr) continue;
// Fire second pass callback
callback.Invoke(isolate);
}
@ -924,6 +922,7 @@ void GlobalHandles::UpdateListOfNewSpaceNodes() {
int GlobalHandles::DispatchPendingPhantomCallbacks(
bool synchronous_second_pass) {
int freed_nodes = 0;
List<PendingPhantomCallback> second_pass_callbacks;
{
// The initial pass callbacks must simply clear the nodes.
for (auto i = pending_phantom_callbacks_.begin();
@ -932,24 +931,25 @@ int GlobalHandles::DispatchPendingPhantomCallbacks(
// Skip callbacks that have already been processed once.
if (callback->node() == nullptr) continue;
callback->Invoke(isolate());
if (callback->callback()) second_pass_callbacks.Add(*callback);
freed_nodes++;
}
}
if (pending_phantom_callbacks_.length() > 0) {
pending_phantom_callbacks_.Clear();
if (second_pass_callbacks.length() > 0) {
if (FLAG_optimize_for_size || FLAG_predictable || synchronous_second_pass) {
isolate()->heap()->CallGCPrologueCallbacks(
GCType::kGCTypeProcessWeakCallbacks, kNoGCCallbackFlags);
InvokeSecondPassPhantomCallbacks(&pending_phantom_callbacks_, isolate());
InvokeSecondPassPhantomCallbacks(&second_pass_callbacks, isolate());
isolate()->heap()->CallGCEpilogueCallbacks(
GCType::kGCTypeProcessWeakCallbacks, kNoGCCallbackFlags);
} else {
auto task = new PendingPhantomCallbacksSecondPassTask(
&pending_phantom_callbacks_, isolate());
&second_pass_callbacks, isolate());
V8::GetCurrentPlatform()->CallOnForegroundThread(
reinterpret_cast<v8::Isolate*>(isolate()), task);
}
}
pending_phantom_callbacks_.Clear();
return freed_nodes;
}