LCOV - code coverage report
Current view: top level - src/compiler - js-heap-broker.h (source / functions) Hit Total Coverage
Test: app.info Lines: 5 5 100.0 %
Date: 2019-02-19 Functions: 0 0 -

          Line data    Source code
       1             : // Copyright 2018 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #ifndef V8_COMPILER_JS_HEAP_BROKER_H_
       6             : #define V8_COMPILER_JS_HEAP_BROKER_H_
       7             : 
       8             : #include "src/base/compiler-specific.h"
       9             : #include "src/base/optional.h"
      10             : #include "src/compiler/refs-map.h"
      11             : #include "src/function-kind.h"
      12             : #include "src/globals.h"
      13             : #include "src/handles.h"
      14             : #include "src/objects.h"
      15             : #include "src/objects/builtin-function-id.h"
      16             : #include "src/objects/instance-type.h"
      17             : #include "src/ostreams.h"
      18             : #include "src/zone/zone-containers.h"
      19             : 
      20             : namespace v8 {
      21             : namespace internal {
      22             : 
      23             : class BytecodeArray;
      24             : class FixedDoubleArray;
      25             : class HeapNumber;
      26             : class InternalizedString;
      27             : class JSBoundFunction;
      28             : class JSDataView;
      29             : class JSGlobalProxy;
      30             : class JSRegExp;
      31             : class JSTypedArray;
      32             : class NativeContext;
      33             : class ScriptContextTable;
      34             : 
      35             : namespace compiler {
      36             : 
      37             : enum class OddballType : uint8_t {
      38             :   kNone,     // Not an Oddball.
      39             :   kBoolean,  // True or False.
      40             :   kUndefined,
      41             :   kNull,
      42             :   kHole,
      43             :   kUninitialized,
      44             :   kOther  // Oddball, but none of the above.
      45             : };
      46             : 
      47             : // This list is sorted such that subtypes appear before their supertypes.
      48             : // DO NOT VIOLATE THIS PROPERTY!
      49             : #define HEAP_BROKER_OBJECT_LIST(V) \
      50             :   /* Subtypes of JSObject */       \
      51             :   V(JSArray)                       \
      52             :   V(JSBoundFunction)               \
      53             :   V(JSDataView)                    \
      54             :   V(JSFunction)                    \
      55             :   V(JSGlobalProxy)                 \
      56             :   V(JSRegExp)                      \
      57             :   V(JSTypedArray)                  \
      58             :   /* Subtypes of Context */        \
      59             :   V(NativeContext)                 \
      60             :   /* Subtypes of FixedArray */     \
      61             :   V(Context)                       \
      62             :   V(ScopeInfo)                     \
      63             :   V(ScriptContextTable)            \
      64             :   /* Subtypes of FixedArrayBase */ \
      65             :   V(BytecodeArray)                 \
      66             :   V(FixedArray)                    \
      67             :   V(FixedDoubleArray)              \
      68             :   /* Subtypes of Name */           \
      69             :   V(InternalizedString)            \
      70             :   V(String)                        \
      71             :   V(Symbol)                        \
      72             :   /* Subtypes of HeapObject */     \
      73             :   V(AllocationSite)                \
      74             :   V(Cell)                          \
      75             :   V(Code)                          \
      76             :   V(DescriptorArray)               \
      77             :   V(FeedbackVector)                \
      78             :   V(FixedArrayBase)                \
      79             :   V(HeapNumber)                    \
      80             :   V(JSObject)                      \
      81             :   V(Map)                           \
      82             :   V(Module)                        \
      83             :   V(MutableHeapNumber)             \
      84             :   V(Name)                          \
      85             :   V(PropertyCell)                  \
      86             :   V(SharedFunctionInfo)            \
      87             :   /* Subtypes of Object */         \
      88             :   V(HeapObject)
      89             : 
      90             : class CompilationDependencies;
      91             : class JSHeapBroker;
      92             : class ObjectData;
      93             : class PerIsolateCompilerCache;
      94             : #define FORWARD_DECL(Name) class Name##Ref;
      95             : HEAP_BROKER_OBJECT_LIST(FORWARD_DECL)
      96             : #undef FORWARD_DECL
      97             : 
      98             : class ObjectRef {
      99             :  public:
     100             :   ObjectRef(JSHeapBroker* broker, Handle<Object> object);
     101             :   ObjectRef(JSHeapBroker* broker, ObjectData* data)
     102      458646 :       : data_(data), broker_(broker) {
     103    85212309 :     CHECK_NOT_NULL(data_);
     104             :   }
     105             : 
     106             :   Handle<Object> object() const;
     107             : 
     108             :   bool equals(const ObjectRef& other) const;
     109             : 
     110             :   bool IsSmi() const;
     111             :   int AsSmi() const;
     112             : 
     113             : #define HEAP_IS_METHOD_DECL(Name) bool Is##Name() const;
     114             :   HEAP_BROKER_OBJECT_LIST(HEAP_IS_METHOD_DECL)
     115             : #undef HEAP_IS_METHOD_DECL
     116             : 
     117             : #define HEAP_AS_METHOD_DECL(Name) Name##Ref As##Name() const;
     118             :   HEAP_BROKER_OBJECT_LIST(HEAP_AS_METHOD_DECL)
     119             : #undef HEAP_AS_METHOD_DECL
     120             : 
     121             :   bool IsNullOrUndefined() const;
     122             : 
     123             :   bool BooleanValue() const;
     124             :   Maybe<double> OddballToNumber() const;
     125             : 
     126             :   Isolate* isolate() const;
     127             : 
     128             :  protected:
     129             :   JSHeapBroker* broker() const;
     130             :   ObjectData* data() const;
     131             :   ObjectData* data_;  // Should be used only by object() getters.
     132             : 
     133             :  private:
     134             :   JSHeapBroker* broker_;
     135             : };
     136             : 
     137             : // Temporary class that carries information from a Map. We'd like to remove
     138             : // this class and use MapRef instead, but we can't as long as we support the
     139             : // kDisabled broker mode. That's because obtaining the MapRef via
     140             : // HeapObjectRef::map() requires a HandleScope when the broker is disabled.
     141             : // During OptimizeGraph we generally don't have a HandleScope, however. There
     142             : // are two places where we therefore use GetHeapObjectType() instead. Both that
     143             : // function and this class should eventually be removed.
     144             : class HeapObjectType {
     145             :  public:
     146             :   enum Flag : uint8_t { kUndetectable = 1 << 0, kCallable = 1 << 1 };
     147             : 
     148             :   typedef base::Flags<Flag> Flags;
     149             : 
     150             :   HeapObjectType(InstanceType instance_type, Flags flags,
     151             :                  OddballType oddball_type)
     152             :       : instance_type_(instance_type),
     153             :         oddball_type_(oddball_type),
     154             :         flags_(flags) {
     155             :     DCHECK_EQ(instance_type == ODDBALL_TYPE,
     156             :               oddball_type != OddballType::kNone);
     157             :   }
     158             : 
     159             :   OddballType oddball_type() const { return oddball_type_; }
     160             :   InstanceType instance_type() const { return instance_type_; }
     161             :   Flags flags() const { return flags_; }
     162             : 
     163             :   bool is_callable() const { return flags_ & kCallable; }
     164             :   bool is_undetectable() const { return flags_ & kUndetectable; }
     165             : 
     166             :  private:
     167             :   InstanceType const instance_type_;
     168             :   OddballType const oddball_type_;
     169             :   Flags const flags_;
     170             : };
     171             : 
     172             : class HeapObjectRef : public ObjectRef {
     173             :  public:
     174    50378888 :   using ObjectRef::ObjectRef;
     175             :   Handle<HeapObject> object() const;
     176             : 
     177             :   MapRef map() const;
     178             : 
     179             :   // See the comment on the HeapObjectType class.
     180             :   HeapObjectType GetHeapObjectType() const;
     181             : };
     182             : 
     183             : class PropertyCellRef : public HeapObjectRef {
     184             :  public:
     185             :   using HeapObjectRef::HeapObjectRef;
     186             :   Handle<PropertyCell> object() const;
     187             : 
     188             :   PropertyDetails property_details() const;
     189             :   ObjectRef value() const;
     190             : };
     191             : 
     192             : class JSObjectRef : public HeapObjectRef {
     193             :  public:
     194             :   using HeapObjectRef::HeapObjectRef;
     195             :   Handle<JSObject> object() const;
     196             : 
     197             :   double RawFastDoublePropertyAt(FieldIndex index) const;
     198             :   ObjectRef RawFastPropertyAt(FieldIndex index) const;
     199             : 
     200             :   FixedArrayBaseRef elements() const;
     201             :   void EnsureElementsTenured();
     202             :   ElementsKind GetElementsKind() const;
     203             : 
     204             :   void SerializeObjectCreateMap();
     205             :   base::Optional<MapRef> GetObjectCreateMap() const;
     206             : };
     207             : 
     208             : class JSDataViewRef : public JSObjectRef {
     209             :  public:
     210             :   using JSObjectRef::JSObjectRef;
     211             :   Handle<JSDataView> object() const;
     212             : 
     213             :   size_t byte_length() const;
     214             :   size_t byte_offset() const;
     215             : };
     216             : 
     217             : class JSBoundFunctionRef : public JSObjectRef {
     218             :  public:
     219             :   using JSObjectRef::JSObjectRef;
     220             :   Handle<JSBoundFunction> object() const;
     221             : 
     222             :   void Serialize();
     223             : 
     224             :   // The following are available only after calling Serialize().
     225             :   ObjectRef bound_target_function() const;
     226             :   ObjectRef bound_this() const;
     227             :   FixedArrayRef bound_arguments() const;
     228             : };
     229             : 
     230             : class JSFunctionRef : public JSObjectRef {
     231             :  public:
     232             :   using JSObjectRef::JSObjectRef;
     233             :   Handle<JSFunction> object() const;
     234             : 
     235             :   bool has_feedback_vector() const;
     236             :   bool has_initial_map() const;
     237             :   bool has_prototype() const;
     238             :   bool PrototypeRequiresRuntimeLookup() const;
     239             : 
     240             :   void Serialize();
     241             :   bool IsSerializedForCompilation() const;
     242             : 
     243             :   // The following are available only after calling Serialize().
     244             :   ObjectRef prototype() const;
     245             :   MapRef initial_map() const;
     246             :   ContextRef context() const;
     247             :   NativeContextRef native_context() const;
     248             :   SharedFunctionInfoRef shared() const;
     249             :   FeedbackVectorRef feedback_vector() const;
     250             :   int InitialMapInstanceSizeWithMinSlack() const;
     251             : };
     252             : 
     253             : class JSRegExpRef : public JSObjectRef {
     254             :  public:
     255             :   using JSObjectRef::JSObjectRef;
     256             :   Handle<JSRegExp> object() const;
     257             : 
     258             :   ObjectRef raw_properties_or_hash() const;
     259             :   ObjectRef data() const;
     260             :   ObjectRef source() const;
     261             :   ObjectRef flags() const;
     262             :   ObjectRef last_index() const;
     263             : };
     264             : 
     265             : class HeapNumberRef : public HeapObjectRef {
     266             :  public:
     267             :   using HeapObjectRef::HeapObjectRef;
     268             :   Handle<HeapNumber> object() const;
     269             : 
     270             :   double value() const;
     271             : };
     272             : 
     273             : class MutableHeapNumberRef : public HeapObjectRef {
     274             :  public:
     275             :   using HeapObjectRef::HeapObjectRef;
     276             :   Handle<MutableHeapNumber> object() const;
     277             : 
     278             :   double value() const;
     279             : };
     280             : 
     281             : class ContextRef : public HeapObjectRef {
     282             :  public:
     283             :   using HeapObjectRef::HeapObjectRef;
     284             :   Handle<Context> object() const;
     285             : 
     286             :   void Serialize();
     287             :   ContextRef previous() const;
     288             :   ObjectRef get(int index) const;
     289             : };
     290             : 
     291             : #define BROKER_COMPULSORY_NATIVE_CONTEXT_FIELDS(V)                    \
     292             :   V(JSFunction, array_function)                                       \
     293             :   V(JSFunction, boolean_function)                                     \
     294             :   V(JSFunction, bigint_function)                                      \
     295             :   V(JSFunction, number_function)                                      \
     296             :   V(JSFunction, object_function)                                      \
     297             :   V(JSFunction, promise_function)                                     \
     298             :   V(JSFunction, promise_then)                                         \
     299             :   V(JSFunction, string_function)                                      \
     300             :   V(JSFunction, symbol_function)                                      \
     301             :   V(JSGlobalProxy, global_proxy_object)                               \
     302             :   V(JSObject, promise_prototype)                                      \
     303             :   V(Map, bound_function_with_constructor_map)                         \
     304             :   V(Map, bound_function_without_constructor_map)                      \
     305             :   V(Map, fast_aliased_arguments_map)                                  \
     306             :   V(Map, initial_array_iterator_map)                                  \
     307             :   V(Map, initial_string_iterator_map)                                 \
     308             :   V(Map, iterator_result_map)                                         \
     309             :   V(Map, js_array_holey_double_elements_map)                          \
     310             :   V(Map, js_array_holey_elements_map)                                 \
     311             :   V(Map, js_array_holey_smi_elements_map)                             \
     312             :   V(Map, js_array_packed_double_elements_map)                         \
     313             :   V(Map, js_array_packed_elements_map)                                \
     314             :   V(Map, js_array_packed_smi_elements_map)                            \
     315             :   V(Map, sloppy_arguments_map)                                        \
     316             :   V(Map, slow_object_with_null_prototype_map)                         \
     317             :   V(Map, strict_arguments_map)                                        \
     318             :   V(ScriptContextTable, script_context_table)                         \
     319             :   V(SharedFunctionInfo, promise_capability_default_reject_shared_fun) \
     320             :   V(SharedFunctionInfo, promise_catch_finally_shared_fun)             \
     321             :   V(SharedFunctionInfo, promise_then_finally_shared_fun)              \
     322             :   V(SharedFunctionInfo, promise_capability_default_resolve_shared_fun)
     323             : 
     324             : // Those are set by Bootstrapper::ExportFromRuntime, which may not yet have
     325             : // happened when Turbofan is invoked via --always-opt.
     326             : #define BROKER_OPTIONAL_NATIVE_CONTEXT_FIELDS(V) \
     327             :   V(Map, async_function_object_map)              \
     328             :   V(Map, map_key_iterator_map)                   \
     329             :   V(Map, map_key_value_iterator_map)             \
     330             :   V(Map, map_value_iterator_map)                 \
     331             :   V(Map, set_key_value_iterator_map)             \
     332             :   V(Map, set_value_iterator_map)
     333             : 
     334             : #define BROKER_NATIVE_CONTEXT_FIELDS(V)      \
     335             :   BROKER_COMPULSORY_NATIVE_CONTEXT_FIELDS(V) \
     336             :   BROKER_OPTIONAL_NATIVE_CONTEXT_FIELDS(V)
     337             : 
     338             : class NativeContextRef : public ContextRef {
     339             :  public:
     340             :   using ContextRef::ContextRef;
     341             :   Handle<NativeContext> object() const;
     342             : 
     343             :   void Serialize();
     344             : 
     345             : #define DECL_ACCESSOR(type, name) type##Ref name() const;
     346             :   BROKER_NATIVE_CONTEXT_FIELDS(DECL_ACCESSOR)
     347             : #undef DECL_ACCESSOR
     348             : 
     349             :   MapRef GetFunctionMapFromIndex(int index) const;
     350             :   MapRef GetInitialJSArrayMap(ElementsKind kind) const;
     351             :   base::Optional<JSFunctionRef> GetConstructorFunction(const MapRef& map) const;
     352             : };
     353             : 
     354             : class NameRef : public HeapObjectRef {
     355             :  public:
     356             :   using HeapObjectRef::HeapObjectRef;
     357             :   Handle<Name> object() const;
     358             : };
     359             : 
     360             : class ScriptContextTableRef : public HeapObjectRef {
     361             :  public:
     362             :   using HeapObjectRef::HeapObjectRef;
     363             :   Handle<ScriptContextTable> object() const;
     364             : 
     365             :   struct LookupResult {
     366             :     ContextRef context;
     367             :     bool immutable;
     368             :     int index;
     369             :   };
     370             : 
     371             :   base::Optional<LookupResult> lookup(const NameRef& name) const;
     372             : };
     373             : 
     374             : class DescriptorArrayRef : public HeapObjectRef {
     375             :  public:
     376             :   using HeapObjectRef::HeapObjectRef;
     377             :   Handle<DescriptorArray> object() const;
     378             : };
     379             : 
     380             : class FeedbackVectorRef : public HeapObjectRef {
     381             :  public:
     382             :   using HeapObjectRef::HeapObjectRef;
     383             :   Handle<FeedbackVector> object() const;
     384             : 
     385             :   ObjectRef get(FeedbackSlot slot) const;
     386             : 
     387             :   void SerializeSlots();
     388             : };
     389             : 
     390             : class AllocationSiteRef : public HeapObjectRef {
     391             :  public:
     392             :   using HeapObjectRef::HeapObjectRef;
     393             :   Handle<AllocationSite> object() const;
     394             : 
     395             :   bool PointsToLiteral() const;
     396             :   PretenureFlag GetPretenureMode() const;
     397             :   ObjectRef nested_site() const;
     398             : 
     399             :   // {IsFastLiteral} determines whether the given array or object literal
     400             :   // boilerplate satisfies all limits to be considered for fast deep-copying
     401             :   // and computes the total size of all objects that are part of the graph.
     402             :   //
     403             :   // If PointsToLiteral() is false, then IsFastLiteral() is also false.
     404             :   bool IsFastLiteral() const;
     405             :   // We only serialize boilerplate if IsFastLiteral is true.
     406             :   base::Optional<JSObjectRef> boilerplate() const;
     407             : 
     408             :   ElementsKind GetElementsKind() const;
     409             :   bool CanInlineCall() const;
     410             : };
     411             : 
     412             : class MapRef : public HeapObjectRef {
     413             :  public:
     414             :   using HeapObjectRef::HeapObjectRef;
     415             :   Handle<Map> object() const;
     416             : 
     417             :   int instance_size() const;
     418             :   InstanceType instance_type() const;
     419             :   int GetInObjectProperties() const;
     420             :   int GetInObjectPropertiesStartInWords() const;
     421             :   int NumberOfOwnDescriptors() const;
     422             :   int GetInObjectPropertyOffset(int index) const;
     423             :   int constructor_function_index() const;
     424             :   int NextFreePropertyIndex() const;
     425             :   int UnusedPropertyFields() const;
     426             :   ElementsKind elements_kind() const;
     427             :   bool is_stable() const;
     428             :   bool is_extensible() const;
     429             :   bool is_constructor() const;
     430             :   bool has_prototype_slot() const;
     431             :   bool is_access_check_needed() const;
     432             :   bool is_deprecated() const;
     433             :   bool CanBeDeprecated() const;
     434             :   bool CanTransition() const;
     435             :   bool IsInobjectSlackTrackingInProgress() const;
     436             :   bool is_dictionary_map() const;
     437             :   bool IsFixedCowArrayMap() const;
     438             :   bool IsPrimitiveMap() const;
     439             :   bool is_undetectable() const;
     440             :   bool is_callable() const;
     441             :   bool has_hidden_prototype() const;
     442             :   bool supports_fast_array_iteration() const;
     443             :   bool supports_fast_array_resize() const;
     444             : 
     445             : #define DEF_TESTER(Type, ...) bool Is##Type##Map() const;
     446             :   INSTANCE_TYPE_CHECKERS(DEF_TESTER)
     447             : #undef DEF_TESTER
     448             : 
     449             :   ObjectRef GetConstructor() const;
     450             : 
     451             :   void SerializePrototype();
     452             :   ObjectRef prototype() const;
     453             : 
     454             :   OddballType oddball_type() const;
     455             : 
     456             :   base::Optional<MapRef> AsElementsKind(ElementsKind kind) const;
     457             : 
     458             :   // Concerning the underlying instance_descriptors:
     459             :   void SerializeOwnDescriptors();
     460             :   MapRef FindFieldOwner(int descriptor_index) const;
     461             :   PropertyDetails GetPropertyDetails(int descriptor_index) const;
     462             :   NameRef GetPropertyKey(int descriptor_index) const;
     463             :   FieldIndex GetFieldIndexFor(int descriptor_index) const;
     464             :   ObjectRef GetFieldType(int descriptor_index) const;
     465             :   bool IsUnboxedDoubleField(int descriptor_index) const;
     466             : };
     467             : 
     468             : class FixedArrayBaseRef : public HeapObjectRef {
     469             :  public:
     470             :   using HeapObjectRef::HeapObjectRef;
     471             :   Handle<FixedArrayBase> object() const;
     472             : 
     473             :   int length() const;
     474             : };
     475             : 
     476             : class FixedArrayRef : public FixedArrayBaseRef {
     477             :  public:
     478             :   using FixedArrayBaseRef::FixedArrayBaseRef;
     479             :   Handle<FixedArray> object() const;
     480             : 
     481             :   ObjectRef get(int i) const;
     482             : };
     483             : 
     484             : class FixedDoubleArrayRef : public FixedArrayBaseRef {
     485             :  public:
     486             :   using FixedArrayBaseRef::FixedArrayBaseRef;
     487             :   Handle<FixedDoubleArray> object() const;
     488             : 
     489             :   double get_scalar(int i) const;
     490             :   bool is_the_hole(int i) const;
     491             : };
     492             : 
     493             : class BytecodeArrayRef : public FixedArrayBaseRef {
     494             :  public:
     495             :   using FixedArrayBaseRef::FixedArrayBaseRef;
     496             :   Handle<BytecodeArray> object() const;
     497             : 
     498             :   int register_count() const;
     499             : };
     500             : 
     501             : class JSArrayRef : public JSObjectRef {
     502             :  public:
     503             :   using JSObjectRef::JSObjectRef;
     504             :   Handle<JSArray> object() const;
     505             : 
     506             :   ObjectRef length() const;
     507             : };
     508             : 
     509             : class ScopeInfoRef : public HeapObjectRef {
     510             :  public:
     511             :   using HeapObjectRef::HeapObjectRef;
     512             :   Handle<ScopeInfo> object() const;
     513             : 
     514             :   int ContextLength() const;
     515             : };
     516             : 
     517             : #define BROKER_SFI_FIELDS(V)                \
     518             :   V(int, internal_formal_parameter_count)   \
     519             :   V(bool, has_duplicate_parameters)         \
     520             :   V(int, function_map_index)                \
     521             :   V(FunctionKind, kind)                     \
     522             :   V(LanguageMode, language_mode)            \
     523             :   V(bool, native)                           \
     524             :   V(bool, HasBreakInfo)                     \
     525             :   V(bool, HasBuiltinFunctionId)             \
     526             :   V(bool, HasBuiltinId)                     \
     527             :   V(BuiltinFunctionId, builtin_function_id) \
     528             :   V(bool, construct_as_builtin)             \
     529             :   V(bool, HasBytecodeArray)
     530             : 
     531             : class SharedFunctionInfoRef : public HeapObjectRef {
     532             :  public:
     533             :   using HeapObjectRef::HeapObjectRef;
     534             :   Handle<SharedFunctionInfo> object() const;
     535             : 
     536             :   int builtin_id() const;
     537             :   BytecodeArrayRef GetBytecodeArray() const;
     538             : #define DECL_ACCESSOR(type, name) type name() const;
     539             :   BROKER_SFI_FIELDS(DECL_ACCESSOR)
     540             : #undef DECL_ACCESSOR
     541             : 
     542             :   bool IsSerializedForCompilation(FeedbackVectorRef feedback) const;
     543             :   void SetSerializedForCompilation(FeedbackVectorRef feedback);
     544             : };
     545             : 
     546             : class StringRef : public NameRef {
     547             :  public:
     548             :   using NameRef::NameRef;
     549             :   Handle<String> object() const;
     550             : 
     551             :   int length() const;
     552             :   uint16_t GetFirstChar();
     553             :   base::Optional<double> ToNumber();
     554             :   bool IsSeqString() const;
     555             :   bool IsExternalString() const;
     556             : };
     557             : 
     558             : class SymbolRef : public NameRef {
     559             :  public:
     560             :   using NameRef::NameRef;
     561             :   Handle<Symbol> object() const;
     562             : };
     563             : 
     564             : class JSTypedArrayRef : public JSObjectRef {
     565             :  public:
     566             :   using JSObjectRef::JSObjectRef;
     567             :   Handle<JSTypedArray> object() const;
     568             : 
     569             :   bool is_on_heap() const;
     570             :   size_t length_value() const;
     571             :   void* elements_external_pointer() const;
     572             : 
     573             :   void Serialize();
     574             : 
     575             :   HeapObjectRef buffer() const;
     576             : };
     577             : 
     578             : class ModuleRef : public HeapObjectRef {
     579             :  public:
     580             :   using HeapObjectRef::HeapObjectRef;
     581             :   Handle<Module> object() const;
     582             : 
     583             :   void Serialize();
     584             : 
     585             :   CellRef GetCell(int cell_index) const;
     586             : };
     587             : 
     588             : class CellRef : public HeapObjectRef {
     589             :  public:
     590             :   using HeapObjectRef::HeapObjectRef;
     591             :   Handle<Cell> object() const;
     592             : 
     593             :   ObjectRef value() const;
     594             : };
     595             : 
     596             : class JSGlobalProxyRef : public JSObjectRef {
     597             :  public:
     598             :   using JSObjectRef::JSObjectRef;
     599             :   Handle<JSGlobalProxy> object() const;
     600             : };
     601             : 
     602             : class CodeRef : public HeapObjectRef {
     603             :  public:
     604             :   using HeapObjectRef::HeapObjectRef;
     605             :   Handle<Code> object() const;
     606             : };
     607             : 
     608             : class InternalizedStringRef : public StringRef {
     609             :  public:
     610             :   using StringRef::StringRef;
     611             :   Handle<InternalizedString> object() const;
     612             : 
     613             :   uint32_t array_index() const;
     614             :   static const uint32_t kNotAnArrayIndex = -1;  // 2^32-1 is not a valid index.
     615             : };
     616             : 
     617        3108 : class V8_EXPORT_PRIVATE JSHeapBroker : public NON_EXPORTED_BASE(ZoneObject) {
     618             :  public:
     619             :   JSHeapBroker(Isolate* isolate, Zone* broker_zone);
     620             :   void SetNativeContextRef();
     621             :   void SerializeStandardObjects();
     622             : 
     623             :   Isolate* isolate() const { return isolate_; }
     624             :   Zone* zone() const { return current_zone_; }
     625     1069268 :   NativeContextRef native_context() const { return native_context_.value(); }
     626             :   PerIsolateCompilerCache* compiler_cache() const { return compiler_cache_; }
     627             : 
     628             :   enum BrokerMode { kDisabled, kSerializing, kSerialized, kRetired };
     629             :   BrokerMode mode() const { return mode_; }
     630             :   void StartSerializing();
     631             :   void StopSerializing();
     632             :   void Retire();
     633             :   bool SerializingAllowed() const;
     634             : 
     635             :   // Returns nullptr iff handle unknown.
     636             :   ObjectData* GetData(Handle<Object>) const;
     637             :   // Never returns nullptr.
     638             :   ObjectData* GetOrCreateData(Handle<Object>);
     639             :   // Like the previous but wraps argument in handle first (for convenience).
     640             :   ObjectData* GetOrCreateData(Object);
     641             : 
     642             :   // Check if {object} is any native context's %ArrayPrototype% or
     643             :   // %ObjectPrototype%.
     644             :   bool IsArrayOrObjectPrototype(const JSObjectRef& object) const;
     645             : 
     646             :   std::ostream& Trace();
     647             : 
     648             :   void IncrementTracingIndentation();
     649             :   void DecrementTracingIndentation();
     650             : 
     651             :  private:
     652             :   friend class HeapObjectRef;
     653             :   friend class ObjectRef;
     654             :   friend class ObjectData;
     655             : 
     656             :   void SerializeShareableObjects();
     657             :   void CollectArrayAndObjectPrototypes();
     658             : 
     659             :   Isolate* const isolate_;
     660             :   Zone* const broker_zone_;
     661             :   Zone* current_zone_;
     662             :   base::Optional<NativeContextRef> native_context_;
     663             :   RefsMap* refs_;
     664             :   ZoneUnorderedSet<Handle<JSObject>, Handle<JSObject>::hash,
     665             :                    Handle<JSObject>::equal_to>
     666             :       array_and_object_prototypes_;
     667             :   BrokerMode mode_ = kDisabled;
     668             :   StdoutStream trace_out_;
     669             :   unsigned trace_indentation_ = 0;
     670             :   PerIsolateCompilerCache* compiler_cache_;
     671             : 
     672             :   static const size_t kMinimalRefsBucketCount = 8;     // must be power of 2
     673             :   static const size_t kInitialRefsBucketCount = 1024;  // must be power of 2
     674             : };
     675             : 
     676             : #define ASSIGN_RETURN_NO_CHANGE_IF_DATA_MISSING(something_var,             \
     677             :                                                 optionally_something)      \
     678             :   auto optionally_something_ = optionally_something;                       \
     679             :   if (!optionally_something_)                                              \
     680             :     return NoChangeBecauseOfMissingData(broker(), __FUNCTION__, __LINE__); \
     681             :   something_var = *optionally_something_;
     682             : 
     683             : class Reduction;
     684             : Reduction NoChangeBecauseOfMissingData(JSHeapBroker* broker,
     685             :                                        const char* function, int line);
     686             : 
     687             : #define TRACE_BROKER(broker, x)                               \
     688             :   do {                                                        \
     689             :     if (FLAG_trace_heap_broker) broker->Trace() << x << '\n'; \
     690             :   } while (false)
     691             : 
     692             : }  // namespace compiler
     693             : }  // namespace internal
     694             : }  // namespace v8
     695             : 
     696             : #endif  // V8_COMPILER_JS_HEAP_BROKER_H_

Generated by: LCOV version 1.10