Skip to content

Commit df2459d

Browse files
committed
deps: V8: cherry-pick 3ba21a17ce2f
Original commit message: Merged: [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 No-Try: true No-Presubmit: true No-Tree-Checks: true [email protected], [email protected] (cherry picked from commit 8e3ae62d294818733a0322d8e8abd53d4e410f19) Change-Id: I659890c2f08c14d1cf94242fb875c19837df2dbb Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2509599 Reviewed-by: Francis McCabe <[email protected]> Reviewed-by: Michael Hablich <[email protected]> Reviewed-by: Bill Budge <[email protected]> Reviewed-by: Igor Sheludko <[email protected]> Cr-Commit-Position: refs/branch-heads/8.6@{nodejs#44} Cr-Branched-From: a64aed2333abf49e494d2a5ce24bbd14fff19f60-refs/heads/8.6.395@{#1} Cr-Branched-From: a626bc036236c9bf92ac7b87dc40c9e538b087e3-refs/heads/master@{#69472} Refs: v8/v8@3ba21a1
1 parent 3936f4f commit df2459d

File tree

5 files changed

+125
-28
lines changed

5 files changed

+125
-28
lines changed

common.gypi

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
# Reset this number to 0 on major V8 upgrades.
3838
# Increment by one for each non-official patch applied to deps/v8.
39-
'v8_embedder_string': '-node.37',
39+
'v8_embedder_string': '-node.38',
4040

4141
##### V8 defaults for Node.js #####
4242

deps/v8/src/objects/map-updater.cc

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

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

deps/v8/src/objects/map.cc

+1
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>()));

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

+41-26
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,8 @@ namespace {
10521052
// where "p2A" and "p2B" differ only in the attributes.
10531053
//
10541054
void TestReconfigureDataFieldAttribute_GeneralizeField(
1055-
const CRFTData& from, const CRFTData& to, const CRFTData& expected) {
1055+
const CRFTData& from, const CRFTData& to, const CRFTData& expected,
1056+
bool expected_deprecation) {
10561057
Isolate* isolate = CcTest::i_isolate();
10571058

10581059
Expectations expectations(isolate);
@@ -1121,24 +1122,29 @@ void TestReconfigureDataFieldAttribute_GeneralizeField(
11211122
CHECK_NE(*map2, *new_map);
11221123
CHECK(expectations2.Check(*map2));
11231124

1124-
// |map| should be deprecated and |new_map| should match new expectations.
11251125
for (int i = kSplitProp; i < kPropCount; i++) {
11261126
expectations.SetDataField(i, expected.constness, expected.representation,
11271127
expected.type);
11281128
}
1129-
CHECK(map->is_deprecated());
1130-
CHECK(!code_field_type->marked_for_deoptimization());
1131-
CHECK(!code_field_repr->marked_for_deoptimization());
1132-
CHECK(!code_field_const->marked_for_deoptimization());
1133-
CHECK_NE(*map, *new_map);
1129+
if (expected_deprecation) {
1130+
// |map| should be deprecated and |new_map| should match new expectations.
1131+
CHECK(map->is_deprecated());
1132+
CHECK(!code_field_type->marked_for_deoptimization());
1133+
CHECK(!code_field_repr->marked_for_deoptimization());
1134+
CHECK(!code_field_const->marked_for_deoptimization());
1135+
CHECK_NE(*map, *new_map);
11341136

1135-
CHECK(!new_map->is_deprecated());
1136-
CHECK(expectations.Check(*new_map));
1137+
CHECK(!new_map->is_deprecated());
1138+
CHECK(expectations.Check(*new_map));
11371139

1138-
// Update deprecated |map|, it should become |new_map|.
1139-
Handle<Map> updated_map = Map::Update(isolate, map);
1140-
CHECK_EQ(*new_map, *updated_map);
1141-
CheckMigrationTarget(isolate, *map, *updated_map);
1140+
// Update deprecated |map|, it should become |new_map|.
1141+
Handle<Map> updated_map = Map::Update(isolate, map);
1142+
CHECK_EQ(*new_map, *updated_map);
1143+
CheckMigrationTarget(isolate, *map, *updated_map);
1144+
} else {
1145+
CHECK(!map->is_deprecated());
1146+
CHECK(expectations.Check(*map));
1147+
}
11421148
}
11431149

11441150
// This test ensures that trivial field generalization (from HeapObject to
@@ -1254,22 +1260,22 @@ TEST(ReconfigureDataFieldAttribute_GeneralizeSmiFieldToDouble) {
12541260
TestReconfigureDataFieldAttribute_GeneralizeField(
12551261
{PropertyConstness::kConst, Representation::Smi(), any_type},
12561262
{PropertyConstness::kConst, Representation::Double(), any_type},
1257-
{PropertyConstness::kConst, Representation::Double(), any_type});
1263+
{PropertyConstness::kConst, Representation::Double(), any_type}, true);
12581264

12591265
TestReconfigureDataFieldAttribute_GeneralizeField(
12601266
{PropertyConstness::kConst, Representation::Smi(), any_type},
12611267
{PropertyConstness::kMutable, Representation::Double(), any_type},
1262-
{PropertyConstness::kMutable, Representation::Double(), any_type});
1268+
{PropertyConstness::kMutable, Representation::Double(), any_type}, true);
12631269

12641270
TestReconfigureDataFieldAttribute_GeneralizeField(
12651271
{PropertyConstness::kMutable, Representation::Smi(), any_type},
12661272
{PropertyConstness::kConst, Representation::Double(), any_type},
1267-
{PropertyConstness::kMutable, Representation::Double(), any_type});
1273+
{PropertyConstness::kMutable, Representation::Double(), any_type}, true);
12681274

12691275
TestReconfigureDataFieldAttribute_GeneralizeField(
12701276
{PropertyConstness::kMutable, Representation::Smi(), any_type},
12711277
{PropertyConstness::kMutable, Representation::Double(), any_type},
1272-
{PropertyConstness::kMutable, Representation::Double(), any_type});
1278+
{PropertyConstness::kMutable, Representation::Double(), any_type}, true);
12731279
}
12741280

12751281
TEST(ReconfigureDataFieldAttribute_GeneralizeSmiFieldToTagged) {
@@ -1284,22 +1290,26 @@ TEST(ReconfigureDataFieldAttribute_GeneralizeSmiFieldToTagged) {
12841290
TestReconfigureDataFieldAttribute_GeneralizeField(
12851291
{PropertyConstness::kConst, Representation::Smi(), any_type},
12861292
{PropertyConstness::kConst, Representation::HeapObject(), value_type},
1287-
{PropertyConstness::kConst, Representation::Tagged(), any_type});
1293+
{PropertyConstness::kConst, Representation::Tagged(), any_type},
1294+
!FLAG_modify_field_representation_inplace);
12881295

12891296
TestReconfigureDataFieldAttribute_GeneralizeField(
12901297
{PropertyConstness::kConst, Representation::Smi(), any_type},
12911298
{PropertyConstness::kMutable, Representation::HeapObject(), value_type},
1292-
{PropertyConstness::kMutable, Representation::Tagged(), any_type});
1299+
{PropertyConstness::kMutable, Representation::Tagged(), any_type},
1300+
!FLAG_modify_field_representation_inplace);
12931301

12941302
TestReconfigureDataFieldAttribute_GeneralizeField(
12951303
{PropertyConstness::kMutable, Representation::Smi(), any_type},
12961304
{PropertyConstness::kConst, Representation::HeapObject(), value_type},
1297-
{PropertyConstness::kMutable, Representation::Tagged(), any_type});
1305+
{PropertyConstness::kMutable, Representation::Tagged(), any_type},
1306+
!FLAG_modify_field_representation_inplace);
12981307

12991308
TestReconfigureDataFieldAttribute_GeneralizeField(
13001309
{PropertyConstness::kMutable, Representation::Smi(), any_type},
13011310
{PropertyConstness::kMutable, Representation::HeapObject(), value_type},
1302-
{PropertyConstness::kMutable, Representation::Tagged(), any_type});
1311+
{PropertyConstness::kMutable, Representation::Tagged(), any_type},
1312+
!FLAG_modify_field_representation_inplace);
13031313
}
13041314

13051315
TEST(ReconfigureDataFieldAttribute_GeneralizeDoubleFieldToTagged) {
@@ -1314,22 +1324,26 @@ TEST(ReconfigureDataFieldAttribute_GeneralizeDoubleFieldToTagged) {
13141324
TestReconfigureDataFieldAttribute_GeneralizeField(
13151325
{PropertyConstness::kConst, Representation::Double(), any_type},
13161326
{PropertyConstness::kConst, Representation::HeapObject(), value_type},
1317-
{PropertyConstness::kConst, Representation::Tagged(), any_type});
1327+
{PropertyConstness::kConst, Representation::Tagged(), any_type},
1328+
FLAG_unbox_double_fields || !FLAG_modify_field_representation_inplace);
13181329

13191330
TestReconfigureDataFieldAttribute_GeneralizeField(
13201331
{PropertyConstness::kConst, Representation::Double(), any_type},
13211332
{PropertyConstness::kMutable, Representation::HeapObject(), value_type},
1322-
{PropertyConstness::kMutable, Representation::Tagged(), any_type});
1333+
{PropertyConstness::kMutable, Representation::Tagged(), any_type},
1334+
FLAG_unbox_double_fields || !FLAG_modify_field_representation_inplace);
13231335

13241336
TestReconfigureDataFieldAttribute_GeneralizeField(
13251337
{PropertyConstness::kMutable, Representation::Double(), any_type},
13261338
{PropertyConstness::kConst, Representation::HeapObject(), value_type},
1327-
{PropertyConstness::kMutable, Representation::Tagged(), any_type});
1339+
{PropertyConstness::kMutable, Representation::Tagged(), any_type},
1340+
FLAG_unbox_double_fields || !FLAG_modify_field_representation_inplace);
13281341

13291342
TestReconfigureDataFieldAttribute_GeneralizeField(
13301343
{PropertyConstness::kMutable, Representation::Double(), any_type},
13311344
{PropertyConstness::kMutable, Representation::HeapObject(), value_type},
1332-
{PropertyConstness::kMutable, Representation::Tagged(), any_type});
1345+
{PropertyConstness::kMutable, Representation::Tagged(), any_type},
1346+
FLAG_unbox_double_fields || !FLAG_modify_field_representation_inplace);
13331347
}
13341348

13351349
TEST(ReconfigureDataFieldAttribute_GeneralizeHeapObjFieldToHeapObj) {
@@ -1415,7 +1429,8 @@ TEST(ReconfigureDataFieldAttribute_GeneralizeHeapObjectFieldToTagged) {
14151429
TestReconfigureDataFieldAttribute_GeneralizeField(
14161430
{PropertyConstness::kMutable, Representation::HeapObject(), value_type},
14171431
{PropertyConstness::kMutable, Representation::Smi(), any_type},
1418-
{PropertyConstness::kMutable, Representation::Tagged(), any_type});
1432+
{PropertyConstness::kMutable, Representation::Tagged(), any_type},
1433+
!FLAG_modify_field_representation_inplace);
14191434
}
14201435

14211436
// Checks that given |map| is deprecated and that it updates to given |new_map|
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)