5 #ifndef V8_COMPILER_JS_HEAP_BROKER_H_ 6 #define V8_COMPILER_JS_HEAP_BROKER_H_ 8 #include "src/base/compiler-specific.h" 9 #include "src/base/optional.h" 10 #include "src/compiler/refs-map.h" 11 #include "src/globals.h" 12 #include "src/handles.h" 13 #include "src/objects.h" 14 #include "src/objects/builtin-function-id.h" 15 #include "src/objects/instance-type.h" 16 #include "src/zone/zone-containers.h" 22 class FixedDoubleArray;
23 class InternalizedString;
24 class JSBoundFunction;
30 class ScriptContextTable;
34 enum class OddballType : uint8_t {
46 #define HEAP_BROKER_OBJECT_LIST(V) \ 60 V(ScriptContextTable) \ 66 V(InternalizedString) \ 79 V(MutableHeapNumber) \ 82 V(SharedFunctionInfo) \ 86 class CompilationDependencies;
89 class PerIsolateCompilerCache;
90 #define FORWARD_DECL(Name) class Name##Ref; 91 HEAP_BROKER_OBJECT_LIST(FORWARD_DECL)
98 : data_(data), broker_(broker) {
99 CHECK_NOT_NULL(data_);
104 bool equals(
const ObjectRef& other)
const;
109 #define HEAP_IS_METHOD_DECL(Name) bool Is##Name() const; 110 HEAP_BROKER_OBJECT_LIST(HEAP_IS_METHOD_DECL)
111 #undef HEAP_IS_METHOD_DECL 113 #define HEAP_AS_METHOD_DECL(Name) Name##Ref As##Name() const; 114 HEAP_BROKER_OBJECT_LIST(HEAP_AS_METHOD_DECL)
115 #undef HEAP_AS_METHOD_DECL 117 bool IsNullOrUndefined()
const;
119 bool BooleanValue()
const;
120 double OddballToNumber()
const;
142 enum Flag : uint8_t { kUndetectable = 1 << 0, kCallable = 1 << 1 };
147 OddballType oddball_type)
148 : instance_type_(instance_type),
149 oddball_type_(oddball_type),
151 DCHECK_EQ(instance_type == ODDBALL_TYPE,
152 oddball_type != OddballType::kNone);
155 OddballType oddball_type()
const {
return oddball_type_; }
156 InstanceType instance_type()
const {
return instance_type_; }
157 Flags flags()
const {
return flags_; }
159 bool is_callable()
const {
return flags_ & kCallable; }
160 bool is_undetectable()
const {
return flags_ & kUndetectable; }
163 InstanceType
const instance_type_;
164 OddballType
const oddball_type_;
170 using ObjectRef::ObjectRef;
181 using HeapObjectRef::HeapObjectRef;
190 using HeapObjectRef::HeapObjectRef;
193 double RawFastDoublePropertyAt(
FieldIndex index)
const;
197 void EnsureElementsTenured();
198 ElementsKind GetElementsKind()
const;
200 void SerializeObjectCreateMap();
206 using JSObjectRef::JSObjectRef;
209 size_t byte_length()
const;
210 size_t byte_offset()
const;
215 using JSObjectRef::JSObjectRef;
228 using JSObjectRef::JSObjectRef;
231 bool has_initial_map()
const;
232 bool has_prototype()
const;
233 bool PrototypeRequiresRuntimeLookup()
const;
239 MapRef initial_map()
const;
243 int InitialMapInstanceSizeWithMinSlack()
const;
248 using JSObjectRef::JSObjectRef;
251 ObjectRef raw_properties_or_hash()
const;
260 using HeapObjectRef::HeapObjectRef;
263 double value()
const;
268 using HeapObjectRef::HeapObjectRef;
271 double value()
const;
276 using HeapObjectRef::HeapObjectRef;
284 #define BROKER_COMPULSORY_NATIVE_CONTEXT_FIELDS(V) \ 285 V(JSFunction, array_function) \ 286 V(JSFunction, boolean_function) \ 287 V(JSFunction, bigint_function) \ 288 V(JSFunction, number_function) \ 289 V(JSFunction, object_function) \ 290 V(JSFunction, promise_function) \ 291 V(JSFunction, promise_then) \ 292 V(JSFunction, string_function) \ 293 V(JSFunction, symbol_function) \ 294 V(JSGlobalProxy, global_proxy_object) \ 295 V(JSObject, promise_prototype) \ 296 V(Map, bound_function_with_constructor_map) \ 297 V(Map, bound_function_without_constructor_map) \ 298 V(Map, fast_aliased_arguments_map) \ 299 V(Map, initial_array_iterator_map) \ 300 V(Map, initial_string_iterator_map) \ 301 V(Map, iterator_result_map) \ 302 V(Map, js_array_holey_double_elements_map) \ 303 V(Map, js_array_holey_elements_map) \ 304 V(Map, js_array_holey_smi_elements_map) \ 305 V(Map, js_array_packed_double_elements_map) \ 306 V(Map, js_array_packed_elements_map) \ 307 V(Map, js_array_packed_smi_elements_map) \ 308 V(Map, sloppy_arguments_map) \ 309 V(Map, slow_object_with_null_prototype_map) \ 310 V(Map, strict_arguments_map) \ 311 V(ScriptContextTable, script_context_table) \ 312 V(SharedFunctionInfo, promise_capability_default_reject_shared_fun) \ 313 V(SharedFunctionInfo, promise_catch_finally_shared_fun) \ 314 V(SharedFunctionInfo, promise_then_finally_shared_fun) \ 315 V(SharedFunctionInfo, promise_capability_default_resolve_shared_fun) 319 #define BROKER_OPTIONAL_NATIVE_CONTEXT_FIELDS(V) \ 320 V(Map, async_function_object_map) \ 321 V(Map, map_key_iterator_map) \ 322 V(Map, map_key_value_iterator_map) \ 323 V(Map, map_value_iterator_map) \ 324 V(Map, set_key_value_iterator_map) \ 325 V(Map, set_value_iterator_map) 327 #define BROKER_NATIVE_CONTEXT_FIELDS(V) \ 328 BROKER_COMPULSORY_NATIVE_CONTEXT_FIELDS(V) \ 329 BROKER_OPTIONAL_NATIVE_CONTEXT_FIELDS(V) 333 using ContextRef::ContextRef;
338 #define DECL_ACCESSOR(type, name) type##Ref name() const; 339 BROKER_NATIVE_CONTEXT_FIELDS(DECL_ACCESSOR)
342 MapRef GetFunctionMapFromIndex(
int index)
const;
343 MapRef GetInitialJSArrayMap(ElementsKind kind)
const;
349 using HeapObjectRef::HeapObjectRef;
355 using HeapObjectRef::HeapObjectRef;
369 using HeapObjectRef::HeapObjectRef;
375 using HeapObjectRef::HeapObjectRef;
380 void SerializeSlots();
385 using HeapObjectRef::HeapObjectRef;
388 bool PointsToLiteral()
const;
389 PretenureFlag GetPretenureMode()
const;
397 bool IsFastLiteral()
const;
401 ElementsKind GetElementsKind()
const;
402 bool CanInlineCall()
const;
407 using HeapObjectRef::HeapObjectRef;
410 int instance_size()
const;
411 InstanceType instance_type()
const;
412 int GetInObjectProperties()
const;
413 int GetInObjectPropertiesStartInWords()
const;
414 int NumberOfOwnDescriptors()
const;
415 int GetInObjectPropertyOffset(
int index)
const;
416 int constructor_function_index()
const;
417 ElementsKind elements_kind()
const;
418 bool is_stable()
const;
419 bool is_extensible()
const;
420 bool is_constructor()
const;
421 bool has_prototype_slot()
const;
422 bool is_access_check_needed()
const;
423 bool is_deprecated()
const;
424 bool CanBeDeprecated()
const;
425 bool CanTransition()
const;
426 bool IsInobjectSlackTrackingInProgress()
const;
427 bool is_dictionary_map()
const;
428 bool IsFixedCowArrayMap()
const;
429 bool IsPrimitiveMap()
const;
430 bool is_undetectable()
const;
431 bool is_callable()
const;
432 bool has_hidden_prototype()
const;
434 #define DEF_TESTER(Type, ...) bool Is##Type##Map() const; 435 INSTANCE_TYPE_CHECKERS(DEF_TESTER)
440 void SerializePrototype();
443 OddballType oddball_type()
const;
448 void SerializeOwnDescriptors();
449 MapRef FindFieldOwner(
int descriptor_index)
const;
451 NameRef GetPropertyKey(
int descriptor_index)
const;
452 FieldIndex GetFieldIndexFor(
int descriptor_index)
const;
453 ObjectRef GetFieldType(
int descriptor_index)
const;
454 bool IsUnboxedDoubleField(
int descriptor_index)
const;
459 using HeapObjectRef::HeapObjectRef;
467 using FixedArrayBaseRef::FixedArrayBaseRef;
475 using FixedArrayBaseRef::FixedArrayBaseRef;
478 double get_scalar(
int i)
const;
479 bool is_the_hole(
int i)
const;
484 using FixedArrayBaseRef::FixedArrayBaseRef;
487 int register_count()
const;
492 using JSObjectRef::JSObjectRef;
500 using HeapObjectRef::HeapObjectRef;
503 int ContextLength()
const;
506 #define BROKER_SFI_FIELDS(V) \ 507 V(int, internal_formal_parameter_count) \ 508 V(bool, has_duplicate_parameters) \ 509 V(int, function_map_index) \ 510 V(FunctionKind, kind) \ 511 V(LanguageMode, language_mode) \ 513 V(bool, HasBreakInfo) \ 514 V(bool, HasBuiltinFunctionId) \ 515 V(bool, HasBuiltinId) \ 516 V(BuiltinFunctionId, builtin_function_id) \ 517 V(bool, construct_as_builtin) \ 518 V(bool, HasBytecodeArray) 522 using HeapObjectRef::HeapObjectRef;
525 int builtin_id()
const;
527 #define DECL_ACCESSOR(type, name) type name() const; 528 BROKER_SFI_FIELDS(DECL_ACCESSOR)
534 using NameRef::NameRef;
538 uint16_t GetFirstChar();
540 bool IsSeqString()
const;
541 bool IsExternalString()
const;
546 using JSObjectRef::JSObjectRef;
549 bool is_on_heap()
const;
550 size_t length_value()
const;
551 void* elements_external_pointer()
const;
560 using HeapObjectRef::HeapObjectRef;
565 CellRef GetCell(
int cell_index)
const;
570 using HeapObjectRef::HeapObjectRef;
578 using JSObjectRef::JSObjectRef;
584 using HeapObjectRef::HeapObjectRef;
590 using StringRef::StringRef;
594 class V8_EXPORT_PRIVATE
JSHeapBroker :
public NON_EXPORTED_BASE(ZoneObject) {
597 void SetNativeContextRef();
598 void SerializeStandardObjects();
600 Isolate* isolate()
const {
return isolate_; }
601 Zone* zone()
const {
return current_zone_; }
605 enum BrokerMode { kDisabled, kSerializing, kSerialized, kRetired };
606 BrokerMode mode()
const {
return mode_; }
607 void StartSerializing();
608 void StopSerializing();
610 bool SerializingAllowed()
const;
621 bool IsArrayOrObjectPrototype(
const JSObjectRef&
object)
const;
623 void Trace(
const char* format, ...)
const;
624 void IncrementTracingIndentation();
625 void DecrementTracingIndentation();
632 void SerializeShareableObjects();
633 void CollectArrayAndObjectPrototypes();
636 Zone*
const broker_zone_;
642 array_and_object_prototypes_;
644 BrokerMode mode_ = kDisabled;
645 unsigned tracing_indentation_ = 0;
648 static const size_t kMinimalRefsBucketCount = 8;
649 static const size_t kInitialRefsBucketCount = 1024;
652 #define ASSIGN_RETURN_NO_CHANGE_IF_DATA_MISSING(something_var, \ 653 optionally_something) \ 654 auto optionally_something_ = optionally_something; \ 655 if (!optionally_something_) \ 656 return NoChangeBecauseOfMissingData(broker(), __FUNCTION__, __LINE__); \ 657 something_var = *optionally_something_; 661 const char*
function,
int line);
667 #endif // V8_COMPILER_JS_HEAP_BROKER_H_