Handlify HashTable and Dictionary growing.
R=ishell@chromium.org Review URL: https://codereview.chromium.org/240023004 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20820 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
28912cae37
commit
2828508358
@ -2232,24 +2232,13 @@ Handle<MapCache> Factory::NewMapCache(int at_least_space_for) {
|
||||
}
|
||||
|
||||
|
||||
MUST_USE_RESULT static MaybeObject* UpdateMapCacheWith(Context* context,
|
||||
FixedArray* keys,
|
||||
Map* map) {
|
||||
Object* result;
|
||||
{ MaybeObject* maybe_result =
|
||||
MapCache::cast(context->map_cache())->Put(keys, map);
|
||||
if (!maybe_result->ToObject(&result)) return maybe_result;
|
||||
}
|
||||
context->set_map_cache(MapCache::cast(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Handle<MapCache> Factory::AddToMapCache(Handle<Context> context,
|
||||
Handle<FixedArray> keys,
|
||||
Handle<Map> map) {
|
||||
CALL_HEAP_FUNCTION(isolate(),
|
||||
UpdateMapCacheWith(*context, *keys, *map), MapCache);
|
||||
Handle<MapCache> map_cache = handle(MapCache::cast(context->map_cache()));
|
||||
Handle<MapCache> result = MapCache::Put(map_cache, keys, map);
|
||||
context->set_map_cache(*result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
153
src/objects.cc
153
src/objects.cc
@ -7930,10 +7930,10 @@ void CodeCache::RemoveByIndex(Object* name, Code* code, int index) {
|
||||
// lookup not to create a new entry.
|
||||
class CodeCacheHashTableKey : public HashTableKey {
|
||||
public:
|
||||
CodeCacheHashTableKey(Name* name, Code::Flags flags)
|
||||
: name_(name), flags_(flags), code_(NULL) { }
|
||||
CodeCacheHashTableKey(Handle<Name> name, Code::Flags flags)
|
||||
: name_(name), flags_(flags), code_() { }
|
||||
|
||||
CodeCacheHashTableKey(Name* name, Code* code)
|
||||
CodeCacheHashTableKey(Handle<Name> name, Handle<Code> code)
|
||||
: name_(name), flags_(code->flags()), code_(code) { }
|
||||
|
||||
|
||||
@ -7952,7 +7952,7 @@ class CodeCacheHashTableKey : public HashTableKey {
|
||||
return name->Hash() ^ flags;
|
||||
}
|
||||
|
||||
uint32_t Hash() { return NameFlagsHashHelper(name_, flags_); }
|
||||
uint32_t Hash() { return NameFlagsHashHelper(*name_, flags_); }
|
||||
|
||||
uint32_t HashForObject(Object* obj) {
|
||||
FixedArray* pair = FixedArray::cast(obj);
|
||||
@ -7962,67 +7962,60 @@ class CodeCacheHashTableKey : public HashTableKey {
|
||||
}
|
||||
|
||||
MUST_USE_RESULT MaybeObject* AsObject(Heap* heap) {
|
||||
ASSERT(code_ != NULL);
|
||||
Handle<Code> code = code_.ToHandleChecked();
|
||||
Object* obj;
|
||||
{ MaybeObject* maybe_obj = heap->AllocateFixedArray(2);
|
||||
if (!maybe_obj->ToObject(&obj)) return maybe_obj;
|
||||
}
|
||||
FixedArray* pair = FixedArray::cast(obj);
|
||||
pair->set(0, name_);
|
||||
pair->set(1, code_);
|
||||
pair->set(0, *name_);
|
||||
pair->set(1, *code);
|
||||
return pair;
|
||||
}
|
||||
|
||||
Handle<FixedArray> AsHandle() {
|
||||
Isolate* isolate = name_->GetIsolate();
|
||||
CALL_HEAP_FUNCTION(isolate,
|
||||
AsObject(isolate->heap()),
|
||||
FixedArray);
|
||||
}
|
||||
|
||||
private:
|
||||
Name* name_;
|
||||
Handle<Name> name_;
|
||||
Code::Flags flags_;
|
||||
// TODO(jkummerow): We should be able to get by without this.
|
||||
Code* code_;
|
||||
MaybeHandle<Code> code_;
|
||||
};
|
||||
|
||||
|
||||
Object* CodeCacheHashTable::Lookup(Name* name, Code::Flags flags) {
|
||||
CodeCacheHashTableKey key(name, flags);
|
||||
DisallowHeapAllocation no_alloc;
|
||||
CodeCacheHashTableKey key(handle(name), flags);
|
||||
int entry = FindEntry(&key);
|
||||
if (entry == kNotFound) return GetHeap()->undefined_value();
|
||||
return get(EntryToIndex(entry) + 1);
|
||||
}
|
||||
|
||||
|
||||
MaybeObject* CodeCacheHashTable::Put(Name* name, Code* code) {
|
||||
CodeCacheHashTableKey key(name, code);
|
||||
Object* obj;
|
||||
{ MaybeObject* maybe_obj = EnsureCapacity(1, &key);
|
||||
if (!maybe_obj->ToObject(&obj)) return maybe_obj;
|
||||
}
|
||||
|
||||
// Don't use |this|, as the table might have grown.
|
||||
CodeCacheHashTable* cache = reinterpret_cast<CodeCacheHashTable*>(obj);
|
||||
|
||||
int entry = cache->FindInsertionEntry(key.Hash());
|
||||
Object* k;
|
||||
{ MaybeObject* maybe_k = key.AsObject(GetHeap());
|
||||
if (!maybe_k->ToObject(&k)) return maybe_k;
|
||||
}
|
||||
|
||||
cache->set(EntryToIndex(entry), k);
|
||||
cache->set(EntryToIndex(entry) + 1, code);
|
||||
cache->ElementAdded();
|
||||
return cache;
|
||||
}
|
||||
|
||||
|
||||
Handle<CodeCacheHashTable> CodeCacheHashTable::Put(
|
||||
Handle<CodeCacheHashTable> cache, Handle<Name> name, Handle<Code> code) {
|
||||
Isolate* isolate = cache->GetIsolate();
|
||||
CALL_HEAP_FUNCTION(isolate,
|
||||
cache->Put(*name, *code),
|
||||
CodeCacheHashTable);
|
||||
CodeCacheHashTableKey key(name, code);
|
||||
|
||||
Handle<CodeCacheHashTable> new_cache = EnsureCapacity(cache, 1, &key);
|
||||
|
||||
int entry = new_cache->FindInsertionEntry(key.Hash());
|
||||
Handle<Object> k = key.AsHandle();
|
||||
|
||||
new_cache->set(EntryToIndex(entry), *k);
|
||||
new_cache->set(EntryToIndex(entry) + 1, *code);
|
||||
new_cache->ElementAdded();
|
||||
return new_cache;
|
||||
}
|
||||
|
||||
|
||||
int CodeCacheHashTable::GetIndex(Name* name, Code::Flags flags) {
|
||||
CodeCacheHashTableKey key(name, flags);
|
||||
DisallowHeapAllocation no_alloc;
|
||||
CodeCacheHashTableKey key(handle(name), flags);
|
||||
int entry = FindEntry(&key);
|
||||
return (entry == kNotFound) ? -1 : entry;
|
||||
}
|
||||
@ -14787,6 +14780,19 @@ MaybeObject* HashTable<Derived, Shape, Key>::EnsureCapacity(
|
||||
}
|
||||
|
||||
|
||||
template<typename Derived, typename Shape, typename Key>
|
||||
Handle<Derived> HashTable<Derived, Shape, Key>::EnsureCapacity(
|
||||
Handle<Derived> table,
|
||||
int n,
|
||||
Key key,
|
||||
PretenureFlag pretenure) {
|
||||
Isolate* isolate = table->GetIsolate();
|
||||
CALL_HEAP_FUNCTION(isolate,
|
||||
table->EnsureCapacity(n, key, pretenure),
|
||||
Derived);
|
||||
}
|
||||
|
||||
|
||||
template<typename Derived, typename Shape, typename Key>
|
||||
Handle<Derived> HashTable<Derived, Shape, Key>::Shrink(Handle<Derived> table,
|
||||
Key key) {
|
||||
@ -15647,7 +15653,7 @@ Handle<CompilationCacheTable> CompilationCacheTable::Put(
|
||||
Handle<SharedFunctionInfo> shared(context->closure()->shared());
|
||||
StringSharedKey key(src, shared, FLAG_use_strict ? STRICT : SLOPPY,
|
||||
RelocInfo::kNoPosition);
|
||||
cache = EnsureCapacityFor(cache, 1, &key);
|
||||
cache = EnsureCapacity(cache, 1, &key);
|
||||
Handle<Object> k = key.AsObject(isolate->factory());
|
||||
int entry = cache->FindInsertionEntry(key.Hash());
|
||||
cache->set(EntryToIndex(entry), *k);
|
||||
@ -15664,7 +15670,7 @@ Handle<CompilationCacheTable> CompilationCacheTable::PutEval(
|
||||
Isolate* isolate = cache->GetIsolate();
|
||||
Handle<SharedFunctionInfo> shared(context->closure()->shared());
|
||||
StringSharedKey key(src, shared, value->strict_mode(), scope_position);
|
||||
cache = EnsureCapacityFor(cache, 1, &key);
|
||||
cache = EnsureCapacity(cache, 1, &key);
|
||||
Handle<Object> k = key.AsObject(isolate->factory());
|
||||
int entry = cache->FindInsertionEntry(key.Hash());
|
||||
cache->set(EntryToIndex(entry), *k);
|
||||
@ -15678,7 +15684,7 @@ Handle<CompilationCacheTable> CompilationCacheTable::PutRegExp(
|
||||
Handle<CompilationCacheTable> cache, Handle<String> src,
|
||||
JSRegExp::Flags flags, Handle<FixedArray> value) {
|
||||
RegExpKey key(src, flags);
|
||||
cache = EnsureCapacityFor(cache, 1, &key);
|
||||
cache = EnsureCapacity(cache, 1, &key);
|
||||
int entry = cache->FindInsertionEntry(key.Hash());
|
||||
// We store the value in the key slot, and compare the search key
|
||||
// to the stored value with a custon IsMatch function during lookups.
|
||||
@ -15689,14 +15695,6 @@ Handle<CompilationCacheTable> CompilationCacheTable::PutRegExp(
|
||||
}
|
||||
|
||||
|
||||
Handle<CompilationCacheTable> CompilationCacheTable::EnsureCapacityFor(
|
||||
Handle<CompilationCacheTable> cache, int n, HashTableKey* key) {
|
||||
CALL_HEAP_FUNCTION(cache->GetIsolate(),
|
||||
cache->EnsureCapacity(n, key),
|
||||
CompilationCacheTable);
|
||||
}
|
||||
|
||||
|
||||
void CompilationCacheTable::Remove(Object* value) {
|
||||
DisallowHeapAllocation no_allocation;
|
||||
Object* the_hole_value = GetHeap()->the_hole_value();
|
||||
@ -15716,7 +15714,7 @@ void CompilationCacheTable::Remove(Object* value) {
|
||||
// StringsKey used for HashTable where key is array of internalized strings.
|
||||
class StringsKey : public HashTableKey {
|
||||
public:
|
||||
explicit StringsKey(FixedArray* strings) : strings_(strings) { }
|
||||
explicit StringsKey(Handle<FixedArray> strings) : strings_(strings) { }
|
||||
|
||||
bool IsMatch(Object* strings) {
|
||||
FixedArray* o = FixedArray::cast(strings);
|
||||
@ -15728,7 +15726,7 @@ class StringsKey : public HashTableKey {
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t Hash() { return HashForObject(strings_); }
|
||||
uint32_t Hash() { return HashForObject(*strings_); }
|
||||
|
||||
uint32_t HashForObject(Object* obj) {
|
||||
FixedArray* strings = FixedArray::cast(obj);
|
||||
@ -15740,34 +15738,32 @@ class StringsKey : public HashTableKey {
|
||||
return hash;
|
||||
}
|
||||
|
||||
Object* AsObject(Heap* heap) { return strings_; }
|
||||
Object* AsObject(Heap* heap) { return *strings_; }
|
||||
|
||||
private:
|
||||
FixedArray* strings_;
|
||||
Handle<FixedArray> strings_;
|
||||
};
|
||||
|
||||
|
||||
Object* MapCache::Lookup(FixedArray* array) {
|
||||
StringsKey key(array);
|
||||
DisallowHeapAllocation no_alloc;
|
||||
StringsKey key(handle(array));
|
||||
int entry = FindEntry(&key);
|
||||
if (entry == kNotFound) return GetHeap()->undefined_value();
|
||||
return get(EntryToIndex(entry) + 1);
|
||||
}
|
||||
|
||||
|
||||
MaybeObject* MapCache::Put(FixedArray* array, Map* value) {
|
||||
Handle<MapCache> MapCache::Put(
|
||||
Handle<MapCache> map_cache, Handle<FixedArray> array, Handle<Map> value) {
|
||||
StringsKey key(array);
|
||||
Object* obj;
|
||||
{ MaybeObject* maybe_obj = EnsureCapacity(1, &key);
|
||||
if (!maybe_obj->ToObject(&obj)) return maybe_obj;
|
||||
}
|
||||
|
||||
MapCache* cache = reinterpret_cast<MapCache*>(obj);
|
||||
int entry = cache->FindInsertionEntry(key.Hash());
|
||||
cache->set(EntryToIndex(entry), array);
|
||||
cache->set(EntryToIndex(entry) + 1, value);
|
||||
cache->ElementAdded();
|
||||
return cache;
|
||||
Handle<MapCache> new_cache = EnsureCapacity(map_cache, 1, &key);
|
||||
int entry = new_cache->FindInsertionEntry(key.Hash());
|
||||
new_cache->set(EntryToIndex(entry), *array);
|
||||
new_cache->set(EntryToIndex(entry) + 1, *value);
|
||||
new_cache->ElementAdded();
|
||||
return new_cache;
|
||||
}
|
||||
|
||||
|
||||
@ -15889,6 +15885,17 @@ MaybeObject* Dictionary<Derived, Shape, Key>::EnsureCapacity(int n, Key key) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename Derived, typename Shape, typename Key>
|
||||
Handle<Derived> Dictionary<Derived, Shape, Key>::EnsureCapacity(
|
||||
Handle<Derived> obj, int n, Key key) {
|
||||
Isolate* isolate = obj->GetIsolate();
|
||||
CALL_HEAP_FUNCTION(isolate,
|
||||
obj->EnsureCapacity(n, key),
|
||||
Derived);
|
||||
}
|
||||
|
||||
|
||||
// TODO(ishell): Temporary wrapper until handlified.
|
||||
template<typename Derived, typename Shape, typename Key>
|
||||
Handle<Object> Dictionary<Derived, Shape, Key>::DeleteProperty(
|
||||
@ -16230,20 +16237,6 @@ Object* Dictionary<Derived, Shape, Key>::SlowReverseLookup(Object* value) {
|
||||
}
|
||||
|
||||
|
||||
Handle<ObjectHashTable> ObjectHashTable::EnsureCapacity(
|
||||
Handle<ObjectHashTable> table,
|
||||
int n,
|
||||
Handle<Object> key,
|
||||
PretenureFlag pretenure) {
|
||||
Handle<HashTable<ObjectHashTable,
|
||||
ObjectHashTableShape,
|
||||
Object*> > table_base = table;
|
||||
CALL_HEAP_FUNCTION(table_base->GetIsolate(),
|
||||
table_base->EnsureCapacity(n, *key, pretenure),
|
||||
ObjectHashTable);
|
||||
}
|
||||
|
||||
|
||||
Object* ObjectHashTable::Lookup(Object* key) {
|
||||
ASSERT(IsKey(key));
|
||||
|
||||
@ -16284,7 +16277,7 @@ Handle<ObjectHashTable> ObjectHashTable::Put(Handle<ObjectHashTable> table,
|
||||
}
|
||||
|
||||
// Check whether the hash table should be extended.
|
||||
table = EnsureCapacity(table, 1, key);
|
||||
table = EnsureCapacity(table, 1, *key);
|
||||
table->AddEntry(table->FindInsertionEntry(Handle<Smi>::cast(hash)->value()),
|
||||
*key,
|
||||
*value);
|
||||
|
@ -3858,6 +3858,11 @@ class HashTable: public FixedArray {
|
||||
int n,
|
||||
Key key,
|
||||
PretenureFlag pretenure = NOT_TENURED);
|
||||
static Handle<Derived> EnsureCapacity(
|
||||
Handle<Derived> table,
|
||||
int n,
|
||||
Key key,
|
||||
PretenureFlag pretenure = NOT_TENURED);
|
||||
};
|
||||
|
||||
|
||||
@ -3964,7 +3969,8 @@ class MapCache: public HashTable<MapCache, MapCacheShape, HashTableKey*> {
|
||||
public:
|
||||
// Find cached value for a name key, otherwise return null.
|
||||
Object* Lookup(FixedArray* key);
|
||||
MUST_USE_RESULT MaybeObject* Put(FixedArray* key, Map* value);
|
||||
static Handle<MapCache> Put(
|
||||
Handle<MapCache> map_cache, Handle<FixedArray> key, Handle<Map> value);
|
||||
static inline MapCache* cast(Object* obj);
|
||||
|
||||
private:
|
||||
@ -4063,6 +4069,8 @@ class Dictionary: public HashTable<Derived, Shape, Key> {
|
||||
// Ensure enough space for n additional elements.
|
||||
MUST_USE_RESULT MaybeObject* EnsureCapacity(int n, Key key);
|
||||
|
||||
static Handle<Derived> EnsureCapacity(Handle<Derived> obj, int n, Key key);
|
||||
|
||||
#ifdef OBJECT_PRINT
|
||||
void Print(FILE* out = stdout);
|
||||
#endif
|
||||
@ -4273,12 +4281,6 @@ class ObjectHashTable: public HashTable<ObjectHashTable,
|
||||
return reinterpret_cast<ObjectHashTable*>(obj);
|
||||
}
|
||||
|
||||
static Handle<ObjectHashTable> EnsureCapacity(
|
||||
Handle<ObjectHashTable> table,
|
||||
int n,
|
||||
Handle<Object> key,
|
||||
PretenureFlag pretenure = NOT_TENURED);
|
||||
|
||||
// Attempt to shrink hash table after removal of key.
|
||||
static inline Handle<ObjectHashTable> Shrink(Handle<ObjectHashTable> table,
|
||||
Handle<Object> key);
|
||||
@ -8285,8 +8287,6 @@ class CompilationCacheTable: public HashTable<CompilationCacheTable,
|
||||
static Handle<CompilationCacheTable> PutRegExp(
|
||||
Handle<CompilationCacheTable> cache, Handle<String> src,
|
||||
JSRegExp::Flags flags, Handle<FixedArray> value);
|
||||
static Handle<CompilationCacheTable> EnsureCapacityFor(
|
||||
Handle<CompilationCacheTable> cache, int n, HashTableKey* key);
|
||||
void Remove(Object* value);
|
||||
|
||||
static inline CompilationCacheTable* cast(Object* obj);
|
||||
@ -8390,8 +8390,6 @@ class CodeCacheHashTable: public HashTable<CodeCacheHashTable,
|
||||
static const int kInitialSize = 64;
|
||||
|
||||
private:
|
||||
MUST_USE_RESULT MaybeObject* Put(Name* name, Code* code);
|
||||
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCacheHashTable);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user