Commit 3ce873c3 authored by sgjesse@chromium.org's avatar sgjesse@chromium.org

Refactor the handling of generations in the compilation cache.

Add generations to the compilation cache for eval and regexp. The number of generations for these are set to two.

BUG=none
TEST=none
Review URL: http://codereview.chromium.org/140056

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2233 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 59cd4dc5
This diff is collapsed.
...@@ -34,20 +34,9 @@ namespace internal { ...@@ -34,20 +34,9 @@ namespace internal {
// The compilation cache keeps function boilerplates for compiled // The compilation cache keeps function boilerplates for compiled
// scripts and evals. The boilerplates are looked up using the source // scripts and evals. The boilerplates are looked up using the source
// string as the key. // string as the key. For regular expressions the compilation data is cached.
class CompilationCache { class CompilationCache {
public: public:
// The same source code string has different compiled code for
// scripts and evals. Internally, we use separate caches to avoid
// getting the wrong kind of entry when looking up.
enum Entry {
EVAL_GLOBAL,
EVAL_CONTEXTUAL,
REGEXP,
SCRIPT,
LAST_ENTRY = SCRIPT
};
// Finds the script function boilerplate for a source // Finds the script function boilerplate 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.
...@@ -61,7 +50,7 @@ class CompilationCache { ...@@ -61,7 +50,7 @@ class CompilationCache {
// contain a script for the given source string. // contain a script for the given source string.
static Handle<JSFunction> LookupEval(Handle<String> source, static Handle<JSFunction> LookupEval(Handle<String> source,
Handle<Context> context, Handle<Context> context,
Entry entry); bool is_global);
// 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.
...@@ -77,7 +66,7 @@ class CompilationCache { ...@@ -77,7 +66,7 @@ class CompilationCache {
// with the boilerplate. This may overwrite an existing mapping. // with the boilerplate. This may overwrite an existing mapping.
static void PutEval(Handle<String> source, static void PutEval(Handle<String> source,
Handle<Context> context, Handle<Context> context,
Entry entry, bool is_global,
Handle<JSFunction> boilerplate); Handle<JSFunction> boilerplate);
// Associate the (source, flags) pair to the given regexp data. // Associate the (source, flags) pair to the given regexp data.
......
...@@ -295,14 +295,11 @@ Handle<JSFunction> Compiler::CompileEval(Handle<String> source, ...@@ -295,14 +295,11 @@ Handle<JSFunction> Compiler::CompileEval(Handle<String> source,
// The VM is in the COMPILER state until exiting this function. // The VM is in the COMPILER state until exiting this function.
VMState state(COMPILER); VMState state(COMPILER);
CompilationCache::Entry entry = is_global
? CompilationCache::EVAL_GLOBAL
: CompilationCache::EVAL_CONTEXTUAL;
// Do a lookup in the compilation cache; if the entry is not there, // Do a lookup in the compilation cache; if the entry is not there,
// invoke the compiler and add the result to the cache. // invoke the compiler and add the result to the cache.
Handle<JSFunction> result = Handle<JSFunction> result =
CompilationCache::LookupEval(source, context, entry); CompilationCache::LookupEval(source, context, is_global);
if (result.is_null()) { if (result.is_null()) {
// Create a script object describing the script to be compiled. // Create a script object describing the script to be compiled.
Handle<Script> script = Factory::NewScript(source); Handle<Script> script = Factory::NewScript(source);
...@@ -314,7 +311,7 @@ Handle<JSFunction> Compiler::CompileEval(Handle<String> source, ...@@ -314,7 +311,7 @@ Handle<JSFunction> Compiler::CompileEval(Handle<String> source,
NULL, NULL,
NULL); NULL);
if (!result.is_null()) { if (!result.is_null()) {
CompilationCache::PutEval(source, context, entry, result); CompilationCache::PutEval(source, context, is_global, result);
} }
} }
......
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