Commit ae1f32a1 authored by jochen's avatar jochen Committed by Commit bot

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