diff options
Diffstat (limited to 'deps/v8/src/compiler/js-heap-broker.h')
-rw-r--r-- | deps/v8/src/compiler/js-heap-broker.h | 222 |
1 files changed, 180 insertions, 42 deletions
diff --git a/deps/v8/src/compiler/js-heap-broker.h b/deps/v8/src/compiler/js-heap-broker.h index 89f3ee871e..0108575013 100644 --- a/deps/v8/src/compiler/js-heap-broker.h +++ b/deps/v8/src/compiler/js-heap-broker.h @@ -9,12 +9,27 @@ #include "src/base/optional.h" #include "src/compiler/refs-map.h" #include "src/globals.h" +#include "src/handles.h" #include "src/objects.h" #include "src/objects/builtin-function-id.h" +#include "src/objects/instance-type.h" #include "src/zone/zone-containers.h" namespace v8 { namespace internal { + +class BytecodeArray; +class FixedDoubleArray; +class HeapNumber; +class InternalizedString; +class JSBoundFunction; +class JSDataView; +class JSGlobalProxy; +class JSRegExp; +class JSTypedArray; +class NativeContext; +class ScriptContextTable; + namespace compiler { enum class OddballType : uint8_t { @@ -32,9 +47,12 @@ enum class OddballType : uint8_t { #define HEAP_BROKER_OBJECT_LIST(V) \ /* Subtypes of JSObject */ \ V(JSArray) \ + V(JSBoundFunction) \ + V(JSDataView) \ V(JSFunction) \ V(JSGlobalProxy) \ V(JSRegExp) \ + V(JSTypedArray) \ /* Subtypes of Context */ \ V(NativeContext) \ /* Subtypes of FixedArray */ \ @@ -48,6 +66,7 @@ enum class OddballType : uint8_t { /* Subtypes of Name */ \ V(InternalizedString) \ V(String) \ + V(Symbol) \ /* Subtypes of HeapObject */ \ V(AllocationSite) \ V(Cell) \ @@ -69,6 +88,7 @@ enum class OddballType : uint8_t { class CompilationDependencies; class JSHeapBroker; class ObjectData; +class PerIsolateCompilerCache; #define FORWARD_DECL(Name) class Name##Ref; HEAP_BROKER_OBJECT_LIST(FORWARD_DECL) #undef FORWARD_DECL @@ -77,19 +97,13 @@ class ObjectRef { public: ObjectRef(JSHeapBroker* broker, Handle<Object> object); ObjectRef(JSHeapBroker* broker, ObjectData* data) - : broker_(broker), data_(data) { + : data_(data), broker_(broker) { CHECK_NOT_NULL(data_); } - bool equals(const ObjectRef& other) const; - Handle<Object> object() const; - // TODO(neis): Remove eventually. - template <typename T> - Handle<T> object() const { - AllowHandleDereference handle_dereference; - return Handle<T>::cast(object()); - } + + bool equals(const ObjectRef& other) const; bool IsSmi() const; int AsSmi() const; @@ -102,6 +116,8 @@ class ObjectRef { HEAP_BROKER_OBJECT_LIST(HEAP_AS_METHOD_DECL) #undef HEAP_AS_METHOD_DECL + bool IsNullOrUndefined() const; + bool BooleanValue() const; double OddballToNumber() const; @@ -110,10 +126,10 @@ class ObjectRef { protected: JSHeapBroker* broker() const; ObjectData* data() const; + ObjectData* data_; // Should be used only by object() getters. private: JSHeapBroker* broker_; - ObjectData* data_; }; // Temporary class that carries information from a Map. We'd like to remove @@ -154,6 +170,7 @@ class HeapObjectType { class HeapObjectRef : public ObjectRef { public: using ObjectRef::ObjectRef; + Handle<HeapObject> object() const; MapRef map() const; @@ -164,6 +181,7 @@ class HeapObjectRef : public ObjectRef { class PropertyCellRef : public HeapObjectRef { public: using HeapObjectRef::HeapObjectRef; + Handle<PropertyCell> object() const; PropertyDetails property_details() const; ObjectRef value() const; @@ -172,6 +190,7 @@ class PropertyCellRef : public HeapObjectRef { class JSObjectRef : public HeapObjectRef { public: using HeapObjectRef::HeapObjectRef; + Handle<JSObject> object() const; double RawFastDoublePropertyAt(FieldIndex index) const; ObjectRef RawFastPropertyAt(FieldIndex index) const; @@ -184,9 +203,32 @@ class JSObjectRef : public HeapObjectRef { base::Optional<MapRef> GetObjectCreateMap() const; }; +class JSDataViewRef : public JSObjectRef { + public: + using JSObjectRef::JSObjectRef; + Handle<JSDataView> object() const; + + size_t byte_length() const; + size_t byte_offset() const; +}; + +class JSBoundFunctionRef : public JSObjectRef { + public: + using JSObjectRef::JSObjectRef; + Handle<JSBoundFunction> object() const; + + void Serialize(); + + // The following are available only after calling Serialize(). + ObjectRef bound_target_function() const; + ObjectRef bound_this() const; + FixedArrayRef bound_arguments() const; +}; + class JSFunctionRef : public JSObjectRef { public: using JSObjectRef::JSObjectRef; + Handle<JSFunction> object() const; bool has_initial_map() const; bool has_prototype() const; @@ -197,7 +239,8 @@ class JSFunctionRef : public JSObjectRef { // The following are available only after calling Serialize(). ObjectRef prototype() const; MapRef initial_map() const; - JSGlobalProxyRef global_proxy() const; + ContextRef context() const; + NativeContextRef native_context() const; SharedFunctionInfoRef shared() const; int InitialMapInstanceSizeWithMinSlack() const; }; @@ -205,6 +248,7 @@ class JSFunctionRef : public JSObjectRef { class JSRegExpRef : public JSObjectRef { public: using JSObjectRef::JSObjectRef; + Handle<JSRegExp> object() const; ObjectRef raw_properties_or_hash() const; ObjectRef data() const; @@ -216,6 +260,7 @@ class JSRegExpRef : public JSObjectRef { class HeapNumberRef : public HeapObjectRef { public: using HeapObjectRef::HeapObjectRef; + Handle<HeapNumber> object() const; double value() const; }; @@ -223,6 +268,7 @@ class HeapNumberRef : public HeapObjectRef { class MutableHeapNumberRef : public HeapObjectRef { public: using HeapObjectRef::HeapObjectRef; + Handle<MutableHeapNumber> object() const; double value() const; }; @@ -230,34 +276,50 @@ class MutableHeapNumberRef : public HeapObjectRef { class ContextRef : public HeapObjectRef { public: using HeapObjectRef::HeapObjectRef; - void Serialize(); + Handle<Context> object() const; + void Serialize(); ContextRef previous() const; ObjectRef get(int index) const; }; -#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) +#define BROKER_COMPULSORY_NATIVE_CONTEXT_FIELDS(V) \ + V(JSFunction, array_function) \ + V(JSFunction, boolean_function) \ + V(JSFunction, bigint_function) \ + V(JSFunction, number_function) \ + V(JSFunction, object_function) \ + V(JSFunction, promise_function) \ + V(JSFunction, promise_then) \ + V(JSFunction, string_function) \ + V(JSFunction, symbol_function) \ + V(JSGlobalProxy, global_proxy_object) \ + V(JSObject, promise_prototype) \ + V(Map, bound_function_with_constructor_map) \ + V(Map, bound_function_without_constructor_map) \ + 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) \ + V(SharedFunctionInfo, promise_capability_default_reject_shared_fun) \ + V(SharedFunctionInfo, promise_catch_finally_shared_fun) \ + V(SharedFunctionInfo, promise_then_finally_shared_fun) \ + V(SharedFunctionInfo, promise_capability_default_resolve_shared_fun) // 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, async_function_object_map) \ V(Map, map_key_iterator_map) \ V(Map, map_key_value_iterator_map) \ V(Map, map_value_iterator_map) \ @@ -271,6 +333,8 @@ class ContextRef : public HeapObjectRef { class NativeContextRef : public ContextRef { public: using ContextRef::ContextRef; + Handle<NativeContext> object() const; + void Serialize(); #define DECL_ACCESSOR(type, name) type##Ref name() const; @@ -279,16 +343,19 @@ class NativeContextRef : public ContextRef { MapRef GetFunctionMapFromIndex(int index) const; MapRef GetInitialJSArrayMap(ElementsKind kind) const; + base::Optional<JSFunctionRef> GetConstructorFunction(const MapRef& map) const; }; class NameRef : public HeapObjectRef { public: using HeapObjectRef::HeapObjectRef; + Handle<Name> object() const; }; class ScriptContextTableRef : public HeapObjectRef { public: using HeapObjectRef::HeapObjectRef; + Handle<ScriptContextTable> object() const; struct LookupResult { ContextRef context; @@ -302,11 +369,13 @@ class ScriptContextTableRef : public HeapObjectRef { class DescriptorArrayRef : public HeapObjectRef { public: using HeapObjectRef::HeapObjectRef; + Handle<DescriptorArray> object() const; }; class FeedbackVectorRef : public HeapObjectRef { public: using HeapObjectRef::HeapObjectRef; + Handle<FeedbackVector> object() const; ObjectRef get(FeedbackSlot slot) const; @@ -316,6 +385,7 @@ class FeedbackVectorRef : public HeapObjectRef { class AllocationSiteRef : public HeapObjectRef { public: using HeapObjectRef::HeapObjectRef; + Handle<AllocationSite> object() const; bool PointsToLiteral() const; PretenureFlag GetPretenureMode() const; @@ -337,6 +407,7 @@ class AllocationSiteRef : public HeapObjectRef { class MapRef : public HeapObjectRef { public: using HeapObjectRef::HeapObjectRef; + Handle<Map> object() const; int instance_size() const; InstanceType instance_type() const; @@ -344,20 +415,35 @@ class MapRef : public HeapObjectRef { int GetInObjectPropertiesStartInWords() const; int NumberOfOwnDescriptors() const; int GetInObjectPropertyOffset(int index) const; + int constructor_function_index() const; + int NextFreePropertyIndex() const; + int UnusedPropertyFields() const; ElementsKind elements_kind() const; bool is_stable() const; + bool is_extensible() const; bool is_constructor() const; bool has_prototype_slot() const; + bool is_access_check_needed() const; bool is_deprecated() const; bool CanBeDeprecated() const; bool CanTransition() const; bool IsInobjectSlackTrackingInProgress() const; bool is_dictionary_map() const; bool IsFixedCowArrayMap() const; + bool IsPrimitiveMap() const; bool is_undetectable() const; bool is_callable() const; + bool has_hidden_prototype() const; + bool supports_fast_array_iteration() const; + bool supports_fast_array_resize() const; + +#define DEF_TESTER(Type, ...) bool Is##Type##Map() const; + INSTANCE_TYPE_CHECKERS(DEF_TESTER) +#undef DEF_TESTER + + ObjectRef GetConstructor() const; - ObjectRef constructor_or_backpointer() const; + void SerializePrototype(); ObjectRef prototype() const; OddballType oddball_type() const; @@ -377,6 +463,7 @@ class MapRef : public HeapObjectRef { class FixedArrayBaseRef : public HeapObjectRef { public: using HeapObjectRef::HeapObjectRef; + Handle<FixedArrayBase> object() const; int length() const; }; @@ -384,6 +471,7 @@ class FixedArrayBaseRef : public HeapObjectRef { class FixedArrayRef : public FixedArrayBaseRef { public: using FixedArrayBaseRef::FixedArrayBaseRef; + Handle<FixedArray> object() const; ObjectRef get(int i) const; }; @@ -391,6 +479,7 @@ class FixedArrayRef : public FixedArrayBaseRef { class FixedDoubleArrayRef : public FixedArrayBaseRef { public: using FixedArrayBaseRef::FixedArrayBaseRef; + Handle<FixedDoubleArray> object() const; double get_scalar(int i) const; bool is_the_hole(int i) const; @@ -399,6 +488,7 @@ class FixedDoubleArrayRef : public FixedArrayBaseRef { class BytecodeArrayRef : public FixedArrayBaseRef { public: using FixedArrayBaseRef::FixedArrayBaseRef; + Handle<BytecodeArray> object() const; int register_count() const; }; @@ -406,6 +496,7 @@ class BytecodeArrayRef : public FixedArrayBaseRef { class JSArrayRef : public JSObjectRef { public: using JSObjectRef::JSObjectRef; + Handle<JSArray> object() const; ObjectRef length() const; }; @@ -413,6 +504,7 @@ class JSArrayRef : public JSObjectRef { class ScopeInfoRef : public HeapObjectRef { public: using HeapObjectRef::HeapObjectRef; + Handle<ScopeInfo> object() const; int ContextLength() const; }; @@ -434,17 +526,22 @@ class ScopeInfoRef : public HeapObjectRef { class SharedFunctionInfoRef : public HeapObjectRef { public: using HeapObjectRef::HeapObjectRef; + Handle<SharedFunctionInfo> object() const; int builtin_id() const; BytecodeArrayRef GetBytecodeArray() const; #define DECL_ACCESSOR(type, name) type name() const; BROKER_SFI_FIELDS(DECL_ACCESSOR) #undef DECL_ACCESSOR + + bool IsSerializedForCompilation(FeedbackVectorRef feedback) const; + void SetSerializedForCompilation(FeedbackVectorRef feedback); }; class StringRef : public NameRef { public: using NameRef::NameRef; + Handle<String> object() const; int length() const; uint16_t GetFirstChar(); @@ -453,9 +550,30 @@ class StringRef : public NameRef { bool IsExternalString() const; }; +class SymbolRef : public NameRef { + public: + using NameRef::NameRef; + Handle<Symbol> object() const; +}; + +class JSTypedArrayRef : public JSObjectRef { + public: + using JSObjectRef::JSObjectRef; + Handle<JSTypedArray> object() const; + + bool is_on_heap() const; + size_t length_value() const; + void* elements_external_pointer() const; + + void Serialize(); + + HeapObjectRef buffer() const; +}; + class ModuleRef : public HeapObjectRef { public: using HeapObjectRef::HeapObjectRef; + Handle<Module> object() const; void Serialize(); @@ -465,24 +583,31 @@ class ModuleRef : public HeapObjectRef { class CellRef : public HeapObjectRef { public: using HeapObjectRef::HeapObjectRef; + Handle<Cell> object() const; + + ObjectRef value() const; }; class JSGlobalProxyRef : public JSObjectRef { public: using JSObjectRef::JSObjectRef; + Handle<JSGlobalProxy> object() const; }; class CodeRef : public HeapObjectRef { public: using HeapObjectRef::HeapObjectRef; + Handle<Code> object() const; }; class InternalizedStringRef : public StringRef { public: using StringRef::StringRef; -}; + Handle<InternalizedString> object() const; -class PerIsolateCompilerCache; + uint32_t array_index() const; + static const uint32_t kNotAnArrayIndex = -1; // 2^32-1 is not a valid index. +}; class V8_EXPORT_PRIVATE JSHeapBroker : public NON_EXPORTED_BASE(ZoneObject) { public: @@ -507,9 +632,14 @@ class V8_EXPORT_PRIVATE JSHeapBroker : public NON_EXPORTED_BASE(ZoneObject) { // Never returns nullptr. ObjectData* GetOrCreateData(Handle<Object>); // Like the previous but wraps argument in handle first (for convenience). - ObjectData* GetOrCreateData(Object*); + ObjectData* GetOrCreateData(Object); + + // Check if {object} is any native context's %ArrayPrototype% or + // %ObjectPrototype%. + bool IsArrayOrObjectPrototype(const JSObjectRef& object) const; + + std::ostream& Trace() const; - void Trace(const char* format, ...) const; void IncrementTracingIndentation(); void DecrementTracingIndentation(); @@ -519,33 +649,41 @@ class V8_EXPORT_PRIVATE JSHeapBroker : public NON_EXPORTED_BASE(ZoneObject) { friend class ObjectData; void SerializeShareableObjects(); + void CollectArrayAndObjectPrototypes(); Isolate* const isolate_; Zone* const broker_zone_; Zone* current_zone_; base::Optional<NativeContextRef> native_context_; RefsMap* refs_; + ZoneUnorderedSet<Handle<JSObject>, Handle<JSObject>::hash, + Handle<JSObject>::equal_to> + array_and_object_prototypes_; BrokerMode mode_ = kDisabled; - unsigned tracing_indentation_ = 0; + unsigned trace_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, \ - optionally_something) \ - auto optionally_something_ = optionally_something; \ - if (!optionally_something_) \ - return NoChangeBecauseOfMissingData(js_heap_broker(), __FUNCTION__, \ - __LINE__); \ +#define ASSIGN_RETURN_NO_CHANGE_IF_DATA_MISSING(something_var, \ + optionally_something) \ + auto optionally_something_ = optionally_something; \ + if (!optionally_something_) \ + return NoChangeBecauseOfMissingData(broker(), __FUNCTION__, __LINE__); \ something_var = *optionally_something_; class Reduction; Reduction NoChangeBecauseOfMissingData(JSHeapBroker* broker, const char* function, int line); +#define TRACE_BROKER(broker, x) \ + do { \ + if (FLAG_trace_heap_broker) broker->Trace() << x << '\n'; \ + } while (false) + } // namespace compiler } // namespace internal } // namespace v8 |