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

Side by Side Diff: src/objects.cc

Issue 2162333002: Fix incorrect parameter to HasSufficientCapacity (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 4 years, 5 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') | no next file » | 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 16259 matching lines...) Expand 10 before | Expand all | Expand 10 after
16270 template<typename Derived, typename Shape, typename Key> 16270 template<typename Derived, typename Shape, typename Key>
16271 Handle<Derived> HashTable<Derived, Shape, Key>::EnsureCapacity( 16271 Handle<Derived> HashTable<Derived, Shape, Key>::EnsureCapacity(
16272 Handle<Derived> table, 16272 Handle<Derived> table,
16273 int n, 16273 int n,
16274 Key key, 16274 Key key,
16275 PretenureFlag pretenure) { 16275 PretenureFlag pretenure) {
16276 Isolate* isolate = table->GetIsolate(); 16276 Isolate* isolate = table->GetIsolate();
16277 int capacity = table->Capacity(); 16277 int capacity = table->Capacity();
16278 int nof = table->NumberOfElements() + n; 16278 int nof = table->NumberOfElements() + n;
16279 16279
16280 if (table->HasSufficientCapacity(n)) return table; 16280 if (table->HasSufficientCapacityToAdd(n)) return table;
16281 16281
16282 const int kMinCapacityForPretenure = 256; 16282 const int kMinCapacityForPretenure = 256;
16283 bool should_pretenure = pretenure == TENURED || 16283 bool should_pretenure = pretenure == TENURED ||
16284 ((capacity > kMinCapacityForPretenure) && 16284 ((capacity > kMinCapacityForPretenure) &&
16285 !isolate->heap()->InNewSpace(*table)); 16285 !isolate->heap()->InNewSpace(*table));
16286 Handle<Derived> new_table = HashTable::New( 16286 Handle<Derived> new_table = HashTable::New(
16287 isolate, 16287 isolate,
16288 nof * 2, 16288 nof * 2,
16289 USE_DEFAULT_MINIMUM_CAPACITY, 16289 USE_DEFAULT_MINIMUM_CAPACITY,
16290 should_pretenure ? TENURED : NOT_TENURED); 16290 should_pretenure ? TENURED : NOT_TENURED);
16291 16291
16292 table->Rehash(new_table, key); 16292 table->Rehash(new_table, key);
16293 return new_table; 16293 return new_table;
16294 } 16294 }
16295 16295
16296
16297 template <typename Derived, typename Shape, typename Key> 16296 template <typename Derived, typename Shape, typename Key>
16298 bool HashTable<Derived, Shape, Key>::HasSufficientCapacity(int n) { 16297 bool HashTable<Derived, Shape, Key>::HasSufficientCapacityToAdd(
16298 int number_of_additional_elements) {
16299 int capacity = Capacity(); 16299 int capacity = Capacity();
16300 int nof = NumberOfElements() + n; 16300 int nof = NumberOfElements() + number_of_additional_elements;
16301 int nod = NumberOfDeletedElements(); 16301 int nod = NumberOfDeletedElements();
16302 // Return true if: 16302 // Return true if:
16303 // 50% is still free after adding n elements and 16303 // 50% is still free after adding number_of_additional_elements elements and
16304 // at most 50% of the free elements are deleted elements. 16304 // at most 50% of the free elements are deleted elements.
16305 if (nod <= (capacity - nof) >> 1) { 16305 if ((nof < capacity) && ((nod <= (capacity - nof) >> 1))) {
16306 int needed_free = nof >> 1; 16306 int needed_free = nof >> 1;
16307 if (nof + needed_free <= capacity) return true; 16307 if (nof + needed_free <= capacity) return true;
16308 } 16308 }
16309 return false; 16309 return false;
16310 } 16310 }
16311 16311
16312 16312
16313 template<typename Derived, typename Shape, typename Key> 16313 template<typename Derived, typename Shape, typename Key>
16314 Handle<Derived> HashTable<Derived, Shape, Key>::Shrink(Handle<Derived> table, 16314 Handle<Derived> HashTable<Derived, Shape, Key>::Shrink(Handle<Derived> table,
16315 Key key) { 16315 Key key) {
(...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after
17267 return iteration_order; 17267 return iteration_order;
17268 } 17268 }
17269 17269
17270 17270
17271 template <typename Derived, typename Shape, typename Key> 17271 template <typename Derived, typename Shape, typename Key>
17272 void Dictionary<Derived, Shape, Key>::SetRequiresCopyOnCapacityChange() { 17272 void Dictionary<Derived, Shape, Key>::SetRequiresCopyOnCapacityChange() {
17273 DCHECK_EQ(0, DerivedHashTable::NumberOfElements()); 17273 DCHECK_EQ(0, DerivedHashTable::NumberOfElements());
17274 DCHECK_EQ(0, DerivedHashTable::NumberOfDeletedElements()); 17274 DCHECK_EQ(0, DerivedHashTable::NumberOfDeletedElements());
17275 // Make sure that HashTable::EnsureCapacity will create a copy. 17275 // Make sure that HashTable::EnsureCapacity will create a copy.
17276 DerivedHashTable::SetNumberOfDeletedElements(DerivedHashTable::Capacity()); 17276 DerivedHashTable::SetNumberOfDeletedElements(DerivedHashTable::Capacity());
17277 DCHECK(!DerivedHashTable::HasSufficientCapacity(1)); 17277 DCHECK(!DerivedHashTable::HasSufficientCapacityToAdd(1));
17278 } 17278 }
17279 17279
17280 17280
17281 template <typename Derived, typename Shape, typename Key> 17281 template <typename Derived, typename Shape, typename Key>
17282 Handle<Derived> Dictionary<Derived, Shape, Key>::EnsureCapacity( 17282 Handle<Derived> Dictionary<Derived, Shape, Key>::EnsureCapacity(
17283 Handle<Derived> dictionary, int n, Key key) { 17283 Handle<Derived> dictionary, int n, Key key) {
17284 // Check whether there are enough enumeration indices to add n elements. 17284 // Check whether there are enough enumeration indices to add n elements.
17285 if (Shape::kIsEnumerable && 17285 if (Shape::kIsEnumerable &&
17286 !PropertyDetails::IsValidIndex(dictionary->NextEnumerationIndex() + n)) { 17286 !PropertyDetails::IsValidIndex(dictionary->NextEnumerationIndex() + n)) {
17287 // If not, we generate new indices for the properties. 17287 // If not, we generate new indices for the properties.
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
17687 return table; 17687 return table;
17688 } 17688 }
17689 17689
17690 // Rehash if more than 33% of the entries are deleted entries. 17690 // Rehash if more than 33% of the entries are deleted entries.
17691 // TODO(jochen): Consider to shrink the fixed array in place. 17691 // TODO(jochen): Consider to shrink the fixed array in place.
17692 if ((table->NumberOfDeletedElements() << 1) > table->NumberOfElements()) { 17692 if ((table->NumberOfDeletedElements() << 1) > table->NumberOfElements()) {
17693 table->Rehash(isolate->factory()->undefined_value()); 17693 table->Rehash(isolate->factory()->undefined_value());
17694 } 17694 }
17695 // If we're out of luck, we didn't get a GC recently, and so rehashing 17695 // If we're out of luck, we didn't get a GC recently, and so rehashing
17696 // isn't enough to avoid a crash. 17696 // isn't enough to avoid a crash.
17697 int nof = table->NumberOfElements() + 1; 17697 if (!table->HasSufficientCapacityToAdd(1)) {
17698 if (!table->HasSufficientCapacity(nof)) { 17698 int nof = table->NumberOfElements() + 1;
17699 int capacity = ObjectHashTable::ComputeCapacity(nof * 2); 17699 int capacity = ObjectHashTable::ComputeCapacity(nof * 2);
17700 if (capacity > ObjectHashTable::kMaxCapacity) { 17700 if (capacity > ObjectHashTable::kMaxCapacity) {
17701 for (size_t i = 0; i < 2; ++i) { 17701 for (size_t i = 0; i < 2; ++i) {
17702 isolate->heap()->CollectAllGarbage( 17702 isolate->heap()->CollectAllGarbage(
17703 Heap::kFinalizeIncrementalMarkingMask, "full object hash table"); 17703 Heap::kFinalizeIncrementalMarkingMask, "full object hash table");
17704 } 17704 }
17705 table->Rehash(isolate->factory()->undefined_value()); 17705 table->Rehash(isolate->factory()->undefined_value());
17706 } 17706 }
17707 } 17707 }
17708 17708
(...skipping 1225 matching lines...) Expand 10 before | Expand all | Expand 10 after
18934 18934
18935 Object* data_obj = 18935 Object* data_obj =
18936 constructor->shared()->get_api_func_data()->access_check_info(); 18936 constructor->shared()->get_api_func_data()->access_check_info();
18937 if (data_obj->IsUndefined(isolate)) return nullptr; 18937 if (data_obj->IsUndefined(isolate)) return nullptr;
18938 18938
18939 return AccessCheckInfo::cast(data_obj); 18939 return AccessCheckInfo::cast(data_obj);
18940 } 18940 }
18941 18941
18942 } // namespace internal 18942 } // namespace internal
18943 } // namespace v8 18943 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698