| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #ifndef V8_COMPILATION_CACHE_H_ | 28 #ifndef V8_COMPILATION_CACHE_H_ |
| 29 #define V8_COMPILATION_CACHE_H_ | 29 #define V8_COMPILATION_CACHE_H_ |
| 30 | 30 |
| 31 namespace v8 { | 31 namespace v8 { |
| 32 namespace internal { | 32 namespace internal { |
| 33 | 33 |
| 34 class HashMap; |
| 34 | 35 |
| 35 // The compilation cache consists of several generational sub-caches which uses | 36 // The compilation cache consists of several generational sub-caches which uses |
| 36 // this class as a base class. A sub-cache contains a compilation cache tables | 37 // this class as a base class. A sub-cache contains a compilation cache tables |
| 37 // for each generation of the sub-cache. Since the same source code string has | 38 // for each generation of the sub-cache. Since the same source code string has |
| 38 // different compiled code for scripts and evals, we use separate sub-caches | 39 // different compiled code for scripts and evals, we use separate sub-caches |
| 39 // for different compilation modes, to avoid retrieving the wrong result. | 40 // for different compilation modes, to avoid retrieving the wrong result. |
| 40 class CompilationSubCache { | 41 class CompilationSubCache { |
| 41 public: | 42 public: |
| 42 explicit CompilationSubCache(int generations): generations_(generations) { | 43 explicit CompilationSubCache(int generations): generations_(generations) { |
| 43 tables_ = NewArray<Object*>(generations); | 44 tables_ = NewArray<Object*>(generations); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 64 // young generation. | 65 // young generation. |
| 65 void Age(); | 66 void Age(); |
| 66 | 67 |
| 67 // GC support. | 68 // GC support. |
| 68 void Iterate(ObjectVisitor* v); | 69 void Iterate(ObjectVisitor* v); |
| 69 void IterateFunctions(ObjectVisitor* v); | 70 void IterateFunctions(ObjectVisitor* v); |
| 70 | 71 |
| 71 // Clear this sub-cache evicting all its content. | 72 // Clear this sub-cache evicting all its content. |
| 72 void Clear(); | 73 void Clear(); |
| 73 | 74 |
| 75 // Remove given shared function info from sub-cache. |
| 76 void Remove(Handle<SharedFunctionInfo> function_info); |
| 77 |
| 74 // Number of generations in this sub-cache. | 78 // Number of generations in this sub-cache. |
| 75 inline int generations() { return generations_; } | 79 inline int generations() { return generations_; } |
| 76 | 80 |
| 77 private: | 81 private: |
| 78 int generations_; // Number of generations. | 82 int generations_; // Number of generations. |
| 79 Object** tables_; // Compilation cache tables - one for each generation. | 83 Object** tables_; // Compilation cache tables - one for each generation. |
| 80 | 84 |
| 81 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationSubCache); | 85 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationSubCache); |
| 82 }; | 86 }; |
| 83 | 87 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 Handle<Context> context, | 208 Handle<Context> context, |
| 205 bool is_global, | 209 bool is_global, |
| 206 Handle<SharedFunctionInfo> function_info); | 210 Handle<SharedFunctionInfo> function_info); |
| 207 | 211 |
| 208 // Associate the (source, flags) pair to the given regexp data. | 212 // Associate the (source, flags) pair to the given regexp data. |
| 209 // This may overwrite an existing mapping. | 213 // This may overwrite an existing mapping. |
| 210 void PutRegExp(Handle<String> source, | 214 void PutRegExp(Handle<String> source, |
| 211 JSRegExp::Flags flags, | 215 JSRegExp::Flags flags, |
| 212 Handle<FixedArray> data); | 216 Handle<FixedArray> data); |
| 213 | 217 |
| 218 // Support for eager optimization tracking. |
| 219 bool ShouldOptimizeEagerly(Handle<JSFunction> function); |
| 220 void MarkForEagerOptimizing(Handle<JSFunction> function); |
| 221 void MarkForLazyOptimizing(Handle<JSFunction> function); |
| 222 |
| 223 // Reset the eager optimization tracking data. |
| 224 void ResetEagerOptimizingData(); |
| 225 |
| 214 // Clear the cache - also used to initialize the cache at startup. | 226 // Clear the cache - also used to initialize the cache at startup. |
| 215 void Clear(); | 227 void Clear(); |
| 216 | 228 |
| 229 // Remove given shared function info from all caches. |
| 230 void Remove(Handle<SharedFunctionInfo> function_info); |
| 231 |
| 217 // GC support. | 232 // GC support. |
| 218 void Iterate(ObjectVisitor* v); | 233 void Iterate(ObjectVisitor* v); |
| 219 void IterateFunctions(ObjectVisitor* v); | 234 void IterateFunctions(ObjectVisitor* v); |
| 220 | 235 |
| 221 // Notify the cache that a mark-sweep garbage collection is about to | 236 // Notify the cache that a mark-sweep garbage collection is about to |
| 222 // take place. This is used to retire entries from the cache to | 237 // take place. This is used to retire entries from the cache to |
| 223 // avoid keeping them alive too long without using them. | 238 // avoid keeping them alive too long without using them. |
| 224 void MarkCompactPrologue(); | 239 void MarkCompactPrologue(); |
| 225 | 240 |
| 226 // Enable/disable compilation cache. Used by debugger to disable compilation | 241 // Enable/disable compilation cache. Used by debugger to disable compilation |
| 227 // cache during debugging to make sure new scripts are always compiled. | 242 // cache during debugging to make sure new scripts are always compiled. |
| 228 void Enable(); | 243 void Enable(); |
| 229 void Disable(); | 244 void Disable(); |
| 230 private: | 245 private: |
| 231 CompilationCache(); | 246 CompilationCache(); |
| 247 ~CompilationCache(); |
| 248 |
| 249 HashMap* EagerOptimizingSet(); |
| 232 | 250 |
| 233 // The number of sub caches covering the different types to cache. | 251 // The number of sub caches covering the different types to cache. |
| 234 static const int kSubCacheCount = 4; | 252 static const int kSubCacheCount = 4; |
| 235 | 253 |
| 236 CompilationCacheScript script_; | 254 CompilationCacheScript script_; |
| 237 CompilationCacheEval eval_global_; | 255 CompilationCacheEval eval_global_; |
| 238 CompilationCacheEval eval_contextual_; | 256 CompilationCacheEval eval_contextual_; |
| 239 CompilationCacheRegExp reg_exp_; | 257 CompilationCacheRegExp reg_exp_; |
| 240 CompilationSubCache* subcaches_[kSubCacheCount]; | 258 CompilationSubCache* subcaches_[kSubCacheCount]; |
| 241 | 259 |
| 242 // Current enable state of the compilation cache. | 260 // Current enable state of the compilation cache. |
| 243 bool enabled_; | 261 bool enabled_; |
| 244 | 262 |
| 263 HashMap* eager_optimizing_set_; |
| 264 |
| 245 bool IsEnabled() { return FLAG_compilation_cache && enabled_; } | 265 bool IsEnabled() { return FLAG_compilation_cache && enabled_; } |
| 246 | 266 |
| 247 friend class Isolate; | 267 friend class Isolate; |
| 248 | 268 |
| 249 DISALLOW_COPY_AND_ASSIGN(CompilationCache); | 269 DISALLOW_COPY_AND_ASSIGN(CompilationCache); |
| 250 }; | 270 }; |
| 251 | 271 |
| 252 | 272 |
| 253 } } // namespace v8::internal | 273 } } // namespace v8::internal |
| 254 | 274 |
| 255 #endif // V8_COMPILATION_CACHE_H_ | 275 #endif // V8_COMPILATION_CACHE_H_ |
| OLD | NEW |