Commit f7886fcd authored by Mike Stanton's avatar Mike Stanton Committed by Commit Bot

[CSA]: Refactor function AllocateUninitializedJSArrayWithoutElements

All users have elements already, and we can just pass that in.

Change-Id: Ie9b8c1290d74bce120461c9f15695e8eb7dfd7c2
Reviewed-on: https://chromium-review.googlesource.com/c/1430072
Commit-Queue: Michael Stanton <mvstanton@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59064}
parent ec4d45a8
...@@ -390,9 +390,7 @@ ObjectEntriesValuesBuiltinsAssembler::FinalizeValuesOrEntriesJSArray( ...@@ -390,9 +390,7 @@ ObjectEntriesValuesBuiltinsAssembler::FinalizeValuesOrEntriesJSArray(
CSA_ASSERT(this, IsJSArrayMap(array_map)); CSA_ASSERT(this, IsJSArrayMap(array_map));
GotoIf(IntPtrEqual(size, IntPtrConstant(0)), if_empty); GotoIf(IntPtrEqual(size, IntPtrConstant(0)), if_empty);
Node* array = AllocateUninitializedJSArrayWithoutElements( Node* array = AllocateJSArray(array_map, result, SmiTag(size));
array_map, SmiTag(size), nullptr);
StoreObjectField(array, JSArray::kElementsOffset, result);
return TNode<JSArray>::UncheckedCast(array); return TNode<JSArray>::UncheckedCast(array);
} }
...@@ -647,10 +645,8 @@ TF_BUILTIN(ObjectKeys, ObjectBuiltinsAssembler) { ...@@ -647,10 +645,8 @@ TF_BUILTIN(ObjectKeys, ObjectBuiltinsAssembler) {
Node* native_context = LoadNativeContext(context); Node* native_context = LoadNativeContext(context);
TNode<Map> array_map = TNode<Map> array_map =
LoadJSArrayElementsMap(PACKED_ELEMENTS, native_context); LoadJSArrayElementsMap(PACKED_ELEMENTS, native_context);
TNode<JSArray> array = AllocateUninitializedJSArrayWithoutElements( TNode<JSArray> array = AllocateJSArray(
array_map, CAST(var_length.value()), nullptr); array_map, CAST(var_elements.value()), CAST(var_length.value()));
StoreObjectFieldNoWriteBarrier(array, JSArray::kElementsOffset,
var_elements.value());
Return(array); Return(array);
} }
} }
...@@ -751,10 +747,8 @@ TF_BUILTIN(ObjectGetOwnPropertyNames, ObjectBuiltinsAssembler) { ...@@ -751,10 +747,8 @@ TF_BUILTIN(ObjectGetOwnPropertyNames, ObjectBuiltinsAssembler) {
Node* native_context = LoadNativeContext(context); Node* native_context = LoadNativeContext(context);
TNode<Map> array_map = TNode<Map> array_map =
LoadJSArrayElementsMap(PACKED_ELEMENTS, native_context); LoadJSArrayElementsMap(PACKED_ELEMENTS, native_context);
TNode<JSArray> array = AllocateUninitializedJSArrayWithoutElements( TNode<JSArray> array = AllocateJSArray(
array_map, CAST(var_length.value()), nullptr); array_map, CAST(var_elements.value()), CAST(var_length.value()));
StoreObjectFieldNoWriteBarrier(array, JSArray::kElementsOffset,
var_elements.value());
Return(array); Return(array);
} }
} }
......
...@@ -116,9 +116,7 @@ Node* ProxiesCodeStubAssembler::AllocateJSArrayForCodeStubArguments( ...@@ -116,9 +116,7 @@ Node* ProxiesCodeStubAssembler::AllocateJSArrayForCodeStubArguments(
TNode<Map> array_map = TNode<Map> array_map =
LoadJSArrayElementsMap(PACKED_ELEMENTS, native_context); LoadJSArrayElementsMap(PACKED_ELEMENTS, native_context);
TNode<JSArray> array = TNode<JSArray> array =
AllocateUninitializedJSArrayWithoutElements(array_map, length); AllocateJSArray(array_map, CAST(elements.value()), length);
StoreObjectFieldNoWriteBarrier(array, JSObject::kElementsOffset,
elements.value());
return array; return array;
} }
......
...@@ -1803,9 +1803,7 @@ TNode<JSArray> StringBuiltinsAssembler::StringToArray( ...@@ -1803,9 +1803,7 @@ TNode<JSArray> StringBuiltinsAssembler::StringToArray(
1, ParameterMode::INTPTR_PARAMETERS, IndexAdvanceMode::kPost); 1, ParameterMode::INTPTR_PARAMETERS, IndexAdvanceMode::kPost);
TNode<Map> array_map = LoadJSArrayElementsMap(PACKED_ELEMENTS, context); TNode<Map> array_map = LoadJSArrayElementsMap(PACKED_ELEMENTS, context);
result_array = result_array = AllocateJSArray(array_map, elements, length_smi);
AllocateUninitializedJSArrayWithoutElements(array_map, length_smi);
StoreObjectField(result_array.value(), JSObject::kElementsOffset, elements);
Goto(&done); Goto(&done);
BIND(&fill_thehole_and_call_runtime); BIND(&fill_thehole_and_call_runtime);
......
...@@ -56,11 +56,8 @@ TNode<JSArray> GrowableFixedArray::ToJSArray(TNode<Context> const context) { ...@@ -56,11 +56,8 @@ TNode<JSArray> GrowableFixedArray::ToJSArray(TNode<Context> const context) {
} }
TNode<Smi> const result_length = SmiTag(length()); TNode<Smi> const result_length = SmiTag(length());
TNode<JSArray> const result = AllocateUninitializedJSArrayWithoutElements( TNode<JSArray> const result =
array_map, result_length, nullptr); AllocateJSArray(array_map, var_array_.value(), result_length);
StoreObjectField(result, JSObject::kElementsOffset, var_array_.value());
return result; return result;
} }
......
...@@ -3832,9 +3832,10 @@ TNode<BoolT> CodeStubAssembler::IsValidFastJSArrayCapacity( ...@@ -3832,9 +3832,10 @@ TNode<BoolT> CodeStubAssembler::IsValidFastJSArrayCapacity(
IntPtrConstant(JSArray::kMaxFastArrayLength))); IntPtrConstant(JSArray::kMaxFastArrayLength)));
} }
TNode<JSArray> CodeStubAssembler::AllocateUninitializedJSArrayWithoutElements( TNode<JSArray> CodeStubAssembler::AllocateJSArray(
TNode<Map> array_map, TNode<Smi> length, Node* allocation_site) { TNode<Map> array_map, TNode<FixedArrayBase> elements, TNode<Smi> length,
Comment("begin allocation of JSArray without elements"); Node* allocation_site) {
Comment("begin allocation of JSArray passing in elements");
CSA_SLOW_ASSERT(this, TaggedIsPositiveSmi(length)); CSA_SLOW_ASSERT(this, TaggedIsPositiveSmi(length));
int base_size = JSArray::kSize; int base_size = JSArray::kSize;
...@@ -3843,7 +3844,10 @@ TNode<JSArray> CodeStubAssembler::AllocateUninitializedJSArrayWithoutElements( ...@@ -3843,7 +3844,10 @@ TNode<JSArray> CodeStubAssembler::AllocateUninitializedJSArrayWithoutElements(
} }
TNode<IntPtrT> size = IntPtrConstant(base_size); TNode<IntPtrT> size = IntPtrConstant(base_size);
return AllocateUninitializedJSArray(array_map, length, allocation_site, size); TNode<JSArray> result =
AllocateUninitializedJSArray(array_map, length, allocation_site, size);
StoreObjectFieldNoWriteBarrier(result, JSArray::kElementsOffset, elements);
return result;
} }
std::pair<TNode<JSArray>, TNode<FixedArrayBase>> std::pair<TNode<JSArray>, TNode<FixedArrayBase>>
...@@ -3897,10 +3901,8 @@ CodeStubAssembler::AllocateUninitializedJSArrayWithElements( ...@@ -3897,10 +3901,8 @@ CodeStubAssembler::AllocateUninitializedJSArrayWithElements(
// The JSArray and possibly allocation memento next. Note that // The JSArray and possibly allocation memento next. Note that
// allocation_flags are *not* passed on here and the resulting JSArray will // allocation_flags are *not* passed on here and the resulting JSArray will
// always be in new space. // always be in new space.
array = AllocateUninitializedJSArrayWithoutElements(array_map, length, array =
allocation_site); AllocateJSArray(array_map, elements.value(), length, allocation_site);
StoreObjectFieldNoWriteBarrier(array.value(), JSObject::kElementsOffset,
elements.value());
Goto(&out); Goto(&out);
...@@ -3969,10 +3971,10 @@ TNode<JSArray> CodeStubAssembler::AllocateJSArray( ...@@ -3969,10 +3971,10 @@ TNode<JSArray> CodeStubAssembler::AllocateJSArray(
if (IsIntPtrOrSmiConstantZero(capacity, capacity_mode)) { if (IsIntPtrOrSmiConstantZero(capacity, capacity_mode)) {
// Array is empty. Use the shared empty fixed array instead of allocating a // Array is empty. Use the shared empty fixed array instead of allocating a
// new one. // new one.
array = AllocateUninitializedJSArrayWithoutElements(array_map, length, TNode<FixedArrayBase> empty_fixed_array =
allocation_site); CAST(LoadRoot(RootIndex::kEmptyFixedArray));
StoreObjectFieldRoot(array, JSArray::kElementsOffset, array =
RootIndex::kEmptyFixedArray); AllocateJSArray(array_map, empty_fixed_array, length, allocation_site);
} else if (TryGetIntPtrOrSmiConstantValue(capacity, &capacity_as_constant, } else if (TryGetIntPtrOrSmiConstantValue(capacity, &capacity_as_constant,
capacity_mode)) { capacity_mode)) {
CHECK_GT(capacity_as_constant, 0); CHECK_GT(capacity_as_constant, 0);
...@@ -3995,10 +3997,10 @@ TNode<JSArray> CodeStubAssembler::AllocateJSArray( ...@@ -3995,10 +3997,10 @@ TNode<JSArray> CodeStubAssembler::AllocateJSArray(
{ {
// Array is empty. Use the shared empty fixed array instead of allocating // Array is empty. Use the shared empty fixed array instead of allocating
// a new one. // a new one.
var_array = AllocateUninitializedJSArrayWithoutElements(array_map, length, TNode<FixedArrayBase> empty_fixed_array =
allocation_site); CAST(LoadRoot(RootIndex::kEmptyFixedArray));
StoreObjectFieldRoot(var_array.value(), JSArray::kElementsOffset, var_array = AllocateJSArray(array_map, empty_fixed_array, length,
RootIndex::kEmptyFixedArray); allocation_site);
Goto(&out); Goto(&out);
} }
...@@ -4035,13 +4037,12 @@ Node* CodeStubAssembler::ExtractFastJSArray(Node* context, Node* array, ...@@ -4035,13 +4037,12 @@ Node* CodeStubAssembler::ExtractFastJSArray(Node* context, Node* array,
Node* native_context = LoadNativeContext(context); Node* native_context = LoadNativeContext(context);
TNode<Map> array_map = LoadJSArrayElementsMap(elements_kind, native_context); TNode<Map> array_map = LoadJSArrayElementsMap(elements_kind, native_context);
Node* new_elements = ExtractFixedArray( TNode<FixedArrayBase> new_elements = ExtractFixedArray(
LoadElements(array), begin, count, capacity, LoadElements(array), begin, count, capacity,
ExtractFixedArrayFlag::kAllFixedArrays, mode, nullptr, elements_kind); ExtractFixedArrayFlag::kAllFixedArrays, mode, nullptr, elements_kind);
TNode<Object> result = AllocateUninitializedJSArrayWithoutElements( TNode<Object> result = AllocateJSArray(
array_map, ParameterToTagged(count, mode), allocation_site); array_map, new_elements, ParameterToTagged(count, mode), allocation_site);
StoreObjectField(result, JSObject::kElementsOffset, new_elements);
return result; return result;
} }
...@@ -4105,9 +4106,8 @@ Node* CodeStubAssembler::CloneFastJSArray(Node* context, Node* array, ...@@ -4105,9 +4106,8 @@ Node* CodeStubAssembler::CloneFastJSArray(Node* context, Node* array,
TNode<Map> array_map = TNode<Map> array_map =
LoadJSArrayElementsMap(var_elements_kind.value(), native_context); LoadJSArrayElementsMap(var_elements_kind.value(), native_context);
TNode<Object> result = AllocateUninitializedJSArrayWithoutElements( TNode<Object> result = AllocateJSArray(
array_map, CAST(length), allocation_site); array_map, CAST(var_new_elements.value()), CAST(length), allocation_site);
StoreObjectField(result, JSObject::kElementsOffset, var_new_elements.value());
return result; return result;
} }
......
...@@ -1444,9 +1444,6 @@ class V8_EXPORT_PRIVATE CodeStubAssembler ...@@ -1444,9 +1444,6 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
TNode<BoolT> IsValidFastJSArrayCapacity(Node* capacity, TNode<BoolT> IsValidFastJSArrayCapacity(Node* capacity,
ParameterMode capacity_mode); ParameterMode capacity_mode);
// Allocate a JSArray without elements and initialize the header fields.
TNode<JSArray> AllocateUninitializedJSArrayWithoutElements(
TNode<Map> array_map, TNode<Smi> length, Node* allocation_site = nullptr);
// //
// Allocate and return a JSArray with initialized header fields and its // Allocate and return a JSArray with initialized header fields and its
// uninitialized elements. // uninitialized elements.
...@@ -1478,6 +1475,12 @@ class V8_EXPORT_PRIVATE CodeStubAssembler ...@@ -1478,6 +1475,12 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
INTPTR_PARAMETERS); INTPTR_PARAMETERS);
} }
// Allocate a JSArray and initialize the header fields.
TNode<JSArray> AllocateJSArray(TNode<Map> array_map,
TNode<FixedArrayBase> elements,
TNode<Smi> length,
Node* allocation_site = nullptr);
enum class HoleConversionMode { kDontConvert, kConvertToUndefined }; enum class HoleConversionMode { kDontConvert, kConvertToUndefined };
// Clone a fast JSArray |array| into a new fast JSArray. // Clone a fast JSArray |array| into a new fast JSArray.
// |convert_holes| tells the function to convert holes into undefined or not. // |convert_holes| tells the function to convert holes into undefined or not.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment