Commit bc427c40 authored by Mike Stanton's avatar Mike Stanton Committed by Commit Bot

[Turbofan] Promise brokerization improvement

We only need to save the native context scope info object to
properly brokerize promise call reductions, rather than
adding the field to each ContextRef.

Bug: v8:7790
Change-Id: Id13dc8505972123cf77a50573c816c9a913686e3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1678416Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Commit-Queue: Michael Stanton <mvstanton@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62382}
parent 9f061823
......@@ -5605,12 +5605,6 @@ Reduction JSCallReducer::ReducePromiseConstructor(Node* node) {
if (!dependencies()->DependOnPromiseHookProtector()) return NoChange();
// Check if we have the required scope_info.
if (!native_context().scope_info().has_value()) {
TRACE_BROKER_MISSING(broker(), "data for native context scope_info");
return NoChange();
}
SharedFunctionInfoRef promise_shared =
native_context().promise_function().shared();
......@@ -5653,7 +5647,7 @@ Reduction JSCallReducer::ReducePromiseConstructor(Node* node) {
// Allocate a promise context for the closures below.
Node* promise_context = effect = graph()->NewNode(
javascript()->CreateFunctionContext(
native_context().scope_info()->object(),
native_context().scope_info().object(),
PromiseBuiltins::kPromiseContextLength - Context::MIN_CONTEXT_SLOTS,
FUNCTION_SCOPE),
context, effect, control);
......@@ -5903,12 +5897,6 @@ Reduction JSCallReducer::ReducePromisePrototypeFinally(Node* node) {
if (!DoPromiseChecks(&inference)) return inference.NoChange();
MapHandles const& receiver_maps = inference.GetMaps();
// Check if we have the required scope_info.
if (!native_context().scope_info().has_value()) {
TRACE_BROKER_MISSING(broker(), "data for native context scope_info");
return inference.NoChange();
}
if (!dependencies()->DependOnPromiseHookProtector())
return inference.NoChange();
if (!dependencies()->DependOnPromiseThenProtector())
......@@ -5936,7 +5924,7 @@ Reduction JSCallReducer::ReducePromisePrototypeFinally(Node* node) {
// Allocate shared context for the closures below.
context = etrue =
graph()->NewNode(javascript()->CreateFunctionContext(
native_context().scope_info()->object(),
native_context().scope_info().object(),
PromiseBuiltins::kPromiseFinallyContextLength -
Context::MIN_CONTEXT_SLOTS,
FUNCTION_SCOPE),
......
......@@ -544,13 +544,9 @@ class ContextData : public HeapObjectData {
return nullptr;
}
void SerializeScopeInfo(JSHeapBroker* broker);
ScopeInfoData* scope_info() const { return scope_info_; }
private:
ZoneMap<int, ObjectData*> slots_;
ContextData* previous_ = nullptr;
ScopeInfoData* scope_info_ = nullptr;
};
ContextData::ContextData(JSHeapBroker* broker, ObjectData** storage,
......@@ -578,13 +574,6 @@ void ContextData::SerializeSlot(JSHeapBroker* broker, int index) {
slots_.insert(std::make_pair(index, odata));
}
void ContextData::SerializeScopeInfo(JSHeapBroker* broker) {
TraceScope tracer(broker, this, "ContextData::SerializeScopeInfo");
TRACE(broker, "Serializing scope info");
Handle<Context> context = Handle<Context>::cast(object());
scope_info_ = broker->GetOrCreateData(context->scope_info())->AsScopeInfo();
}
class NativeContextData : public ContextData {
public:
#define DECL_ACCESSOR(type, name) \
......@@ -597,6 +586,11 @@ class NativeContextData : public ContextData {
return function_maps_;
}
ScopeInfoData* scope_info() const {
CHECK(serialized_);
return scope_info_;
}
NativeContextData(JSHeapBroker* broker, ObjectData** storage,
Handle<NativeContext> object);
void Serialize(JSHeapBroker* broker);
......@@ -607,6 +601,7 @@ class NativeContextData : public ContextData {
BROKER_NATIVE_CONTEXT_FIELDS(DECL_MEMBER)
#undef DECL_MEMBER
ZoneVector<MapData*> function_maps_;
ScopeInfoData* scope_info_ = nullptr;
};
class NameData : public HeapObjectData {
......@@ -2921,6 +2916,16 @@ bool StringRef::IsSeqString() const {
return data()->AsString()->is_seq_string();
}
ScopeInfoRef NativeContextRef::scope_info() const {
if (broker()->mode() == JSHeapBroker::kDisabled) {
AllowHandleAllocation handle_allocation;
AllowHandleDereference handle_dereference;
return ScopeInfoRef(broker(),
handle(object()->scope_info(), broker()->isolate()));
}
return ScopeInfoRef(broker(), data()->AsNativeContext()->scope_info());
}
MapRef NativeContextRef::GetFunctionMapFromIndex(int index) const {
DCHECK_GE(index, Context::FIRST_FUNCTION_MAP_INDEX);
DCHECK_LE(index, Context::LAST_FUNCTION_MAP_INDEX);
......@@ -3283,6 +3288,8 @@ void NativeContextData::Serialize(JSHeapBroker* broker) {
for (int i = first; i <= last; ++i) {
function_maps_.push_back(broker->GetOrCreateData(context->get(i))->AsMap());
}
scope_info_ = broker->GetOrCreateData(context->scope_info())->AsScopeInfo();
}
void JSFunctionRef::Serialize() {
......@@ -3392,26 +3399,6 @@ void ContextRef::SerializeSlot(int index) {
data()->AsContext()->SerializeSlot(broker(), index);
}
void ContextRef::SerializeScopeInfo() {
if (broker()->mode() == JSHeapBroker::kDisabled) return;
CHECK_EQ(broker()->mode(), JSHeapBroker::kSerializing);
data()->AsContext()->SerializeScopeInfo(broker());
}
base::Optional<ScopeInfoRef> ContextRef::scope_info() const {
if (broker()->mode() == JSHeapBroker::kDisabled) {
AllowHandleAllocation handle_allocation;
AllowHandleDereference handle_dereference;
return ScopeInfoRef(broker(),
handle(object()->scope_info(), broker()->isolate()));
}
ScopeInfoData* scope_info = data()->AsContext()->scope_info();
if (scope_info != nullptr) {
return ScopeInfoRef(broker(), scope_info);
}
return base::Optional<ScopeInfoRef>();
}
void NativeContextRef::Serialize() {
if (broker()->mode() == JSHeapBroker::kDisabled) return;
CHECK_EQ(broker()->mode(), JSHeapBroker::kSerializing);
......
......@@ -391,6 +391,7 @@ class NativeContextRef : public ContextRef {
BROKER_NATIVE_CONTEXT_FIELDS(DECL_ACCESSOR)
#undef DECL_ACCESSOR
ScopeInfoRef scope_info() const;
MapRef GetFunctionMapFromIndex(int index) const;
MapRef GetInitialJSArrayMap(ElementsKind kind) const;
base::Optional<JSFunctionRef> GetConstructorFunction(const MapRef& map) const;
......
......@@ -1133,18 +1133,10 @@ void SerializerForBackgroundCompilation::ProcessBuiltinCall(
DCHECK(target->HasBuiltinId());
const int builtin_id = target->builtin_id();
switch (builtin_id) {
case Builtins::kPromiseConstructor: {
TRACE_BROKER(broker(), "Serializing data for builtin PromiseConstructor");
// For JSCallReducer::ReducePromiseConstructor.
broker()->native_context().SerializeScopeInfo();
break;
}
case Builtins::kPromisePrototypeCatch: {
TRACE_BROKER(broker(),
"Serializing data for builtin PromisePrototypeCatch");
// For JSCallReducer::ReducePromisePrototypeCatch.
broker()->native_context().SerializeScopeInfo();
CHECK_GE(arguments.size(), 1);
Hints const& receiver_hints = arguments[0];
ProcessMapHintsForPromises(receiver_hints);
......@@ -1154,8 +1146,6 @@ void SerializerForBackgroundCompilation::ProcessBuiltinCall(
TRACE_BROKER(broker(),
"Serializing data for builtin PromisePrototypeFinally");
// For JSCallReducer::ReducePromisePrototypeFinally.
broker()->native_context().SerializeScopeInfo();
CHECK_GE(arguments.size(), 1);
Hints const& receiver_hints = arguments[0];
ProcessMapHintsForPromises(receiver_hints);
......
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