Commit 731d1b73 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[runtime] Unify *DictionaryShape::SetEntry into *Dictionary::SetEntry

Bug: 
Change-Id: I45414453378c77f00ba01ca79fd4d84245c5a423
Reviewed-on: https://chromium-review.googlesource.com/544862Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46143}
parent ab22e64e
...@@ -1385,13 +1385,12 @@ class DictionaryElementsAccessor ...@@ -1385,13 +1385,12 @@ class DictionaryElementsAccessor
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
// Remove elements that should be deleted. // Remove elements that should be deleted.
int removed_entries = 0; int removed_entries = 0;
Handle<Object> the_hole_value = isolate->factory()->the_hole_value();
for (int entry = 0; entry < capacity; entry++) { for (int entry = 0; entry < capacity; entry++) {
Object* index = dict->KeyAt(entry); Object* index = dict->KeyAt(entry);
if (index->IsNumber()) { if (index->IsNumber()) {
uint32_t number = static_cast<uint32_t>(index->Number()); uint32_t number = static_cast<uint32_t>(index->Number());
if (length <= number && number < old_length) { if (length <= number && number < old_length) {
dict->SetEntry(entry, the_hole_value, the_hole_value); dict->ClearEntry(entry);
removed_entries++; removed_entries++;
} }
} }
......
...@@ -304,7 +304,7 @@ void LookupIterator::ReconfigureDataProperty(Handle<Object> value, ...@@ -304,7 +304,7 @@ void LookupIterator::ReconfigureDataProperty(Handle<Object> value,
int enumeration_index = original_details.dictionary_index(); int enumeration_index = original_details.dictionary_index();
DCHECK(enumeration_index > 0); DCHECK(enumeration_index > 0);
details = details.set_index(enumeration_index); details = details.set_index(enumeration_index);
dictionary->SetEntry(dictionary_entry(), name(), value, details); dictionary->SetEntry(dictionary_entry(), *name(), *value, details);
property_details_ = details; property_details_ = details;
} }
state_ = DATA; state_ = DATA;
......
...@@ -6043,51 +6043,22 @@ bool AccessorPair::IsJSAccessor(Object* obj) { ...@@ -6043,51 +6043,22 @@ bool AccessorPair::IsJSAccessor(Object* obj) {
} }
template <typename Derived, typename Shape> template <typename Derived, typename Shape>
void Dictionary<Derived, Shape>::SetEntry(int entry, Handle<Object> key, void Dictionary<Derived, Shape>::ClearEntry(int entry) {
Handle<Object> value) { Object* the_hole = this->GetHeap()->the_hole_value();
this->SetEntry(entry, key, value, PropertyDetails(Smi::kZero)); SetEntry(entry, the_hole, the_hole, PropertyDetails::Empty());
} }
template <typename Derived, typename Shape> template <typename Derived, typename Shape>
void Dictionary<Derived, Shape>::SetEntry(int entry, Handle<Object> key, void Dictionary<Derived, Shape>::SetEntry(int entry, Object* key, Object* value,
Handle<Object> value,
PropertyDetails details) { PropertyDetails details) {
Shape::SetEntry(static_cast<Derived*>(this), entry, key, value, details);
}
template <typename Key>
template <typename Dictionary>
void BaseDictionaryShape<Key>::SetEntry(Dictionary* dict, int entry,
Handle<Object> key,
Handle<Object> value,
PropertyDetails details) {
STATIC_ASSERT(Dictionary::kEntrySize == 2 || Dictionary::kEntrySize == 3); STATIC_ASSERT(Dictionary::kEntrySize == 2 || Dictionary::kEntrySize == 3);
DCHECK(!key->IsName() || details.dictionary_index() > 0); DCHECK(!key->IsName() || details.dictionary_index() > 0);
int index = dict->EntryToIndex(entry); int index = DerivedHashTable::EntryToIndex(entry);
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
WriteBarrierMode mode = dict->GetWriteBarrierMode(no_gc); WriteBarrierMode mode = this->GetWriteBarrierMode(no_gc);
dict->set(index + Dictionary::kEntryKeyIndex, *key, mode); this->set(index + Derived::kEntryKeyIndex, key, mode);
dict->set(index + Dictionary::kEntryValueIndex, *value, mode); this->set(index + Derived::kEntryValueIndex, value, mode);
if (Dictionary::kEntrySize == 3) { if (Shape::kHasDetails) DetailsAtPut(entry, details);
dict->set(index + Dictionary::kEntryDetailsIndex, details.AsSmi());
}
}
template <typename Dictionary>
void GlobalDictionaryShape::SetEntry(Dictionary* dict, int entry,
Handle<Object> key, Handle<Object> value,
PropertyDetails details) {
STATIC_ASSERT(Dictionary::kEntrySize == 2);
DCHECK(!key->IsName() || details.dictionary_index() > 0);
DCHECK(value->IsPropertyCell());
int index = dict->EntryToIndex(entry);
DisallowHeapAllocation no_gc;
WriteBarrierMode mode = dict->GetWriteBarrierMode(no_gc);
dict->set(index + Dictionary::kEntryKeyIndex, *key, mode);
dict->set(index + Dictionary::kEntryValueIndex, *value, mode);
PropertyCell::cast(*value)->set_property_details(details);
} }
...@@ -6152,7 +6123,7 @@ Handle<Object> NameDictionaryShape::AsHandle(Isolate* isolate, ...@@ -6152,7 +6123,7 @@ Handle<Object> NameDictionaryShape::AsHandle(Isolate* isolate,
template <typename Dictionary> template <typename Dictionary>
PropertyDetails GlobalDictionaryShape::DetailsAt(Dictionary* dict, int entry) { PropertyDetails GlobalDictionaryShape::DetailsAt(Dictionary* dict, int entry) {
DCHECK(entry >= 0); // Not found is -1, which is not caught by get(). DCHECK_LE(0, entry); // Not found is -1, which is not caught by get().
Object* raw_value = dict->ValueAt(entry); Object* raw_value = dict->ValueAt(entry);
DCHECK(raw_value->IsPropertyCell()); DCHECK(raw_value->IsPropertyCell());
PropertyCell* cell = PropertyCell::cast(raw_value); PropertyCell* cell = PropertyCell::cast(raw_value);
...@@ -6163,10 +6134,8 @@ PropertyDetails GlobalDictionaryShape::DetailsAt(Dictionary* dict, int entry) { ...@@ -6163,10 +6134,8 @@ PropertyDetails GlobalDictionaryShape::DetailsAt(Dictionary* dict, int entry) {
template <typename Dictionary> template <typename Dictionary>
void GlobalDictionaryShape::DetailsAtPut(Dictionary* dict, int entry, void GlobalDictionaryShape::DetailsAtPut(Dictionary* dict, int entry,
PropertyDetails value) { PropertyDetails value) {
DCHECK(entry >= 0); // Not found is -1, which is not caught by get(). DCHECK_LE(0, entry); // Not found is -1, which is not caught by get().
Object* raw_value = dict->ValueAt(entry); PropertyCell* cell = PropertyCell::cast(dict->ValueAt(entry));
DCHECK(raw_value->IsPropertyCell());
PropertyCell* cell = PropertyCell::cast(raw_value);
if (cell->property_details().IsReadOnly() != value.IsReadOnly()) { if (cell->property_details().IsReadOnly() != value.IsReadOnly()) {
cell->dependent_code()->DeoptimizeDependentCodeGroup( cell->dependent_code()->DeoptimizeDependentCodeGroup(
cell->GetIsolate(), DependentCode::kPropertyCellChangedGroup); cell->GetIsolate(), DependentCode::kPropertyCellChangedGroup);
...@@ -6174,7 +6143,6 @@ void GlobalDictionaryShape::DetailsAtPut(Dictionary* dict, int entry, ...@@ -6174,7 +6143,6 @@ void GlobalDictionaryShape::DetailsAtPut(Dictionary* dict, int entry,
cell->set_property_details(value); cell->set_property_details(value);
} }
template <typename Dictionary> template <typename Dictionary>
bool GlobalDictionaryShape::IsDeleted(Dictionary* dict, int entry) { bool GlobalDictionaryShape::IsDeleted(Dictionary* dict, int entry) {
DCHECK(dict->ValueAt(entry)->IsPropertyCell()); DCHECK(dict->ValueAt(entry)->IsPropertyCell());
......
...@@ -1953,7 +1953,7 @@ void JSObject::SetNormalizedProperty(Handle<JSObject> object, ...@@ -1953,7 +1953,7 @@ void JSObject::SetNormalizedProperty(Handle<JSObject> object,
int enumeration_index = original_details.dictionary_index(); int enumeration_index = original_details.dictionary_index();
DCHECK(enumeration_index > 0); DCHECK(enumeration_index > 0);
details = details.set_index(enumeration_index); details = details.set_index(enumeration_index);
dictionary->SetEntry(entry, name, value, details); dictionary->SetEntry(entry, *name, *value, details);
} }
} }
} }
...@@ -17570,11 +17570,9 @@ Handle<Derived> BaseNameDictionary<Derived, Shape>::EnsureCapacity( ...@@ -17570,11 +17570,9 @@ Handle<Derived> BaseNameDictionary<Derived, Shape>::EnsureCapacity(
template <typename Derived, typename Shape> template <typename Derived, typename Shape>
Handle<Derived> Dictionary<Derived, Shape>::DeleteEntry( Handle<Derived> Dictionary<Derived, Shape>::DeleteEntry(
Handle<Derived> dictionary, int entry) { Handle<Derived> dictionary, int entry) {
Factory* factory = dictionary->GetIsolate()->factory();
DCHECK(Shape::kEntrySize != 3 || DCHECK(Shape::kEntrySize != 3 ||
dictionary->DetailsAt(entry).IsConfigurable()); dictionary->DetailsAt(entry).IsConfigurable());
dictionary->SetEntry( dictionary->ClearEntry(entry);
entry, factory->the_hole_value(), factory->the_hole_value());
dictionary->ElementRemoved(); dictionary->ElementRemoved();
return Shrink(dictionary); return Shrink(dictionary);
} }
...@@ -17627,7 +17625,7 @@ Handle<Derived> Dictionary<Derived, Shape>::Add(Handle<Derived> dictionary, ...@@ -17627,7 +17625,7 @@ Handle<Derived> Dictionary<Derived, Shape>::Add(Handle<Derived> dictionary,
Handle<Object> k = Shape::AsHandle(isolate, key); Handle<Object> k = Shape::AsHandle(isolate, key);
uint32_t entry = dictionary->FindInsertionEntry(hash); uint32_t entry = dictionary->FindInsertionEntry(hash);
dictionary->SetEntry(entry, k, value, details); dictionary->SetEntry(entry, *k, *value, details);
DCHECK(dictionary->KeyAt(entry)->IsNumber() || DCHECK(dictionary->KeyAt(entry)->IsNumber() ||
dictionary->KeyAt(entry)->IsUniqueName()); dictionary->KeyAt(entry)->IsUniqueName());
dictionary->ElementAdded(); dictionary->ElementAdded();
......
...@@ -74,8 +74,8 @@ class Dictionary : public HashTable<Derived, Shape> { ...@@ -74,8 +74,8 @@ class Dictionary : public HashTable<Derived, Shape> {
Object* SlowReverseLookup(Object* value); Object* SlowReverseLookup(Object* value);
// Sets the entry to (key, value) pair. // Sets the entry to (key, value) pair.
inline void SetEntry(int entry, Handle<Object> key, Handle<Object> value); inline void ClearEntry(int entry);
inline void SetEntry(int entry, Handle<Object> key, Handle<Object> value, inline void SetEntry(int entry, Object* key, Object* value,
PropertyDetails details); PropertyDetails details);
MUST_USE_RESULT static Handle<Derived> Add(Handle<Derived> dictionary, MUST_USE_RESULT static Handle<Derived> Add(Handle<Derived> dictionary,
...@@ -93,6 +93,7 @@ class Dictionary : public HashTable<Derived, Shape> { ...@@ -93,6 +93,7 @@ class Dictionary : public HashTable<Derived, Shape> {
template <typename Key> template <typename Key>
class BaseDictionaryShape : public BaseShape<Key> { class BaseDictionaryShape : public BaseShape<Key> {
public: public:
static const bool kHasDetails = true;
template <typename Dictionary> template <typename Dictionary>
static inline PropertyDetails DetailsAt(Dictionary* dict, int entry) { static inline PropertyDetails DetailsAt(Dictionary* dict, int entry) {
STATIC_ASSERT(Dictionary::kEntrySize == 3); STATIC_ASSERT(Dictionary::kEntrySize == 3);
...@@ -113,10 +114,6 @@ class BaseDictionaryShape : public BaseShape<Key> { ...@@ -113,10 +114,6 @@ class BaseDictionaryShape : public BaseShape<Key> {
static bool IsDeleted(Dictionary* dict, int entry) { static bool IsDeleted(Dictionary* dict, int entry) {
return false; return false;
} }
template <typename Dictionary>
static inline void SetEntry(Dictionary* dict, int entry, Handle<Object> key,
Handle<Object> value, PropertyDetails details);
}; };
class NameDictionaryShape : public BaseDictionaryShape<Handle<Name>> { class NameDictionaryShape : public BaseDictionaryShape<Handle<Name>> {
...@@ -200,10 +197,6 @@ class GlobalDictionaryShape : public NameDictionaryShape { ...@@ -200,10 +197,6 @@ class GlobalDictionaryShape : public NameDictionaryShape {
template <typename Dictionary> template <typename Dictionary>
static bool IsDeleted(Dictionary* dict, int entry); static bool IsDeleted(Dictionary* dict, int entry);
template <typename Dictionary>
static inline void SetEntry(Dictionary* dict, int entry, Handle<Object> key,
Handle<Object> value, PropertyDetails details);
}; };
class GlobalDictionary class GlobalDictionary
...@@ -231,6 +224,7 @@ class SeededNumberDictionaryShape : public NumberDictionaryShape { ...@@ -231,6 +224,7 @@ class SeededNumberDictionaryShape : public NumberDictionaryShape {
class UnseededNumberDictionaryShape : public NumberDictionaryShape { class UnseededNumberDictionaryShape : public NumberDictionaryShape {
public: public:
static const bool kHasDetails = false;
static const int kPrefixSize = 0; static const int kPrefixSize = 0;
static const int kEntrySize = 2; static const int kEntrySize = 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