5 #ifndef V8_OBJECTS_MAP_H_ 6 #define V8_OBJECTS_MAP_H_ 8 #include "src/globals.h" 9 #include "src/objects.h" 10 #include "src/objects/code.h" 11 #include "src/objects/heap-object.h" 14 #include "src/objects/object-macros.h" 19 enum InstanceType : uint16_t;
21 #define VISITOR_ID_LIST(V) \ 28 V(CodeDataContainer) \ 34 V(EmbedderDataArray) \ 35 V(EphemeronHashTable) \ 40 V(FixedFloat64Array) \ 41 V(FixedTypedArrayBase) \ 54 V(PreParsedScopeData) \ 60 V(SharedFunctionInfo) \ 61 V(ShortcutCandidate) \ 63 V(SmallOrderedHashMap) \ 64 V(SmallOrderedHashSet) \ 65 V(SmallOrderedNameDictionary) \ 70 V(UncompiledDataWithoutPreParsedScope) \ 71 V(UncompiledDataWithPreParsedScope) \ 72 V(WasmInstanceObject) \ 85 #define VISITOR_ID_ENUM_DECL(id) kVisit##id, 86 VISITOR_ID_LIST(VISITOR_ID_ENUM_DECL)
87 #undef VISITOR_ID_ENUM_DECL 91 typedef std::vector<Handle<Map>> MapHandles;
183 DECL_INT_ACCESSORS(instance_size)
186 DECL_INT_ACCESSORS(instance_size_in_words)
191 DECL_INT_ACCESSORS(inobject_properties_start_or_constructor_function_index)
194 inline int GetInObjectPropertiesStartInWords()
const;
195 inline void SetInObjectPropertiesStartInWords(
int value);
197 inline int GetInObjectProperties()
const;
201 static const int kNoConstructorFunctionIndex = 0;
202 inline int GetConstructorFunctionIndex()
const;
203 inline void SetConstructorFunctionIndex(
int value);
212 DECL_PRIMITIVE_ACCESSORS(instance_type, InstanceType)
217 inline int UsedInstanceSize()
const;
221 inline int UnusedPropertyFields()
const;
223 inline int UnusedInObjectProperties()
const;
225 inline void SetInObjectUnusedPropertyFields(
int unused_property_fields);
227 inline void SetOutOfObjectUnusedPropertyFields(
int unused_property_fields);
228 inline void CopyUnusedPropertyFields(
Map map);
229 inline void CopyUnusedPropertyFieldsAdjustedForInstanceSize(
Map map);
230 inline void AccountAddedPropertyField();
231 inline void AccountAddedOutOfObjectPropertyField(
232 int unused_in_property_array);
237 DECL_PRIMITIVE_ACCESSORS(bit_field, byte)
240 #define MAP_BIT_FIELD_FIELDS(V, _) \ 241 V(HasNonInstancePrototypeBit, bool, 1, _) \ 242 V(IsCallableBit, bool, 1, _) \ 243 V(HasNamedInterceptorBit, bool, 1, _) \ 244 V(HasIndexedInterceptorBit, bool, 1, _) \ 245 V(IsUndetectableBit, bool, 1, _) \ 246 V(IsAccessCheckNeededBit, bool, 1, _) \ 247 V(IsConstructorBit, bool, 1, _) \ 248 V(HasPrototypeSlotBit, bool, 1, _) 250 DEFINE_BIT_FIELDS(MAP_BIT_FIELD_FIELDS)
251 #undef MAP_BIT_FIELD_FIELDS 256 DECL_PRIMITIVE_ACCESSORS(bit_field2, byte)
259 #define MAP_BIT_FIELD2_FIELDS(V, _) \ 260 V(IsExtensibleBit, bool, 1, _) \ 261 V(IsPrototypeMapBit, bool, 1, _) \ 262 V(IsInRetainedMapListBit, bool, 1, _) \ 263 V(ElementsKindBits, ElementsKind, 5, _) 265 DEFINE_BIT_FIELDS(MAP_BIT_FIELD2_FIELDS)
266 #undef MAP_BIT_FIELD2_FIELDS 271 DECL_PRIMITIVE_ACCESSORS(bit_field3,
uint32_t)
274 #define MAP_BIT_FIELD3_FIELDS(V, _) \ 275 V(EnumLengthBits, int, kDescriptorIndexBitCount, _) \ 276 V(NumberOfOwnDescriptorsBits, int, kDescriptorIndexBitCount, _) \ 277 V(IsDictionaryMapBit, bool, 1, _) \ 278 V(OwnsDescriptorsBit, bool, 1, _) \ 279 V(HasHiddenPrototypeBit, bool, 1, _) \ 280 V(IsDeprecatedBit, bool, 1, _) \ 281 V(IsUnstableBit, bool, 1, _) \ 282 V(IsMigrationTargetBit, bool, 1, _) \ 283 V(IsImmutablePrototypeBit, bool, 1, _) \ 284 V(NewTargetIsBaseBit, bool, 1, _) \ 285 V(MayHaveInterestingSymbolsBit, bool, 1, _) \ 286 V(ConstructionCounterBits, int, 3, _) 288 DEFINE_BIT_FIELDS(MAP_BIT_FIELD3_FIELDS)
289 #undef MAP_BIT_FIELD3_FIELDS 291 STATIC_ASSERT(NumberOfOwnDescriptorsBits::kMax >= kMaxNumberOfDescriptors);
293 static const int kSlackTrackingCounterStart = 7;
294 static const int kSlackTrackingCounterEnd = 1;
295 static const int kNoSlackTracking = 0;
296 STATIC_ASSERT(kSlackTrackingCounterStart <= ConstructionCounterBits::kMax);
327 static const int kGenerousAllocationCount =
328 kSlackTrackingCounterStart - kSlackTrackingCounterEnd + 1;
331 void StartInobjectSlackTracking();
335 inline bool IsInobjectSlackTrackingInProgress()
const;
338 inline void InobjectSlackTrackingStep(
Isolate* isolate);
342 int ComputeMinObjectSlack(
Isolate* isolate);
343 inline int InstanceSizeFromSlack(
int slack)
const;
347 void CompleteInobjectSlackTracking(
Isolate* isolate);
354 DECL_BOOLEAN_ACCESSORS(has_non_instance_prototype)
358 DECL_BOOLEAN_ACCESSORS(is_constructor)
364 DECL_BOOLEAN_ACCESSORS(may_have_interesting_symbols)
366 DECL_BOOLEAN_ACCESSORS(has_prototype_slot)
369 DECL_BOOLEAN_ACCESSORS(has_hidden_prototype)
372 DECL_BOOLEAN_ACCESSORS(has_named_interceptor)
375 DECL_BOOLEAN_ACCESSORS(has_indexed_interceptor)
383 DECL_BOOLEAN_ACCESSORS(is_undetectable)
387 DECL_BOOLEAN_ACCESSORS(is_callable)
389 DECL_BOOLEAN_ACCESSORS(new_target_is_base)
390 DECL_BOOLEAN_ACCESSORS(is_extensible)
391 DECL_BOOLEAN_ACCESSORS(is_prototype_map)
392 inline bool is_abandoned_prototype_map()
const;
396 DECL_BOOLEAN_ACCESSORS(is_in_retained_map_list)
398 DECL_PRIMITIVE_ACCESSORS(elements_kind, ElementsKind)
401 inline bool has_fast_smi_elements()
const;
404 inline bool has_fast_object_elements()
const;
405 inline bool has_fast_smi_or_object_elements()
const;
406 inline bool has_fast_double_elements()
const;
407 inline bool has_fast_elements()
const;
408 inline bool has_sloppy_arguments_elements()
const;
409 inline bool has_fast_sloppy_arguments_elements()
const;
410 inline bool has_fast_string_wrapper_elements()
const;
411 inline bool has_fixed_typed_array_elements()
const;
412 inline bool has_dictionary_elements()
const;
416 bool DictionaryElementsInPrototypeChainOnly(
Isolate* isolate);
418 inline Map ElementsTransitionMap();
428 DECL_ACCESSORS(prototype_info,
Object)
435 inline bool should_be_fast_prototype_map()
const;
436 static void SetShouldBeFastPrototypeMap(
Handle<Map> map,
bool value,
447 static const int kPrototypeChainValid = 0;
448 static const int kPrototypeChainInvalid = 1;
450 static bool IsPrototypeChainInvalidated(
Map map);
453 Map GetPrototypeChainRootMap(
Isolate* isolate)
const;
456 Map FindFieldOwner(
Isolate* isolate,
int descriptor)
const;
458 inline int GetInObjectPropertyOffset(
int index)
const;
463 : mutable_count_(mutable_count), const_count_(const_count) {}
465 int GetTotal()
const {
return mutable_count() + const_count(); }
467 int mutable_count()
const {
return mutable_count_; }
468 int const_count()
const {
return const_count_; }
476 int NumberOfFields()
const;
478 bool HasOutOfObjectProperties()
const;
482 bool TransitionRequiresSynchronizationWithGC(
Map target)
const;
485 bool TransitionRemovesTaggedField(
Map target)
const;
488 bool TransitionChangesTaggedFieldToUntaggedField(
Map target)
const;
491 bool InstancesNeedRewriting(
Map target)
const;
492 bool InstancesNeedRewriting(
Map target,
int target_number_of_fields,
493 int target_inobject,
int target_unused,
494 int* old_number_of_fields)
const;
499 int modify_index, PropertyConstness new_constness,
504 static inline bool IsInplaceGeneralizableField(PropertyConstness constness,
515 static inline void GeneralizeIfCanHaveTransitionableFastElementsKind(
516 Isolate* isolate, InstanceType instance_type,
522 PropertyKind new_kind,
523 PropertyAttributes new_attributes,
528 ElementsKind new_elements_kind);
532 int descriptor_number,
533 PropertyConstness constness,
537 PropertyNormalizationMode mode,
544 DECL_BOOLEAN_ACCESSORS(is_dictionary_map)
548 DECL_BOOLEAN_ACCESSORS(is_access_check_needed)
551 DECL_ACCESSORS(prototype,
Object)
555 bool enable_prototype_setup_mode =
true);
564 DECL_ACCESSORS(constructor_or_backpointer,
Object)
565 inline Object* GetConstructor()
const;
567 inline void SetConstructor(
Object* constructor,
568 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
571 inline Object* GetBackPointer()
const;
572 inline void SetBackPointer(
Object* value,
573 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
582 inline bool HasFastPointerLayout()
const;
609 DECL_ACCESSORS(prototype_validity_cell,
Object)
613 inline bool IsPrototypeValidityCellValid()
const;
617 inline int LastAdded()
const;
619 inline int NumberOfOwnDescriptors()
const;
620 inline void SetNumberOfOwnDescriptors(
int number);
622 inline Cell* RetrieveDescriptorsPointer();
627 bool OnlyHasSimpleProperties()
const;
628 inline int EnumLength()
const;
629 inline void SetEnumLength(
int length);
631 DECL_BOOLEAN_ACCESSORS(owns_descriptors)
633 inline void mark_unstable();
634 inline bool is_stable()
const;
636 DECL_BOOLEAN_ACCESSORS(is_migration_target)
638 DECL_BOOLEAN_ACCESSORS(is_immutable_proto)
647 DECL_INT_ACCESSORS(construction_counter)
649 DECL_BOOLEAN_ACCESSORS(is_deprecated)
650 inline bool CanBeDeprecated()
const;
658 static Map TryUpdateSlow(
Isolate* isolate,
Map map) V8_WARN_UNUSED_RESULT;
667 int instance_size,
int in_object_properties,
668 int unused_property_fields);
671 PropertyNormalizationMode mode = CLEAR_INOBJECT_PROPERTIES);
675 TransitionFlag flag);
685 TransitionFlag flag);
690 TransitionFlag flag);
695 ElementsKind to_kind);
701 ElementsKind kind, TransitionFlag flag);
707 PropertyAttributes attrs_to_add,
716 inline bool TooManyFastProperties(StoreOrigin store_origin)
const;
720 PropertyAttributes attributes,
721 PropertyConstness constness,
722 StoreOrigin store_origin);
726 PropertyAttributes attributes);
731 PropertyAttributes attributes);
733 inline void AppendDescriptor(
Descriptor* desc);
748 int NextFreePropertyIndex()
const;
751 int NumberOfEnumerableProperties()
const;
755 static inline int SlackForArraySize(
int old_size,
int size_limit);
776 Map FindElementsKindTransitionedMap(
Isolate* isolate,
777 MapHandles
const& candidates);
779 inline bool CanTransition()
const;
781 #define DECL_TESTER(Type, ...) inline bool Is##Type##Map() const; 782 INSTANCE_TYPE_CHECKERS(DECL_TESTER)
784 inline bool IsBooleanMap()
const;
785 inline bool IsNullOrUndefinedMap()
const;
786 inline bool IsPrimitiveMap()
const;
787 inline bool IsSpecialReceiverMap()
const;
788 inline bool IsCustomElementsReceiverMap()
const;
790 bool IsMapInArrayPrototypeChain(
Isolate* isolate)
const;
797 void DictionaryMapVerify(
Isolate* isolate);
800 DECL_PRIMITIVE_ACCESSORS(visitor_id, VisitorId)
808 static const int kMaxPreAllocatedPropertyFields = 255;
811 #define MAP_FIELDS(V) \ 813 V(kInstanceSizeInWordsOffset, kUInt8Size) \ 814 V(kInObjectPropertiesStartOrConstructorFunctionIndexOffset, kUInt8Size) \ 815 V(kUsedOrUnusedInstanceSizeInWordsOffset, kUInt8Size) \ 816 V(kVisitorIdOffset, kUInt8Size) \ 817 V(kInstanceTypeOffset, kUInt16Size) \ 818 V(kBitFieldOffset, kUInt8Size) \ 819 V(kBitField2Offset, kUInt8Size) \ 820 V(kBitField3Offset, kUInt32Size) \ 821 V(k64BitArchPaddingOffset, \ 822 kSystemPointerSize == kUInt32Size ? 0 : kUInt32Size) \ 824 V(kPointerFieldsBeginOffset, 0) \ 825 V(kPrototypeOffset, kTaggedSize) \ 826 V(kConstructorOrBackPointerOffset, kTaggedSize) \ 827 V(kTransitionsOrPrototypeInfoOffset, kTaggedSize) \ 828 V(kDescriptorsOffset, kTaggedSize) \ 829 V(kLayoutDescriptorOffset, FLAG_unbox_double_fields ? kTaggedSize : 0) \ 830 V(kDependentCodeOffset, kTaggedSize) \ 831 V(kPrototypeValidityCellOffset, kTaggedSize) \ 832 V(kPointerFieldsEndOffset, 0) \ 836 DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize, MAP_FIELDS)
839 STATIC_ASSERT(kInstanceTypeOffset == Internals::kMapInstanceTypeOffset);
847 bool EquivalentToForNormalization(
const Map other,
848 PropertyNormalizationMode mode)
const;
851 inline bool IsUnboxedDoubleField(
FieldIndex index)
const;
853 void PrintMapDetails(std::ostream& os);
855 static inline Handle<Map> AddMissingTransitionsForTesting(
863 inline void NotifyLeafMapLayoutChange(
Isolate* isolate);
865 static VisitorId GetVisitorId(
Map map);
873 static inline bool CanHaveFastTransitionableElementsKind(
874 InstanceType instance_type);
875 inline bool CanHaveFastTransitionableElementsKind()
const;
889 DECL_INT_ACCESSORS(used_or_unused_instance_size_in_words)
893 Map LookupElementsTransitionMap(
Isolate* isolate, ElementsKind elements_kind);
904 SimpleTransitionFlag flag);
906 bool EquivalentToForTransition(
const Map other)
const;
907 bool EquivalentToForElementsKindTransition(
const Map other)
const;
909 int instance_size,
int inobject_properties);
916 static void InstallDescriptors(
922 TransitionFlag flag);
927 SimpleTransitionFlag simple_flag);
932 TransitionFlag flag);
934 PropertyNormalizationMode mode);
938 ElementsKind elements_kind,
941 PropertyAttributes attributes,
944 void DeprecateTransitionTree(
Isolate* isolate);
952 void UpdateFieldType(
Isolate* isolate,
int descriptor_number,
958 void PrintReconfiguration(
Isolate* isolate, FILE* file,
int modify_index,
959 PropertyKind kind, PropertyAttributes attributes);
961 void PrintGeneralization(
962 Isolate* isolate, FILE* file,
const char* reason,
int modify_index,
963 int split,
int descriptors,
bool constant_to_field,
967 static const int kFastPropertiesSoftLimit = 12;
968 static const int kMaxFastProperties = 128;
984 PropertyNormalizationMode mode);
989 static inline bool IsNormalizedMapCache(
const HeapObject* obj);
994 static const int kEntries = 64;
1000 void set(
int index,
Object* value);
1006 #include "src/objects/object-macros-undef.h" 1008 #endif // V8_OBJECTS_MAP_H_