Commit fcdc737f authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[runtime] Don't regenerate enumeration indices in slow-to-fast

BUG=

Change-Id: Ibadaef9ee4cb16afa01b782afc07a32bd39ad8aa
Reviewed-on: https://chromium-review.googlesource.com/461140
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44191}
parent 1b0bd5fd
......@@ -3076,12 +3076,6 @@ bool HashTableBase::IsKey(Isolate* isolate, Object* k) {
return k != heap->the_hole_value() && k != heap->undefined_value();
}
bool HashTableBase::IsKey(Object* k) {
Isolate* isolate = this->GetIsolate();
return !k->IsTheHole(isolate) && !k->IsUndefined(isolate);
}
void HashTableBase::SetNumberOfElements(int nof) {
set(kNumberOfElementsIndex, Smi::FromInt(nof));
}
......@@ -7784,12 +7778,6 @@ Handle<Object> NameDictionaryShape::AsHandle(Isolate* isolate,
}
Handle<FixedArray> NameDictionary::DoGenerateNewEnumerationIndices(
Handle<NameDictionary> dictionary) {
return DerivedDictionary::GenerateNewEnumerationIndices(dictionary);
}
template <typename Dictionary>
PropertyDetails GlobalDictionaryShape::DetailsAt(Dictionary* dict, int entry) {
DCHECK(entry >= 0); // Not found is -1, which is not caught by get().
......
......@@ -5647,13 +5647,8 @@ void JSObject::MigrateSlowToFast(Handle<JSObject> object,
int number_of_elements = dictionary->NumberOfElements();
if (number_of_elements > kMaxNumberOfDescriptors) return;
Handle<FixedArray> iteration_order;
if (number_of_elements != dictionary->NextEnumerationIndex()) {
iteration_order =
NameDictionary::DoGenerateNewEnumerationIndices(dictionary);
} else {
iteration_order = NameDictionary::IterationIndices(dictionary);
}
Handle<FixedArray> iteration_order =
NameDictionary::IterationIndices(dictionary);
int instance_descriptor_length = iteration_order->length();
int number_of_fields = 0;
......@@ -5727,7 +5722,7 @@ void JSObject::MigrateSlowToFast(Handle<JSObject> object,
for (int i = 0; i < instance_descriptor_length; i++) {
int index = Smi::cast(iteration_order->get(i))->value();
Object* k = dictionary->KeyAt(index);
DCHECK(dictionary->IsKey(k));
DCHECK(dictionary->IsKey(isolate, k));
// Dictionary keys are internalized upon insertion.
// TODO(jkummerow): Turn this into a DCHECK if it's not hit in the wild.
CHECK(k->IsUniqueName());
......@@ -5738,7 +5733,6 @@ void JSObject::MigrateSlowToFast(Handle<JSObject> object,
PropertyDetails details = dictionary->DetailsAt(index);
DCHECK_EQ(kField, details.location());
DCHECK_EQ(kMutable, details.constness());
int enumeration_index = details.dictionary_index();
Descriptor d;
if (details.kind() == kData) {
......@@ -5767,7 +5761,7 @@ void JSObject::MigrateSlowToFast(Handle<JSObject> object,
}
current_offset += details.field_width_in_words();
}
descriptors->Set(enumeration_index - 1, &d);
descriptors->Set(i, &d);
}
DCHECK(current_offset == number_of_fields);
......@@ -16551,7 +16545,7 @@ void HashTable<Derived, Shape, Key>::Rehash(Key key) {
uint32_t target = EntryForProbe(key, current_key, probe, current);
if (current == target) continue;
Object* target_key = KeyAt(target);
if (!IsKey(target_key) ||
if (!IsKey(isolate, target_key) ||
EntryForProbe(key, target_key, probe, target) != target) {
// Put the current element into the correct position.
Swap(current, target, mode);
......@@ -16782,10 +16776,6 @@ Dictionary<GlobalDictionary, GlobalDictionaryShape, Handle<Name>>::Add(
Handle<GlobalDictionary>, Handle<Name>, Handle<Object>, PropertyDetails,
int*);
template Handle<FixedArray> Dictionary<
NameDictionary, NameDictionaryShape,
Handle<Name> >::GenerateNewEnumerationIndices(Handle<NameDictionary>);
template Handle<SeededNumberDictionary>
Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>::Add(
Handle<SeededNumberDictionary>, uint32_t, Handle<Object>, PropertyDetails,
......@@ -17864,34 +17854,6 @@ Handle<Derived> Dictionary<Derived, Shape, Key>::NewEmpty(
return dict;
}
template <typename Derived, typename Shape, typename Key>
Handle<FixedArray>
Dictionary<Derived, Shape, Key>::GenerateNewEnumerationIndices(
Handle<Derived> dictionary) {
int length = dictionary->NumberOfElements();
Handle<FixedArray> iteration_order = IterationIndices(dictionary);
DCHECK(iteration_order->length() == length);
// Iterate over the dictionary using the enumeration order and update
// the dictionary with new enumeration indices.
for (int i = 0; i < length; i++) {
int index = Smi::cast(iteration_order->get(i))->value();
DCHECK(dictionary->IsKey(dictionary->KeyAt(index)));
int enum_index = PropertyDetails::kInitialIndex + i;
PropertyDetails details = dictionary->DetailsAt(index);
PropertyDetails new_details = details.set_index(enum_index);
dictionary->DetailsAtPut(index, new_details);
}
// Set the next enumeration index.
dictionary->SetNextEnumerationIndex(PropertyDetails::kInitialIndex+length);
return iteration_order;
}
template <typename Derived, typename Shape, typename Key>
void Dictionary<Derived, Shape, Key>::SetRequiresCopyOnCapacityChange() {
DCHECK_EQ(0, DerivedHashTable::NumberOfElements());
......@@ -17909,7 +17871,28 @@ Handle<Derived> Dictionary<Derived, Shape, Key>::EnsureCapacity(
if (Shape::kIsEnumerable &&
!PropertyDetails::IsValidIndex(dictionary->NextEnumerationIndex() + n)) {
// If not, we generate new indices for the properties.
GenerateNewEnumerationIndices(dictionary);
int length = dictionary->NumberOfElements();
Handle<FixedArray> iteration_order = IterationIndices(dictionary);
DCHECK_EQ(length, iteration_order->length());
// Iterate over the dictionary using the enumeration order and update
// the dictionary with new enumeration indices.
for (int i = 0; i < length; i++) {
int index = Smi::cast(iteration_order->get(i))->value();
DCHECK(dictionary->IsKey(dictionary->GetIsolate(),
dictionary->KeyAt(index)));
int enum_index = PropertyDetails::kInitialIndex + i;
PropertyDetails details = dictionary->DetailsAt(index);
PropertyDetails new_details = details.set_index(enum_index);
dictionary->DetailsAtPut(index, new_details);
}
// Set the next enumeration index.
dictionary->SetNextEnumerationIndex(PropertyDetails::kInitialIndex +
length);
}
return DerivedHashTable::EnsureCapacity(dictionary, n, key);
}
......@@ -18841,7 +18824,7 @@ void JSWeakCollection::Set(Handle<JSWeakCollection> weak_collection,
DCHECK(key->IsJSReceiver() || key->IsSymbol());
Handle<ObjectHashTable> table(
ObjectHashTable::cast(weak_collection->table()));
DCHECK(table->IsKey(*key));
DCHECK(table->IsKey(table->GetIsolate(), *key));
Handle<ObjectHashTable> new_table =
ObjectHashTable::Put(table, key, value, hash);
weak_collection->set_table(*new_table);
......@@ -18857,7 +18840,7 @@ bool JSWeakCollection::Delete(Handle<JSWeakCollection> weak_collection,
DCHECK(key->IsJSReceiver() || key->IsSymbol());
Handle<ObjectHashTable> table(
ObjectHashTable::cast(weak_collection->table()));
DCHECK(table->IsKey(*key));
DCHECK(table->IsKey(table->GetIsolate(), *key));
bool was_present = false;
Handle<ObjectHashTable> new_table =
ObjectHashTable::Remove(table, key, &was_present, hash);
......
......@@ -3049,7 +3049,6 @@ class HashTableBase : public FixedArray {
// Tells whether k is a real key. The hole and undefined are not allowed
// as keys and can be used to indicate missing or deleted elements.
inline bool IsKey(Object* k);
inline bool IsKey(Isolate* isolate, Object* k);
// Compute the probe offset (quadratic probing).
......@@ -3430,10 +3429,6 @@ class Dictionary: public HashTable<Derived, Shape, Key> {
// Add entry to dictionary. Returns entry value.
static int AddEntry(Handle<Derived> dictionary, Key key, Handle<Object> value,
PropertyDetails details, uint32_t hash);
// Generate new enumeration indices to avoid enumeration index overflow.
// Returns iteration indices array for the |dictionary|.
static Handle<FixedArray> GenerateNewEnumerationIndices(
Handle<Derived> dictionary);
};
......@@ -3500,9 +3495,6 @@ class NameDictionary
public:
DECLARE_CAST(NameDictionary)
inline static Handle<FixedArray> DoGenerateNewEnumerationIndices(
Handle<NameDictionary> dictionary);
static const int kEntryValueIndex = 1;
static const int kEntryDetailsIndex = 2;
static const int kInitialCapacity = 2;
......
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