OLD | NEW |
---|---|
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 6886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6897 | 6897 |
6898 template<typename Shape, typename Key> | 6898 template<typename Shape, typename Key> |
6899 void HashTable<Shape, Key>::IterateElements(ObjectVisitor* v) { | 6899 void HashTable<Shape, Key>::IterateElements(ObjectVisitor* v) { |
6900 IteratePointers(v, | 6900 IteratePointers(v, |
6901 kElementsStartOffset, | 6901 kElementsStartOffset, |
6902 kHeaderSize + length() * kPointerSize); | 6902 kHeaderSize + length() * kPointerSize); |
6903 } | 6903 } |
6904 | 6904 |
6905 | 6905 |
6906 template<typename Shape, typename Key> | 6906 template<typename Shape, typename Key> |
6907 Object* HashTable<Shape, Key>::Allocate(int at_least_space_for) { | 6907 Object* HashTable<Shape, Key>::Allocate(int at_least_space_for, |
6908 int capacity = RoundUpToPowerOf2(at_least_space_for); | 6908 PretenureFlag pretenure) { |
6909 if (capacity < 4) { | 6909 int capacity = RoundUpToPowerOf2(at_least_space_for * 2); |
6910 capacity = 4; // Guarantee min capacity. | 6910 if (capacity < 32) { |
6911 capacity = 32; // Guarantee min capacity. | |
6911 } else if (capacity > HashTable::kMaxCapacity) { | 6912 } else if (capacity > HashTable::kMaxCapacity) { |
6912 return Failure::OutOfMemoryException(); | 6913 return Failure::OutOfMemoryException(); |
6913 } | 6914 } |
6914 | 6915 |
6915 Object* obj = Heap::AllocateHashTable(EntryToIndex(capacity)); | 6916 Object* obj = Heap::AllocateHashTable(EntryToIndex(capacity), pretenure); |
6916 if (!obj->IsFailure()) { | 6917 if (!obj->IsFailure()) { |
6917 HashTable::cast(obj)->SetNumberOfElements(0); | 6918 HashTable::cast(obj)->SetNumberOfElements(0); |
6918 HashTable::cast(obj)->SetNumberOfDeletedElements(0); | 6919 HashTable::cast(obj)->SetNumberOfDeletedElements(0); |
6919 HashTable::cast(obj)->SetCapacity(capacity); | 6920 HashTable::cast(obj)->SetCapacity(capacity); |
6920 } | 6921 } |
6921 return obj; | 6922 return obj; |
6922 } | 6923 } |
6923 | 6924 |
6924 | 6925 |
6925 // Find entry for key otherwise return kNotFound. | 6926 // Find entry for key otherwise return kNotFound. |
(...skipping 12 matching lines...) Expand all Loading... | |
6938 return kNotFound; | 6939 return kNotFound; |
6939 } | 6940 } |
6940 | 6941 |
6941 | 6942 |
6942 template<typename Shape, typename Key> | 6943 template<typename Shape, typename Key> |
6943 Object* HashTable<Shape, Key>::EnsureCapacity(int n, Key key) { | 6944 Object* HashTable<Shape, Key>::EnsureCapacity(int n, Key key) { |
6944 int capacity = Capacity(); | 6945 int capacity = Capacity(); |
6945 int nof = NumberOfElements() + n; | 6946 int nof = NumberOfElements() + n; |
6946 int nod = NumberOfDeletedElements(); | 6947 int nod = NumberOfDeletedElements(); |
6947 // Return if: | 6948 // Return if: |
6948 // 25% is still free after adding n elements and | 6949 // 25% is still free after adding n elements and |
Kasper Lund
2010/03/03 16:01:06
Update comment to reflect 50%.
bak
2010/03/03 16:18:26
Done.
| |
6949 // at most 50% of the free elements are deleted elements. | 6950 // at most 50% of the free elements are deleted elements. |
6950 if ((nof + (nof >> 2) <= capacity) && | 6951 if (nod <= (capacity - nof) >> 1) { |
6951 (nod <= (capacity - nof) >> 1)) return this; | 6952 int needed_free = nof >> 1; |
6953 if (nof + needed_free <= capacity) return this; | |
6954 } | |
6952 | 6955 |
6953 Object* obj = Allocate(nof * 2); | 6956 const int kMinCapacityForPreTenure = 256; |
Kasper Lund
2010/03/03 16:01:06
PreTenure -> Pretenure (to match the rest of the c
bak
2010/03/03 16:18:26
I changed the uppercase issue.
| |
6957 bool pretenure = | |
6958 (capacity > kMinCapacityForPreTenure) && !Heap::InNewSpace(this); | |
6959 Object* obj = Allocate(nof * 2, pretenure ? TENURED : NOT_TENURED); | |
6954 if (obj->IsFailure()) return obj; | 6960 if (obj->IsFailure()) return obj; |
6955 | 6961 |
6956 AssertNoAllocation no_gc; | 6962 AssertNoAllocation no_gc; |
6957 HashTable* table = HashTable::cast(obj); | 6963 HashTable* table = HashTable::cast(obj); |
6958 WriteBarrierMode mode = table->GetWriteBarrierMode(no_gc); | 6964 WriteBarrierMode mode = table->GetWriteBarrierMode(no_gc); |
6959 | 6965 |
6960 // Copy prefix to new array. | 6966 // Copy prefix to new array. |
6961 for (int i = kPrefixStartIndex; | 6967 for (int i = kPrefixStartIndex; |
6962 i < kPrefixStartIndex + Shape::kPrefixSize; | 6968 i < kPrefixStartIndex + Shape::kPrefixSize; |
6963 i++) { | 6969 i++) { |
(...skipping 1398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8362 if (break_point_objects()->IsUndefined()) return 0; | 8368 if (break_point_objects()->IsUndefined()) return 0; |
8363 // Single beak point. | 8369 // Single beak point. |
8364 if (!break_point_objects()->IsFixedArray()) return 1; | 8370 if (!break_point_objects()->IsFixedArray()) return 1; |
8365 // Multiple break points. | 8371 // Multiple break points. |
8366 return FixedArray::cast(break_point_objects())->length(); | 8372 return FixedArray::cast(break_point_objects())->length(); |
8367 } | 8373 } |
8368 #endif | 8374 #endif |
8369 | 8375 |
8370 | 8376 |
8371 } } // namespace v8::internal | 8377 } } // namespace v8::internal |
OLD | NEW |