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) {
}
Handle<CodeCache> Factory::NewCodeCache() {
CALL_HEAP_FUNCTION(
isolate(),
isolate()->heap()->AllocateCodeCache(),
CodeCache);
}
Handle<AliasedArgumentsEntry> Factory::NewAliasedArgumentsEntry(
int aliased_context_slot) {
Handle<AliasedArgumentsEntry> entry = Handle<AliasedArgumentsEntry>::cast(
......
......@@ -214,6 +214,8 @@ class Factory V8_FINAL {
// the old generation).
Handle<Struct> NewStruct(InstanceType type);
Handle<CodeCache> NewCodeCache();
Handle<AliasedArgumentsEntry> NewAliasedArgumentsEntry(
int aliased_context_slot);
......
......@@ -7272,23 +7272,15 @@ void Map::UpdateCodeCache(Handle<Map> map,
Handle<Name> name,
Handle<Code> code) {
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.
if (code_cache()->IsFixedArray()) {
Object* result;
{ MaybeObject* maybe_result = GetHeap()->AllocateCodeCache();
if (!maybe_result->ToObject(&result)) return maybe_result;
}
set_code_cache(result);
if (map->code_cache()->IsFixedArray()) {
Handle<Object> result = isolate->factory()->NewCodeCache();
map->set_code_cache(*result);
}
// 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) {
}
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
// a large number and therefore they need to go into a hash table. They are
// used to load global properties from cells.
if (code->type() == Code::NORMAL) {
// Make sure that a hash table is allocated for the normal load code cache.
if (normal_type_cache()->IsUndefined()) {
Object* result;
{ MaybeObject* maybe_result =
CodeCacheHashTable::Allocate(GetHeap(),
if (code_cache->normal_type_cache()->IsUndefined()) {
Handle<Object> result =
CodeCacheHashTable::New(code_cache->GetIsolate(),
CodeCacheHashTable::kInitialSize);
if (!maybe_result->ToObject(&result)) return maybe_result;
}
set_normal_type_cache(result);
code_cache->set_normal_type_cache(*result);
}
return UpdateNormalTypeCache(name, code);
UpdateNormalTypeCache(code_cache, name, code);
} else {
ASSERT(default_cache()->IsFixedArray());
return UpdateDefaultCache(name, code);
ASSERT(code_cache->default_cache()->IsFixedArray());
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
// flags. This allows call constant stubs to overwrite call field
// stubs, etc.
......@@ -7556,8 +7547,10 @@ MaybeObject* CodeCache::UpdateDefaultCache(Name* name, Code* code) {
// First check whether we can update existing code cache without
// extending it.
FixedArray* cache = default_cache();
Handle<FixedArray> cache = handle(code_cache->default_cache());
int length = cache->length();
{
DisallowHeapAllocation no_alloc;
int deleted_index = -1;
for (int i = 0; i < length; i += kCodeCacheEntrySize) {
Object* key = cache->get(i);
......@@ -7567,16 +7560,16 @@ MaybeObject* CodeCache::UpdateDefaultCache(Name* name, Code* code) {
}
if (key->IsUndefined()) {
if (deleted_index >= 0) i = deleted_index;
cache->set(i + kCodeCacheEntryNameOffset, name);
cache->set(i + kCodeCacheEntryCodeOffset, code);
return this;
cache->set(i + kCodeCacheEntryNameOffset, *name);
cache->set(i + kCodeCacheEntryCodeOffset, *code);
return;
}
if (name->Equals(Name::cast(key))) {
Code::Flags found =
Code::cast(cache->get(i + kCodeCacheEntryCodeOffset))->flags();
if (Code::RemoveTypeFromFlags(found) == flags) {
cache->set(i + kCodeCacheEntryCodeOffset, code);
return this;
cache->set(i + kCodeCacheEntryCodeOffset, *code);
return;
}
}
}
......@@ -7584,9 +7577,10 @@ MaybeObject* CodeCache::UpdateDefaultCache(Name* name, Code* code) {
// Reached the end of the code cache. If there were deleted
// elements, reuse the space for the first of them.
if (deleted_index >= 0) {
cache->set(deleted_index + kCodeCacheEntryNameOffset, name);
cache->set(deleted_index + kCodeCacheEntryCodeOffset, code);
return this;
cache->set(deleted_index + kCodeCacheEntryNameOffset, *name);
cache->set(deleted_index + kCodeCacheEntryCodeOffset, *code);
return;
}
}
// 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) {
int new_length = length + ((length >> 1)) + kCodeCacheEntrySize;
new_length = new_length - new_length % kCodeCacheEntrySize;
ASSERT((new_length % kCodeCacheEntrySize) == 0);
Object* result;
{ MaybeObject* maybe_result = cache->CopySize(new_length);
if (!maybe_result->ToObject(&result)) return maybe_result;
}
cache = FixedArray::CopySize(cache, new_length);
// Add the (name, code) pair to the new cache.
cache = FixedArray::cast(result);
cache->set(length + kCodeCacheEntryNameOffset, name);
cache->set(length + kCodeCacheEntryCodeOffset, code);
set_default_cache(cache);
return this;
cache->set(length + kCodeCacheEntryNameOffset, *name);
cache->set(length + kCodeCacheEntryCodeOffset, *code);
code_cache->set_default_cache(*cache);
}
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.
CodeCacheHashTable* cache = CodeCacheHashTable::cast(normal_type_cache());
Object* new_cache;
{ MaybeObject* maybe_new_cache = cache->Put(name, code);
if (!maybe_new_cache->ToObject(&new_cache)) return maybe_new_cache;
}
set_normal_type_cache(new_cache);
return this;
Handle<CodeCacheHashTable> cache(
CodeCacheHashTable::cast(code_cache->normal_type_cache()));
Handle<Object> new_cache = CodeCacheHashTable::Put(cache, name, code);
code_cache->set_normal_type_cache(*new_cache);
}
......@@ -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) {
CodeCacheHashTableKey key(name, flags);
int entry = FindEntry(&key);
......@@ -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) {
DisallowHeapAllocation no_gc;
WriteBarrierMode mode = dest->GetWriteBarrierMode(no_gc);
......
......@@ -3060,6 +3060,9 @@ class FixedArray: public FixedArrayBase {
MUST_USE_RESULT inline MaybeObject* Copy();
MUST_USE_RESULT MaybeObject* CopySize(int new_length,
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.
MUST_USE_RESULT static MaybeHandle<FixedArray> AddKeysFromJSArray(
......@@ -6471,7 +6474,6 @@ class Map: public HeapObject {
static void UpdateCodeCache(Handle<Map> map,
Handle<Name> name,
Handle<Code> code);
MUST_USE_RESULT MaybeObject* UpdateCodeCache(Name* name, Code* code);
// Extend the descriptor array of the map with the list of descriptors.
// In case of duplicates, the latest descriptor is used.
......@@ -8256,7 +8258,8 @@ class CodeCache: public Struct {
DECL_ACCESSORS(normal_type_cache, Object)
// 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
// if not.
......@@ -8283,8 +8286,10 @@ class CodeCache: public Struct {
static const int kSize = kNormalTypeCacheOffset + kPointerSize;
private:
MUST_USE_RESULT MaybeObject* UpdateDefaultCache(Name* name, Code* code);
MUST_USE_RESULT MaybeObject* UpdateNormalTypeCache(Name* name, Code* code);
static void UpdateDefaultCache(
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* LookupNormalTypeCache(Name* name, Code::Flags flags);
......@@ -8327,7 +8332,10 @@ class CodeCacheHashTable: public HashTable<CodeCacheHashTable,
HashTableKey*> {
public:
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);
void RemoveByIndex(int index);
......@@ -8338,6 +8346,8 @@ class CodeCacheHashTable: public HashTable<CodeCacheHashTable,
static const int kInitialSize = 64;
private:
MUST_USE_RESULT MaybeObject* Put(Name* name, Code* code);
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