Commit 9f85caeb authored by bak@chromium.org's avatar bak@chromium.org

- 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
parent 7e163d25
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
// The number of sub caches covering the different types to cache. // The number of sub caches covering the different types to cache.
static const int kSubCacheCount = 4; static const int kSubCacheCount = 4;
...@@ -47,6 +46,9 @@ static const int kRegExpGenerations = 2; ...@@ -47,6 +46,9 @@ static const int kRegExpGenerations = 2;
// Initial size of each compilation cache table allocated. // Initial size of each compilation cache table allocated.
static const int kInitialCacheSize = 64; 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 // 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 // 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 // for each generation of the sub-cache. Since the same source code string has
...@@ -63,6 +65,15 @@ class CompilationSubCache { ...@@ -63,6 +65,15 @@ class CompilationSubCache {
// Get the compilation cache tables for a specific generation. // Get the compilation cache tables for a specific generation.
Handle<CompilationCacheTable> GetTable(int generation); Handle<CompilationCacheTable> GetTable(int generation);
// Accessors for first generation.
Handle<CompilationCacheTable> GetFirstTable() {
return GetTable(kFirstGeneration);
}
void SetFirstTable(Handle<CompilationCacheTable> value) {
ASSERT(kFirstGeneration < generations_);
tables_[kFirstGeneration] = *value;
}
// Age the sub-cache by evicting the oldest generation and creating a new // Age the sub-cache by evicting the oldest generation and creating a new
// young generation. // young generation.
void Age(); void Age();
...@@ -97,6 +108,10 @@ class CompilationCacheScript : public CompilationSubCache { ...@@ -97,6 +108,10 @@ class CompilationCacheScript : public CompilationSubCache {
void Put(Handle<String> source, Handle<JSFunction> boilerplate); void Put(Handle<String> source, Handle<JSFunction> boilerplate);
private: private:
// Note: Returns a new hash table if operation results in expansion.
Handle<CompilationCacheTable> TablePut(Handle<String> source,
Handle<JSFunction> boilerplate);
bool HasOrigin(Handle<JSFunction> boilerplate, bool HasOrigin(Handle<JSFunction> boilerplate,
Handle<Object> name, Handle<Object> name,
int line_offset, int line_offset,
...@@ -118,6 +133,12 @@ class CompilationCacheEval: public CompilationSubCache { ...@@ -118,6 +133,12 @@ class CompilationCacheEval: public CompilationSubCache {
Handle<Context> context, Handle<Context> context,
Handle<JSFunction> boilerplate); Handle<JSFunction> boilerplate);
private:
// Note: Returns a new hash table if operation results in expansion.
Handle<CompilationCacheTable> TablePut(Handle<String> source,
Handle<Context> context,
Handle<JSFunction> boilerplate);
DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheEval); DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheEval);
}; };
...@@ -133,6 +154,11 @@ class CompilationCacheRegExp: public CompilationSubCache { ...@@ -133,6 +154,11 @@ class CompilationCacheRegExp: public CompilationSubCache {
void Put(Handle<String> source, void Put(Handle<String> source,
JSRegExp::Flags flags, JSRegExp::Flags flags,
Handle<FixedArray> data); Handle<FixedArray> data);
private:
// Note: Returns a new hash table if operation results in expansion.
Handle<CompilationCacheTable> TablePut(Handle<String> source,
JSRegExp::Flags flags,
Handle<FixedArray> data);
DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheRegExp); DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheRegExp);
}; };
...@@ -280,12 +306,19 @@ Handle<JSFunction> CompilationCacheScript::Lookup(Handle<String> source, ...@@ -280,12 +306,19 @@ Handle<JSFunction> CompilationCacheScript::Lookup(Handle<String> source,
} }
Handle<CompilationCacheTable> CompilationCacheScript::TablePut(
Handle<String> source,
Handle<JSFunction> boilerplate) {
CALL_HEAP_FUNCTION(GetFirstTable()->Put(*source, *boilerplate),
CompilationCacheTable);
}
void CompilationCacheScript::Put(Handle<String> source, void CompilationCacheScript::Put(Handle<String> source,
Handle<JSFunction> boilerplate) { Handle<JSFunction> boilerplate) {
HandleScope scope; HandleScope scope;
ASSERT(boilerplate->IsBoilerplate()); ASSERT(boilerplate->IsBoilerplate());
Handle<CompilationCacheTable> table = GetTable(0); SetFirstTable(TablePut(source, boilerplate));
CALL_HEAP_FUNCTION_VOID(table->Put(*source, *boilerplate));
} }
...@@ -319,13 +352,21 @@ Handle<JSFunction> CompilationCacheEval::Lookup(Handle<String> source, ...@@ -319,13 +352,21 @@ Handle<JSFunction> CompilationCacheEval::Lookup(Handle<String> source,
} }
Handle<CompilationCacheTable> CompilationCacheEval::TablePut(
Handle<String> source,
Handle<Context> context,
Handle<JSFunction> boilerplate) {
CALL_HEAP_FUNCTION(GetFirstTable()->PutEval(*source, *context, *boilerplate),
CompilationCacheTable);
}
void CompilationCacheEval::Put(Handle<String> source, void CompilationCacheEval::Put(Handle<String> source,
Handle<Context> context, Handle<Context> context,
Handle<JSFunction> boilerplate) { Handle<JSFunction> boilerplate) {
HandleScope scope; HandleScope scope;
ASSERT(boilerplate->IsBoilerplate()); ASSERT(boilerplate->IsBoilerplate());
Handle<CompilationCacheTable> table = GetTable(0); SetFirstTable(TablePut(source, context, boilerplate));
CALL_HEAP_FUNCTION_VOID(table->PutEval(*source, *context, *boilerplate));
} }
...@@ -359,12 +400,20 @@ Handle<FixedArray> CompilationCacheRegExp::Lookup(Handle<String> source, ...@@ -359,12 +400,20 @@ Handle<FixedArray> CompilationCacheRegExp::Lookup(Handle<String> source,
} }
Handle<CompilationCacheTable> CompilationCacheRegExp::TablePut(
Handle<String> source,
JSRegExp::Flags flags,
Handle<FixedArray> data) {
CALL_HEAP_FUNCTION(GetFirstTable()->PutRegExp(*source, flags, *data),
CompilationCacheTable);
}
void CompilationCacheRegExp::Put(Handle<String> source, void CompilationCacheRegExp::Put(Handle<String> source,
JSRegExp::Flags flags, JSRegExp::Flags flags,
Handle<FixedArray> data) { Handle<FixedArray> data) {
HandleScope scope; HandleScope scope;
Handle<CompilationCacheTable> table = GetTable(0); SetFirstTable(TablePut(source, flags, data));
CALL_HEAP_FUNCTION_VOID(table->PutRegExp(*source, flags, *data));
} }
......
...@@ -2180,7 +2180,7 @@ Object* JSObject::NormalizeProperties(PropertyNormalizationMode mode, ...@@ -2180,7 +2180,7 @@ Object* JSObject::NormalizeProperties(PropertyNormalizationMode mode,
property_count += 2; // Make space for two more properties. property_count += 2; // Make space for two more properties.
} }
Object* obj = Object* obj =
StringDictionary::Allocate(property_count * 2); StringDictionary::Allocate(property_count);
if (obj->IsFailure()) return obj; if (obj->IsFailure()) return obj;
StringDictionary* dictionary = StringDictionary::cast(obj); StringDictionary* dictionary = StringDictionary::cast(obj);
...@@ -6911,9 +6911,10 @@ void HashTable<Shape, Key>::IterateElements(ObjectVisitor* v) { ...@@ -6911,9 +6911,10 @@ void HashTable<Shape, Key>::IterateElements(ObjectVisitor* v) {
template<typename Shape, typename Key> template<typename Shape, typename Key>
Object* HashTable<Shape, Key>::Allocate(int at_least_space_for, Object* HashTable<Shape, Key>::Allocate(int at_least_space_for,
PretenureFlag pretenure) { PretenureFlag pretenure) {
const int kMinCapacity = 32;
int capacity = RoundUpToPowerOf2(at_least_space_for * 2); int capacity = RoundUpToPowerOf2(at_least_space_for * 2);
if (capacity < 32) { if (capacity < kMinCapacity) {
capacity = 32; // Guarantee min capacity. capacity = kMinCapacity; // Guarantee min capacity.
} else if (capacity > HashTable::kMaxCapacity) { } else if (capacity > HashTable::kMaxCapacity) {
return Failure::OutOfMemoryException(); return Failure::OutOfMemoryException();
} }
...@@ -7103,8 +7104,7 @@ Object* JSObject::PrepareSlowElementsForSort(uint32_t limit) { ...@@ -7103,8 +7104,7 @@ Object* JSObject::PrepareSlowElementsForSort(uint32_t limit) {
result_double = HeapNumber::cast(new_double); result_double = HeapNumber::cast(new_double);
} }
int capacity = dict->Capacity(); Object* obj = NumberDictionary::Allocate(dict->NumberOfElements());
Object* obj = NumberDictionary::Allocate(dict->Capacity());
if (obj->IsFailure()) return obj; if (obj->IsFailure()) return obj;
NumberDictionary* new_dict = NumberDictionary::cast(obj); NumberDictionary* new_dict = NumberDictionary::cast(obj);
...@@ -7112,6 +7112,7 @@ Object* JSObject::PrepareSlowElementsForSort(uint32_t limit) { ...@@ -7112,6 +7112,7 @@ Object* JSObject::PrepareSlowElementsForSort(uint32_t limit) {
uint32_t pos = 0; uint32_t pos = 0;
uint32_t undefs = 0; uint32_t undefs = 0;
int capacity = dict->Capacity();
for (int i = 0; i < capacity; i++) { for (int i = 0; i < capacity; i++) {
Object* k = dict->KeyAt(i); Object* k = dict->KeyAt(i);
if (dict->IsKey(k)) { if (dict->IsKey(k)) {
......
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