Skip to content

Commit 8e3ae62

Browse files
LeszekSwirskiCommit Bot
authored andcommitted
[map] Try to in-place transition during map update
When searching for a target map during map update, attempt to update field representations in-place to the more general representation, where possible. Bug: chromium:1143772 Change-Id: I6a43c94910a1d2d8f8b0ad89048f94b51461f76c Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2507715 Commit-Queue: Leszek Swirski <[email protected]> Commit-Queue: Igor Sheludko <[email protected]> Reviewed-by: Igor Sheludko <[email protected]> Auto-Submit: Leszek Swirski <[email protected]> Cr-Commit-Position: refs/heads/master@{#70887}
1 parent 95e1fa5 commit 8e3ae62

4 files changed

Lines changed: 124 additions & 27 deletions

File tree

src/objects/map-updater.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,17 @@ MapUpdater::State MapUpdater::FindTargetMap() {
402402
}
403403
Representation tmp_representation = tmp_details.representation();
404404
if (!old_details.representation().fits_into(tmp_representation)) {
405-
break;
405+
// Try updating the field in-place to a generalized type.
406+
Representation generalized =
407+
tmp_representation.generalize(old_details.representation());
408+
if (!tmp_representation.CanBeInPlaceChangedTo(generalized)) {
409+
break;
410+
}
411+
Handle<Map> field_owner(tmp_map->FindFieldOwner(isolate_, i), isolate_);
412+
tmp_representation = generalized;
413+
GeneralizeField(field_owner, i, tmp_details.constness(),
414+
tmp_representation,
415+
handle(tmp_descriptors->GetFieldType(i), isolate_));
406416
}
407417

408418
if (tmp_details.location() == kField) {

src/objects/map.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ void Map::DeprecateTransitionTree(Isolate* isolate) {
610610
transitions.GetTarget(i).DeprecateTransitionTree(isolate);
611611
}
612612
DCHECK(!constructor_or_backpointer().IsFunctionTemplateInfo());
613+
DCHECK(CanBeDeprecated());
613614
set_is_deprecated(true);
614615
if (FLAG_trace_maps) {
615616
LOG(isolate, MapEvent("Deprecate", handle(*this, isolate), Handle<Map>()));

test/cctest/test-field-type-tracking.cc

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,8 @@ namespace {
10401040
// where "p2A" and "p2B" differ only in the attributes.
10411041
//
10421042
void TestReconfigureDataFieldAttribute_GeneralizeField(
1043-
const CRFTData& from, const CRFTData& to, const CRFTData& expected) {
1043+
const CRFTData& from, const CRFTData& to, const CRFTData& expected,
1044+
bool expected_deprecation) {
10441045
Isolate* isolate = CcTest::i_isolate();
10451046

10461047
Expectations expectations(isolate);
@@ -1109,24 +1110,29 @@ void TestReconfigureDataFieldAttribute_GeneralizeField(
11091110
CHECK_NE(*map2, *new_map);
11101111
CHECK(expectations2.Check(*map2));
11111112

1112-
// |map| should be deprecated and |new_map| should match new expectations.
11131113
for (int i = kSplitProp; i < kPropCount; i++) {
11141114
expectations.SetDataField(i, expected.constness, expected.representation,
11151115
expected.type);
11161116
}
1117-
CHECK(map->is_deprecated());
1118-
CHECK(!code_field_type->marked_for_deoptimization());
1119-
CHECK(!code_field_repr->marked_for_deoptimization());
1120-
CHECK(!code_field_const->marked_for_deoptimization());
1121-
CHECK_NE(*map, *new_map);
1117+
if (expected_deprecation) {
1118+
// |map| should be deprecated and |new_map| should match new expectations.
1119+
CHECK(map->is_deprecated());
1120+
CHECK(!code_field_type->marked_for_deoptimization());
1121+
CHECK(!code_field_repr->marked_for_deoptimization());
1122+
CHECK(!code_field_const->marked_for_deoptimization());
1123+
CHECK_NE(*map, *new_map);
11221124

1123-
CHECK(!new_map->is_deprecated());
1124-
CHECK(expectations.Check(*new_map));
1125+
CHECK(!new_map->is_deprecated());
1126+
CHECK(expectations.Check(*new_map));
11251127

1126-
// Update deprecated |map|, it should become |new_map|.
1127-
Handle<Map> updated_map = Map::Update(isolate, map);
1128-
CHECK_EQ(*new_map, *updated_map);
1129-
CheckMigrationTarget(isolate, *map, *updated_map);
1128+
// Update deprecated |map|, it should become |new_map|.
1129+
Handle<Map> updated_map = Map::Update(isolate, map);
1130+
CHECK_EQ(*new_map, *updated_map);
1131+
CheckMigrationTarget(isolate, *map, *updated_map);
1132+
} else {
1133+
CHECK(!map->is_deprecated());
1134+
CHECK(expectations.Check(*map));
1135+
}
11301136
}
11311137

11321138
// This test ensures that trivial field generalization (from HeapObject to
@@ -1242,22 +1248,22 @@ TEST(ReconfigureDataFieldAttribute_GeneralizeSmiFieldToDouble) {
12421248
TestReconfigureDataFieldAttribute_GeneralizeField(
12431249
{PropertyConstness::kConst, Representation::Smi(), any_type},
12441250
{PropertyConstness::kConst, Representation::Double(), any_type},
1245-
{PropertyConstness::kConst, Representation::Double(), any_type});
1251+
{PropertyConstness::kConst, Representation::Double(), any_type}, true);
12461252

12471253
TestReconfigureDataFieldAttribute_GeneralizeField(
12481254
{PropertyConstness::kConst, Representation::Smi(), any_type},
12491255
{PropertyConstness::kMutable, Representation::Double(), any_type},
1250-
{PropertyConstness::kMutable, Representation::Double(), any_type});
1256+
{PropertyConstness::kMutable, Representation::Double(), any_type}, true);
12511257

12521258
TestReconfigureDataFieldAttribute_GeneralizeField(
12531259
{PropertyConstness::kMutable, Representation::Smi(), any_type},
12541260
{PropertyConstness::kConst, Representation::Double(), any_type},
1255-
{PropertyConstness::kMutable, Representation::Double(), any_type});
1261+
{PropertyConstness::kMutable, Representation::Double(), any_type}, true);
12561262

12571263
TestReconfigureDataFieldAttribute_GeneralizeField(
12581264
{PropertyConstness::kMutable, Representation::Smi(), any_type},
12591265
{PropertyConstness::kMutable, Representation::Double(), any_type},
1260-
{PropertyConstness::kMutable, Representation::Double(), any_type});
1266+
{PropertyConstness::kMutable, Representation::Double(), any_type}, true);
12611267
}
12621268

12631269
TEST(ReconfigureDataFieldAttribute_GeneralizeSmiFieldToTagged) {
@@ -1272,22 +1278,26 @@ TEST(ReconfigureDataFieldAttribute_GeneralizeSmiFieldToTagged) {
12721278
TestReconfigureDataFieldAttribute_GeneralizeField(
12731279
{PropertyConstness::kConst, Representation::Smi(), any_type},
12741280
{PropertyConstness::kConst, Representation::HeapObject(), value_type},
1275-
{PropertyConstness::kConst, Representation::Tagged(), any_type});
1281+
{PropertyConstness::kConst, Representation::Tagged(), any_type},
1282+
!FLAG_modify_field_representation_inplace);
12761283

12771284
TestReconfigureDataFieldAttribute_GeneralizeField(
12781285
{PropertyConstness::kConst, Representation::Smi(), any_type},
12791286
{PropertyConstness::kMutable, Representation::HeapObject(), value_type},
1280-
{PropertyConstness::kMutable, Representation::Tagged(), any_type});
1287+
{PropertyConstness::kMutable, Representation::Tagged(), any_type},
1288+
!FLAG_modify_field_representation_inplace);
12811289

12821290
TestReconfigureDataFieldAttribute_GeneralizeField(
12831291
{PropertyConstness::kMutable, Representation::Smi(), any_type},
12841292
{PropertyConstness::kConst, Representation::HeapObject(), value_type},
1285-
{PropertyConstness::kMutable, Representation::Tagged(), any_type});
1293+
{PropertyConstness::kMutable, Representation::Tagged(), any_type},
1294+
!FLAG_modify_field_representation_inplace);
12861295

