Commit ecb92ad3 authored by Hannes Payer's avatar Hannes Payer Committed by Commit Bot

Allow write barrier elimination when copying elements from one array to another.

Change-Id: I878bc11ac8d4988b608507bced1363129c29a179
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1528993
Commit-Queue: Hannes Payer <hpayer@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60328}
parent b1f89b61
......@@ -166,10 +166,8 @@ void CopyObjectToObjectElements(Isolate* isolate, FixedArrayBase from_base,
(IsObjectElementsKind(from_kind) && IsObjectElementsKind(to_kind))
? UPDATE_WRITE_BARRIER
: SKIP_WRITE_BARRIER;
for (int i = 0; i < copy_size; i++) {
Object value = from->get(from_start + i);
to->set(to_start + i, value, write_barrier_mode);
}
to->CopyElements(isolate->heap(), to_start, from, from_start, copy_size,
write_barrier_mode);
}
static void CopyDictionaryToObjectElements(
......
......@@ -1499,7 +1499,7 @@ void Heap::MoveElements(FixedArray array, int dst_index, int src_index, int len,
WriteBarrierMode mode) {
if (len == 0) return;
DCHECK(array->map() != ReadOnlyRoots(this).fixed_cow_array_map());
DCHECK_NE(array->map(), ReadOnlyRoots(this).fixed_cow_array_map());
ObjectSlot dst = array->RawFieldOfElementAt(dst_index);
ObjectSlot src = array->RawFieldOfElementAt(src_index);
if (FLAG_concurrent_marking && incremental_marking()->IsMarking()) {
......@@ -1526,6 +1526,20 @@ void Heap::MoveElements(FixedArray array, int dst_index, int src_index, int len,
FIXED_ARRAY_ELEMENTS_WRITE_BARRIER(this, array, dst_index, len);
}
void Heap::CopyElements(FixedArray dst, FixedArray src, int dst_index,
int src_index, int len, WriteBarrierMode mode) {
DCHECK_NE(dst, src);
if (len == 0) return;
DCHECK_NE(dst->map(), ReadOnlyRoots(this).fixed_cow_array_map());
ObjectSlot dst_slot = dst->RawFieldOfElementAt(dst_index);
ObjectSlot src_slot = src->RawFieldOfElementAt(src_index);
MemMove(dst_slot.ToVoidPtr(), src_slot.ToVoidPtr(), len * kTaggedSize);
if (mode == SKIP_WRITE_BARRIER) return;
FIXED_ARRAY_ELEMENTS_WRITE_BARRIER(this, dst, dst_index, len);
}
#ifdef VERIFY_HEAP
// Helper class for verifying the string table.
class StringTableVerifier : public ObjectVisitor {
......
......@@ -365,6 +365,10 @@ class Heap {
void MoveElements(FixedArray array, int dst_index, int src_index, int len,
WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
// Copy len elements from src_index of src array to dst_index of dst array.
void CopyElements(FixedArray dst, FixedArray src, int dst_index,
int src_index, int len, WriteBarrierMode mode);
// Initialize a filler object to keep the ability to iterate over the heap
// when introducing gaps within pages. If slots could have been recorded in
// the freed area, then pass ClearRecordedSlots::kYes as the mode. Otherwise,
......
......@@ -208,6 +208,12 @@ void FixedArray::MoveElements(Heap* heap, int dst_index, int src_index, int len,
heap->MoveElements(*this, dst_index, src_index, len, mode);
}
void FixedArray::CopyElements(Heap* heap, int dst_index, FixedArray src,
int src_index, int len, WriteBarrierMode mode) {
DisallowHeapAllocation no_gc;
heap->CopyElements(*this, src, dst_index, src_index, len, mode);
}
// Perform a binary search in a fixed array.
template <SearchMode search_mode, typename T>
int BinarySearch(T* array, Name name, int valid_entries,
......
......@@ -156,6 +156,9 @@ class FixedArray : public FixedArrayBase {
inline void MoveElements(Heap* heap, int dst_index, int src_index, int len,
WriteBarrierMode mode);
inline void CopyElements(Heap* heap, int dst_index, FixedArray src,
int src_index, int len, WriteBarrierMode mode);
inline void FillWithHoles(int from, int to);
// Shrink the array and insert filler objects. {new_length} must be > 0.
......
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