Commit e1b5cb43 authored by machenbach's avatar machenbach Committed by Commit bot

Revert of [api] Clean up scopes and precheck instantiations cache (patchset #3...

Revert of [api] Clean up scopes and precheck instantiations cache (patchset #3 id:40001 of https://codereview.chromium.org/2206773003/ )

Reason for revert:
[Sheriff] Leads to mac asan failures:
https://build.chromium.org/p/client.v8/builders/V8%20Mac64%20ASAN/builds/7835

Original issue's description:
> [api] Clean up scopes and precheck instantiations cache
>
> Make sure all the scopes used in api-natives.cc have inlineable constructors
> and destructors. Additionally directly precheck the instantiations cache before
> trying to enter the InvokeScope which sets the save_context.
>
> BUG=chromium:630217
>
> Committed: https://crrev.com/a2496b942cad524f0f3144b107936eaa9a7c9fd5
> Cr-Commit-Position: refs/heads/master@{#38346}

TBR=yangguo@chromium.org,cbruni@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=chromium:630217

Review-Url: https://codereview.chromium.org/2216903003
Cr-Commit-Position: refs/heads/master@{#38356}
parent cad5b296
...@@ -17,42 +17,40 @@ namespace { ...@@ -17,42 +17,40 @@ namespace {
class InvokeScope { class InvokeScope {
public: public:
explicit InvokeScope(Isolate* isolate) : save_context_(isolate) {} explicit InvokeScope(Isolate* isolate)
: isolate_(isolate), save_context_(isolate) {}
~InvokeScope() { ~InvokeScope() {
Isolate* isolate = save_context_.isolate(); bool has_exception = isolate_->has_pending_exception();
bool has_exception = isolate->has_pending_exception();
if (has_exception) { if (has_exception) {
isolate->ReportPendingMessages(); isolate_->ReportPendingMessages();
} else { } else {
isolate->clear_pending_message(); isolate_->clear_pending_message();
} }
} }
private: private:
Isolate* isolate_;
SaveContext save_context_; SaveContext save_context_;
}; };
enum class CacheCheck { kCheck, kSkip }; MaybeHandle<JSObject> InstantiateObject(Isolate* isolate,
Handle<ObjectTemplateInfo> data,
Handle<JSReceiver> new_target,
bool is_hidden_prototype);
MaybeHandle<JSObject> InstantiateObject( MaybeHandle<JSFunction> InstantiateFunction(Isolate* isolate,
Isolate* isolate, Handle<ObjectTemplateInfo> data, Handle<FunctionTemplateInfo> data,
Handle<JSReceiver> new_target, CacheCheck cache_check = CacheCheck::kCheck, Handle<Name> name = Handle<Name>());
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, MaybeHandle<Object> Instantiate(Isolate* isolate, Handle<Object> data,
Handle<Name> name = Handle<Name>()) { Handle<Name> name = Handle<Name>()) {
if (data->IsFunctionTemplateInfo()) { if (data->IsFunctionTemplateInfo()) {
return InstantiateFunction(isolate, return InstantiateFunction(isolate,
Handle<FunctionTemplateInfo>::cast(data), Handle<FunctionTemplateInfo>::cast(data), name);
CacheCheck::kCheck, name);
} else if (data->IsObjectTemplateInfo()) { } else if (data->IsObjectTemplateInfo()) {
return InstantiateObject(isolate, Handle<ObjectTemplateInfo>::cast(data), return InstantiateObject(isolate, Handle<ObjectTemplateInfo>::cast(data),
Handle<JSReceiver>()); Handle<JSReceiver>(), false);
} else { } else {
return data; return data;
} }
...@@ -339,17 +337,9 @@ bool IsSimpleInstantiation(Isolate* isolate, ObjectTemplateInfo* info, ...@@ -339,17 +337,9 @@ bool IsSimpleInstantiation(Isolate* isolate, ObjectTemplateInfo* info,
return fun->context()->native_context() == isolate->raw_native_context(); return fun->context()->native_context() == isolate->raw_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, MaybeHandle<JSObject> InstantiateObject(Isolate* isolate,
Handle<ObjectTemplateInfo> info, Handle<ObjectTemplateInfo> info,
Handle<JSReceiver> new_target, Handle<JSReceiver> new_target,
CacheCheck cache_check,
bool is_hidden_prototype) { bool is_hidden_prototype) {
Handle<JSFunction> constructor; Handle<JSFunction> constructor;
int serial_number = Smi::cast(info->serial_number())->value(); int serial_number = Smi::cast(info->serial_number())->value();
...@@ -363,7 +353,7 @@ MaybeHandle<JSObject> InstantiateObject(Isolate* isolate, ...@@ -363,7 +353,7 @@ MaybeHandle<JSObject> InstantiateObject(Isolate* isolate,
} }
// Fast path. // Fast path.
Handle<JSObject> result; Handle<JSObject> result;
if (serial_number && cache_check == CacheCheck::kCheck) { if (serial_number) {
if (ProbeInstantiationsCache(isolate, serial_number).ToHandle(&result)) { if (ProbeInstantiationsCache(isolate, serial_number).ToHandle(&result)) {
return isolate->factory()->CopyJSObject(result); return isolate->factory()->CopyJSObject(result);
} }
...@@ -397,6 +387,7 @@ MaybeHandle<JSObject> InstantiateObject(Isolate* isolate, ...@@ -397,6 +387,7 @@ MaybeHandle<JSObject> InstantiateObject(Isolate* isolate,
if (info->immutable_proto()) { if (info->immutable_proto()) {
JSObject::SetImmutableProto(object); JSObject::SetImmutableProto(object);
} }
// TODO(dcarney): is this necessary?
JSObject::MigrateSlowToFast(result, 0, "ApiNatives::InstantiateObject"); JSObject::MigrateSlowToFast(result, 0, "ApiNatives::InstantiateObject");
if (serial_number) { if (serial_number) {
...@@ -406,18 +397,12 @@ MaybeHandle<JSObject> InstantiateObject(Isolate* isolate, ...@@ -406,18 +397,12 @@ MaybeHandle<JSObject> InstantiateObject(Isolate* isolate,
return result; 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, MaybeHandle<JSFunction> InstantiateFunction(Isolate* isolate,
Handle<FunctionTemplateInfo> data, Handle<FunctionTemplateInfo> data,
CacheCheck cache_check,
Handle<Name> name) { Handle<Name> name) {
int serial_number = Smi::cast(data->serial_number())->value(); int serial_number = Smi::cast(data->serial_number())->value();
if (serial_number && cache_check == CacheCheck::kCheck) { if (serial_number) {
Handle<JSObject> result; Handle<JSObject> result;
if (ProbeInstantiationsCache(isolate, serial_number).ToHandle(&result)) { if (ProbeInstantiationsCache(isolate, serial_number).ToHandle(&result)) {
return Handle<JSFunction>::cast(result); return Handle<JSFunction>::cast(result);
...@@ -434,8 +419,7 @@ MaybeHandle<JSFunction> InstantiateFunction(Isolate* isolate, ...@@ -434,8 +419,7 @@ MaybeHandle<JSFunction> InstantiateFunction(Isolate* isolate,
InstantiateObject( InstantiateObject(
isolate, isolate,
handle(ObjectTemplateInfo::cast(prototype_templ), isolate), handle(ObjectTemplateInfo::cast(prototype_templ), isolate),
Handle<JSReceiver>(), CacheCheck::kCheck, Handle<JSReceiver>(), data->hidden_prototype()),
data->hidden_prototype()),
JSFunction); JSFunction);
} }
Object* parent = data->parent_template(); Object* parent = data->parent_template();
...@@ -504,32 +488,19 @@ void AddPropertyToPropertyList(Isolate* isolate, Handle<TemplateInfo> templ, ...@@ -504,32 +488,19 @@ void AddPropertyToPropertyList(Isolate* isolate, Handle<TemplateInfo> templ,
} // namespace } // namespace
MaybeHandle<JSFunction> ApiNatives::InstantiateFunction( MaybeHandle<JSFunction> ApiNatives::InstantiateFunction(
Handle<FunctionTemplateInfo> info) { Handle<FunctionTemplateInfo> data) {
Isolate* isolate = info->GetIsolate(); Isolate* isolate = data->GetIsolate();
int serial_number = Smi::cast(info->serial_number())->value(); InvokeScope invoke_scope(isolate);
if (serial_number) { return ::v8::internal::InstantiateFunction(isolate, data);
Handle<JSObject> result;
if (ProbeInstantiationsCache(isolate, serial_number).ToHandle(&result)) {
return Handle<JSFunction>::cast(result);
}
}
return InstantiateFunctionWithInvokeScope(isolate, info);
} }
MaybeHandle<JSObject> ApiNatives::InstantiateObject( MaybeHandle<JSObject> ApiNatives::InstantiateObject(
Handle<ObjectTemplateInfo> info, Handle<JSReceiver> new_target) { Handle<ObjectTemplateInfo> data, Handle<JSReceiver> new_target) {
Isolate* isolate = info->GetIsolate(); Isolate* isolate = data->GetIsolate();
int serial_number = Smi::cast(info->serial_number())->value(); InvokeScope invoke_scope(isolate);
if (serial_number && !new_target.is_null() && return ::v8::internal::InstantiateObject(isolate, data, new_target, false);
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( MaybeHandle<JSObject> ApiNatives::InstantiateRemoteObject(
......
...@@ -100,20 +100,6 @@ Isolate::ExceptionScope::~ExceptionScope() { ...@@ -100,20 +100,6 @@ Isolate::ExceptionScope::~ExceptionScope() {
isolate_->set_pending_exception(*pending_exception_); isolate_->set_pending_exception(*pending_exception_);
} }
SaveContext::SaveContext(Isolate* isolate)
: isolate_(isolate), prev_(isolate->save_context()) {
if (isolate->context() != NULL) {
context_ = Handle<Context>(isolate->context());
}
isolate->set_save_context(this);
c_entry_fp_ = isolate->c_entry_fp(isolate->thread_local_top());
}
SaveContext::~SaveContext() {
isolate_->set_context(context_.is_null() ? NULL : *context_);
isolate_->set_save_context(prev_);
}
#define NATIVE_CONTEXT_FIELD_ACCESSOR(index, type, name) \ #define NATIVE_CONTEXT_FIELD_ACCESSOR(index, type, name) \
Handle<type> Isolate::name() { \ Handle<type> Isolate::name() { \
return Handle<type>(raw_native_context()->name(), this); \ return Handle<type>(raw_native_context()->name(), this); \
......
...@@ -3176,6 +3176,24 @@ bool StackLimitCheck::JsHasOverflowed(uintptr_t gap) const { ...@@ -3176,6 +3176,24 @@ bool StackLimitCheck::JsHasOverflowed(uintptr_t gap) const {
return GetCurrentStackPosition() - gap < stack_guard->real_climit(); return GetCurrentStackPosition() - gap < stack_guard->real_climit();
} }
SaveContext::SaveContext(Isolate* isolate)
: isolate_(isolate), prev_(isolate->save_context()) {
if (isolate->context() != NULL) {
context_ = Handle<Context>(isolate->context());
}
isolate->set_save_context(this);
c_entry_fp_ = isolate->c_entry_fp(isolate->thread_local_top());
}
SaveContext::~SaveContext() {
isolate_->set_context(context_.is_null() ? NULL : *context_);
isolate_->set_save_context(prev_);
}
#ifdef DEBUG #ifdef DEBUG
AssertNoContextChange::AssertNoContextChange(Isolate* isolate) AssertNoContextChange::AssertNoContextChange(Isolate* isolate)
: isolate_(isolate), context_(isolate->context(), isolate) {} : isolate_(isolate), context_(isolate->context(), isolate) {}
......
...@@ -1473,8 +1473,8 @@ class PromiseOnStack { ...@@ -1473,8 +1473,8 @@ class PromiseOnStack {
// versions of GCC. See V8 issue 122 for details. // versions of GCC. See V8 issue 122 for details.
class SaveContext BASE_EMBEDDED { class SaveContext BASE_EMBEDDED {
public: public:
explicit inline SaveContext(Isolate* isolate); explicit SaveContext(Isolate* isolate);
inline ~SaveContext(); ~SaveContext();
Handle<Context> context() { return context_; } Handle<Context> context() { return context_; }
SaveContext* prev() { return prev_; } SaveContext* prev() { return prev_; }
...@@ -1484,8 +1484,6 @@ class SaveContext BASE_EMBEDDED { ...@@ -1484,8 +1484,6 @@ class SaveContext BASE_EMBEDDED {
return (c_entry_fp_ == 0) || (c_entry_fp_ > frame->sp()); return (c_entry_fp_ == 0) || (c_entry_fp_ > frame->sp());
} }
Isolate* isolate() { return isolate_; }
private: private:
Isolate* isolate_; Isolate* isolate_;
Handle<Context> context_; Handle<Context> context_;
......
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