OLD | NEW |
---|---|
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/code-stub-assembler.h" | 5 #include "src/code-stub-assembler.h" |
6 #include "src/code-factory.h" | 6 #include "src/code-factory.h" |
7 #include "src/frames-inl.h" | 7 #include "src/frames-inl.h" |
8 #include "src/frames.h" | 8 #include "src/frames.h" |
9 #include "src/ic/handler-configuration.h" | 9 #include "src/ic/handler-configuration.h" |
10 #include "src/ic/stub-cache.h" | 10 #include "src/ic/stub-cache.h" |
(...skipping 28 matching lines...) Expand all Loading... | |
39 } | 39 } |
40 | 40 |
41 Node* CodeStubAssembler::BooleanMapConstant() { | 41 Node* CodeStubAssembler::BooleanMapConstant() { |
42 return HeapConstant(isolate()->factory()->boolean_map()); | 42 return HeapConstant(isolate()->factory()->boolean_map()); |
43 } | 43 } |
44 | 44 |
45 Node* CodeStubAssembler::EmptyStringConstant() { | 45 Node* CodeStubAssembler::EmptyStringConstant() { |
46 return LoadRoot(Heap::kempty_stringRootIndex); | 46 return LoadRoot(Heap::kempty_stringRootIndex); |
47 } | 47 } |
48 | 48 |
49 Node* CodeStubAssembler::FixedArrayMapConstant() { | |
50 return HeapConstant(isolate()->factory()->fixed_array_map()); | |
51 } | |
52 | |
53 Node* CodeStubAssembler::FixedCowArrayMapConstant() { | |
54 return HeapConstant(isolate()->factory()->fixed_cow_array_map()); | |
55 } | |
56 | |
49 Node* CodeStubAssembler::HeapNumberMapConstant() { | 57 Node* CodeStubAssembler::HeapNumberMapConstant() { |
50 return LoadRoot(Heap::kHeapNumberMapRootIndex); | 58 return LoadRoot(Heap::kHeapNumberMapRootIndex); |
51 } | 59 } |
52 | 60 |
53 Node* CodeStubAssembler::NoContextConstant() { | 61 Node* CodeStubAssembler::NoContextConstant() { |
54 return SmiConstant(Smi::FromInt(0)); | 62 return SmiConstant(Smi::FromInt(0)); |
55 } | 63 } |
56 | 64 |
57 Node* CodeStubAssembler::MinusZeroConstant() { | 65 Node* CodeStubAssembler::MinusZeroConstant() { |
58 return LoadRoot(Heap::kMinusZeroValueRootIndex); | 66 return LoadRoot(Heap::kMinusZeroValueRootIndex); |
(...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
993 } | 1001 } |
994 | 1002 |
995 Node* CodeStubAssembler::LoadProperties(Node* object) { | 1003 Node* CodeStubAssembler::LoadProperties(Node* object) { |
996 return LoadObjectField(object, JSObject::kPropertiesOffset); | 1004 return LoadObjectField(object, JSObject::kPropertiesOffset); |
997 } | 1005 } |
998 | 1006 |
999 Node* CodeStubAssembler::LoadElements(Node* object) { | 1007 Node* CodeStubAssembler::LoadElements(Node* object) { |
1000 return LoadObjectField(object, JSObject::kElementsOffset); | 1008 return LoadObjectField(object, JSObject::kElementsOffset); |
1001 } | 1009 } |
1002 | 1010 |
1011 Node* CodeStubAssembler::LoadJSArrayLength(compiler::Node* array) { | |
1012 return LoadObjectField(array, JSArray::kLengthOffset); | |
1013 } | |
1014 | |
1003 Node* CodeStubAssembler::LoadFixedArrayBaseLength(compiler::Node* array) { | 1015 Node* CodeStubAssembler::LoadFixedArrayBaseLength(compiler::Node* array) { |
1004 return LoadObjectField(array, FixedArrayBase::kLengthOffset); | 1016 return LoadObjectField(array, FixedArrayBase::kLengthOffset); |
1005 } | 1017 } |
1006 | 1018 |
1007 Node* CodeStubAssembler::LoadAndUntagFixedArrayBaseLength(Node* array) { | 1019 Node* CodeStubAssembler::LoadAndUntagFixedArrayBaseLength(Node* array) { |
1008 return LoadAndUntagObjectField(array, FixedArrayBase::kLengthOffset); | 1020 return LoadAndUntagObjectField(array, FixedArrayBase::kLengthOffset); |
1009 } | 1021 } |
1010 | 1022 |
1011 Node* CodeStubAssembler::LoadMapBitField(Node* map) { | 1023 Node* CodeStubAssembler::LoadMapBitField(Node* map) { |
1012 return LoadObjectField(map, Map::kBitFieldOffset, MachineType::Uint8()); | 1024 return LoadObjectField(map, Map::kBitFieldOffset, MachineType::Uint8()); |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1359 Node* result = CallRuntime(Runtime::kAllocateSeqTwoByteString, context, | 1371 Node* result = CallRuntime(Runtime::kAllocateSeqTwoByteString, context, |
1360 SmiFromWord(length)); | 1372 SmiFromWord(length)); |
1361 var_result.Bind(result); | 1373 var_result.Bind(result); |
1362 Goto(&if_join); | 1374 Goto(&if_join); |
1363 } | 1375 } |
1364 | 1376 |
1365 Bind(&if_join); | 1377 Bind(&if_join); |
1366 return var_result.value(); | 1378 return var_result.value(); |
1367 } | 1379 } |
1368 | 1380 |
1369 Node* CodeStubAssembler::AllocateJSArray(ElementsKind kind, Node* array_map, | 1381 Node* CodeStubAssembler::AllocateEmptyJSArray(ElementsKind kind, |
rmcilroy
2016/09/13 20:29:59
Maybe we should call this something like AllocateU
klaasb
2016/09/14 18:24:51
Done.
| |
1370 Node* capacity_node, Node* length_node, | 1382 Node* array_map, Node* length, |
1371 compiler::Node* allocation_site, | 1383 Node* allocation_site, |
1372 ParameterMode mode) { | 1384 ParameterMode mode, |
1373 bool is_double = IsFastDoubleElementsKind(kind); | 1385 Node* capacity) { |
1374 int base_size = JSArray::kSize + FixedArray::kHeaderSize; | 1386 Comment("begin allocation of JSArray"); |
1375 int elements_offset = JSArray::kSize; | |
1376 | 1387 |
1377 Comment("begin allocation of JSArray"); | 1388 int base_size = JSArray::kSize; |
1378 | 1389 |
1379 if (allocation_site != nullptr) { | 1390 if (allocation_site != nullptr) { |
1380 base_size += AllocationMemento::kSize; | 1391 base_size += AllocationMemento::kSize; |
1381 elements_offset += AllocationMemento::kSize; | |
1382 } | 1392 } |
1383 | 1393 |
1384 Node* total_size = | 1394 int elements_offset = base_size; |
1385 ElementOffsetFromIndex(capacity_node, kind, mode, base_size); | 1395 Node* total_size; |
1396 | |
1397 // Compute space for elements if capacity is not null. | |
1398 if (capacity != nullptr) { | |
1399 base_size += FixedArray::kHeaderSize; | |
1400 total_size = ElementOffsetFromIndex(capacity, kind, mode, base_size); | |
1401 } else { | |
1402 total_size = IntPtrConstant(base_size); | |
1403 } | |
1386 | 1404 |
1387 // Allocate both array and elements object, and initialize the JSArray. | 1405 // Allocate both array and elements object, and initialize the JSArray. |
1388 Heap* heap = isolate()->heap(); | |
1389 Node* array = Allocate(total_size); | 1406 Node* array = Allocate(total_size); |
1407 | |
1390 StoreMapNoWriteBarrier(array, array_map); | 1408 StoreMapNoWriteBarrier(array, array_map); |
1391 Node* empty_properties = LoadRoot(Heap::kEmptyFixedArrayRootIndex); | 1409 |
1392 StoreObjectFieldNoWriteBarrier(array, JSArray::kPropertiesOffset, | |
1393 empty_properties); | |
1394 StoreObjectFieldNoWriteBarrier(array, JSArray::kLengthOffset, | 1410 StoreObjectFieldNoWriteBarrier(array, JSArray::kLengthOffset, |
1395 TagParameter(length_node, mode)); | 1411 TagParameter(length, mode)); |
1412 | |
1413 StoreObjectFieldRoot(array, JSArray::kPropertiesOffset, | |
1414 Heap::kEmptyFixedArrayRootIndex); | |
1415 | |
1416 if (capacity != nullptr) { | |
1417 Node* elements = InnerAllocate(array, elements_offset); | |
1418 StoreObjectField(array, JSObject::kElementsOffset, elements); | |
1419 } | |
1396 | 1420 |
1397 if (allocation_site != nullptr) { | 1421 if (allocation_site != nullptr) { |
1398 InitializeAllocationMemento(array, JSArray::kSize, allocation_site); | 1422 InitializeAllocationMemento(array, JSArray::kSize, allocation_site); |
1399 } | 1423 } |
1400 | 1424 |
1425 return array; | |
1426 } | |
1427 | |
1428 Node* CodeStubAssembler::AllocateFilledJSArray(ElementsKind kind, | |
1429 Node* array_map, Node* capacity, | |
1430 Node* length, | |
1431 Node* allocation_site, | |
1432 ParameterMode mode) { | |
1433 bool is_double = IsFastDoubleElementsKind(kind); | |
1434 int elements_offset = | |
1435 JSArray::kSize + | |
1436 (allocation_site != nullptr ? AllocationMemento::kSize : 0); | |
1437 | |
1438 // Allocate both array and elements object, and initialize the JSArray. | |
1439 Node* array = AllocateEmptyJSArray(kind, array_map, length, allocation_site, | |
1440 mode, capacity); | |
1441 Node* elements = InnerAllocate(array, elements_offset); | |
rmcilroy
2016/09/13 20:29:58
Do you do this twice? There is an InnerAllocate fo
klaasb
2016/09/14 18:24:51
We still want to allocate space for the array and
| |
1442 | |
1401 // Setup elements object. | 1443 // Setup elements object. |
1402 Node* elements = InnerAllocate(array, elements_offset); | 1444 Heap* heap = isolate()->heap(); |
1403 StoreObjectFieldNoWriteBarrier(array, JSArray::kElementsOffset, elements); | |
1404 Handle<Map> elements_map(is_double ? heap->fixed_double_array_map() | 1445 Handle<Map> elements_map(is_double ? heap->fixed_double_array_map() |
1405 : heap->fixed_array_map()); | 1446 : heap->fixed_array_map()); |
1406 StoreMapNoWriteBarrier(elements, HeapConstant(elements_map)); | 1447 StoreMapNoWriteBarrier(elements, HeapConstant(elements_map)); |
1407 StoreObjectFieldNoWriteBarrier(elements, FixedArray::kLengthOffset, | 1448 StoreObjectFieldNoWriteBarrier(elements, FixedArray::kLengthOffset, |
1408 TagParameter(capacity_node, mode)); | 1449 TagParameter(capacity, mode)); |
1409 | 1450 |
1410 // Fill in the elements with holes. | 1451 // Fill in the elements with holes. |
1411 FillFixedArrayWithValue(kind, elements, IntPtrConstant(0), capacity_node, | 1452 FillFixedArrayWithValue(kind, elements, IntPtrConstant(0), capacity, |
1412 Heap::kTheHoleValueRootIndex, mode); | 1453 Heap::kTheHoleValueRootIndex, mode); |
1413 | 1454 |
1414 return array; | 1455 return array; |
1415 } | 1456 } |
1416 | 1457 |
1417 Node* CodeStubAssembler::AllocateFixedArray(ElementsKind kind, | 1458 Node* CodeStubAssembler::AllocateFixedArray(ElementsKind kind, |
1418 Node* capacity_node, | 1459 Node* capacity_node, |
1419 ParameterMode mode, | 1460 ParameterMode mode, |
1420 AllocationFlags flags) { | 1461 AllocationFlags flags) { |
1421 Node* total_size = GetFixedAarrayAllocationSize(capacity_node, kind, mode); | 1462 Node* total_size = GetFixedAarrayAllocationSize(capacity_node, kind, mode); |
(...skipping 2431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3853 Label* miss) { | 3894 Label* miss) { |
3854 Variable var_length(this, MachineType::PointerRepresentation()); | 3895 Variable var_length(this, MachineType::PointerRepresentation()); |
3855 Label if_array(this), length_loaded(this, &var_length); | 3896 Label if_array(this), length_loaded(this, &var_length); |
3856 GotoIf(is_jsarray_condition, &if_array); | 3897 GotoIf(is_jsarray_condition, &if_array); |
3857 { | 3898 { |
3858 var_length.Bind(SmiUntag(LoadFixedArrayBaseLength(elements))); | 3899 var_length.Bind(SmiUntag(LoadFixedArrayBaseLength(elements))); |
3859 Goto(&length_loaded); | 3900 Goto(&length_loaded); |
3860 } | 3901 } |
3861 Bind(&if_array); | 3902 Bind(&if_array); |
3862 { | 3903 { |
3863 var_length.Bind(SmiUntag(LoadObjectField(object, JSArray::kLengthOffset))); | 3904 var_length.Bind(SmiUntag(LoadJSArrayLength(object))); |
3864 Goto(&length_loaded); | 3905 Goto(&length_loaded); |
3865 } | 3906 } |
3866 Bind(&length_loaded); | 3907 Bind(&length_loaded); |
3867 GotoUnless(UintPtrLessThan(intptr_index, var_length.value()), miss); | 3908 GotoUnless(UintPtrLessThan(intptr_index, var_length.value()), miss); |
3868 } | 3909 } |
3869 | 3910 |
3870 void CodeStubAssembler::EmitElementLoad(Node* object, Node* elements, | 3911 void CodeStubAssembler::EmitElementLoad(Node* object, Node* elements, |
3871 Node* elements_kind, Node* intptr_index, | 3912 Node* elements_kind, Node* intptr_index, |
3872 Node* is_jsarray_condition, | 3913 Node* is_jsarray_condition, |
3873 Label* if_hole, Label* rebox_double, | 3914 Label* if_hole, Label* rebox_double, |
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4717 Heap::kTheHoleValueRootIndex); | 4758 Heap::kTheHoleValueRootIndex); |
4718 | 4759 |
4719 // Store the WeakCell in the feedback vector. | 4760 // Store the WeakCell in the feedback vector. |
4720 StoreFixedArrayElement(feedback_vector, slot, cell, UPDATE_WRITE_BARRIER, | 4761 StoreFixedArrayElement(feedback_vector, slot, cell, UPDATE_WRITE_BARRIER, |
4721 CodeStubAssembler::SMI_PARAMETERS); | 4762 CodeStubAssembler::SMI_PARAMETERS); |
4722 return cell; | 4763 return cell; |
4723 } | 4764 } |
4724 | 4765 |
4725 } // namespace internal | 4766 } // namespace internal |
4726 } // namespace v8 | 4767 } // namespace v8 |
OLD | NEW |