12871296
TestReconfigureDataFieldAttribute_GeneralizeField(
12881297
{PropertyConstness::kMutable, Representation::Smi(), any_type},
12891298
{PropertyConstness::kMutable, Representation::HeapObject(), value_type},
1290-
{PropertyConstness::kMutable, Representation::Tagged(), any_type});
1299+
{PropertyConstness::kMutable, Representation::Tagged(), any_type},
1300+
!FLAG_modify_field_representation_inplace);
12911301
}
12921302

12931303
TEST(ReconfigureDataFieldAttribute_GeneralizeDoubleFieldToTagged) {
@@ -1302,22 +1312,26 @@ TEST(ReconfigureDataFieldAttribute_GeneralizeDoubleFieldToTagged) {
13021312
TestReconfigureDataFieldAttribute_GeneralizeField(
13031313
{PropertyConstness::kConst, Representation::Double(), any_type},
13041314
{PropertyConstness::kConst, Representation::HeapObject(), value_type},
1305-
{PropertyConstness::kConst, Representation::Tagged(), any_type});
1315+
{PropertyConstness::kConst, Representation::Tagged(), any_type},
1316+
FLAG_unbox_double_fields || !FLAG_modify_field_representation_inplace);
13061317

13071318
TestReconfigureDataFieldAttribute_GeneralizeField(
13081319
{PropertyConstness::kConst, Representation::Double(), any_type},
13091320
{PropertyConstness::kMutable, Representation::HeapObject(), value_type},
1310-
{PropertyConstness::kMutable, Representation::Tagged(), any_type});
1321+
{PropertyConstness::kMutable, Representation::Tagged(), any_type},
1322+
FLAG_unbox_double_fields || !FLAG_modify_field_representation_inplace);
13111323

