From 9ad30587566c6300a9da44b886a56f7b72d7771a Mon Sep 17 00:00:00 2001 From: "ulan@chromium.org" Date: Mon, 24 Oct 2011 13:11:14 +0000 Subject: [PATCH] Use handle lists instead of raw pointer lists in polymorphic code cache. BUG= TEST= Review URL: http://codereview.chromium.org/8368024 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9756 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/objects.cc | 43 ++++++++++++++++++------------------------- src/objects.h | 11 ++++++----- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/src/objects.cc b/src/objects.cc index f007f38..b307930 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -5146,15 +5146,11 @@ void PolymorphicCodeCache::Update(Handle cache, Code::Flags flags, Handle code) { Isolate* isolate = cache->GetIsolate(); - List raw_maps(maps->length()); - CALL_HEAP_FUNCTION_VOID( - isolate, - (raw_maps.Clear(), - cache->Update(UnwrapHandleList(&raw_maps, maps), flags, *code))); + CALL_HEAP_FUNCTION_VOID(isolate, cache->Update(maps, flags, *code)); } -MaybeObject* PolymorphicCodeCache::Update(MapList* maps, +MaybeObject* PolymorphicCodeCache::Update(MapHandleList* maps, Code::Flags flags, Code* code) { // Initialize cache if necessary. @@ -5184,18 +5180,12 @@ MaybeObject* PolymorphicCodeCache::Update(MapList* maps, Handle PolymorphicCodeCache::Lookup(MapHandleList* maps, Code::Flags flags) { - List raw_maps(maps->length()); - return Handle(Lookup(UnwrapHandleList(&raw_maps, maps), flags)); -} - - -Object* PolymorphicCodeCache::Lookup(MapList* maps, Code::Flags flags) { if (!cache()->IsUndefined()) { PolymorphicCodeCacheHashTable* hash_table = PolymorphicCodeCacheHashTable::cast(cache()); - return hash_table->Lookup(maps, flags); + return Handle(hash_table->Lookup(maps, flags)); } else { - return GetHeap()->undefined_value(); + return GetIsolate()->factory()->undefined_value(); } } @@ -5206,12 +5196,12 @@ Object* PolymorphicCodeCache::Lookup(MapList* maps, Code::Flags flags) { class PolymorphicCodeCacheHashTableKey : public HashTableKey { public: // Callers must ensure that |maps| outlives the newly constructed object. - PolymorphicCodeCacheHashTableKey(MapList* maps, int code_flags) + PolymorphicCodeCacheHashTableKey(MapHandleList* maps, int code_flags) : maps_(maps), code_flags_(code_flags) {} bool IsMatch(Object* other) { - MapList other_maps(kDefaultListAllocationSize); + MapHandleList other_maps(kDefaultListAllocationSize); int other_flags; FromObject(other, &other_flags, &other_maps); if (code_flags_ != other_flags) return false; @@ -5227,7 +5217,7 @@ class PolymorphicCodeCacheHashTableKey : public HashTableKey { for (int i = 0; i < maps_->length(); ++i) { bool match_found = false; for (int j = 0; j < other_maps.length(); ++j) { - if (maps_->at(i)->EquivalentTo(other_maps.at(j))) { + if (maps_->at(i)->EquivalentTo(*other_maps.at(j))) { match_found = true; break; } @@ -5237,7 +5227,7 @@ class PolymorphicCodeCacheHashTableKey : public HashTableKey { return true; } - static uint32_t MapsHashHelper(MapList* maps, int code_flags) { + static uint32_t MapsHashHelper(MapHandleList* maps, int code_flags) { uint32_t hash = code_flags; for (int i = 0; i < maps->length(); ++i) { hash ^= maps->at(i)->Hash(); @@ -5250,7 +5240,7 @@ class PolymorphicCodeCacheHashTableKey : public HashTableKey { } uint32_t HashForObject(Object* obj) { - MapList other_maps(kDefaultListAllocationSize); + MapHandleList other_maps(kDefaultListAllocationSize); int other_flags; FromObject(obj, &other_flags, &other_maps); return MapsHashHelper(&other_maps, other_flags); @@ -5268,29 +5258,32 @@ class PolymorphicCodeCacheHashTableKey : public HashTableKey { FixedArray* list = FixedArray::cast(obj); list->set(0, Smi::FromInt(code_flags_)); for (int i = 0; i < maps_->length(); ++i) { - list->set(i + 1, maps_->at(i)); + list->set(i + 1, *maps_->at(i)); } return list; } private: - static MapList* FromObject(Object* obj, int* code_flags, MapList* maps) { + static MapHandleList* FromObject(Object* obj, + int* code_flags, + MapHandleList* maps) { FixedArray* list = FixedArray::cast(obj); maps->Rewind(0); *code_flags = Smi::cast(list->get(0))->value(); for (int i = 1; i < list->length(); ++i) { - maps->Add(Map::cast(list->get(i))); + maps->Add(Handle(Map::cast(list->get(i)))); } return maps; } - MapList* maps_; // weak. + MapHandleList* maps_; // weak. int code_flags_; static const int kDefaultListAllocationSize = kMaxKeyedPolymorphism + 1; }; -Object* PolymorphicCodeCacheHashTable::Lookup(MapList* maps, int code_flags) { +Object* PolymorphicCodeCacheHashTable::Lookup(MapHandleList* maps, + int code_flags) { PolymorphicCodeCacheHashTableKey key(maps, code_flags); int entry = FindEntry(&key); if (entry == kNotFound) return GetHeap()->undefined_value(); @@ -5298,7 +5291,7 @@ Object* PolymorphicCodeCacheHashTable::Lookup(MapList* maps, int code_flags) { } -MaybeObject* PolymorphicCodeCacheHashTable::Put(MapList* maps, +MaybeObject* PolymorphicCodeCacheHashTable::Put(MapHandleList* maps, int code_flags, Code* code) { PolymorphicCodeCacheHashTableKey key(maps, code_flags); diff --git a/src/objects.h b/src/objects.h index 09ed775..a3c9cc2 100644 --- a/src/objects.h +++ b/src/objects.h @@ -5872,15 +5872,13 @@ class PolymorphicCodeCache: public Struct { Code::Flags flags, Handle code); - MUST_USE_RESULT MaybeObject* Update(MapList* maps, + MUST_USE_RESULT MaybeObject* Update(MapHandleList* maps, Code::Flags flags, Code* code); // Returns an undefined value if the entry is not found. Handle Lookup(MapHandleList* maps, Code::Flags flags); - Object* Lookup(MapList* maps, Code::Flags flags); - static inline PolymorphicCodeCache* cast(Object* obj); #ifdef OBJECT_PRINT @@ -5904,8 +5902,11 @@ class PolymorphicCodeCache: public Struct { class PolymorphicCodeCacheHashTable : public HashTable { public: - Object* Lookup(MapList* maps, int code_kind); - MUST_USE_RESULT MaybeObject* Put(MapList* maps, int code_kind, Code* code); + Object* Lookup(MapHandleList* maps, int code_kind); + + MUST_USE_RESULT MaybeObject* Put(MapHandleList* maps, + int code_kind, + Code* code); static inline PolymorphicCodeCacheHashTable* cast(Object* obj); -- 2.7.4