Commit 3ce91203 authored by ishell@chromium.org's avatar ishell@chromium.org

ObjectHashTable's key and WeakHashTable's key types are now Handle<Object> instead of Object*.

R=yangguo@chromium.org

Review URL: https://codereview.chromium.org/257853003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20982 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent a5bde585
......@@ -3670,7 +3670,7 @@ void MarkCompactCollector::EvacuateNewSpaceAndCandidates() {
WeakHashTable* table =
WeakHashTable::cast(heap_->weak_object_to_code_table());
table->Iterate(&updating_visitor);
table->Rehash(heap_->undefined_value());
table->Rehash(heap_->isolate()->factory()->undefined_value());
}
// Update pointers from external string table.
......
......@@ -6683,47 +6683,54 @@ void NameDictionary::DoGenerateNewEnumerationIndices(
}
bool ObjectHashTableShape::IsMatch(Object* key, Object* other) {
bool ObjectHashTableShape::IsMatch(Handle<Object> key, Object* other) {
return key->SameValue(other);
}
uint32_t ObjectHashTableShape::Hash(Object* key) {
uint32_t ObjectHashTableShape::Hash(Handle<Object> key) {
return Smi::cast(key->GetHash())->value();
}
uint32_t ObjectHashTableShape::HashForObject(Object* key, Object* other) {
uint32_t ObjectHashTableShape::HashForObject(Handle<Object> key,
Object* other) {
return Smi::cast(other->GetHash())->value();
}
MaybeObject* ObjectHashTableShape::AsObject(Heap* heap, Object* key) {
MaybeObject* ObjectHashTableShape::AsObject(Heap* heap, Handle<Object> key) {
return *key;
}
Handle<Object> ObjectHashTableShape::AsHandle(Isolate* isolate,
Handle<Object> key) {
return key;
}
Handle<ObjectHashTable> ObjectHashTable::Shrink(
Handle<ObjectHashTable> table, Handle<Object> key) {
return DerivedHashTable::Shrink(table, *key);
return DerivedHashTable::Shrink(table, key);
}
template <int entrysize>
bool WeakHashTableShape<entrysize>::IsMatch(Object* key, Object* other) {
bool WeakHashTableShape<entrysize>::IsMatch(Handle<Object> key, Object* other) {
return key->SameValue(other);
}
template <int entrysize>
uint32_t WeakHashTableShape<entrysize>::Hash(Object* key) {
intptr_t hash = reinterpret_cast<intptr_t>(key);
uint32_t WeakHashTableShape<entrysize>::Hash(Handle<Object> key) {
intptr_t hash = reinterpret_cast<intptr_t>(*key);
return (uint32_t)(hash & 0xFFFFFFFF);
}
template <int entrysize>
uint32_t WeakHashTableShape<entrysize>::HashForObject(Object* key,
uint32_t WeakHashTableShape<entrysize>::HashForObject(Handle<Object> key,
Object* other) {
intptr_t hash = reinterpret_cast<intptr_t>(other);
return (uint32_t)(hash & 0xFFFFFFFF);
......@@ -6731,8 +6738,8 @@ uint32_t WeakHashTableShape<entrysize>::HashForObject(Object* key,
template <int entrysize>
MaybeObject* WeakHashTableShape<entrysize>::AsObject(Heap* heap,
Object* key) {
Handle<Object> WeakHashTableShape<entrysize>::AsHandle(Isolate* isolate,
Handle<Object> key) {
return key;
}
......
......@@ -14855,9 +14855,11 @@ template class HashTable<CompilationCacheTable,
template class HashTable<MapCache, MapCacheShape, HashTableKey*>;
template class HashTable<ObjectHashTable, ObjectHashTableShape, Object*>;
template class HashTable<ObjectHashTable,
ObjectHashTableShape,
Handle<Object> >;
template class HashTable<WeakHashTable, WeakHashTableShape<2>, Object*>;
template class HashTable<WeakHashTable, WeakHashTableShape<2>, Handle<Object> >;
template class Dictionary<NameDictionary, NameDictionaryShape, Handle<Name> >;
......@@ -16137,6 +16139,21 @@ Object* ObjectHashTable::Lookup(Object* key) {
}
// TODO(ishell): Try to remove this when FindEntry(Object* key) is removed
int ObjectHashTable::FindEntry(Handle<Object> key) {
return DerivedHashTable::FindEntry(key);
}
// TODO(ishell): Remove this when all the callers are handlified.
int ObjectHashTable::FindEntry(Object* key) {
DisallowHeapAllocation no_allocation;
Isolate* isolate = GetIsolate();
HandleScope scope(isolate);
return FindEntry(handle(key, isolate));
}
Handle<ObjectHashTable> ObjectHashTable::Put(Handle<ObjectHashTable> table,
Handle<Object> key,
Handle<Object> value) {
......@@ -16147,7 +16164,7 @@ Handle<ObjectHashTable> ObjectHashTable::Put(Handle<ObjectHashTable> table,
// Make sure the key object has an identity hash code.
Handle<Object> hash = Object::GetOrCreateHash(key, isolate);
int entry = table->FindEntry(*key);
int entry = table->FindEntry(key);
// Check whether to perform removal operation.
if (value->IsTheHole()) {
......@@ -16163,7 +16180,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);
......@@ -16193,11 +16210,26 @@ Object* WeakHashTable::Lookup(Object* key) {
}
// TODO(ishell): Try to remove this when FindEntry(Object* key) is removed
int WeakHashTable::FindEntry(Handle<Object> key) {
return DerivedHashTable::FindEntry(key);
}
// TODO(ishell): Remove this when all the callers are handlified.
int WeakHashTable::FindEntry(Object* key) {
DisallowHeapAllocation no_allocation;
Isolate* isolate = GetIsolate();
HandleScope scope(isolate);
return FindEntry(handle(key, isolate));
}
Handle<WeakHashTable> WeakHashTable::Put(Handle<WeakHashTable> table,
Handle<Object> key,
Handle<Object> value) {
ASSERT(table->IsKey(*key));
int entry = table->FindEntry(*key);
int entry = table->FindEntry(key);
// Key is already in table, just overwrite value.
if (entry != kNotFound) {
table->set(EntryToValueIndex(entry), *value);
......@@ -16205,9 +16237,9 @@ Handle<WeakHashTable> WeakHashTable::Put(Handle<WeakHashTable> table,
}
// Check whether the hash table should be extended.
table = EnsureCapacity(table, 1, *key, TENURED);
table = EnsureCapacity(table, 1, key, TENURED);
table->AddEntry(table->FindInsertionEntry(table->Hash(*key)), key, value);
table->AddEntry(table->FindInsertionEntry(table->Hash(key)), key, value);
return table;
}
......
......@@ -3667,8 +3667,7 @@ class HashTable: public FixedArray {
// Wrapper methods
inline uint32_t Hash(Key key) {
if (Shape::UsesSeed) {
return Shape::SeededHash(key,
GetHeap()->HashSeed());
return Shape::SeededHash(key, GetHeap()->HashSeed());
} else {
return Shape::Hash(key);
}
......@@ -3676,8 +3675,7 @@ class HashTable: public FixedArray {
inline uint32_t HashForObject(Key key, Object* object) {
if (Shape::UsesSeed) {
return Shape::SeededHashForObject(key,
GetHeap()->HashSeed(), object);
return Shape::SeededHashForObject(key, GetHeap()->HashSeed(), object);
} else {
return Shape::HashForObject(key, object);
}
......@@ -4237,13 +4235,14 @@ class UnseededNumberDictionary
};
class ObjectHashTableShape : public BaseShape<Object*> {
class ObjectHashTableShape : public BaseShape<Handle<Object> > {
public:
static inline bool IsMatch(Object* key, Object* other);
static inline uint32_t Hash(Object* key);
static inline uint32_t HashForObject(Object* key, Object* object);
static inline bool IsMatch(Handle<Object> key, Object* other);
static inline uint32_t Hash(Handle<Object> key);
static inline uint32_t HashForObject(Handle<Object> key, Object* object);
MUST_USE_RESULT static inline MaybeObject* AsObject(Heap* heap,
Object* key);
Handle<Object> key);
static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Object> key);
static const int kPrefixSize = 0;
static const int kEntrySize = 2;
};
......@@ -4253,9 +4252,9 @@ class ObjectHashTableShape : public BaseShape<Object*> {
// using the identity hash of the key for hashing purposes.
class ObjectHashTable: public HashTable<ObjectHashTable,
ObjectHashTableShape,
Object*> {
Handle<Object> > {
typedef HashTable<
ObjectHashTable, ObjectHashTableShape, Object*> DerivedHashTable;
ObjectHashTable, ObjectHashTableShape, Handle<Object> > DerivedHashTable;
public:
static inline ObjectHashTable* cast(Object* obj) {
ASSERT(obj->IsHashTable());
......@@ -4271,6 +4270,10 @@ class ObjectHashTable: public HashTable<ObjectHashTable,
// returned in case the key is not present.
Object* Lookup(Object* key);
int FindEntry(Handle<Object> key);
// TODO(ishell): Remove this when all the callers are handlified.
int FindEntry(Object* key);
// Adds (or overwrites) the value associated with the given key. Mapping a
// key to the hole value causes removal of the whole entry.
static Handle<ObjectHashTable> Put(Handle<ObjectHashTable> table,
......@@ -4469,13 +4472,12 @@ class OrderedHashMap:public OrderedHashTable<
template <int entrysize>
class WeakHashTableShape : public BaseShape<Object*> {
class WeakHashTableShape : public BaseShape<Handle<Object> > {
public:
static inline bool IsMatch(Object* key, Object* other);
static inline uint32_t Hash(Object* key);
static inline uint32_t HashForObject(Object* key, Object* object);
MUST_USE_RESULT static inline MaybeObject* AsObject(Heap* heap,
Object* key);
static inline bool IsMatch(Handle<Object> key, Object* other);
static inline uint32_t Hash(Handle<Object> key);
static inline uint32_t HashForObject(Handle<Object> key, Object* object);
static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Object> key);
static const int kPrefixSize = 0;
static const int kEntrySize = entrysize;
};
......@@ -4486,7 +4488,9 @@ class WeakHashTableShape : public BaseShape<Object*> {
// embedded in optimized code to dependent code lists.
class WeakHashTable: public HashTable<WeakHashTable,
WeakHashTableShape<2>,
Object*> {
Handle<Object> > {
typedef HashTable<
WeakHashTable, WeakHashTableShape<2>, Handle<Object> > DerivedHashTable;
public:
static inline WeakHashTable* cast(Object* obj) {
ASSERT(obj->IsHashTable());
......@@ -4497,6 +4501,10 @@ class WeakHashTable: public HashTable<WeakHashTable,
// returned in case the key is not present.
Object* Lookup(Object* key);
int FindEntry(Handle<Object> key);
// TODO(ishell): Remove this when all the callers are handlified.
int FindEntry(Object* key);
// Adds (or overwrites) the value associated with the given key. Mapping a
// key to the hole value causes removal of the whole entry.
MUST_USE_RESULT static Handle<WeakHashTable> Put(Handle<WeakHashTable> table,
......
......@@ -140,7 +140,7 @@ TEST(HashTableRehash) {
for (int i = 0; i < capacity - 1; i++) {
t->insert(i, i * i, i);
}
t->Rehash(Smi::FromInt(0));
t->Rehash(handle(Smi::FromInt(0), isolate));
for (int i = 0; i < capacity - 1; i++) {
CHECK_EQ(i, t->lookup(i * i));
}
......@@ -153,7 +153,7 @@ TEST(HashTableRehash) {
for (int i = 0; i < capacity / 2; i++) {
t->insert(i, i * i, i);
}
t->Rehash(Smi::FromInt(0));
t->Rehash(handle(Smi::FromInt(0), isolate));
for (int i = 0; i < capacity / 2; i++) {
CHECK_EQ(i, t->lookup(i * i));
}
......
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