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 1322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1333 StoreGlobalStub* stub = casted_stub(); | 1333 StoreGlobalStub* stub = casted_stub(); |
1334 HParameter* value = GetParameter(StoreDescriptor::kValueIndex); | 1334 HParameter* value = GetParameter(StoreDescriptor::kValueIndex); |
1335 if (stub->check_global()) { | 1335 if (stub->check_global()) { |
1336 // Check that the map of the global has not changed: use a placeholder map | 1336 // Check that the map of the global has not changed: use a placeholder map |
1337 // that will be replaced later with the global object's map. | 1337 // that will be replaced later with the global object's map. |
1338 HParameter* proxy = GetParameter(StoreDescriptor::kReceiverIndex); | 1338 HParameter* proxy = GetParameter(StoreDescriptor::kReceiverIndex); |
1339 HValue* proxy_map = | 1339 HValue* proxy_map = |
1340 Add<HLoadNamedField>(proxy, nullptr, HObjectAccess::ForMap()); | 1340 Add<HLoadNamedField>(proxy, nullptr, HObjectAccess::ForMap()); |
1341 HValue* global = | 1341 HValue* global = |
1342 Add<HLoadNamedField>(proxy_map, nullptr, HObjectAccess::ForPrototype()); | 1342 Add<HLoadNamedField>(proxy_map, nullptr, HObjectAccess::ForPrototype()); |
1343 Handle<Map> placeholder_map = isolate()->factory()->meta_map(); | 1343 HValue* map_cell = Add<HConstant>(isolate()->factory()->NewWeakCell( |
1344 HValue* cell = Add<HConstant>(Map::WeakCellForMap(placeholder_map)); | 1344 StoreGlobalStub::global_map_placeholder(isolate()))); |
1345 HValue* expected_map = | 1345 HValue* expected_map = Add<HLoadNamedField>( |
1346 Add<HLoadNamedField>(cell, nullptr, HObjectAccess::ForWeakCellValue()); | 1346 map_cell, nullptr, HObjectAccess::ForWeakCellValue()); |
1347 HValue* map = | 1347 HValue* map = |
1348 Add<HLoadNamedField>(global, nullptr, HObjectAccess::ForMap()); | 1348 Add<HLoadNamedField>(global, nullptr, HObjectAccess::ForMap()); |
1349 IfBuilder map_check(this); | 1349 IfBuilder map_check(this); |
1350 map_check.IfNot<HCompareObjectEqAndBranch>(expected_map, map); | 1350 map_check.IfNot<HCompareObjectEqAndBranch>(expected_map, map); |
1351 map_check.ThenDeopt(Deoptimizer::kUnknownMap); | 1351 map_check.ThenDeopt(Deoptimizer::kUnknownMap); |
1352 map_check.End(); | 1352 map_check.End(); |
1353 } | 1353 } |
1354 | 1354 |
1355 HValue* weak_cell = Add<HConstant>(isolate()->factory()->NewWeakCell( | 1355 HValue* weak_cell = Add<HConstant>(isolate()->factory()->NewWeakCell( |
1356 StoreGlobalStub::property_cell_placeholder(isolate()))); | 1356 StoreGlobalStub::property_cell_placeholder(isolate()))); |
1357 HValue* cell = Add<HLoadNamedField>(weak_cell, nullptr, | 1357 HValue* cell = Add<HLoadNamedField>(weak_cell, nullptr, |
1358 HObjectAccess::ForWeakCellValue()); | 1358 HObjectAccess::ForWeakCellValue()); |
1359 Add<HCheckHeapObject>(cell); | 1359 Add<HCheckHeapObject>(cell); |
1360 HObjectAccess access = HObjectAccess::ForPropertyCellValue(); | 1360 HObjectAccess access = HObjectAccess::ForPropertyCellValue(); |
| 1361 // Load the payload of the global parameter cell. A hole indicates that the |
| 1362 // cell has been invalidated and that the store must be handled by the |
| 1363 // runtime. |
1361 HValue* cell_contents = Add<HLoadNamedField>(cell, nullptr, access); | 1364 HValue* cell_contents = Add<HLoadNamedField>(cell, nullptr, access); |
1362 | 1365 |
1363 if (stub->is_constant()) { | 1366 auto cell_type = stub->cell_type(); |
| 1367 if (cell_type == PropertyCellType::kConstant || |
| 1368 cell_type == PropertyCellType::kUndefined) { |
| 1369 // This is always valid for all states a cell can be in. |
1364 IfBuilder builder(this); | 1370 IfBuilder builder(this); |
1365 builder.If<HCompareObjectEqAndBranch>(cell_contents, value); | 1371 builder.If<HCompareObjectEqAndBranch>(cell_contents, value); |
1366 builder.Then(); | 1372 builder.Then(); |
1367 builder.ElseDeopt( | 1373 builder.ElseDeopt( |
1368 Deoptimizer::kUnexpectedCellContentsInConstantGlobalStore); | 1374 Deoptimizer::kUnexpectedCellContentsInConstantGlobalStore); |
1369 builder.End(); | 1375 builder.End(); |
1370 } else { | 1376 } else { |
1371 // Load the payload of the global parameter cell. A hole indicates that the | |
1372 // property has been deleted and that the store must be handled by the | |
1373 // runtime. | |
1374 IfBuilder builder(this); | 1377 IfBuilder builder(this); |
1375 HValue* hole_value = graph()->GetConstantHole(); | 1378 HValue* hole_value = graph()->GetConstantHole(); |
1376 builder.If<HCompareObjectEqAndBranch>(cell_contents, hole_value); | 1379 builder.If<HCompareObjectEqAndBranch>(cell_contents, hole_value); |
1377 builder.Then(); | 1380 builder.Then(); |
1378 builder.Deopt(Deoptimizer::kUnexpectedCellContentsInGlobalStore); | 1381 builder.Deopt(Deoptimizer::kUnexpectedCellContentsInGlobalStore); |
1379 builder.Else(); | 1382 builder.Else(); |
| 1383 // When dealing with constant types, the type may be allowed to change, as |
| 1384 // long as optimized code remains valid. |
| 1385 if (cell_type == PropertyCellType::kConstantType) { |
| 1386 switch (stub->constant_type()) { |
| 1387 case PropertyCellConstantType::kSmi: |
| 1388 access = access.WithRepresentation(Representation::Smi()); |
| 1389 break; |
| 1390 case PropertyCellConstantType::kStableMap: { |
| 1391 // It is sufficient here to check that the value and cell contents |
| 1392 // have identical maps, no matter if they are stable or not or if they |
| 1393 // are the maps that were originally in the cell or not. If optimized |
| 1394 // code will deopt when a cell has a unstable map and if it has a |
| 1395 // dependency on a stable map, it will deopt if the map destabilizes. |
| 1396 Add<HCheckHeapObject>(value); |
| 1397 Add<HCheckHeapObject>(cell_contents); |
| 1398 HValue* expected_map = Add<HLoadNamedField>(cell_contents, nullptr, |
| 1399 HObjectAccess::ForMap()); |
| 1400 HValue* map = |
| 1401 Add<HLoadNamedField>(value, nullptr, HObjectAccess::ForMap()); |
| 1402 IfBuilder map_check(this); |
| 1403 map_check.IfNot<HCompareObjectEqAndBranch>(expected_map, map); |
| 1404 map_check.ThenDeopt(Deoptimizer::kUnknownMap); |
| 1405 map_check.End(); |
| 1406 access = access.WithRepresentation(Representation::HeapObject()); |
| 1407 break; |
| 1408 } |
| 1409 } |
| 1410 } |
1380 Add<HStoreNamedField>(cell, access, value); | 1411 Add<HStoreNamedField>(cell, access, value); |
1381 builder.End(); | 1412 builder.End(); |
1382 } | 1413 } |
1383 | 1414 |
1384 return value; | 1415 return value; |
1385 } | 1416 } |
1386 | 1417 |
1387 | 1418 |
1388 Handle<Code> StoreGlobalStub::GenerateCode() { | 1419 Handle<Code> StoreGlobalStub::GenerateCode() { |
1389 return DoGenerateCode(this); | 1420 return DoGenerateCode(this); |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2049 // need. | 2080 // need. |
2050 info()->MarkMustNotHaveEagerFrame(); | 2081 info()->MarkMustNotHaveEagerFrame(); |
2051 | 2082 |
2052 // Probe the stub cache. | 2083 // Probe the stub cache. |
2053 Add<HTailCallThroughMegamorphicCache>(receiver, name); | 2084 Add<HTailCallThroughMegamorphicCache>(receiver, name); |
2054 | 2085 |
2055 // We never continue. | 2086 // We never continue. |
2056 return graph()->GetConstant0(); | 2087 return graph()->GetConstant0(); |
2057 } | 2088 } |
2058 } } // namespace v8::internal | 2089 } } // namespace v8::internal |
OLD | NEW |