| Index: src/compilation-cache.cc
|
| ===================================================================
|
| --- src/compilation-cache.cc (revision 12582)
|
| +++ src/compilation-cache.cc (working copy)
|
| @@ -262,21 +262,29 @@
|
| // scope. Otherwise, we risk keeping old tables around even after
|
| // having cleared the cache.
|
| Object* result = NULL;
|
| - int generation;
|
| + int generation = -1;
|
| { HandleScope scope(isolate());
|
| - for (generation = 0; generation < generations(); generation++) {
|
| - Handle<CompilationCacheTable> table = GetTable(generation);
|
| - result = table->LookupEval(
|
| - *source, *context, language_mode, scope_position);
|
| - if (result->IsSharedFunctionInfo()) {
|
| - break;
|
| + if (FLAG_json_eval_cache &&
|
| + json_table_->IsShortTermJSONEvalCacheTable()) {
|
| + ShortTermJSONEvalCacheTable* table =
|
| + ShortTermJSONEvalCacheTable::cast(json_table_);
|
| + result = table->Lookup(*source);
|
| + }
|
| + if (!result->IsSharedFunctionInfo()) {
|
| + for (generation = 0; generation < generations(); generation++) {
|
| + Handle<CompilationCacheTable> table = GetTable(generation);
|
| + result = table->LookupEval(
|
| + *source, *context, language_mode, scope_position);
|
| + if (result->IsSharedFunctionInfo()) {
|
| + break;
|
| + }
|
| }
|
| }
|
| }
|
| if (result->IsSharedFunctionInfo()) {
|
| Handle<SharedFunctionInfo>
|
| function_info(SharedFunctionInfo::cast(result), isolate());
|
| - if (generation != 0) {
|
| + if (generation > 0) {
|
| Put(source, context, function_info, scope_position);
|
| }
|
| isolate()->counters()->compilation_cache_hits()->Increment();
|
| @@ -293,20 +301,39 @@
|
| Handle<Context> context,
|
| Handle<SharedFunctionInfo> function_info,
|
| int scope_position) {
|
| - Handle<CompilationCacheTable> table = GetFirstTable();
|
| - return table->PutEval(*source, *context, *function_info, scope_position);
|
| + if (FLAG_json_eval_cache && function_info->is_json_eval()) {
|
| + ShortTermJSONEvalCacheTable* json_table = NULL;
|
| + if (json_table_->IsUndefined()) {
|
| + MaybeObject* maybe_table = ShortTermJSONEvalCacheTable::Allocate();
|
| + if (!maybe_table->To<ShortTermJSONEvalCacheTable>(&json_table)) {
|
| + return maybe_table;
|
| + }
|
| + } else {
|
| + json_table = ShortTermJSONEvalCacheTable::cast(json_table_);
|
| + }
|
| + { MaybeObject* maybe_table = json_table->Put(*source, *function_info);
|
| + if (!maybe_table->ToObject(&json_table_)) return maybe_table;
|
| + }
|
| + }
|
| +
|
| + CompilationCacheTable* table = *GetFirstTable();
|
| + { MaybeObject* maybe_table =
|
| + table->PutEval(*source, *context, *function_info, scope_position);
|
| + if (!maybe_table->To<CompilationCacheTable>(&table)) return maybe_table;
|
| + }
|
| + SetFirstTable(Handle<CompilationCacheTable>(table));
|
| + return isolate()->heap()->undefined_value();
|
| }
|
|
|
|
|
| -Handle<CompilationCacheTable> CompilationCacheEval::TablePut(
|
| +void 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);
|
| + CALL_HEAP_FUNCTION_VOID(isolate(),
|
| + TryTablePut(
|
| + source, context, function_info, scope_position));
|
| }
|
|
|
|
|
| @@ -315,10 +342,75 @@
|
| Handle<SharedFunctionInfo> function_info,
|
| int scope_position) {
|
| HandleScope scope(isolate());
|
| - SetFirstTable(TablePut(source, context, function_info, scope_position));
|
| + TablePut(source, context, function_info, scope_position);
|
| }
|
|
|
|
|
| +void CompilationCacheEval::Iterate(ObjectVisitor* v) {
|
| + CompilationSubCache::Iterate(v);
|
| + v->VisitPointer(&json_table_);
|
| +}
|
| +
|
| +
|
| +void CompilationCacheEval::IterateFunctions(ObjectVisitor* v) {
|
| + CompilationSubCache::IterateFunctions(v);
|
| + Object* undefined = isolate()->heap()->raw_unchecked_undefined_value();
|
| + if (json_table_ != undefined) {
|
| + ShortTermJSONEvalCacheTable* table =
|
| + reinterpret_cast<ShortTermJSONEvalCacheTable*>(json_table_);
|
| + table->IterateElements(v);
|
| + }
|
| +}
|
| +
|
| +
|
| +void CompilationCacheEval::Clear() {
|
| + CompilationSubCache::Clear();
|
| + ClearShortTerm();
|
| +}
|
| +
|
| +
|
| +bool CompilationCacheEval::ClearShortTerm() {
|
| + bool already_clear = json_table_ != NULL &&
|
| + json_table_->IsUndefined();
|
| + if (!already_clear) {
|
| + json_table_ = isolate()->heap()->undefined_value();
|
| + }
|
| + return already_clear;
|
| +}
|
| +
|
| +
|
| +void CompilationCacheEval::Remove(Handle<SharedFunctionInfo> function_info) {
|
| + CompilationSubCache::Remove(function_info);
|
| + if (json_table_ != NULL &&
|
| + json_table_->IsShortTermJSONEvalCacheTable()) {
|
| + ShortTermJSONEvalCacheTable* short_term_table =
|
| + ShortTermJSONEvalCacheTable::cast(json_table_);
|
| + short_term_table->Remove(*function_info);
|
| + }
|
| +}
|
| +
|
| +
|
| +void CompilationCacheEval::GetShortTermStatistics(int* entry_count,
|
| + int* max_entries,
|
| + int* total_size,
|
| + int* max_total_size) {
|
| + if (json_table_ == NULL ||
|
| + !json_table_->IsShortTermJSONEvalCacheTable()) {
|
| + *entry_count = 0;
|
| + *max_entries = 0;
|
| + *total_size = 0;
|
| + *max_total_size = 0;
|
| + } else {
|
| + ShortTermJSONEvalCacheTable* table =
|
| + ShortTermJSONEvalCacheTable::cast(json_table_);
|
| + *entry_count = table->NumberOfElements();
|
| + *max_entries = ShortTermJSONEvalCacheTable::max_entries();
|
| + *total_size = table->total_source_size();
|
| + *max_total_size = ShortTermJSONEvalCacheTable::max_total_source_size();
|
| + }
|
| +}
|
| +
|
| +
|
| Handle<FixedArray> CompilationCacheRegExp::Lookup(Handle<String> source,
|
| JSRegExp::Flags flags) {
|
| // Make sure not to leak the table into the surrounding handle
|
| @@ -481,6 +573,15 @@
|
| }
|
|
|
|
|
| +bool CompilationCache::ClearShortTerm() {
|
| + bool already_clear = true;
|
| + for (int i = 0; i < kSubCacheCount; i++) {
|
| + already_clear &= subcaches_[i]->ClearShortTerm();
|
| + }
|
| + return already_clear;
|
| +}
|
| +
|
| +
|
| void CompilationCache::Iterate(ObjectVisitor* v) {
|
| for (int i = 0; i < kSubCacheCount; i++) {
|
| subcaches_[i]->Iterate(v);
|
| @@ -513,4 +614,13 @@
|
| }
|
|
|
|
|
| +void CompilationCache::GetShortTermEvalStatistics(int* entry_count,
|
| + int* max_entries,
|
| + int* total_size,
|
| + int* max_total_size) {
|
| + eval_global_.GetShortTermStatistics(entry_count, max_entries,
|
| + total_size, max_total_size);
|
| +}
|
| +
|
| +
|
| } } // namespace v8::internal
|
|
|