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 22 matching lines...) Expand all Loading... |
33 | 33 |
34 class HashMap; | 34 class HashMap; |
35 | 35 |
36 // The compilation cache consists of several generational sub-caches which uses | 36 // The compilation cache consists of several generational sub-caches which uses |
37 // 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 |
38 // 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 |
39 // 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 |
40 // for different compilation modes, to avoid retrieving the wrong result. | 40 // for different compilation modes, to avoid retrieving the wrong result. |
41 class CompilationSubCache { | 41 class CompilationSubCache { |
42 public: | 42 public: |
43 explicit CompilationSubCache(int generations): generations_(generations) { | 43 CompilationSubCache(Isolate* isolate, int generations) |
| 44 : isolate_(isolate), |
| 45 generations_(generations) { |
44 tables_ = NewArray<Object*>(generations); | 46 tables_ = NewArray<Object*>(generations); |
45 } | 47 } |
46 | 48 |
47 ~CompilationSubCache() { DeleteArray(tables_); } | 49 ~CompilationSubCache() { DeleteArray(tables_); } |
48 | 50 |
49 // Index for the first generation in the cache. | 51 // Index for the first generation in the cache. |
50 static const int kFirstGeneration = 0; | 52 static const int kFirstGeneration = 0; |
51 | 53 |
52 // Get the compilation cache tables for a specific generation. | 54 // Get the compilation cache tables for a specific generation. |
53 Handle<CompilationCacheTable> GetTable(int generation); | 55 Handle<CompilationCacheTable> GetTable(int generation); |
(...skipping 17 matching lines...) Expand all Loading... |
71 | 73 |
72 // Clear this sub-cache evicting all its content. | 74 // Clear this sub-cache evicting all its content. |
73 void Clear(); | 75 void Clear(); |
74 | 76 |
75 // Remove given shared function info from sub-cache. | 77 // Remove given shared function info from sub-cache. |
76 void Remove(Handle<SharedFunctionInfo> function_info); | 78 void Remove(Handle<SharedFunctionInfo> function_info); |
77 | 79 |
78 // Number of generations in this sub-cache. | 80 // Number of generations in this sub-cache. |
79 inline int generations() { return generations_; } | 81 inline int generations() { return generations_; } |
80 | 82 |
| 83 protected: |
| 84 Isolate* isolate() { return isolate_; } |
| 85 |
81 private: | 86 private: |
| 87 Isolate* isolate_; |
82 int generations_; // Number of generations. | 88 int generations_; // Number of generations. |
83 Object** tables_; // Compilation cache tables - one for each generation. | 89 Object** tables_; // Compilation cache tables - one for each generation. |
84 | 90 |
85 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationSubCache); | 91 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationSubCache); |
86 }; | 92 }; |
87 | 93 |
88 | 94 |
89 // Sub-cache for scripts. | 95 // Sub-cache for scripts. |
90 class CompilationCacheScript : public CompilationSubCache { | 96 class CompilationCacheScript : public CompilationSubCache { |
91 public: | 97 public: |
92 explicit CompilationCacheScript(int generations); | 98 CompilationCacheScript(Isolate* isolate, int generations); |
93 | 99 |
94 Handle<SharedFunctionInfo> Lookup(Handle<String> source, | 100 Handle<SharedFunctionInfo> Lookup(Handle<String> source, |
95 Handle<Object> name, | 101 Handle<Object> name, |
96 int line_offset, | 102 int line_offset, |
97 int column_offset); | 103 int column_offset); |
98 void Put(Handle<String> source, Handle<SharedFunctionInfo> function_info); | 104 void Put(Handle<String> source, Handle<SharedFunctionInfo> function_info); |
99 | 105 |
100 private: | 106 private: |
101 MUST_USE_RESULT MaybeObject* TryTablePut( | 107 MUST_USE_RESULT MaybeObject* TryTablePut( |
102 Handle<String> source, Handle<SharedFunctionInfo> function_info); | 108 Handle<String> source, Handle<SharedFunctionInfo> function_info); |
(...skipping 10 matching lines...) Expand all Loading... |
113 void* script_histogram_; | 119 void* script_histogram_; |
114 bool script_histogram_initialized_; | 120 bool script_histogram_initialized_; |
115 | 121 |
116 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheScript); | 122 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheScript); |
117 }; | 123 }; |
118 | 124 |
119 | 125 |
120 // Sub-cache for eval scripts. | 126 // Sub-cache for eval scripts. |
121 class CompilationCacheEval: public CompilationSubCache { | 127 class CompilationCacheEval: public CompilationSubCache { |
122 public: | 128 public: |
123 explicit CompilationCacheEval(int generations) | 129 CompilationCacheEval(Isolate* isolate, int generations) |
124 : CompilationSubCache(generations) { } | 130 : CompilationSubCache(isolate, generations) { } |
125 | 131 |
126 Handle<SharedFunctionInfo> Lookup(Handle<String> source, | 132 Handle<SharedFunctionInfo> Lookup(Handle<String> source, |
127 Handle<Context> context, | 133 Handle<Context> context, |
128 StrictModeFlag strict_mode); | 134 StrictModeFlag strict_mode); |
129 | 135 |
130 void Put(Handle<String> source, | 136 void Put(Handle<String> source, |
131 Handle<Context> context, | 137 Handle<Context> context, |
132 Handle<SharedFunctionInfo> function_info); | 138 Handle<SharedFunctionInfo> function_info); |
133 | 139 |
134 private: | 140 private: |
135 MUST_USE_RESULT MaybeObject* TryTablePut( | 141 MUST_USE_RESULT MaybeObject* TryTablePut( |
136 Handle<String> source, | 142 Handle<String> source, |
137 Handle<Context> context, | 143 Handle<Context> context, |
138 Handle<SharedFunctionInfo> function_info); | 144 Handle<SharedFunctionInfo> function_info); |
139 | 145 |
140 // Note: Returns a new hash table if operation results in expansion. | 146 // Note: Returns a new hash table if operation results in expansion. |
141 Handle<CompilationCacheTable> TablePut( | 147 Handle<CompilationCacheTable> TablePut( |
142 Handle<String> source, | 148 Handle<String> source, |
143 Handle<Context> context, | 149 Handle<Context> context, |
144 Handle<SharedFunctionInfo> function_info); | 150 Handle<SharedFunctionInfo> function_info); |
145 | 151 |
146 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheEval); | 152 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheEval); |
147 }; | 153 }; |
148 | 154 |
149 | 155 |
150 // Sub-cache for regular expressions. | 156 // Sub-cache for regular expressions. |
151 class CompilationCacheRegExp: public CompilationSubCache { | 157 class CompilationCacheRegExp: public CompilationSubCache { |
152 public: | 158 public: |
153 explicit CompilationCacheRegExp(int generations) | 159 CompilationCacheRegExp(Isolate* isolate, int generations) |
154 : CompilationSubCache(generations) { } | 160 : CompilationSubCache(isolate, generations) { } |
155 | 161 |
156 Handle<FixedArray> Lookup(Handle<String> source, JSRegExp::Flags flags); | 162 Handle<FixedArray> Lookup(Handle<String> source, JSRegExp::Flags flags); |
157 | 163 |
158 void Put(Handle<String> source, | 164 void Put(Handle<String> source, |
159 JSRegExp::Flags flags, | 165 JSRegExp::Flags flags, |
160 Handle<FixedArray> data); | 166 Handle<FixedArray> data); |
161 private: | 167 private: |
162 MUST_USE_RESULT MaybeObject* TryTablePut(Handle<String> source, | 168 MUST_USE_RESULT MaybeObject* TryTablePut(Handle<String> source, |
163 JSRegExp::Flags flags, | 169 JSRegExp::Flags flags, |
164 Handle<FixedArray> data); | 170 Handle<FixedArray> data); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 // Notify the cache that a mark-sweep garbage collection is about to | 244 // Notify the cache that a mark-sweep garbage collection is about to |
239 // take place. This is used to retire entries from the cache to | 245 // take place. This is used to retire entries from the cache to |
240 // avoid keeping them alive too long without using them. | 246 // avoid keeping them alive too long without using them. |
241 void MarkCompactPrologue(); | 247 void MarkCompactPrologue(); |
242 | 248 |
243 // Enable/disable compilation cache. Used by debugger to disable compilation | 249 // Enable/disable compilation cache. Used by debugger to disable compilation |
244 // cache during debugging to make sure new scripts are always compiled. | 250 // cache during debugging to make sure new scripts are always compiled. |
245 void Enable(); | 251 void Enable(); |
246 void Disable(); | 252 void Disable(); |
247 private: | 253 private: |
248 CompilationCache(); | 254 explicit CompilationCache(Isolate* isolate); |
249 ~CompilationCache(); | 255 ~CompilationCache(); |
250 | 256 |
251 HashMap* EagerOptimizingSet(); | 257 HashMap* EagerOptimizingSet(); |
252 | 258 |
253 // The number of sub caches covering the different types to cache. | 259 // The number of sub caches covering the different types to cache. |
254 static const int kSubCacheCount = 4; | 260 static const int kSubCacheCount = 4; |
255 | 261 |
| 262 bool IsEnabled() { return FLAG_compilation_cache && enabled_; } |
| 263 |
| 264 Isolate* isolate() { return isolate_; } |
| 265 |
| 266 Isolate* isolate_; |
| 267 |
256 CompilationCacheScript script_; | 268 CompilationCacheScript script_; |
257 CompilationCacheEval eval_global_; | 269 CompilationCacheEval eval_global_; |
258 CompilationCacheEval eval_contextual_; | 270 CompilationCacheEval eval_contextual_; |
259 CompilationCacheRegExp reg_exp_; | 271 CompilationCacheRegExp reg_exp_; |
260 CompilationSubCache* subcaches_[kSubCacheCount]; | 272 CompilationSubCache* subcaches_[kSubCacheCount]; |
261 | 273 |
262 // Current enable state of the compilation cache. | 274 // Current enable state of the compilation cache. |
263 bool enabled_; | 275 bool enabled_; |
264 | 276 |
265 HashMap* eager_optimizing_set_; | 277 HashMap* eager_optimizing_set_; |
266 | 278 |
267 bool IsEnabled() { return FLAG_compilation_cache && enabled_; } | |
268 | |
269 friend class Isolate; | 279 friend class Isolate; |
270 | 280 |
271 DISALLOW_COPY_AND_ASSIGN(CompilationCache); | 281 DISALLOW_COPY_AND_ASSIGN(CompilationCache); |
272 }; | 282 }; |
273 | 283 |
274 | 284 |
275 } } // namespace v8::internal | 285 } } // namespace v8::internal |
276 | 286 |
277 #endif // V8_COMPILATION_CACHE_H_ | 287 #endif // V8_COMPILATION_CACHE_H_ |
OLD | NEW |