Revision: 4870
Author: [email protected]
Date: Tue Jun 15 12:28:12 2010
Log: [Isolates] KeyedLookupCache / DescriptorLookupCache / ContextSlotCache
moved to Isolate.
Landing patch by Maxim.Mossienko.
Original review: http://codereview.chromium.org/2770014/show
Review URL: http://codereview.chromium.org/2816006
http://code.google.com/p/v8/source/detail?r=4870
Modified:
/branches/experimental/isolates/src/assembler.cc
/branches/experimental/isolates/src/heap.cc
/branches/experimental/isolates/src/heap.h
/branches/experimental/isolates/src/isolate.cc
/branches/experimental/isolates/src/isolate.h
/branches/experimental/isolates/src/objects.cc
/branches/experimental/isolates/src/runtime.cc
/branches/experimental/isolates/src/scopeinfo.cc
/branches/experimental/isolates/src/scopeinfo.h
=======================================
--- /branches/experimental/isolates/src/assembler.cc Thu Jun 10 11:15:06
2010
+++ /branches/experimental/isolates/src/assembler.cc Tue Jun 15 12:28:12
2010
@@ -595,12 +595,14 @@
ExternalReference ExternalReference::keyed_lookup_cache_keys() {
- return ExternalReference(KeyedLookupCache::keys_address());
+ return ExternalReference(Isolate::Current()->
+ keyed_lookup_cache()->keys_address());
}
ExternalReference ExternalReference::keyed_lookup_cache_field_offsets() {
- return ExternalReference(KeyedLookupCache::field_offsets_address());
+ return ExternalReference(Isolate::Current()->
+ keyed_lookup_cache()->field_offsets_address());
}
=======================================
--- /branches/experimental/isolates/src/heap.cc Thu Jun 10 11:15:06 2010
+++ /branches/experimental/isolates/src/heap.cc Tue Jun 15 12:28:12 2010
@@ -705,9 +705,9 @@
void Heap::MarkCompactPrologue(bool is_compacting) {
// At any old GC clear the keyed lookup cache to enable collection of
unused
// maps.
- KeyedLookupCache::Clear();
- ContextSlotCache::Clear();
- DescriptorLookupCache::Clear();
+ isolate_->keyed_lookup_cache()->Clear();
+ isolate_->context_slot_cache()->Clear();
+ isolate_->descriptor_lookup_cache()->Clear();
CompilationCache::MarkCompactPrologue();
@@ -860,7 +860,7 @@
LOG(ResourceEvent("scavenge", "begin"));
// Clear descriptor cache.
- DescriptorLookupCache::Clear();
+ isolate_->descriptor_lookup_cache()->Clear();
// Used for updating survived_since_last_expansion_ at function end.
int survived_watermark = PromotedSpaceSize();
@@ -1670,13 +1670,13 @@
set_last_script_id(undefined_value());
// Initialize keyed lookup cache.
- KeyedLookupCache::Clear();
+ isolate_->keyed_lookup_cache()->Clear();
// Initialize context slot cache.
- ContextSlotCache::Clear();
+ isolate_->context_slot_cache()->Clear();
// Initialize descriptor cache.
- DescriptorLookupCache::Clear();
+ isolate_->descriptor_lookup_cache()->Clear();
// Initialize compilation cache.
CompilationCache::Clear();
@@ -4672,7 +4672,7 @@
if ((key.map == map) && key.name->Equals(name)) {
return field_offsets_[index];
}
- return -1;
+ return kNotFound;
}
@@ -4691,23 +4691,11 @@
void KeyedLookupCache::Clear() {
for (int index = 0; index < kLength; index++) keys_[index].map = NULL;
}
-
-
-KeyedLookupCache::Key KeyedLookupCache::keys_[KeyedLookupCache::kLength];
-
-
-int KeyedLookupCache::field_offsets_[KeyedLookupCache::kLength];
void DescriptorLookupCache::Clear() {
for (int index = 0; index < kLength; index++) keys_[index].array = NULL;
}
-
-
-DescriptorLookupCache::Key
-DescriptorLookupCache::keys_[DescriptorLookupCache::kLength];
-
-int DescriptorLookupCache::results_[DescriptorLookupCache::kLength];
#ifdef DEBUG
=======================================
--- /branches/experimental/isolates/src/heap.h Thu Jun 10 11:15:06 2010
+++ /branches/experimental/isolates/src/heap.h Tue Jun 15 12:28:12 2010
@@ -1472,28 +1472,37 @@
class KeyedLookupCache {
public:
// Lookup field offset for (map, name). If absent, -1 is returned.
- static int Lookup(Map* map, String* name);
+ int Lookup(Map* map, String* name);
// Update an element in the cache.
- static void Update(Map* map, String* name, int field_offset);
+ void Update(Map* map, String* name, int field_offset);
// Clear the cache.
- static void Clear();
+ void Clear();
static const int kLength = 64;
static const int kCapacityMask = kLength - 1;
static const int kMapHashShift = 2;
+ static const int kNotFound = -1;
private:
+ KeyedLookupCache() {
+ for (int i = 0; i < kLength; ++i) {
+ keys_[i].map = NULL;
+ keys_[i].name = NULL;
+ field_offsets_[i] = kNotFound;
+ }
+ }
+
static inline int Hash(Map* map, String* name);
// Get the address of the keys and field_offsets arrays. Used in
// generated code to perform cache lookups.
- static Address keys_address() {
+ Address keys_address() {
return reinterpret_cast<Address>(&keys_);
}
- static Address field_offsets_address() {
+ Address field_offsets_address() {
return reinterpret_cast<Address>(&field_offsets_);
}
@@ -1501,10 +1510,13 @@
Map* map;
String* name;
};
- static Key keys_[kLength];
- static int field_offsets_[kLength];
+
+ Key keys_[kLength];
+ int field_offsets_[kLength];
friend class ExternalReference;
+ friend class Isolate;
+ DISALLOW_COPY_AND_ASSIGN(KeyedLookupCache);
};
@@ -1516,7 +1528,7 @@
public:
// Lookup descriptor index for (map, name).
// If absent, kAbsent is returned.
- static int Lookup(DescriptorArray* array, String* name) {
+ int Lookup(DescriptorArray* array, String* name) {
if (!StringShape(name).IsSymbol()) return kAbsent;
int index = Hash(array, name);
Key& key = keys_[index];
@@ -1525,7 +1537,7 @@
}
// Update an element in the cache.
- static void Update(DescriptorArray* array, String* name, int result) {
+ void Update(DescriptorArray* array, String* name, int result) {
ASSERT(result != kAbsent);
if (StringShape(name).IsSymbol()) {
int index = Hash(array, name);
@@ -1537,10 +1549,18 @@
}
// Clear the cache.
- static void Clear();
+ void Clear();
static const int kAbsent = -2;
private:
+ DescriptorLookupCache() {
+ for (int i = 0; i < kLength; ++i) {
+ keys_[i].array = NULL;
+ keys_[i].name = NULL;
+ results_[i] = kAbsent;
+ }
+ }
+
static int Hash(DescriptorArray* array, String* name) {
// Uses only lower 32 bits if pointers are larger.
uint32_t array_hash =
@@ -1556,8 +1576,11 @@
String* name;
};
- static Key keys_[kLength];
- static int results_[kLength];
+ Key keys_[kLength];
+ int results_[kLength];
+
+ friend class Isolate;
+ DISALLOW_COPY_AND_ASSIGN(DescriptorLookupCache);
};
=======================================
--- /branches/experimental/isolates/src/isolate.cc Thu Jun 10 11:15:06 2010
+++ /branches/experimental/isolates/src/isolate.cc Tue Jun 15 12:28:12 2010
@@ -34,6 +34,7 @@
#include "log.h"
#include "isolate.h"
#include "serialize.h"
+#include "scopeinfo.h"
#include "simulator.h"
#include "stub-cache.h"
#include "oprofile-agent.h"
@@ -92,6 +93,9 @@
break_access_(OS::CreateMutex()),
stub_cache_(NULL),
transcendental_cache_(new TranscendentalCache()),
+ keyed_lookup_cache_(new KeyedLookupCache()),
+ context_slot_cache_(new ContextSlotCache()),
+ descriptor_lookup_cache_(new DescriptorLookupCache()),
handle_scope_implementer_(NULL) {
heap_.isolate_ = this;
stack_guard_.isolate_ = this;
@@ -111,6 +115,13 @@
Isolate::~Isolate() {
+ delete descriptor_lookup_cache_;
+ descriptor_lookup_cache_ = NULL;
+ delete context_slot_cache_;
+ context_slot_cache_ = NULL;
+ delete keyed_lookup_cache_;
+ keyed_lookup_cache_ = NULL;
+
delete transcendental_cache_;
transcendental_cache_ = NULL;
delete stub_cache_;
=======================================
--- /branches/experimental/isolates/src/isolate.h Tue Jun 15 09:28:35 2010
+++ /branches/experimental/isolates/src/isolate.h Tue Jun 15 12:28:12 2010
@@ -37,6 +37,7 @@
namespace internal {
class Bootstrapper;
+class ContextSlotCache;
class Deserializer;
class HandleScopeImplementer;
class SaveContext;
@@ -164,9 +165,21 @@
StubCache* stub_cache() { return stub_cache_; }
ThreadLocalTop* thread_local_top() { return &thread_local_top_; }
- TranscendentalCache* transcendental_cache() const {
+ TranscendentalCache* transcendental_cache() {
return transcendental_cache_;
}
+
+ KeyedLookupCache* keyed_lookup_cache() {
+ return keyed_lookup_cache_;
+ }
+
+ ContextSlotCache* context_slot_cache() {
+ return context_slot_cache_;
+ }
+
+ DescriptorLookupCache* descriptor_lookup_cache() {
+ return descriptor_lookup_cache_;
+ }
v8::ImplementationUtilities::HandleScopeData* handle_scope_data() {
return &handle_scope_data_;
@@ -211,6 +224,9 @@
StubCache* stub_cache_;
ThreadLocalTop thread_local_top_;
TranscendentalCache* transcendental_cache_;
+ KeyedLookupCache* keyed_lookup_cache_;
+ ContextSlotCache* context_slot_cache_;
+ DescriptorLookupCache* descriptor_lookup_cache_;
v8::ImplementationUtilities::HandleScopeData handle_scope_data_;
HandleScopeImplementer* handle_scope_implementer_;
Zone zone_;
=======================================
--- /branches/experimental/isolates/src/objects.cc Thu Jun 10 10:14:01 2010
+++ /branches/experimental/isolates/src/objects.cc Tue Jun 15 12:28:12 2010
@@ -1682,10 +1682,13 @@
void JSObject::LookupInDescriptor(String* name, LookupResult* result) {
DescriptorArray* descriptors = map()->instance_descriptors();
- int number = DescriptorLookupCache::Lookup(descriptors, name);
+ DescriptorLookupCache* descriptor_lookup_cache = Isolate::Current()->
+ descriptor_lookup_cache();
+ int number = descriptor_lookup_cache->Lookup(descriptors, name);
+
if (number == DescriptorLookupCache::kAbsent) {
number = descriptors->Search(name);
- DescriptorLookupCache::Update(descriptors, name, number);
+ descriptor_lookup_cache->Update(descriptors, name, number);
}
if (number != DescriptorArray::kNotFound) {
result->DescriptorResult(this, descriptors->GetDetails(number),
number);
=======================================
--- /branches/experimental/isolates/src/runtime.cc Thu Jun 10 11:15:06 2010
+++ /branches/experimental/isolates/src/runtime.cc Tue Jun 15 12:28:12 2010
@@ -3771,7 +3771,9 @@
if (receiver->HasFastProperties()) {
// Attempt to use lookup cache.
Map* receiver_map = receiver->map();
- int offset = KeyedLookupCache::Lookup(receiver_map, key);
+ KeyedLookupCache* keyed_lookup_cache = Isolate::Current()->
+ keyed_lookup_cache();
+ int offset = keyed_lookup_cache->Lookup(receiver_map, key);
if (offset != -1) {
Object* value = receiver->FastPropertyAt(offset);
return value->IsTheHole() ? HEAP->undefined_value() : value;
@@ -3781,7 +3783,7 @@
receiver->LocalLookup(key, &result);
if (result.IsProperty() && result.type() == FIELD) {
int offset = result.GetFieldIndex();
- KeyedLookupCache::Update(receiver_map, key, offset);
+ keyed_lookup_cache->Update(receiver_map, key, offset);
return receiver->FastPropertyAt(offset);
}
} else {
=======================================
--- /branches/experimental/isolates/src/scopeinfo.cc Thu Jun 10 08:41:41
2010
+++ /branches/experimental/isolates/src/scopeinfo.cc Tue Jun 15 12:28:12
2010
@@ -431,7 +431,8 @@
String* name,
Variable::Mode* mode) {
ASSERT(name->IsSymbol());
- int result = ContextSlotCache::Lookup(code, name, mode);
+ Isolate* isolate = Isolate::Current();
+ int result = isolate->context_slot_cache()->Lookup(code, name, mode);
if (result != ContextSlotCache::kNotFound) return result;
if (code->sinfo_size() > 0) {
// Loop below depends on the NULL sentinel after the context slot
names.
@@ -450,13 +451,13 @@
Variable::Mode mode_value = static_cast<Variable::Mode>(v);
if (mode != NULL) *mode = mode_value;
result = static_cast<int>((p - p0) >> 1) +
Context::MIN_CONTEXT_SLOTS;
- ContextSlotCache::Update(code, name, mode_value, result);
+ isolate->context_slot_cache()->Update(code, name, mode_value,
result);
return result;
}
p += 2;
}
}
- ContextSlotCache::Update(code, name, Variable::INTERNAL, -1);
+ isolate->context_slot_cache()->Update(code, name, Variable::INTERNAL,
-1);
return -1;
}
@@ -577,12 +578,6 @@
void ContextSlotCache::Clear() {
for (int index = 0; index < kLength; index++) keys_[index].code = NULL;
}
-
-
-ContextSlotCache::Key ContextSlotCache::keys_[ContextSlotCache::kLength];
-
-
-uint32_t ContextSlotCache::values_[ContextSlotCache::kLength];
#ifdef DEBUG
=======================================
--- /branches/experimental/isolates/src/scopeinfo.h Mon Mar 8 22:38:33 2010
+++ /branches/experimental/isolates/src/scopeinfo.h Tue Jun 15 12:28:12 2010
@@ -172,28 +172,31 @@
public:
// Lookup context slot index for (code, name).
// If absent, kNotFound is returned.
- static int Lookup(Code* code,
- String* name,
- Variable::Mode* mode);
+ int Lookup(Code* code, String* name, Variable::Mode* mode);
// Update an element in the cache.
- static void Update(Code* code,
- String* name,
- Variable::Mode mode,
- int slot_index);
+ void Update(Code* code, String* name, Variable::Mode mode, int
slot_index);
// Clear the cache.
- static void Clear();
+ void Clear();
static const int kNotFound = -2;
private:
+ ContextSlotCache() {
+ for (int i = 0; i < kLength; ++i) {
+ keys_[i].code = NULL;
+ keys_[i].name = NULL;
+ values_[i] = kNotFound;
+ }
+ }
+
inline static int Hash(Code* code, String* name);
#ifdef DEBUG
- static void ValidateEntry(Code* code,
- String* name,
- Variable::Mode mode,
- int slot_index);
+ void ValidateEntry(Code* code,
+ String* name,
+ Variable::Mode mode,
+ int slot_index);
#endif
static const int kLength = 256;
@@ -227,8 +230,11 @@
uint32_t value_;
};
- static Key keys_[kLength];
- static uint32_t values_[kLength];
+ Key keys_[kLength];
+ uint32_t values_[kLength];
+
+ friend class Isolate;
+ DISALLOW_COPY_AND_ASSIGN(ContextSlotCache);
};
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev