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) { ...@@ -108,9 +108,8 @@ void Builtins::Generate_GrowFastDoubleElements(CodeStubAssembler* assembler) {
Label runtime(assembler, CodeStubAssembler::Label::kDeferred); Label runtime(assembler, CodeStubAssembler::Label::kDeferred);
Node* elements = assembler->LoadElements(object); Node* elements = assembler->LoadElements(object);
elements = assembler->CheckAndGrowElementsCapacity( elements = assembler->TryGrowElementsCapacity(
context, elements, FAST_DOUBLE_ELEMENTS, key, &runtime); object, elements, FAST_DOUBLE_ELEMENTS, key, &runtime);
assembler->StoreObjectField(object, JSObject::kElementsOffset, elements);
assembler->Return(elements); assembler->Return(elements);
assembler->Bind(&runtime); assembler->Bind(&runtime);
...@@ -129,9 +128,8 @@ void Builtins::Generate_GrowFastSmiOrObjectElements( ...@@ -129,9 +128,8 @@ void Builtins::Generate_GrowFastSmiOrObjectElements(
Label runtime(assembler, CodeStubAssembler::Label::kDeferred); Label runtime(assembler, CodeStubAssembler::Label::kDeferred);
Node* elements = assembler->LoadElements(object); Node* elements = assembler->LoadElements(object);
elements = assembler->CheckAndGrowElementsCapacity( elements = assembler->TryGrowElementsCapacity(object, elements, FAST_ELEMENTS,
context, elements, FAST_ELEMENTS, key, &runtime); key, &runtime);
assembler->StoreObjectField(object, JSObject::kElementsOffset, elements);
assembler->Return(elements); assembler->Return(elements);
assembler->Bind(&runtime); assembler->Bind(&runtime);
......
...@@ -1690,43 +1690,64 @@ Node* CodeStubAssembler::CalculateNewElementsCapacity(Node* old_capacity, ...@@ -1690,43 +1690,64 @@ Node* CodeStubAssembler::CalculateNewElementsCapacity(Node* old_capacity,
} }
} }
Node* CodeStubAssembler::CheckAndGrowElementsCapacity(Node* context, Node* CodeStubAssembler::TryGrowElementsCapacity(Node* object, Node* elements,
Node* elements, ElementsKind kind, Node* key,
ElementsKind kind, Label* bailout) {
Node* key, Label* fail) {
Node* capacity = LoadFixedArrayBaseLength(elements); Node* capacity = LoadFixedArrayBaseLength(elements);
ParameterMode mode = OptimalParameterMode(); ParameterMode mode = OptimalParameterMode();
capacity = UntagParameter(capacity, mode); capacity = UntagParameter(capacity, mode);
key = UntagParameter(key, 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. // If the gap growth is too big, fall back to the runtime.
Node* max_gap = IntPtrOrSmiConstant(JSObject::kMaxGap, mode); Node* max_gap = IntPtrOrSmiConstant(JSObject::kMaxGap, mode);
Node* max_capacity = IntPtrAdd(capacity, max_gap); 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( Node* new_capacity = CalculateNewElementsCapacity(
IntPtrAdd(key, IntPtrOrSmiConstant(1, mode)), mode); 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 // 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, // that we can bump-pointer allocate from, fall back to the runtime.
int max_size = FixedArrayBase::GetMaxLengthForNewSpaceAllocation(kind); int max_size = FixedArrayBase::GetMaxLengthForNewSpaceAllocation(to_kind);
GotoIf(UintPtrGreaterThanOrEqual(new_capacity, GotoIf(UintPtrGreaterThanOrEqual(new_capacity,
IntPtrOrSmiConstant(max_size, mode)), IntPtrOrSmiConstant(max_size, mode)),
fail); bailout);
// Allocate the new backing store. // 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. // 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); Heap::kTheHoleValueRootIndex, mode);
// Copy the elements from the old elements store to the new. // Copy the elements from the old elements store to the new.
CopyFixedArrayElements(kind, elements, new_elements, capacity, // The size-check above guarantees that the |new_elements| is allocated
SKIP_WRITE_BARRIER, mode); // 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; return new_elements;
} }
......
...@@ -366,11 +366,28 @@ class CodeStubAssembler : public compiler::CodeAssembler { ...@@ -366,11 +366,28 @@ class CodeStubAssembler : public compiler::CodeAssembler {
compiler::Node* CalculateNewElementsCapacity( compiler::Node* CalculateNewElementsCapacity(
compiler::Node* old_capacity, ParameterMode mode = INTEGER_PARAMETERS); compiler::Node* old_capacity, ParameterMode mode = INTEGER_PARAMETERS);
compiler::Node* CheckAndGrowElementsCapacity(compiler::Node* context, // Tries to grow the |elements| array of given |object| to store the |key|
compiler::Node* elements, // or bails out if the growing gap is too big. Returns new elements.
ElementsKind kind, compiler::Node* TryGrowElementsCapacity(compiler::Node* object,
compiler::Node* key, compiler::Node* elements,
Label* fail); 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 // Allocation site manipulation
void InitializeAllocationMemento(compiler::Node* base_allocation, void InitializeAllocationMemento(compiler::Node* base_allocation,
......
...@@ -5798,9 +5798,8 @@ void GrowArrayElementsStub::GenerateAssembly( ...@@ -5798,9 +5798,8 @@ void GrowArrayElementsStub::GenerateAssembly(
ElementsKind kind = elements_kind(); ElementsKind kind = elements_kind();
Node* elements = assembler->LoadElements(object); Node* elements = assembler->LoadElements(object);
Node* new_elements = assembler->CheckAndGrowElementsCapacity( Node* new_elements =
context, elements, kind, key, &runtime); assembler->TryGrowElementsCapacity(object, elements, kind, key, &runtime);
assembler->StoreObjectField(object, JSObject::kElementsOffset, new_elements);
assembler->Return(new_elements); assembler->Return(new_elements);
assembler->Bind(&runtime); 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