Commit 9cf33338 authored by ishell's avatar ishell Committed by Commit bot

[stubs] Factor CSA::GrowElementsCapacity() out of existing code.

... and rename CheckAndGrowElementsCapacity() to TryGrowElementsCapacity().

Review-Url: https://codereview.chromium.org/2324863002
Cr-Commit-Position: refs/heads/master@{#39307}
parent 0681deb9
......@@ -108,9 +108,8 @@ void Builtins::Generate_GrowFastDoubleElements(CodeStubAssembler* assembler) {
Label runtime(assembler, CodeStubAssembler::Label::kDeferred);
Node* elements = assembler->LoadElements(object);
elements = assembler->CheckAndGrowElementsCapacity(
context, elements, FAST_DOUBLE_ELEMENTS, key, &runtime);
assembler->StoreObjectField(object, JSObject::kElementsOffset, elements);
elements = assembler->TryGrowElementsCapacity(
object, elements, FAST_DOUBLE_ELEMENTS, key, &runtime);
assembler->Return(elements);
assembler->Bind(&runtime);
......@@ -129,9 +128,8 @@ void Builtins::Generate_GrowFastSmiOrObjectElements(
Label runtime(assembler, CodeStubAssembler::Label::kDeferred);
Node* elements = assembler->LoadElements(object);
elements = assembler->CheckAndGrowElementsCapacity(
context, elements, FAST_ELEMENTS, key, &runtime);
assembler->StoreObjectField(object, JSObject::kElementsOffset, elements);
elements = assembler->TryGrowElementsCapacity(object, elements, FAST_ELEMENTS,
key, &runtime);
assembler->Return(elements);
assembler->Bind(&runtime);
......
......@@ -1690,43 +1690,64 @@ Node* CodeStubAssembler::CalculateNewElementsCapacity(Node* old_capacity,
}
}
Node* CodeStubAssembler::CheckAndGrowElementsCapacity(Node* context,
Node* elements,
ElementsKind kind,
Node* key, Label* fail) {
Node* CodeStubAssembler::TryGrowElementsCapacity(Node* object, Node* elements,
ElementsKind kind, Node* key,
Label* bailout) {
Node* capacity = LoadFixedArrayBaseLength(elements);
ParameterMode mode = OptimalParameterMode();
capacity = UntagParameter(capacity, mode);
key = UntagParameter(key, mode);
return TryGrowElementsCapacity(object, elements, kind, key, capacity, mode,
bailout);
}
Node* CodeStubAssembler::TryGrowElementsCapacity(Node* object, Node* elements,
ElementsKind kind, Node* key,
Node* capacity,
ParameterMode mode,
Label* bailout) {
Comment("TryGrowElementsCapacity");
// If the gap growth is too big, fall back to the runtime.
Node* max_gap = IntPtrOrSmiConstant(JSObject::kMaxGap, mode);
Node* max_capacity = IntPtrAdd(capacity, max_gap);
GotoIf(UintPtrGreaterThanOrEqual(key, max_capacity), fail);
GotoIf(UintPtrGreaterThanOrEqual(key, max_capacity), bailout);
// Calculate the capacity of the new backing tore
// Calculate the capacity of the new backing store.
Node* new_capacity = CalculateNewElementsCapacity(
IntPtrAdd(key, IntPtrOrSmiConstant(1, mode)), mode);
return GrowElementsCapacity(object, elements, kind, kind, capacity,
new_capacity, mode, bailout);
}
Node* CodeStubAssembler::GrowElementsCapacity(
Node* object, Node* elements, ElementsKind from_kind, ElementsKind to_kind,
Node* capacity, Node* new_capacity, ParameterMode mode, Label* bailout) {
Comment("[ GrowElementsCapacity");
// If size of the allocation for the new capacity doesn't fit in a page
// that we can bump-pointer allocate from, fall back to the runtime,
int max_size = FixedArrayBase::GetMaxLengthForNewSpaceAllocation(kind);
// that we can bump-pointer allocate from, fall back to the runtime.
int max_size = FixedArrayBase::GetMaxLengthForNewSpaceAllocation(to_kind);
GotoIf(UintPtrGreaterThanOrEqual(new_capacity,
IntPtrOrSmiConstant(max_size, mode)),
fail);
bailout);
// Allocate the new backing store.
Node* new_elements = AllocateFixedArray(kind, new_capacity, mode);
Node* new_elements = AllocateFixedArray(to_kind, new_capacity, mode);
// Fill in the added capacity in the new store with holes.
FillFixedArrayWithValue(kind, new_elements, capacity, new_capacity,
FillFixedArrayWithValue(to_kind, new_elements, capacity, new_capacity,
Heap::kTheHoleValueRootIndex, mode);
// Copy the elements from the old elements store to the new.
CopyFixedArrayElements(kind, elements, new_elements, capacity,
SKIP_WRITE_BARRIER, mode);
// The size-check above guarantees that the |new_elements| is allocated
// in new space so we can skip the write barrier.
CopyFixedArrayElements(from_kind, elements, to_kind, new_elements, capacity,
new_capacity, SKIP_WRITE_BARRIER, mode);
StoreObjectField(object, JSObject::kElementsOffset, new_elements);
Comment("] GrowElementsCapacity");
return new_elements;
}
......
......@@ -366,11 +366,28 @@ class CodeStubAssembler : public compiler::CodeAssembler {
compiler::Node* CalculateNewElementsCapacity(
compiler::Node* old_capacity, ParameterMode mode = INTEGER_PARAMETERS);
compiler::Node* CheckAndGrowElementsCapacity(compiler::Node* context,
compiler::Node* elements,
ElementsKind kind,
compiler::Node* key,
Label* fail);
// Tries to grow the |elements| array of given |object| to store the |key|
// or bails out if the growing gap is too big. Returns new elements.
compiler::Node* TryGrowElementsCapacity(compiler::Node* object,
compiler::Node* elements,
ElementsKind kind,
compiler::Node* key, Label* bailout);
// Tries to grow the |capacity|-length |elements| array of given |object|
// to store the |key| or bails out if the growing gap is too big. Returns
// new elements.
compiler::Node* TryGrowElementsCapacity(compiler::Node* object,
compiler::Node* elements,
ElementsKind kind,
compiler::Node* key,
compiler::Node* capacity,
ParameterMode mode, Label* bailout);
// Grows elements capacity of given object. Returns new elements.
compiler::Node* GrowElementsCapacity(
compiler::Node* object, compiler::Node* elements, ElementsKind from_kind,
ElementsKind to_kind, compiler::Node* capacity,
compiler::Node* new_capacity, ParameterMode mode, Label* bailout);
// Allocation site manipulation
void InitializeAllocationMemento(compiler::Node* base_allocation,
......
......@@ -5798,9 +5798,8 @@ void GrowArrayElementsStub::GenerateAssembly(
ElementsKind kind = elements_kind();
Node* elements = assembler->LoadElements(object);
Node* new_elements = assembler->CheckAndGrowElementsCapacity(
context, elements, kind, key, &runtime);
assembler->StoreObjectField(object, JSObject::kElementsOffset, new_elements);
Node* new_elements =
assembler->TryGrowElementsCapacity(object, elements, kind, key, &runtime);
assembler->Return(new_elements);
assembler->Bind(&runtime);
......
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