OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/allocation-site-scopes.h" | 8 #include "src/allocation-site-scopes.h" |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/arguments.h" | 10 #include "src/arguments.h" |
| 11 #include "src/base/bits.h" |
11 #include "src/bootstrapper.h" | 12 #include "src/bootstrapper.h" |
12 #include "src/code-stubs.h" | 13 #include "src/code-stubs.h" |
13 #include "src/codegen.h" | 14 #include "src/codegen.h" |
14 #include "src/cpu-profiler.h" | 15 #include "src/cpu-profiler.h" |
15 #include "src/date.h" | 16 #include "src/date.h" |
16 #include "src/debug.h" | 17 #include "src/debug.h" |
17 #include "src/deoptimizer.h" | 18 #include "src/deoptimizer.h" |
18 #include "src/elements.h" | 19 #include "src/elements.h" |
19 #include "src/execution.h" | 20 #include "src/execution.h" |
20 #include "src/field-index-inl.h" | 21 #include "src/field-index-inl.h" |
(...skipping 13756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13777 } | 13778 } |
13778 | 13779 |
13779 | 13780 |
13780 template<typename Derived, typename Shape, typename Key> | 13781 template<typename Derived, typename Shape, typename Key> |
13781 Handle<Derived> HashTable<Derived, Shape, Key>::New( | 13782 Handle<Derived> HashTable<Derived, Shape, Key>::New( |
13782 Isolate* isolate, | 13783 Isolate* isolate, |
13783 int at_least_space_for, | 13784 int at_least_space_for, |
13784 MinimumCapacity capacity_option, | 13785 MinimumCapacity capacity_option, |
13785 PretenureFlag pretenure) { | 13786 PretenureFlag pretenure) { |
13786 DCHECK(0 <= at_least_space_for); | 13787 DCHECK(0 <= at_least_space_for); |
13787 DCHECK(!capacity_option || IsPowerOf2(at_least_space_for)); | 13788 DCHECK(!capacity_option || base::bits::IsPowerOfTwo32(at_least_space_for)); |
13788 int capacity = (capacity_option == USE_CUSTOM_MINIMUM_CAPACITY) | 13789 int capacity = (capacity_option == USE_CUSTOM_MINIMUM_CAPACITY) |
13789 ? at_least_space_for | 13790 ? at_least_space_for |
13790 : ComputeCapacity(at_least_space_for); | 13791 : ComputeCapacity(at_least_space_for); |
13791 if (capacity > HashTable::kMaxCapacity) { | 13792 if (capacity > HashTable::kMaxCapacity) { |
13792 v8::internal::Heap::FatalProcessOutOfMemory("invalid table size", true); | 13793 v8::internal::Heap::FatalProcessOutOfMemory("invalid table size", true); |
13793 } | 13794 } |
13794 | 13795 |
13795 Factory* factory = isolate->factory(); | 13796 Factory* factory = isolate->factory(); |
13796 int length = EntryToIndex(capacity); | 13797 int length = EntryToIndex(capacity); |
13797 Handle<FixedArray> array = factory->NewFixedArray(length, pretenure); | 13798 Handle<FixedArray> array = factory->NewFixedArray(length, pretenure); |
(...skipping 1636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15434 | 15435 |
15435 | 15436 |
15436 template<class Derived, class Iterator, int entrysize> | 15437 template<class Derived, class Iterator, int entrysize> |
15437 Handle<Derived> OrderedHashTable<Derived, Iterator, entrysize>::Allocate( | 15438 Handle<Derived> OrderedHashTable<Derived, Iterator, entrysize>::Allocate( |
15438 Isolate* isolate, int capacity, PretenureFlag pretenure) { | 15439 Isolate* isolate, int capacity, PretenureFlag pretenure) { |
15439 // Capacity must be a power of two, since we depend on being able | 15440 // Capacity must be a power of two, since we depend on being able |
15440 // to divide and multiple by 2 (kLoadFactor) to derive capacity | 15441 // to divide and multiple by 2 (kLoadFactor) to derive capacity |
15441 // from number of buckets. If we decide to change kLoadFactor | 15442 // from number of buckets. If we decide to change kLoadFactor |
15442 // to something other than 2, capacity should be stored as another | 15443 // to something other than 2, capacity should be stored as another |
15443 // field of this object. | 15444 // field of this object. |
15444 capacity = RoundUpToPowerOf2(Max(kMinCapacity, capacity)); | 15445 capacity = base::bits::RoundUpToPowerOfTwo32(Max(kMinCapacity, capacity)); |
15445 if (capacity > kMaxCapacity) { | 15446 if (capacity > kMaxCapacity) { |
15446 v8::internal::Heap::FatalProcessOutOfMemory("invalid table size", true); | 15447 v8::internal::Heap::FatalProcessOutOfMemory("invalid table size", true); |
15447 } | 15448 } |
15448 int num_buckets = capacity / kLoadFactor; | 15449 int num_buckets = capacity / kLoadFactor; |
15449 Handle<FixedArray> backing_store = isolate->factory()->NewFixedArray( | 15450 Handle<FixedArray> backing_store = isolate->factory()->NewFixedArray( |
15450 kHashTableStartIndex + num_buckets + (capacity * kEntrySize), pretenure); | 15451 kHashTableStartIndex + num_buckets + (capacity * kEntrySize), pretenure); |
15451 backing_store->set_map_no_write_barrier( | 15452 backing_store->set_map_no_write_barrier( |
15452 isolate->heap()->ordered_hash_table_map()); | 15453 isolate->heap()->ordered_hash_table_map()); |
15453 Handle<Derived> table = Handle<Derived>::cast(backing_store); | 15454 Handle<Derived> table = Handle<Derived>::cast(backing_store); |
15454 for (int i = 0; i < num_buckets; ++i) { | 15455 for (int i = 0; i < num_buckets; ++i) { |
(...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16417 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16418 #define ERROR_MESSAGES_TEXTS(C, T) T, |
16418 static const char* error_messages_[] = { | 16419 static const char* error_messages_[] = { |
16419 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16420 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
16420 }; | 16421 }; |
16421 #undef ERROR_MESSAGES_TEXTS | 16422 #undef ERROR_MESSAGES_TEXTS |
16422 return error_messages_[reason]; | 16423 return error_messages_[reason]; |
16423 } | 16424 } |
16424 | 16425 |
16425 | 16426 |
16426 } } // namespace v8::internal | 16427 } } // namespace v8::internal |
OLD | NEW |