diff --git a/src/objects/js-objects.cc b/src/objects/js-objects.cc index f7d8888b29..01df8e1524 100644 --- a/src/objects/js-objects.cc +++ b/src/objects/js-objects.cc @@ -29,6 +29,7 @@ #include "src/objects/js-array-buffer-inl.h" #include "src/objects/js-array-inl.h" #include "src/objects/lookup.h" +#include "src/objects/map-updater.h" #include "src/objects/objects-inl.h" #ifdef V8_INTL_SUPPORT #include "src/objects/js-break-iterator.h" @@ -3151,6 +3152,7 @@ void JSObject::AllocateStorageForMap(Handle object, Handle map) { DCHECK(object->map().GetInObjectProperties() == map->GetInObjectProperties()); ElementsKind obj_kind = object->map().elements_kind(); ElementsKind map_kind = map->elements_kind(); + Isolate* isolate = object->GetIsolate(); if (map_kind != obj_kind) { ElementsKind to_kind = GetMoreGeneralElementsKind(map_kind, obj_kind); if (IsDictionaryElementsKind(obj_kind)) { @@ -3161,7 +3163,7 @@ void JSObject::AllocateStorageForMap(Handle object, Handle map) { } else { TransitionElementsKind(object, to_kind); } - map = Map::ReconfigureElementsKind(object->GetIsolate(), map, to_kind); + map = MapUpdater{isolate, map}.ReconfigureElementsKind(to_kind); } int number_of_fields = map->NumberOfFields(); int inobject = map->GetInObjectProperties(); @@ -3171,7 +3173,6 @@ void JSObject::AllocateStorageForMap(Handle object, Handle map) { // Allocate mutable double boxes if necessary. It is always necessary if we // have external properties, but is also necessary if we only have inobject // properties but don't unbox double fields. - Isolate* isolate = object->GetIsolate(); Handle descriptors(map->instance_descriptors(isolate), isolate); diff --git a/src/objects/map-updater.h b/src/objects/map-updater.h index 4fbf9a72dc..c3283c68b0 100644 --- a/src/objects/map-updater.h +++ b/src/objects/map-updater.h @@ -47,7 +47,7 @@ namespace internal { // - Otherwise, invalidate the outdated transition target from |target_map|, and // replace its transition tree with a new branch for the updated descriptors. // - If the |old_map| had integrity level transition, create the new map for it. -class MapUpdater { +class V8_EXPORT_PRIVATE MapUpdater { public: MapUpdater(Isolate* isolate, Handle old_map); diff --git a/src/objects/map.cc b/src/objects/map.cc index 9c073c1956..0f281519b7 100644 --- a/src/objects/map.cc +++ b/src/objects/map.cc @@ -806,29 +806,6 @@ void Map::GeneralizeField(Isolate* isolate, Handle map, } } -// TODO(ishell): remove. -// static -Handle Map::ReconfigureProperty(Isolate* isolate, Handle map, - InternalIndex modify_index, - PropertyKind new_kind, - PropertyAttributes new_attributes, - Representation new_representation, - Handle new_field_type) { - DCHECK_EQ(kData, new_kind); // Only kData case is supported. - MapUpdater mu(isolate, map); - return mu.ReconfigureToDataField(modify_index, new_attributes, - PropertyConstness::kConst, - new_representation, new_field_type); -} - -// TODO(ishell): remove. -// static -Handle Map::ReconfigureElementsKind(Isolate* isolate, Handle map, - ElementsKind new_elements_kind) { - MapUpdater mu(isolate, map); - return mu.ReconfigureElementsKind(new_elements_kind); -} - namespace { Map SearchMigrationTarget(Isolate* isolate, Map old_map) { @@ -1324,7 +1301,7 @@ Handle Map::TransitionElementsTo(Isolate* isolate, Handle map, return Map::CopyAsElementsKind(isolate, map, to_kind, OMIT_TRANSITION); } - return Map::ReconfigureElementsKind(isolate, map, to_kind); + return MapUpdater{isolate, map}.ReconfigureElementsKind(to_kind); } static Handle AddMissingElementsTransitions(Isolate* isolate, diff --git a/src/objects/map.h b/src/objects/map.h index 6eeb68d2cc..5cf44a1b75 100644 --- a/src/objects/map.h +++ b/src/objects/map.h @@ -512,14 +512,6 @@ class Map : public HeapObject { Isolate* isolate, InstanceType instance_type, Representation* representation, Handle* field_type); - V8_EXPORT_PRIVATE static Handle ReconfigureProperty( - Isolate* isolate, Handle map, InternalIndex modify_index, - PropertyKind new_kind, PropertyAttributes new_attributes, - Representation new_representation, Handle new_field_type); - - V8_EXPORT_PRIVATE static Handle ReconfigureElementsKind( - Isolate* isolate, Handle map, ElementsKind new_elements_kind); - V8_EXPORT_PRIVATE static Handle PrepareForDataProperty( Isolate* isolate, Handle old_map, InternalIndex descriptor_number, PropertyConstness constness, Handle value); diff --git a/test/cctest/test-field-type-tracking.cc b/test/cctest/test-field-type-tracking.cc index d48db140c7..2565507ce2 100644 --- a/test/cctest/test-field-type-tracking.cc +++ b/test/cctest/test-field-type-tracking.cc @@ -14,6 +14,7 @@ #include "src/init/v8.h" #include "src/objects/field-type.h" #include "src/objects/heap-number-inl.h" +#include "src/objects/map-updater.h" #include "src/objects/objects-inl.h" #include "src/objects/property.h" #include "src/objects/struct-inl.h" @@ -461,6 +462,23 @@ class Expectations { // branch. // +namespace { + +Handle ReconfigureProperty(Isolate* isolate, Handle map, + InternalIndex modify_index, + PropertyKind new_kind, + PropertyAttributes new_attributes, + Representation new_representation, + Handle new_field_type) { + DCHECK_EQ(kData, new_kind); // Only kData case is supported. + MapUpdater mu(isolate, map); + return mu.ReconfigureToDataField(modify_index, new_attributes, + PropertyConstness::kConst, + new_representation, new_field_type); +} + +} // namespace + TEST(ReconfigureAccessorToNonExistingDataField) { CcTest::InitializeVM(); v8::HandleScope scope(CcTest::isolate()); @@ -482,8 +500,8 @@ TEST(ReconfigureAccessorToNonExistingDataField) { CHECK(expectations.Check(*map)); InternalIndex first(0); - Handle new_map = Map::ReconfigureProperty( - isolate, map, first, kData, NONE, Representation::None(), none_type); + Handle new_map = ReconfigureProperty(isolate, map, first, kData, NONE, + Representation::None(), none_type); // |map| did not change except marked unstable. CHECK(!map->is_deprecated()); CHECK(!map->is_stable()); @@ -497,8 +515,8 @@ TEST(ReconfigureAccessorToNonExistingDataField) { CHECK(new_map->is_stable()); CHECK(expectations.Check(*new_map)); - Handle new_map2 = Map::ReconfigureProperty( - isolate, map, first, kData, NONE, Representation::None(), none_type); + Handle new_map2 = ReconfigureProperty(isolate, map, first, kData, NONE, + Representation::None(), none_type); CHECK_EQ(*new_map, *new_map2); Handle value(Smi::zero(), isolate); @@ -670,7 +688,7 @@ void TestGeneralizeField(int detach_property_at_index, int property_index, CHECK(expectations.Check(*map)); if (is_detached_map) { - detach_point_map = Map::ReconfigureProperty( + detach_point_map = ReconfigureProperty( isolate, detach_point_map, InternalIndex(detach_property_at_index), kData, NONE, Representation::Double(), any_type); expectations.SetDataField(detach_property_at_index, @@ -703,8 +721,8 @@ void TestGeneralizeField(int detach_property_at_index, int property_index, // Create new maps by generalizing representation of propX field. Handle new_map = - Map::ReconfigureProperty(isolate, map, InternalIndex(property_index), - kData, NONE, to.representation, to.type); + ReconfigureProperty(isolate, map, InternalIndex(property_index), kData, + NONE, to.representation, to.type); expectations.SetDataField(property_index, expected.constness, expected.representation, expected.type); @@ -978,8 +996,8 @@ TEST(GeneralizeFieldWithAccessorProperties) { continue; } Handle new_map = - Map::ReconfigureProperty(isolate, map, InternalIndex(i), kData, NONE, - Representation::Double(), any_type); + ReconfigureProperty(isolate, map, InternalIndex(i), kData, NONE, + Representation::Double(), any_type); maps[i] = new_map; expectations.SetDataField(i, PropertyConstness::kMutable, @@ -1798,7 +1816,7 @@ static void TestReconfigureElementsKind_GeneralizeFieldInPlace( // Reconfigure elements kinds of |map2|, which should generalize // representations in |map|. Handle new_map = - Map::ReconfigureElementsKind(isolate, map2, PACKED_ELEMENTS); + MapUpdater{isolate, map2}.ReconfigureElementsKind(PACKED_ELEMENTS); // |map2| should be left unchanged but marked unstable. CHECK(!map2->is_stable()); @@ -2064,9 +2082,8 @@ TEST(ReconfigurePropertySplitMapTransitionsOverflow) { map2 = handle(target, isolate); } - map2 = Map::ReconfigureProperty(isolate, map2, InternalIndex(kSplitProp), - kData, NONE, Representation::Double(), - any_type); + map2 = ReconfigureProperty(isolate, map2, InternalIndex(kSplitProp), kData, + NONE, Representation::Double(), any_type); expectations.SetDataField(kSplitProp, PropertyConstness::kMutable, Representation::Double(), any_type); @@ -2163,8 +2180,8 @@ static void TestGeneralizeFieldWithSpecialTransition( Handle maps[kPropCount]; for (int i = 0; i < kPropCount; i++) { Handle new_map = - Map::ReconfigureProperty(isolate, map, InternalIndex(i), kData, NONE, - to.representation, to.type); + ReconfigureProperty(isolate, map, InternalIndex(i), kData, NONE, + to.representation, to.type); maps[i] = new_map; expectations.SetDataField(i, expected.constness, expected.representation,