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 @@
#include "arm/regexp-macro-assembler-arm.h"
#endif
namespace v8 {
namespace internal {
......@@ -2984,8 +2985,8 @@ Object* Heap::AllocateFixedArrayWithHoles(int length) {
}
Object* Heap::AllocateHashTable(int length) {
Object* result = Heap::AllocateFixedArray(length);
Object* Heap::AllocateHashTable(int length, PretenureFlag pretenure) {
Object* result = Heap::AllocateFixedArray(length, pretenure);
if (result->IsFailure()) return result;
reinterpret_cast<Array*>(result)->set_map(hash_table_map());
ASSERT(result->IsHashTable());
......
......@@ -465,7 +465,8 @@ class Heap : public AllStatic {
// AllocateHashTable is identical to AllocateFixedArray except
// 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.
static Object* AllocateGlobalContext();
......
......@@ -6904,15 +6904,16 @@ void HashTable<Shape, Key>::IterateElements(ObjectVisitor* v) {
template<typename Shape, typename Key>
Object* HashTable<Shape, Key>::Allocate(int at_least_space_for) {
int capacity = RoundUpToPowerOf2(at_least_space_for);
if (capacity < 4) {
capacity = 4; // Guarantee min capacity.
Object* HashTable<Shape, Key>::Allocate(int at_least_space_for,
PretenureFlag pretenure) {
int capacity = RoundUpToPowerOf2(at_least_space_for * 2);
if (capacity < 32) {
capacity = 32; // Guarantee min capacity.
} else if (capacity > HashTable::kMaxCapacity) {
return Failure::OutOfMemoryException();
}
Object* obj = Heap::AllocateHashTable(EntryToIndex(capacity));
Object* obj = Heap::AllocateHashTable(EntryToIndex(capacity), pretenure);
if (!obj->IsFailure()) {
HashTable::cast(obj)->SetNumberOfElements(0);
HashTable::cast(obj)->SetNumberOfDeletedElements(0);
......@@ -6945,12 +6946,17 @@ Object* HashTable<Shape, Key>::EnsureCapacity(int n, Key key) {
int nof = NumberOfElements() + n;
int nod = NumberOfDeletedElements();
// 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.
if ((nof + (nof >> 2) <= capacity) &&
(nod <= (capacity - nof) >> 1)) return this;
if (nod <= (capacity - nof) >> 1) {
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;
AssertNoAllocation no_gc;
......
......@@ -1936,7 +1936,8 @@ class HashTable: public FixedArray {
}
// 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.
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