Reviewers: Yang,
Message:
PTAL #8
Description:
Public interface of KeyedLookupCache handlified.
Please review this at https://codereview.chromium.org/264563003/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+20, -18 lines):
M src/heap.h
M src/heap.cc
M src/runtime.cc
Index: src/heap.cc
diff --git a/src/heap.cc b/src/heap.cc
index
f139788a76e5d34ef48384c0874fccaa33047057..2c5d9862f83cdd093afbaf8d6ea50029c7816ee6
100644
--- a/src/heap.cc
+++ b/src/heap.cc
@@ -6238,19 +6238,19 @@ const char* GCTracer::CollectorString() {
}
-int KeyedLookupCache::Hash(Map* map, Name* name) {
+int KeyedLookupCache::Hash(Handle<Map> map, Handle<Name> name) {
// Uses only lower 32 bits if pointers are larger.
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);
}
-int KeyedLookupCache::Lookup(Map* map, Name* name) {
+int KeyedLookupCache::Lookup(Handle<Map> map, Handle<Name> name) {
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];
}
}
@@ -6258,18 +6258,20 @@ 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) {
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
@@ -6278,8 +6280,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;
}
@@ -6295,8 +6297,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;
}
Index: src/heap.h
diff --git a/src/heap.h b/src/heap.h
index
77c0984fa23e69c0f3262e3362015f5701900fb6..eb66c277d480eb92929e6c0a593011e2c2971180
100644
--- a/src/heap.h
+++ b/src/heap.h
@@ -2414,10 +2414,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> map, Handle<Name> name);
// 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.
void Clear();
@@ -2442,7 +2442,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
// generated code to perform cache lookups.
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index
e28783d4e06a5a71267830a6c5f4832c33d2599e..61d363ac20f7cd78aa62db070e372a64be10d2f6
100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -5083,9 +5083,9 @@ RUNTIME_FUNCTION(Runtime_KeyedGetProperty) {
Handle<Name> key = Handle<Name>::cast(key_obj);
if (receiver->HasFastProperties()) {
// 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();
- 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);
@@ -5102,7 +5102,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(
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.