Commit 35a30a5a authored by dslomov@chromium.org's avatar dslomov@chromium.org

Handlify CodeCache.

R=yangguo@chromium.org
BUG=

Review URL: https://codereview.chromium.org/239203003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20801 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 7976d95c
...@@ -695,6 +695,14 @@ Handle<Struct> Factory::NewStruct(InstanceType type) { ...@@ -695,6 +695,14 @@ Handle<Struct> Factory::NewStruct(InstanceType type) {
} }
Handle<CodeCache> Factory::NewCodeCache() {
CALL_HEAP_FUNCTION(
isolate(),
isolate()->heap()->AllocateCodeCache(),
CodeCache);
}
Handle<AliasedArgumentsEntry> Factory::NewAliasedArgumentsEntry( Handle<AliasedArgumentsEntry> Factory::NewAliasedArgumentsEntry(
int aliased_context_slot) { int aliased_context_slot) {
Handle<AliasedArgumentsEntry> entry = Handle<AliasedArgumentsEntry>::cast( Handle<AliasedArgumentsEntry> entry = Handle<AliasedArgumentsEntry>::cast(
......
...@@ -214,6 +214,8 @@ class Factory V8_FINAL { ...@@ -214,6 +214,8 @@ class Factory V8_FINAL {
// the old generation). // the old generation).
Handle<Struct> NewStruct(InstanceType type); Handle<Struct> NewStruct(InstanceType type);
Handle<CodeCache> NewCodeCache();
Handle<AliasedArgumentsEntry> NewAliasedArgumentsEntry( Handle<AliasedArgumentsEntry> NewAliasedArgumentsEntry(
int aliased_context_slot); int aliased_context_slot);
......
...@@ -7272,23 +7272,15 @@ void Map::UpdateCodeCache(Handle<Map> map, ...@@ -7272,23 +7272,15 @@ void Map::UpdateCodeCache(Handle<Map> map,
Handle<Name> name, Handle<Name> name,
Handle<Code> code) { Handle<Code> code) {
Isolate* isolate = map->GetIsolate(); Isolate* isolate = map->GetIsolate();
CALL_HEAP_FUNCTION_VOID(isolate,
map->UpdateCodeCache(*name, *code));
}
MaybeObject* Map::UpdateCodeCache(Name* name, Code* code) {
// Allocate the code cache if not present. // Allocate the code cache if not present.
if (code_cache()->IsFixedArray()) { if (map->code_cache()->IsFixedArray()) {
Object* result; Handle<Object> result = isolate->factory()->NewCodeCache();
{ MaybeObject* maybe_result = GetHeap()->AllocateCodeCache(); map->set_code_cache(*result);
if (!maybe_result->ToObject(&result)) return maybe_result;
}
set_code_cache(result);
} }
// Update the code cache. // Update the code cache.
return CodeCache::cast(code_cache())->Update(name, code); Handle<CodeCache> code_cache(CodeCache::cast(map->code_cache()), isolate);
CodeCache::Update(code_cache, name, code);
} }
...@@ -7525,30 +7517,29 @@ void Map::TraverseTransitionTree(TraverseCallback callback, void* data) { ...@@ -7525,30 +7517,29 @@ void Map::TraverseTransitionTree(TraverseCallback callback, void* data) {
} }
MaybeObject* CodeCache::Update(Name* name, Code* code) { void CodeCache::Update(
Handle<CodeCache> code_cache, Handle<Name> name, Handle<Code> code) {
// The number of monomorphic stubs for normal load/store/call IC's can grow to // The number of monomorphic stubs for normal load/store/call IC's can grow to
// a large number and therefore they need to go into a hash table. They are // a large number and therefore they need to go into a hash table. They are
// used to load global properties from cells. // used to load global properties from cells.
if (code->type() == Code::NORMAL) { if (code->type() == Code::NORMAL) {
// Make sure that a hash table is allocated for the normal load code cache. // Make sure that a hash table is allocated for the normal load code cache.
if (normal_type_cache()->IsUndefined()) { if (code_cache->normal_type_cache()->IsUndefined()) {
Object* result; Handle<Object> result =
{ MaybeObject* maybe_result = CodeCacheHashTable::New(code_cache->GetIsolate(),
CodeCacheHashTable::Allocate(GetHeap(), CodeCacheHashTable::kInitialSize);
CodeCacheHashTable::kInitialSize); code_cache->set_normal_type_cache(*result);
if (!maybe_result->ToObject(&result)) return maybe_result;
}
set_normal_type_cache(result);
} }
return UpdateNormalTypeCache(name, code); UpdateNormalTypeCache(code_cache, name, code);
} else { } else {
ASSERT(default_cache()->IsFixedArray()); ASSERT(code_cache->default_cache()->IsFixedArray());
return UpdateDefaultCache(name, code); UpdateDefaultCache(code_cache, name, code);
} }
} }
MaybeObject* CodeCache::UpdateDefaultCache(Name* name, Code* code) { void CodeCache::UpdateDefaultCache(
Handle<CodeCache> code_cache, Handle<Name> name, Handle<Code> code) {
// When updating the default code cache we disregard the type encoded in the // When updating the default code cache we disregard the type encoded in the
// flags. This allows call constant stubs to overwrite call field // flags. This allows call constant stubs to overwrite call field
// stubs, etc. // stubs, etc.
...@@ -7556,37 +7547,40 @@ MaybeObject* CodeCache::UpdateDefaultCache(Name* name, Code* code) { ...@@ -7556,37 +7547,40 @@ MaybeObject* CodeCache::UpdateDefaultCache(Name* name, Code* code) {
// First check whether we can update existing code cache without // First check whether we can update existing code cache without
// extending it. // extending it.
FixedArray* cache = default_cache(); Handle<FixedArray> cache = handle(code_cache->default_cache());
int length = cache->length(); int length = cache->length();
int deleted_index = -1; {
for (int i = 0; i < length; i += kCodeCacheEntrySize) { DisallowHeapAllocation no_alloc;
Object* key = cache->get(i); int deleted_index = -1;
if (key->IsNull()) { for (int i = 0; i < length; i += kCodeCacheEntrySize) {
if (deleted_index < 0) deleted_index = i; Object* key = cache->get(i);
continue; if (key->IsNull()) {
} if (deleted_index < 0) deleted_index = i;
if (key->IsUndefined()) { continue;
if (deleted_index >= 0) i = deleted_index; }
cache->set(i + kCodeCacheEntryNameOffset, name); if (key->IsUndefined()) {
cache->set(i + kCodeCacheEntryCodeOffset, code); if (deleted_index >= 0) i = deleted_index;
return this; cache->set(i + kCodeCacheEntryNameOffset, *name);
} cache->set(i + kCodeCacheEntryCodeOffset, *code);
if (name->Equals(Name::cast(key))) { return;
Code::Flags found = }
Code::cast(cache->get(i + kCodeCacheEntryCodeOffset))->flags(); if (name->Equals(Name::cast(key))) {
if (Code::RemoveTypeFromFlags(found) == flags) { Code::Flags found =
cache->set(i + kCodeCacheEntryCodeOffset, code); Code::cast(cache->get(i + kCodeCacheEntryCodeOffset))->flags();
return this; if (Code::RemoveTypeFromFlags(found) == flags) {
cache->set(i + kCodeCacheEntryCodeOffset, *code);
return;
}
} }
} }
}
// Reached the end of the code cache. If there were deleted // Reached the end of the code cache. If there were deleted
// elements, reuse the space for the first of them. // elements, reuse the space for the first of them.
if (deleted_index >= 0) { if (deleted_index >= 0) {
cache->set(deleted_index + kCodeCacheEntryNameOffset, name); cache->set(deleted_index + kCodeCacheEntryNameOffset, *name);
cache->set(deleted_index + kCodeCacheEntryCodeOffset, code); cache->set(deleted_index + kCodeCacheEntryCodeOffset, *code);
return this; return;
}
} }
// Extend the code cache with some new entries (at least one). Must be a // Extend the code cache with some new entries (at least one). Must be a
...@@ -7594,29 +7588,22 @@ MaybeObject* CodeCache::UpdateDefaultCache(Name* name, Code* code) { ...@@ -7594,29 +7588,22 @@ MaybeObject* CodeCache::UpdateDefaultCache(Name* name, Code* code) {
int new_length = length + ((length >> 1)) + kCodeCacheEntrySize; int new_length = length + ((length >> 1)) + kCodeCacheEntrySize;
new_length = new_length - new_length % kCodeCacheEntrySize; new_length = new_length - new_length % kCodeCacheEntrySize;
ASSERT((new_length % kCodeCacheEntrySize) == 0); ASSERT((new_length % kCodeCacheEntrySize) == 0);
Object* result; cache = FixedArray::CopySize(cache, new_length);
{ MaybeObject* maybe_result = cache->CopySize(new_length);
if (!maybe_result->ToObject(&result)) return maybe_result;
}
// Add the (name, code) pair to the new cache. // Add the (name, code) pair to the new cache.
cache = FixedArray::cast(result); cache->set(length + kCodeCacheEntryNameOffset, *name);
cache->set(length + kCodeCacheEntryNameOffset, name); cache->set(length + kCodeCacheEntryCodeOffset, *code);
cache->set(length + kCodeCacheEntryCodeOffset, code); code_cache->set_default_cache(*cache);
set_default_cache(cache);
return this;
} }
MaybeObject* CodeCache::UpdateNormalTypeCache(Name* name, Code* code) { void CodeCache::UpdateNormalTypeCache(
Handle<CodeCache> code_cache, Handle<Name> name, Handle<Code> code) {
// Adding a new entry can cause a new cache to be allocated. // Adding a new entry can cause a new cache to be allocated.
CodeCacheHashTable* cache = CodeCacheHashTable::cast(normal_type_cache()); Handle<CodeCacheHashTable> cache(
Object* new_cache; CodeCacheHashTable::cast(code_cache->normal_type_cache()));
{ MaybeObject* maybe_new_cache = cache->Put(name, code); Handle<Object> new_cache = CodeCacheHashTable::Put(cache, name, code);
if (!maybe_new_cache->ToObject(&new_cache)) return maybe_new_cache; code_cache->set_normal_type_cache(*new_cache);
}
set_normal_type_cache(new_cache);
return this;
} }
...@@ -7782,6 +7769,15 @@ MaybeObject* CodeCacheHashTable::Put(Name* name, Code* code) { ...@@ -7782,6 +7769,15 @@ MaybeObject* CodeCacheHashTable::Put(Name* name, Code* code) {
} }
Handle<CodeCacheHashTable> CodeCacheHashTable::Put(
Handle<CodeCacheHashTable> cache, Handle<Name> name, Handle<Code> code) {
Isolate* isolate = cache->GetIsolate();
CALL_HEAP_FUNCTION(isolate,
cache->Put(*name, *code),
CodeCacheHashTable);
}
int CodeCacheHashTable::GetIndex(Name* name, Code::Flags flags) { int CodeCacheHashTable::GetIndex(Name* name, Code::Flags flags) {
CodeCacheHashTableKey key(name, flags); CodeCacheHashTableKey key(name, flags);
int entry = FindEntry(&key); int entry = FindEntry(&key);
...@@ -8051,6 +8047,15 @@ MaybeObject* FixedArray::CopySize(int new_length, PretenureFlag pretenure) { ...@@ -8051,6 +8047,15 @@ MaybeObject* FixedArray::CopySize(int new_length, PretenureFlag pretenure) {
} }
Handle<FixedArray> FixedArray::CopySize(
Handle<FixedArray> array, int new_length, PretenureFlag pretenure) {
Isolate* isolate = array->GetIsolate();
CALL_HEAP_FUNCTION(isolate,
array->CopySize(new_length, pretenure),
FixedArray);
}
void FixedArray::CopyTo(int pos, FixedArray* dest, int dest_pos, int len) { void FixedArray::CopyTo(int pos, FixedArray* dest, int dest_pos, int len) {
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
WriteBarrierMode mode = dest->GetWriteBarrierMode(no_gc); WriteBarrierMode mode = dest->GetWriteBarrierMode(no_gc);
......
...@@ -3060,6 +3060,9 @@ class FixedArray: public FixedArrayBase { ...@@ -3060,6 +3060,9 @@ class FixedArray: public FixedArrayBase {
MUST_USE_RESULT inline MaybeObject* Copy(); MUST_USE_RESULT inline MaybeObject* Copy();
MUST_USE_RESULT MaybeObject* CopySize(int new_length, MUST_USE_RESULT MaybeObject* CopySize(int new_length,
PretenureFlag pretenure = NOT_TENURED); PretenureFlag pretenure = NOT_TENURED);
static Handle<FixedArray> CopySize(Handle<FixedArray> array,
int new_length,
PretenureFlag pretenure = NOT_TENURED);
// Add the elements of a JSArray to this FixedArray. // Add the elements of a JSArray to this FixedArray.
MUST_USE_RESULT static MaybeHandle<FixedArray> AddKeysFromJSArray( MUST_USE_RESULT static MaybeHandle<FixedArray> AddKeysFromJSArray(
...@@ -6471,7 +6474,6 @@ class Map: public HeapObject { ...@@ -6471,7 +6474,6 @@ class Map: public HeapObject {
static void UpdateCodeCache(Handle<Map> map, static void UpdateCodeCache(Handle<Map> map,
Handle<Name> name, Handle<Name> name,
Handle<Code> code); Handle<Code> code);
MUST_USE_RESULT MaybeObject* UpdateCodeCache(Name* name, Code* code);
// Extend the descriptor array of the map with the list of descriptors. // Extend the descriptor array of the map with the list of descriptors.
// In case of duplicates, the latest descriptor is used. // In case of duplicates, the latest descriptor is used.
...@@ -8256,7 +8258,8 @@ class CodeCache: public Struct { ...@@ -8256,7 +8258,8 @@ class CodeCache: public Struct {
DECL_ACCESSORS(normal_type_cache, Object) DECL_ACCESSORS(normal_type_cache, Object)
// Add the code object to the cache. // Add the code object to the cache.
MUST_USE_RESULT MaybeObject* Update(Name* name, Code* code); static void Update(
Handle<CodeCache> cache, Handle<Name> name, Handle<Code> code);
// Lookup code object in the cache. Returns code object if found and undefined // Lookup code object in the cache. Returns code object if found and undefined
// if not. // if not.
...@@ -8283,8 +8286,10 @@ class CodeCache: public Struct { ...@@ -8283,8 +8286,10 @@ class CodeCache: public Struct {
static const int kSize = kNormalTypeCacheOffset + kPointerSize; static const int kSize = kNormalTypeCacheOffset + kPointerSize;
private: private:
MUST_USE_RESULT MaybeObject* UpdateDefaultCache(Name* name, Code* code); static void UpdateDefaultCache(
MUST_USE_RESULT MaybeObject* UpdateNormalTypeCache(Name* name, Code* code); Handle<CodeCache> code_cache, Handle<Name> name, Handle<Code> code);
static void UpdateNormalTypeCache(
Handle<CodeCache> code_cache, Handle<Name> name, Handle<Code> code);
Object* LookupDefaultCache(Name* name, Code::Flags flags); Object* LookupDefaultCache(Name* name, Code::Flags flags);
Object* LookupNormalTypeCache(Name* name, Code::Flags flags); Object* LookupNormalTypeCache(Name* name, Code::Flags flags);
...@@ -8327,7 +8332,10 @@ class CodeCacheHashTable: public HashTable<CodeCacheHashTable, ...@@ -8327,7 +8332,10 @@ class CodeCacheHashTable: public HashTable<CodeCacheHashTable,
HashTableKey*> { HashTableKey*> {
public: public:
Object* Lookup(Name* name, Code::Flags flags); Object* Lookup(Name* name, Code::Flags flags);
MUST_USE_RESULT MaybeObject* Put(Name* name, Code* code); static Handle<CodeCacheHashTable> Put(
Handle<CodeCacheHashTable> table,
Handle<Name> name,
Handle<Code> code);
int GetIndex(Name* name, Code::Flags flags); int GetIndex(Name* name, Code::Flags flags);
void RemoveByIndex(int index); void RemoveByIndex(int index);
...@@ -8338,6 +8346,8 @@ class CodeCacheHashTable: public HashTable<CodeCacheHashTable, ...@@ -8338,6 +8346,8 @@ class CodeCacheHashTable: public HashTable<CodeCacheHashTable,
static const int kInitialSize = 64; static const int kInitialSize = 64;
private: private:
MUST_USE_RESULT MaybeObject* Put(Name* name, Code* code);
DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCacheHashTable); DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCacheHashTable);
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment