kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1 | // Copyright 2008 the V8 project authors. All rights reserved. |
| 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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. |
| 27 | |
| 28 | #include "v8.h" |
| 29 | |
| 30 | #include "compilation-cache.h" |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 31 | #include "serialize.h" |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 32 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 33 | namespace v8 { |
| 34 | namespace internal { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 35 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 36 | // The number of sub caches covering the different types to cache. |
| 37 | static const int kSubCacheCount = 4; |
| 38 | |
| 39 | // The number of generations for each sub cache. |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 40 | // The number of ScriptGenerations is carefully chosen based on histograms. |
| 41 | // See issue 458: http://code.google.com/p/v8/issues/detail?id=458 |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 42 | static const int kScriptGenerations = 5; |
| 43 | static const int kEvalGlobalGenerations = 2; |
| 44 | static const int kEvalContextualGenerations = 2; |
| 45 | static const int kRegExpGenerations = 2; |
| 46 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 47 | // Initial size of each compilation cache table allocated. |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 48 | static const int kInitialCacheSize = 64; |
| 49 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 50 | // Index for the first generation in the cache. |
| 51 | static const int kFirstGeneration = 0; |
| 52 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 53 | // The compilation cache consists of several generational sub-caches which uses |
| 54 | // this class as a base class. A sub-cache contains a compilation cache tables |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 55 | // for each generation of the sub-cache. Since the same source code string has |
| 56 | // different compiled code for scripts and evals, we use separate sub-caches |
| 57 | // for different compilation modes, to avoid retrieving the wrong result. |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 58 | class CompilationSubCache { |
| 59 | public: |
| 60 | explicit CompilationSubCache(int generations): generations_(generations) { |
| 61 | tables_ = NewArray<Object*>(generations); |
| 62 | } |
| 63 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 64 | ~CompilationSubCache() { DeleteArray(tables_); } |
| 65 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 66 | // Get the compilation cache tables for a specific generation. |
| 67 | Handle<CompilationCacheTable> GetTable(int generation); |
| 68 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 69 | // Accessors for first generation. |
| 70 | Handle<CompilationCacheTable> GetFirstTable() { |
| 71 | return GetTable(kFirstGeneration); |
| 72 | } |
| 73 | void SetFirstTable(Handle<CompilationCacheTable> value) { |
| 74 | ASSERT(kFirstGeneration < generations_); |
| 75 | tables_[kFirstGeneration] = *value; |
| 76 | } |
| 77 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 78 | // Age the sub-cache by evicting the oldest generation and creating a new |
| 79 | // young generation. |
| 80 | void Age(); |
| 81 | |
| 82 | // GC support. |
| 83 | void Iterate(ObjectVisitor* v); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 84 | void IterateFunctions(ObjectVisitor* v); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 85 | |
| 86 | // Clear this sub-cache evicting all its content. |
| 87 | void Clear(); |
| 88 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 89 | // Remove given shared function info from sub-cache. |
| 90 | void Remove(Handle<SharedFunctionInfo> function_info); |
| 91 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 92 | // Number of generations in this sub-cache. |
| 93 | inline int generations() { return generations_; } |
| 94 | |
| 95 | private: |
| 96 | int generations_; // Number of generations. |
| 97 | Object** tables_; // Compilation cache tables - one for each generation. |
| 98 | |
| 99 | DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationSubCache); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 103 | // Sub-cache for scripts. |
| 104 | class CompilationCacheScript : public CompilationSubCache { |
| 105 | public: |
| 106 | explicit CompilationCacheScript(int generations) |
| 107 | : CompilationSubCache(generations) { } |
| 108 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 109 | Handle<SharedFunctionInfo> Lookup(Handle<String> source, |
| 110 | Handle<Object> name, |
| 111 | int line_offset, |
| 112 | int column_offset); |
| 113 | void Put(Handle<String> source, Handle<SharedFunctionInfo> function_info); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 114 | |
| 115 | private: |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 116 | MUST_USE_RESULT MaybeObject* TryTablePut( |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 117 | Handle<String> source, Handle<SharedFunctionInfo> function_info); |
| 118 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 119 | // Note: Returns a new hash table if operation results in expansion. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 120 | Handle<CompilationCacheTable> TablePut( |
| 121 | Handle<String> source, Handle<SharedFunctionInfo> function_info); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 122 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 123 | bool HasOrigin(Handle<SharedFunctionInfo> function_info, |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 124 | Handle<Object> name, |
| 125 | int line_offset, |
| 126 | int column_offset); |
| 127 | |
| 128 | DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheScript); |
| 129 | }; |
| 130 | |
| 131 | |
| 132 | // Sub-cache for eval scripts. |
| 133 | class CompilationCacheEval: public CompilationSubCache { |
| 134 | public: |
| 135 | explicit CompilationCacheEval(int generations) |
| 136 | : CompilationSubCache(generations) { } |
| 137 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 138 | Handle<SharedFunctionInfo> Lookup(Handle<String> source, |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 139 | Handle<Context> context, |
| 140 | StrictModeFlag strict_mode); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 141 | |
| 142 | void Put(Handle<String> source, |
| 143 | Handle<Context> context, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 144 | Handle<SharedFunctionInfo> function_info); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 145 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 146 | private: |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 147 | MUST_USE_RESULT MaybeObject* TryTablePut( |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 148 | Handle<String> source, |
| 149 | Handle<Context> context, |
| 150 | Handle<SharedFunctionInfo> function_info); |
| 151 | |
| 152 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 153 | // Note: Returns a new hash table if operation results in expansion. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 154 | Handle<CompilationCacheTable> TablePut( |
| 155 | Handle<String> source, |
| 156 | Handle<Context> context, |
| 157 | Handle<SharedFunctionInfo> function_info); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 158 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 159 | DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheEval); |
| 160 | }; |
| 161 | |
| 162 | |
| 163 | // Sub-cache for regular expressions. |
| 164 | class CompilationCacheRegExp: public CompilationSubCache { |
| 165 | public: |
| 166 | explicit CompilationCacheRegExp(int generations) |
| 167 | : CompilationSubCache(generations) { } |
| 168 | |
| 169 | Handle<FixedArray> Lookup(Handle<String> source, JSRegExp::Flags flags); |
| 170 | |
| 171 | void Put(Handle<String> source, |
| 172 | JSRegExp::Flags flags, |
| 173 | Handle<FixedArray> data); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 174 | private: |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 175 | MUST_USE_RESULT MaybeObject* TryTablePut(Handle<String> source, |
| 176 | JSRegExp::Flags flags, |
| 177 | Handle<FixedArray> data); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 178 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 179 | // Note: Returns a new hash table if operation results in expansion. |
| 180 | Handle<CompilationCacheTable> TablePut(Handle<String> source, |
| 181 | JSRegExp::Flags flags, |
| 182 | Handle<FixedArray> data); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 183 | |
| 184 | DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheRegExp); |
| 185 | }; |
| 186 | |
| 187 | |
| 188 | // Statically allocate all the sub-caches. |
| 189 | static CompilationCacheScript script(kScriptGenerations); |
| 190 | static CompilationCacheEval eval_global(kEvalGlobalGenerations); |
| 191 | static CompilationCacheEval eval_contextual(kEvalContextualGenerations); |
| 192 | static CompilationCacheRegExp reg_exp(kRegExpGenerations); |
| 193 | static CompilationSubCache* subcaches[kSubCacheCount] = |
| 194 | {&script, &eval_global, &eval_contextual, ®_exp}; |
| 195 | |
| 196 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 197 | // Current enable state of the compilation cache. |
| 198 | static bool enabled = true; |
| 199 | static inline bool IsEnabled() { |
| 200 | return FLAG_compilation_cache && enabled; |
| 201 | } |
| 202 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 203 | |
| 204 | static Handle<CompilationCacheTable> AllocateTable(int size) { |
| 205 | CALL_HEAP_FUNCTION(CompilationCacheTable::Allocate(size), |
| 206 | CompilationCacheTable); |
| 207 | } |
| 208 | |
| 209 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 210 | Handle<CompilationCacheTable> CompilationSubCache::GetTable(int generation) { |
| 211 | ASSERT(generation < generations_); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 212 | Handle<CompilationCacheTable> result; |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 213 | if (tables_[generation]->IsUndefined()) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 214 | result = AllocateTable(kInitialCacheSize); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 215 | tables_[generation] = *result; |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 216 | } else { |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 217 | CompilationCacheTable* table = |
| 218 | CompilationCacheTable::cast(tables_[generation]); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 219 | result = Handle<CompilationCacheTable>(table); |
| 220 | } |
| 221 | return result; |
| 222 | } |
| 223 | |
| 224 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 225 | void CompilationSubCache::Age() { |
| 226 | // Age the generations implicitly killing off the oldest. |
| 227 | for (int i = generations_ - 1; i > 0; i--) { |
| 228 | tables_[i] = tables_[i - 1]; |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 229 | } |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 230 | |
| 231 | // Set the first generation as unborn. |
| 232 | tables_[0] = Heap::undefined_value(); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 236 | void CompilationSubCache::IterateFunctions(ObjectVisitor* v) { |
| 237 | Object* undefined = Heap::raw_unchecked_undefined_value(); |
| 238 | for (int i = 0; i < generations_; i++) { |
| 239 | if (tables_[i] != undefined) { |
| 240 | reinterpret_cast<CompilationCacheTable*>(tables_[i])->IterateElements(v); |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 246 | void CompilationSubCache::Iterate(ObjectVisitor* v) { |
| 247 | v->VisitPointers(&tables_[0], &tables_[generations_]); |
| 248 | } |
| 249 | |
| 250 | |
| 251 | void CompilationSubCache::Clear() { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 252 | MemsetPointer(tables_, Heap::undefined_value(), generations_); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 256 | void CompilationSubCache::Remove(Handle<SharedFunctionInfo> function_info) { |
| 257 | // Probe the script generation tables. Make sure not to leak handles |
| 258 | // into the caller's handle scope. |
| 259 | { HandleScope scope; |
| 260 | for (int generation = 0; generation < generations(); generation++) { |
| 261 | Handle<CompilationCacheTable> table = GetTable(generation); |
| 262 | table->Remove(*function_info); |
| 263 | } |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 268 | // We only re-use a cached function for some script source code if the |
| 269 | // script originates from the same place. This is to avoid issues |
| 270 | // when reporting errors, etc. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 271 | bool CompilationCacheScript::HasOrigin( |
| 272 | Handle<SharedFunctionInfo> function_info, |
| 273 | Handle<Object> name, |
| 274 | int line_offset, |
| 275 | int column_offset) { |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 276 | Handle<Script> script = |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 277 | Handle<Script>(Script::cast(function_info->script())); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 278 | // If the script name isn't set, the boilerplate script should have |
| 279 | // an undefined name to have the same origin. |
| 280 | if (name.is_null()) { |
| 281 | return script->name()->IsUndefined(); |
| 282 | } |
| 283 | // Do the fast bailout checks first. |
| 284 | if (line_offset != script->line_offset()->value()) return false; |
| 285 | if (column_offset != script->column_offset()->value()) return false; |
| 286 | // Check that both names are strings. If not, no match. |
| 287 | if (!name->IsString() || !script->name()->IsString()) return false; |
| 288 | // Compare the two name strings for equality. |
| 289 | return String::cast(*name)->Equals(String::cast(script->name())); |
| 290 | } |
| 291 | |
| 292 | |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 293 | // TODO(245): Need to allow identical code from different contexts to |
| 294 | // be cached in the same script generation. Currently the first use |
| 295 | // will be cached, but subsequent code from different source / line |
| 296 | // won't. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 297 | Handle<SharedFunctionInfo> CompilationCacheScript::Lookup(Handle<String> source, |
| 298 | Handle<Object> name, |
| 299 | int line_offset, |
| 300 | int column_offset) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 301 | Object* result = NULL; |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 302 | int generation; |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 303 | |
| 304 | // Probe the script generation tables. Make sure not to leak handles |
| 305 | // into the caller's handle scope. |
| 306 | { HandleScope scope; |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 307 | for (generation = 0; generation < generations(); generation++) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 308 | Handle<CompilationCacheTable> table = GetTable(generation); |
| 309 | Handle<Object> probe(table->Lookup(*source)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 310 | if (probe->IsSharedFunctionInfo()) { |
| 311 | Handle<SharedFunctionInfo> function_info = |
| 312 | Handle<SharedFunctionInfo>::cast(probe); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 313 | // Break when we've found a suitable shared function info that |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 314 | // matches the origin. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 315 | if (HasOrigin(function_info, name, line_offset, column_offset)) { |
| 316 | result = *function_info; |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 317 | break; |
| 318 | } |
| 319 | } |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 320 | } |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 321 | } |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 322 | |
kasperl@chromium.org | 31ca888 | 2009-05-26 09:36:02 +0000 | [diff] [blame] | 323 | static void* script_histogram = StatsTable::CreateHistogram( |
| 324 | "V8.ScriptCache", |
| 325 | 0, |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 326 | kScriptGenerations, |
| 327 | kScriptGenerations + 1); |
kasperl@chromium.org | 31ca888 | 2009-05-26 09:36:02 +0000 | [diff] [blame] | 328 | |
| 329 | if (script_histogram != NULL) { |
| 330 | // The level NUMBER_OF_SCRIPT_GENERATIONS is equivalent to a cache miss. |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 331 | StatsTable::AddHistogramSample(script_histogram, generation); |
kasperl@chromium.org | 31ca888 | 2009-05-26 09:36:02 +0000 | [diff] [blame] | 332 | } |
| 333 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 334 | // Once outside the manacles of the handle scope, we need to recheck |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 335 | // to see if we actually found a cached script. If so, we return a |
| 336 | // handle created in the caller's handle scope. |
| 337 | if (result != NULL) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 338 | Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result)); |
| 339 | ASSERT(HasOrigin(shared, name, line_offset, column_offset)); |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 340 | // If the script was found in a later generation, we promote it to |
| 341 | // the first generation to let it survive longer in the cache. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 342 | if (generation != 0) Put(source, shared); |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 343 | Counters::compilation_cache_hits.Increment(); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 344 | return shared; |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 345 | } else { |
| 346 | Counters::compilation_cache_misses.Increment(); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 347 | return Handle<SharedFunctionInfo>::null(); |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 348 | } |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 352 | MaybeObject* CompilationCacheScript::TryTablePut( |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 353 | Handle<String> source, |
| 354 | Handle<SharedFunctionInfo> function_info) { |
| 355 | Handle<CompilationCacheTable> table = GetFirstTable(); |
| 356 | return table->Put(*source, *function_info); |
| 357 | } |
| 358 | |
| 359 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 360 | Handle<CompilationCacheTable> CompilationCacheScript::TablePut( |
| 361 | Handle<String> source, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 362 | Handle<SharedFunctionInfo> function_info) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 363 | CALL_HEAP_FUNCTION(TryTablePut(source, function_info), CompilationCacheTable); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 367 | void CompilationCacheScript::Put(Handle<String> source, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 368 | Handle<SharedFunctionInfo> function_info) { |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 369 | HandleScope scope; |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 370 | SetFirstTable(TablePut(source, function_info)); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 374 | Handle<SharedFunctionInfo> CompilationCacheEval::Lookup( |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 375 | Handle<String> source, |
| 376 | Handle<Context> context, |
| 377 | StrictModeFlag strict_mode) { |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 378 | // Make sure not to leak the table into the surrounding handle |
| 379 | // scope. Otherwise, we risk keeping old tables around even after |
| 380 | // having cleared the cache. |
| 381 | Object* result = NULL; |
| 382 | int generation; |
| 383 | { HandleScope scope; |
| 384 | for (generation = 0; generation < generations(); generation++) { |
| 385 | Handle<CompilationCacheTable> table = GetTable(generation); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 386 | result = table->LookupEval(*source, *context, strict_mode); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 387 | if (result->IsSharedFunctionInfo()) { |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 388 | break; |
| 389 | } |
| 390 | } |
| 391 | } |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 392 | if (result->IsSharedFunctionInfo()) { |
| 393 | Handle<SharedFunctionInfo> |
| 394 | function_info(SharedFunctionInfo::cast(result)); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 395 | if (generation != 0) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 396 | Put(source, context, function_info); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 397 | } |
| 398 | Counters::compilation_cache_hits.Increment(); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 399 | return function_info; |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 400 | } else { |
| 401 | Counters::compilation_cache_misses.Increment(); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 402 | return Handle<SharedFunctionInfo>::null(); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 403 | } |
| 404 | } |
| 405 | |
| 406 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 407 | MaybeObject* CompilationCacheEval::TryTablePut( |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 408 | Handle<String> source, |
| 409 | Handle<Context> context, |
| 410 | Handle<SharedFunctionInfo> function_info) { |
| 411 | Handle<CompilationCacheTable> table = GetFirstTable(); |
| 412 | return table->PutEval(*source, *context, *function_info); |
| 413 | } |
| 414 | |
| 415 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 416 | Handle<CompilationCacheTable> CompilationCacheEval::TablePut( |
| 417 | Handle<String> source, |
| 418 | Handle<Context> context, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 419 | Handle<SharedFunctionInfo> function_info) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 420 | CALL_HEAP_FUNCTION(TryTablePut(source, context, function_info), |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 421 | CompilationCacheTable); |
| 422 | } |
| 423 | |
| 424 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 425 | void CompilationCacheEval::Put(Handle<String> source, |
| 426 | Handle<Context> context, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 427 | Handle<SharedFunctionInfo> function_info) { |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 428 | HandleScope scope; |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 429 | SetFirstTable(TablePut(source, context, function_info)); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | |
| 433 | Handle<FixedArray> CompilationCacheRegExp::Lookup(Handle<String> source, |
| 434 | JSRegExp::Flags flags) { |
| 435 | // Make sure not to leak the table into the surrounding handle |
| 436 | // scope. Otherwise, we risk keeping old tables around even after |
| 437 | // having cleared the cache. |
| 438 | Object* result = NULL; |
| 439 | int generation; |
| 440 | { HandleScope scope; |
| 441 | for (generation = 0; generation < generations(); generation++) { |
| 442 | Handle<CompilationCacheTable> table = GetTable(generation); |
| 443 | result = table->LookupRegExp(*source, flags); |
| 444 | if (result->IsFixedArray()) { |
| 445 | break; |
| 446 | } |
| 447 | } |
| 448 | } |
| 449 | if (result->IsFixedArray()) { |
| 450 | Handle<FixedArray> data(FixedArray::cast(result)); |
| 451 | if (generation != 0) { |
| 452 | Put(source, flags, data); |
| 453 | } |
| 454 | Counters::compilation_cache_hits.Increment(); |
| 455 | return data; |
| 456 | } else { |
| 457 | Counters::compilation_cache_misses.Increment(); |
| 458 | return Handle<FixedArray>::null(); |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 463 | MaybeObject* CompilationCacheRegExp::TryTablePut( |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 464 | Handle<String> source, |
| 465 | JSRegExp::Flags flags, |
| 466 | Handle<FixedArray> data) { |
| 467 | Handle<CompilationCacheTable> table = GetFirstTable(); |
| 468 | return table->PutRegExp(*source, flags, *data); |
| 469 | } |
| 470 | |
| 471 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 472 | Handle<CompilationCacheTable> CompilationCacheRegExp::TablePut( |
| 473 | Handle<String> source, |
| 474 | JSRegExp::Flags flags, |
| 475 | Handle<FixedArray> data) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 476 | CALL_HEAP_FUNCTION(TryTablePut(source, flags, data), CompilationCacheTable); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 480 | void CompilationCacheRegExp::Put(Handle<String> source, |
| 481 | JSRegExp::Flags flags, |
| 482 | Handle<FixedArray> data) { |
| 483 | HandleScope scope; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 484 | SetFirstTable(TablePut(source, flags, data)); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 488 | void CompilationCache::Remove(Handle<SharedFunctionInfo> function_info) { |
| 489 | if (!IsEnabled()) return; |
| 490 | |
| 491 | eval_global.Remove(function_info); |
| 492 | eval_contextual.Remove(function_info); |
| 493 | script.Remove(function_info); |
| 494 | } |
| 495 | |
| 496 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 497 | Handle<SharedFunctionInfo> CompilationCache::LookupScript(Handle<String> source, |
| 498 | Handle<Object> name, |
| 499 | int line_offset, |
| 500 | int column_offset) { |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 501 | if (!IsEnabled()) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 502 | return Handle<SharedFunctionInfo>::null(); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 503 | } |
| 504 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 505 | return script.Lookup(source, name, line_offset, column_offset); |
| 506 | } |
| 507 | |
| 508 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 509 | Handle<SharedFunctionInfo> CompilationCache::LookupEval( |
| 510 | Handle<String> source, |
| 511 | Handle<Context> context, |
| 512 | bool is_global, |
| 513 | StrictModeFlag strict_mode) { |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 514 | if (!IsEnabled()) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 515 | return Handle<SharedFunctionInfo>::null(); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 516 | } |
| 517 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 518 | Handle<SharedFunctionInfo> result; |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 519 | if (is_global) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 520 | result = eval_global.Lookup(source, context, strict_mode); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 521 | } else { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 522 | result = eval_contextual.Lookup(source, context, strict_mode); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 523 | } |
| 524 | return result; |
| 525 | } |
| 526 | |
| 527 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 528 | Handle<FixedArray> CompilationCache::LookupRegExp(Handle<String> source, |
| 529 | JSRegExp::Flags flags) { |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 530 | if (!IsEnabled()) { |
| 531 | return Handle<FixedArray>::null(); |
| 532 | } |
| 533 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 534 | return reg_exp.Lookup(source, flags); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 538 | void CompilationCache::PutScript(Handle<String> source, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 539 | Handle<SharedFunctionInfo> function_info) { |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 540 | if (!IsEnabled()) { |
| 541 | return; |
| 542 | } |
| 543 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 544 | script.Put(source, function_info); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | |
| 548 | void CompilationCache::PutEval(Handle<String> source, |
| 549 | Handle<Context> context, |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 550 | bool is_global, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 551 | Handle<SharedFunctionInfo> function_info) { |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 552 | if (!IsEnabled()) { |
| 553 | return; |
| 554 | } |
| 555 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 556 | HandleScope scope; |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 557 | if (is_global) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 558 | eval_global.Put(source, context, function_info); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 559 | } else { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 560 | eval_contextual.Put(source, context, function_info); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 561 | } |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 565 | |
| 566 | void CompilationCache::PutRegExp(Handle<String> source, |
| 567 | JSRegExp::Flags flags, |
| 568 | Handle<FixedArray> data) { |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 569 | if (!IsEnabled()) { |
| 570 | return; |
| 571 | } |
| 572 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 573 | reg_exp.Put(source, flags, data); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 577 | static bool SourceHashCompare(void* key1, void* key2) { |
| 578 | return key1 == key2; |
| 579 | } |
| 580 | |
| 581 | |
| 582 | static HashMap* EagerOptimizingSet() { |
| 583 | static HashMap map(&SourceHashCompare); |
| 584 | return ↦ |
| 585 | } |
| 586 | |
| 587 | |
| 588 | bool CompilationCache::ShouldOptimizeEagerly(Handle<JSFunction> function) { |
| 589 | if (FLAG_opt_eagerly) return true; |
| 590 | uint32_t hash = function->SourceHash(); |
| 591 | void* key = reinterpret_cast<void*>(hash); |
| 592 | return EagerOptimizingSet()->Lookup(key, hash, false) != NULL; |
| 593 | } |
| 594 | |
| 595 | |
| 596 | void CompilationCache::MarkForEagerOptimizing(Handle<JSFunction> function) { |
| 597 | uint32_t hash = function->SourceHash(); |
| 598 | void* key = reinterpret_cast<void*>(hash); |
| 599 | EagerOptimizingSet()->Lookup(key, hash, true); |
| 600 | } |
| 601 | |
| 602 | |
| 603 | void CompilationCache::MarkForLazyOptimizing(Handle<JSFunction> function) { |
| 604 | uint32_t hash = function->SourceHash(); |
| 605 | void* key = reinterpret_cast<void*>(hash); |
| 606 | EagerOptimizingSet()->Remove(key, hash); |
| 607 | } |
| 608 | |
| 609 | |
| 610 | void CompilationCache::ResetEagerOptimizingData() { |
| 611 | HashMap* set = EagerOptimizingSet(); |
| 612 | if (set->occupancy() > 0) set->Clear(); |
| 613 | } |
| 614 | |
| 615 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 616 | void CompilationCache::Clear() { |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 617 | for (int i = 0; i < kSubCacheCount; i++) { |
| 618 | subcaches[i]->Clear(); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 619 | } |
| 620 | } |
| 621 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 622 | void CompilationCache::Iterate(ObjectVisitor* v) { |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 623 | for (int i = 0; i < kSubCacheCount; i++) { |
| 624 | subcaches[i]->Iterate(v); |
| 625 | } |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 629 | void CompilationCache::IterateFunctions(ObjectVisitor* v) { |
| 630 | for (int i = 0; i < kSubCacheCount; i++) { |
| 631 | subcaches[i]->IterateFunctions(v); |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 636 | void CompilationCache::MarkCompactPrologue() { |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 637 | for (int i = 0; i < kSubCacheCount; i++) { |
| 638 | subcaches[i]->Age(); |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 639 | } |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 643 | void CompilationCache::Enable() { |
| 644 | enabled = true; |
| 645 | } |
| 646 | |
| 647 | |
| 648 | void CompilationCache::Disable() { |
| 649 | enabled = false; |
| 650 | Clear(); |
| 651 | } |
| 652 | |
| 653 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 654 | } } // namespace v8::internal |