From 134ead10d3f3ecbec540a55d580ddba726fd2c1b Mon Sep 17 00:00:00 2001 From: "ishell@chromium.org" Date: Wed, 30 Apr 2014 15:03:18 +0000 Subject: [PATCH] Public interface of KeyedLookupCache handlified. R=yangguo@chromium.org Review URL: https://codereview.chromium.org/264563003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@21095 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/heap.cc | 29 +++++++++++++++++------------ src/heap.h | 6 +++--- src/runtime.cc | 6 +++--- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/heap.cc b/src/heap.cc index 1ffd5c9..f306bcf 100644 --- a/src/heap.cc +++ b/src/heap.cc @@ -6219,19 +6219,21 @@ const char* GCTracer::CollectorString() { } -int KeyedLookupCache::Hash(Map* map, Name* name) { +int KeyedLookupCache::Hash(Handle map, Handle name) { + DisallowHeapAllocation no_gc; // Uses only lower 32 bits if pointers are larger. uintptr_t addr_hash = - static_cast(reinterpret_cast(map)) >> kMapHashShift; + static_cast(reinterpret_cast(*map)) >> kMapHashShift; return static_cast((addr_hash ^ name->Hash()) & kCapacityMask); } -int KeyedLookupCache::Lookup(Map* map, Name* name) { +int KeyedLookupCache::Lookup(Handle map, Handle name) { + DisallowHeapAllocation no_gc; int index = (Hash(map, name) & kHashMask); for (int i = 0; i < kEntriesPerBucket; i++) { Key& key = keys_[index + i]; - if ((key.map == map) && key.name->Equals(name)) { + if ((key.map == *map) && key.name->Equals(*name)) { return field_offsets_[index + i]; } } @@ -6239,18 +6241,21 @@ int KeyedLookupCache::Lookup(Map* map, Name* name) { } -void KeyedLookupCache::Update(Map* map, Name* name, int field_offset) { +void KeyedLookupCache::Update(Handle map, + Handle name, + int field_offset) { + DisallowHeapAllocation no_gc; if (!name->IsUniqueName()) { String* internalized_string; if (!map->GetIsolate()->heap()->InternalizeStringIfExists( - String::cast(name), &internalized_string)) { + String::cast(*name), &internalized_string)) { return; } - name = internalized_string; + name = handle(internalized_string); } // This cache is cleared only between mark compact passes, so we expect the // cache to only contain old space names. - ASSERT(!map->GetIsolate()->heap()->InNewSpace(name)); + ASSERT(!map->GetIsolate()->heap()->InNewSpace(*name)); int index = (Hash(map, name) & kHashMask); // After a GC there will be free slots, so we use them in order (this may @@ -6259,8 +6264,8 @@ void KeyedLookupCache::Update(Map* map, Name* name, int field_offset) { Key& key = keys_[index]; Object* free_entry_indicator = NULL; if (key.map == free_entry_indicator) { - key.map = map; - key.name = name; + key.map = *map; + key.name = *name; field_offsets_[index + i] = field_offset; return; } @@ -6276,8 +6281,8 @@ void KeyedLookupCache::Update(Map* map, Name* name, int field_offset) { // Write the new first entry. Key& key = keys_[index]; - key.map = map; - key.name = name; + key.map = *map; + key.name = *name; field_offsets_[index] = field_offset; } diff --git a/src/heap.h b/src/heap.h index f2acb44..2821eaf 100644 --- a/src/heap.h +++ b/src/heap.h @@ -2413,10 +2413,10 @@ class HeapIterator BASE_EMBEDDED { class KeyedLookupCache { public: // Lookup field offset for (map, name). If absent, -1 is returned. - int Lookup(Map* map, Name* name); + int Lookup(Handle map, Handle name); // Update an element in the cache. - void Update(Map* map, Name* name, int field_offset); + void Update(Handle map, Handle name, int field_offset); // Clear the cache. void Clear(); @@ -2441,7 +2441,7 @@ class KeyedLookupCache { } } - static inline int Hash(Map* map, Name* name); + static inline int Hash(Handle map, Handle name); // Get the address of the keys and field_offsets arrays. Used in // generated code to perform cache lookups. diff --git a/src/runtime.cc b/src/runtime.cc index 7eddc41..4a5638c 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -5099,9 +5099,9 @@ RUNTIME_FUNCTION(Runtime_KeyedGetProperty) { Handle key = Handle::cast(key_obj); if (receiver->HasFastProperties()) { // Attempt to use lookup cache. - Map* receiver_map = receiver->map(); + Handle receiver_map(receiver->map(), isolate); KeyedLookupCache* keyed_lookup_cache = isolate->keyed_lookup_cache(); - int offset = keyed_lookup_cache->Lookup(receiver_map, *key); + int offset = keyed_lookup_cache->Lookup(receiver_map, key); if (offset != -1) { // Doubles are not cached, so raw read the value. Object* value = receiver->RawFastPropertyAt(offset); @@ -5118,7 +5118,7 @@ RUNTIME_FUNCTION(Runtime_KeyedGetProperty) { // Do not track double fields in the keyed lookup cache. Reading // double values requires boxing. if (!result.representation().IsDouble()) { - keyed_lookup_cache->Update(receiver_map, *key, offset); + keyed_lookup_cache->Update(receiver_map, key, offset); } AllowHeapAllocation allow_allocation; return *JSObject::FastPropertyAt( -- 2.7.4