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 {
void Serialize();
CellRef GetCell(int cell_index) const;
base::Optional<CellRef> GetCell(int cell_index) const;
};
class CellRef : public HeapObjectRef {
......
......@@ -1709,7 +1709,7 @@ class SourceTextModuleData : public HeapObjectData {
Handle<SourceTextModule> object);
void Serialize(JSHeapBroker* broker);
CellData* GetCell(int cell_index) const;
CellData* GetCell(JSHeapBroker* broker, int cell_index) const;
private:
bool serialized_ = false;
......@@ -1724,8 +1724,14 @@ SourceTextModuleData::SourceTextModuleData(JSHeapBroker* broker,
imports_(broker->zone()),
exports_(broker->zone()) {}
CellData* SourceTextModuleData::GetCell(int cell_index) const {
CHECK(serialized_);
CellData* SourceTextModuleData::GetCell(JSHeapBroker* broker,
int cell_index) const {
if (!serialized_) {
DCHECK(imports_.empty());
TRACE_BROKER_MISSING(broker,
"module cell " << cell_index << " on " << this);
return nullptr;
}
CellData* cell;
switch (SourceTextModuleDescriptor::GetCellIndexKind(cell_index)) {
case SourceTextModuleDescriptor::kImport:
......@@ -3509,14 +3515,16 @@ uint64_t BigIntRef::AsUint64() const {
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) {
AllowHandleAllocation handle_allocation;
AllowHandleDereference allow_handle_dereference;
return CellRef(broker(),
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,
......
......@@ -30,7 +30,11 @@ Reduction JSHeapCopyReducer::Reduce(Node* node) {
ObjectRef object(broker(), HeapConstantOf(node->op()));
if (object.IsJSFunction()) object.AsJSFunction().Serialize();
if (object.IsJSObject()) object.AsJSObject().SerializeObjectCreateMap();
if (object.IsSourceTextModule()) object.AsSourceTextModule().Serialize();
if (!FLAG_concurrent_inlining) {
if (object.IsSourceTextModule()) {
object.AsSourceTextModule().Serialize();
}
}
break;
}
case IrOpcode::kJSCreateArray: {
......
......@@ -1367,8 +1367,8 @@ Node* JSTypedLowering::BuildGetModuleCell(Node* node) {
if (module_type.IsHeapConstant()) {
SourceTextModuleRef module_constant =
module_type.AsHeapConstant()->Ref().AsSourceTextModule();
CellRef cell_constant = module_constant.GetCell(cell_index);
return jsgraph()->Constant(cell_constant);
base::Optional<CellRef> cell_constant = module_constant.GetCell(cell_index);
if (cell_constant.has_value()) return jsgraph()->Constant(*cell_constant);
}
FieldAccess field_access;
......
......@@ -402,6 +402,9 @@ class SerializerForBackgroundCompilation {
ElementAccessFeedback const& feedback,
AccessMode access_mode);
void ProcessModuleVariableAccess(
interpreter::BytecodeArrayIterator* iterator);
void ProcessMapHintsForPromises(Hints const& receiver_hints);
void ProcessHintsForPromiseResolve(Hints const& resolution_hints);
void ProcessHintsForHasInPrototypeChain(Hints const& instance_hints);
......@@ -438,7 +441,7 @@ class SerializerForBackgroundCompilation {
void ProcessContextAccess(Hints const& context_hints, int slot, int depth,
ContextProcessingMode mode,
Hints* new_accumulator_hints = nullptr);
Hints* result_hints = nullptr);
void ProcessImmutableLoad(ContextRef const& context, int slot,
ContextProcessingMode mode,
Hints* new_accumulator_hints);
......@@ -1164,20 +1167,20 @@ void SerializerForBackgroundCompilation::VisitPopContext(
void SerializerForBackgroundCompilation::ProcessImmutableLoad(
ContextRef const& context_ref, int slot, ContextProcessingMode mode,
Hints* new_accumulator_hints) {
Hints* result_hints) {
DCHECK_EQ(mode, kSerializeSlot);
base::Optional<ObjectRef> slot_value =
context_ref.get(slot, SerializationPolicy::kSerializeIfNeeded);
// If requested, record the object as a new hint for the accumulator.
if (new_accumulator_hints != nullptr && slot_value.has_value()) {
new_accumulator_hints->AddConstant(slot_value.value().object());
// If requested, record the object as a hint for the result value.
if (result_hints != nullptr && slot_value.has_value()) {
result_hints->AddConstant(slot_value.value().object());
}
}
void SerializerForBackgroundCompilation::ProcessContextAccess(
Hints const& context_hints, int slot, int depth, ContextProcessingMode mode,
Hints* new_accumulator_hints) {
Hints* result_hints) {
// This function is for JSContextSpecialization::ReduceJSLoadContext and
// ReduceJSStoreContext. Those reductions attempt to eliminate as many
// loads as possible by making use of constant Context objects. In the
......@@ -1191,7 +1194,7 @@ void SerializerForBackgroundCompilation::ProcessContextAccess(
context_ref = context_ref.previous(
&remaining_depth, SerializationPolicy::kSerializeIfNeeded);
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(
context_ref = context_ref.previous(
&remaining_depth, SerializationPolicy::kSerializeIfNeeded);
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(
environment()->accumulator_hints().Add(new_accumulator_hints);
}
void SerializerForBackgroundCompilation::VisitLdaModuleVariable(
void SerializerForBackgroundCompilation::ProcessModuleVariableAccess(
BytecodeArrayIterator* iterator) {
const int slot = Context::EXTENSION_INDEX;
const int depth = iterator->GetUnsignedImmediateOperand(1);
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(
BytecodeArrayIterator* iterator) {
const int slot = Context::EXTENSION_INDEX;
const int depth = iterator->GetUnsignedImmediateOperand(1);
Hints const& context_hints = environment()->current_context_hints();
ProcessContextAccess(context_hints, slot, depth, kSerializeSlot);
ProcessModuleVariableAccess(iterator);
}
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