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
This commit is contained in:
parent
792af58115
commit
134ead10d3
29
src/heap.cc
29
src/heap.cc
@ -6219,19 +6219,21 @@ const char* GCTracer::CollectorString() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int KeyedLookupCache::Hash(Map* map, Name* name) {
|
int KeyedLookupCache::Hash(Handle<Map> map, Handle<Name> name) {
|
||||||
|
DisallowHeapAllocation no_gc;
|
||||||
// Uses only lower 32 bits if pointers are larger.
|
// Uses only lower 32 bits if pointers are larger.
|
||||||
uintptr_t addr_hash =
|
uintptr_t addr_hash =
|
||||||
static_cast<uint32_t>(reinterpret_cast<uintptr_t>(map)) >> kMapHashShift;
|
static_cast<uint32_t>(reinterpret_cast<uintptr_t>(*map)) >> kMapHashShift;
|
||||||
return static_cast<uint32_t>((addr_hash ^ name->Hash()) & kCapacityMask);
|
return static_cast<uint32_t>((addr_hash ^ name->Hash()) & kCapacityMask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int KeyedLookupCache::Lookup(Map* map, Name* name) {
|
int KeyedLookupCache::Lookup(Handle<Map> map, Handle<Name> name) {
|
||||||
|
DisallowHeapAllocation no_gc;
|
||||||
int index = (Hash(map, name) & kHashMask);
|
int index = (Hash(map, name) & kHashMask);
|
||||||
for (int i = 0; i < kEntriesPerBucket; i++) {
|
for (int i = 0; i < kEntriesPerBucket; i++) {
|
||||||
Key& key = keys_[index + 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];
|
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> map,
|
||||||
|
Handle<Name> name,
|
||||||
|
int field_offset) {
|
||||||
|
DisallowHeapAllocation no_gc;
|
||||||
if (!name->IsUniqueName()) {
|
if (!name->IsUniqueName()) {
|
||||||
String* internalized_string;
|
String* internalized_string;
|
||||||
if (!map->GetIsolate()->heap()->InternalizeStringIfExists(
|
if (!map->GetIsolate()->heap()->InternalizeStringIfExists(
|
||||||
String::cast(name), &internalized_string)) {
|
String::cast(*name), &internalized_string)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
name = internalized_string;
|
name = handle(internalized_string);
|
||||||
}
|
}
|
||||||
// This cache is cleared only between mark compact passes, so we expect the
|
// This cache is cleared only between mark compact passes, so we expect the
|
||||||
// cache to only contain old space names.
|
// 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);
|
int index = (Hash(map, name) & kHashMask);
|
||||||
// After a GC there will be free slots, so we use them in order (this may
|
// 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];
|
Key& key = keys_[index];
|
||||||
Object* free_entry_indicator = NULL;
|
Object* free_entry_indicator = NULL;
|
||||||
if (key.map == free_entry_indicator) {
|
if (key.map == free_entry_indicator) {
|
||||||
key.map = map;
|
key.map = *map;
|
||||||
key.name = name;
|
key.name = *name;
|
||||||
field_offsets_[index + i] = field_offset;
|
field_offsets_[index + i] = field_offset;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -6276,8 +6281,8 @@ void KeyedLookupCache::Update(Map* map, Name* name, int field_offset) {
|
|||||||
|
|
||||||
// Write the new first entry.
|
// Write the new first entry.
|
||||||
Key& key = keys_[index];
|
Key& key = keys_[index];
|
||||||
key.map = map;
|
key.map = *map;
|
||||||
key.name = name;
|
key.name = *name;
|
||||||
field_offsets_[index] = field_offset;
|
field_offsets_[index] = field_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2413,10 +2413,10 @@ class HeapIterator BASE_EMBEDDED {
|
|||||||
class KeyedLookupCache {
|
class KeyedLookupCache {
|
||||||
public:
|
public:
|
||||||
// Lookup field offset for (map, name). If absent, -1 is returned.
|
// Lookup field offset for (map, name). If absent, -1 is returned.
|
||||||
int Lookup(Map* map, Name* name);
|
int Lookup(Handle<Map> map, Handle<Name> name);
|
||||||
|
|
||||||
// Update an element in the cache.
|
// Update an element in the cache.
|
||||||
void Update(Map* map, Name* name, int field_offset);
|
void Update(Handle<Map> map, Handle<Name> name, int field_offset);
|
||||||
|
|
||||||
// Clear the cache.
|
// Clear the cache.
|
||||||
void Clear();
|
void Clear();
|
||||||
@ -2441,7 +2441,7 @@ class KeyedLookupCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int Hash(Map* map, Name* name);
|
static inline int Hash(Handle<Map> map, Handle<Name> name);
|
||||||
|
|
||||||
// Get the address of the keys and field_offsets arrays. Used in
|
// Get the address of the keys and field_offsets arrays. Used in
|
||||||
// generated code to perform cache lookups.
|
// generated code to perform cache lookups.
|
||||||
|
@ -5099,9 +5099,9 @@ RUNTIME_FUNCTION(Runtime_KeyedGetProperty) {
|
|||||||
Handle<Name> key = Handle<Name>::cast(key_obj);
|
Handle<Name> key = Handle<Name>::cast(key_obj);
|
||||||
if (receiver->HasFastProperties()) {
|
if (receiver->HasFastProperties()) {
|
||||||
// Attempt to use lookup cache.
|
// Attempt to use lookup cache.
|
||||||
Map* receiver_map = receiver->map();
|
Handle<Map> receiver_map(receiver->map(), isolate);
|
||||||
KeyedLookupCache* keyed_lookup_cache = isolate->keyed_lookup_cache();
|
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) {
|
if (offset != -1) {
|
||||||
// Doubles are not cached, so raw read the value.
|
// Doubles are not cached, so raw read the value.
|
||||||
Object* value = receiver->RawFastPropertyAt(offset);
|
Object* value = receiver->RawFastPropertyAt(offset);
|
||||||
@ -5118,7 +5118,7 @@ RUNTIME_FUNCTION(Runtime_KeyedGetProperty) {
|
|||||||
// Do not track double fields in the keyed lookup cache. Reading
|
// Do not track double fields in the keyed lookup cache. Reading
|
||||||
// double values requires boxing.
|
// double values requires boxing.
|
||||||
if (!result.representation().IsDouble()) {
|
if (!result.representation().IsDouble()) {
|
||||||
keyed_lookup_cache->Update(receiver_map, *key, offset);
|
keyed_lookup_cache->Update(receiver_map, key, offset);
|
||||||
}
|
}
|
||||||
AllowHeapAllocation allow_allocation;
|
AllowHeapAllocation allow_allocation;
|
||||||
return *JSObject::FastPropertyAt(
|
return *JSObject::FastPropertyAt(
|
||||||
|
Loading…
Reference in New Issue
Block a user