Commit 1334adbd authored by bak@chromium.org's avatar bak@chromium.org

- Changed the initial size for HashTable.

- Pretenured large expanding hash tables.

Review URL: http://codereview.chromium.org/661468

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4010 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent d49a5db0
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
#include "arm/regexp-macro-assembler-arm.h" #include "arm/regexp-macro-assembler-arm.h"
#endif #endif
namespace v8 { namespace v8 {
namespace internal { namespace internal {
...@@ -2984,8 +2985,8 @@ Object* Heap::AllocateFixedArrayWithHoles(int length) { ...@@ -2984,8 +2985,8 @@ Object* Heap::AllocateFixedArrayWithHoles(int length) {
} }
Object* Heap::AllocateHashTable(int length) { Object* Heap::AllocateHashTable(int length, PretenureFlag pretenure) {
Object* result = Heap::AllocateFixedArray(length); Object* result = Heap::AllocateFixedArray(length, pretenure);
if (result->IsFailure()) return result; if (result->IsFailure()) return result;
reinterpret_cast<Array*>(result)->set_map(hash_table_map()); reinterpret_cast<Array*>(result)->set_map(hash_table_map());
ASSERT(result->IsHashTable()); ASSERT(result->IsHashTable());
......
...@@ -465,7 +465,8 @@ class Heap : public AllStatic { ...@@ -465,7 +465,8 @@ class Heap : public AllStatic {
// AllocateHashTable is identical to AllocateFixedArray except // AllocateHashTable is identical to AllocateFixedArray except
// that the resulting object has hash_table_map as map. // that the resulting object has hash_table_map as map.
static Object* AllocateHashTable(int length); static Object* AllocateHashTable(int length,
PretenureFlag pretenure = NOT_TENURED);
// Allocate a global (but otherwise uninitialized) context. // Allocate a global (but otherwise uninitialized) context.
static Object* AllocateGlobalContext(); static Object* AllocateGlobalContext();
......
...@@ -6904,15 +6904,16 @@ void HashTable<Shape, Key>::IterateElements(ObjectVisitor* v) { ...@@ -6904,15 +6904,16 @@ void HashTable<Shape, Key>::IterateElements(ObjectVisitor* v) {
template<typename Shape, typename Key> template<typename Shape, typename Key>
Object* HashTable<Shape, Key>::Allocate(int at_least_space_for) { Object* HashTable<Shape, Key>::Allocate(int at_least_space_for,
int capacity = RoundUpToPowerOf2(at_least_space_for); PretenureFlag pretenure) {
if (capacity < 4) { int capacity = RoundUpToPowerOf2(at_least_space_for * 2);
capacity = 4; // Guarantee min capacity. if (capacity < 32) {
capacity = 32; // Guarantee min capacity.
} else if (capacity > HashTable::kMaxCapacity) { } else if (capacity > HashTable::kMaxCapacity) {
return Failure::OutOfMemoryException(); return Failure::OutOfMemoryException();
} }
Object* obj = Heap::AllocateHashTable(EntryToIndex(capacity)); Object* obj = Heap::AllocateHashTable(EntryToIndex(capacity), pretenure);
if (!obj->IsFailure()) { if (!obj->IsFailure()) {
HashTable::cast(obj)->SetNumberOfElements(0); HashTable::cast(obj)->SetNumberOfElements(0);
HashTable::cast(obj)->SetNumberOfDeletedElements(0); HashTable::cast(obj)->SetNumberOfDeletedElements(0);
...@@ -6945,12 +6946,17 @@ Object* HashTable<Shape, Key>::EnsureCapacity(int n, Key key) { ...@@ -6945,12 +6946,17 @@ Object* HashTable<Shape, Key>::EnsureCapacity(int n, Key key) {
int nof = NumberOfElements() + n; int nof = NumberOfElements() + n;
int nod = NumberOfDeletedElements(); int nod = NumberOfDeletedElements();
// Return if: // Return if:
// 25% is still free after adding n elements and // 50% is still free after adding n elements and
// at most 50% of the free elements are deleted elements. // at most 50% of the free elements are deleted elements.
if ((nof + (nof >> 2) <= capacity) && if (nod <= (capacity - nof) >> 1) {
(nod <= (capacity - nof) >> 1)) return this; int needed_free = nof >> 1;
if (nof + needed_free <= capacity) return this;
}
Object* obj = Allocate(nof * 2); const int kMinCapacityForPretenure = 256;
bool pretenure =
(capacity > kMinCapacityForPretenure) && !Heap::InNewSpace(this);
Object* obj = Allocate(nof * 2, pretenure ? TENURED : NOT_TENURED);
if (obj->IsFailure()) return obj; if (obj->IsFailure()) return obj;
AssertNoAllocation no_gc; AssertNoAllocation no_gc;
......
...@@ -1936,7 +1936,8 @@ class HashTable: public FixedArray { ...@@ -1936,7 +1936,8 @@ class HashTable: public FixedArray {
} }
// Returns a new HashTable object. Might return Failure. // Returns a new HashTable object. Might return Failure.
static Object* Allocate(int at_least_space_for); static Object* Allocate(int at_least_space_for,
PretenureFlag pretenure = NOT_TENURED);
// Returns the key at entry. // Returns the key at entry.
Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } Object* KeyAt(int entry) { return get(EntryToIndex(entry)); }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment