From: ishell@chromium.org Date: Fri, 11 Apr 2014 17:44:58 +0000 (+0000) Subject: HashTable::Shrink() handlified and derived template parameter added to HashTable... X-Git-Tag: upstream/4.7.83~9664 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=be3df6164b9a7d561b7c5dc69c9af1a1223e94c7;p=platform%2Fupstream%2Fv8.git HashTable::Shrink() handlified and derived template parameter added to HashTable hierarchy. R=yangguo@chromium.org Review URL: https://codereview.chromium.org/234663004 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20697 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/objects-inl.h b/src/objects-inl.h index ed66dc6..668f716 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -2875,8 +2875,8 @@ DescriptorArray::WhitenessWitness::~WhitenessWitness() { } -template -int HashTable::ComputeCapacity(int at_least_space_for) { +template +int HashTable::ComputeCapacity(int at_least_space_for) { const int kMinCapacity = 32; int capacity = RoundUpToPowerOf2(at_least_space_for * 2); if (capacity < kMinCapacity) { @@ -2886,17 +2886,17 @@ int HashTable::ComputeCapacity(int at_least_space_for) { } -template -int HashTable::FindEntry(Key key) { +template +int HashTable::FindEntry(Key key) { return FindEntry(GetIsolate(), key); } // Find entry for key otherwise return kNotFound. -template -int HashTable::FindEntry(Isolate* isolate, Key key) { +template +int HashTable::FindEntry(Isolate* isolate, Key key) { uint32_t capacity = Capacity(); - uint32_t entry = FirstProbe(HashTable::Hash(key), capacity); + uint32_t entry = FirstProbe(HashTable::Hash(key), capacity); uint32_t count = 1; // EnsureCapacity will guarantee the hash table is never full. while (true) { @@ -3021,8 +3021,9 @@ FixedTypedArray* FixedTypedArray::cast(Object* object) { #undef MAKE_STRUCT_CAST -template -HashTable* HashTable::cast(Object* obj) { +template +HashTable* +HashTable::cast(Object* obj) { ASSERT(obj->IsHashTable()); return reinterpret_cast(obj); } @@ -6682,23 +6683,23 @@ bool AccessorPair::prohibits_overwriting() { } -template -void Dictionary::SetEntry(int entry, - Object* key, - Object* value) { +template +void Dictionary::SetEntry(int entry, + Object* key, + Object* value) { SetEntry(entry, key, value, PropertyDetails(Smi::FromInt(0))); } -template -void Dictionary::SetEntry(int entry, - Object* key, - Object* value, - PropertyDetails details) { +template +void Dictionary::SetEntry(int entry, + Object* key, + Object* value, + PropertyDetails details) { ASSERT(!key->IsName() || details.IsDeleted() || details.dictionary_index() > 0); - int index = HashTable::EntryToIndex(entry); + int index = DerivedHashTable::EntryToIndex(entry); DisallowHeapAllocation no_gc; WriteBarrierMode mode = FixedArray::GetWriteBarrierMode(no_gc); FixedArray::set(index, key, mode); @@ -6784,6 +6785,12 @@ MaybeObject* ObjectHashTableShape::AsObject(Heap* heap, Object* key) { } +Handle ObjectHashTable::Shrink( + Handle table, Handle key) { + return HashTable_::Shrink(table, *key); +} + + template bool WeakHashTableShape::IsMatch(Object* key, Object* other) { return key->SameValue(other); diff --git a/src/objects.cc b/src/objects.cc index aaa0320..bcdfe38 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -723,13 +723,6 @@ void JSObject::SetNormalizedProperty(Handle object, } -// TODO(mstarzinger): Temporary wrapper until target is handlified. -Handle NameDictionaryShrink(Handle dict, - Handle name) { - CALL_HEAP_FUNCTION(dict->GetIsolate(), dict->Shrink(*name), NameDictionary); -} - - Handle JSObject::DeleteNormalizedProperty(Handle object, Handle name, DeleteMode mode) { @@ -759,7 +752,7 @@ Handle JSObject::DeleteNormalizedProperty(Handle object, Handle deleted(dictionary->DeleteProperty(entry, mode), isolate); if (*deleted == isolate->heap()->true_value()) { Handle new_properties = - NameDictionaryShrink(dictionary, name); + NameDictionary::Shrink(dictionary, *name); object->set_properties(*new_properties); } return deleted; @@ -13206,12 +13199,12 @@ bool JSObject::ShouldConvertToFastDoubleElements( // together, so even though this function belongs in objects-debug.cc, // we keep it here instead to satisfy certain compilers. #ifdef OBJECT_PRINT -template -void Dictionary::Print(FILE* out) { - int capacity = HashTable::Capacity(); +template +void Dictionary::Print(FILE* out) { + int capacity = DerivedHashTable::Capacity(); for (int i = 0; i < capacity; i++) { - Object* k = HashTable::KeyAt(i); - if (HashTable::IsKey(k)) { + Object* k = DerivedHashTable::KeyAt(i); + if (DerivedHashTable::IsKey(k)) { PrintF(out, " "); if (k->IsString()) { String::cast(k)->StringPrint(out); @@ -13227,15 +13220,15 @@ void Dictionary::Print(FILE* out) { #endif -template -void Dictionary::CopyValuesTo(FixedArray* elements) { +template +void Dictionary::CopyValuesTo(FixedArray* elements) { int pos = 0; - int capacity = HashTable::Capacity(); + int capacity = DerivedHashTable::Capacity(); DisallowHeapAllocation no_gc; WriteBarrierMode mode = elements->GetWriteBarrierMode(no_gc); for (int i = 0; i < capacity; i++) { - Object* k = Dictionary::KeyAt(i); - if (Dictionary::IsKey(k)) { + Object* k = Dictionary::KeyAt(i); + if (Dictionary::IsKey(k)) { elements->set(pos++, ValueAt(i), mode); } } @@ -13939,25 +13932,26 @@ class InternalizedStringKey : public HashTableKey { }; -template -void HashTable::IteratePrefix(ObjectVisitor* v) { +template +void HashTable::IteratePrefix(ObjectVisitor* v) { IteratePointers(v, 0, kElementsStartOffset); } -template -void HashTable::IterateElements(ObjectVisitor* v) { +template +void HashTable::IterateElements(ObjectVisitor* v) { IteratePointers(v, kElementsStartOffset, kHeaderSize + length() * kPointerSize); } -template -MaybeObject* HashTable::Allocate(Heap* heap, - int at_least_space_for, - MinimumCapacity capacity_option, - PretenureFlag pretenure) { +template +MaybeObject* HashTable::Allocate( + Heap* heap, + int at_least_space_for, + MinimumCapacity capacity_option, + PretenureFlag pretenure) { ASSERT(!capacity_option || IsPowerOf2(at_least_space_for)); int capacity = (capacity_option == USE_CUSTOM_MINIMUM_CAPACITY) ? at_least_space_for @@ -13978,10 +13972,23 @@ MaybeObject* HashTable::Allocate(Heap* heap, } +template +Handle HashTable::New( + Isolate* isolate, + int at_least_space_for, + MinimumCapacity capacity_option, + PretenureFlag pretenure) { + CALL_HEAP_FUNCTION( + isolate, + Allocate(isolate->heap(), at_least_space_for, capacity_option, pretenure), + Derived); +} + + // Find entry for key otherwise return kNotFound. int NameDictionary::FindEntry(Name* key) { if (!key->IsUniqueName()) { - return HashTable::FindEntry(key); + return DerivedHashTable::FindEntry(key); } // Optimized for unique names. Knowledge of the key type allows: @@ -14018,8 +14025,8 @@ int NameDictionary::FindEntry(Name* key) { } -template -MaybeObject* HashTable::Rehash(HashTable* new_table, Key key) { +template +void HashTable::Rehash(Derived* new_table, Key key) { ASSERT(NumberOfElements() < new_table->Capacity()); DisallowHeapAllocation no_gc; @@ -14038,7 +14045,7 @@ MaybeObject* HashTable::Rehash(HashTable* new_table, Key key) { uint32_t from_index = EntryToIndex(i); Object* k = get(from_index); if (IsKey(k)) { - uint32_t hash = HashTable::HashForObject(key, k); + uint32_t hash = HashTable::HashForObject(key, k); uint32_t insertion_index = EntryToIndex(new_table->FindInsertionEntry(hash)); for (int j = 0; j < Shape::kEntrySize; j++) { @@ -14048,16 +14055,16 @@ MaybeObject* HashTable::Rehash(HashTable* new_table, Key key) { } new_table->SetNumberOfElements(NumberOfElements()); new_table->SetNumberOfDeletedElements(0); - return new_table; } -template -uint32_t HashTable::EntryForProbe(Key key, - Object* k, - int probe, - uint32_t expected) { - uint32_t hash = HashTable::HashForObject(key, k); +template +uint32_t HashTable::EntryForProbe( + Key key, + Object* k, + int probe, + uint32_t expected) { + uint32_t hash = HashTable::HashForObject(key, k); uint32_t capacity = Capacity(); uint32_t entry = FirstProbe(hash, capacity); for (int i = 1; i < probe; i++) { @@ -14068,10 +14075,10 @@ uint32_t HashTable::EntryForProbe(Key key, } -template -void HashTable::Swap(uint32_t entry1, - uint32_t entry2, - WriteBarrierMode mode) { +template +void HashTable::Swap(uint32_t entry1, + uint32_t entry2, + WriteBarrierMode mode) { int index1 = EntryToIndex(entry1); int index2 = EntryToIndex(entry2); Object* temp[Shape::kEntrySize]; @@ -14087,8 +14094,8 @@ void HashTable::Swap(uint32_t entry1, } -template -void HashTable::Rehash(Key key) { +template +void HashTable::Rehash(Key key) { DisallowHeapAllocation no_gc; WriteBarrierMode mode = GetWriteBarrierMode(no_gc); uint32_t capacity = Capacity(); @@ -14120,10 +14127,11 @@ void HashTable::Rehash(Key key) { } -template -MaybeObject* HashTable::EnsureCapacity(int n, - Key key, - PretenureFlag pretenure) { +template +MaybeObject* HashTable::EnsureCapacity( + int n, + Key key, + PretenureFlag pretenure) { int capacity = Capacity(); int nof = NumberOfElements() + n; int nod = NumberOfDeletedElements(); @@ -14147,44 +14155,45 @@ MaybeObject* HashTable::EnsureCapacity(int n, if (!maybe_obj->ToObject(&obj)) return maybe_obj; } - return Rehash(HashTable::cast(obj), key); + Rehash(Derived::cast(obj), key); + return Derived::cast(obj); } -template -MaybeObject* HashTable::Shrink(Key key) { - int capacity = Capacity(); - int nof = NumberOfElements(); +template +Handle HashTable::Shrink(Handle table, + Key key) { + int capacity = table->Capacity(); + int nof = table->NumberOfElements(); // Shrink to fit the number of elements if only a quarter of the // capacity is filled with elements. - if (nof > (capacity >> 2)) return this; + if (nof > (capacity >> 2)) return table; // Allocate a new dictionary with room for at least the current // number of elements. The allocation method will make sure that // there is extra room in the dictionary for additions. Don't go // lower than room for 16 elements. int at_least_room_for = nof; - if (at_least_room_for < 16) return this; + if (at_least_room_for < 16) return table; + Isolate* isolate = table->GetIsolate(); const int kMinCapacityForPretenure = 256; bool pretenure = (at_least_room_for > kMinCapacityForPretenure) && - !GetHeap()->InNewSpace(this); - Object* obj; - { MaybeObject* maybe_obj = - Allocate(GetHeap(), - at_least_room_for, - USE_DEFAULT_MINIMUM_CAPACITY, - pretenure ? TENURED : NOT_TENURED); - if (!maybe_obj->ToObject(&obj)) return maybe_obj; - } + !isolate->heap()->InNewSpace(*table); + Handle new_table = New( + isolate, + at_least_room_for, + USE_DEFAULT_MINIMUM_CAPACITY, + pretenure ? TENURED : NOT_TENURED); - return Rehash(HashTable::cast(obj), key); + table->Rehash(*new_table, key); + return new_table; } -template -uint32_t HashTable::FindInsertionEntry(uint32_t hash) { +template +uint32_t HashTable::FindInsertionEntry(uint32_t hash) { uint32_t capacity = Capacity(); uint32_t entry = FirstProbe(hash, capacity); uint32_t count = 1; @@ -14201,129 +14210,157 @@ uint32_t HashTable::FindInsertionEntry(uint32_t hash) { // Force instantiation of template instances class. // Please note this list is compiler dependent. -template class HashTable; +template class HashTable; -template class HashTable; +template class HashTable; -template class HashTable; +template class HashTable; -template class HashTable; +template class HashTable; -template class HashTable, Object*>; +template class HashTable, Object*>; -template class Dictionary; +template class Dictionary; -template class Dictionary; +template class Dictionary; -template class Dictionary; +template class Dictionary; -template MaybeObject* Dictionary:: +template MaybeObject* +Dictionary:: Allocate(Heap* heap, int at_least_space_for, PretenureFlag pretenure); -template MaybeObject* Dictionary:: +template MaybeObject* +Dictionary:: Allocate(Heap* heap, int at_least_space_for, PretenureFlag pretenure); -template MaybeObject* Dictionary:: +template MaybeObject* Dictionary:: Allocate(Heap* heap, int n, PretenureFlag pretenure); -template MaybeObject* Dictionary::AtPut( - uint32_t, Object*); +template MaybeObject* +Dictionary:: + AtPut(uint32_t, Object*); -template MaybeObject* Dictionary:: +template MaybeObject* +Dictionary:: AtPut(uint32_t, Object*); -template Object* Dictionary:: +template Object* +Dictionary:: SlowReverseLookup(Object* value); -template Object* Dictionary:: +template Object* +Dictionary:: SlowReverseLookup(Object* value); -template Object* Dictionary::SlowReverseLookup( +template Object* +Dictionary::SlowReverseLookup( Object*); -template void Dictionary::CopyKeysTo( - FixedArray*, - PropertyAttributes, - Dictionary::SortMode); - -template Object* Dictionary::DeleteProperty( +template void +Dictionary:: + CopyKeysTo( + FixedArray*, + PropertyAttributes, + Dictionary::SortMode); + +template Object* +Dictionary::DeleteProperty( int, JSObject::DeleteMode); -template Handle Dictionary::DeleteProperty( - Handle >, +template Handle +Dictionary::DeleteProperty( + Handle >, int, JSObject::DeleteMode); -template Object* Dictionary:: +template Object* +Dictionary:: DeleteProperty(int, JSObject::DeleteMode); template Handle -Dictionary::DeleteProperty( - Handle >, - int, - JSObject::DeleteMode); - -template MaybeObject* Dictionary::Shrink(Name* n); - -template MaybeObject* Dictionary::Shrink( - uint32_t); -template Handle -Dictionary::Shrink( - Handle >, - uint32_t); - -template void Dictionary::CopyKeysTo( - FixedArray*, - int, - PropertyAttributes, - Dictionary::SortMode); +Dictionary:: + DeleteProperty( + Handle >, + int, + JSObject::DeleteMode); + +template void Dictionary:: + CopyKeysTo( + FixedArray*, + int, + PropertyAttributes, + Dictionary::SortMode); template int -Dictionary::NumberOfElementsFilterAttributes( - PropertyAttributes); +Dictionary:: + NumberOfElementsFilterAttributes(PropertyAttributes); -template MaybeObject* Dictionary::Add( +template MaybeObject* +Dictionary::Add( Name*, Object*, PropertyDetails); template MaybeObject* -Dictionary::GenerateNewEnumerationIndices(); +Dictionary:: + GenerateNewEnumerationIndices(); template int -Dictionary:: +Dictionary:: NumberOfElementsFilterAttributes(PropertyAttributes); -template MaybeObject* Dictionary::Add( +template MaybeObject* +Dictionary::Add( uint32_t, Object*, PropertyDetails); -template MaybeObject* Dictionary::Add( - uint32_t, Object*, PropertyDetails); +template MaybeObject* +Dictionary:: + Add(uint32_t, Object*, PropertyDetails); -template MaybeObject* Dictionary:: +template MaybeObject* +Dictionary:: EnsureCapacity(int, uint32_t); -template MaybeObject* Dictionary:: +template MaybeObject* +Dictionary:: EnsureCapacity(int, uint32_t); -template MaybeObject* Dictionary:: +template MaybeObject* +Dictionary:: EnsureCapacity(int, Name*); -template MaybeObject* Dictionary:: +template MaybeObject* +Dictionary:: AddEntry(uint32_t, Object*, PropertyDetails, uint32_t); -template MaybeObject* Dictionary:: +template MaybeObject* +Dictionary:: AddEntry(uint32_t, Object*, PropertyDetails, uint32_t); -template MaybeObject* Dictionary::AddEntry( +template MaybeObject* +Dictionary::AddEntry( Name*, Object*, PropertyDetails, uint32_t); template -int Dictionary::NumberOfEnumElements(); +int Dictionary:: + NumberOfEnumElements(); template -int Dictionary::NumberOfEnumElements(); +int Dictionary:: + NumberOfEnumElements(); template -int HashTable::FindEntry(uint32_t); +int HashTable:: + FindEntry(uint32_t); Handle JSObject::PrepareSlowElementsForSort( @@ -15169,13 +15206,14 @@ MaybeObject* MapCache::Put(FixedArray* array, Map* value) { } -template -MaybeObject* Dictionary::Allocate(Heap* heap, - int at_least_space_for, - PretenureFlag pretenure) { +template +MaybeObject* Dictionary::Allocate( + Heap* heap, + int at_least_space_for, + PretenureFlag pretenure) { Object* obj; { MaybeObject* maybe_obj = - HashTable::Allocate( + DerivedHashTable::Allocate( heap, at_least_space_for, USE_DEFAULT_MINIMUM_CAPACITY, @@ -15183,7 +15221,7 @@ MaybeObject* Dictionary::Allocate(Heap* heap, if (!maybe_obj->ToObject(&obj)) return maybe_obj; } // Initialize the next enumeration index. - Dictionary::cast(obj)-> + Dictionary::cast(obj)-> SetNextEnumerationIndex(PropertyDetails::kInitialIndex); return obj; } @@ -15195,10 +15233,10 @@ void NameDictionary::DoGenerateNewEnumerationIndices( dictionary->GenerateNewEnumerationIndices()); } -template -MaybeObject* Dictionary::GenerateNewEnumerationIndices() { - Heap* heap = Dictionary::GetHeap(); - int length = HashTable::NumberOfElements(); +template +MaybeObject* Dictionary::GenerateNewEnumerationIndices() { + Heap* heap = Dictionary::GetHeap(); + int length = DerivedHashTable::NumberOfElements(); // Allocate and initialize iteration order array. Object* obj; @@ -15217,10 +15255,10 @@ MaybeObject* Dictionary::GenerateNewEnumerationIndices() { FixedArray* enumeration_order = FixedArray::cast(obj); // Fill the enumeration order array with property details. - int capacity = HashTable::Capacity(); + int capacity = DerivedHashTable::Capacity(); int pos = 0; for (int i = 0; i < capacity; i++) { - if (Dictionary::IsKey(Dictionary::KeyAt(i))) { + if (Dictionary::IsKey(Dictionary::KeyAt(i))) { int index = DetailsAt(i).dictionary_index(); enumeration_order->set(pos++, Smi::FromInt(index)); } @@ -15237,10 +15275,10 @@ MaybeObject* Dictionary::GenerateNewEnumerationIndices() { } // Update the dictionary with new indices. - capacity = HashTable::Capacity(); + capacity = DerivedHashTable::Capacity(); pos = 0; for (int i = 0; i < capacity; i++) { - if (Dictionary::IsKey(Dictionary::KeyAt(i))) { + if (Dictionary::IsKey(Dictionary::KeyAt(i))) { int enum_index = Smi::cast(enumeration_order->get(pos++))->value(); PropertyDetails details = DetailsAt(i); PropertyDetails new_details = PropertyDetails( @@ -15254,8 +15292,8 @@ MaybeObject* Dictionary::GenerateNewEnumerationIndices() { return this; } -template -MaybeObject* Dictionary::EnsureCapacity(int n, Key key) { +template +MaybeObject* Dictionary::EnsureCapacity(int n, Key key) { // Check whether there are enough enumeration indices to add n elements. if (Shape::kIsEnumerable && !PropertyDetails::IsValidIndex(NextEnumerationIndex() + n)) { @@ -15265,14 +15303,14 @@ MaybeObject* Dictionary::EnsureCapacity(int n, Key key) { if (!maybe_result->ToObject(&result)) return maybe_result; } } - return HashTable::EnsureCapacity(n, key); + return DerivedHashTable::EnsureCapacity(n, key); } // TODO(ishell): Temporary wrapper until handlified. -template -Handle Dictionary::DeleteProperty( - Handle > dictionary, +template +Handle Dictionary::DeleteProperty( + Handle > dictionary, int entry, JSObject::DeleteMode mode) { CALL_HEAP_FUNCTION(dictionary->GetIsolate(), @@ -15281,44 +15319,28 @@ Handle Dictionary::DeleteProperty( } -template -Object* Dictionary::DeleteProperty(int entry, - JSReceiver::DeleteMode mode) { - Heap* heap = Dictionary::GetHeap(); +template +Object* Dictionary::DeleteProperty( + int entry, + JSReceiver::DeleteMode mode) { + Heap* heap = Dictionary::GetHeap(); PropertyDetails details = DetailsAt(entry); // Ignore attributes if forcing a deletion. if (details.IsDontDelete() && mode != JSReceiver::FORCE_DELETION) { return heap->false_value(); } SetEntry(entry, heap->the_hole_value(), heap->the_hole_value()); - HashTable::ElementRemoved(); + DerivedHashTable::ElementRemoved(); return heap->true_value(); } -// TODO(ishell): Temporary wrapper until handlified. -template -Handle Dictionary::Shrink( - Handle > dictionary, - Key key) { - CALL_HEAP_FUNCTION(dictionary->GetIsolate(), - dictionary->Shrink(key), - FixedArray); -} - - -template -MaybeObject* Dictionary::Shrink(Key key) { - return HashTable::Shrink(key); -} - - -template -MaybeObject* Dictionary::AtPut(Key key, Object* value) { +template +MaybeObject* Dictionary::AtPut(Key key, Object* value) { int entry = this->FindEntry(key); // If the entry is present set the value; - if (entry != Dictionary::kNotFound) { + if (entry != Dictionary::kNotFound) { ValueAtPut(entry, value); return this; } @@ -15335,41 +15357,43 @@ MaybeObject* Dictionary::AtPut(Key key, Object* value) { } PropertyDetails details = PropertyDetails(NONE, NORMAL, 0); - return Dictionary::cast(obj)->AddEntry(key, value, details, - Dictionary::Hash(key)); + return Dictionary::cast(obj)->AddEntry( + key, value, details, Dictionary::Hash(key)); } -template -MaybeObject* Dictionary::Add(Key key, - Object* value, - PropertyDetails details) { +template +MaybeObject* Dictionary::Add( + Key key, + Object* value, + PropertyDetails details) { // Valdate key is absent. - SLOW_ASSERT((this->FindEntry(key) == Dictionary::kNotFound)); + SLOW_ASSERT((this->FindEntry(key) == Dictionary::kNotFound)); // Check whether the dictionary should be extended. Object* obj; { MaybeObject* maybe_obj = EnsureCapacity(1, key); if (!maybe_obj->ToObject(&obj)) return maybe_obj; } - return Dictionary::cast(obj)->AddEntry(key, value, details, - Dictionary::Hash(key)); + return Dictionary::cast(obj)->AddEntry( + key, value, details, Dictionary::Hash(key)); } // Add a key, value pair to the dictionary. -template -MaybeObject* Dictionary::AddEntry(Key key, - Object* value, - PropertyDetails details, - uint32_t hash) { +template +MaybeObject* Dictionary::AddEntry( + Key key, + Object* value, + PropertyDetails details, + uint32_t hash) { // Compute the key object. Object* k; { MaybeObject* maybe_k = Shape::AsObject(this->GetHeap(), key); if (!maybe_k->ToObject(&k)) return maybe_k; } - uint32_t entry = Dictionary::FindInsertionEntry(hash); + uint32_t entry = Dictionary::FindInsertionEntry(hash); // Insert element at empty or deleted entry if (!details.IsDeleted() && details.dictionary_index() == 0 && @@ -15381,9 +15405,9 @@ MaybeObject* Dictionary::AddEntry(Key key, SetNextEnumerationIndex(index + 1); } SetEntry(entry, k, value, details); - ASSERT((Dictionary::KeyAt(entry)->IsNumber() || - Dictionary::KeyAt(entry)->IsName())); - HashTable::ElementAdded(); + ASSERT((Dictionary::KeyAt(entry)->IsNumber() || + Dictionary::KeyAt(entry)->IsName())); + DerivedHashTable::ElementAdded(); return this; } @@ -15497,14 +15521,14 @@ MaybeObject* UnseededNumberDictionary::Set(uint32_t key, -template -int Dictionary::NumberOfElementsFilterAttributes( +template +int Dictionary::NumberOfElementsFilterAttributes( PropertyAttributes filter) { - int capacity = HashTable::Capacity(); + int capacity = DerivedHashTable::Capacity(); int result = 0; for (int i = 0; i < capacity; i++) { - Object* k = HashTable::KeyAt(i); - if (HashTable::IsKey(k) && !FilterKey(k, filter)) { + Object* k = DerivedHashTable::KeyAt(i); + if (DerivedHashTable::IsKey(k) && !FilterKey(k, filter)) { PropertyDetails details = DetailsAt(i); if (details.IsDeleted()) continue; PropertyAttributes attr = details.attributes(); @@ -15515,31 +15539,31 @@ int Dictionary::NumberOfElementsFilterAttributes( } -template -int Dictionary::NumberOfEnumElements() { +template +int Dictionary::NumberOfEnumElements() { return NumberOfElementsFilterAttributes( static_cast(DONT_ENUM | SYMBOLIC)); } -template -void Dictionary::CopyKeysTo( +template +void Dictionary::CopyKeysTo( FixedArray* storage, PropertyAttributes filter, - typename Dictionary::SortMode sort_mode) { + typename Dictionary::SortMode sort_mode) { ASSERT(storage->length() >= NumberOfElementsFilterAttributes(filter)); - int capacity = HashTable::Capacity(); + int capacity = DerivedHashTable::Capacity(); int index = 0; for (int i = 0; i < capacity; i++) { - Object* k = HashTable::KeyAt(i); - if (HashTable::IsKey(k) && !FilterKey(k, filter)) { + Object* k = DerivedHashTable::KeyAt(i); + if (DerivedHashTable::IsKey(k) && !FilterKey(k, filter)) { PropertyDetails details = DetailsAt(i); if (details.IsDeleted()) continue; PropertyAttributes attr = details.attributes(); if ((attr & filter) == 0) storage->set(index++, k); } } - if (sort_mode == Dictionary::SORTED) { + if (sort_mode == Dictionary::SORTED) { storage->SortPairs(storage, index); } ASSERT(storage->length() >= index); @@ -15581,24 +15605,24 @@ void NameDictionary::CopyEnumKeysTo(FixedArray* storage) { } -template -void Dictionary::CopyKeysTo( +template +void Dictionary::CopyKeysTo( FixedArray* storage, int index, PropertyAttributes filter, - typename Dictionary::SortMode sort_mode) { + typename Dictionary::SortMode sort_mode) { ASSERT(storage->length() >= NumberOfElementsFilterAttributes(filter)); - int capacity = HashTable::Capacity(); + int capacity = DerivedHashTable::Capacity(); for (int i = 0; i < capacity; i++) { - Object* k = HashTable::KeyAt(i); - if (HashTable::IsKey(k) && !FilterKey(k, filter)) { + Object* k = DerivedHashTable::KeyAt(i); + if (DerivedHashTable::IsKey(k) && !FilterKey(k, filter)) { PropertyDetails details = DetailsAt(i); if (details.IsDeleted()) continue; PropertyAttributes attr = details.attributes(); if ((attr & filter) == 0) storage->set(index++, k); } } - if (sort_mode == Dictionary::SORTED) { + if (sort_mode == Dictionary::SORTED) { storage->SortPairs(storage, index); } ASSERT(storage->length() >= index); @@ -15606,12 +15630,12 @@ void Dictionary::CopyKeysTo( // Backwards lookup (slow). -template -Object* Dictionary::SlowReverseLookup(Object* value) { - int capacity = HashTable::Capacity(); +template +Object* Dictionary::SlowReverseLookup(Object* value) { + int capacity = DerivedHashTable::Capacity(); for (int i = 0; i < capacity; i++) { - Object* k = HashTable::KeyAt(i); - if (Dictionary::IsKey(k)) { + Object* k = DerivedHashTable::KeyAt(i); + if (Dictionary::IsKey(k)) { Object* e = ValueAt(i); if (e->IsPropertyCell()) { e = PropertyCell::cast(e)->value(); @@ -15619,7 +15643,7 @@ Object* Dictionary::SlowReverseLookup(Object* value) { if (e == value) return k; } } - Heap* heap = Dictionary::GetHeap(); + Heap* heap = Dictionary::GetHeap(); return heap->undefined_value(); } @@ -15629,22 +15653,15 @@ Handle ObjectHashTable::EnsureCapacity( int n, Handle key, PretenureFlag pretenure) { - Handle > table_base = table; + Handle > table_base = table; CALL_HEAP_FUNCTION(table_base->GetIsolate(), table_base->EnsureCapacity(n, *key, pretenure), ObjectHashTable); } -Handle ObjectHashTable::Shrink( - Handle table, Handle key) { - Handle > table_base = table; - CALL_HEAP_FUNCTION(table_base->GetIsolate(), - table_base->Shrink(*key), - ObjectHashTable); -} - - Object* ObjectHashTable::Lookup(Object* key) { ASSERT(IsKey(key)); diff --git a/src/objects.h b/src/objects.h index 1f656bc..9502df1 100644 --- a/src/objects.h +++ b/src/objects.h @@ -3652,7 +3652,7 @@ class BaseShape { } }; -template +template class HashTable: public FixedArray { public: // Wrapper methods @@ -3705,12 +3705,20 @@ class HashTable: public FixedArray { } // Returns a new HashTable object. Might return Failure. + // TODO(ishell): this will be eventually replaced by New(). MUST_USE_RESULT static MaybeObject* Allocate( Heap* heap, int at_least_space_for, MinimumCapacity capacity_option = USE_DEFAULT_MINIMUM_CAPACITY, PretenureFlag pretenure = NOT_TENURED); + // Returns a new HashTable object. + static Handle New( + Isolate* isolate, + int at_least_space_for, + MinimumCapacity capacity_option = USE_DEFAULT_MINIMUM_CAPACITY, + PretenureFlag pretenure = NOT_TENURED); + // Computes the required capacity for a table holding the given // number of elements. May be more than HashTable::kMaxCapacity. static int ComputeCapacity(int at_least_space_for); @@ -3820,10 +3828,10 @@ class HashTable: public FixedArray { void Swap(uint32_t entry1, uint32_t entry2, WriteBarrierMode mode); // Rehashes this hash-table into the new table. - MUST_USE_RESULT MaybeObject* Rehash(HashTable* new_table, Key key); + void Rehash(Derived* new_table, Key key); // Attempt to shrink hash table after removal of key. - MUST_USE_RESULT MaybeObject* Shrink(Key key); + static Handle Shrink(Handle table, Key key); // Ensure enough space for n additional elements. MUST_USE_RESULT MaybeObject* EnsureCapacity( @@ -3876,7 +3884,9 @@ class SeqOneByteString; // // No special elements in the prefix and the element size is 1 // because only the string itself (the key) needs to be stored. -class StringTable: public HashTable { +class StringTable: public HashTable { public: // Find string in the string table. If it is not there yet, it is // added. The return value is the string table which might have @@ -3928,7 +3938,7 @@ class MapCacheShape : public BaseShape { // // Maps keys that are a fixed array of unique names to a map. // Used for canonicalize maps for object literals. -class MapCache: public HashTable { +class MapCache: public HashTable { public: // Find cached value for a name key, otherwise return null. Object* Lookup(FixedArray* key); @@ -3940,33 +3950,36 @@ class MapCache: public HashTable { }; -template -class Dictionary: public HashTable { +template +class Dictionary: public HashTable { + protected: + typedef HashTable DerivedHashTable; + public: - static inline Dictionary* cast(Object* obj) { - return reinterpret_cast*>(obj); + static inline Dictionary* cast(Object* obj) { + return reinterpret_cast(obj); } // Returns the value at entry. Object* ValueAt(int entry) { - return this->get(HashTable::EntryToIndex(entry) + 1); + return this->get(DerivedHashTable::EntryToIndex(entry) + 1); } // Set the value for entry. void ValueAtPut(int entry, Object* value) { - this->set(HashTable::EntryToIndex(entry) + 1, value); + this->set(DerivedHashTable::EntryToIndex(entry) + 1, value); } // Returns the property details for the property at entry. PropertyDetails DetailsAt(int entry) { ASSERT(entry >= 0); // Not found is -1, which is not caught by get(). return PropertyDetails( - Smi::cast(this->get(HashTable::EntryToIndex(entry) + 2))); + Smi::cast(this->get(DerivedHashTable::EntryToIndex(entry) + 2))); } // Set the details for entry. void DetailsAtPut(int entry, PropertyDetails value) { - this->set(HashTable::EntryToIndex(entry) + 2, value.AsSmi()); + this->set(DerivedHashTable::EntryToIndex(entry) + 2, value.AsSmi()); } // Sorting support @@ -3976,16 +3989,14 @@ class Dictionary: public HashTable { Object* DeleteProperty(int entry, JSObject::DeleteMode mode); // TODO(ishell): Temporary wrapper until handlified. static Handle DeleteProperty( - Handle > dictionary, + Handle dictionary, int entry, JSObject::DeleteMode mode); // Attempt to shrink the dictionary after deletion of key. - MUST_USE_RESULT MaybeObject* Shrink(Key key); - // TODO(ishell): Temporary wrapper until handlified. - MUST_USE_RESULT static Handle Shrink( - Handle > dictionary, - Key key); + static inline Handle Shrink(Handle dictionary, Key key) { + return DerivedHashTable::Shrink(dictionary, key); + } // Returns the number of elements in the dictionary filtering out properties // with the specified attributes. @@ -4055,8 +4066,7 @@ class Dictionary: public HashTable { // Generate new enumeration indices to avoid enumeration index overflow. MUST_USE_RESULT MaybeObject* GenerateNewEnumerationIndices(); - static const int kMaxNumberKeyIndex = - HashTable::kPrefixStartIndex; + static const int kMaxNumberKeyIndex = DerivedHashTable::kPrefixStartIndex; static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1; }; @@ -4074,7 +4084,9 @@ class NameDictionaryShape : public BaseShape { }; -class NameDictionary: public Dictionary { +class NameDictionary: public Dictionary { public: static inline NameDictionary* cast(Object* obj) { ASSERT(obj->IsDictionary()); @@ -4124,7 +4136,9 @@ class UnseededNumberDictionaryShape : public NumberDictionaryShape { class SeededNumberDictionary - : public Dictionary { + : public Dictionary { public: static SeededNumberDictionary* cast(Object* obj) { ASSERT(obj->IsDictionary()); @@ -4177,7 +4191,9 @@ class SeededNumberDictionary class UnseededNumberDictionary - : public Dictionary { + : public Dictionary { public: static UnseededNumberDictionary* cast(Object* obj) { ASSERT(obj->IsDictionary()); @@ -4213,7 +4229,10 @@ class ObjectHashTableShape : public BaseShape { // ObjectHashTable maps keys that are arbitrary objects to object values by // using the identity hash of the key for hashing purposes. -class ObjectHashTable: public HashTable { +class ObjectHashTable: public HashTable { + typedef HashTable HashTable_; public: static inline ObjectHashTable* cast(Object* obj) { ASSERT(obj->IsHashTable()); @@ -4227,8 +4246,8 @@ class ObjectHashTable: public HashTable { PretenureFlag pretenure = NOT_TENURED); // Attempt to shrink hash table after removal of key. - static Handle Shrink(Handle table, - Handle key); + static inline Handle Shrink(Handle table, + Handle key); // Looks up the value associated with the given key. The hole value is // returned in case the key is not present. @@ -4426,7 +4445,9 @@ class WeakHashTableShape : public BaseShape { // WeakHashTable maps keys that are arbitrary objects to object values. // It is used for the global weak hash table that maps objects // embedded in optimized code to dependent code lists. -class WeakHashTable: public HashTable, Object*> { +class WeakHashTable: public HashTable, + Object*> { public: static inline WeakHashTable* cast(Object* obj) { ASSERT(obj->IsHashTable()); @@ -8198,7 +8219,8 @@ class CompilationCacheShape : public BaseShape { }; -class CompilationCacheTable: public HashTable { public: // Find cached value for a string key, otherwise return null. @@ -8299,7 +8321,8 @@ class CodeCacheHashTableShape : public BaseShape { }; -class CodeCacheHashTable: public HashTable { public: Object* Lookup(Name* name, Code::Flags flags); @@ -8349,7 +8372,9 @@ class PolymorphicCodeCache: public Struct { class PolymorphicCodeCacheHashTable - : public HashTable { + : public HashTable { public: Object* Lookup(MapHandleList* maps, int code_kind);