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
This commit is contained in:
ulan@chromium.org 2011-10-24 13:11:14 +00:00
parent 3eb3f8cb65
commit 9ad3058756
2 changed files with 24 additions and 30 deletions

View File

@ -5146,15 +5146,11 @@ void PolymorphicCodeCache::Update(Handle<PolymorphicCodeCache> cache,
Code::Flags flags, Code::Flags flags,
Handle<Code> code) { Handle<Code> code) {
Isolate* isolate = cache->GetIsolate(); Isolate* isolate = cache->GetIsolate();
List<Map*> raw_maps(maps->length()); CALL_HEAP_FUNCTION_VOID(isolate, cache->Update(maps, flags, *code));
CALL_HEAP_FUNCTION_VOID(
isolate,
(raw_maps.Clear(),
cache->Update(UnwrapHandleList(&raw_maps, maps), flags, *code)));
} }
MaybeObject* PolymorphicCodeCache::Update(MapList* maps, MaybeObject* PolymorphicCodeCache::Update(MapHandleList* maps,
Code::Flags flags, Code::Flags flags,
Code* code) { Code* code) {
// Initialize cache if necessary. // Initialize cache if necessary.
@ -5184,18 +5180,12 @@ MaybeObject* PolymorphicCodeCache::Update(MapList* maps,
Handle<Object> PolymorphicCodeCache::Lookup(MapHandleList* maps, Handle<Object> PolymorphicCodeCache::Lookup(MapHandleList* maps,
Code::Flags flags) { Code::Flags flags) {
List<Map*> raw_maps(maps->length());
return Handle<Object>(Lookup(UnwrapHandleList(&raw_maps, maps), flags));
}
Object* PolymorphicCodeCache::Lookup(MapList* maps, Code::Flags flags) {
if (!cache()->IsUndefined()) { if (!cache()->IsUndefined()) {
PolymorphicCodeCacheHashTable* hash_table = PolymorphicCodeCacheHashTable* hash_table =
PolymorphicCodeCacheHashTable::cast(cache()); PolymorphicCodeCacheHashTable::cast(cache());
return hash_table->Lookup(maps, flags); return Handle<Object>(hash_table->Lookup(maps, flags));
} else { } 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 { class PolymorphicCodeCacheHashTableKey : public HashTableKey {
public: public:
// Callers must ensure that |maps| outlives the newly constructed object. // Callers must ensure that |maps| outlives the newly constructed object.
PolymorphicCodeCacheHashTableKey(MapList* maps, int code_flags) PolymorphicCodeCacheHashTableKey(MapHandleList* maps, int code_flags)
: maps_(maps), : maps_(maps),
code_flags_(code_flags) {} code_flags_(code_flags) {}
bool IsMatch(Object* other) { bool IsMatch(Object* other) {
MapList other_maps(kDefaultListAllocationSize); MapHandleList other_maps(kDefaultListAllocationSize);
int other_flags; int other_flags;
FromObject(other, &other_flags, &other_maps); FromObject(other, &other_flags, &other_maps);
if (code_flags_ != other_flags) return false; if (code_flags_ != other_flags) return false;
@ -5227,7 +5217,7 @@ class PolymorphicCodeCacheHashTableKey : public HashTableKey {
for (int i = 0; i < maps_->length(); ++i) { for (int i = 0; i < maps_->length(); ++i) {
bool match_found = false; bool match_found = false;
for (int j = 0; j < other_maps.length(); ++j) { 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; match_found = true;
break; break;
} }
@ -5237,7 +5227,7 @@ class PolymorphicCodeCacheHashTableKey : public HashTableKey {
return true; 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; uint32_t hash = code_flags;
for (int i = 0; i < maps->length(); ++i) { for (int i = 0; i < maps->length(); ++i) {
hash ^= maps->at(i)->Hash(); hash ^= maps->at(i)->Hash();
@ -5250,7 +5240,7 @@ class PolymorphicCodeCacheHashTableKey : public HashTableKey {
} }
uint32_t HashForObject(Object* obj) { uint32_t HashForObject(Object* obj) {
MapList other_maps(kDefaultListAllocationSize); MapHandleList other_maps(kDefaultListAllocationSize);
int other_flags; int other_flags;
FromObject(obj, &other_flags, &other_maps); FromObject(obj, &other_flags, &other_maps);
return MapsHashHelper(&other_maps, other_flags); return MapsHashHelper(&other_maps, other_flags);
@ -5268,29 +5258,32 @@ class PolymorphicCodeCacheHashTableKey : public HashTableKey {
FixedArray* list = FixedArray::cast(obj); FixedArray* list = FixedArray::cast(obj);
list->set(0, Smi::FromInt(code_flags_)); list->set(0, Smi::FromInt(code_flags_));
for (int i = 0; i < maps_->length(); ++i) { for (int i = 0; i < maps_->length(); ++i) {
list->set(i + 1, maps_->at(i)); list->set(i + 1, *maps_->at(i));
} }
return list; return list;
} }
private: 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); FixedArray* list = FixedArray::cast(obj);
maps->Rewind(0); maps->Rewind(0);
*code_flags = Smi::cast(list->get(0))->value(); *code_flags = Smi::cast(list->get(0))->value();
for (int i = 1; i < list->length(); ++i) { for (int i = 1; i < list->length(); ++i) {
maps->Add(Map::cast(list->get(i))); maps->Add(Handle<Map>(Map::cast(list->get(i))));
} }
return maps; return maps;
} }
MapList* maps_; // weak. MapHandleList* maps_; // weak.
int code_flags_; int code_flags_;
static const int kDefaultListAllocationSize = kMaxKeyedPolymorphism + 1; 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); PolymorphicCodeCacheHashTableKey key(maps, code_flags);
int entry = FindEntry(&key); int entry = FindEntry(&key);
if (entry == kNotFound) return GetHeap()->undefined_value(); 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, int code_flags,
Code* code) { Code* code) {
PolymorphicCodeCacheHashTableKey key(maps, code_flags); PolymorphicCodeCacheHashTableKey key(maps, code_flags);

View File

@ -5872,15 +5872,13 @@ class PolymorphicCodeCache: public Struct {
Code::Flags flags, Code::Flags flags,
Handle<Code> code); Handle<Code> code);
MUST_USE_RESULT MaybeObject* Update(MapList* maps, MUST_USE_RESULT MaybeObject* Update(MapHandleList* maps,
Code::Flags flags, Code::Flags flags,
Code* code); Code* code);
// Returns an undefined value if the entry is not found. // Returns an undefined value if the entry is not found.
Handle<Object> Lookup(MapHandleList* maps, Code::Flags flags); Handle<Object> Lookup(MapHandleList* maps, Code::Flags flags);
Object* Lookup(MapList* maps, Code::Flags flags);
static inline PolymorphicCodeCache* cast(Object* obj); static inline PolymorphicCodeCache* cast(Object* obj);
#ifdef OBJECT_PRINT #ifdef OBJECT_PRINT
@ -5904,8 +5902,11 @@ class PolymorphicCodeCache: public Struct {
class PolymorphicCodeCacheHashTable class PolymorphicCodeCacheHashTable
: public HashTable<CodeCacheHashTableShape, HashTableKey*> { : public HashTable<CodeCacheHashTableShape, HashTableKey*> {
public: public:
Object* Lookup(MapList* maps, int code_kind); Object* Lookup(MapHandleList* maps, int code_kind);
MUST_USE_RESULT MaybeObject* Put(MapList* maps, int code_kind, Code* code);
MUST_USE_RESULT MaybeObject* Put(MapHandleList* maps,
int code_kind,
Code* code);
static inline PolymorphicCodeCacheHashTable* cast(Object* obj); static inline PolymorphicCodeCacheHashTable* cast(Object* obj);