Lines Matching defs:map

5 #include "src/objects/map.h"
20 #include "src/objects/map-updater.h"
44 return ReadOnlyRoots(isolate).null_value().map();
48 base::Optional<JSFunction> Map::GetConstructorFunction(Map map,
51 if (map.IsPrimitiveMap()) {
52 int const constructor_function_index = map.GetConstructorFunctionIndex();
61 Map map;
65 map = roots.name##_map(); \
71 map = roots.name##_map(); \
78 return map;
81 VisitorId Map::GetVisitorId(Map map) {
84 const int instance_type = map.instance_type();
114 if (InstanceTypeChecker::IsJSApiObject(map.instance_type())) {
322 COMPRESS_POINTERS_BOOL && JSObject::GetEmbedderFieldCount(map) > 0;
432 MaybeHandle<Map> Map::CopyWithField(Isolate* isolate, Handle<Map> map,
438 DCHECK(map->instance_descriptors(isolate)
439 .Search(*name, map->NumberOfOwnDescriptors())
443 if (map->NumberOfOwnDescriptors() >= kMaxNumberOfDescriptors) {
448 int index = map->NextFreePropertyIndex();
450 if (map->instance_type() == JS_CONTEXT_EXTENSION_OBJECT_TYPE) {
456 isolate, map->instance_type(), &representation, &type);
463 Handle<Map> new_map = Map::CopyAddDescriptor(isolate, map, &d, flag);
468 MaybeHandle<Map> Map::CopyWithConstant(Isolate* isolate, Handle<Map> map,
474 if (map->NumberOfOwnDescriptors() >= kMaxNumberOfDescriptors) {
480 return CopyWithField(isolate, map, name, type, attributes,
519 // the map is sufficient.
521 // In-object slack tracking may have reduced the object size of the new map.
592 // Don't overwrite the empty descriptor array or initial map's descriptors.
608 if (next.IsUndefined(isolate)) break; // Stop overwriting at initial map.
624 // Initial map must not contain descriptors in the descriptors array
625 // that do not belong to the map.
667 // TryReplayPropertyTransitions() and consider checking the target map's field
669 // Go to slow map updating if the old_map has fast properties with cleared
783 Handle<Map> Map::Update(Isolate* isolate, Handle<Map> map) {
784 if (!map->is_deprecated()) return map;
786 Map target_map = SearchMigrationTarget(isolate, *map);
791 MapUpdater mu(isolate, map);
795 void Map::EnsureDescriptorSlack(Isolate* isolate, Handle<Map> map, int slack) {
797 DCHECK(map->owns_descriptors());
799 Handle<DescriptorArray> descriptors(map->instance_descriptors(isolate),
801 int old_size = map->NumberOfOwnDescriptors();
809 map->UpdateDescriptors(isolate, *new_descriptors,
810 map->NumberOfOwnDescriptors());
816 // on a cache always being available once it is set. If the map has more
828 // Update the descriptors from {map} (inclusive) until the initial map
829 // (exclusive). In the case that {map} is the initial map, update it.
830 map->UpdateDescriptors(isolate, *new_descriptors,
831 map->NumberOfOwnDescriptors());
832 Object next = map->GetBackPointer();
848 Handle<Map> map(isolate->native_context()->object_function().initial_map(),
850 if (map->prototype() == *prototype) return map;
856 if (!js_prototype->map().is_prototype_map()) {
861 // TODO(verwaest): Use inobject slack tracking for this map.
863 map = handle(info->ObjectCreateMap(), isolate);
865 map = Map::CopyInitialMap(isolate, map);
866 Map::SetPrototype(isolate, map, prototype);
867 PrototypeInfo::SetObjectCreateMap(info, map);
869 return map;
872 return Map::TransitionToPrototype(isolate, map, prototype);
875 static bool ContainsMap(MapHandles const& maps, Map map) {
876 DCHECK(!map.is_null());
878 if (!current.is_null() && *current == map) return true;
904 // Check the state of the root map.
935 static Map FindClosestElementsTransition(Isolate* isolate, Map map,
940 DCHECK_EQ(map.FindRootMap(isolate).NumberOfOwnDescriptors(),
941 map.NumberOfOwnDescriptors());
942 Map current_map = map;
944 ElementsKind kind = map.elements_kind();
964 if (isolate->initial_array_prototype()->map() == *this) {
968 if (isolate->initial_object_prototype()->map() == *this) {
975 Handle<Map> Map::TransitionElementsTo(Isolate* isolate, Handle<Map> map,
977 ElementsKind from_kind = map->elements_kind();
978 if (from_kind == to_kind) return map;
982 if (*map == native_context.fast_aliased_arguments_map()) {
987 if (*map == native_context.slow_aliased_arguments_map()) {
992 // Reuse map transitions for JSArrays.
994 if (native_context.GetInitialJSArrayMap(from_kind) == *map) {
1003 DCHECK(!map->IsUndefined(isolate));
1007 map->GetBackPointer().IsMap() &&
1008 Map::cast(map->GetBackPointer()).elements_kind() == to_kind) {
1009 return handle(Map::cast(map->GetBackPointer()), isolate);
1021 return Map::CopyAsElementsKind(isolate, map, to_kind, OMIT_TRANSITION);
1024 return MapUpdater{isolate, map}.ReconfigureElementsKind(to_kind);
1028 Handle<Map> map,
1030 DCHECK(IsTransitionElementsKind(map->elements_kind()));
1032 Handle<Map> current_map = map;
1034 ElementsKind kind = map->elements_kind();
1036 if (map->IsDetached(isolate)) {
1048 // In case we are exiting the fast elements kind system, just add the map in
1059 base::Optional<Map> Map::TryAsElementsKind(Isolate* isolate, Handle<Map> map,
1062 Map closest_map = FindClosestElementsTransition(isolate, *map, kind, cmode);
1068 Handle<Map> Map::AsElementsKind(Isolate* isolate, Handle<Map> map,
1071 FindClosestElementsTransition(isolate, *map, kind,
1120 if (iter.GetCurrent().map().IsCustomElementsReceiverMap()) return true;
1199 // The cached map should match newly created normalized map bit-by-bit,
1201 // applied to the shared map, dependent code and weak cell cache.
1256 Handle<Map> Map::CopyNormalized(Isolate* isolate, Handle<Map> map,
1258 int new_instance_size = map->instance_size();
1260 new_instance_size -= map->GetInObjectProperties() * kTaggedSize;
1264 isolate, map, new_instance_size,
1265 mode == CLEAR_INOBJECT_PROPERTIES ? 0 : map->GetInObjectProperties());
1285 // Return an immutable prototype exotic object version of the input map.
1288 // memory on the map transition tree.
1291 Handle<Map> Map::TransitionToImmutableProto(Isolate* isolate, Handle<Map> map) {
1292 Handle<Map> new_map = Map::Copy(isolate, map, "ImmutablePrototype");
1298 void EnsureInitialMap(Isolate* isolate, Handle<Map> map) {
1300 Object maybe_constructor = map->GetConstructor();
1302 *map == JSFunction::cast(maybe_constructor).initial_map()) ||
1305 // Function's initial map is a sloppy function map.
1306 *map == *isolate->strict_function_map() ||
1307 *map == *isolate->strict_function_with_name_map() ||
1308 // Same holds for GeneratorFunction and its initial map.
1309 *map == *isolate->generator_function_map() ||
1310 *map == *isolate->generator_function_with_name_map() ||
1312 *map == *isolate->async_function_map() ||
1313 *map == *isolate->async_function_with_name_map());
1316 // that do not belong to the map.
1317 DCHECK_EQ(map->NumberOfOwnDescriptors(),
1318 map->instance_descriptors(isolate).number_of_descriptors());
1323 Handle<Map> Map::CopyInitialMapNormalized(Isolate* isolate, Handle<Map> map,
1325 EnsureInitialMap(isolate, map);
1326 return CopyNormalized(isolate, map, mode);
1330 Handle<Map> Map::CopyInitialMap(Isolate* isolate, Handle<Map> map,
1333 EnsureInitialMap(isolate, map);
1336 RawCopy(isolate, map, instance_size, inobject_properties);
1341 int number_of_own_descriptors = map->NumberOfOwnDescriptors();
1344 DescriptorArray descriptors = map->instance_descriptors(isolate);
1355 Handle<Map> Map::CopyDropDescriptors(Isolate* isolate, Handle<Map> map) {
1357 RawCopy(isolate, map, map->instance_size(),
1358 map->IsJSObjectMap() ? map->GetInObjectProperties() : 0);
1361 if (map->IsJSObjectMap()) {
1362 result->CopyUnusedPropertyFields(*map);
1364 map->NotifyLeafMapLayoutChange(isolate);
1368 Handle<Map> Map::ShareDescriptor(Isolate* isolate, Handle<Map> map,
1371 // Sanity check. This path is only to be taken if the map owns its descriptor
1374 DCHECK_EQ(map->NumberOfOwnDescriptors(),
1375 map->instance_descriptors(isolate).number_of_descriptors());
1377 Handle<Map> result = CopyDropDescriptors(isolate, map);
1392 EnsureDescriptorSlack(isolate, map, slack);
1393 descriptors = handle(map->instance_descriptors(isolate), isolate);
1403 DCHECK(result->NumberOfOwnDescriptors() == map->NumberOfOwnDescriptors() + 1);
1404 ConnectTransition(isolate, map, result, name, SIMPLE_PROPERTY_TRANSITION);
1419 // |parent| is initial map and it must not contain descriptors in the
1420 // descriptors array that do not belong to the map.
1437 Handle<Map> Map::CopyReplaceDescriptors(Isolate* isolate, Handle<Map> map,
1445 Handle<Map> result = CopyDropDescriptors(isolate, map);
1454 if (map->is_prototype_map()) {
1458 TransitionsAccessor::CanHaveMoreTransitions(isolate, map)) {
1462 ConnectTransition(isolate, map, result, name, simple_flag);
1470 LOG(isolate, MapEvent("ReplaceDescriptors", map, result, reason,
1487 // Start with creating last map which will own full descriptors array.
1493 // Also the last map might have interesting symbols, we temporarily set
1502 // invariant since the last map is not yet connected to the transition tree
1503 // we create here. But it is safe because GC never trims map's descriptors
1504 // if there are no dead transitions from that map and this is exactly the
1506 Handle<Map> map = split_map;
1508 Handle<Map> new_map = CopyDropDescriptors(isolate, map);
1509 InstallDescriptors(isolate, map, new_map, i, descriptors);
1511 map = new_map;
1513 map->NotifyLeafMapLayoutChange(isolate);
1515 InstallDescriptors(isolate, map, last_map, InternalIndex(nof_descriptors - 1),
1542 Handle<Map> Map::CopyAsElementsKind(Isolate* isolate, Handle<Map> map,
1546 DCHECK(map->IsJSObjectMap());
1548 !map->CanHaveFastTransitionableElementsKind(),
1554 DCHECK_EQ(map->FindRootMap(isolate).NumberOfOwnDescriptors(),
1555 map->NumberOfOwnDescriptors());
1558 map->ElementsTransitionMap(isolate, ConcurrencyMode::kSynchronous);
1564 IsMoreGeneralElementsKindTransition(map->elements_kind(), kind));
1565 DCHECK(kind != map->elements_kind());
1570 TransitionsAccessor::CanHaveMoreTransitions(isolate, map) &&
1574 Handle<Map> new_map = CopyForElementsTransition(isolate, map);
1578 ConnectTransition(isolate, map, new_map, name, SPECIAL_TRANSITION);
1582 // Create a new free-floating map only if we are not allowed to store it.
1583 Handle<Map> new_map = Copy(isolate, map, "CopyAsElementsKind");
1591 // Initial map for sloppy mode function is stored in the function
1611 // Create new map taking descriptors from the |function_map| and all
1613 Handle<Map> map =
1617 map->SetConstructor(initial_map->GetConstructor());
1618 map->set_prototype(initial_map->prototype());
1619 map->set_construction_counter(initial_map->construction_counter());
1622 Map::ConnectTransition(isolate, initial_map, map, transition_symbol,
1625 return map;
1628 Handle<Map> Map::CopyForElementsTransition(Isolate* isolate, Handle<Map> map) {
1629 DCHECK(!map->IsDetached(isolate));
1630 Handle<Map> new_map = CopyDropDescriptors(isolate, map);
1632 if (map->owns_descriptors()) {
1633 // In case the map owned its own descriptors, share the descriptors and
1634 // transfer ownership to the new map.
1636 map->set_owns_descriptors(false);
1637 new_map->InitializeDescriptors(isolate, map->instance_descriptors(isolate));
1639 // In case the map did not own its own descriptors, a split is forced by
1640 // copying the map; creating a new descriptor array cell.
1641 Handle<DescriptorArray> descriptors(map->instance_descriptors(isolate),
1643 int number_of_own_descriptors = map->NumberOfOwnDescriptors();
1651 Handle<Map> Map::Copy(Isolate* isolate, Handle<Map> map, const char* reason) {
1652 Handle<DescriptorArray> descriptors(map->instance_descriptors(isolate),
1654 int number_of_own_descriptors = map->NumberOfOwnDescriptors();
1657 return CopyReplaceDescriptors(isolate, map, new_descriptors, OMIT_TRANSITION,
1679 // Adjust the map with the extra inobject properties.
1690 Isolate* isolate, Handle<Map> map, PropertyAttributes attrs_to_add,
1693 int num_descriptors = map->NumberOfOwnDescriptors();
1695 isolate, handle(map->instance_descriptors(isolate), isolate),
1701 CopyReplaceDescriptors(isolate, map, new_desc, flag, transition_marker,
1704 if (!IsTypedArrayOrRabGsabTypedArrayElementsKind(map->elements_kind())) {
1705 ElementsKind new_kind = IsStringWrapperElementsKind(map->elements_kind())
1710 switch (map->elements_kind()) {
1786 Handle<Map> UpdateDescriptorForValue(Isolate* isolate, Handle<Map> map,
1790 if (CanHoldValue(map->instance_descriptors(isolate), descriptor, constness,
1792 return map;
1796 map->instance_descriptors(isolate).GetDetails(descriptor).attributes();
1800 MapUpdater mu(isolate, map);
1808 Handle<Map> Map::PrepareForDataProperty(Isolate* isolate, Handle<Map> map,
1812 // Update to the newest map before storing the property.
1813 map = Update(isolate, map);
1815 DCHECK(!map->is_dictionary_map());
1816 return UpdateDescriptorForValue(isolate, map, descriptor, constness, value);
1819 Handle<Map> Map::TransitionToDataProperty(Isolate* isolate, Handle<Map> map,
1826 map->IsDetached(isolate)
1831 DCHECK(!map->is_dictionary_map());
1833 // Migrate to the newest map before storing the property.
1834 map = Update(isolate, map);
1837 isolate, map, *name, PropertyKind::kData, attributes);
1854 if (!map->TooManyFastProperties(store_origin)) {
1857 maybe_map = Map::CopyWithField(isolate, map, name, type, attributes,
1874 Handle<Object> maybe_constructor(map->GetConstructor(), isolate);
1875 if (FLAG_feedback_normalization && map->new_target_is_base() &&
1888 // Deoptimize all code that embeds the previous initial map.
1891 if (!result->EquivalentToForNormalization(*map,
1894 Map::Normalize(isolate, map, CLEAR_INOBJECT_PROPERTIES, reason);
1897 result = Map::Normalize(isolate, map, CLEAR_INOBJECT_PROPERTIES, reason);
1904 Handle<Map> Map::TransitionToAccessorProperty(Isolate* isolate, Handle<Map> map,
1912 map->IsDetached(isolate)
1920 // Migrate to the newest map before transitioning to the new property.
1921 map = Update(isolate, map);
1924 if (map->is_dictionary_map()) return map;
1926 PropertyNormalizationMode mode = map->is_prototype_map()
1931 isolate, map, *name, PropertyKind::kAccessor, attributes);
1945 return Map::Normalize(isolate, map, mode,
1951 return Map::Normalize(isolate, map, mode,
1959 DescriptorArray old_descriptors = map->instance_descriptors(isolate);
1961 if (descriptor != map->LastAdded()) {
1962 return Map::Normalize(isolate, map, mode, "AccessorsOverwritingNonLast");
1966 return Map::Normalize(isolate, map, mode,
1971 return Map::Normalize(isolate, map, mode, "AccessorsWithAttributes");
1977 return Map::Normalize(isolate, map, mode, "AccessorsOverwritingNonPair");
1981 if (current_pair->Equals(*getter, *setter)) return map;
1995 return Map::Normalize(isolate, map, mode,
2000 } else if (map->NumberOfOwnDescriptors() >= kMaxNumberOfDescriptors ||
2001 map->TooManyFastProperties(StoreOrigin::kNamed)) {
2002 return Map::Normalize(isolate, map, CLEAR_INOBJECT_PROPERTIES,
2014 return Map::CopyInsertDescriptor(isolate, map, &d, flag);
2017 Handle<Map> Map::CopyAddDescriptor(Isolate* isolate, Handle<Map> map,
2020 Handle<DescriptorArray> descriptors(map->instance_descriptors(isolate),
2023 // Share descriptors only if map owns descriptors and it not an initial map.
2024 if (flag == INSERT_TRANSITION && map->owns_descriptors() &&
2025 !map->GetBackPointer().IsUndefined(isolate) &&
2026 TransitionsAccessor::CanHaveMoreTransitions(isolate, map)) {
2027 return ShareDescriptor(isolate, map, descriptors, descriptor);
2030 int nof = map->NumberOfOwnDescriptors();
2035 return CopyReplaceDescriptors(isolate, map, new_descriptors, flag,
2040 Handle<Map> Map::CopyInsertDescriptor(Isolate* isolate, Handle<Map> map,
2043 Handle<DescriptorArray> old_descriptors(map->instance_descriptors(isolate),
2048 old_descriptors->SearchWithCache(isolate, *descriptor->GetKey(), *map);
2050 return CopyReplaceDescriptor(isolate, map, old_descriptors, descriptor,
2053 return CopyAddDescriptor(isolate, map, descriptor, flag);
2056 Handle<Map> Map::CopyReplaceDescriptor(Isolate* isolate, Handle<Map> map,
2070 isolate, descriptors, map->NumberOfOwnDescriptors());
2078 return CopyReplaceDescriptors(isolate, map, new_descriptors, flag, key,
2083 // For performance reasons we only hash the 2 most variable fields of a map:
2177 // Has to be an initial map.
2182 TransitionsAccessor::TraverseCallback callback = [&](Map map) {
2183 slack = std::min(slack, map.UnusedPropertyFields());
2201 Object maybe_proto_info = prototype->map().prototype_info();
2206 prototype->map().set_prototype_info(*proto_info, kReleaseStore);
2223 void Map::SetShouldBeFastPrototypeMap(Handle<Map> map, bool value,
2225 if (value == false && !map->prototype_info().IsPrototypeInfo()) {
2229 GetOrCreatePrototypeInfo(map, isolate)->set_should_be_fast_map(value);
2233 Handle<Object> Map::GetOrCreatePrototypeChainValidityCell(Handle<Map> map,
2236 if (map->IsJSGlobalObjectMap()) {
2237 DCHECK(map->is_prototype_map());
2243 handle(map->GetPrototypeChainRootMap(isolate).prototype(), isolate);
2251 JSObject::LazyRegisterPrototypeUser(handle(prototype->map(), isolate),
2254 Object maybe_cell = prototype->map().prototype_validity_cell();
2265 prototype->map().set_prototype_validity_cell(*cell);
2270 bool Map::IsPrototypeChainInvalidated(Map map) {
2271 DCHECK(map.is_prototype_map());
2272 Object maybe_cell = map.prototype_validity_cell();
2281 void Map::SetPrototype(Isolate* isolate, Handle<Map> map,
2295 map->set_prototype(*prototype, wb_mode);
2304 Handle<Map> Map::TransitionToPrototype(Isolate* isolate, Handle<Map> map,
2307 TransitionsAccessor::GetPrototypeTransition(isolate, map, prototype);
2309 new_map = Copy(isolate, map, "TransitionToPrototype");
2310 TransitionsAccessor::PutPrototypeTransition(isolate, map, prototype,