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: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64145}
This commit is contained in:
Michael Lippautz 2019-10-07 18:49:21 +02:00 committed by Commit Bot
parent 340868769c
commit 994b64c024

View File

@ -34,7 +34,7 @@ Maybe<bool> IsProperty(v8::Isolate* isolate, v8::Local<v8::Context> ctx,
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) {
// Default values.
auto options =
@ -42,9 +42,10 @@ Maybe<GCOptions> Parse(v8::Isolate* isolate, v8::Local<v8::Context> ctx,
ExecutionType::kSync};
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 maybe_type = IsProperty(isolate, ctx, param, "type", "minor");
if (maybe_type.IsNothing()) return Nothing<GCOptions>();
if (maybe_type.ToChecked()) {
@ -93,12 +94,11 @@ class AsyncGC final : public CancelableTask {
public:
~AsyncGC() final = default;
AsyncGC(v8::Isolate* isolate, v8::Local<v8::Context> ctx,
v8::Local<v8::Promise::Resolver> resolver,
AsyncGC(v8::Isolate* isolate, v8::Local<v8::Promise::Resolver> resolver,
v8::Isolate::GarbageCollectionType type)
: CancelableTask(reinterpret_cast<Isolate*>(isolate)),
isolate_(isolate),
ctx_(isolate, ctx),
ctx_(isolate, isolate->GetCurrentContext()),
resolver_(isolate, resolver),
type_(type) {}
@ -129,10 +129,16 @@ v8::Local<v8::FunctionTemplate> GCExtension::GetNativeFunctionTemplate(
void GCExtension::GC(const v8::FunctionCallbackInfo<v8::Value>& args) {
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;
GCOptions options = maybe_options.ToChecked();
switch (options.execution) {
@ -141,6 +147,7 @@ void GCExtension::GC(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::EmbedderHeapTracer::EmbedderStackState::kUnknown);
break;
case ExecutionType::kAsync: {
v8::HandleScope scope(isolate);
auto resolver = v8::Promise::Resolver::New(isolate->GetCurrentContext())
.ToLocalChecked();
args.GetReturnValue().Set(resolver->GetPromise());
@ -148,7 +155,7 @@ void GCExtension::GC(const v8::FunctionCallbackInfo<v8::Value>& args) {
V8::GetCurrentPlatform()->GetForegroundTaskRunner(isolate);
CHECK(task_runner->NonNestableTasksEnabled());
task_runner->PostNonNestableTask(
std::make_unique<AsyncGC>(isolate, ctx, resolver, options.type));
std::make_unique<AsyncGC>(isolate, resolver, options.type));
} break;
}
}