Commit 226c1d25 authored by ulan@chromium.org's avatar ulan@chromium.org

Handlify CompilationCache.

BUG=
R=yangguo@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20578 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent c8df5f42
...@@ -184,7 +184,7 @@ Handle<SharedFunctionInfo> CompilationCacheScript::Lookup( ...@@ -184,7 +184,7 @@ Handle<SharedFunctionInfo> CompilationCacheScript::Lookup(
{ HandleScope scope(isolate()); { HandleScope scope(isolate());
for (generation = 0; generation < generations(); generation++) { for (generation = 0; generation < generations(); generation++) {
Handle<CompilationCacheTable> table = GetTable(generation); Handle<CompilationCacheTable> table = GetTable(generation);
Handle<Object> probe(table->Lookup(*source, *context), isolate()); Handle<Object> probe = table->Lookup(source, context);
if (probe->IsSharedFunctionInfo()) { if (probe->IsSharedFunctionInfo()) {
Handle<SharedFunctionInfo> function_info = Handle<SharedFunctionInfo> function_info =
Handle<SharedFunctionInfo>::cast(probe); Handle<SharedFunctionInfo>::cast(probe);
...@@ -239,34 +239,17 @@ Handle<SharedFunctionInfo> CompilationCacheScript::Lookup( ...@@ -239,34 +239,17 @@ Handle<SharedFunctionInfo> CompilationCacheScript::Lookup(
} }
MaybeObject* CompilationCacheScript::TryTablePut(
Handle<String> source,
Handle<Context> context,
Handle<SharedFunctionInfo> function_info) {
Handle<CompilationCacheTable> table = GetFirstTable();
return table->Put(*source, *context, *function_info);
}
Handle<CompilationCacheTable> CompilationCacheScript::TablePut(
Handle<String> source,
Handle<Context> context,
Handle<SharedFunctionInfo> function_info) {
CALL_HEAP_FUNCTION(isolate(),
TryTablePut(source, context, function_info),
CompilationCacheTable);
}
void CompilationCacheScript::Put(Handle<String> source, void CompilationCacheScript::Put(Handle<String> source,
Handle<Context> context, Handle<Context> context,
Handle<SharedFunctionInfo> function_info) { Handle<SharedFunctionInfo> function_info) {
HandleScope scope(isolate()); HandleScope scope(isolate());
SetFirstTable(TablePut(source, context, function_info)); Handle<CompilationCacheTable> table = GetFirstTable();
SetFirstTable(
CompilationCacheTable::Put(table, source, context, function_info));
} }
Handle<SharedFunctionInfo> CompilationCacheEval::Lookup( MaybeHandle<SharedFunctionInfo> CompilationCacheEval::Lookup(
Handle<String> source, Handle<String> source,
Handle<Context> context, Handle<Context> context,
StrictMode strict_mode, StrictMode strict_mode,
...@@ -274,21 +257,20 @@ Handle<SharedFunctionInfo> CompilationCacheEval::Lookup( ...@@ -274,21 +257,20 @@ Handle<SharedFunctionInfo> CompilationCacheEval::Lookup(
// Make sure not to leak the table into the surrounding handle // Make sure not to leak the table into the surrounding handle
// scope. Otherwise, we risk keeping old tables around even after // scope. Otherwise, we risk keeping old tables around even after
// having cleared the cache. // having cleared the cache.
Object* result = NULL; Handle<Object> result = isolate()->factory()->undefined_value();
int generation; int generation;
{ HandleScope scope(isolate()); { HandleScope scope(isolate());
Handle<Object> temp = result;
for (generation = 0; generation < generations(); generation++) { for (generation = 0; generation < generations(); generation++) {
Handle<CompilationCacheTable> table = GetTable(generation); Handle<CompilationCacheTable> table = GetTable(generation);
result = table->LookupEval( temp = table->LookupEval(source, context, strict_mode, scope_position);
*source, *context, strict_mode, scope_position); if (temp->IsSharedFunctionInfo()) break;
if (result->IsSharedFunctionInfo()) {
break;
}
} }
if (temp->IsSharedFunctionInfo()) result = scope.CloseAndEscape(temp);
} }
if (result->IsSharedFunctionInfo()) { if (result->IsSharedFunctionInfo()) {
Handle<SharedFunctionInfo> Handle<SharedFunctionInfo> function_info =
function_info(SharedFunctionInfo::cast(result), isolate()); Handle<SharedFunctionInfo>::cast(result);
if (generation != 0) { if (generation != 0) {
Put(source, context, function_info, scope_position); Put(source, context, function_info, scope_position);
} }
...@@ -296,60 +278,44 @@ Handle<SharedFunctionInfo> CompilationCacheEval::Lookup( ...@@ -296,60 +278,44 @@ Handle<SharedFunctionInfo> CompilationCacheEval::Lookup(
return function_info; return function_info;
} else { } else {
isolate()->counters()->compilation_cache_misses()->Increment(); isolate()->counters()->compilation_cache_misses()->Increment();
return Handle<SharedFunctionInfo>::null(); return MaybeHandle<SharedFunctionInfo>();
} }
} }
MaybeObject* CompilationCacheEval::TryTablePut(
Handle<String> source,
Handle<Context> context,
Handle<SharedFunctionInfo> function_info,
int scope_position) {
Handle<CompilationCacheTable> table = GetFirstTable();
return table->PutEval(*source, *context, *function_info, scope_position);
}
Handle<CompilationCacheTable> CompilationCacheEval::TablePut(
Handle<String> source,
Handle<Context> context,
Handle<SharedFunctionInfo> function_info,
int scope_position) {
CALL_HEAP_FUNCTION(isolate(),
TryTablePut(
source, context, function_info, scope_position),
CompilationCacheTable);
}
void CompilationCacheEval::Put(Handle<String> source, void CompilationCacheEval::Put(Handle<String> source,
Handle<Context> context, Handle<Context> context,
Handle<SharedFunctionInfo> function_info, Handle<SharedFunctionInfo> function_info,
int scope_position) { int scope_position) {
HandleScope scope(isolate()); HandleScope scope(isolate());
SetFirstTable(TablePut(source, context, function_info, scope_position)); Handle<CompilationCacheTable> table = GetFirstTable();
table = CompilationCacheTable::PutEval(table, source, context,
function_info, scope_position);
SetFirstTable(table);
} }
Handle<FixedArray> CompilationCacheRegExp::Lookup(Handle<String> source, MaybeHandle<FixedArray> CompilationCacheRegExp::Lookup(
Handle<String> source,
JSRegExp::Flags flags) { JSRegExp::Flags flags) {
// Make sure not to leak the table into the surrounding handle // Make sure not to leak the table into the surrounding handle
// scope. Otherwise, we risk keeping old tables around even after // scope. Otherwise, we risk keeping old tables around even after
// having cleared the cache. // having cleared the cache.
Object* result = NULL; Handle<Object> result = isolate()->factory()->undefined_value();
int generation; int generation;
{ HandleScope scope(isolate()); { HandleScope scope(isolate());
Handle<Object> temp = result;
for (generation = 0; generation < generations(); generation++) { for (generation = 0; generation < generations(); generation++) {
Handle<CompilationCacheTable> table = GetTable(generation); Handle<CompilationCacheTable> table = GetTable(generation);
result = table->LookupRegExp(*source, flags); temp = table->LookupRegExp(source, flags);
if (result->IsFixedArray()) { if (temp->IsFixedArray()) {
break; break;
} }
} }
if (temp->IsSharedFunctionInfo()) result = scope.CloseAndEscape(temp);
} }
if (result->IsFixedArray()) { if (result->IsFixedArray()) {
Handle<FixedArray> data(FixedArray::cast(result), isolate()); Handle<FixedArray> data = Handle<FixedArray>::cast(result);
if (generation != 0) { if (generation != 0) {
Put(source, flags, data); Put(source, flags, data);
} }
...@@ -357,35 +323,17 @@ Handle<FixedArray> CompilationCacheRegExp::Lookup(Handle<String> source, ...@@ -357,35 +323,17 @@ Handle<FixedArray> CompilationCacheRegExp::Lookup(Handle<String> source,
return data; return data;
} else { } else {
isolate()->counters()->compilation_cache_misses()->Increment(); isolate()->counters()->compilation_cache_misses()->Increment();
return Handle<FixedArray>::null(); return MaybeHandle<FixedArray>();
} }
} }
MaybeObject* CompilationCacheRegExp::TryTablePut(
Handle<String> source,
JSRegExp::Flags flags,
Handle<FixedArray> data) {
Handle<CompilationCacheTable> table = GetFirstTable();
return table->PutRegExp(*source, flags, *data);
}
Handle<CompilationCacheTable> CompilationCacheRegExp::TablePut(
Handle<String> source,
JSRegExp::Flags flags,
Handle<FixedArray> data) {
CALL_HEAP_FUNCTION(isolate(),
TryTablePut(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(isolate()); HandleScope scope(isolate());
SetFirstTable(TablePut(source, flags, data)); Handle<CompilationCacheTable> table = GetFirstTable();
SetFirstTable(CompilationCacheTable::PutRegExp(table, source, flags, data));
} }
...@@ -398,36 +346,28 @@ void CompilationCache::Remove(Handle<SharedFunctionInfo> function_info) { ...@@ -398,36 +346,28 @@ void CompilationCache::Remove(Handle<SharedFunctionInfo> function_info) {
} }
Handle<SharedFunctionInfo> CompilationCache::LookupScript( MaybeHandle<SharedFunctionInfo> CompilationCache::LookupScript(
Handle<String> source, Handle<String> source,
Handle<Object> name, Handle<Object> name,
int line_offset, int line_offset,
int column_offset, int column_offset,
bool is_shared_cross_origin, bool is_shared_cross_origin,
Handle<Context> context) { Handle<Context> context) {
if (!IsEnabled()) { if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>();
return Handle<SharedFunctionInfo>::null();
}
return script_.Lookup(source, return script_.Lookup(source, name, line_offset, column_offset,
name, is_shared_cross_origin, context);
line_offset,
column_offset,
is_shared_cross_origin,
context);
} }
Handle<SharedFunctionInfo> CompilationCache::LookupEval( MaybeHandle<SharedFunctionInfo> CompilationCache::LookupEval(
Handle<String> source, Handle<String> source,
Handle<Context> context, Handle<Context> context,
StrictMode strict_mode, StrictMode strict_mode,
int scope_position) { int scope_position) {
if (!IsEnabled()) { if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>();
return Handle<SharedFunctionInfo>::null();
}
Handle<SharedFunctionInfo> result; MaybeHandle<SharedFunctionInfo> result;
if (context->IsNativeContext()) { if (context->IsNativeContext()) {
result = eval_global_.Lookup( result = eval_global_.Lookup(
source, context, strict_mode, scope_position); source, context, strict_mode, scope_position);
...@@ -440,11 +380,9 @@ Handle<SharedFunctionInfo> CompilationCache::LookupEval( ...@@ -440,11 +380,9 @@ Handle<SharedFunctionInfo> CompilationCache::LookupEval(
} }
Handle<FixedArray> CompilationCache::LookupRegExp(Handle<String> source, MaybeHandle<FixedArray> CompilationCache::LookupRegExp(Handle<String> source,
JSRegExp::Flags flags) { JSRegExp::Flags flags) {
if (!IsEnabled()) { if (!IsEnabled()) return MaybeHandle<FixedArray>();
return Handle<FixedArray>::null();
}
return reg_exp_.Lookup(source, flags); return reg_exp_.Lookup(source, flags);
} }
......
...@@ -106,17 +106,6 @@ class CompilationCacheScript : public CompilationSubCache { ...@@ -106,17 +106,6 @@ class CompilationCacheScript : public CompilationSubCache {
Handle<SharedFunctionInfo> function_info); Handle<SharedFunctionInfo> function_info);
private: private:
MUST_USE_RESULT MaybeObject* TryTablePut(
Handle<String> source,
Handle<Context> context,
Handle<SharedFunctionInfo> function_info);
// Note: Returns a new hash table if operation results in expansion.
Handle<CompilationCacheTable> TablePut(
Handle<String> source,
Handle<Context> context,
Handle<SharedFunctionInfo> function_info);
bool HasOrigin(Handle<SharedFunctionInfo> function_info, bool HasOrigin(Handle<SharedFunctionInfo> function_info,
Handle<Object> name, Handle<Object> name,
int line_offset, int line_offset,
...@@ -147,7 +136,7 @@ class CompilationCacheEval: public CompilationSubCache { ...@@ -147,7 +136,7 @@ class CompilationCacheEval: public CompilationSubCache {
CompilationCacheEval(Isolate* isolate, int generations) CompilationCacheEval(Isolate* isolate, int generations)
: CompilationSubCache(isolate, generations) { } : CompilationSubCache(isolate, generations) { }
Handle<SharedFunctionInfo> Lookup(Handle<String> source, MaybeHandle<SharedFunctionInfo> Lookup(Handle<String> source,
Handle<Context> context, Handle<Context> context,
StrictMode strict_mode, StrictMode strict_mode,
int scope_position); int scope_position);
...@@ -158,19 +147,6 @@ class CompilationCacheEval: public CompilationSubCache { ...@@ -158,19 +147,6 @@ class CompilationCacheEval: public CompilationSubCache {
int scope_position); int scope_position);
private: private:
MUST_USE_RESULT MaybeObject* TryTablePut(
Handle<String> source,
Handle<Context> context,
Handle<SharedFunctionInfo> function_info,
int scope_position);
// Note: Returns a new hash table if operation results in expansion.
Handle<CompilationCacheTable> TablePut(
Handle<String> source,
Handle<Context> context,
Handle<SharedFunctionInfo> function_info,
int scope_position);
DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheEval); DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheEval);
}; };
...@@ -181,21 +157,12 @@ class CompilationCacheRegExp: public CompilationSubCache { ...@@ -181,21 +157,12 @@ class CompilationCacheRegExp: public CompilationSubCache {
CompilationCacheRegExp(Isolate* isolate, int generations) CompilationCacheRegExp(Isolate* isolate, int generations)
: CompilationSubCache(isolate, generations) { } : CompilationSubCache(isolate, generations) { }
Handle<FixedArray> Lookup(Handle<String> source, JSRegExp::Flags flags); MaybeHandle<FixedArray> Lookup(Handle<String> source, JSRegExp::Flags flags);
void Put(Handle<String> source, void Put(Handle<String> source,
JSRegExp::Flags flags, JSRegExp::Flags flags,
Handle<FixedArray> data); Handle<FixedArray> data);
private: private:
MUST_USE_RESULT MaybeObject* TryTablePut(Handle<String> source,
JSRegExp::Flags flags,
Handle<FixedArray> data);
// 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);
}; };
...@@ -209,25 +176,21 @@ class CompilationCache { ...@@ -209,25 +176,21 @@ class CompilationCache {
// Finds the script shared function info for a source // Finds the script shared function info for a source
// string. Returns an empty handle if the cache doesn't contain a // string. Returns an empty handle if the cache doesn't contain a
// script for the given source string with the right origin. // script for the given source string with the right origin.
Handle<SharedFunctionInfo> LookupScript(Handle<String> source, MaybeHandle<SharedFunctionInfo> LookupScript(
Handle<Object> name, Handle<String> source, Handle<Object> name, int line_offset,
int line_offset, int column_offset, bool is_shared_cross_origin, Handle<Context> context);
int column_offset,
bool is_shared_cross_origin,
Handle<Context> context);
// Finds the shared function info for a source string for eval in a // Finds the shared function info for a source string for eval in a
// given context. Returns an empty handle if the cache doesn't // given context. Returns an empty handle if the cache doesn't
// contain a script for the given source string. // contain a script for the given source string.
Handle<SharedFunctionInfo> LookupEval(Handle<String> source, MaybeHandle<SharedFunctionInfo> LookupEval(
Handle<Context> context, Handle<String> source, Handle<Context> context, StrictMode strict_mode,
StrictMode strict_mode,
int scope_position); int scope_position);
// Returns the regexp data associated with the given regexp if it // Returns the regexp data associated with the given regexp if it
// is in cache, otherwise an empty handle. // is in cache, otherwise an empty handle.
Handle<FixedArray> LookupRegExp(Handle<String> source, MaybeHandle<FixedArray> LookupRegExp(
JSRegExp::Flags flags); Handle<String> source, JSRegExp::Flags flags);
// Associate the (source, kind) pair to the shared function // Associate the (source, kind) pair to the shared function
// info. This may overwrite an existing mapping. // info. This may overwrite an existing mapping.
......
...@@ -877,10 +877,12 @@ Handle<JSFunction> Compiler::GetFunctionFromEval(Handle<String> source, ...@@ -877,10 +877,12 @@ Handle<JSFunction> Compiler::GetFunctionFromEval(Handle<String> source,
isolate->counters()->total_compile_size()->Increment(source_length); isolate->counters()->total_compile_size()->Increment(source_length);
CompilationCache* compilation_cache = isolate->compilation_cache(); CompilationCache* compilation_cache = isolate->compilation_cache();
Handle<SharedFunctionInfo> shared_info = compilation_cache->LookupEval( MaybeHandle<SharedFunctionInfo> maybe_shared_info =
source, context, strict_mode, scope_position); compilation_cache->LookupEval(source, context, strict_mode,
scope_position);
Handle<SharedFunctionInfo> shared_info;
if (shared_info.is_null()) { if (!maybe_shared_info.ToHandle(&shared_info)) {
Handle<Script> script = isolate->factory()->NewScript(source); Handle<Script> script = isolate->factory()->NewScript(source);
CompilationInfoWithZone info(script); CompilationInfoWithZone info(script);
info.MarkAsEval(); info.MarkAsEval();
...@@ -945,17 +947,15 @@ Handle<SharedFunctionInfo> Compiler::CompileScript( ...@@ -945,17 +947,15 @@ Handle<SharedFunctionInfo> Compiler::CompileScript(
CompilationCache* compilation_cache = isolate->compilation_cache(); CompilationCache* compilation_cache = isolate->compilation_cache();
// Do a lookup in the compilation cache but not for extensions. // Do a lookup in the compilation cache but not for extensions.
MaybeHandle<SharedFunctionInfo> maybe_result;
Handle<SharedFunctionInfo> result; Handle<SharedFunctionInfo> result;
if (extension == NULL) { if (extension == NULL) {
result = compilation_cache->LookupScript(source, maybe_result = compilation_cache->LookupScript(
script_name, source, script_name, line_offset, column_offset,
line_offset, is_shared_cross_origin, context);
column_offset,
is_shared_cross_origin,
context);
} }
if (result.is_null()) { if (!maybe_result.ToHandle(&result)) {
// No cache entry found. Compile the script. // No cache entry found. Compile the script.
// Create a script object describing the script to be compiled. // Create a script object describing the script to be compiled.
...@@ -981,11 +981,10 @@ Handle<SharedFunctionInfo> Compiler::CompileScript( ...@@ -981,11 +981,10 @@ Handle<SharedFunctionInfo> Compiler::CompileScript(
if (extension == NULL && !result.is_null() && !result->dont_cache()) { if (extension == NULL && !result.is_null() && !result->dont_cache()) {
compilation_cache->PutScript(source, context, result); compilation_cache->PutScript(source, context, result);
} }
if (result.is_null()) isolate->ReportPendingMessages();
} else if (result->ic_age() != isolate->heap()->global_ic_age()) { } else if (result->ic_age() != isolate->heap()->global_ic_age()) {
result->ResetForNewContext(isolate->heap()->global_ic_age()); result->ResetForNewContext(isolate->heap()->global_ic_age());
} }
if (result.is_null()) isolate->ReportPendingMessages();
return result; return result;
} }
......
...@@ -175,8 +175,10 @@ Handle<Object> RegExpImpl::Compile(Handle<JSRegExp> re, ...@@ -175,8 +175,10 @@ Handle<Object> RegExpImpl::Compile(Handle<JSRegExp> re,
Zone zone(isolate); Zone zone(isolate);
JSRegExp::Flags flags = RegExpFlagsFromString(flag_str); JSRegExp::Flags flags = RegExpFlagsFromString(flag_str);
CompilationCache* compilation_cache = isolate->compilation_cache(); CompilationCache* compilation_cache = isolate->compilation_cache();
Handle<FixedArray> cached = compilation_cache->LookupRegExp(pattern, flags); MaybeHandle<FixedArray> maybe_cached =
bool in_cache = !cached.is_null(); compilation_cache->LookupRegExp(pattern, flags);
Handle<FixedArray> cached;
bool in_cache = maybe_cached.ToHandle(&cached);
LOG(isolate, RegExpCompileEvent(re, in_cache)); LOG(isolate, RegExpCompileEvent(re, in_cache));
Handle<Object> result; Handle<Object> result;
......
This diff is collapsed.
...@@ -8200,24 +8200,22 @@ class CompilationCacheTable: public HashTable<CompilationCacheShape, ...@@ -8200,24 +8200,22 @@ class CompilationCacheTable: public HashTable<CompilationCacheShape,
HashTableKey*> { HashTableKey*> {
public: public:
// Find cached value for a string key, otherwise return null. // Find cached value for a string key, otherwise return null.
Object* Lookup(String* src, Context* context); Handle<Object> Lookup(Handle<String> src, Handle<Context> context);
Object* LookupEval(String* src, Handle<Object> LookupEval(Handle<String> src, Handle<Context> context,
Context* context, StrictMode strict_mode, int scope_position);
StrictMode strict_mode, Handle<Object> LookupRegExp(Handle<String> source, JSRegExp::Flags flags);
int scope_position); static Handle<CompilationCacheTable> Put(
Object* LookupRegExp(String* source, JSRegExp::Flags flags); Handle<CompilationCacheTable> cache, Handle<String> src,
MUST_USE_RESULT MaybeObject* Put(String* src, Handle<Context> context, Handle<Object> value);
Context* context, static Handle<CompilationCacheTable> PutEval(
Object* value); Handle<CompilationCacheTable> cache, Handle<String> src,
MUST_USE_RESULT MaybeObject* PutEval(String* src, Handle<Context> context, Handle<SharedFunctionInfo> value,
Context* context,
SharedFunctionInfo* value,
int scope_position); int scope_position);
MUST_USE_RESULT MaybeObject* PutRegExp(String* src, static Handle<CompilationCacheTable> PutRegExp(
JSRegExp::Flags flags, Handle<CompilationCacheTable> cache, Handle<String> src,
FixedArray* value); JSRegExp::Flags flags, Handle<FixedArray> value);
static Handle<CompilationCacheTable> EnsureCapacityFor(
// Remove given value from cache. Handle<CompilationCacheTable> cache, int n, HashTableKey* key);
void Remove(Object* value); void Remove(Object* value);
static inline CompilationCacheTable* cast(Object* obj); static inline CompilationCacheTable* cast(Object* obj);
......
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