[heap] Add optimized RecordWrites

BUG=

Review URL: https://codereview.chromium.org/1834373003

Cr-Commit-Position: refs/heads/master@{#35231}
This commit is contained in:
cbruni 2016-04-04 02:54:06 -07:00 committed by Commit bot
parent 3d4f85ab9f
commit 5210f167e8
5 changed files with 27 additions and 17 deletions

View File

@ -1011,13 +1011,10 @@ class ElementsAccessorBase : public ElementsAccessor {
&array_length) &&
array_length <= Smi::kMaxValue)) {
// Since we use std::sort above, the GC will no longer know where the
// HeapNumbers are, hence we have to write them again.
// For Arrays with valid Smi length, we are sure to have no HeapNumber
// indices and thus we can skip this step.
for (uint32_t i = 0; i < nof_indices; i++) {
Object* index = combined_keys->get(i);
combined_keys->set(i, index);
}
// HeapNumbers are. For Arrays with valid Smi length, we are sure to
// have no HeapNumber indices and thus we can skip this step.
FIXED_ARRAY_ELEMENTS_WRITE_BARRIER(isolate->heap(), *combined_keys, 0,
nof_indices);
}
}

View File

@ -399,9 +399,20 @@ void Heap::RecordWrite(Object* object, int offset, Object* o) {
if (!InNewSpace(o) || !object->IsHeapObject() || InNewSpace(object)) {
return;
}
Page* page = Page::FromAddress(reinterpret_cast<Address>(object));
Address slot = HeapObject::cast(object)->address() + offset;
RememberedSet<OLD_TO_NEW>::Insert(page, slot);
RememberedSet<OLD_TO_NEW>::Insert(
Page::FromAddress(reinterpret_cast<Address>(object)),
HeapObject::cast(object)->address() + offset);
}
void Heap::RecordFixedArrayElements(FixedArray* array, int offset, int length) {
if (InNewSpace(array)) return;
Page* page = Page::FromAddress(reinterpret_cast<Address>(array));
for (int i = 0; i < length; i++) {
if (!InNewSpace(array->get(i))) continue;
RememberedSet<OLD_TO_NEW>::Insert(
page,
reinterpret_cast<Address>(array->RawFieldOfElementAt(offset + i)));
}
}

View File

@ -1111,13 +1111,7 @@ void Heap::MoveElements(FixedArray* array, int dst_index, int src_index,
DCHECK(array->map() != fixed_cow_array_map());
Object** dst_objects = array->data_start() + dst_index;
MemMove(dst_objects, array->data_start() + src_index, len * kPointerSize);
if (!InNewSpace(array)) {
for (int i = 0; i < len; i++) {
RecordWrite(array, array->OffsetOfElementAt(dst_index + i),
dst_objects[i]);
}
}
incremental_marking()->IterateBlackObject(array);
FIXED_ARRAY_ELEMENTS_WRITE_BARRIER(this, array, dst_index, src_index);
}

View File

@ -1084,6 +1084,8 @@ class Heap {
// Write barrier support for object[offset] = o;
inline void RecordWrite(Object* object, int offset, Object* o);
inline void RecordFixedArrayElements(FixedArray* array, int offset,
int length);
Address* store_buffer_top_address() { return store_buffer()->top_address(); }

View File

@ -1149,6 +1149,12 @@ MaybeHandle<Object> JSReceiver::GetProperty(Isolate* isolate,
object, HeapObject::RawField(object, offset), value); \
heap->RecordWrite(object, offset, value);
#define FIXED_ARRAY_ELEMENTS_WRITE_BARRIER(heap, array, start, length) \
do { \
heap->RecordFixedArrayElements(array, start, length); \
heap->incremental_marking()->IterateBlackObject(array); \
} while (false)
#define CONDITIONAL_WRITE_BARRIER(heap, object, offset, value, mode) \
if (mode != SKIP_WRITE_BARRIER) { \
if (mode == UPDATE_WRITE_BARRIER) { \