Commit c3d349f0 authored by ishell@chromium.org's avatar ishell@chromium.org

OrderedHashMap::Lookup() and ObjectHashTable::Lookup() handlified.

R=yangguo@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@21055 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 3a92c26e
......@@ -5187,7 +5187,7 @@ Object* JSObject::GetHiddenProperty(Handle<Name> key) {
if (inline_value->IsUndefined()) return GetHeap()->the_hole_value();
ObjectHashTable* hashtable = ObjectHashTable::cast(inline_value);
Object* entry = hashtable->Lookup(*key);
Object* entry = hashtable->Lookup(key);
return entry;
}
......@@ -16036,8 +16036,9 @@ Object* Dictionary<Derived, Shape, Key>::SlowReverseLookup(Object* value) {
}
Object* ObjectHashTable::Lookup(Object* key) {
ASSERT(IsKey(key));
Object* ObjectHashTable::Lookup(Handle<Object> key) {
DisallowHeapAllocation no_gc;
ASSERT(IsKey(*key));
// If the object does not have an identity hash, it was never used as a key.
Object* hash = key->GetHash();
......@@ -16411,8 +16412,9 @@ Handle<OrderedHashSet> OrderedHashSet::Remove(Handle<OrderedHashSet> table,
}
Object* OrderedHashMap::Lookup(Object* key) {
int entry = FindEntry(key);
Object* OrderedHashMap::Lookup(Handle<Object> key) {
DisallowHeapAllocation no_gc;
int entry = FindEntry(*key);
if (entry == kNotFound) return GetHeap()->the_hole_value();
return ValueAt(entry);
}
......
......@@ -4200,7 +4200,7 @@ class ObjectHashTable: public HashTable<ObjectHashTable,
// Looks up the value associated with the given key. The hole value is
// returned in case the key is not present.
Object* Lookup(Object* key);
Object* Lookup(Handle<Object> key);
int FindEntry(Handle<Object> key);
// TODO(ishell): Remove this when all the callers are handlified.
......@@ -4388,7 +4388,7 @@ class OrderedHashMap:public OrderedHashTable<
return reinterpret_cast<OrderedHashMap*>(obj);
}
Object* Lookup(Object* key);
Object* Lookup(Handle<Object> key);
static Handle<OrderedHashMap> Put(
Handle<OrderedHashMap> table,
Handle<Object> key,
......
......@@ -1612,7 +1612,7 @@ RUNTIME_FUNCTION(Runtime_MapGet) {
CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
Handle<OrderedHashMap> table(OrderedHashMap::cast(holder->table()));
Handle<Object> lookup(table->Lookup(*key), isolate);
Handle<Object> lookup(table->Lookup(key), isolate);
return lookup->IsTheHole() ? isolate->heap()->undefined_value() : *lookup;
}
......@@ -1623,7 +1623,7 @@ RUNTIME_FUNCTION(Runtime_MapHas) {
CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
Handle<OrderedHashMap> table(OrderedHashMap::cast(holder->table()));
Handle<Object> lookup(table->Lookup(*key), isolate);
Handle<Object> lookup(table->Lookup(key), isolate);
return isolate->heap()->ToBoolean(!lookup->IsTheHole());
}
......@@ -1634,7 +1634,7 @@ RUNTIME_FUNCTION(Runtime_MapDelete) {
CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
Handle<OrderedHashMap> table(OrderedHashMap::cast(holder->table()));
Handle<Object> lookup(table->Lookup(*key), isolate);
Handle<Object> lookup(table->Lookup(key), isolate);
Handle<OrderedHashMap> new_table =
OrderedHashMap::Put(table, key, isolate->factory()->the_hole_value());
holder->set_table(*new_table);
......@@ -1731,7 +1731,7 @@ RUNTIME_FUNCTION(Runtime_WeakCollectionGet) {
CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
Handle<ObjectHashTable> table(
ObjectHashTable::cast(weak_collection->table()));
Handle<Object> lookup(table->Lookup(*key), isolate);
Handle<Object> lookup(table->Lookup(key), isolate);
return lookup->IsTheHole() ? isolate->heap()->undefined_value() : *lookup;
}
......@@ -1743,7 +1743,7 @@ RUNTIME_FUNCTION(Runtime_WeakCollectionHas) {
CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
Handle<ObjectHashTable> table(
ObjectHashTable::cast(weak_collection->table()));
Handle<Object> lookup(table->Lookup(*key), isolate);
Handle<Object> lookup(table->Lookup(key), isolate);
return isolate->heap()->ToBoolean(!lookup->IsTheHole());
}
......@@ -1755,7 +1755,7 @@ RUNTIME_FUNCTION(Runtime_WeakCollectionDelete) {
CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
Handle<ObjectHashTable> table(ObjectHashTable::cast(
weak_collection->table()));
Handle<Object> lookup(table->Lookup(*key), isolate);
Handle<Object> lookup(table->Lookup(key), isolate);
Handle<ObjectHashTable> new_table =
ObjectHashTable::Put(table, key, isolate->factory()->the_hole_value());
weak_collection->set_table(*new_table);
......
......@@ -50,24 +50,24 @@ static void TestHashMap(Handle<HashMap> table) {
Handle<JSObject> b = factory->NewJSArray(11);
table = HashMap::Put(table, a, b);
CHECK_EQ(table->NumberOfElements(), 1);
CHECK_EQ(table->Lookup(*a), *b);
CHECK_EQ(table->Lookup(*b), CcTest::heap()->the_hole_value());
CHECK_EQ(table->Lookup(a), *b);
CHECK_EQ(table->Lookup(b), CcTest::heap()->the_hole_value());
// Keys still have to be valid after objects were moved.
CcTest::heap()->CollectGarbage(NEW_SPACE);
CHECK_EQ(table->NumberOfElements(), 1);
CHECK_EQ(table->Lookup(*a), *b);
CHECK_EQ(table->Lookup(*b), CcTest::heap()->the_hole_value());
CHECK_EQ(table->Lookup(a), *b);
CHECK_EQ(table->Lookup(b), CcTest::heap()->the_hole_value());
// Keys that are overwritten should not change number of elements.
table = HashMap::Put(table, a, factory->NewJSArray(13));
CHECK_EQ(table->NumberOfElements(), 1);
CHECK_NE(table->Lookup(*a), *b);
CHECK_NE(table->Lookup(a), *b);
// Keys mapped to the hole should be removed permanently.
table = HashMap::Put(table, a, factory->the_hole_value());
CHECK_EQ(table->NumberOfElements(), 0);
CHECK_EQ(table->Lookup(*a), CcTest::heap()->the_hole_value());
CHECK_EQ(table->Lookup(a), CcTest::heap()->the_hole_value());
// Keys should map back to their respective values and also should get
// an identity hash code generated.
......@@ -77,7 +77,7 @@ static void TestHashMap(Handle<HashMap> table) {
table = HashMap::Put(table, key, value);
CHECK_EQ(table->NumberOfElements(), i + 1);
CHECK_NE(table->FindEntry(*key), HashMap::kNotFound);
CHECK_EQ(table->Lookup(*key), *value);
CHECK_EQ(table->Lookup(key), *value);
CHECK(key->GetIdentityHash()->IsSmi());
}
......@@ -87,7 +87,7 @@ static void TestHashMap(Handle<HashMap> table) {
Handle<JSReceiver> key = factory->NewJSArray(7);
CHECK(JSReceiver::GetOrCreateIdentityHash(key)->IsSmi());
CHECK_EQ(table->FindEntry(*key), HashMap::kNotFound);
CHECK_EQ(table->Lookup(*key), CcTest::heap()->the_hole_value());
CHECK_EQ(table->Lookup(key), CcTest::heap()->the_hole_value());
CHECK(key->GetIdentityHash()->IsSmi());
}
......@@ -95,7 +95,7 @@ static void TestHashMap(Handle<HashMap> table) {
// should not get an identity hash code generated.
for (int i = 0; i < 100; i++) {
Handle<JSReceiver> key = factory->NewJSArray(7);
CHECK_EQ(table->Lookup(*key), CcTest::heap()->the_hole_value());
CHECK_EQ(table->Lookup(key), CcTest::heap()->the_hole_value());
CHECK_EQ(key->GetIdentityHash(),
CcTest::heap()->undefined_value());
}
......@@ -119,7 +119,8 @@ class ObjectHashTableTest: public ObjectHashTable {
}
int lookup(int key) {
return Smi::cast(Lookup(Smi::FromInt(key)))->value();
Handle<Object> key_obj(Smi::FromInt(key), GetIsolate());
return Smi::cast(Lookup(key_obj))->value();
}
int capacity() {
......@@ -225,7 +226,7 @@ static void TestHashMapCausesGC(Handle<HashMap> table) {
SimulateFullSpace(CcTest::heap()->old_pointer_space());
// Calling Lookup() should not cause GC ever.
CHECK(table->Lookup(*key)->IsTheHole());
CHECK(table->Lookup(key)->IsTheHole());
// Calling Put() should request GC by returning a failure.
int gc_count = isolate->heap()->gc_count();
......
......@@ -162,14 +162,14 @@ TEST(Map) {
Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
Handle<JSObject> obj = factory->NewJSObjectFromMap(map);
Handle<JSObject> val = factory->NewJSObjectFromMap(map);
CHECK(ordered_map->Lookup(*obj)->IsTheHole());
CHECK(ordered_map->Lookup(obj)->IsTheHole());
ordered_map = OrderedHashMap::Put(ordered_map, obj, val);
CHECK_EQ(1, ordered_map->NumberOfElements());
CHECK(ordered_map->Lookup(*obj)->SameValue(*val));
CHECK(ordered_map->Lookup(obj)->SameValue(*val));
ordered_map = OrderedHashMap::Put(
ordered_map, obj, factory->the_hole_value());
CHECK_EQ(0, ordered_map->NumberOfElements());
CHECK(ordered_map->Lookup(*obj)->IsTheHole());
CHECK(ordered_map->Lookup(obj)->IsTheHole());
// Test for collisions/chaining
Handle<JSObject> obj1 = factory->NewJSObjectFromMap(map);
......@@ -182,9 +182,9 @@ TEST(Map) {
ordered_map = OrderedHashMap::Put(ordered_map, obj2, val2);
ordered_map = OrderedHashMap::Put(ordered_map, obj3, val3);
CHECK_EQ(3, ordered_map->NumberOfElements());
CHECK(ordered_map->Lookup(*obj1)->SameValue(*val1));
CHECK(ordered_map->Lookup(*obj2)->SameValue(*val2));
CHECK(ordered_map->Lookup(*obj3)->SameValue(*val3));
CHECK(ordered_map->Lookup(obj1)->SameValue(*val1));
CHECK(ordered_map->Lookup(obj2)->SameValue(*val2));
CHECK(ordered_map->Lookup(obj3)->SameValue(*val3));
// Test iteration
CheckIterResultObject(
......@@ -203,11 +203,11 @@ TEST(Map) {
Handle<JSObject> obj4 = factory->NewJSObjectFromMap(map);
Handle<JSObject> val4 = factory->NewJSObjectFromMap(map);
ordered_map = OrderedHashMap::Put(ordered_map, obj4, val4);
CHECK(ordered_map->Lookup(*obj)->SameValue(*val));
CHECK(ordered_map->Lookup(*obj1)->SameValue(*val1));
CHECK(ordered_map->Lookup(*obj2)->SameValue(*val2));
CHECK(ordered_map->Lookup(*obj3)->SameValue(*val3));
CHECK(ordered_map->Lookup(*obj4)->SameValue(*val4));
CHECK(ordered_map->Lookup(obj)->SameValue(*val));
CHECK(ordered_map->Lookup(obj1)->SameValue(*val1));
CHECK(ordered_map->Lookup(obj2)->SameValue(*val2));
CHECK(ordered_map->Lookup(obj3)->SameValue(*val3));
CHECK(ordered_map->Lookup(obj4)->SameValue(*val4));
CHECK_EQ(5, ordered_map->NumberOfElements());
CHECK_EQ(4, ordered_map->NumberOfBuckets());
......
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