Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Unified Diff: src/api-natives.cc

Issue 2206773003: [api] Clean up scopes and precheck instantiations cache (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fixing omitted serial_number check Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/isolate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/api-natives.cc
diff --git a/src/api-natives.cc b/src/api-natives.cc
index bb1119dc59466ece534a8bfc5ccf6cc3a7af935b..b0d46b531853dce5cc8a1d78bea84431b187ae97 100644
--- a/src/api-natives.cc
+++ b/src/api-natives.cc
@@ -17,40 +17,42 @@ namespace {
class InvokeScope {
public:
- explicit InvokeScope(Isolate* isolate)
- : isolate_(isolate), save_context_(isolate) {}
+ explicit InvokeScope(Isolate* isolate) : save_context_(isolate) {}
~InvokeScope() {
- bool has_exception = isolate_->has_pending_exception();
+ Isolate* isolate = save_context_.isolate();
+ bool has_exception = isolate->has_pending_exception();
if (has_exception) {
- isolate_->ReportPendingMessages();
+ isolate->ReportPendingMessages();
} else {
- isolate_->clear_pending_message();
+ isolate->clear_pending_message();
}
}
private:
- Isolate* isolate_;
SaveContext save_context_;
};
-MaybeHandle<JSObject> InstantiateObject(Isolate* isolate,
- Handle<ObjectTemplateInfo> data,
- Handle<JSReceiver> new_target,
- bool is_hidden_prototype);
+enum class CacheCheck { kCheck, kSkip };
-MaybeHandle<JSFunction> InstantiateFunction(Isolate* isolate,
- Handle<FunctionTemplateInfo> data,
- Handle<Name> name = Handle<Name>());
+MaybeHandle<JSObject> InstantiateObject(
+ Isolate* isolate, Handle<ObjectTemplateInfo> data,
+ Handle<JSReceiver> new_target, CacheCheck cache_check = CacheCheck::kCheck,
+ bool is_hidden_prototype = false);
+MaybeHandle<JSFunction> InstantiateFunction(
+ Isolate* isolate, Handle<FunctionTemplateInfo> data,
+ CacheCheck cache_check = CacheCheck::kCheck,
+ Handle<Name> name = Handle<Name>());
MaybeHandle<Object> Instantiate(Isolate* isolate, Handle<Object> data,
Handle<Name> name = Handle<Name>()) {
if (data->IsFunctionTemplateInfo()) {
return InstantiateFunction(isolate,
- Handle<FunctionTemplateInfo>::cast(data), name);
+ Handle<FunctionTemplateInfo>::cast(data),
+ CacheCheck::kCheck, name);
} else if (data->IsObjectTemplateInfo()) {
return InstantiateObject(isolate, Handle<ObjectTemplateInfo>::cast(data),
- Handle<JSReceiver>(), false);
+ Handle<JSReceiver>());
} else {
return data;
}
@@ -338,9 +340,17 @@ bool IsSimpleInstantiation(Isolate* isolate, ObjectTemplateInfo* info,
isolate->context()->native_context();
}
+MaybeHandle<JSObject> InstantiateObjectWithInvokeScope(
+ Isolate* isolate, Handle<ObjectTemplateInfo> info,
+ Handle<JSReceiver> new_target) {
+ InvokeScope invoke_scope(isolate);
+ return InstantiateObject(isolate, info, new_target, CacheCheck::kSkip);
+}
+
MaybeHandle<JSObject> InstantiateObject(Isolate* isolate,
Handle<ObjectTemplateInfo> info,
Handle<JSReceiver> new_target,
+ CacheCheck cache_check,
bool is_hidden_prototype) {
Handle<JSFunction> constructor;
int serial_number = Smi::cast(info->serial_number())->value();
@@ -354,7 +364,7 @@ MaybeHandle<JSObject> InstantiateObject(Isolate* isolate,
}
// Fast path.
Handle<JSObject> result;
- if (serial_number) {
+ if (serial_number && cache_check == CacheCheck::kCheck) {
if (ProbeInstantiationsCache(isolate, serial_number).ToHandle(&result)) {
return isolate->factory()->CopyJSObject(result);
}
@@ -388,7 +398,6 @@ MaybeHandle<JSObject> InstantiateObject(Isolate* isolate,
if (info->immutable_proto()) {
JSObject::SetImmutableProto(object);
}
- // TODO(dcarney): is this necessary?
JSObject::MigrateSlowToFast(result, 0, "ApiNatives::InstantiateObject");
if (serial_number) {
@@ -398,12 +407,18 @@ MaybeHandle<JSObject> InstantiateObject(Isolate* isolate,
return result;
}
+MaybeHandle<JSFunction> InstantiateFunctionWithInvokeScope(
+ Isolate* isolate, Handle<FunctionTemplateInfo> info) {
+ InvokeScope invoke_scope(isolate);
+ return InstantiateFunction(isolate, info, CacheCheck::kSkip);
+}
MaybeHandle<JSFunction> InstantiateFunction(Isolate* isolate,
Handle<FunctionTemplateInfo> data,
+ CacheCheck cache_check,
Handle<Name> name) {
int serial_number = Smi::cast(data->serial_number())->value();
- if (serial_number) {
+ if (serial_number && cache_check == CacheCheck::kCheck) {
Handle<JSObject> result;
if (ProbeInstantiationsCache(isolate, serial_number).ToHandle(&result)) {
return Handle<JSFunction>::cast(result);
@@ -420,7 +435,8 @@ MaybeHandle<JSFunction> InstantiateFunction(Isolate* isolate,
InstantiateObject(
isolate,
handle(ObjectTemplateInfo::cast(prototype_templ), isolate),
- Handle<JSReceiver>(), data->hidden_prototype()),
+ Handle<JSReceiver>(), CacheCheck::kCheck,
+ data->hidden_prototype()),
JSFunction);
}
Object* parent = data->parent_template();
@@ -489,19 +505,32 @@ void AddPropertyToPropertyList(Isolate* isolate, Handle<TemplateInfo> templ,
} // namespace
-
MaybeHandle<JSFunction> ApiNatives::InstantiateFunction(
- Handle<FunctionTemplateInfo> data) {
- Isolate* isolate = data->GetIsolate();
- InvokeScope invoke_scope(isolate);
- return ::v8::internal::InstantiateFunction(isolate, data);
+ Handle<FunctionTemplateInfo> info) {
+ Isolate* isolate = info->GetIsolate();
+ int serial_number = Smi::cast(info->serial_number())->value();
+ if (serial_number) {
+ Handle<JSObject> result;
+ if (ProbeInstantiationsCache(isolate, serial_number).ToHandle(&result)) {
+ return Handle<JSFunction>::cast(result);
+ }
+ }
+ return InstantiateFunctionWithInvokeScope(isolate, info);
}
MaybeHandle<JSObject> ApiNatives::InstantiateObject(
- Handle<ObjectTemplateInfo> data, Handle<JSReceiver> new_target) {
- Isolate* isolate = data->GetIsolate();
- InvokeScope invoke_scope(isolate);
- return ::v8::internal::InstantiateObject(isolate, data, new_target, false);
+ Handle<ObjectTemplateInfo> info, Handle<JSReceiver> new_target) {
+ Isolate* isolate = info->GetIsolate();
+ int serial_number = Smi::cast(info->serial_number())->value();
+ if (serial_number && !new_target.is_null() &&
+ IsSimpleInstantiation(isolate, *info, *new_target)) {
+ // Fast path.
+ Handle<JSObject> result;
+ if (ProbeInstantiationsCache(isolate, serial_number).ToHandle(&result)) {
+ return isolate->factory()->CopyJSObject(result);
+ }
+ }
+ return InstantiateObjectWithInvokeScope(isolate, info, new_target);
}
MaybeHandle<JSObject> ApiNatives::InstantiateRemoteObject(
« no previous file with comments | « no previous file | src/isolate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698