diff options
Diffstat (limited to 'deps/v8/src/compiler/js-heap-broker.h')
-rw-r--r-- | deps/v8/src/compiler/js-heap-broker.h | 90 |
1 files changed, 75 insertions, 15 deletions
diff --git a/deps/v8/src/compiler/js-heap-broker.h b/deps/v8/src/compiler/js-heap-broker.h index 1faa1004e9..b7c0cce8e1 100644 --- a/deps/v8/src/compiler/js-heap-broker.h +++ b/deps/v8/src/compiler/js-heap-broker.h @@ -6,6 +6,7 @@ #define V8_COMPILER_JS_HEAP_BROKER_H_ #include "src/base/compiler-specific.h" +#include "src/base/macros.h" #include "src/base/optional.h" #include "src/base/platform/mutex.h" #include "src/common/globals.h" @@ -22,6 +23,7 @@ #include "src/objects/code-kind.h" #include "src/objects/feedback-vector.h" #include "src/objects/objects.h" +#include "src/roots/roots.h" #include "src/utils/address-map.h" #include "src/utils/identity-map.h" #include "src/utils/ostreams.h" @@ -118,7 +120,7 @@ class V8_EXPORT_PRIVATE JSHeapBroker { Isolate* isolate() const { return isolate_; } // The pointer compression cage base value used for decompression of all - // tagged values except references to Code objects. + // tagged values except references to InstructionStream objects. PtrComprCageBase cage_base() const { #if V8_COMPRESS_POINTERS return cage_base_; @@ -143,6 +145,11 @@ class V8_EXPORT_PRIVATE JSHeapBroker { void Retire(); bool SerializingAllowed() const; +#ifdef DEBUG + // Get the current heap broker for this thread. Only to be used for DCHECKs. + static JSHeapBroker* Current(); +#endif + // Remember the local isolate and initialize its local heap with the // persistent and canonical handles provided by {info}. void AttachLocalIsolate(OptimizedCompilationInfo* info, @@ -214,7 +221,7 @@ class V8_EXPORT_PRIVATE JSHeapBroker { FeedbackSource const& source); ProcessedFeedback const& GetFeedbackForPropertyAccess( FeedbackSource const& source, AccessMode mode, - base::Optional<NameRef> static_name); + OptionalNameRef static_name); ProcessedFeedback const& ProcessFeedbackForBinaryOperation( FeedbackSource const& source); @@ -225,11 +232,10 @@ class V8_EXPORT_PRIVATE JSHeapBroker { bool FeedbackIsInsufficient(FeedbackSource const& source) const; - base::Optional<NameRef> GetNameFeedback(FeedbackNexus const& nexus); + OptionalNameRef GetNameFeedback(FeedbackNexus const& nexus); - PropertyAccessInfo GetPropertyAccessInfo( - MapRef map, NameRef name, AccessMode access_mode, - CompilationDependencies* dependencies); + PropertyAccessInfo GetPropertyAccessInfo(MapRef map, NameRef name, + AccessMode access_mode); StringRef GetTypedArrayStringTag(ElementsKind kind); @@ -247,6 +253,17 @@ class V8_EXPORT_PRIVATE JSHeapBroker { : isolate()->AsLocalIsolate(); } + base::Optional<RootIndex> FindRootIndex(const HeapObjectRef& object) { + // No root constant is a JSReceiver. + if (object.IsJSReceiver()) return {}; + Address address = object.object()->ptr(); + RootIndex root_index; + if (root_index_map_.Lookup(address, &root_index)) { + return root_index; + } + return {}; + } + // Return the corresponding canonical persistent handle for {object}. Create // one if it does not exist. // If we have the canonical map, we can create the canonical & persistent @@ -364,6 +381,10 @@ class V8_EXPORT_PRIVATE JSHeapBroker { return dependencies_; } +#define V(Type, name, Name) inline typename ref_traits<Type>::ref_type name(); + READ_ONLY_ROOT_LIST(V) +#undef V + private: friend class HeapObjectRef; friend class ObjectRef; @@ -385,12 +406,12 @@ class V8_EXPORT_PRIVATE JSHeapBroker { ProcessedFeedback const& ReadFeedbackForForIn( FeedbackSource const& source) const; ProcessedFeedback const& ReadFeedbackForGlobalAccess( - FeedbackSource const& source); + JSHeapBroker* broker, FeedbackSource const& source); ProcessedFeedback const& ReadFeedbackForInstanceOf( FeedbackSource const& source); ProcessedFeedback const& ReadFeedbackForPropertyAccess( FeedbackSource const& source, AccessMode mode, - base::Optional<NameRef> static_name); + OptionalNameRef static_name); ProcessedFeedback const& ReadFeedbackForRegExpLiteral( FeedbackSource const& source); ProcessedFeedback const& ReadFeedbackForTemplateObject( @@ -425,12 +446,16 @@ class V8_EXPORT_PRIVATE JSHeapBroker { void CopyCanonicalHandlesForTesting( std::unique_ptr<CanonicalHandlesMap> canonical_handles); +#define V(Type, name, Name) void Init##Name(); + READ_ONLY_ROOT_LIST(V) +#undef V + Isolate* const isolate_; #if V8_COMPRESS_POINTERS const PtrComprCageBase cage_base_; #endif // V8_COMPRESS_POINTERS Zone* const zone_; - base::Optional<NativeContextRef> target_native_context_; + OptionalNativeContextRef target_native_context_; RefsMap* refs_; RootIndexMap root_index_map_; ZoneUnorderedSet<Handle<JSObject>, Handle<JSObject>::hash, @@ -450,6 +475,12 @@ class V8_EXPORT_PRIVATE JSHeapBroker { PropertyAccessTarget::Hash, PropertyAccessTarget::Equal> property_access_infos_; + // Cache read only roots to avoid needing to look them up via the map. +#define V(Type, name, Name) \ + OptionalRef<typename ref_traits<Type>::ref_type> name##_; + READ_ONLY_ROOT_LIST(V) +#undef V + CompilationDependencies* dependencies_ = nullptr; // The MapUpdater mutex is used in recursive patterns; for example, @@ -468,6 +499,25 @@ class V8_EXPORT_PRIVATE JSHeapBroker { static_assert(base::bits::IsPowerOfTwo(kInitialRefsBucketCount)); }; +#ifdef DEBUG +// In debug builds, store the current heap broker on a thread local, for +// DCHECKs to access it via JSHeapBroker::Current(); +class V8_NODISCARD V8_EXPORT_PRIVATE CurrentHeapBrokerScope { + public: + explicit CurrentHeapBrokerScope(JSHeapBroker* broker); + ~CurrentHeapBrokerScope(); + + private: + JSHeapBroker* const prev_broker_; +}; +#else +class V8_NODISCARD V8_EXPORT_PRIVATE CurrentHeapBrokerScope { + public: + explicit CurrentHeapBrokerScope(JSHeapBroker* broker) {} + ~CurrentHeapBrokerScope() {} +}; +#endif + class V8_NODISCARD TraceScope { public: TraceScope(JSHeapBroker* broker, const char* label) @@ -513,15 +563,15 @@ class V8_NODISCARD UnparkedScopeIfNeeded { template <class T, typename = std::enable_if_t<std::is_convertible<T*, Object*>::value>> -base::Optional<typename ref_traits<T>::ref_type> TryMakeRef( - JSHeapBroker* broker, ObjectData* data) { +OptionalRef<typename ref_traits<T>::ref_type> TryMakeRef(JSHeapBroker* broker, + ObjectData* data) { if (data == nullptr) return {}; - return {typename ref_traits<T>::ref_type(broker, data)}; + return {typename ref_traits<T>::ref_type(data)}; } // Usage: // -// base::Optional<FooRef> ref = TryMakeRef(broker, o); +// OptionalFooRef ref = TryMakeRef(broker, o); // if (!ref.has_value()) return {}; // bailout // // or @@ -529,7 +579,7 @@ base::Optional<typename ref_traits<T>::ref_type> TryMakeRef( // FooRef ref = MakeRef(broker, o); template <class T, typename = std::enable_if_t<std::is_convertible<T*, Object*>::value>> -base::Optional<typename ref_traits<T>::ref_type> TryMakeRef( +OptionalRef<typename ref_traits<T>::ref_type> TryMakeRef( JSHeapBroker* broker, T object, GetOrCreateDataFlags flags = {}) { ObjectData* data = broker->TryGetOrCreateData(object, flags); if (data == nullptr) { @@ -540,7 +590,7 @@ base::Optional<typename ref_traits<T>::ref_type> TryMakeRef( template <class T, typename = std::enable_if_t<std::is_convertible<T*, Object*>::value>> -base::Optional<typename ref_traits<T>::ref_type> TryMakeRef( +OptionalRef<typename ref_traits<T>::ref_type> TryMakeRef( JSHeapBroker* broker, Handle<T> object, GetOrCreateDataFlags flags = {}) { ObjectData* data = broker->TryGetOrCreateData(object, flags); if (data == nullptr) { @@ -577,6 +627,16 @@ typename ref_traits<T>::ref_type MakeRefAssumeMemoryFence(JSHeapBroker* broker, return TryMakeRef(broker, object, kAssumeMemoryFence | kCrashOnError).value(); } +#define V(Type, name, Name) \ + inline typename ref_traits<Type>::ref_type JSHeapBroker::name() { \ + if (!name##_) { \ + Init##Name(); \ + } \ + return name##_.value(); \ + } +READ_ONLY_ROOT_LIST(V) +#undef V + } // namespace compiler } // namespace internal } // namespace v8 |