Commit 985f7353 authored by Benedikt Meurer's avatar Benedikt Meurer Committed by Commit Bot

[cleanup] Remove obsolete ElementsAccessor::kCopyToEnd.

Also generally cleanup the Copy* code in elements.cc a bit.

Bug: v8:9183
Change-Id: I4a56db1f0b382a4b9583cae3b47e4ce572393d9e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1634249Reviewed-by: 's avatarSimon Zünd <szuend@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61908}
parent 060b9ec4
......@@ -141,6 +141,12 @@ WriteBarrierMode GetWriteBarrierMode(ElementsKind kind) {
return UPDATE_WRITE_BARRIER;
}
// If kCopyToEndAndInitializeToHole is specified as the copy_size to
// CopyElements, it copies all of elements from source after source_start to
// destination array, padding any remaining uninitialized elements in the
// destination array with the hole.
constexpr int kCopyToEndAndInitializeToHole = -1;
void CopyObjectToObjectElements(Isolate* isolate, FixedArrayBase from_base,
ElementsKind from_kind, uint32_t from_start,
FixedArrayBase to_base, ElementsKind to_kind,
......@@ -150,11 +156,9 @@ void CopyObjectToObjectElements(Isolate* isolate, FixedArrayBase from_base,
DisallowHeapAllocation no_allocation;
int copy_size = raw_copy_size;
if (raw_copy_size < 0) {
DCHECK(raw_copy_size == ElementsAccessor::kCopyToEnd ||
raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole);
DCHECK_EQ(kCopyToEndAndInitializeToHole, raw_copy_size);
copy_size =
Min(from_base.length() - from_start, to_base.length() - to_start);
if (raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole) {
int start = to_start + copy_size;
int length = to_base.length() - start;
if (length > 0) {
......@@ -162,7 +166,6 @@ void CopyObjectToObjectElements(Isolate* isolate, FixedArrayBase from_base,
roots.the_hole_value(), length);
}
}
}
DCHECK((copy_size + static_cast<int>(to_start)) <= to_base.length() &&
(copy_size + static_cast<int>(from_start)) <= from_base.length());
if (copy_size == 0) return;
......@@ -179,18 +182,16 @@ void CopyObjectToObjectElements(Isolate* isolate, FixedArrayBase from_base,
write_barrier_mode);
}
static void CopyDictionaryToObjectElements(
Isolate* isolate, FixedArrayBase from_base, uint32_t from_start,
FixedArrayBase to_base, ElementsKind to_kind, uint32_t to_start,
void CopyDictionaryToObjectElements(Isolate* isolate, FixedArrayBase from_base,
uint32_t from_start, FixedArrayBase to_base,
ElementsKind to_kind, uint32_t to_start,
int raw_copy_size) {
DisallowHeapAllocation no_allocation;
NumberDictionary from = NumberDictionary::cast(from_base);
int copy_size = raw_copy_size;
if (raw_copy_size < 0) {
DCHECK(raw_copy_size == ElementsAccessor::kCopyToEnd ||
raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole);
DCHECK_EQ(kCopyToEndAndInitializeToHole, raw_copy_size);
copy_size = from.max_number_key() + 1 - from_start;
if (raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole) {
int start = to_start + copy_size;
int length = to_base.length() - start;
if (length > 0) {
......@@ -198,7 +199,6 @@ static void CopyDictionaryToObjectElements(
ReadOnlyRoots(isolate).the_hole_value(), length);
}
}
}
DCHECK(to_base != from_base);
DCHECK(IsSmiOrObjectElementsKind(to_kind));
if (copy_size == 0) return;
......@@ -223,19 +223,15 @@ static void CopyDictionaryToObjectElements(
// NOTE: this method violates the handlified function signature convention:
// raw pointer parameters in the function that allocates.
// See ElementsAccessorBase::CopyElements() for details.
static void CopyDoubleToObjectElements(Isolate* isolate,
FixedArrayBase from_base,
uint32_t from_start,
FixedArrayBase to_base,
void CopyDoubleToObjectElements(Isolate* isolate, FixedArrayBase from_base,
uint32_t from_start, FixedArrayBase to_base,
uint32_t to_start, int raw_copy_size) {
int copy_size = raw_copy_size;
if (raw_copy_size < 0) {
DisallowHeapAllocation no_allocation;
DCHECK(raw_copy_size == ElementsAccessor::kCopyToEnd ||
raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole);
DCHECK_EQ(kCopyToEndAndInitializeToHole, raw_copy_size);
copy_size =
Min(from_base.length() - from_start, to_base.length() - to_start);
if (raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole) {
// Also initialize the area that will be copied over since HeapNumber
// allocation below can cause an incremental marking step, requiring all
// existing heap objects to be propertly initialized.
......@@ -246,7 +242,6 @@ static void CopyDoubleToObjectElements(Isolate* isolate,
ReadOnlyRoots(isolate).the_hole_value(), length);
}
}
}
DCHECK((copy_size + static_cast<int>(to_start)) <= to_base.length() &&
(copy_size + static_cast<int>(from_start)) <= from_base.length());
......@@ -272,23 +267,19 @@ static void CopyDoubleToObjectElements(Isolate* isolate,
}
}
static void CopyDoubleToDoubleElements(FixedArrayBase from_base,
uint32_t from_start,
FixedArrayBase to_base,
uint32_t to_start, int raw_copy_size) {
void CopyDoubleToDoubleElements(FixedArrayBase from_base, uint32_t from_start,
FixedArrayBase to_base, uint32_t to_start,
int raw_copy_size) {
DisallowHeapAllocation no_allocation;
int copy_size = raw_copy_size;
if (raw_copy_size < 0) {
DCHECK(raw_copy_size == ElementsAccessor::kCopyToEnd ||
raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole);
DCHECK_EQ(kCopyToEndAndInitializeToHole, raw_copy_size);
copy_size =
Min(from_base.length() - from_start, to_base.length() - to_start);
if (raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole) {
for (int i = to_start + copy_size; i < to_base.length(); ++i) {
FixedDoubleArray::cast(to_base).set_the_hole(i);
}
}
}
DCHECK((copy_size + static_cast<int>(to_start)) <= to_base.length() &&
(copy_size + static_cast<int>(from_start)) <= from_base.length());
if (copy_size == 0) return;
......@@ -312,21 +303,18 @@ static void CopyDoubleToDoubleElements(FixedArrayBase from_base,
#endif
}
static void CopySmiToDoubleElements(FixedArrayBase from_base,
uint32_t from_start, FixedArrayBase to_base,
uint32_t to_start, int raw_copy_size) {
void CopySmiToDoubleElements(FixedArrayBase from_base, uint32_t from_start,
FixedArrayBase to_base, uint32_t to_start,
int raw_copy_size) {
DisallowHeapAllocation no_allocation;
int copy_size = raw_copy_size;
if (raw_copy_size < 0) {
DCHECK(raw_copy_size == ElementsAccessor::kCopyToEnd ||
raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole);
DCHECK_EQ(kCopyToEndAndInitializeToHole, raw_copy_size);
copy_size = from_base.length() - from_start;
if (raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole) {
for (int i = to_start + copy_size; i < to_base.length(); ++i) {
FixedDoubleArray::cast(to_base).set_the_hole(i);
}
}
}
DCHECK((copy_size + static_cast<int>(to_start)) <= to_base.length() &&
(copy_size + static_cast<int>(from_start)) <= from_base.length());
if (copy_size == 0) return;
......@@ -344,19 +332,16 @@ static void CopySmiToDoubleElements(FixedArrayBase from_base,
}
}
static void CopyPackedSmiToDoubleElements(FixedArrayBase from_base,
uint32_t from_start,
FixedArrayBase to_base,
void CopyPackedSmiToDoubleElements(FixedArrayBase from_base,
uint32_t from_start, FixedArrayBase to_base,
uint32_t to_start, int packed_size,
int raw_copy_size) {
DisallowHeapAllocation no_allocation;
int copy_size = raw_copy_size;
uint32_t to_end;
if (raw_copy_size < 0) {
DCHECK(raw_copy_size == ElementsAccessor::kCopyToEnd ||
raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole);
DCHECK_EQ(kCopyToEndAndInitializeToHole, raw_copy_size);
copy_size = packed_size - from_start;
if (raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole) {
to_end = to_base.length();
for (uint32_t i = to_start + copy_size; i < to_end; ++i) {
FixedDoubleArray::cast(to_base).set_the_hole(i);
......@@ -364,9 +349,6 @@ static void CopyPackedSmiToDoubleElements(FixedArrayBase from_base,
} else {
to_end = to_start + static_cast<uint32_t>(copy_size);
}
} else {
to_end = to_start + static_cast<uint32_t>(copy_size);
}
DCHECK(static_cast<int>(to_end) <= to_base.length());
DCHECK(packed_size >= 0 && packed_size <= copy_size);
DCHECK((copy_size + static_cast<int>(to_start)) <= to_base.length() &&
......@@ -382,22 +364,18 @@ static void CopyPackedSmiToDoubleElements(FixedArrayBase from_base,
}
}
static void CopyObjectToDoubleElements(FixedArrayBase from_base,
uint32_t from_start,
FixedArrayBase to_base,
uint32_t to_start, int raw_copy_size) {
void CopyObjectToDoubleElements(FixedArrayBase from_base, uint32_t from_start,
FixedArrayBase to_base, uint32_t to_start,
int raw_copy_size) {
DisallowHeapAllocation no_allocation;
int copy_size = raw_copy_size;
if (raw_copy_size < 0) {
DCHECK(raw_copy_size == ElementsAccessor::kCopyToEnd ||
raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole);
DCHECK_EQ(kCopyToEndAndInitializeToHole, raw_copy_size);
copy_size = from_base.length() - from_start;
if (raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole) {
for (int i = to_start + copy_size; i < to_base.length(); ++i) {
FixedDoubleArray::cast(to_base).set_the_hole(i);
}
}
}
DCHECK((copy_size + static_cast<int>(to_start)) <= to_base.length() &&
(copy_size + static_cast<int>(from_start)) <= from_base.length());
if (copy_size == 0) return;
......@@ -415,22 +393,19 @@ static void CopyObjectToDoubleElements(FixedArrayBase from_base,
}
}
static void CopyDictionaryToDoubleElements(
Isolate* isolate, FixedArrayBase from_base, uint32_t from_start,
FixedArrayBase to_base, uint32_t to_start, int raw_copy_size) {
void CopyDictionaryToDoubleElements(Isolate* isolate, FixedArrayBase from_base,
uint32_t from_start, FixedArrayBase to_base,
uint32_t to_start, int raw_copy_size) {
DisallowHeapAllocation no_allocation;
NumberDictionary from = NumberDictionary::cast(from_base);
int copy_size = raw_copy_size;
if (copy_size < 0) {
DCHECK(copy_size == ElementsAccessor::kCopyToEnd ||
copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole);
DCHECK_EQ(kCopyToEndAndInitializeToHole, copy_size);
copy_size = from.max_number_key() + 1 - from_start;
if (raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole) {
for (int i = to_start + copy_size; i < to_base.length(); ++i) {
FixedDoubleArray::cast(to_base).set_the_hole(i);
}
}
}
if (copy_size == 0) return;
FixedDoubleArray to = FixedDoubleArray::cast(to_base);
uint32_t to_length = to.length();
......@@ -447,7 +422,7 @@ static void CopyDictionaryToDoubleElements(
}
}
static void SortIndices(Isolate* isolate, Handle<FixedArray> indices,
void SortIndices(Isolate* isolate, Handle<FixedArray> indices,
uint32_t sort_size) {
// Use AtomicSlot wrapper to ensure that std::sort uses atomic load and
// store operations that are safe for concurrent marking.
......@@ -474,10 +449,9 @@ static void SortIndices(Isolate* isolate, Handle<FixedArray> indices,
ObjectSlot(end));
}
static Maybe<bool> IncludesValueSlowPath(Isolate* isolate,
Handle<JSObject> receiver,
Handle<Object> value,
uint32_t start_from, uint32_t length) {
Maybe<bool> IncludesValueSlowPath(Isolate* isolate, Handle<JSObject> receiver,
Handle<Object> value, uint32_t start_from,
uint32_t length) {
bool search_for_hole = value->IsUndefined(isolate);
for (uint32_t k = start_from; k < length; ++k) {
LookupIterator it(isolate, receiver, k);
......@@ -495,10 +469,8 @@ static Maybe<bool> IncludesValueSlowPath(Isolate* isolate,
return Just(false);
}
static Maybe<int64_t> IndexOfValueSlowPath(Isolate* isolate,
Handle<JSObject> receiver,
Handle<Object> value,
uint32_t start_from,
Maybe<int64_t> IndexOfValueSlowPath(Isolate* isolate, Handle<JSObject> receiver,
Handle<Object> value, uint32_t start_from,
uint32_t length) {
for (uint32_t k = start_from; k < length; ++k) {
LookupIterator it(isolate, receiver, k);
......@@ -804,22 +776,14 @@ class ElementsAccessorBase : public InternalElementsAccessor {
static Handle<FixedArrayBase> ConvertElementsWithCapacity(
Handle<JSObject> object, Handle<FixedArrayBase> old_elements,
ElementsKind from_kind, uint32_t capacity) {
return ConvertElementsWithCapacity(
object, old_elements, from_kind, capacity, 0, 0,
ElementsAccessor::kCopyToEndAndInitializeToHole);
}
static Handle<FixedArrayBase> ConvertElementsWithCapacity(
Handle<JSObject> object, Handle<FixedArrayBase> old_elements,
ElementsKind from_kind, uint32_t capacity, int copy_size) {
return ConvertElementsWithCapacity(object, old_elements, from_kind,
capacity, 0, 0, copy_size);
capacity, 0, 0);
}
static Handle<FixedArrayBase> ConvertElementsWithCapacity(
Handle<JSObject> object, Handle<FixedArrayBase> old_elements,
ElementsKind from_kind, uint32_t capacity, uint32_t src_index,
uint32_t dst_index, int copy_size) {
uint32_t dst_index) {
Isolate* isolate = object->GetIsolate();
Handle<FixedArrayBase> new_elements;
if (IsDoubleElementsKind(kind())) {
......@@ -834,7 +798,8 @@ class ElementsAccessorBase : public InternalElementsAccessor {
}
Subclass::CopyElementsImpl(isolate, *old_elements, src_index, *new_elements,
from_kind, dst_index, packed_size, copy_size);
from_kind, dst_index, packed_size,
kCopyToEndAndInitializeToHole);
return new_elements;
}
......@@ -2394,7 +2359,7 @@ class FastElementsAccessor : public ElementsAccessorBase<Subclass, KindTraits> {
// Copy over all objects to a new backing_store.
backing_store = Subclass::ConvertElementsWithCapacity(
receiver, backing_store, KindTraits::Kind, capacity, 0,
copy_dst_index, ElementsAccessor::kCopyToEndAndInitializeToHole);
copy_dst_index);
receiver->set_elements(*backing_store);
} else if (add_position == AT_START) {
// If the backing store has enough capacity and we add elements to the
......
......@@ -66,15 +66,6 @@ class ElementsAccessor {
// element that is non-deletable.
virtual void SetLength(Handle<JSArray> holder, uint32_t new_length) = 0;
// If kCopyToEnd is specified as the copy_size to CopyElements, it copies all
// of elements from source after source_start to the destination array.
static const int kCopyToEnd = -1;
// If kCopyToEndAndInitializeToHole is specified as the copy_size to
// CopyElements, it copies all of elements from source after source_start to
// destination array, padding any remaining uninitialized elements in the
// destination array with the hole.
static const int kCopyToEndAndInitializeToHole = -2;
// Copy all indices that have elements from |object| into the given
// KeyAccumulator. For Dictionary-based element-kinds we filter out elements
// whose PropertyAttribute match |filter|.
......
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