From 9f85caeb2dd5f70134b06db5b287657bc762428c Mon Sep 17 00:00:00 2001 From: "bak@chromium.org" Date: Thu, 4 Mar 2010 11:27:28 +0000 Subject: [PATCH] - Fixed the compilation cache so Put works. - Cleaned up the calls to HashTable::Allocate. Review URL: http://codereview.chromium.org/669057 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4015 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/compilation-cache.cc | 63 ++++++++++++++++++++++++++++++++++++++++++------ src/objects.cc | 11 +++++---- 2 files changed, 62 insertions(+), 12 deletions(-) diff --git a/src/compilation-cache.cc b/src/compilation-cache.cc index 333848a..9dcbeb5 100644 --- a/src/compilation-cache.cc +++ b/src/compilation-cache.cc @@ -32,7 +32,6 @@ namespace v8 { namespace internal { - // The number of sub caches covering the different types to cache. static const int kSubCacheCount = 4; @@ -47,6 +46,9 @@ static const int kRegExpGenerations = 2; // Initial size of each compilation cache table allocated. static const int kInitialCacheSize = 64; +// Index for the first generation in the cache. +static const int kFirstGeneration = 0; + // The compilation cache consists of several generational sub-caches which uses // this class as a base class. A sub-cache contains a compilation cache tables // for each generation of the sub-cache. Since the same source code string has @@ -63,6 +65,15 @@ class CompilationSubCache { // Get the compilation cache tables for a specific generation. Handle GetTable(int generation); + // Accessors for first generation. + Handle GetFirstTable() { + return GetTable(kFirstGeneration); + } + void SetFirstTable(Handle value) { + ASSERT(kFirstGeneration < generations_); + tables_[kFirstGeneration] = *value; + } + // Age the sub-cache by evicting the oldest generation and creating a new // young generation. void Age(); @@ -97,6 +108,10 @@ class CompilationCacheScript : public CompilationSubCache { void Put(Handle source, Handle boilerplate); private: + // Note: Returns a new hash table if operation results in expansion. + Handle TablePut(Handle source, + Handle boilerplate); + bool HasOrigin(Handle boilerplate, Handle name, int line_offset, @@ -118,6 +133,12 @@ class CompilationCacheEval: public CompilationSubCache { Handle context, Handle boilerplate); + private: + // Note: Returns a new hash table if operation results in expansion. + Handle TablePut(Handle source, + Handle context, + Handle boilerplate); + DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheEval); }; @@ -133,6 +154,11 @@ class CompilationCacheRegExp: public CompilationSubCache { void Put(Handle source, JSRegExp::Flags flags, Handle data); + private: + // Note: Returns a new hash table if operation results in expansion. + Handle TablePut(Handle source, + JSRegExp::Flags flags, + Handle data); DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheRegExp); }; @@ -280,12 +306,19 @@ Handle CompilationCacheScript::Lookup(Handle source, } +Handle CompilationCacheScript::TablePut( + Handle source, + Handle boilerplate) { + CALL_HEAP_FUNCTION(GetFirstTable()->Put(*source, *boilerplate), + CompilationCacheTable); +} + + void CompilationCacheScript::Put(Handle source, Handle boilerplate) { HandleScope scope; ASSERT(boilerplate->IsBoilerplate()); - Handle table = GetTable(0); - CALL_HEAP_FUNCTION_VOID(table->Put(*source, *boilerplate)); + SetFirstTable(TablePut(source, boilerplate)); } @@ -319,13 +352,21 @@ Handle CompilationCacheEval::Lookup(Handle source, } +Handle CompilationCacheEval::TablePut( + Handle source, + Handle context, + Handle boilerplate) { + CALL_HEAP_FUNCTION(GetFirstTable()->PutEval(*source, *context, *boilerplate), + CompilationCacheTable); +} + + void CompilationCacheEval::Put(Handle source, Handle context, Handle boilerplate) { HandleScope scope; ASSERT(boilerplate->IsBoilerplate()); - Handle table = GetTable(0); - CALL_HEAP_FUNCTION_VOID(table->PutEval(*source, *context, *boilerplate)); + SetFirstTable(TablePut(source, context, boilerplate)); } @@ -359,12 +400,20 @@ Handle CompilationCacheRegExp::Lookup(Handle source, } +Handle CompilationCacheRegExp::TablePut( + Handle source, + JSRegExp::Flags flags, + Handle data) { + CALL_HEAP_FUNCTION(GetFirstTable()->PutRegExp(*source, flags, *data), + CompilationCacheTable); +} + + void CompilationCacheRegExp::Put(Handle source, JSRegExp::Flags flags, Handle data) { HandleScope scope; - Handle table = GetTable(0); - CALL_HEAP_FUNCTION_VOID(table->PutRegExp(*source, flags, *data)); + SetFirstTable(TablePut(source, flags, data)); } diff --git a/src/objects.cc b/src/objects.cc index 3260d07..d236610 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -2180,7 +2180,7 @@ Object* JSObject::NormalizeProperties(PropertyNormalizationMode mode, property_count += 2; // Make space for two more properties. } Object* obj = - StringDictionary::Allocate(property_count * 2); + StringDictionary::Allocate(property_count); if (obj->IsFailure()) return obj; StringDictionary* dictionary = StringDictionary::cast(obj); @@ -6911,9 +6911,10 @@ void HashTable::IterateElements(ObjectVisitor* v) { template Object* HashTable::Allocate(int at_least_space_for, PretenureFlag pretenure) { + const int kMinCapacity = 32; int capacity = RoundUpToPowerOf2(at_least_space_for * 2); - if (capacity < 32) { - capacity = 32; // Guarantee min capacity. + if (capacity < kMinCapacity) { + capacity = kMinCapacity; // Guarantee min capacity. } else if (capacity > HashTable::kMaxCapacity) { return Failure::OutOfMemoryException(); } @@ -7103,8 +7104,7 @@ Object* JSObject::PrepareSlowElementsForSort(uint32_t limit) { result_double = HeapNumber::cast(new_double); } - int capacity = dict->Capacity(); - Object* obj = NumberDictionary::Allocate(dict->Capacity()); + Object* obj = NumberDictionary::Allocate(dict->NumberOfElements()); if (obj->IsFailure()) return obj; NumberDictionary* new_dict = NumberDictionary::cast(obj); @@ -7112,6 +7112,7 @@ Object* JSObject::PrepareSlowElementsForSort(uint32_t limit) { uint32_t pos = 0; uint32_t undefs = 0; + int capacity = dict->Capacity(); for (int i = 0; i < capacity; i++) { Object* k = dict->KeyAt(i); if (dict->IsKey(k)) { -- 2.7.4