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) { ...@@ -141,6 +141,12 @@ WriteBarrierMode GetWriteBarrierMode(ElementsKind kind) {
return UPDATE_WRITE_BARRIER; 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, void CopyObjectToObjectElements(Isolate* isolate, FixedArrayBase from_base,
ElementsKind from_kind, uint32_t from_start, ElementsKind from_kind, uint32_t from_start,
FixedArrayBase to_base, ElementsKind to_kind, FixedArrayBase to_base, ElementsKind to_kind,
...@@ -150,17 +156,14 @@ void CopyObjectToObjectElements(Isolate* isolate, FixedArrayBase from_base, ...@@ -150,17 +156,14 @@ void CopyObjectToObjectElements(Isolate* isolate, FixedArrayBase from_base,
DisallowHeapAllocation no_allocation; DisallowHeapAllocation no_allocation;
int copy_size = raw_copy_size; int copy_size = raw_copy_size;
if (raw_copy_size < 0) { if (raw_copy_size < 0) {
DCHECK(raw_copy_size == ElementsAccessor::kCopyToEnd || DCHECK_EQ(kCopyToEndAndInitializeToHole, raw_copy_size);
raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole);
copy_size = copy_size =
Min(from_base.length() - from_start, to_base.length() - to_start); Min(from_base.length() - from_start, to_base.length() - to_start);
if (raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole) { int start = to_start + copy_size;
int start = to_start + copy_size; int length = to_base.length() - start;
int length = to_base.length() - start; if (length > 0) {
if (length > 0) { MemsetTagged(FixedArray::cast(to_base).RawFieldOfElementAt(start),
MemsetTagged(FixedArray::cast(to_base).RawFieldOfElementAt(start), roots.the_hole_value(), length);
roots.the_hole_value(), length);
}
} }
} }
DCHECK((copy_size + static_cast<int>(to_start)) <= to_base.length() && DCHECK((copy_size + static_cast<int>(to_start)) <= to_base.length() &&
...@@ -179,24 +182,21 @@ void CopyObjectToObjectElements(Isolate* isolate, FixedArrayBase from_base, ...@@ -179,24 +182,21 @@ void CopyObjectToObjectElements(Isolate* isolate, FixedArrayBase from_base,
write_barrier_mode); write_barrier_mode);
} }
static void CopyDictionaryToObjectElements( void CopyDictionaryToObjectElements(Isolate* isolate, FixedArrayBase from_base,
Isolate* isolate, FixedArrayBase from_base, uint32_t from_start, uint32_t from_start, FixedArrayBase to_base,
FixedArrayBase to_base, ElementsKind to_kind, uint32_t to_start, ElementsKind to_kind, uint32_t to_start,
int raw_copy_size) { int raw_copy_size) {
DisallowHeapAllocation no_allocation; DisallowHeapAllocation no_allocation;
NumberDictionary from = NumberDictionary::cast(from_base); NumberDictionary from = NumberDictionary::cast(from_base);
int copy_size = raw_copy_size; int copy_size = raw_copy_size;
if (raw_copy_size < 0) { if (raw_copy_size < 0) {
DCHECK(raw_copy_size == ElementsAccessor::kCopyToEnd || DCHECK_EQ(kCopyToEndAndInitializeToHole, raw_copy_size);
raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole);
copy_size = from.max_number_key() + 1 - from_start; copy_size = from.max_number_key() + 1 - from_start;
if (raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole) { int start = to_start + copy_size;
int start = to_start + copy_size; int length = to_base.length() - start;
int length = to_base.length() - start; if (length > 0) {
if (length > 0) { MemsetTagged(FixedArray::cast(to_base).RawFieldOfElementAt(start),
MemsetTagged(FixedArray::cast(to_base).RawFieldOfElementAt(start), ReadOnlyRoots(isolate).the_hole_value(), length);
ReadOnlyRoots(isolate).the_hole_value(), length);
}
} }
} }
DCHECK(to_base != from_base); DCHECK(to_base != from_base);
...@@ -223,28 +223,23 @@ static void CopyDictionaryToObjectElements( ...@@ -223,28 +223,23 @@ static void CopyDictionaryToObjectElements(
// NOTE: this method violates the handlified function signature convention: // NOTE: this method violates the handlified function signature convention:
// raw pointer parameters in the function that allocates. // raw pointer parameters in the function that allocates.
// See ElementsAccessorBase::CopyElements() for details. // See ElementsAccessorBase::CopyElements() for details.
static void CopyDoubleToObjectElements(Isolate* isolate, void CopyDoubleToObjectElements(Isolate* isolate, FixedArrayBase from_base,
FixedArrayBase from_base, uint32_t from_start, FixedArrayBase to_base,
uint32_t from_start, uint32_t to_start, int raw_copy_size) {
FixedArrayBase to_base,
uint32_t to_start, int raw_copy_size) {
int copy_size = raw_copy_size; int copy_size = raw_copy_size;
if (raw_copy_size < 0) { if (raw_copy_size < 0) {
DisallowHeapAllocation no_allocation; DisallowHeapAllocation no_allocation;
DCHECK(raw_copy_size == ElementsAccessor::kCopyToEnd || DCHECK_EQ(kCopyToEndAndInitializeToHole, raw_copy_size);
raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole);
copy_size = copy_size =
Min(from_base.length() - from_start, to_base.length() - to_start); 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
// Also initialize the area that will be copied over since HeapNumber // allocation below can cause an incremental marking step, requiring all
// allocation below can cause an incremental marking step, requiring all // existing heap objects to be propertly initialized.
// existing heap objects to be propertly initialized. int start = to_start;
int start = to_start; int length = to_base.length() - start;
int length = to_base.length() - start; if (length > 0) {
if (length > 0) { MemsetTagged(FixedArray::cast(to_base).RawFieldOfElementAt(start),
MemsetTagged(FixedArray::cast(to_base).RawFieldOfElementAt(start), ReadOnlyRoots(isolate).the_hole_value(), length);
ReadOnlyRoots(isolate).the_hole_value(), length);
}
} }
} }
...@@ -272,21 +267,17 @@ static void CopyDoubleToObjectElements(Isolate* isolate, ...@@ -272,21 +267,17 @@ static void CopyDoubleToObjectElements(Isolate* isolate,
} }
} }
static void CopyDoubleToDoubleElements(FixedArrayBase from_base, void CopyDoubleToDoubleElements(FixedArrayBase from_base, uint32_t from_start,
uint32_t from_start, FixedArrayBase to_base, uint32_t to_start,
FixedArrayBase to_base, int raw_copy_size) {
uint32_t to_start, int raw_copy_size) {
DisallowHeapAllocation no_allocation; DisallowHeapAllocation no_allocation;
int copy_size = raw_copy_size; int copy_size = raw_copy_size;
if (raw_copy_size < 0) { if (raw_copy_size < 0) {
DCHECK(raw_copy_size == ElementsAccessor::kCopyToEnd || DCHECK_EQ(kCopyToEndAndInitializeToHole, raw_copy_size);
raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole);
copy_size = copy_size =
Min(from_base.length() - from_start, to_base.length() - to_start); 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) {
for (int i = to_start + copy_size; i < to_base.length(); ++i) { FixedDoubleArray::cast(to_base).set_the_hole(i);
FixedDoubleArray::cast(to_base).set_the_hole(i);
}
} }
} }
DCHECK((copy_size + static_cast<int>(to_start)) <= to_base.length() && DCHECK((copy_size + static_cast<int>(to_start)) <= to_base.length() &&
...@@ -312,19 +303,16 @@ static void CopyDoubleToDoubleElements(FixedArrayBase from_base, ...@@ -312,19 +303,16 @@ static void CopyDoubleToDoubleElements(FixedArrayBase from_base,
#endif #endif
} }
static void CopySmiToDoubleElements(FixedArrayBase from_base, void CopySmiToDoubleElements(FixedArrayBase from_base, uint32_t from_start,
uint32_t from_start, FixedArrayBase to_base, FixedArrayBase to_base, uint32_t to_start,
uint32_t to_start, int raw_copy_size) { int raw_copy_size) {
DisallowHeapAllocation no_allocation; DisallowHeapAllocation no_allocation;
int copy_size = raw_copy_size; int copy_size = raw_copy_size;
if (raw_copy_size < 0) { if (raw_copy_size < 0) {
DCHECK(raw_copy_size == ElementsAccessor::kCopyToEnd || DCHECK_EQ(kCopyToEndAndInitializeToHole, raw_copy_size);
raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole);
copy_size = from_base.length() - from_start; 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) {
for (int i = to_start + copy_size; i < to_base.length(); ++i) { FixedDoubleArray::cast(to_base).set_the_hole(i);
FixedDoubleArray::cast(to_base).set_the_hole(i);
}
} }
} }
DCHECK((copy_size + static_cast<int>(to_start)) <= to_base.length() && DCHECK((copy_size + static_cast<int>(to_start)) <= to_base.length() &&
...@@ -344,25 +332,19 @@ static void CopySmiToDoubleElements(FixedArrayBase from_base, ...@@ -344,25 +332,19 @@ static void CopySmiToDoubleElements(FixedArrayBase from_base,
} }
} }
static void CopyPackedSmiToDoubleElements(FixedArrayBase from_base, void CopyPackedSmiToDoubleElements(FixedArrayBase from_base,
uint32_t from_start, uint32_t from_start, FixedArrayBase to_base,
FixedArrayBase to_base, uint32_t to_start, int packed_size,
uint32_t to_start, int packed_size, int raw_copy_size) {
int raw_copy_size) {
DisallowHeapAllocation no_allocation; DisallowHeapAllocation no_allocation;
int copy_size = raw_copy_size; int copy_size = raw_copy_size;
uint32_t to_end; uint32_t to_end;
if (raw_copy_size < 0) { if (raw_copy_size < 0) {
DCHECK(raw_copy_size == ElementsAccessor::kCopyToEnd || DCHECK_EQ(kCopyToEndAndInitializeToHole, raw_copy_size);
raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole);
copy_size = packed_size - from_start; copy_size = packed_size - from_start;
if (raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole) { to_end = to_base.length();
to_end = to_base.length(); for (uint32_t i = to_start + copy_size; i < to_end; ++i) {
for (uint32_t i = to_start + copy_size; i < to_end; ++i) { FixedDoubleArray::cast(to_base).set_the_hole(i);
FixedDoubleArray::cast(to_base).set_the_hole(i);
}
} else {
to_end = to_start + static_cast<uint32_t>(copy_size);
} }
} else { } else {
to_end = to_start + static_cast<uint32_t>(copy_size); to_end = to_start + static_cast<uint32_t>(copy_size);
...@@ -382,20 +364,16 @@ static void CopyPackedSmiToDoubleElements(FixedArrayBase from_base, ...@@ -382,20 +364,16 @@ static void CopyPackedSmiToDoubleElements(FixedArrayBase from_base,
} }
} }
static void CopyObjectToDoubleElements(FixedArrayBase from_base, void CopyObjectToDoubleElements(FixedArrayBase from_base, uint32_t from_start,
uint32_t from_start, FixedArrayBase to_base, uint32_t to_start,
FixedArrayBase to_base, int raw_copy_size) {
uint32_t to_start, int raw_copy_size) {
DisallowHeapAllocation no_allocation; DisallowHeapAllocation no_allocation;
int copy_size = raw_copy_size; int copy_size = raw_copy_size;
if (raw_copy_size < 0) { if (raw_copy_size < 0) {
DCHECK(raw_copy_size == ElementsAccessor::kCopyToEnd || DCHECK_EQ(kCopyToEndAndInitializeToHole, raw_copy_size);
raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole);
copy_size = from_base.length() - from_start; 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) {
for (int i = to_start + copy_size; i < to_base.length(); ++i) { FixedDoubleArray::cast(to_base).set_the_hole(i);
FixedDoubleArray::cast(to_base).set_the_hole(i);
}
} }
} }
DCHECK((copy_size + static_cast<int>(to_start)) <= to_base.length() && DCHECK((copy_size + static_cast<int>(to_start)) <= to_base.length() &&
...@@ -415,20 +393,17 @@ static void CopyObjectToDoubleElements(FixedArrayBase from_base, ...@@ -415,20 +393,17 @@ static void CopyObjectToDoubleElements(FixedArrayBase from_base,
} }
} }
static void CopyDictionaryToDoubleElements( void CopyDictionaryToDoubleElements(Isolate* isolate, FixedArrayBase from_base,
Isolate* isolate, FixedArrayBase from_base, uint32_t from_start, uint32_t from_start, FixedArrayBase to_base,
FixedArrayBase to_base, uint32_t to_start, int raw_copy_size) { uint32_t to_start, int raw_copy_size) {
DisallowHeapAllocation no_allocation; DisallowHeapAllocation no_allocation;
NumberDictionary from = NumberDictionary::cast(from_base); NumberDictionary from = NumberDictionary::cast(from_base);
int copy_size = raw_copy_size; int copy_size = raw_copy_size;
if (copy_size < 0) { if (copy_size < 0) {
DCHECK(copy_size == ElementsAccessor::kCopyToEnd || DCHECK_EQ(kCopyToEndAndInitializeToHole, copy_size);
copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole);
copy_size = from.max_number_key() + 1 - from_start; 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) {
for (int i = to_start + copy_size; i < to_base.length(); ++i) { FixedDoubleArray::cast(to_base).set_the_hole(i);
FixedDoubleArray::cast(to_base).set_the_hole(i);
}
} }
} }
if (copy_size == 0) return; if (copy_size == 0) return;
...@@ -447,8 +422,8 @@ static void CopyDictionaryToDoubleElements( ...@@ -447,8 +422,8 @@ static void CopyDictionaryToDoubleElements(
} }
} }
static void SortIndices(Isolate* isolate, Handle<FixedArray> indices, void SortIndices(Isolate* isolate, Handle<FixedArray> indices,
uint32_t sort_size) { uint32_t sort_size) {
// Use AtomicSlot wrapper to ensure that std::sort uses atomic load and // Use AtomicSlot wrapper to ensure that std::sort uses atomic load and
// store operations that are safe for concurrent marking. // store operations that are safe for concurrent marking.
AtomicSlot start(indices->GetFirstElementAddress()); AtomicSlot start(indices->GetFirstElementAddress());
...@@ -474,10 +449,9 @@ static void SortIndices(Isolate* isolate, Handle<FixedArray> indices, ...@@ -474,10 +449,9 @@ static void SortIndices(Isolate* isolate, Handle<FixedArray> indices,
ObjectSlot(end)); ObjectSlot(end));
} }
static Maybe<bool> IncludesValueSlowPath(Isolate* isolate, Maybe<bool> IncludesValueSlowPath(Isolate* isolate, Handle<JSObject> receiver,
Handle<JSObject> receiver, Handle<Object> value, uint32_t start_from,
Handle<Object> value, uint32_t length) {
uint32_t start_from, uint32_t length) {
bool search_for_hole = value->IsUndefined(isolate); bool search_for_hole = value->IsUndefined(isolate);
for (uint32_t k = start_from; k < length; ++k) { for (uint32_t k = start_from; k < length; ++k) {
LookupIterator it(isolate, receiver, k); LookupIterator it(isolate, receiver, k);
...@@ -495,11 +469,9 @@ static Maybe<bool> IncludesValueSlowPath(Isolate* isolate, ...@@ -495,11 +469,9 @@ static Maybe<bool> IncludesValueSlowPath(Isolate* isolate,
return Just(false); return Just(false);
} }
static Maybe<int64_t> IndexOfValueSlowPath(Isolate* isolate, Maybe<int64_t> IndexOfValueSlowPath(Isolate* isolate, Handle<JSObject> receiver,
Handle<JSObject> receiver, Handle<Object> value, uint32_t start_from,
Handle<Object> value, uint32_t length) {
uint32_t start_from,
uint32_t length) {
for (uint32_t k = start_from; k < length; ++k) { for (uint32_t k = start_from; k < length; ++k) {
LookupIterator it(isolate, receiver, k); LookupIterator it(isolate, receiver, k);
if (!it.IsFound()) { if (!it.IsFound()) {
...@@ -804,22 +776,14 @@ class ElementsAccessorBase : public InternalElementsAccessor { ...@@ -804,22 +776,14 @@ class ElementsAccessorBase : public InternalElementsAccessor {
static Handle<FixedArrayBase> ConvertElementsWithCapacity( static Handle<FixedArrayBase> ConvertElementsWithCapacity(
Handle<JSObject> object, Handle<FixedArrayBase> old_elements, Handle<JSObject> object, Handle<FixedArrayBase> old_elements,
ElementsKind from_kind, uint32_t capacity) { 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, return ConvertElementsWithCapacity(object, old_elements, from_kind,
capacity, 0, 0, copy_size); capacity, 0, 0);
} }
static Handle<FixedArrayBase> ConvertElementsWithCapacity( static Handle<FixedArrayBase> ConvertElementsWithCapacity(
Handle<JSObject> object, Handle<FixedArrayBase> old_elements, Handle<JSObject> object, Handle<FixedArrayBase> old_elements,
ElementsKind from_kind, uint32_t capacity, uint32_t src_index, 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(); Isolate* isolate = object->GetIsolate();
Handle<FixedArrayBase> new_elements; Handle<FixedArrayBase> new_elements;
if (IsDoubleElementsKind(kind())) { if (IsDoubleElementsKind(kind())) {
...@@ -834,7 +798,8 @@ class ElementsAccessorBase : public InternalElementsAccessor { ...@@ -834,7 +798,8 @@ class ElementsAccessorBase : public InternalElementsAccessor {
} }
Subclass::CopyElementsImpl(isolate, *old_elements, src_index, *new_elements, 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; return new_elements;
} }
...@@ -2394,7 +2359,7 @@ class FastElementsAccessor : public ElementsAccessorBase<Subclass, KindTraits> { ...@@ -2394,7 +2359,7 @@ class FastElementsAccessor : public ElementsAccessorBase<Subclass, KindTraits> {
// Copy over all objects to a new backing_store. // Copy over all objects to a new backing_store.
backing_store = Subclass::ConvertElementsWithCapacity( backing_store = Subclass::ConvertElementsWithCapacity(
receiver, backing_store, KindTraits::Kind, capacity, 0, receiver, backing_store, KindTraits::Kind, capacity, 0,
copy_dst_index, ElementsAccessor::kCopyToEndAndInitializeToHole); copy_dst_index);
receiver->set_elements(*backing_store); receiver->set_elements(*backing_store);
} else if (add_position == AT_START) { } else if (add_position == AT_START) {
// If the backing store has enough capacity and we add elements to the // If the backing store has enough capacity and we add elements to the
......
...@@ -66,15 +66,6 @@ class ElementsAccessor { ...@@ -66,15 +66,6 @@ class ElementsAccessor {
// element that is non-deletable. // element that is non-deletable.
virtual void SetLength(Handle<JSArray> holder, uint32_t new_length) = 0; 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 // Copy all indices that have elements from |object| into the given
// KeyAccumulator. For Dictionary-based element-kinds we filter out elements // KeyAccumulator. For Dictionary-based element-kinds we filter out elements
// whose PropertyAttribute match |filter|. // 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