Index: src/compilation-cache.h |
=================================================================== |
--- src/compilation-cache.h (revision 2226) |
+++ src/compilation-cache.h (working copy) |
@@ -34,20 +34,9 @@ |
// The compilation cache keeps function boilerplates for compiled |
// 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 { |
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 |
// string. Returns an empty handle if the cache doesn't contain a |
// script for the given source string with the right origin. |
@@ -61,7 +50,7 @@ |
// contain a script for the given source string. |
static Handle<JSFunction> LookupEval(Handle<String> source, |
Handle<Context> context, |
- Entry entry); |
+ bool is_global); |
// Returns the regexp data associated with the given regexp if it |
// is in cache, otherwise an empty handle. |
@@ -77,7 +66,7 @@ |
// with the boilerplate. This may overwrite an existing mapping. |
static void PutEval(Handle<String> source, |
Handle<Context> context, |
- Entry entry, |
+ bool is_global, |
Handle<JSFunction> boilerplate); |
// Associate the (source, flags) pair to the given regexp data. |
@@ -104,6 +93,99 @@ |
}; |
+// 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 |
+// for each generation of the sub-cache. As the same source code string has |
+// different compiled code for scripts and evals. Internally, we use separate |
+// sub-caches to avoid getting the wrong kind of entry when looking up. |
+class CompilationSubCache { |
+ public: |
+ explicit CompilationSubCache(int generations): generations_(generations) { |
+ // tables_ = new Object*[generations]; |
+ tables_ = NewArray<Object*>(generations); |
+ } |
+ virtual ~CompilationSubCache() { |
+ DeleteArray(tables_); |
+ } |
+ |
+ // Get the compilation cache tables for a specific generation. |
+ Handle<CompilationCacheTable> GetTable(int generation); |
+ |
+ // Age the sub-cache by evicting the oldest generation and creating a new |
+ // young generation. |
+ void Age(); |
+ |
+ // GC support. |
+ void Iterate(ObjectVisitor* v); |
+ |
+ // Clear this sub-cache evicting all its content. |
+ void Clear(); |
+ |
+ // Number of generations in this sub-cache. |
+ inline int generations() { return generations_; } |
+ |
+ private: |
+ int generations_; // Number of generations. |
+ Object** tables_; // Compilation cache tables - one for each generation. |
+ |
+ DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationSubCache); |
+}; |
+ |
+ |
+// Sub-cache for scripts. |
+class CompilationCacheScript: public CompilationSubCache { |
+ public: |
+ explicit CompilationCacheScript(int generations) |
+ : CompilationSubCache(generations) { } |
+ |
+ Handle<JSFunction> Lookup(Handle<String> source, |
+ Handle<Object> name, |
+ int line_offset, |
+ int column_offset); |
+ void Put(Handle<String> source, Handle<JSFunction> boilerplate); |
+ |
+ private: |
+ bool HasOrigin(Handle<JSFunction> boilerplate, |
+ Handle<Object> name, |
+ int line_offset, |
+ int column_offset); |
+ |
+ DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheScript); |
+}; |
+ |
+ |
+// Sub-cache for eval scripts. |
+class CompilationCacheEval: public CompilationSubCache { |
+ public: |
+ explicit CompilationCacheEval(int generations) |
+ : CompilationSubCache(generations) { } |
+ |
+ Handle<JSFunction> Lookup(Handle<String> source, Handle<Context> context); |
+ |
+ void Put(Handle<String> source, |
+ Handle<Context> context, |
+ Handle<JSFunction> boilerplate); |
+ |
+ DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheEval); |
+}; |
+ |
+ |
+// Sub-cache for regular expressions. |
+class CompilationCacheRegExp: public CompilationSubCache { |
+ public: |
+ explicit CompilationCacheRegExp(int generations) |
+ : CompilationSubCache(generations) { } |
+ |
+ Handle<FixedArray> Lookup(Handle<String> source, JSRegExp::Flags flags); |
+ |
+ void Put(Handle<String> source, |
+ JSRegExp::Flags flags, |
+ Handle<FixedArray> data); |
+ |
+ DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheRegExp); |
+}; |
+ |
+ |
} } // namespace v8::internal |
#endif // V8_COMPILATION_CACHE_H_ |