Commit b30e3388 authored by vitalyr@chromium.org's avatar vitalyr@chromium.org

Clean up Isolate usages in compilation cache.

Review URL: http://codereview.chromium.org/6688065

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7281 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent e8209261
......@@ -46,11 +46,12 @@ static const int kRegExpGenerations = 2;
static const int kInitialCacheSize = 64;
CompilationCache::CompilationCache()
: script_(kScriptGenerations),
eval_global_(kEvalGlobalGenerations),
eval_contextual_(kEvalContextualGenerations),
reg_exp_(kRegExpGenerations),
CompilationCache::CompilationCache(Isolate* isolate)
: isolate_(isolate),
script_(isolate, kScriptGenerations),
eval_global_(isolate, kEvalGlobalGenerations),
eval_contextual_(isolate, kEvalContextualGenerations),
reg_exp_(isolate, kRegExpGenerations),
enabled_(true),
eager_optimizing_set_(NULL) {
CompilationSubCache* subcaches[kSubCacheCount] =
......@@ -67,8 +68,7 @@ CompilationCache::~CompilationCache() {
}
static Handle<CompilationCacheTable> AllocateTable(int size) {
Isolate* isolate = Isolate::Current();
static Handle<CompilationCacheTable> AllocateTable(Isolate* isolate, int size) {
CALL_HEAP_FUNCTION(isolate,
CompilationCacheTable::Allocate(size),
CompilationCacheTable);
......@@ -79,12 +79,12 @@ Handle<CompilationCacheTable> CompilationSubCache::GetTable(int generation) {
ASSERT(generation < generations_);
Handle<CompilationCacheTable> result;
if (tables_[generation]->IsUndefined()) {
result = AllocateTable(kInitialCacheSize);
result = AllocateTable(isolate(), kInitialCacheSize);
tables_[generation] = *result;
} else {
CompilationCacheTable* table =
CompilationCacheTable::cast(tables_[generation]);
result = Handle<CompilationCacheTable>(table);
result = Handle<CompilationCacheTable>(table, isolate());
}
return result;
}
......@@ -96,12 +96,12 @@ void CompilationSubCache::Age() {
}
// Set the first generation as unborn.
tables_[0] = HEAP->undefined_value();
tables_[0] = isolate()->heap()->undefined_value();
}
void CompilationSubCache::IterateFunctions(ObjectVisitor* v) {
Object* undefined = HEAP->raw_unchecked_undefined_value();
Object* undefined = isolate()->heap()->raw_unchecked_undefined_value();
for (int i = 0; i < generations_; i++) {
if (tables_[i] != undefined) {
reinterpret_cast<CompilationCacheTable*>(tables_[i])->IterateElements(v);
......@@ -116,14 +116,14 @@ void CompilationSubCache::Iterate(ObjectVisitor* v) {
void CompilationSubCache::Clear() {
MemsetPointer(tables_, HEAP->undefined_value(), generations_);
MemsetPointer(tables_, isolate()->heap()->undefined_value(), generations_);
}
void CompilationSubCache::Remove(Handle<SharedFunctionInfo> function_info) {
// Probe the script generation tables. Make sure not to leak handles
// into the caller's handle scope.
{ HandleScope scope;
{ HandleScope scope(isolate());
for (int generation = 0; generation < generations(); generation++) {
Handle<CompilationCacheTable> table = GetTable(generation);
table->Remove(*function_info);
......@@ -132,11 +132,11 @@ void CompilationSubCache::Remove(Handle<SharedFunctionInfo> function_info) {
}
CompilationCacheScript::CompilationCacheScript(int generations)
: CompilationSubCache(generations),
script_histogram_(NULL),
script_histogram_initialized_(false) {
}
CompilationCacheScript::CompilationCacheScript(Isolate* isolate,
int generations)
: CompilationSubCache(isolate, generations),
script_histogram_(NULL),
script_histogram_initialized_(false) { }
// We only re-use a cached function for some script source code if the
......@@ -148,7 +148,7 @@ bool CompilationCacheScript::HasOrigin(
int line_offset,
int column_offset) {
Handle<Script> script =
Handle<Script>(Script::cast(function_info->script()));
Handle<Script>(Script::cast(function_info->script()), isolate());
// If the script name isn't set, the boilerplate script should have
// an undefined name to have the same origin.
if (name.is_null()) {
......@@ -177,10 +177,10 @@ Handle<SharedFunctionInfo> CompilationCacheScript::Lookup(Handle<String> source,
// Probe the script generation tables. Make sure not to leak handles
// into the caller's handle scope.
{ HandleScope scope;
{ HandleScope scope(isolate());
for (generation = 0; generation < generations(); generation++) {
Handle<CompilationCacheTable> table = GetTable(generation);
Handle<Object> probe(table->Lookup(*source));
Handle<Object> probe(table->Lookup(*source), isolate());
if (probe->IsSharedFunctionInfo()) {
Handle<SharedFunctionInfo> function_info =
Handle<SharedFunctionInfo>::cast(probe);
......@@ -194,9 +194,8 @@ Handle<SharedFunctionInfo> CompilationCacheScript::Lookup(Handle<String> source,
}
}
Isolate* isolate = Isolate::Current();
if (!script_histogram_initialized_) {
script_histogram_ = isolate->stats_table()->CreateHistogram(
script_histogram_ = isolate()->stats_table()->CreateHistogram(
"V8.ScriptCache",
0,
kScriptGenerations,
......@@ -206,22 +205,23 @@ Handle<SharedFunctionInfo> CompilationCacheScript::Lookup(Handle<String> source,
if (script_histogram_ != NULL) {
// The level NUMBER_OF_SCRIPT_GENERATIONS is equivalent to a cache miss.
isolate->stats_table()->AddHistogramSample(script_histogram_, generation);
isolate()->stats_table()->AddHistogramSample(script_histogram_, generation);
}
// Once outside the manacles of the handle scope, we need to recheck
// to see if we actually found a cached script. If so, we return a
// handle created in the caller's handle scope.
if (result != NULL) {
Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result));
Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result),
isolate());
ASSERT(HasOrigin(shared, name, line_offset, column_offset));
// If the script was found in a later generation, we promote it to
// the first generation to let it survive longer in the cache.
if (generation != 0) Put(source, shared);
isolate->counters()->compilation_cache_hits()->Increment();
isolate()->counters()->compilation_cache_hits()->Increment();
return shared;
} else {
isolate->counters()->compilation_cache_misses()->Increment();
isolate()->counters()->compilation_cache_misses()->Increment();
return Handle<SharedFunctionInfo>::null();
}
}
......@@ -238,8 +238,7 @@ MaybeObject* CompilationCacheScript::TryTablePut(
Handle<CompilationCacheTable> CompilationCacheScript::TablePut(
Handle<String> source,
Handle<SharedFunctionInfo> function_info) {
Isolate* isolate = Isolate::Current();
CALL_HEAP_FUNCTION(isolate,
CALL_HEAP_FUNCTION(isolate(),
TryTablePut(source, function_info),
CompilationCacheTable);
}
......@@ -247,7 +246,7 @@ Handle<CompilationCacheTable> CompilationCacheScript::TablePut(
void CompilationCacheScript::Put(Handle<String> source,
Handle<SharedFunctionInfo> function_info) {
HandleScope scope;
HandleScope scope(isolate());
SetFirstTable(TablePut(source, function_info));
}
......@@ -261,7 +260,7 @@ Handle<SharedFunctionInfo> CompilationCacheEval::Lookup(
// having cleared the cache.
Object* result = NULL;
int generation;
{ HandleScope scope;
{ HandleScope scope(isolate());
for (generation = 0; generation < generations(); generation++) {
Handle<CompilationCacheTable> table = GetTable(generation);
result = table->LookupEval(*source, *context, strict_mode);
......@@ -272,14 +271,14 @@ Handle<SharedFunctionInfo> CompilationCacheEval::Lookup(
}
if (result->IsSharedFunctionInfo()) {
Handle<SharedFunctionInfo>
function_info(SharedFunctionInfo::cast(result));
function_info(SharedFunctionInfo::cast(result), isolate());
if (generation != 0) {
Put(source, context, function_info);
}
COUNTERS->compilation_cache_hits()->Increment();
isolate()->counters()->compilation_cache_hits()->Increment();
return function_info;
} else {
COUNTERS->compilation_cache_misses()->Increment();
isolate()->counters()->compilation_cache_misses()->Increment();
return Handle<SharedFunctionInfo>::null();
}
}
......@@ -298,8 +297,7 @@ Handle<CompilationCacheTable> CompilationCacheEval::TablePut(
Handle<String> source,
Handle<Context> context,
Handle<SharedFunctionInfo> function_info) {
Isolate* isolate = Isolate::Current();
CALL_HEAP_FUNCTION(isolate,
CALL_HEAP_FUNCTION(isolate(),
TryTablePut(source, context, function_info),
CompilationCacheTable);
}
......@@ -308,7 +306,7 @@ Handle<CompilationCacheTable> CompilationCacheEval::TablePut(
void CompilationCacheEval::Put(Handle<String> source,
Handle<Context> context,
Handle<SharedFunctionInfo> function_info) {
HandleScope scope;
HandleScope scope(isolate());
SetFirstTable(TablePut(source, context, function_info));
}
......@@ -320,7 +318,7 @@ Handle<FixedArray> CompilationCacheRegExp::Lookup(Handle<String> source,
// having cleared the cache.
Object* result = NULL;
int generation;
{ HandleScope scope;
{ HandleScope scope(isolate());
for (generation = 0; generation < generations(); generation++) {
Handle<CompilationCacheTable> table = GetTable(generation);
result = table->LookupRegExp(*source, flags);
......@@ -330,14 +328,14 @@ Handle<FixedArray> CompilationCacheRegExp::Lookup(Handle<String> source,
}
}
if (result->IsFixedArray()) {
Handle<FixedArray> data(FixedArray::cast(result));
Handle<FixedArray> data(FixedArray::cast(result), isolate());
if (generation != 0) {
Put(source, flags, data);
}
COUNTERS->compilation_cache_hits()->Increment();
isolate()->counters()->compilation_cache_hits()->Increment();
return data;
} else {
COUNTERS->compilation_cache_misses()->Increment();
isolate()->counters()->compilation_cache_misses()->Increment();
return Handle<FixedArray>::null();
}
}
......@@ -356,8 +354,7 @@ Handle<CompilationCacheTable> CompilationCacheRegExp::TablePut(
Handle<String> source,
JSRegExp::Flags flags,
Handle<FixedArray> data) {
Isolate* isolate = Isolate::Current();
CALL_HEAP_FUNCTION(isolate,
CALL_HEAP_FUNCTION(isolate(),
TryTablePut(source, flags, data),
CompilationCacheTable);
}
......@@ -366,7 +363,7 @@ Handle<CompilationCacheTable> CompilationCacheRegExp::TablePut(
void CompilationCacheRegExp::Put(Handle<String> source,
JSRegExp::Flags flags,
Handle<FixedArray> data) {
HandleScope scope;
HandleScope scope(isolate());
SetFirstTable(TablePut(source, flags, data));
}
......@@ -439,7 +436,7 @@ void CompilationCache::PutEval(Handle<String> source,
return;
}
HandleScope scope;
HandleScope scope(isolate());
if (is_global) {
eval_global_.Put(source, context, function_info);
} else {
......
......@@ -40,7 +40,9 @@ class HashMap;
// for different compilation modes, to avoid retrieving the wrong result.
class CompilationSubCache {
public:
explicit CompilationSubCache(int generations): generations_(generations) {
CompilationSubCache(Isolate* isolate, int generations)
: isolate_(isolate),
generations_(generations) {
tables_ = NewArray<Object*>(generations);
}
......@@ -78,7 +80,11 @@ class CompilationSubCache {
// Number of generations in this sub-cache.
inline int generations() { return generations_; }
protected:
Isolate* isolate() { return isolate_; }
private:
Isolate* isolate_;
int generations_; // Number of generations.
Object** tables_; // Compilation cache tables - one for each generation.
......@@ -89,7 +95,7 @@ class CompilationSubCache {
// Sub-cache for scripts.
class CompilationCacheScript : public CompilationSubCache {
public:
explicit CompilationCacheScript(int generations);
CompilationCacheScript(Isolate* isolate, int generations);
Handle<SharedFunctionInfo> Lookup(Handle<String> source,
Handle<Object> name,
......@@ -120,8 +126,8 @@ class CompilationCacheScript : public CompilationSubCache {
// Sub-cache for eval scripts.
class CompilationCacheEval: public CompilationSubCache {
public:
explicit CompilationCacheEval(int generations)
: CompilationSubCache(generations) { }
CompilationCacheEval(Isolate* isolate, int generations)
: CompilationSubCache(isolate, generations) { }
Handle<SharedFunctionInfo> Lookup(Handle<String> source,
Handle<Context> context,
......@@ -150,8 +156,8 @@ class CompilationCacheEval: public CompilationSubCache {
// Sub-cache for regular expressions.
class CompilationCacheRegExp: public CompilationSubCache {
public:
explicit CompilationCacheRegExp(int generations)
: CompilationSubCache(generations) { }
CompilationCacheRegExp(Isolate* isolate, int generations)
: CompilationSubCache(isolate, generations) { }
Handle<FixedArray> Lookup(Handle<String> source, JSRegExp::Flags flags);
......@@ -245,7 +251,7 @@ class CompilationCache {
void Enable();
void Disable();
private:
CompilationCache();
explicit CompilationCache(Isolate* isolate);
~CompilationCache();
HashMap* EagerOptimizingSet();
......@@ -253,6 +259,12 @@ class CompilationCache {
// The number of sub caches covering the different types to cache.
static const int kSubCacheCount = 4;
bool IsEnabled() { return FLAG_compilation_cache && enabled_; }
Isolate* isolate() { return isolate_; }
Isolate* isolate_;
CompilationCacheScript script_;
CompilationCacheEval eval_global_;
CompilationCacheEval eval_contextual_;
......@@ -264,8 +276,6 @@ class CompilationCache {
HashMap* eager_optimizing_set_;
bool IsEnabled() { return FLAG_compilation_cache && enabled_; }
friend class Isolate;
DISALLOW_COPY_AND_ASSIGN(CompilationCache);
......
......@@ -598,7 +598,7 @@ bool Isolate::PreInit() {
string_tracker_->isolate_ = this;
thread_manager_ = new ThreadManager();
thread_manager_->isolate_ = this;
compilation_cache_ = new CompilationCache();
compilation_cache_ = new CompilationCache(this);
transcendental_cache_ = new TranscendentalCache();
keyed_lookup_cache_ = new KeyedLookupCache();
context_slot_cache_ = new ContextSlotCache();
......
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