Commit 74257189 authored by Georg Neis's avatar Georg Neis Committed by Commit Bot

[turbofan] Move serialization of module cells into serializer

Bug: v8:7790
Change-Id: I6705e5399ad37201b89d5d6d5174138b22401ca1
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1762518Reviewed-by: 's avatarMaya Lekova <mslekova@chromium.org>
Commit-Queue: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63315}
parent 26e39d12
...@@ -838,7 +838,7 @@ class SourceTextModuleRef : public HeapObjectRef { ...@@ -838,7 +838,7 @@ class SourceTextModuleRef : public HeapObjectRef {
void Serialize(); void Serialize();
CellRef GetCell(int cell_index) const; base::Optional<CellRef> GetCell(int cell_index) const;
}; };
class CellRef : public HeapObjectRef { class CellRef : public HeapObjectRef {
......
...@@ -1709,7 +1709,7 @@ class SourceTextModuleData : public HeapObjectData { ...@@ -1709,7 +1709,7 @@ class SourceTextModuleData : public HeapObjectData {
Handle<SourceTextModule> object); Handle<SourceTextModule> object);
void Serialize(JSHeapBroker* broker); void Serialize(JSHeapBroker* broker);
CellData* GetCell(int cell_index) const; CellData* GetCell(JSHeapBroker* broker, int cell_index) const;
private: private:
bool serialized_ = false; bool serialized_ = false;
...@@ -1724,8 +1724,14 @@ SourceTextModuleData::SourceTextModuleData(JSHeapBroker* broker, ...@@ -1724,8 +1724,14 @@ SourceTextModuleData::SourceTextModuleData(JSHeapBroker* broker,
imports_(broker->zone()), imports_(broker->zone()),
exports_(broker->zone()) {} exports_(broker->zone()) {}
CellData* SourceTextModuleData::GetCell(int cell_index) const { CellData* SourceTextModuleData::GetCell(JSHeapBroker* broker,
CHECK(serialized_); int cell_index) const {
if (!serialized_) {
DCHECK(imports_.empty());
TRACE_BROKER_MISSING(broker,
"module cell " << cell_index << " on " << this);
return nullptr;
}
CellData* cell; CellData* cell;
switch (SourceTextModuleDescriptor::GetCellIndexKind(cell_index)) { switch (SourceTextModuleDescriptor::GetCellIndexKind(cell_index)) {
case SourceTextModuleDescriptor::kImport: case SourceTextModuleDescriptor::kImport:
...@@ -3509,14 +3515,16 @@ uint64_t BigIntRef::AsUint64() const { ...@@ -3509,14 +3515,16 @@ uint64_t BigIntRef::AsUint64() const {
return data()->AsBigInt()->AsUint64(); return data()->AsBigInt()->AsUint64();
} }
CellRef SourceTextModuleRef::GetCell(int cell_index) const { base::Optional<CellRef> SourceTextModuleRef::GetCell(int cell_index) const {
if (broker()->mode() == JSHeapBroker::kDisabled) { if (broker()->mode() == JSHeapBroker::kDisabled) {
AllowHandleAllocation handle_allocation; AllowHandleAllocation handle_allocation;
AllowHandleDereference allow_handle_dereference; AllowHandleDereference allow_handle_dereference;
return CellRef(broker(), return CellRef(broker(),
handle(object()->GetCell(cell_index), broker()->isolate())); handle(object()->GetCell(cell_index), broker()->isolate()));
} }
return CellRef(broker(), data()->AsSourceTextModule()->GetCell(cell_index)); CellData* cell = data()->AsSourceTextModule()->GetCell(broker(), cell_index);
if (cell == nullptr) return base::nullopt;
return CellRef(broker(), cell);
} }
ObjectRef::ObjectRef(JSHeapBroker* broker, Handle<Object> object, ObjectRef::ObjectRef(JSHeapBroker* broker, Handle<Object> object,
......
...@@ -30,7 +30,11 @@ Reduction JSHeapCopyReducer::Reduce(Node* node) { ...@@ -30,7 +30,11 @@ Reduction JSHeapCopyReducer::Reduce(Node* node) {
ObjectRef object(broker(), HeapConstantOf(node->op())); ObjectRef object(broker(), HeapConstantOf(node->op()));
if (object.IsJSFunction()) object.AsJSFunction().Serialize(); if (object.IsJSFunction()) object.AsJSFunction().Serialize();
if (object.IsJSObject()) object.AsJSObject().SerializeObjectCreateMap(); if (object.IsJSObject()) object.AsJSObject().SerializeObjectCreateMap();
if (object.IsSourceTextModule()) object.AsSourceTextModule().Serialize(); if (!FLAG_concurrent_inlining) {
if (object.IsSourceTextModule()) {
object.AsSourceTextModule().Serialize();
}
}
break; break;
} }
case IrOpcode::kJSCreateArray: { case IrOpcode::kJSCreateArray: {
......
...@@ -1367,8 +1367,8 @@ Node* JSTypedLowering::BuildGetModuleCell(Node* node) { ...@@ -1367,8 +1367,8 @@ Node* JSTypedLowering::BuildGetModuleCell(Node* node) {
if (module_type.IsHeapConstant()) { if (module_type.IsHeapConstant()) {
SourceTextModuleRef module_constant = SourceTextModuleRef module_constant =
module_type.AsHeapConstant()->Ref().AsSourceTextModule(); module_type.AsHeapConstant()->Ref().AsSourceTextModule();
CellRef cell_constant = module_constant.GetCell(cell_index); base::Optional<CellRef> cell_constant = module_constant.GetCell(cell_index);
return jsgraph()->Constant(cell_constant); if (cell_constant.has_value()) return jsgraph()->Constant(*cell_constant);
} }
FieldAccess field_access; FieldAccess field_access;
......
...@@ -402,6 +402,9 @@ class SerializerForBackgroundCompilation { ...@@ -402,6 +402,9 @@ class SerializerForBackgroundCompilation {
ElementAccessFeedback const& feedback, ElementAccessFeedback const& feedback,
AccessMode access_mode); AccessMode access_mode);
void ProcessModuleVariableAccess(
interpreter::BytecodeArrayIterator* iterator);
void ProcessMapHintsForPromises(Hints const& receiver_hints); void ProcessMapHintsForPromises(Hints const& receiver_hints);
void ProcessHintsForPromiseResolve(Hints const& resolution_hints); void ProcessHintsForPromiseResolve(Hints const& resolution_hints);
void ProcessHintsForHasInPrototypeChain(Hints const& instance_hints); void ProcessHintsForHasInPrototypeChain(Hints const& instance_hints);
...@@ -438,7 +441,7 @@ class SerializerForBackgroundCompilation { ...@@ -438,7 +441,7 @@ class SerializerForBackgroundCompilation {
void ProcessContextAccess(Hints const& context_hints, int slot, int depth, void ProcessContextAccess(Hints const& context_hints, int slot, int depth,
ContextProcessingMode mode, ContextProcessingMode mode,
Hints* new_accumulator_hints = nullptr); Hints* result_hints = nullptr);
void ProcessImmutableLoad(ContextRef const& context, int slot, void ProcessImmutableLoad(ContextRef const& context, int slot,
ContextProcessingMode mode, ContextProcessingMode mode,
Hints* new_accumulator_hints); Hints* new_accumulator_hints);
...@@ -1164,20 +1167,20 @@ void SerializerForBackgroundCompilation::VisitPopContext( ...@@ -1164,20 +1167,20 @@ void SerializerForBackgroundCompilation::VisitPopContext(
void SerializerForBackgroundCompilation::ProcessImmutableLoad( void SerializerForBackgroundCompilation::ProcessImmutableLoad(
ContextRef const& context_ref, int slot, ContextProcessingMode mode, ContextRef const& context_ref, int slot, ContextProcessingMode mode,
Hints* new_accumulator_hints) { Hints* result_hints) {
DCHECK_EQ(mode, kSerializeSlot); DCHECK_EQ(mode, kSerializeSlot);
base::Optional<ObjectRef> slot_value = base::Optional<ObjectRef> slot_value =
context_ref.get(slot, SerializationPolicy::kSerializeIfNeeded); context_ref.get(slot, SerializationPolicy::kSerializeIfNeeded);
// If requested, record the object as a new hint for the accumulator. // If requested, record the object as a hint for the result value.
if (new_accumulator_hints != nullptr && slot_value.has_value()) { if (result_hints != nullptr && slot_value.has_value()) {
new_accumulator_hints->AddConstant(slot_value.value().object()); result_hints->AddConstant(slot_value.value().object());
} }
} }
void SerializerForBackgroundCompilation::ProcessContextAccess( void SerializerForBackgroundCompilation::ProcessContextAccess(
Hints const& context_hints, int slot, int depth, ContextProcessingMode mode, Hints const& context_hints, int slot, int depth, ContextProcessingMode mode,
Hints* new_accumulator_hints) { Hints* result_hints) {
// This function is for JSContextSpecialization::ReduceJSLoadContext and // This function is for JSContextSpecialization::ReduceJSLoadContext and
// ReduceJSStoreContext. Those reductions attempt to eliminate as many // ReduceJSStoreContext. Those reductions attempt to eliminate as many
// loads as possible by making use of constant Context objects. In the // loads as possible by making use of constant Context objects. In the
...@@ -1191,7 +1194,7 @@ void SerializerForBackgroundCompilation::ProcessContextAccess( ...@@ -1191,7 +1194,7 @@ void SerializerForBackgroundCompilation::ProcessContextAccess(
context_ref = context_ref.previous( context_ref = context_ref.previous(
&remaining_depth, SerializationPolicy::kSerializeIfNeeded); &remaining_depth, SerializationPolicy::kSerializeIfNeeded);
if (remaining_depth == 0 && mode != kIgnoreSlot) { if (remaining_depth == 0 && mode != kIgnoreSlot) {
ProcessImmutableLoad(context_ref, slot, mode, new_accumulator_hints); ProcessImmutableLoad(context_ref, slot, mode, result_hints);
} }
} }
} }
...@@ -1202,7 +1205,7 @@ void SerializerForBackgroundCompilation::ProcessContextAccess( ...@@ -1202,7 +1205,7 @@ void SerializerForBackgroundCompilation::ProcessContextAccess(
context_ref = context_ref.previous( context_ref = context_ref.previous(
&remaining_depth, SerializationPolicy::kSerializeIfNeeded); &remaining_depth, SerializationPolicy::kSerializeIfNeeded);
if (remaining_depth == 0 && mode != kIgnoreSlot) { if (remaining_depth == 0 && mode != kIgnoreSlot) {
ProcessImmutableLoad(context_ref, slot, mode, new_accumulator_hints); ProcessImmutableLoad(context_ref, slot, mode, result_hints);
} }
} }
} }
...@@ -1258,20 +1261,30 @@ void SerializerForBackgroundCompilation::VisitLdaImmutableCurrentContextSlot( ...@@ -1258,20 +1261,30 @@ void SerializerForBackgroundCompilation::VisitLdaImmutableCurrentContextSlot(
environment()->accumulator_hints().Add(new_accumulator_hints); environment()->accumulator_hints().Add(new_accumulator_hints);
} }
void SerializerForBackgroundCompilation::VisitLdaModuleVariable( void SerializerForBackgroundCompilation::ProcessModuleVariableAccess(
BytecodeArrayIterator* iterator) { BytecodeArrayIterator* iterator) {
const int slot = Context::EXTENSION_INDEX; const int slot = Context::EXTENSION_INDEX;
const int depth = iterator->GetUnsignedImmediateOperand(1); const int depth = iterator->GetUnsignedImmediateOperand(1);
Hints const& context_hints = environment()->current_context_hints(); Hints const& context_hints = environment()->current_context_hints();
ProcessContextAccess(context_hints, slot, depth, kSerializeSlot);
Hints result_hints(zone());
ProcessContextAccess(context_hints, slot, depth, kSerializeSlot,
&result_hints);
for (Handle<Object> constant : result_hints.constants()) {
ObjectRef object(broker(), constant);
// For JSTypedLowering::BuildGetModuleCell.
if (object.IsSourceTextModule()) object.AsSourceTextModule().Serialize();
}
}
void SerializerForBackgroundCompilation::VisitLdaModuleVariable(
BytecodeArrayIterator* iterator) {
ProcessModuleVariableAccess(iterator);
} }
void SerializerForBackgroundCompilation::VisitStaModuleVariable( void SerializerForBackgroundCompilation::VisitStaModuleVariable(
BytecodeArrayIterator* iterator) { BytecodeArrayIterator* iterator) {
const int slot = Context::EXTENSION_INDEX; ProcessModuleVariableAccess(iterator);
const int depth = iterator->GetUnsignedImmediateOperand(1);
Hints const& context_hints = environment()->current_context_hints();
ProcessContextAccess(context_hints, slot, depth, kSerializeSlot);
} }
void SerializerForBackgroundCompilation::VisitStaLookupSlot( void SerializerForBackgroundCompilation::VisitStaLookupSlot(
......
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