13121324
TestReconfigureDataFieldAttribute_GeneralizeField(
13131325
{PropertyConstness::kMutable, Representation::Double(), any_type},
13141326
{PropertyConstness::kConst, Representation::HeapObject(), value_type},
1315-
{PropertyConstness::kMutable, Representation::Tagged(), any_type});
1327+
{PropertyConstness::kMutable, Representation::Tagged(), any_type},
1328+
FLAG_unbox_double_fields || !FLAG_modify_field_representation_inplace);
13161329

13171330
TestReconfigureDataFieldAttribute_GeneralizeField(
13181331
{PropertyConstness::kMutable, Representation::Double(), any_type},
13191332
{PropertyConstness::kMutable, Representation::HeapObject(), value_type},
1320-
{PropertyConstness::kMutable, Representation::Tagged(), any_type});
1333+
{PropertyConstness::kMutable, Representation::Tagged(), any_type},
1334+
FLAG_unbox_double_fields || !FLAG_modify_field_representation_inplace);
13211335
}
13221336

13231337
TEST(ReconfigureDataFieldAttribute_GeneralizeHeapObjFieldToHeapObj) {
@@ -1403,7 +1417,8 @@ TEST(ReconfigureDataFieldAttribute_GeneralizeHeapObjectFieldToTagged) {
14031417
TestReconfigureDataFieldAttribute_GeneralizeField(
14041418
{PropertyConstness::kMutable, Representation::HeapObject(), value_type},
14051419
{PropertyConstness::kMutable, Representation::Smi(), any_type},
1406-
{PropertyConstness::kMutable, Representation::Tagged(), any_type});
1420+
{PropertyConstness::kMutable, Representation::Tagged(), any_type},
1421+
!FLAG_modify_field_representation_inplace);
14071422
}
14081423

14091424
// Checks that given |map| is deprecated and that it updates to given |new_map|
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright 2020 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+
// Flags: --allow-natives-syntax
6+
7+
(function() {
8+
// Only run this test if doubles are transitioned in-place to tagged.
9+
let x = {};
10+
x.a = 0.1;
11+
let y = {};
12+
y.a = {};
13+
if (!%HaveSameMap(x, y)) return;
14+
15+
// m1: {}
16+
let m1 = {};
17+
18+
// m2: {a:d}
19+
let m2 = {};
20+
assertTrue(%HaveSameMap(m2, m1));
21+
m2.a = 13.37;
22+
23+
// m3: {a:d, b:s}
24+
let m3 = {};
25+
m3.a = 13.37;
26+
assertTrue(%HaveSameMap(m3, m2));
27+
m3.b = 1;
28+
29+
// m4: {a:d, b:s, c:h}
30+
let m4 = {};
31+
m4.a = 13.37;
32+
m4.b = 1;
33+
assertTrue(%HaveSameMap(m4, m3));
34+
m4.c = {};
35+
36+
// m4_2 == m4
37+
let m4_2 = {};
38+
m4_2.a = 13.37;
39+
m4_2.b = 1;
40+
m4_2.c = {};
41+
assertTrue(%HaveSameMap(m4_2, m4));
42+
43+
// m5: {a:d, b:d}
44+
let m5 = {};
45+
m5.a = 13.37;
46+
assertTrue(%HaveSameMap(m5, m2));
47+
m5.b = 13.37;
48+
assertFalse(%HaveSameMap(m5, m3));
49+
50+
// At this point, Map3 and Map4 are both deprecated. Map2 transitions to
51+
// Map5. Map5 is the migration target for Map3.
52+
assertFalse(%HaveSameMap(m5, m3));
53+
54+
// m6: {a:d, b:d, c:d}
55+
let m6 = {};
56+
m6.a = 13.37;
57+
assertTrue(%HaveSameMap(m6, m2));
58+
m6.b = 13.37;
59+
assertTrue(%HaveSameMap(m6, m5));
60+
m6.c = 13.37
61+
62+
// Make m7: {a:d, b:d, c:t}
63+
let m7 = m4_2;
64+
assertTrue(%HaveSameMap(m7, m4));
65+
// Map4 is deprecated, so this property access triggers a Map migration.
66+
// With in-place map updates and no double unboxing, this should end up
67+
// migrating to Map6, and updating it in-place.
68+
m7.c;
69+
assertFalse(%HaveSameMap(m7, m4));
70+
assertTrue(%HaveSameMap(m6, m7));
71+
})();

0 commit comments

Comments
 (0)