From: ishell@chromium.org Date: Fri, 25 Apr 2014 08:31:21 +0000 (+0000) Subject: Revert "HashTable::EnsureCapacity() handlified." X-Git-Tag: upstream/4.7.83~9434 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9bda4a298790711014d76ccea9d04e6255a878e2;p=platform%2Fupstream%2Fv8.git Revert "HashTable::EnsureCapacity() handlified." This reverts commit r20960 for breaking Windows build. TBR=yangguo@chromium.org Review URL: https://codereview.chromium.org/250893002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20961 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/objects.cc b/src/objects.cc index fcaa25a..2a7252c 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -14677,9 +14677,7 @@ int NameDictionary::FindEntry(Handle key) { template -void HashTable::Rehash( - Handle new_table, - Key key) { +void HashTable::Rehash(Derived* new_table, Key key) { ASSERT(NumberOfElements() < new_table->Capacity()); DisallowHeapAllocation no_gc; @@ -14781,35 +14779,49 @@ void HashTable::Rehash(Key key) { template -Handle HashTable::EnsureCapacity( - Handle table, +MaybeObject* HashTable::EnsureCapacity( int n, Key key, PretenureFlag pretenure) { - Isolate* isolate = table->GetIsolate(); - int capacity = table->Capacity(); - int nof = table->NumberOfElements() + n; - int nod = table->NumberOfDeletedElements(); + int capacity = Capacity(); + int nof = NumberOfElements() + n; + int nod = NumberOfDeletedElements(); // Return if: // 50% is still free after adding n elements and // at most 50% of the free elements are deleted elements. if (nod <= (capacity - nof) >> 1) { int needed_free = nof >> 1; - if (nof + needed_free <= capacity) return table; + if (nof + needed_free <= capacity) return this; } const int kMinCapacityForPretenure = 256; bool should_pretenure = pretenure == TENURED || - ((capacity > kMinCapacityForPretenure) && - !isolate->heap()->InNewSpace(*table)); - Handle new_table = HashTable::New( - isolate, - nof * 2, - USE_DEFAULT_MINIMUM_CAPACITY, - should_pretenure ? TENURED : NOT_TENURED); + ((capacity > kMinCapacityForPretenure) && !GetHeap()->InNewSpace(this)); + Object* obj; + { MaybeObject* maybe_obj = + Allocate(GetHeap(), + nof * 2, + USE_DEFAULT_MINIMUM_CAPACITY, + should_pretenure ? TENURED : NOT_TENURED); + if (!maybe_obj->ToObject(&obj)) return maybe_obj; + } - table->Rehash(new_table, key); - return new_table; + Rehash(Derived::cast(obj), key); + return Derived::cast(obj); +} + + +template +Handle HashTable::EnsureCapacity( + Handle table, + int n, + Key key, + PretenureFlag pretenure) { + Isolate* isolate = table->GetIsolate(); + CALL_HEAP_FUNCTION( + isolate, + static_cast(*table)->EnsureCapacity(n, key, pretenure), + Derived); } @@ -14834,13 +14846,13 @@ Handle HashTable::Shrink(Handle table, bool pretenure = (at_least_room_for > kMinCapacityForPretenure) && !isolate->heap()->InNewSpace(*table); - Handle new_table = HashTable::New( + Handle new_table = New( isolate, at_least_room_for, USE_DEFAULT_MINIMUM_CAPACITY, pretenure ? TENURED : NOT_TENURED); - table->Rehash(new_table, key); + table->Rehash(*new_table, key); return new_table; } diff --git a/src/objects.h b/src/objects.h index 3fd8d7b..d926165 100644 --- a/src/objects.h +++ b/src/objects.h @@ -3736,7 +3736,7 @@ class HashTable: public FixedArray { PretenureFlag pretenure = NOT_TENURED); // Returns a new HashTable object. - MUST_USE_RESULT static Handle New( + static Handle New( Isolate* isolate, int at_least_space_for, MinimumCapacity capacity_option = USE_DEFAULT_MINIMUM_CAPACITY, @@ -3843,17 +3843,6 @@ class HashTable: public FixedArray { return (last + number) & (size - 1); } - // Attempt to shrink hash table after removal of key. - static Handle Shrink(Handle table, Key key); - - // Ensure enough space for n additional elements. - MUST_USE_RESULT static Handle EnsureCapacity( - Handle table, - int n, - Key key, - PretenureFlag pretenure = NOT_TENURED); - - private: // Returns _expected_ if one of entries given by the first _probe_ probes is // equal to _expected_. Otherwise, returns the entry given by the probe // number _probe_. @@ -3862,7 +3851,21 @@ class HashTable: public FixedArray { void Swap(uint32_t entry1, uint32_t entry2, WriteBarrierMode mode); // Rehashes this hash-table into the new table. - void Rehash(Handle new_table, Key key); + void Rehash(Derived* new_table, Key key); + + // Attempt to shrink hash table after removal of key. + static Handle Shrink(Handle table, Key key); + + // Ensure enough space for n additional elements. + MUST_USE_RESULT MaybeObject* EnsureCapacity( + int n, + Key key, + PretenureFlag pretenure = NOT_TENURED); + static Handle EnsureCapacity( + Handle table, + int n, + Key key, + PretenureFlag pretenure = NOT_TENURED); }; @@ -4105,15 +4108,6 @@ class Dictionary: public HashTable { static void GenerateNewEnumerationIndices(Handle dictionary); static const int kMaxNumberKeyIndex = DerivedHashTable::kPrefixStartIndex; static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1; - - private: - // This is to hide HashTable::New() which could clash with Dictionary::New(). - // The latter one must be used for creating Dictionary and successors. - MUST_USE_RESULT static Handle New( - Isolate* isolate, - int at_least_space_for, - MinimumCapacity capacity_option, - PretenureFlag pretenure); };