Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(404)

Side by Side Diff: src/code-stub-assembler.cc

Issue 2633273003: [csa] Improve code generation for JSArrays (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "src/code-stub-assembler.h" 4 #include "src/code-stub-assembler.h"
5 #include "src/code-factory.h" 5 #include "src/code-factory.h"
6 #include "src/frames-inl.h" 6 #include "src/frames-inl.h"
7 #include "src/frames.h" 7 #include "src/frames.h"
8 8
9 namespace v8 { 9 namespace v8 {
10 namespace internal { 10 namespace internal {
(...skipping 1994 matching lines...) Expand 10 before | Expand all | Expand 10 after
2005 int elements_offset = base_size; 2005 int elements_offset = base_size;
2006 2006
2007 // Compute space for elements 2007 // Compute space for elements
2008 base_size += FixedArray::kHeaderSize; 2008 base_size += FixedArray::kHeaderSize;
2009 Node* size = ElementOffsetFromIndex(capacity, kind, capacity_mode, base_size); 2009 Node* size = ElementOffsetFromIndex(capacity, kind, capacity_mode, base_size);
2010 2010
2011 Node* array = AllocateUninitializedJSArray(kind, array_map, length, 2011 Node* array = AllocateUninitializedJSArray(kind, array_map, length,
2012 allocation_site, size); 2012 allocation_site, size);
2013 2013
2014 Node* elements = InnerAllocate(array, elements_offset); 2014 Node* elements = InnerAllocate(array, elements_offset);
2015 StoreObjectField(array, JSObject::kElementsOffset, elements); 2015 StoreObjectFieldNoWriteBarrier(array, JSObject::kElementsOffset, elements);
2016 2016
2017 return {array, elements}; 2017 return {array, elements};
2018 } 2018 }
2019 2019
2020 Node* CodeStubAssembler::AllocateUninitializedJSArray(ElementsKind kind, 2020 Node* CodeStubAssembler::AllocateUninitializedJSArray(ElementsKind kind,
2021 Node* array_map, 2021 Node* array_map,
2022 Node* length, 2022 Node* length,
2023 Node* allocation_site, 2023 Node* allocation_site,
2024 Node* size_in_bytes) { 2024 Node* size_in_bytes) {
2025 Node* array = Allocate(size_in_bytes); 2025 Node* array = Allocate(size_in_bytes);
(...skipping 10 matching lines...) Expand all
2036 if (allocation_site != nullptr) { 2036 if (allocation_site != nullptr) {
2037 InitializeAllocationMemento(array, JSArray::kSize, allocation_site); 2037 InitializeAllocationMemento(array, JSArray::kSize, allocation_site);
2038 } 2038 }
2039 return array; 2039 return array;
2040 } 2040 }
2041 2041
2042 Node* CodeStubAssembler::AllocateJSArray(ElementsKind kind, Node* array_map, 2042 Node* CodeStubAssembler::AllocateJSArray(ElementsKind kind, Node* array_map,
2043 Node* capacity, Node* length, 2043 Node* capacity, Node* length,
2044 Node* allocation_site, 2044 Node* allocation_site,
2045 ParameterMode capacity_mode) { 2045 ParameterMode capacity_mode) {
2046 // Allocate both array and elements object, and initialize the JSArray. 2046 Node *array = nullptr, *elements = nullptr;
2047 Node *array, *elements; 2047 int32_t constant_capacity;
2048 std::tie(array, elements) = AllocateUninitializedJSArrayWithElements( 2048 if (ToInt32Constant(capacity, constant_capacity) && constant_capacity == 0) {
2049 kind, array_map, length, allocation_site, capacity, capacity_mode); 2049 // Array is empty. Use the shared empty fixed array instead of allocating a
2050 // Setup elements object. 2050 // new one.
2051 Heap::RootListIndex elements_map_index = 2051 array = AllocateUninitializedJSArrayWithoutElements(kind, array_map, length,
2052 IsFastDoubleElementsKind(kind) ? Heap::kFixedDoubleArrayMapRootIndex 2052 nullptr);
2053 : Heap::kFixedArrayMapRootIndex; 2053 StoreObjectFieldRoot(array, JSArray::kElementsOffset,
2054 DCHECK(Heap::RootIsImmortalImmovable(elements_map_index)); 2054 Heap::kEmptyFixedArrayRootIndex);
2055 StoreMapNoWriteBarrier(elements, elements_map_index); 2055 } else {
2056 StoreObjectFieldNoWriteBarrier(elements, FixedArray::kLengthOffset, 2056 // Allocate both array and elements object, and initialize the JSArray.
2057 ParameterToTagged(capacity, capacity_mode)); 2057 std::tie(array, elements) = AllocateUninitializedJSArrayWithElements(
2058 2058 kind, array_map, length, allocation_site, capacity, capacity_mode);
2059 // Fill in the elements with holes. 2059 // Setup elements object.
2060 FillFixedArrayWithValue(kind, elements, IntPtrOrSmiConstant(0, capacity_mode), 2060 Heap::RootListIndex elements_map_index =
2061 capacity, Heap::kTheHoleValueRootIndex, 2061 IsFastDoubleElementsKind(kind) ? Heap::kFixedDoubleArrayMapRootIndex
2062 capacity_mode); 2062 : Heap::kFixedArrayMapRootIndex;
2063 DCHECK(Heap::RootIsImmortalImmovable(elements_map_index));
2064 StoreMapNoWriteBarrier(elements, elements_map_index);
2065 StoreObjectFieldNoWriteBarrier(elements, FixedArray::kLengthOffset,
2066 ParameterToTagged(capacity, capacity_mode));
2067 // Fill in the elements with holes.
2068 FillFixedArrayWithValue(kind, elements,
2069 IntPtrOrSmiConstant(0, capacity_mode), capacity,
2070 Heap::kTheHoleValueRootIndex, capacity_mode);
2071 }
2063 2072
2064 return array; 2073 return array;
2065 } 2074 }
2066 2075
2067 Node* CodeStubAssembler::AllocateFixedArray(ElementsKind kind, 2076 Node* CodeStubAssembler::AllocateFixedArray(ElementsKind kind,
2068 Node* capacity_node, 2077 Node* capacity_node,
2069 ParameterMode mode, 2078 ParameterMode mode,
2070 AllocationFlags flags) { 2079 AllocationFlags flags) {
2071 CSA_ASSERT(this, IntPtrOrSmiGreaterThan(capacity_node, 2080 CSA_ASSERT(this, IntPtrOrSmiGreaterThan(capacity_node,
2072 IntPtrOrSmiConstant(0, mode), mode)); 2081 IntPtrOrSmiConstant(0, mode), mode));
(...skipping 6168 matching lines...) Expand 10 before | Expand all | Expand 10 after
8241 deferred_on_reject); 8250 deferred_on_reject);
8242 StoreObjectFieldNoWriteBarrier(result, PromiseReactionJobInfo::kDebugIdOffset, 8251 StoreObjectFieldNoWriteBarrier(result, PromiseReactionJobInfo::kDebugIdOffset,
8243 SmiConstant(kDebugPromiseNoID)); 8252 SmiConstant(kDebugPromiseNoID));
8244 StoreObjectFieldNoWriteBarrier(result, PromiseReactionJobInfo::kContextOffset, 8253 StoreObjectFieldNoWriteBarrier(result, PromiseReactionJobInfo::kContextOffset,
8245 context); 8254 context);
8246 return result; 8255 return result;
8247 } 8256 }
8248 8257
8249 } // namespace internal 8258 } // namespace internal
8250 } // namespace v8 8259 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698