Commit 994b64c0 authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

GCExtension: Provide fast path when called with no arguments

Bug: chromium:1005073
Change-Id: I300fd4ef272c0b69dade195048c11a828ac46203
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1845411
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Auto-Submit: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64145}
parent 34086876
...@@ -34,7 +34,7 @@ Maybe<bool> IsProperty(v8::Isolate* isolate, v8::Local<v8::Context> ctx, ...@@ -34,7 +34,7 @@ Maybe<bool> IsProperty(v8::Isolate* isolate, v8::Local<v8::Context> ctx,
v8::String::NewFromUtf8(isolate, value).ToLocalChecked())); v8::String::NewFromUtf8(isolate, value).ToLocalChecked()));
} }
Maybe<GCOptions> Parse(v8::Isolate* isolate, v8::Local<v8::Context> ctx, Maybe<GCOptions> Parse(v8::Isolate* isolate,
const v8::FunctionCallbackInfo<v8::Value>& args) { const v8::FunctionCallbackInfo<v8::Value>& args) {
// Default values. // Default values.
auto options = auto options =
...@@ -42,9 +42,10 @@ Maybe<GCOptions> Parse(v8::Isolate* isolate, v8::Local<v8::Context> ctx, ...@@ -42,9 +42,10 @@ Maybe<GCOptions> Parse(v8::Isolate* isolate, v8::Local<v8::Context> ctx,
ExecutionType::kSync}; ExecutionType::kSync};
bool found_options_object = false; bool found_options_object = false;
if (args[0]->IsObject()) { if (args.Length() > 0 && args[0]->IsObject()) {
v8::HandleScope scope(isolate);
auto ctx = isolate->GetCurrentContext();
auto param = v8::Local<v8::Object>::Cast(args[0]); auto param = v8::Local<v8::Object>::Cast(args[0]);
auto maybe_type = IsProperty(isolate, ctx, param, "type", "minor"); auto maybe_type = IsProperty(isolate, ctx, param, "type", "minor");
if (maybe_type.IsNothing()) return Nothing<GCOptions>(); if (maybe_type.IsNothing()) return Nothing<GCOptions>();
if (maybe_type.ToChecked()) { if (maybe_type.ToChecked()) {
...@@ -93,12 +94,11 @@ class AsyncGC final : public CancelableTask { ...@@ -93,12 +94,11 @@ class AsyncGC final : public CancelableTask {
public: public:
~AsyncGC() final = default; ~AsyncGC() final = default;
AsyncGC(v8::Isolate* isolate, v8::Local<v8::Context> ctx, AsyncGC(v8::Isolate* isolate, v8::Local<v8::Promise::Resolver> resolver,
v8::Local<v8::Promise::Resolver> resolver,
v8::Isolate::GarbageCollectionType type) v8::Isolate::GarbageCollectionType type)
: CancelableTask(reinterpret_cast<Isolate*>(isolate)), : CancelableTask(reinterpret_cast<Isolate*>(isolate)),
isolate_(isolate), isolate_(isolate),
ctx_(isolate, ctx), ctx_(isolate, isolate->GetCurrentContext()),
resolver_(isolate, resolver), resolver_(isolate, resolver),
type_(type) {} type_(type) {}
...@@ -129,10 +129,16 @@ v8::Local<v8::FunctionTemplate> GCExtension::GetNativeFunctionTemplate( ...@@ -129,10 +129,16 @@ v8::Local<v8::FunctionTemplate> GCExtension::GetNativeFunctionTemplate(
void GCExtension::GC(const v8::FunctionCallbackInfo<v8::Value>& args) { void GCExtension::GC(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate(); v8::Isolate* isolate = args.GetIsolate();
v8::HandleScope scope(isolate);
auto ctx = isolate->GetCurrentContext();
auto maybe_options = Parse(isolate, ctx, args); // Immediate bailout if no arguments are provided.
if (args.Length() == 0) {
InvokeGC(isolate,
v8::Isolate::GarbageCollectionType::kFullGarbageCollection,
v8::EmbedderHeapTracer::EmbedderStackState::kUnknown);
return;
}
auto maybe_options = Parse(isolate, args);
if (maybe_options.IsNothing()) return; if (maybe_options.IsNothing()) return;
GCOptions options = maybe_options.ToChecked(); GCOptions options = maybe_options.ToChecked();
switch (options.execution) { switch (options.execution) {
...@@ -141,6 +147,7 @@ void GCExtension::GC(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -141,6 +147,7 @@ void GCExtension::GC(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::EmbedderHeapTracer::EmbedderStackState::kUnknown); v8::EmbedderHeapTracer::EmbedderStackState::kUnknown);
break; break;
case ExecutionType::kAsync: { case ExecutionType::kAsync: {
v8::HandleScope scope(isolate);
auto resolver = v8::Promise::Resolver::New(isolate->GetCurrentContext()) auto resolver = v8::Promise::Resolver::New(isolate->GetCurrentContext())
.ToLocalChecked(); .ToLocalChecked();
args.GetReturnValue().Set(resolver->GetPromise()); args.GetReturnValue().Set(resolver->GetPromise());
...@@ -148,7 +155,7 @@ void GCExtension::GC(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -148,7 +155,7 @@ void GCExtension::GC(const v8::FunctionCallbackInfo<v8::Value>& args) {
V8::GetCurrentPlatform()->GetForegroundTaskRunner(isolate); V8::GetCurrentPlatform()->GetForegroundTaskRunner(isolate);
CHECK(task_runner->NonNestableTasksEnabled()); CHECK(task_runner->NonNestableTasksEnabled());
task_runner->PostNonNestableTask( task_runner->PostNonNestableTask(
std::make_unique<AsyncGC>(isolate, ctx, resolver, options.type)); std::make_unique<AsyncGC>(isolate, resolver, options.type));
} break; } break;
} }
} }
......
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