Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: src/objects.cc

Issue 1619473006: Version 4.9.385.8 (cherry-pick) (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@4.9
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/objects.h" 5 #include "src/objects.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <iomanip> 8 #include <iomanip>
9 #include <sstream> 9 #include <sstream>
10 10
(...skipping 17168 matching lines...) Expand 10 before | Expand all | Expand 10 after
17179 17179
17180 template<typename Derived, typename Shape, typename Key> 17180 template<typename Derived, typename Shape, typename Key>
17181 Handle<Derived> HashTable<Derived, Shape, Key>::EnsureCapacity( 17181 Handle<Derived> HashTable<Derived, Shape, Key>::EnsureCapacity(
17182 Handle<Derived> table, 17182 Handle<Derived> table,
17183 int n, 17183 int n,
17184 Key key, 17184 Key key,
17185 PretenureFlag pretenure) { 17185 PretenureFlag pretenure) {
17186 Isolate* isolate = table->GetIsolate(); 17186 Isolate* isolate = table->GetIsolate();
17187 int capacity = table->Capacity(); 17187 int capacity = table->Capacity();
17188 int nof = table->NumberOfElements() + n; 17188 int nof = table->NumberOfElements() + n;
17189 int nod = table->NumberOfDeletedElements(); 17189
17190 // Return if: 17190 if (table->HasSufficientCapacity(n)) return table;
17191 // 50% is still free after adding n elements and
17192 // at most 50% of the free elements are deleted elements.
17193 if (nod <= (capacity - nof) >> 1) {
17194 int needed_free = nof >> 1;
17195 if (nof + needed_free <= capacity) return table;
17196 }
17197 17191
17198 const int kMinCapacityForPretenure = 256; 17192 const int kMinCapacityForPretenure = 256;
17199 bool should_pretenure = pretenure == TENURED || 17193 bool should_pretenure = pretenure == TENURED ||
17200 ((capacity > kMinCapacityForPretenure) && 17194 ((capacity > kMinCapacityForPretenure) &&
17201 !isolate->heap()->InNewSpace(*table)); 17195 !isolate->heap()->InNewSpace(*table));
17202 Handle<Derived> new_table = HashTable::New( 17196 Handle<Derived> new_table = HashTable::New(
17203 isolate, 17197 isolate,
17204 nof * 2, 17198 nof * 2,
17205 USE_DEFAULT_MINIMUM_CAPACITY, 17199 USE_DEFAULT_MINIMUM_CAPACITY,
17206 should_pretenure ? TENURED : NOT_TENURED); 17200 should_pretenure ? TENURED : NOT_TENURED);
17207 17201
17208 table->Rehash(new_table, key); 17202 table->Rehash(new_table, key);
17209 return new_table; 17203 return new_table;
17210 } 17204 }
17211 17205
17212 17206
17207 template <typename Derived, typename Shape, typename Key>
17208 bool HashTable<Derived, Shape, Key>::HasSufficientCapacity(int n) {
17209 int capacity = Capacity();
17210 int nof = NumberOfElements() + n;
17211 int nod = NumberOfDeletedElements();
17212 // Return true if:
17213 // 50% is still free after adding n elements and
17214 // at most 50% of the free elements are deleted elements.
17215 if (nod <= (capacity - nof) >> 1) {
17216 int needed_free = nof >> 1;
17217 if (nof + needed_free <= capacity) return true;
17218 }
17219 return false;
17220 }
17221
17222
17213 template<typename Derived, typename Shape, typename Key> 17223 template<typename Derived, typename Shape, typename Key>
17214 Handle<Derived> HashTable<Derived, Shape, Key>::Shrink(Handle<Derived> table, 17224 Handle<Derived> HashTable<Derived, Shape, Key>::Shrink(Handle<Derived> table,
17215 Key key) { 17225 Key key) {
17216 int capacity = table->Capacity(); 17226 int capacity = table->Capacity();
17217 int nof = table->NumberOfElements(); 17227 int nof = table->NumberOfElements();
17218 17228
17219 // Shrink to fit the number of elements if only a quarter of the 17229 // Shrink to fit the number of elements if only a quarter of the
17220 // capacity is filled with elements. 17230 // capacity is filled with elements.
17221 if (nof > (capacity >> 2)) return table; 17231 if (nof > (capacity >> 2)) return table;
17222 // Allocate a new dictionary with room for at least the current 17232 // Allocate a new dictionary with room for at least the current
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
17369 PropertyDetails); 17379 PropertyDetails);
17370 17380
17371 template Handle<SeededNumberDictionary> 17381 template Handle<SeededNumberDictionary>
17372 Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>:: 17382 Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>::
17373 EnsureCapacity(Handle<SeededNumberDictionary>, int, uint32_t); 17383 EnsureCapacity(Handle<SeededNumberDictionary>, int, uint32_t);
17374 17384
17375 template Handle<UnseededNumberDictionary> 17385 template Handle<UnseededNumberDictionary>
17376 Dictionary<UnseededNumberDictionary, UnseededNumberDictionaryShape, uint32_t>:: 17386 Dictionary<UnseededNumberDictionary, UnseededNumberDictionaryShape, uint32_t>::
17377 EnsureCapacity(Handle<UnseededNumberDictionary>, int, uint32_t); 17387 EnsureCapacity(Handle<UnseededNumberDictionary>, int, uint32_t);
17378 17388
17389 template void Dictionary<NameDictionary, NameDictionaryShape,
17390 Handle<Name> >::SetRequiresCopyOnCapacityChange();
17391
17379 template Handle<NameDictionary> 17392 template Handle<NameDictionary>
17380 Dictionary<NameDictionary, NameDictionaryShape, Handle<Name> >:: 17393 Dictionary<NameDictionary, NameDictionaryShape, Handle<Name> >::
17381 EnsureCapacity(Handle<NameDictionary>, int, Handle<Name>); 17394 EnsureCapacity(Handle<NameDictionary>, int, Handle<Name>);
17382 17395
17383 template bool Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, 17396 template bool Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape,
17384 uint32_t>::HasComplexElements(); 17397 uint32_t>::HasComplexElements();
17385 17398
17386 template int HashTable<SeededNumberDictionary, SeededNumberDictionaryShape, 17399 template int HashTable<SeededNumberDictionary, SeededNumberDictionaryShape,
17387 uint32_t>::FindEntry(uint32_t); 17400 uint32_t>::FindEntry(uint32_t);
17388 17401
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after
18097 PropertyDetails new_details = details.set_index(enum_index); 18110 PropertyDetails new_details = details.set_index(enum_index);
18098 dictionary->DetailsAtPut(index, new_details); 18111 dictionary->DetailsAtPut(index, new_details);
18099 } 18112 }
18100 18113
18101 // Set the next enumeration index. 18114 // Set the next enumeration index.
18102 dictionary->SetNextEnumerationIndex(PropertyDetails::kInitialIndex+length); 18115 dictionary->SetNextEnumerationIndex(PropertyDetails::kInitialIndex+length);
18103 return iteration_order; 18116 return iteration_order;
18104 } 18117 }
18105 18118
18106 18119
18107 template<typename Derived, typename Shape, typename Key> 18120 template <typename Derived, typename Shape, typename Key>
18121 void Dictionary<Derived, Shape, Key>::SetRequiresCopyOnCapacityChange() {
18122 DCHECK_EQ(0, DerivedHashTable::NumberOfElements());
18123 DCHECK_EQ(0, DerivedHashTable::NumberOfDeletedElements());
18124 // Make sure that HashTable::EnsureCapacity will create a copy.
18125 DerivedHashTable::SetNumberOfDeletedElements(DerivedHashTable::Capacity());
18126 DCHECK(!DerivedHashTable::HasSufficientCapacity(1));
18127 }
18128
18129
18130 template <typename Derived, typename Shape, typename Key>
18108 Handle<Derived> Dictionary<Derived, Shape, Key>::EnsureCapacity( 18131 Handle<Derived> Dictionary<Derived, Shape, Key>::EnsureCapacity(
18109 Handle<Derived> dictionary, int n, Key key) { 18132 Handle<Derived> dictionary, int n, Key key) {
18110 // Check whether there are enough enumeration indices to add n elements. 18133 // Check whether there are enough enumeration indices to add n elements.
18111 if (Shape::kIsEnumerable && 18134 if (Shape::kIsEnumerable &&
18112 !PropertyDetails::IsValidIndex(dictionary->NextEnumerationIndex() + n)) { 18135 !PropertyDetails::IsValidIndex(dictionary->NextEnumerationIndex() + n)) {
18113 // If not, we generate new indices for the properties. 18136 // If not, we generate new indices for the properties.
18114 GenerateNewEnumerationIndices(dictionary); 18137 GenerateNewEnumerationIndices(dictionary);
18115 } 18138 }
18116 return DerivedHashTable::EnsureCapacity(dictionary, n, key); 18139 return DerivedHashTable::EnsureCapacity(dictionary, n, key);
18117 } 18140 }
(...skipping 1551 matching lines...) Expand 10 before | Expand all | Expand 10 after
19669 if (cell->value() != *new_value) { 19692 if (cell->value() != *new_value) {
19670 cell->set_value(*new_value); 19693 cell->set_value(*new_value);
19671 Isolate* isolate = cell->GetIsolate(); 19694 Isolate* isolate = cell->GetIsolate();
19672 cell->dependent_code()->DeoptimizeDependentCodeGroup( 19695 cell->dependent_code()->DeoptimizeDependentCodeGroup(
19673 isolate, DependentCode::kPropertyCellChangedGroup); 19696 isolate, DependentCode::kPropertyCellChangedGroup);
19674 } 19697 }
19675 } 19698 }
19676 19699
19677 } // namespace internal 19700 } // namespace internal
19678 } // namespace v8 19701 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698