Commit bbb74424 authored by cbruni's avatar cbruni Committed by Commit bot

Introduce set_the_hole(Isolate*, int) and friends

Passing in the isolate to retrieve the heap constants (undefine, the_hole, null)
has a positive performance impact.

BUG=

Review-Url: https://codereview.chromium.org/2517153002
Cr-Commit-Position: refs/heads/master@{#41210}
parent 5f5300a6
......@@ -185,14 +185,15 @@ static void CopyDictionaryToObjectElements(
WriteBarrierMode write_barrier_mode = IsFastObjectElementsKind(to_kind)
? UPDATE_WRITE_BARRIER
: SKIP_WRITE_BARRIER;
Isolate* isolate = from->GetIsolate();
for (int i = 0; i < copy_size; i++) {
int entry = from->FindEntry(i + from_start);
if (entry != SeededNumberDictionary::kNotFound) {
Object* value = from->ValueAt(entry);
DCHECK(!value->IsTheHole(from->GetIsolate()));
DCHECK(!value->IsTheHole(isolate));
to->set(i + to_start, value, write_barrier_mode);
} else {
to->set_the_hole(i + to_start);
to->set_the_hole(isolate, i + to_start);
}
}
}
......@@ -761,9 +762,7 @@ class ElementsAccessorBase : public ElementsAccessor {
isolate->heap()->RightTrimFixedArray(*backing_store, capacity - length);
} else {
// Otherwise, fill the unused tail with holes.
for (uint32_t i = length; i < old_length; i++) {
BackingStore::cast(*backing_store)->set_the_hole(i);
}
BackingStore::cast(*backing_store)->FillWithHoles(length, old_length);
}
} else {
// Check whether the backing store should be expanded.
......@@ -1814,7 +1813,7 @@ class FastElementsAccessor : public ElementsAccessorBase<Subclass, KindTraits> {
}
Isolate* isolate = obj->GetIsolate();
backing_store->set_the_hole(entry);
backing_store->set_the_hole(isolate, entry);
// TODO(verwaest): Move this out of elements.cc.
// If an old space backing store is larger than a certain size and
......@@ -3281,7 +3280,7 @@ class SlowSloppyArgumentsElementsAccessor
context->set(context_entry, *value);
// Redefining attributes of an aliased element destroys fast aliasing.
parameter_map->set_the_hole(entry + 2);
parameter_map->set_the_hole(isolate, entry + 2);
// For elements that are still writable we re-establish slow aliasing.
if ((attributes & READ_ONLY) == 0) {
value = isolate->factory()->NewAliasedArgumentsEntry(context_entry);
......@@ -3340,7 +3339,7 @@ class FastSloppyArgumentsElementsAccessor
if (entry != kMaxUInt32 && HasEntryImpl(isolate, parameters, entry)) {
elements->set(insertion_index, *GetImpl(parameters, entry));
} else {
elements->set_the_hole(insertion_index);
elements->set_the_hole(isolate, insertion_index);
}
insertion_index++;
}
......
......@@ -183,11 +183,7 @@ Handle<FixedArrayBase> Factory::NewFixedDoubleArrayWithHoles(
DCHECK(0 <= size);
Handle<FixedArrayBase> array = NewFixedDoubleArray(size, pretenure);
if (size > 0) {
Handle<FixedDoubleArray> double_array =
Handle<FixedDoubleArray>::cast(array);
for (int i = 0; i < size; ++i) {
double_array->set_the_hole(i);
}
Handle<FixedDoubleArray>::cast(array)->FillWithHoles(0, size);
}
return array;
}
......
......@@ -2420,6 +2420,9 @@ void FixedDoubleArray::set(int index, double value) {
DCHECK(!is_the_hole(index));
}
void FixedDoubleArray::set_the_hole(Isolate* isolate, int index) {
set_the_hole(index);
}
void FixedDoubleArray::set_the_hole(int index) {
DCHECK(map() != GetHeap()->fixed_cow_array_map() &&
......@@ -2597,8 +2600,9 @@ AllocationAlignment HeapObject::RequiredAlignment() {
void FixedArray::set(int index,
Object* value,
WriteBarrierMode mode) {
DCHECK(map() != GetHeap()->fixed_cow_array_map());
DCHECK(index >= 0 && index < this->length());
DCHECK_NE(map(), GetHeap()->fixed_cow_array_map());
DCHECK_GE(index, 0);
DCHECK_LT(index, this->length());
int offset = kHeaderSize + index * kPointerSize;
WRITE_FIELD(this, offset, value);
CONDITIONAL_WRITE_BARRIER(GetHeap(), this, offset, value, mode);
......@@ -2608,45 +2612,38 @@ void FixedArray::set(int index,
void FixedArray::NoWriteBarrierSet(FixedArray* array,
int index,
Object* value) {
DCHECK(array->map() != array->GetHeap()->fixed_cow_array_map());
DCHECK(index >= 0 && index < array->length());
DCHECK_NE(array->map(), array->GetHeap()->fixed_cow_array_map());
DCHECK_GE(index, 0);
DCHECK_LT(index, array->length());
DCHECK(!array->GetHeap()->InNewSpace(value));
WRITE_FIELD(array, kHeaderSize + index * kPointerSize, value);
}
void FixedArray::set_undefined(int index) {
DCHECK(map() != GetHeap()->fixed_cow_array_map());
DCHECK(index >= 0 && index < this->length());
DCHECK(!GetHeap()->InNewSpace(GetHeap()->undefined_value()));
WRITE_FIELD(this,
kHeaderSize + index * kPointerSize,
GetHeap()->undefined_value());
set_undefined(GetIsolate(), index);
}
void FixedArray::set_null(int index) {
DCHECK(index >= 0 && index < this->length());
DCHECK(!GetHeap()->InNewSpace(GetHeap()->null_value()));
WRITE_FIELD(this,
kHeaderSize + index * kPointerSize,
GetHeap()->null_value());
void FixedArray::set_undefined(Isolate* isolate, int index) {
FixedArray::NoWriteBarrierSet(this, index,
isolate->heap()->undefined_value());
}
void FixedArray::set_null(int index) { set_null(GetIsolate(), index); }
void FixedArray::set_the_hole(int index) {
DCHECK(map() != GetHeap()->fixed_cow_array_map());
DCHECK(index >= 0 && index < this->length());
DCHECK(!GetHeap()->InNewSpace(GetHeap()->the_hole_value()));
WRITE_FIELD(this,
kHeaderSize + index * kPointerSize,
GetHeap()->the_hole_value());
void FixedArray::set_null(Isolate* isolate, int index) {
FixedArray::NoWriteBarrierSet(this, index, isolate->heap()->null_value());
}
void FixedArray::set_the_hole(int index) { set_the_hole(GetIsolate(), index); }
void FixedArray::set_the_hole(Isolate* isolate, int index) {
FixedArray::NoWriteBarrierSet(this, index, isolate->heap()->the_hole_value());
}
void FixedArray::FillWithHoles(int from, int to) {
Isolate* isolate = GetIsolate();
for (int i = from; i < to; i++) {
set_the_hole(i);
set_the_hole(isolate, i);
}
}
......
......@@ -17528,11 +17528,11 @@ Handle<Object> JSObject::PrepareElementsForSort(Handle<JSObject> object,
}
result = undefs;
while (undefs < holes) {
elements->set_undefined(undefs);
elements->set_undefined(isolate, undefs);
undefs++;
}
while (holes < limit) {
elements->set_the_hole(holes);
elements->set_the_hole(isolate, holes);
holes++;
}
}
......
......@@ -2851,8 +2851,11 @@ class FixedArray: public FixedArrayBase {
// Setters for frequently used oddballs located in old space.
inline void set_undefined(int index);
inline void set_undefined(Isolate* isolate, int index);
inline void set_null(int index);
inline void set_null(Isolate* isolate, int index);
inline void set_the_hole(int index);
inline void set_the_hole(Isolate* isolate, int index);
inline Object** GetFirstElementAddress();
inline bool ContainsOnlySmisOrHoles();
......@@ -2929,6 +2932,7 @@ class FixedDoubleArray: public FixedArrayBase {
static inline Handle<Object> get(FixedDoubleArray* array, int index,
Isolate* isolate);
inline void set(int index, double value);
inline void set_the_hole(Isolate* isolate, int index);
inline void set_the_hole(int index);
// Checking for the hole.
......
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