[turbofan] Introduce SerializationPolicy enum

This improves overall readability by replacing bool arguments.

Bug: v8:7790
Change-Id: I02f8f43088497c9503f253788ee5e0015c7edc2d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1730991
Commit-Queue: Georg Neis <neis@chromium.org>
Reviewed-by: Maya Lekova <mslekova@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63032}
This commit is contained in:
Georg Neis 2019-08-01 14:45:15 +02:00 committed by Commit Bot
parent 5a624dc465
commit 6d31360757
6 changed files with 139 additions and 106 deletions

View File

@ -964,7 +964,8 @@ BytecodeGraphBuilder::BytecodeGraphBuilder(
bytecode_analysis_(broker_->GetBytecodeAnalysis( bytecode_analysis_(broker_->GetBytecodeAnalysis(
bytecode_array.object(), osr_offset, bytecode_array.object(), osr_offset,
flags & BytecodeGraphBuilderFlag::kAnalyzeEnvironmentLiveness, flags & BytecodeGraphBuilderFlag::kAnalyzeEnvironmentLiveness,
!FLAG_concurrent_inlining)), FLAG_concurrent_inlining ? SerializationPolicy::kAssumeSerialized
: SerializationPolicy::kSerializeIfNeeded)),
environment_(nullptr), environment_(nullptr),
osr_(!osr_offset.IsNone()), osr_(!osr_offset.IsNone()),
currently_peeled_loop_offset_(-1), currently_peeled_loop_offset_(-1),

View File

@ -35,6 +35,8 @@ namespace compiler {
// For a store during literal creation, do not walk up the prototype chain. // For a store during literal creation, do not walk up the prototype chain.
enum class AccessMode { kLoad, kStore, kStoreInLiteral, kHas }; enum class AccessMode { kLoad, kStore, kStoreInLiteral, kHas };
enum class SerializationPolicy { kAssumeSerialized, kSerializeIfNeeded };
enum class OddballType : uint8_t { enum class OddballType : uint8_t {
kNone, // Not an Oddball. kNone, // Not an Oddball.
kBoolean, // True or False. kBoolean, // True or False.
@ -134,8 +136,9 @@ class V8_EXPORT_PRIVATE ObjectRef {
// Return the element at key {index} if {index} is known to be an own data // Return the element at key {index} if {index} is known to be an own data
// property of the object that is non-writable and non-configurable. // property of the object that is non-writable and non-configurable.
base::Optional<ObjectRef> GetOwnConstantElement(uint32_t index, base::Optional<ObjectRef> GetOwnConstantElement(
bool serialize = false) const; uint32_t index, SerializationPolicy policy =
SerializationPolicy::kAssumeSerialized) const;
Isolate* isolate() const; Isolate* isolate() const;
@ -244,7 +247,8 @@ class JSObjectRef : public JSReceiverRef {
// if {index} is known to be an own data property of the object. // if {index} is known to be an own data property of the object.
base::Optional<ObjectRef> GetOwnDataProperty( base::Optional<ObjectRef> GetOwnDataProperty(
Representation field_representation, FieldIndex index, Representation field_representation, FieldIndex index,
bool serialize = false) const; SerializationPolicy policy =
SerializationPolicy::kAssumeSerialized) const;
FixedArrayBaseRef elements() const; FixedArrayBaseRef elements() const;
void SerializeElements(); void SerializeElements();
void EnsureElementsTenured(); void EnsureElementsTenured();
@ -339,10 +343,14 @@ class ContextRef : public HeapObjectRef {
// followed. If {depth} != 0 on function return, then it only got // followed. If {depth} != 0 on function return, then it only got
// partway to the desired depth. If {serialize} is true, then // partway to the desired depth. If {serialize} is true, then
// {previous} will cache its findings. // {previous} will cache its findings.
ContextRef previous(size_t* depth, bool serialize = false) const; ContextRef previous(size_t* depth,
SerializationPolicy policy =
SerializationPolicy::kAssumeSerialized) const;
// Only returns a value if the index is valid for this ContextRef. // Only returns a value if the index is valid for this ContextRef.
base::Optional<ObjectRef> get(int index, bool serialize = false) const; base::Optional<ObjectRef> get(
int index, SerializationPolicy policy =
SerializationPolicy::kAssumeSerialized) const;
// We only serialize the ScopeInfo if certain Promise // We only serialize the ScopeInfo if certain Promise
// builtins are called. // builtins are called.
@ -602,8 +610,9 @@ class FunctionTemplateInfoRef : public HeapObjectRef {
void SerializeCallCode(); void SerializeCallCode();
base::Optional<CallHandlerInfoRef> call_code() const; base::Optional<CallHandlerInfoRef> call_code() const;
HolderLookupResult LookupHolderOfExpectedType(MapRef receiver_map, HolderLookupResult LookupHolderOfExpectedType(
bool serialize); MapRef receiver_map,
SerializationPolicy policy = SerializationPolicy::kAssumeSerialized);
}; };
class FixedArrayBaseRef : public HeapObjectRef { class FixedArrayBaseRef : public HeapObjectRef {
@ -670,8 +679,9 @@ class JSArrayRef : public JSObjectRef {
// Return the element at key {index} if the array has a copy-on-write elements // Return the element at key {index} if the array has a copy-on-write elements
// storage and {index} is known to be an own data property. // storage and {index} is known to be an own data property.
base::Optional<ObjectRef> GetOwnCowElement(uint32_t index, base::Optional<ObjectRef> GetOwnCowElement(
bool serialize = false) const; uint32_t index, SerializationPolicy policy =
SerializationPolicy::kAssumeSerialized) const;
}; };
class ScopeInfoRef : public HeapObjectRef { class ScopeInfoRef : public HeapObjectRef {
@ -716,8 +726,9 @@ class V8_EXPORT_PRIVATE SharedFunctionInfoRef : public HeapObjectRef {
// Template objects may not be created at compilation time. This method // Template objects may not be created at compilation time. This method
// wraps the retrieval of the template object and creates it if // wraps the retrieval of the template object and creates it if
// necessary. // necessary.
JSArrayRef GetTemplateObject(ObjectRef description, FeedbackVectorRef vector, JSArrayRef GetTemplateObject(
FeedbackSlot slot, bool serialize = false); ObjectRef description, FeedbackVectorRef vector, FeedbackSlot slot,
SerializationPolicy policy = SerializationPolicy::kAssumeSerialized);
void SerializeFunctionTemplateInfo(); void SerializeFunctionTemplateInfo();
base::Optional<FunctionTemplateInfoRef> function_template_info() const; base::Optional<FunctionTemplateInfoRef> function_template_info() const;
@ -786,8 +797,9 @@ class JSGlobalProxyRef : public JSObjectRef {
// If {serialize} is true: // If {serialize} is true:
// Like above but potentially access the heap and serialize the necessary // Like above but potentially access the heap and serialize the necessary
// information. // information.
base::Optional<PropertyCellRef> GetPropertyCell(NameRef const& name, base::Optional<PropertyCellRef> GetPropertyCell(
bool serialize = false) const; NameRef const& name, SerializationPolicy policy =
SerializationPolicy::kAssumeSerialized) const;
}; };
class CodeRef : public HeapObjectRef { class CodeRef : public HeapObjectRef {

View File

@ -2941,8 +2941,7 @@ Reduction JSCallReducer::ReduceCallApiFunction(
// See if we can constant-fold the compatible receiver checks. // See if we can constant-fold the compatible receiver checks.
HolderLookupResult api_holder = HolderLookupResult api_holder =
function_template_info.LookupHolderOfExpectedType(first_receiver_map, function_template_info.LookupHolderOfExpectedType(first_receiver_map);
false);
if (api_holder.lookup == CallOptimization::kHolderNotFound) if (api_holder.lookup == CallOptimization::kHolderNotFound)
return inference.NoChange(); return inference.NoChange();
@ -2972,8 +2971,7 @@ Reduction JSCallReducer::ReduceCallApiFunction(
for (size_t i = 1; i < receiver_maps.size(); ++i) { for (size_t i = 1; i < receiver_maps.size(); ++i) {
MapRef receiver_map(broker(), receiver_maps[i]); MapRef receiver_map(broker(), receiver_maps[i]);
HolderLookupResult holder_i = HolderLookupResult holder_i =
function_template_info.LookupHolderOfExpectedType(receiver_map, function_template_info.LookupHolderOfExpectedType(receiver_map);
false);
if (api_holder.lookup != holder_i.lookup) return inference.NoChange(); if (api_holder.lookup != holder_i.lookup) return inference.NoChange();
if (!(api_holder.holder.has_value() && holder_i.holder.has_value())) if (!(api_holder.holder.has_value() && holder_i.holder.has_value()))

View File

@ -283,11 +283,13 @@ class JSObjectData : public JSReceiverData {
return object_create_map_; return object_create_map_;
} }
ObjectData* GetOwnConstantElement(JSHeapBroker* broker, uint32_t index, ObjectData* GetOwnConstantElement(
bool serialize); JSHeapBroker* broker, uint32_t index,
ObjectData* GetOwnDataProperty(JSHeapBroker* broker, SerializationPolicy policy = SerializationPolicy::kAssumeSerialized);
Representation representation, ObjectData* GetOwnDataProperty(
FieldIndex field_index, bool serialize); JSHeapBroker* broker, Representation representation,
FieldIndex field_index,
SerializationPolicy policy = SerializationPolicy::kAssumeSerialized);
// This method is only used to assert our invariants. // This method is only used to assert our invariants.
bool cow_or_empty_elements_tenured() const; bool cow_or_empty_elements_tenured() const;
@ -369,12 +371,12 @@ ObjectRef GetOwnDataPropertyFromHeap(JSHeapBroker* broker,
ObjectData* JSObjectData::GetOwnConstantElement(JSHeapBroker* broker, ObjectData* JSObjectData::GetOwnConstantElement(JSHeapBroker* broker,
uint32_t index, uint32_t index,
bool serialize) { SerializationPolicy policy) {
for (auto const& p : own_constant_elements_) { for (auto const& p : own_constant_elements_) {
if (p.first == index) return p.second; if (p.first == index) return p.second;
} }
if (!serialize) { if (policy == SerializationPolicy::kAssumeSerialized) {
TRACE_MISSING(broker, "knowledge about index " << index << " on " << this); TRACE_MISSING(broker, "knowledge about index " << index << " on " << this);
return nullptr; return nullptr;
} }
@ -389,11 +391,11 @@ ObjectData* JSObjectData::GetOwnConstantElement(JSHeapBroker* broker,
ObjectData* JSObjectData::GetOwnDataProperty(JSHeapBroker* broker, ObjectData* JSObjectData::GetOwnDataProperty(JSHeapBroker* broker,
Representation representation, Representation representation,
FieldIndex field_index, FieldIndex field_index,
bool serialize) { SerializationPolicy policy) {
auto p = own_properties_.find(field_index.property_index()); auto p = own_properties_.find(field_index.property_index());
if (p != own_properties_.end()) return p->second; if (p != own_properties_.end()) return p->second;
if (!serialize) { if (policy == SerializationPolicy::kAssumeSerialized) {
TRACE_MISSING(broker, "knowledge about property with index " TRACE_MISSING(broker, "knowledge about property with index "
<< field_index.property_index() << " on " << field_index.property_index() << " on "
<< this); << this);
@ -581,12 +583,15 @@ class ContextData : public HeapObjectData {
// {previous} will return the closest valid context possible to desired // {previous} will return the closest valid context possible to desired
// {depth}, decrementing {depth} for each previous link successfully followed. // {depth}, decrementing {depth} for each previous link successfully followed.
// If {serialize} is true, it will serialize contexts along the way. ContextData* previous(
ContextData* previous(JSHeapBroker* broker, size_t* depth, bool serialize); JSHeapBroker* broker, size_t* depth,
SerializationPolicy policy = SerializationPolicy::kAssumeSerialized);
// Returns nullptr if the slot index isn't valid or wasn't serialized // Returns nullptr if the slot index isn't valid or wasn't serialized,
// (unless {serialize} is true). // unless {policy} is {kSerializeIfNeeded}.
ObjectData* GetSlot(JSHeapBroker* broker, int index, bool serialize); ObjectData* GetSlot(
JSHeapBroker* broker, int index,
SerializationPolicy policy = SerializationPolicy::kAssumeSerialized);
private: private:
ZoneMap<int, ObjectData*> slots_; ZoneMap<int, ObjectData*> slots_;
@ -598,10 +603,11 @@ ContextData::ContextData(JSHeapBroker* broker, ObjectData** storage,
: HeapObjectData(broker, storage, object), slots_(broker->zone()) {} : HeapObjectData(broker, storage, object), slots_(broker->zone()) {}
ContextData* ContextData::previous(JSHeapBroker* broker, size_t* depth, ContextData* ContextData::previous(JSHeapBroker* broker, size_t* depth,
bool serialize) { SerializationPolicy policy) {
if (*depth == 0) return this; if (*depth == 0) return this;
if (serialize && previous_ == nullptr) { if (policy == SerializationPolicy::kSerializeIfNeeded &&
previous_ == nullptr) {
TraceScope tracer(broker, this, "ContextData::previous"); TraceScope tracer(broker, this, "ContextData::previous");
Handle<Context> context = Handle<Context>::cast(object()); Handle<Context> context = Handle<Context>::cast(object());
Object prev = context->unchecked_previous(); Object prev = context->unchecked_previous();
@ -612,20 +618,20 @@ ContextData* ContextData::previous(JSHeapBroker* broker, size_t* depth,
if (previous_ != nullptr) { if (previous_ != nullptr) {
*depth = *depth - 1; *depth = *depth - 1;
return previous_->previous(broker, depth, serialize); return previous_->previous(broker, depth, policy);
} }
return this; return this;
} }
ObjectData* ContextData::GetSlot(JSHeapBroker* broker, int index, ObjectData* ContextData::GetSlot(JSHeapBroker* broker, int index,
bool serialize) { SerializationPolicy policy) {
CHECK_GE(index, 0); CHECK_GE(index, 0);
auto search = slots_.find(index); auto search = slots_.find(index);
if (search != slots_.end()) { if (search != slots_.end()) {
return search->second; return search->second;
} }
if (serialize) { if (policy == SerializationPolicy::kSerializeIfNeeded) {
Handle<Context> context = Handle<Context>::cast(object()); Handle<Context> context = Handle<Context>::cast(object());
if (index < context->length()) { if (index < context->length()) {
TraceScope tracer(broker, this, "ContextData::GetSlot"); TraceScope tracer(broker, this, "ContextData::GetSlot");
@ -685,8 +691,9 @@ class StringData : public NameData {
bool is_external_string() const { return is_external_string_; } bool is_external_string() const { return is_external_string_; }
bool is_seq_string() const { return is_seq_string_; } bool is_seq_string() const { return is_seq_string_; }
StringData* GetCharAsString(JSHeapBroker* broker, uint32_t index, StringData* GetCharAsString(
bool serialize); JSHeapBroker* broker, uint32_t index,
SerializationPolicy policy = SerializationPolicy::kAssumeSerialized);
private: private:
int const length_; int const length_;
@ -735,14 +742,14 @@ class InternalizedStringData : public StringData {
}; };
StringData* StringData::GetCharAsString(JSHeapBroker* broker, uint32_t index, StringData* StringData::GetCharAsString(JSHeapBroker* broker, uint32_t index,
bool serialize) { SerializationPolicy policy) {
if (index >= static_cast<uint32_t>(length())) return nullptr; if (index >= static_cast<uint32_t>(length())) return nullptr;
for (auto const& p : chars_as_strings_) { for (auto const& p : chars_as_strings_) {
if (p.first == index) return p.second; if (p.first == index) return p.second;
} }
if (!serialize) { if (policy == SerializationPolicy::kAssumeSerialized) {
TRACE_MISSING(broker, "knowledge about index " << index << " on " << this); TRACE_MISSING(broker, "knowledge about index " << index << " on " << this);
return nullptr; return nullptr;
} }
@ -1516,8 +1523,9 @@ class JSArrayData : public JSObjectData {
void Serialize(JSHeapBroker* broker); void Serialize(JSHeapBroker* broker);
ObjectData* length() const { return length_; } ObjectData* length() const { return length_; }
ObjectData* GetOwnElement(JSHeapBroker* broker, uint32_t index, ObjectData* GetOwnElement(
bool serialize); JSHeapBroker* broker, uint32_t index,
SerializationPolicy policy = SerializationPolicy::kAssumeSerialized);
private: private:
bool serialized_ = false; bool serialized_ = false;
@ -1546,12 +1554,12 @@ void JSArrayData::Serialize(JSHeapBroker* broker) {
} }
ObjectData* JSArrayData::GetOwnElement(JSHeapBroker* broker, uint32_t index, ObjectData* JSArrayData::GetOwnElement(JSHeapBroker* broker, uint32_t index,
bool serialize) { SerializationPolicy policy) {
for (auto const& p : own_elements_) { for (auto const& p : own_elements_) {
if (p.first == index) return p.second; if (p.first == index) return p.second;
} }
if (!serialize) { if (policy == SerializationPolicy::kAssumeSerialized) {
TRACE_MISSING(broker, "knowledge about index " << index << " on " << this); TRACE_MISSING(broker, "knowledge about index " << index << " on " << this);
return nullptr; return nullptr;
} }
@ -1768,8 +1776,9 @@ class JSGlobalProxyData : public JSObjectData {
JSGlobalProxyData(JSHeapBroker* broker, ObjectData** storage, JSGlobalProxyData(JSHeapBroker* broker, ObjectData** storage,
Handle<JSGlobalProxy> object); Handle<JSGlobalProxy> object);
PropertyCellData* GetPropertyCell(JSHeapBroker* broker, NameData* name, PropertyCellData* GetPropertyCell(
bool serialize); JSHeapBroker* broker, NameData* name,
SerializationPolicy policy = SerializationPolicy::kAssumeSerialized);
private: private:
// Properties that either // Properties that either
@ -1799,15 +1808,14 @@ base::Optional<PropertyCellRef> GetPropertyCellFromHeap(JSHeapBroker* broker,
} }
} // namespace } // namespace
PropertyCellData* JSGlobalProxyData::GetPropertyCell(JSHeapBroker* broker, PropertyCellData* JSGlobalProxyData::GetPropertyCell(
NameData* name, JSHeapBroker* broker, NameData* name, SerializationPolicy policy) {
bool serialize) {
CHECK_NOT_NULL(name); CHECK_NOT_NULL(name);
for (auto const& p : properties_) { for (auto const& p : properties_) {
if (p.first == name) return p.second; if (p.first == name) return p.second;
} }
if (!serialize) { if (policy == SerializationPolicy::kAssumeSerialized) {
TRACE_MISSING(broker, "knowledge about global property " << name); TRACE_MISSING(broker, "knowledge about global property " << name);
return nullptr; return nullptr;
} }
@ -2113,7 +2121,8 @@ bool ObjectRef::equals(const ObjectRef& other) const {
Isolate* ObjectRef::isolate() const { return broker()->isolate(); } Isolate* ObjectRef::isolate() const { return broker()->isolate(); }
ContextRef ContextRef::previous(size_t* depth, bool serialize) const { ContextRef ContextRef::previous(size_t* depth,
SerializationPolicy policy) const {
DCHECK_NOT_NULL(depth); DCHECK_NOT_NULL(depth);
if (broker()->mode() == JSHeapBroker::kDisabled) { if (broker()->mode() == JSHeapBroker::kDisabled) {
AllowHandleAllocation handle_allocation; AllowHandleAllocation handle_allocation;
@ -2126,10 +2135,11 @@ ContextRef ContextRef::previous(size_t* depth, bool serialize) const {
return ContextRef(broker(), handle(current, broker()->isolate())); return ContextRef(broker(), handle(current, broker()->isolate()));
} }
ContextData* current = this->data()->AsContext(); ContextData* current = this->data()->AsContext();
return ContextRef(broker(), current->previous(broker(), depth, serialize)); return ContextRef(broker(), current->previous(broker(), depth, policy));
} }
base::Optional<ObjectRef> ContextRef::get(int index, bool serialize) const { base::Optional<ObjectRef> ContextRef::get(int index,
SerializationPolicy policy) const {
if (broker()->mode() == JSHeapBroker::kDisabled) { if (broker()->mode() == JSHeapBroker::kDisabled) {
AllowHandleAllocation handle_allocation; AllowHandleAllocation handle_allocation;
AllowHandleDereference handle_dereference; AllowHandleDereference handle_dereference;
@ -2137,7 +2147,7 @@ base::Optional<ObjectRef> ContextRef::get(int index, bool serialize) const {
return ObjectRef(broker(), value); return ObjectRef(broker(), value);
} }
ObjectData* optional_slot = ObjectData* optional_slot =
data()->AsContext()->GetSlot(broker(), index, serialize); data()->AsContext()->GetSlot(broker(), index, policy);
if (optional_slot != nullptr) { if (optional_slot != nullptr) {
return ObjectRef(broker(), optional_slot); return ObjectRef(broker(), optional_slot);
} }
@ -3083,7 +3093,7 @@ bool FunctionTemplateInfoRef::has_call_code() const {
BIMODAL_ACCESSOR_C(FunctionTemplateInfo, bool, accept_any_receiver) BIMODAL_ACCESSOR_C(FunctionTemplateInfo, bool, accept_any_receiver)
HolderLookupResult FunctionTemplateInfoRef::LookupHolderOfExpectedType( HolderLookupResult FunctionTemplateInfoRef::LookupHolderOfExpectedType(
MapRef receiver_map, bool serialize) { MapRef receiver_map, SerializationPolicy policy) {
const HolderLookupResult not_found; const HolderLookupResult not_found;
if (broker()->mode() == JSHeapBroker::kDisabled) { if (broker()->mode() == JSHeapBroker::kDisabled) {
@ -3119,7 +3129,7 @@ HolderLookupResult FunctionTemplateInfoRef::LookupHolderOfExpectedType(
if (lookup_it != fti_data->known_receivers().cend()) { if (lookup_it != fti_data->known_receivers().cend()) {
return lookup_it->second; return lookup_it->second;
} }
if (!serialize) { if (policy == SerializationPolicy::kAssumeSerialized) {
TRACE_BROKER_MISSING(broker(), TRACE_BROKER_MISSING(broker(),
"holder for receiver with map " << receiver_map); "holder for receiver with map " << receiver_map);
return not_found; return not_found;
@ -3344,7 +3354,7 @@ Maybe<double> ObjectRef::OddballToNumber() const {
} }
base::Optional<ObjectRef> ObjectRef::GetOwnConstantElement( base::Optional<ObjectRef> ObjectRef::GetOwnConstantElement(
uint32_t index, bool serialize) const { uint32_t index, SerializationPolicy policy) const {
if (broker()->mode() == JSHeapBroker::kDisabled) { if (broker()->mode() == JSHeapBroker::kDisabled) {
return (IsJSObject() || IsString()) return (IsJSObject() || IsString())
? GetOwnElementFromHeap(broker(), object(), index, true) ? GetOwnElementFromHeap(broker(), object(), index, true)
@ -3353,9 +3363,9 @@ base::Optional<ObjectRef> ObjectRef::GetOwnConstantElement(
ObjectData* element = nullptr; ObjectData* element = nullptr;
if (IsJSObject()) { if (IsJSObject()) {
element = element =
data()->AsJSObject()->GetOwnConstantElement(broker(), index, serialize); data()->AsJSObject()->GetOwnConstantElement(broker(), index, policy);
} else if (IsString()) { } else if (IsString()) {
element = data()->AsString()->GetCharAsString(broker(), index, serialize); element = data()->AsString()->GetCharAsString(broker(), index, policy);
} }
if (element == nullptr) return base::nullopt; if (element == nullptr) return base::nullopt;
return ObjectRef(broker(), element); return ObjectRef(broker(), element);
@ -3363,26 +3373,26 @@ base::Optional<ObjectRef> ObjectRef::GetOwnConstantElement(
base::Optional<ObjectRef> JSObjectRef::GetOwnDataProperty( base::Optional<ObjectRef> JSObjectRef::GetOwnDataProperty(
Representation field_representation, FieldIndex index, Representation field_representation, FieldIndex index,
bool serialize) const { SerializationPolicy policy) const {
if (broker()->mode() == JSHeapBroker::kDisabled) { if (broker()->mode() == JSHeapBroker::kDisabled) {
return GetOwnDataPropertyFromHeap(broker(), return GetOwnDataPropertyFromHeap(broker(),
Handle<JSObject>::cast(object()), Handle<JSObject>::cast(object()),
field_representation, index); field_representation, index);
} }
ObjectData* property = data()->AsJSObject()->GetOwnDataProperty( ObjectData* property = data()->AsJSObject()->GetOwnDataProperty(
broker(), field_representation, index, serialize); broker(), field_representation, index, policy);
if (property == nullptr) return base::nullopt; if (property == nullptr) return base::nullopt;
return ObjectRef(broker(), property); return ObjectRef(broker(), property);
} }
base::Optional<ObjectRef> JSArrayRef::GetOwnCowElement(uint32_t index, base::Optional<ObjectRef> JSArrayRef::GetOwnCowElement(
bool serialize) const { uint32_t index, SerializationPolicy policy) const {
if (broker()->mode() == JSHeapBroker::kDisabled) { if (broker()->mode() == JSHeapBroker::kDisabled) {
if (!object()->elements().IsCowArray()) return base::nullopt; if (!object()->elements().IsCowArray()) return base::nullopt;
return GetOwnElementFromHeap(broker(), object(), index, false); return GetOwnElementFromHeap(broker(), object(), index, false);
} }
if (serialize) { if (policy == SerializationPolicy::kSerializeIfNeeded) {
data()->AsJSObject()->SerializeElements(broker()); data()->AsJSObject()->SerializeElements(broker());
} else if (!data()->AsJSObject()->serialized_elements()) { } else if (!data()->AsJSObject()->serialized_elements()) {
TRACE(broker(), "'elements' on " << this); TRACE(broker(), "'elements' on " << this);
@ -3391,7 +3401,7 @@ base::Optional<ObjectRef> JSArrayRef::GetOwnCowElement(uint32_t index,
if (!elements().map().IsFixedCowArrayMap()) return base::nullopt; if (!elements().map().IsFixedCowArrayMap()) return base::nullopt;
ObjectData* element = ObjectData* element =
data()->AsJSArray()->GetOwnElement(broker(), index, serialize); data()->AsJSArray()->GetOwnElement(broker(), index, policy);
if (element == nullptr) return base::nullopt; if (element == nullptr) return base::nullopt;
return ObjectRef(broker(), element); return ObjectRef(broker(), element);
} }
@ -3667,10 +3677,9 @@ bool JSFunctionRef::IsSerializedForCompilation() const {
shared().IsSerializedForCompilation(feedback_vector()); shared().IsSerializedForCompilation(feedback_vector());
} }
JSArrayRef SharedFunctionInfoRef::GetTemplateObject(ObjectRef description, JSArrayRef SharedFunctionInfoRef::GetTemplateObject(
FeedbackVectorRef vector, ObjectRef description, FeedbackVectorRef vector, FeedbackSlot slot,
FeedbackSlot slot, SerializationPolicy policy) {
bool serialize) {
// Look in the feedback vector for the array. A Smi indicates that it's // Look in the feedback vector for the array. A Smi indicates that it's
// not yet cached here. // not yet cached here.
ObjectRef candidate = vector.get(slot); ObjectRef candidate = vector.get(slot);
@ -3693,7 +3702,7 @@ JSArrayRef SharedFunctionInfoRef::GetTemplateObject(ObjectRef description,
JSArrayData* array = data()->AsSharedFunctionInfo()->GetTemplateObject(slot); JSArrayData* array = data()->AsSharedFunctionInfo()->GetTemplateObject(slot);
if (array != nullptr) return JSArrayRef(broker(), array); if (array != nullptr) return JSArrayRef(broker(), array);
CHECK(serialize); CHECK_EQ(policy, SerializationPolicy::kSerializeIfNeeded);
CHECK(broker()->SerializingAllowed()); CHECK(broker()->SerializingAllowed());
Handle<TemplateObjectDescription> tod = Handle<TemplateObjectDescription> tod =
@ -3825,13 +3834,13 @@ void FunctionTemplateInfoRef::SerializeCallCode() {
} }
base::Optional<PropertyCellRef> JSGlobalProxyRef::GetPropertyCell( base::Optional<PropertyCellRef> JSGlobalProxyRef::GetPropertyCell(
NameRef const& name, bool serialize) const { NameRef const& name, SerializationPolicy policy) const {
if (broker()->mode() == JSHeapBroker::kDisabled) { if (broker()->mode() == JSHeapBroker::kDisabled) {
return GetPropertyCellFromHeap(broker(), name.object()); return GetPropertyCellFromHeap(broker(), name.object());
} }
PropertyCellData* property_cell_data = PropertyCellData* property_cell_data =
data()->AsJSGlobalProxy()->GetPropertyCell( data()->AsJSGlobalProxy()->GetPropertyCell(broker(),
broker(), name.data()->AsName(), serialize); name.data()->AsName(), policy);
if (property_cell_data == nullptr) return base::nullopt; if (property_cell_data == nullptr) return base::nullopt;
return PropertyCellRef(broker(), property_cell_data); return PropertyCellRef(broker(), property_cell_data);
} }
@ -4121,7 +4130,8 @@ GlobalAccessFeedback const* JSHeapBroker::ProcessFeedbackForGlobalAccess(
} }
ContextRef context_ref(this, context); ContextRef context_ref(this, context);
if (immutable) { if (immutable) {
context_ref.get(context_slot_index, true); context_ref.get(context_slot_index,
SerializationPolicy::kSerializeIfNeeded);
} }
return new (zone()) return new (zone())
GlobalAccessFeedback(context_ref, context_slot_index, immutable); GlobalAccessFeedback(context_ref, context_slot_index, immutable);
@ -4412,7 +4422,7 @@ ForInFeedback const* ProcessedFeedback::AsForIn() const {
BytecodeAnalysis const& JSHeapBroker::GetBytecodeAnalysis( BytecodeAnalysis const& JSHeapBroker::GetBytecodeAnalysis(
Handle<BytecodeArray> bytecode_array, BailoutId osr_bailout_id, Handle<BytecodeArray> bytecode_array, BailoutId osr_bailout_id,
bool analyze_liveness, bool serialize) { bool analyze_liveness, SerializationPolicy policy) {
ObjectData* bytecode_array_data = GetData(bytecode_array); ObjectData* bytecode_array_data = GetData(bytecode_array);
CHECK_NOT_NULL(bytecode_array_data); CHECK_NOT_NULL(bytecode_array_data);
@ -4432,7 +4442,7 @@ BytecodeAnalysis const& JSHeapBroker::GetBytecodeAnalysis(
return *it->second; return *it->second;
} }
CHECK(serialize); CHECK_EQ(policy, SerializationPolicy::kSerializeIfNeeded);
BytecodeAnalysis* analysis = new (zone()) BytecodeAnalysis( BytecodeAnalysis* analysis = new (zone()) BytecodeAnalysis(
bytecode_array, zone(), osr_bailout_id, analyze_liveness); bytecode_array, zone(), osr_bailout_id, analyze_liveness);
DCHECK_EQ(analysis->osr_bailout_id(), osr_bailout_id); DCHECK_EQ(analysis->osr_bailout_id(), osr_bailout_id);

View File

@ -129,7 +129,8 @@ class V8_EXPORT_PRIVATE JSHeapBroker {
FeedbackSource const& source); FeedbackSource const& source);
BytecodeAnalysis const& GetBytecodeAnalysis( BytecodeAnalysis const& GetBytecodeAnalysis(
Handle<BytecodeArray> bytecode_array, BailoutId osr_offset, Handle<BytecodeArray> bytecode_array, BailoutId osr_offset,
bool analyze_liveness, bool serialize); bool analyze_liveness,
SerializationPolicy policy = SerializationPolicy::kAssumeSerialized);
// Binary, comparison and for-in hints can be fully expressed via // Binary, comparison and for-in hints can be fully expressed via
// an enum. Insufficient feedback is signaled by <Hint enum>::kNone. // an enum. Insufficient feedback is signaled by <Hint enum>::kNone.

View File

@ -459,7 +459,8 @@ class SerializerForBackgroundCompilation {
void IncorporateJumpTargetEnvironment(int target_offset); void IncorporateJumpTargetEnvironment(int target_offset);
Handle<BytecodeArray> bytecode_array() const; Handle<BytecodeArray> bytecode_array() const;
BytecodeAnalysis const& GetBytecodeAnalysis(bool serialize); BytecodeAnalysis const& GetBytecodeAnalysis(
SerializationPolicy policy = SerializationPolicy::kAssumeSerialized);
JSHeapBroker* broker() const { return broker_; } JSHeapBroker* broker() const { return broker_; }
CompilationDependencies* dependencies() const { return dependencies_; } CompilationDependencies* dependencies() const { return dependencies_; }
@ -960,16 +961,17 @@ Handle<BytecodeArray> SerializerForBackgroundCompilation::bytecode_array()
} }
BytecodeAnalysis const& SerializerForBackgroundCompilation::GetBytecodeAnalysis( BytecodeAnalysis const& SerializerForBackgroundCompilation::GetBytecodeAnalysis(
bool serialize) { SerializationPolicy policy) {
return broker()->GetBytecodeAnalysis( return broker()->GetBytecodeAnalysis(
bytecode_array(), osr_offset(), bytecode_array(), osr_offset(),
flags() & flags() &
SerializerForBackgroundCompilationFlag::kAnalyzeEnvironmentLiveness, SerializerForBackgroundCompilationFlag::kAnalyzeEnvironmentLiveness,
serialize); policy);
} }
void SerializerForBackgroundCompilation::TraverseBytecode() { void SerializerForBackgroundCompilation::TraverseBytecode() {
BytecodeAnalysis const& bytecode_analysis = GetBytecodeAnalysis(true); BytecodeAnalysis const& bytecode_analysis =
GetBytecodeAnalysis(SerializationPolicy::kSerializeIfNeeded);
BytecodeArrayRef(broker(), bytecode_array()).SerializeForCompilation(); BytecodeArrayRef(broker(), bytecode_array()).SerializeForCompilation();
BytecodeArrayIterator iterator(bytecode_array()); BytecodeArrayIterator iterator(bytecode_array());
@ -1043,7 +1045,8 @@ void SerializerForBackgroundCompilation::VisitGetTemplateObject(
broker(), environment()->function().feedback_vector()); broker(), environment()->function().feedback_vector());
SharedFunctionInfoRef shared(broker(), environment()->function().shared()); SharedFunctionInfoRef shared(broker(), environment()->function().shared());
JSArrayRef template_object = JSArrayRef template_object =
shared.GetTemplateObject(description, feedback_vector, slot, true); shared.GetTemplateObject(description, feedback_vector, slot,
SerializationPolicy::kSerializeIfNeeded);
environment()->accumulator_hints().Clear(); environment()->accumulator_hints().Clear();
environment()->accumulator_hints().AddConstant(template_object.object()); environment()->accumulator_hints().AddConstant(template_object.object());
} }
@ -1150,7 +1153,8 @@ 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) {
DCHECK(mode == kSerializeSlot || mode == kSerializeSlotAndAddToAccumulator); DCHECK(mode == kSerializeSlot || mode == kSerializeSlotAndAddToAccumulator);
base::Optional<ObjectRef> slot_value = context_ref.get(slot, true); base::Optional<ObjectRef> slot_value =
context_ref.get(slot, SerializationPolicy::kSerializeIfNeeded);
// Also, put the object into the constant hints for the accumulator. // Also, put the object into the constant hints for the accumulator.
if (mode == kSerializeSlotAndAddToAccumulator && slot_value.has_value()) { if (mode == kSerializeSlotAndAddToAccumulator && slot_value.has_value()) {
@ -1171,7 +1175,8 @@ void SerializerForBackgroundCompilation::ProcessContextAccess(
// Walk this context to the given depth and serialize the slot found. // Walk this context to the given depth and serialize the slot found.
ContextRef context_ref(broker(), x); ContextRef context_ref(broker(), x);
size_t remaining_depth = depth; size_t remaining_depth = depth;
context_ref = context_ref.previous(&remaining_depth, true); context_ref = context_ref.previous(
&remaining_depth, SerializationPolicy::kSerializeIfNeeded);
if (remaining_depth == 0 && mode != kIgnoreSlot) { if (remaining_depth == 0 && mode != kIgnoreSlot) {
ProcessImmutableLoad(context_ref, slot, mode); ProcessImmutableLoad(context_ref, slot, mode);
} }
@ -1181,7 +1186,8 @@ void SerializerForBackgroundCompilation::ProcessContextAccess(
if (x.distance <= static_cast<unsigned int>(depth)) { if (x.distance <= static_cast<unsigned int>(depth)) {
ContextRef context_ref(broker(), x.context); ContextRef context_ref(broker(), x.context);
size_t remaining_depth = depth - x.distance; size_t remaining_depth = depth - x.distance;
context_ref = context_ref.previous(&remaining_depth, true); context_ref = context_ref.previous(
&remaining_depth, SerializationPolicy::kSerializeIfNeeded);
if (remaining_depth == 0 && mode != kIgnoreSlot) { if (remaining_depth == 0 && mode != kIgnoreSlot) {
ProcessImmutableLoad(context_ref, slot, mode); ProcessImmutableLoad(context_ref, slot, mode);
} }
@ -1477,7 +1483,8 @@ void SerializerForBackgroundCompilation::VisitCallJSRuntime(
// BytecodeGraphBuilder::VisitCallJSRuntime needs the {runtime_index} // BytecodeGraphBuilder::VisitCallJSRuntime needs the {runtime_index}
// slot in the native context to be serialized. // slot in the native context to be serialized.
const int runtime_index = iterator->GetNativeContextIndexOperand(0); const int runtime_index = iterator->GetNativeContextIndexOperand(0);
broker()->native_context().get(runtime_index, true); broker()->native_context().get(runtime_index,
SerializationPolicy::kSerializeIfNeeded);
} }
Hints SerializerForBackgroundCompilation::RunChildSerializer( Hints SerializerForBackgroundCompilation::RunChildSerializer(
@ -1701,14 +1708,12 @@ void SerializerForBackgroundCompilation::ProcessApiCall(
void SerializerForBackgroundCompilation::ProcessReceiverMapForApiCall( void SerializerForBackgroundCompilation::ProcessReceiverMapForApiCall(
FunctionTemplateInfoRef target, Handle<Map> receiver) { FunctionTemplateInfoRef target, Handle<Map> receiver) {
if (receiver->is_access_check_needed()) { if (!receiver->is_access_check_needed()) {
return; MapRef receiver_map(broker(), receiver);
TRACE_BROKER(broker(), "Serializing holder for target:" << target);
target.LookupHolderOfExpectedType(receiver_map,
SerializationPolicy::kSerializeIfNeeded);
} }
MapRef receiver_map(broker(), receiver);
TRACE_BROKER(broker(), "Serializing holder for target:" << target);
target.LookupHolderOfExpectedType(receiver_map, true);
} }
void SerializerForBackgroundCompilation::ProcessBuiltinCall( void SerializerForBackgroundCompilation::ProcessBuiltinCall(
@ -1872,7 +1877,8 @@ PropertyAccessInfo SerializerForBackgroundCompilation::ProcessMapForRegExpTest(
// The property is on the prototype chain. // The property is on the prototype chain.
JSObjectRef holder_ref(broker(), holder); JSObjectRef holder_ref(broker(), holder);
holder_ref.GetOwnDataProperty(ai_exec.field_representation(), holder_ref.GetOwnDataProperty(ai_exec.field_representation(),
ai_exec.field_index(), true); ai_exec.field_index(),
SerializationPolicy::kSerializeIfNeeded);
} }
return ai_exec; return ai_exec;
} }
@ -1890,7 +1896,8 @@ void SerializerForBackgroundCompilation::ProcessHintsForRegExpTest(
// The property is on the object itself. // The property is on the object itself.
JSObjectRef holder_ref(broker(), regexp); JSObjectRef holder_ref(broker(), regexp);
holder_ref.GetOwnDataProperty(ai_exec.field_representation(), holder_ref.GetOwnDataProperty(ai_exec.field_representation(),
ai_exec.field_index(), true); ai_exec.field_index(),
SerializationPolicy::kSerializeIfNeeded);
} }
} }
@ -1983,7 +1990,7 @@ void SerializerForBackgroundCompilation::VisitSwitchOnSmiNoFeedback(
void SerializerForBackgroundCompilation::VisitSwitchOnGeneratorState( void SerializerForBackgroundCompilation::VisitSwitchOnGeneratorState(
interpreter::BytecodeArrayIterator* iterator) { interpreter::BytecodeArrayIterator* iterator) {
for (const auto& target : GetBytecodeAnalysis(false).resume_jump_targets()) { for (const auto& target : GetBytecodeAnalysis().resume_jump_targets()) {
ContributeToJumpTargetEnvironment(target.target_offset()); ContributeToJumpTargetEnvironment(target.target_offset());
} }
} }
@ -2291,12 +2298,14 @@ void SerializerForBackgroundCompilation::ProcessKeyedPropertyAccess(
// TODO(neis): Do this for integer-HeapNumbers too? // TODO(neis): Do this for integer-HeapNumbers too?
if (key_ref.IsSmi() && key_ref.AsSmi() >= 0) { if (key_ref.IsSmi() && key_ref.AsSmi() >= 0) {
base::Optional<ObjectRef> element = base::Optional<ObjectRef> element =
receiver_ref.GetOwnConstantElement(key_ref.AsSmi(), true); receiver_ref.GetOwnConstantElement(
key_ref.AsSmi(), SerializationPolicy::kSerializeIfNeeded);
if (!element.has_value() && receiver_ref.IsJSArray()) { if (!element.has_value() && receiver_ref.IsJSArray()) {
// We didn't find a constant element, but if the receiver is a // We didn't find a constant element, but if the receiver is a
// cow-array we can exploit the fact that any future write to the // cow-array we can exploit the fact that any future write to the
// element will replace the whole elements storage. // element will replace the whole elements storage.
receiver_ref.AsJSArray().GetOwnCowElement(key_ref.AsSmi(), true); receiver_ref.AsJSArray().GetOwnCowElement(
key_ref.AsSmi(), SerializationPolicy::kSerializeIfNeeded);
} }
} }
} }
@ -2314,8 +2323,8 @@ SerializerForBackgroundCompilation::ProcessMapForNamedPropertyAccess(
base::Optional<JSObjectRef> receiver) { base::Optional<JSObjectRef> receiver) {
// For JSNativeContextSpecialization::ReduceNamedAccess. // For JSNativeContextSpecialization::ReduceNamedAccess.
if (receiver_map.IsMapOfCurrentGlobalProxy()) { if (receiver_map.IsMapOfCurrentGlobalProxy()) {
broker()->native_context().global_proxy_object().GetPropertyCell(name, broker()->native_context().global_proxy_object().GetPropertyCell(
true); name, SerializationPolicy::kSerializeIfNeeded);
} }
AccessInfoFactory access_info_factory(broker(), dependencies(), AccessInfoFactory access_info_factory(broker(), dependencies(),
@ -2360,9 +2369,9 @@ SerializerForBackgroundCompilation::ProcessMapForNamedPropertyAccess(
} }
if (holder.has_value()) { if (holder.has_value()) {
base::Optional<ObjectRef> constant( base::Optional<ObjectRef> constant(holder->GetOwnDataProperty(
holder->GetOwnDataProperty(access_info.field_representation(), access_info.field_representation(), access_info.field_index(),
access_info.field_index(), true)); SerializationPolicy::kSerializeIfNeeded));
if (constant.has_value()) { if (constant.has_value()) {
environment()->accumulator_hints().AddConstant(constant->object()); environment()->accumulator_hints().AddConstant(constant->object());
} }
@ -2398,7 +2407,8 @@ void SerializerForBackgroundCompilation::ProcessNamedPropertyAccess(
} }
// For JSNativeContextSpecialization::ReduceNamedAccessFromNexus. // For JSNativeContextSpecialization::ReduceNamedAccessFromNexus.
if (object.equals(global_proxy)) { if (object.equals(global_proxy)) {
global_proxy.GetPropertyCell(name, true); global_proxy.GetPropertyCell(name,
SerializationPolicy::kSerializeIfNeeded);
} }
// For JSNativeContextSpecialization::ReduceJSLoadNamed. // For JSNativeContextSpecialization::ReduceJSLoadNamed.
if (mode == AccessMode::kLoad && object.IsJSFunction() && if (mode == AccessMode::kLoad && object.IsJSFunction() &&
@ -2489,7 +2499,8 @@ void SerializerForBackgroundCompilation::ProcessConstantForInstanceOf(
JSObjectRef holder_ref = found_on_proto ? JSObjectRef(broker(), holder) JSObjectRef holder_ref = found_on_proto ? JSObjectRef(broker(), holder)
: constructor.AsJSObject(); : constructor.AsJSObject();
base::Optional<ObjectRef> constant = holder_ref.GetOwnDataProperty( base::Optional<ObjectRef> constant = holder_ref.GetOwnDataProperty(
access_info.field_representation(), access_info.field_index(), true); access_info.field_representation(), access_info.field_index(),
SerializationPolicy::kSerializeIfNeeded);
CHECK(constant.has_value()); CHECK(constant.has_value());
if (constant->IsJSFunction()) { if (constant->IsJSFunction()) {
JSFunctionRef function = constant->AsJSFunction(); JSFunctionRef function = constant->AsJSFunction();