Commit 6c3d86d8 authored by jgruber's avatar jgruber Committed by Commit Bot

[regexp] Fold allocations for JSRegExpResult

This folds the allocation of the JSRegExpResult (basically a JSArray)
together with its elements fixed array.

Bug: v8:6741
Change-Id: I027c4fce7169c1bd6a17637619fdf3890e3f7f24
Reviewed-on: https://chromium-review.googlesource.com/625877
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47536}
parent 8bf15bf1
......@@ -32,36 +32,52 @@ Node* RegExpBuiltinsAssembler::AllocateRegExpResult(Node* context, Node* length,
CSA_ASSERT(this, SmiLessThanOrEqual(length, max_length));
#endif // DEBUG
// Allocate the JSRegExpResult.
// TODO(jgruber): Fold JSArray and FixedArray allocations, then remove
// unneeded store of elements.
Node* const result = Allocate(JSRegExpResult::kSize);
// Allocate the JSRegExpResult together with its elements fixed array.
// Initial preparations first.
Node* const length_intptr = SmiUntag(length);
const ElementsKind elements_kind = PACKED_ELEMENTS;
Node* const elements_size = GetFixedArrayAllocationSize(
length_intptr, elements_kind, INTPTR_PARAMETERS);
Node* const total_size =
IntPtrAdd(elements_size, IntPtrConstant(JSRegExpResult::kSize));
static const int kRegExpResultOffset = 0;
static const int kElementsOffset =
kRegExpResultOffset + JSRegExpResult::kSize;
// The folded allocation.
Node* const result = Allocate(total_size);
Node* const elements = InnerAllocate(result, kElementsOffset);
// Initialize the JSRegExpResult.
// TODO(jgruber): Store map as Heap constant?
Node* const native_context = LoadNativeContext(context);
Node* const map =
LoadContextElement(native_context, Context::REGEXP_RESULT_MAP_INDEX);
StoreMapNoWriteBarrier(result, map);
// Initialize the header before allocating the elements.
Node* const empty_array = EmptyFixedArrayConstant();
DCHECK(Heap::RootIsImmortalImmovable(Heap::kEmptyFixedArrayRootIndex));
StoreObjectFieldNoWriteBarrier(result, JSArray::kPropertiesOrHashOffset,
empty_array);
StoreObjectFieldNoWriteBarrier(result, JSArray::kElementsOffset, empty_array);
StoreObjectFieldNoWriteBarrier(result, JSArray::kElementsOffset, elements);
StoreObjectFieldNoWriteBarrier(result, JSArray::kLengthOffset, length);
StoreObjectFieldNoWriteBarrier(result, JSRegExpResult::kIndexOffset, index);
StoreObjectField(result, JSRegExpResult::kInputOffset, input);
Node* const zero = IntPtrConstant(0);
Node* const length_intptr = SmiUntag(length);
const ElementsKind elements_kind = PACKED_ELEMENTS;
// Initialize the elements.
Node* const elements = AllocateFixedArray(elements_kind, length_intptr);
StoreObjectField(result, JSArray::kElementsOffset, elements);
DCHECK(!IsDoubleElementsKind(elements_kind));
const Heap::RootListIndex map_index = Heap::kFixedArrayMapRootIndex;
DCHECK(Heap::RootIsImmortalImmovable(map_index));
StoreMapNoWriteBarrier(elements, map_index);
StoreObjectFieldNoWriteBarrier(elements, FixedArray::kLengthOffset, length);
// Fill in the elements with undefined.
Node* const zero = IntPtrConstant(0);
FillFixedArrayWithValue(elements_kind, elements, zero, length_intptr,
Heap::kUndefinedValueRootIndex);
......
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