diff options
Diffstat (limited to 'deps/v8/src/compiler/js-heap-broker.h')
-rw-r--r-- | deps/v8/src/compiler/js-heap-broker.h | 251 |
1 files changed, 151 insertions, 100 deletions
diff --git a/deps/v8/src/compiler/js-heap-broker.h b/deps/v8/src/compiler/js-heap-broker.h index 7ea12ee733..89f3ee871e 100644 --- a/deps/v8/src/compiler/js-heap-broker.h +++ b/deps/v8/src/compiler/js-heap-broker.h @@ -7,8 +7,10 @@ #include "src/base/compiler-specific.h" #include "src/base/optional.h" +#include "src/compiler/refs-map.h" #include "src/globals.h" #include "src/objects.h" +#include "src/objects/builtin-function-id.h" #include "src/zone/zone-containers.h" namespace v8 { @@ -25,35 +27,6 @@ enum class OddballType : uint8_t { kOther // Oddball, but none of the above. }; -// TODO(neis): Get rid of the HeapObjectType class. -class HeapObjectType { - public: - enum Flag : uint8_t { kUndetectable = 1 << 0, kCallable = 1 << 1 }; - - typedef base::Flags<Flag> Flags; - - HeapObjectType(InstanceType instance_type, Flags flags, - OddballType oddball_type) - : instance_type_(instance_type), - oddball_type_(oddball_type), - flags_(flags) { - DCHECK_EQ(instance_type == ODDBALL_TYPE, - oddball_type != OddballType::kNone); - } - - OddballType oddball_type() const { return oddball_type_; } - InstanceType instance_type() const { return instance_type_; } - Flags flags() const { return flags_; } - - bool is_callable() const { return flags_ & kCallable; } - bool is_undetectable() const { return flags_ & kUndetectable; } - - private: - InstanceType const instance_type_; - OddballType const oddball_type_; - Flags const flags_; -}; - // This list is sorted such that subtypes appear before their supertypes. // DO NOT VIOLATE THIS PROPERTY! #define HEAP_BROKER_OBJECT_LIST(V) \ @@ -64,6 +37,10 @@ class HeapObjectType { V(JSRegExp) \ /* Subtypes of Context */ \ V(NativeContext) \ + /* Subtypes of FixedArray */ \ + V(Context) \ + V(ScopeInfo) \ + V(ScriptContextTable) \ /* Subtypes of FixedArrayBase */ \ V(BytecodeArray) \ V(FixedArray) \ @@ -75,19 +52,17 @@ class HeapObjectType { V(AllocationSite) \ V(Cell) \ V(Code) \ + V(DescriptorArray) \ V(FeedbackVector) \ - V(Map) \ - V(Module) \ - V(ScopeInfo) \ - V(ScriptContextTable) \ - V(SharedFunctionInfo) \ - V(Context) \ V(FixedArrayBase) \ V(HeapNumber) \ V(JSObject) \ + V(Map) \ + V(Module) \ V(MutableHeapNumber) \ V(Name) \ V(PropertyCell) \ + V(SharedFunctionInfo) \ /* Subtypes of Object */ \ V(HeapObject) @@ -101,7 +76,10 @@ HEAP_BROKER_OBJECT_LIST(FORWARD_DECL) class ObjectRef { public: ObjectRef(JSHeapBroker* broker, Handle<Object> object); - explicit ObjectRef(ObjectData* data) : data_(data) { CHECK_NOT_NULL(data_); } + ObjectRef(JSHeapBroker* broker, ObjectData* data) + : broker_(broker), data_(data) { + CHECK_NOT_NULL(data_); + } bool equals(const ObjectRef& other) const; @@ -113,8 +91,6 @@ class ObjectRef { return Handle<T>::cast(object()); } - OddballType oddball_type() const; - bool IsSmi() const; int AsSmi() const; @@ -126,8 +102,7 @@ class ObjectRef { HEAP_BROKER_OBJECT_LIST(HEAP_AS_METHOD_DECL) #undef HEAP_AS_METHOD_DECL - StringRef TypeOf() const; - bool BooleanValue(); + bool BooleanValue() const; double OddballToNumber() const; Isolate* isolate() const; @@ -137,54 +112,94 @@ class ObjectRef { ObjectData* data() const; private: + JSHeapBroker* broker_; ObjectData* data_; }; +// Temporary class that carries information from a Map. We'd like to remove +// this class and use MapRef instead, but we can't as long as we support the +// kDisabled broker mode. That's because obtaining the MapRef via +// HeapObjectRef::map() requires a HandleScope when the broker is disabled. +// During OptimizeGraph we generally don't have a HandleScope, however. There +// are two places where we therefore use GetHeapObjectType() instead. Both that +// function and this class should eventually be removed. +class HeapObjectType { + public: + enum Flag : uint8_t { kUndetectable = 1 << 0, kCallable = 1 << 1 }; + + typedef base::Flags<Flag> Flags; + + HeapObjectType(InstanceType instance_type, Flags flags, + OddballType oddball_type) + : instance_type_(instance_type), + oddball_type_(oddball_type), + flags_(flags) { + DCHECK_EQ(instance_type == ODDBALL_TYPE, + oddball_type != OddballType::kNone); + } + + OddballType oddball_type() const { return oddball_type_; } + InstanceType instance_type() const { return instance_type_; } + Flags flags() const { return flags_; } + + bool is_callable() const { return flags_ & kCallable; } + bool is_undetectable() const { return flags_ & kUndetectable; } + + private: + InstanceType const instance_type_; + OddballType const oddball_type_; + Flags const flags_; +}; + class HeapObjectRef : public ObjectRef { public: using ObjectRef::ObjectRef; - HeapObjectType type() const; MapRef map() const; - base::Optional<MapRef> TryGetObjectCreateMap() const; - bool IsSeqString() const; - bool IsExternalString() const; + + // See the comment on the HeapObjectType class. + HeapObjectType GetHeapObjectType() const; }; class PropertyCellRef : public HeapObjectRef { public: using HeapObjectRef::HeapObjectRef; - ObjectRef value() const; PropertyDetails property_details() const; + ObjectRef value() const; }; class JSObjectRef : public HeapObjectRef { public: using HeapObjectRef::HeapObjectRef; - bool IsUnboxedDoubleField(FieldIndex index) const; double RawFastDoublePropertyAt(FieldIndex index) const; ObjectRef RawFastPropertyAt(FieldIndex index) const; FixedArrayBaseRef elements() const; void EnsureElementsTenured(); ElementsKind GetElementsKind() const; + + void SerializeObjectCreateMap(); + base::Optional<MapRef> GetObjectCreateMap() const; }; class JSFunctionRef : public JSObjectRef { public: using JSObjectRef::JSObjectRef; - bool IsConstructor() const; bool has_initial_map() const; - MapRef initial_map() const; bool has_prototype() const; - ObjectRef prototype() const; bool PrototypeRequiresRuntimeLookup() const; + + void Serialize(); + + // The following are available only after calling Serialize(). + ObjectRef prototype() const; + MapRef initial_map() const; JSGlobalProxyRef global_proxy() const; - int InitialMapInstanceSizeWithMinSlack() const; SharedFunctionInfoRef shared() const; + int InitialMapInstanceSizeWithMinSlack() const; }; class JSRegExpRef : public JSObjectRef { @@ -215,37 +230,48 @@ class MutableHeapNumberRef : public HeapObjectRef { class ContextRef : public HeapObjectRef { public: using HeapObjectRef::HeapObjectRef; + void Serialize(); - base::Optional<ContextRef> previous() const; + ContextRef previous() const; ObjectRef get(int index) const; }; -#define BROKER_NATIVE_CONTEXT_FIELDS(V) \ - V(JSFunction, array_function) \ - V(JSFunction, object_function) \ - V(JSFunction, promise_function) \ - V(Map, fast_aliased_arguments_map) \ - V(Map, initial_array_iterator_map) \ - V(Map, iterator_result_map) \ - V(Map, js_array_holey_double_elements_map) \ - V(Map, js_array_holey_elements_map) \ - V(Map, js_array_holey_smi_elements_map) \ - V(Map, js_array_packed_double_elements_map) \ - V(Map, js_array_packed_elements_map) \ - V(Map, js_array_packed_smi_elements_map) \ - V(Map, map_key_iterator_map) \ - V(Map, map_key_value_iterator_map) \ - V(Map, map_value_iterator_map) \ - V(Map, set_key_value_iterator_map) \ - V(Map, set_value_iterator_map) \ - V(Map, sloppy_arguments_map) \ - V(Map, strict_arguments_map) \ - V(Map, string_iterator_map) \ +#define BROKER_COMPULSORY_NATIVE_CONTEXT_FIELDS(V) \ + V(JSFunction, array_function) \ + V(JSFunction, object_function) \ + V(JSFunction, promise_function) \ + V(Map, fast_aliased_arguments_map) \ + V(Map, initial_array_iterator_map) \ + V(Map, initial_string_iterator_map) \ + V(Map, iterator_result_map) \ + V(Map, js_array_holey_double_elements_map) \ + V(Map, js_array_holey_elements_map) \ + V(Map, js_array_holey_smi_elements_map) \ + V(Map, js_array_packed_double_elements_map) \ + V(Map, js_array_packed_elements_map) \ + V(Map, js_array_packed_smi_elements_map) \ + V(Map, sloppy_arguments_map) \ + V(Map, slow_object_with_null_prototype_map) \ + V(Map, strict_arguments_map) \ V(ScriptContextTable, script_context_table) +// Those are set by Bootstrapper::ExportFromRuntime, which may not yet have +// happened when Turbofan is invoked via --always-opt. +#define BROKER_OPTIONAL_NATIVE_CONTEXT_FIELDS(V) \ + V(Map, map_key_iterator_map) \ + V(Map, map_key_value_iterator_map) \ + V(Map, map_value_iterator_map) \ + V(Map, set_key_value_iterator_map) \ + V(Map, set_value_iterator_map) + +#define BROKER_NATIVE_CONTEXT_FIELDS(V) \ + BROKER_COMPULSORY_NATIVE_CONTEXT_FIELDS(V) \ + BROKER_OPTIONAL_NATIVE_CONTEXT_FIELDS(V) + class NativeContextRef : public ContextRef { public: using ContextRef::ContextRef; + void Serialize(); #define DECL_ACCESSOR(type, name) type##Ref name() const; BROKER_NATIVE_CONTEXT_FIELDS(DECL_ACCESSOR) @@ -273,11 +299,18 @@ class ScriptContextTableRef : public HeapObjectRef { base::Optional<LookupResult> lookup(const NameRef& name) const; }; +class DescriptorArrayRef : public HeapObjectRef { + public: + using HeapObjectRef::HeapObjectRef; +}; + class FeedbackVectorRef : public HeapObjectRef { public: using HeapObjectRef::HeapObjectRef; ObjectRef get(FeedbackSlot slot) const; + + void SerializeSlots(); }; class AllocationSiteRef : public HeapObjectRef { @@ -313,25 +346,32 @@ class MapRef : public HeapObjectRef { int GetInObjectPropertyOffset(int index) const; ElementsKind elements_kind() const; bool is_stable() const; + bool is_constructor() const; bool has_prototype_slot() const; bool is_deprecated() const; bool CanBeDeprecated() const; bool CanTransition() const; bool IsInobjectSlackTrackingInProgress() const; bool is_dictionary_map() const; - bool IsJSArrayMap() const; bool IsFixedCowArrayMap() const; + bool is_undetectable() const; + bool is_callable() const; ObjectRef constructor_or_backpointer() const; + ObjectRef prototype() const; + + OddballType oddball_type() const; base::Optional<MapRef> AsElementsKind(ElementsKind kind) const; // Concerning the underlying instance_descriptors: - MapRef FindFieldOwner(int descriptor) const; - PropertyDetails GetPropertyDetails(int i) const; - NameRef GetPropertyKey(int i) const; - FieldIndex GetFieldIndexFor(int i) const; - ObjectRef GetFieldType(int descriptor) const; + void SerializeOwnDescriptors(); + MapRef FindFieldOwner(int descriptor_index) const; + PropertyDetails GetPropertyDetails(int descriptor_index) const; + NameRef GetPropertyKey(int descriptor_index) const; + FieldIndex GetFieldIndexFor(int descriptor_index) const; + ObjectRef GetFieldType(int descriptor_index) const; + bool IsUnboxedDoubleField(int descriptor_index) const; }; class FixedArrayBaseRef : public HeapObjectRef { @@ -346,7 +386,6 @@ class FixedArrayRef : public FixedArrayBaseRef { using FixedArrayBaseRef::FixedArrayBaseRef; ObjectRef get(int i) const; - bool is_the_hole(int i) const; }; class FixedDoubleArrayRef : public FixedArrayBaseRef { @@ -400,7 +439,7 @@ class SharedFunctionInfoRef : public HeapObjectRef { BytecodeArrayRef GetBytecodeArray() const; #define DECL_ACCESSOR(type, name) type name() const; BROKER_SFI_FIELDS(DECL_ACCESSOR) -#undef DECL_ACCSESOR +#undef DECL_ACCESSOR }; class StringRef : public NameRef { @@ -410,13 +449,17 @@ class StringRef : public NameRef { int length() const; uint16_t GetFirstChar(); base::Optional<double> ToNumber(); + bool IsSeqString() const; + bool IsExternalString() const; }; class ModuleRef : public HeapObjectRef { public: using HeapObjectRef::HeapObjectRef; - CellRef GetCell(int cell_index); + void Serialize(); + + CellRef GetCell(int cell_index) const; }; class CellRef : public HeapObjectRef { @@ -439,48 +482,56 @@ class InternalizedStringRef : public StringRef { using StringRef::StringRef; }; +class PerIsolateCompilerCache; + class V8_EXPORT_PRIVATE JSHeapBroker : public NON_EXPORTED_BASE(ZoneObject) { public: - JSHeapBroker(Isolate* isolate, Zone* zone); + JSHeapBroker(Isolate* isolate, Zone* broker_zone); + void SetNativeContextRef(); void SerializeStandardObjects(); - HeapObjectType HeapObjectTypeFromMap(Handle<Map> map) const { - AllowHandleDereference handle_dereference; - return HeapObjectTypeFromMap(*map); - } - Isolate* isolate() const { return isolate_; } - Zone* zone() const { return zone_; } + Zone* zone() const { return current_zone_; } + NativeContextRef native_context() const { return native_context_.value(); } + PerIsolateCompilerCache* compiler_cache() const { return compiler_cache_; } - enum BrokerMode { kDisabled, kSerializing, kSerialized }; + enum BrokerMode { kDisabled, kSerializing, kSerialized, kRetired }; BrokerMode mode() const { return mode_; } - void StopSerializing() { - CHECK_EQ(mode_, kSerializing); - mode_ = kSerialized; - } + void StartSerializing(); + void StopSerializing(); + void Retire(); bool SerializingAllowed() const; // Returns nullptr iff handle unknown. ObjectData* GetData(Handle<Object>) const; // Never returns nullptr. ObjectData* GetOrCreateData(Handle<Object>); + // Like the previous but wraps argument in handle first (for convenience). + ObjectData* GetOrCreateData(Object*); void Trace(const char* format, ...) const; + void IncrementTracingIndentation(); + void DecrementTracingIndentation(); private: friend class HeapObjectRef; friend class ObjectRef; friend class ObjectData; - // TODO(neis): Remove eventually. - HeapObjectType HeapObjectTypeFromMap(Map* map) const; - - void AddData(Handle<Object> object, ObjectData* data); + void SerializeShareableObjects(); Isolate* const isolate_; - Zone* const zone_; - ZoneUnorderedMap<Address, ObjectData*> refs_; - BrokerMode mode_; + Zone* const broker_zone_; + Zone* current_zone_; + base::Optional<NativeContextRef> native_context_; + RefsMap* refs_; + + BrokerMode mode_ = kDisabled; + unsigned tracing_indentation_ = 0; + PerIsolateCompilerCache* compiler_cache_; + + static const size_t kMinimalRefsBucketCount = 8; // must be power of 2 + static const size_t kInitialRefsBucketCount = 1024; // must be power of 2 }; #define ASSIGN_RETURN_NO_CHANGE_IF_DATA_MISSING(something_var, \ |