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(
CSA_ASSERT(this, IsJSArrayMap(array_map));
GotoIf(IntPtrEqual(size, IntPtrConstant(0)), if_empty);
Node* array = AllocateUninitializedJSArrayWithoutElements(
array_map, SmiTag(size), nullptr);
StoreObjectField(array, JSArray::kElementsOffset, result);
Node* array = AllocateJSArray(array_map, result, SmiTag(size));
return TNode<JSArray>::UncheckedCast(array);
}
......@@ -647,10 +645,8 @@ TF_BUILTIN(ObjectKeys, ObjectBuiltinsAssembler) {
Node* native_context = LoadNativeContext(context);
TNode<Map> array_map =
LoadJSArrayElementsMap(PACKED_ELEMENTS, native_context);
TNode<JSArray> array = AllocateUninitializedJSArrayWithoutElements(
array_map, CAST(var_length.value()), nullptr);
StoreObjectFieldNoWriteBarrier(array, JSArray::kElementsOffset,
var_elements.value());
TNode<JSArray> array = AllocateJSArray(
array_map, CAST(var_elements.value()), CAST(var_length.value()));
Return(array);
}
}
......@@ -751,10 +747,8 @@ TF_BUILTIN(ObjectGetOwnPropertyNames, ObjectBuiltinsAssembler) {
Node* native_context = LoadNativeContext(context);
TNode<Map> array_map =
LoadJSArrayElementsMap(PACKED_ELEMENTS, native_context);
TNode<JSArray> array = AllocateUninitializedJSArrayWithoutElements(
array_map, CAST(var_length.value()), nullptr);
StoreObjectFieldNoWriteBarrier(array, JSArray::kElementsOffset,
var_elements.value());
TNode<JSArray> array = AllocateJSArray(
array_map, CAST(var_elements.value()), CAST(var_length.value()));
Return(array);
}
}
......
......@@ -116,9 +116,7 @@ Node* ProxiesCodeStubAssembler::AllocateJSArrayForCodeStubArguments(
TNode<Map> array_map =
LoadJSArrayElementsMap(PACKED_ELEMENTS, native_context);
TNode<JSArray> array =
AllocateUninitializedJSArrayWithoutElements(array_map, length);
StoreObjectFieldNoWriteBarrier(array, JSObject::kElementsOffset,
elements.value());
AllocateJSArray(array_map, CAST(elements.value()), length);
return array;
}
......
......@@ -1803,9 +1803,7 @@ TNode<JSArray> StringBuiltinsAssembler::StringToArray(
1, ParameterMode::INTPTR_PARAMETERS, IndexAdvanceMode::kPost);
TNode<Map> array_map = LoadJSArrayElementsMap(PACKED_ELEMENTS, context);
result_array =
AllocateUninitializedJSArrayWithoutElements(array_map, length_smi);
StoreObjectField(result_array.value(), JSObject::kElementsOffset, elements);
result_array = AllocateJSArray(array_map, elements, length_smi);
Goto(&done);
BIND(&fill_thehole_and_call_runtime);
......
......@@ -56,11 +56,8 @@ TNode<JSArray> GrowableFixedArray::ToJSArray(TNode<Context> const context) {
}
TNode<Smi> const result_length = SmiTag(length());
TNode<JSArray> const result = AllocateUninitializedJSArrayWithoutElements(
array_map, result_length, nullptr);
StoreObjectField(result, JSObject::kElementsOffset, var_array_.value());
TNode<JSArray> const result =
AllocateJSArray(array_map, var_array_.value(), result_length);
return result;
}
......
......@@ -3832,9 +3832,10 @@ TNode<BoolT> CodeStubAssembler::IsValidFastJSArrayCapacity(
IntPtrConstant(JSArray::kMaxFastArrayLength)));
}
TNode<JSArray> CodeStubAssembler::AllocateUninitializedJSArrayWithoutElements(
TNode<Map> array_map, TNode<Smi> length, Node* allocation_site) {
Comment("begin allocation of JSArray without elements");
TNode<JSArray> CodeStubAssembler::AllocateJSArray(
TNode<Map> array_map, TNode<FixedArrayBase> elements, TNode<Smi> length,
Node* allocation_site) {
Comment("begin allocation of JSArray passing in elements");
CSA_SLOW_ASSERT(this, TaggedIsPositiveSmi(length));
int base_size = JSArray::kSize;
......@@ -3843,7 +3844,10 @@ TNode<JSArray> CodeStubAssembler::AllocateUninitializedJSArrayWithoutElements(
}
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>>
......@@ -3897,10 +3901,8 @@ CodeStubAssembler::AllocateUninitializedJSArrayWithElements(
// The JSArray and possibly allocation memento next. Note that
// allocation_flags are *not* passed on here and the resulting JSArray will
// always be in new space.
array = AllocateUninitializedJSArrayWithoutElements(array_map, length,
allocation_site);
StoreObjectFieldNoWriteBarrier(array.value(), JSObject::kElementsOffset,
elements.value());
array =
AllocateJSArray(array_map, elements.value(), length, allocation_site);
Goto(&out);
......@@ -3969,10 +3971,10 @@ TNode<JSArray> CodeStubAssembler::AllocateJSArray(
if (IsIntPtrOrSmiConstantZero(capacity, capacity_mode)) {
// Array is empty. Use the shared empty fixed array instead of allocating a
// new one.
array = AllocateUninitializedJSArrayWithoutElements(array_map, length,
allocation_site);
StoreObjectFieldRoot(array, JSArray::kElementsOffset,
RootIndex::kEmptyFixedArray);
TNode<FixedArrayBase> empty_fixed_array =
CAST(LoadRoot(RootIndex::kEmptyFixedArray));
array =
AllocateJSArray(array_map, empty_fixed_array, length, allocation_site);
} else if (TryGetIntPtrOrSmiConstantValue(capacity, &capacity_as_constant,
capacity_mode)) {
CHECK_GT(capacity_as_constant, 0);
......@@ -3995,10 +3997,10 @@ TNode<JSArray> CodeStubAssembler::AllocateJSArray(
{
// Array is empty. Use the shared empty fixed array instead of allocating
// a new one.
var_array = AllocateUninitializedJSArrayWithoutElements(array_map, length,
allocation_site);
StoreObjectFieldRoot(var_array.value(), JSArray::kElementsOffset,
RootIndex::kEmptyFixedArray);
TNode<FixedArrayBase> empty_fixed_array =
CAST(LoadRoot(RootIndex::kEmptyFixedArray));
var_array = AllocateJSArray(array_map, empty_fixed_array, length,
allocation_site);
Goto(&out);
}
......@@ -4035,13 +4037,12 @@ Node* CodeStubAssembler::ExtractFastJSArray(Node* context, Node* array,
Node* native_context = LoadNativeContext(context);
TNode<Map> array_map = LoadJSArrayElementsMap(elements_kind, native_context);
Node* new_elements = ExtractFixedArray(
TNode<FixedArrayBase> new_elements = ExtractFixedArray(
LoadElements(array), begin, count, capacity,
ExtractFixedArrayFlag::kAllFixedArrays, mode, nullptr, elements_kind);
TNode<Object> result = AllocateUninitializedJSArrayWithoutElements(
array_map, ParameterToTagged(count, mode), allocation_site);
StoreObjectField(result, JSObject::kElementsOffset, new_elements);
TNode<Object> result = AllocateJSArray(
array_map, new_elements, ParameterToTagged(count, mode), allocation_site);
return result;
}
......@@ -4105,9 +4106,8 @@ Node* CodeStubAssembler::CloneFastJSArray(Node* context, Node* array,
TNode<Map> array_map =
LoadJSArrayElementsMap(var_elements_kind.value(), native_context);
TNode<Object> result = AllocateUninitializedJSArrayWithoutElements(
array_map, CAST(length), allocation_site);
StoreObjectField(result, JSObject::kElementsOffset, var_new_elements.value());
TNode<Object> result = AllocateJSArray(
array_map, CAST(var_new_elements.value()), CAST(length), allocation_site);
return result;
}
......
......@@ -1444,9 +1444,6 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
TNode<BoolT> IsValidFastJSArrayCapacity(Node* capacity,
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
// uninitialized elements.
......@@ -1478,6 +1475,12 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
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 };
// Clone a fast JSArray |array| into a new fast JSArray.
// |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