OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/bailout-reason.h" | 7 #include "src/bailout-reason.h" |
8 #include "src/code-stubs.h" | 8 #include "src/code-stubs.h" |
9 #include "src/field-index.h" | 9 #include "src/field-index.h" |
10 #include "src/hydrogen.h" | 10 #include "src/hydrogen.h" |
(...skipping 1306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1317 StoreGlobalStub* stub = casted_stub(); | 1317 StoreGlobalStub* stub = casted_stub(); |
1318 HParameter* value = GetParameter(StoreDescriptor::kValueIndex); | 1318 HParameter* value = GetParameter(StoreDescriptor::kValueIndex); |
1319 if (stub->check_global()) { | 1319 if (stub->check_global()) { |
1320 // Check that the map of the global has not changed: use a placeholder map | 1320 // Check that the map of the global has not changed: use a placeholder map |
1321 // that will be replaced later with the global object's map. | 1321 // that will be replaced later with the global object's map. |
1322 HParameter* proxy = GetParameter(StoreDescriptor::kReceiverIndex); | 1322 HParameter* proxy = GetParameter(StoreDescriptor::kReceiverIndex); |
1323 HValue* proxy_map = | 1323 HValue* proxy_map = |
1324 Add<HLoadNamedField>(proxy, nullptr, HObjectAccess::ForMap()); | 1324 Add<HLoadNamedField>(proxy, nullptr, HObjectAccess::ForMap()); |
1325 HValue* global = | 1325 HValue* global = |
1326 Add<HLoadNamedField>(proxy_map, nullptr, HObjectAccess::ForPrototype()); | 1326 Add<HLoadNamedField>(proxy_map, nullptr, HObjectAccess::ForPrototype()); |
1327 Handle<Map> placeholder_map = isolate()->factory()->meta_map(); | 1327 HValue* map_cell = Add<HConstant>(isolate()->factory()->NewWeakCell( |
1328 HValue* cell = Add<HConstant>(Map::WeakCellForMap(placeholder_map)); | 1328 StoreGlobalStub::global_map_placeholder(isolate()))); |
1329 HValue* expected_map = | 1329 HValue* expected_map = Add<HLoadNamedField>( |
1330 Add<HLoadNamedField>(cell, nullptr, HObjectAccess::ForWeakCellValue()); | 1330 map_cell, nullptr, HObjectAccess::ForWeakCellValue()); |
1331 HValue* map = | 1331 HValue* map = |
1332 Add<HLoadNamedField>(global, nullptr, HObjectAccess::ForMap()); | 1332 Add<HLoadNamedField>(global, nullptr, HObjectAccess::ForMap()); |
1333 IfBuilder map_check(this); | 1333 IfBuilder map_check(this); |
1334 map_check.IfNot<HCompareObjectEqAndBranch>(expected_map, map); | 1334 map_check.IfNot<HCompareObjectEqAndBranch>(expected_map, map); |
1335 map_check.ThenDeopt(Deoptimizer::kUnknownMap); | 1335 map_check.ThenDeopt(Deoptimizer::kUnknownMap); |
1336 map_check.End(); | 1336 map_check.End(); |
1337 } | 1337 } |
1338 | 1338 |
1339 HValue* weak_cell = Add<HConstant>(isolate()->factory()->NewWeakCell( | 1339 HValue* weak_cell = Add<HConstant>(isolate()->factory()->NewWeakCell( |
1340 StoreGlobalStub::property_cell_placeholder(isolate()))); | 1340 StoreGlobalStub::property_cell_placeholder(isolate()))); |
1341 HValue* cell = Add<HLoadNamedField>(weak_cell, nullptr, | 1341 HValue* cell = Add<HLoadNamedField>(weak_cell, nullptr, |
1342 HObjectAccess::ForWeakCellValue()); | 1342 HObjectAccess::ForWeakCellValue()); |
1343 Add<HCheckHeapObject>(cell); | 1343 Add<HCheckHeapObject>(cell); |
1344 HObjectAccess access = HObjectAccess::ForPropertyCellValue(); | 1344 HObjectAccess access = HObjectAccess::ForPropertyCellValue(); |
| 1345 // Load the payload of the global parameter cell. A hole indicates that the |
| 1346 // cell has been invalidated and that the store must be handled by the |
| 1347 // runtime. |
1345 HValue* cell_contents = Add<HLoadNamedField>(cell, nullptr, access); | 1348 HValue* cell_contents = Add<HLoadNamedField>(cell, nullptr, access); |
1346 | 1349 |
1347 if (stub->is_constant()) { | 1350 auto cell_type = stub->cell_type(); |
| 1351 if (cell_type == PropertyCellType::kConstant || |
| 1352 cell_type == PropertyCellType::kUndefined) { |
| 1353 // This is always valid for all states a cell can be in. |
1348 IfBuilder builder(this); | 1354 IfBuilder builder(this); |
1349 builder.If<HCompareObjectEqAndBranch>(cell_contents, value); | 1355 builder.If<HCompareObjectEqAndBranch>(cell_contents, value); |
1350 builder.Then(); | 1356 builder.Then(); |
1351 builder.ElseDeopt( | 1357 builder.ElseDeopt( |
1352 Deoptimizer::kUnexpectedCellContentsInConstantGlobalStore); | 1358 Deoptimizer::kUnexpectedCellContentsInConstantGlobalStore); |
1353 builder.End(); | 1359 builder.End(); |
1354 } else { | 1360 } else { |
1355 // Load the payload of the global parameter cell. A hole indicates that the | |
1356 // property has been deleted and that the store must be handled by the | |
1357 // runtime. | |
1358 IfBuilder builder(this); | 1361 IfBuilder builder(this); |
1359 HValue* hole_value = graph()->GetConstantHole(); | 1362 HValue* hole_value = graph()->GetConstantHole(); |
1360 builder.If<HCompareObjectEqAndBranch>(cell_contents, hole_value); | 1363 builder.If<HCompareObjectEqAndBranch>(cell_contents, hole_value); |
1361 builder.Then(); | 1364 builder.Then(); |
1362 builder.Deopt(Deoptimizer::kUnexpectedCellContentsInGlobalStore); | 1365 builder.Deopt(Deoptimizer::kUnexpectedCellContentsInGlobalStore); |
1363 builder.Else(); | 1366 builder.Else(); |
| 1367 // When dealing with constant types, the type may be allowed to change, as |
| 1368 // long as optimized code remains valid. |
| 1369 if (cell_type == PropertyCellType::kConstantType) { |
| 1370 switch (stub->constant_type()) { |
| 1371 case PropertyCellConstantType::kSmi: |
| 1372 access = access.WithRepresentation(Representation::Smi()); |
| 1373 break; |
| 1374 case PropertyCellConstantType::kStableMap: { |
| 1375 // It is sufficient here to check that the value and cell contents |
| 1376 // have identical maps, no matter if they are stable or not or if they |
| 1377 // are the maps that were originally in the cell or not. If optimized |
| 1378 // code will deopt when a cell has a unstable map and if it has a |
| 1379 // dependency on a stable map, it will deopt if the map destabilizes. |
| 1380 Add<HCheckHeapObject>(value); |
| 1381 Add<HCheckHeapObject>(cell_contents); |
| 1382 HValue* expected_map = Add<HLoadNamedField>(cell_contents, nullptr, |
| 1383 HObjectAccess::ForMap()); |
| 1384 HValue* map = |
| 1385 Add<HLoadNamedField>(value, nullptr, HObjectAccess::ForMap()); |
| 1386 IfBuilder map_check(this); |
| 1387 map_check.IfNot<HCompareObjectEqAndBranch>(expected_map, map); |
| 1388 map_check.ThenDeopt(Deoptimizer::kUnknownMap); |
| 1389 map_check.End(); |
| 1390 access = access.WithRepresentation(Representation::HeapObject()); |
| 1391 break; |
| 1392 } |
| 1393 } |
| 1394 } |
1364 Add<HStoreNamedField>(cell, access, value); | 1395 Add<HStoreNamedField>(cell, access, value); |
1365 builder.End(); | 1396 builder.End(); |
1366 } | 1397 } |
1367 | 1398 |
1368 return value; | 1399 return value; |
1369 } | 1400 } |
1370 | 1401 |
1371 | 1402 |
1372 Handle<Code> StoreGlobalStub::GenerateCode() { | 1403 Handle<Code> StoreGlobalStub::GenerateCode() { |
1373 return DoGenerateCode(this); | 1404 return DoGenerateCode(this); |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2033 // need. | 2064 // need. |
2034 info()->MarkMustNotHaveEagerFrame(); | 2065 info()->MarkMustNotHaveEagerFrame(); |
2035 | 2066 |
2036 // Probe the stub cache. | 2067 // Probe the stub cache. |
2037 Add<HTailCallThroughMegamorphicCache>(receiver, name); | 2068 Add<HTailCallThroughMegamorphicCache>(receiver, name); |
2038 | 2069 |
2039 // We never continue. | 2070 // We never continue. |
2040 return graph()->GetConstant0(); | 2071 return graph()->GetConstant0(); |
2041 } | 2072 } |
2042 } } // namespace v8::internal | 2073 } } // namespace v8::internal |
OLD | NEW |