| 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 void CompilationSubCache::Iterate(ObjectVisitor* v) { | 116 void CompilationSubCache::Iterate(ObjectVisitor* v) { |
| 117 v->VisitPointers(&tables_[0], &tables_[generations_]); | 117 v->VisitPointers(&tables_[0], &tables_[generations_]); |
| 118 } | 118 } |
| 119 | 119 |
| 120 | 120 |
| 121 void CompilationSubCache::Clear() { | 121 void CompilationSubCache::Clear() { |
| 122 MemsetPointer(tables_, HEAP->undefined_value(), generations_); | 122 MemsetPointer(tables_, HEAP->undefined_value(), generations_); |
| 123 } | 123 } |
| 124 | 124 |
| 125 | 125 |
| 126 CompilationCacheScript::CompilationCacheScript(int generations) |
| 127 : CompilationSubCache(generations), |
| 128 script_histogram_(NULL), |
| 129 script_histogram_initialized_(false) { |
| 130 } |
| 131 |
| 132 |
| 126 // We only re-use a cached function for some script source code if the | 133 // We only re-use a cached function for some script source code if the |
| 127 // script originates from the same place. This is to avoid issues | 134 // script originates from the same place. This is to avoid issues |
| 128 // when reporting errors, etc. | 135 // when reporting errors, etc. |
| 129 bool CompilationCacheScript::HasOrigin( | 136 bool CompilationCacheScript::HasOrigin( |
| 130 Handle<SharedFunctionInfo> function_info, | 137 Handle<SharedFunctionInfo> function_info, |
| 131 Handle<Object> name, | 138 Handle<Object> name, |
| 132 int line_offset, | 139 int line_offset, |
| 133 int column_offset) { | 140 int column_offset) { |
| 134 Handle<Script> script = | 141 Handle<Script> script = |
| 135 Handle<Script>(Script::cast(function_info->script())); | 142 Handle<Script>(Script::cast(function_info->script())); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 // Break when we've found a suitable shared function info that | 178 // Break when we've found a suitable shared function info that |
| 172 // matches the origin. | 179 // matches the origin. |
| 173 if (HasOrigin(function_info, name, line_offset, column_offset)) { | 180 if (HasOrigin(function_info, name, line_offset, column_offset)) { |
| 174 result = *function_info; | 181 result = *function_info; |
| 175 break; | 182 break; |
| 176 } | 183 } |
| 177 } | 184 } |
| 178 } | 185 } |
| 179 } | 186 } |
| 180 | 187 |
| 181 // TODO(isolates): make it per isolate | 188 if (!script_histogram_initialized_) { |
| 182 static void* script_histogram = StatsTable::CreateHistogram( | 189 script_histogram_ = Isolate::Current()->stats_table()->CreateHistogram( |
| 183 "V8.ScriptCache", | 190 "V8.ScriptCache", |
| 184 0, | 191 0, |
| 185 kScriptGenerations, | 192 kScriptGenerations, |
| 186 kScriptGenerations + 1); | 193 kScriptGenerations + 1); |
| 194 script_histogram_initialized_ = true; |
| 195 } |
| 187 | 196 |
| 188 if (script_histogram != NULL) { | 197 if (script_histogram_ != NULL) { |
| 189 // The level NUMBER_OF_SCRIPT_GENERATIONS is equivalent to a cache miss. | 198 // The level NUMBER_OF_SCRIPT_GENERATIONS is equivalent to a cache miss. |
| 190 StatsTable::AddHistogramSample(script_histogram, generation); | 199 Isolate::Current()->stats_table()->AddHistogramSample( |
| 200 script_histogram_, generation); |
| 191 } | 201 } |
| 192 | 202 |
| 193 // Once outside the manacles of the handle scope, we need to recheck | 203 // Once outside the manacles of the handle scope, we need to recheck |
| 194 // to see if we actually found a cached script. If so, we return a | 204 // to see if we actually found a cached script. If so, we return a |
| 195 // handle created in the caller's handle scope. | 205 // handle created in the caller's handle scope. |
| 196 if (result != NULL) { | 206 if (result != NULL) { |
| 197 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result)); | 207 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result)); |
| 198 ASSERT(HasOrigin(shared, name, line_offset, column_offset)); | 208 ASSERT(HasOrigin(shared, name, line_offset, column_offset)); |
| 199 // If the script was found in a later generation, we promote it to | 209 // If the script was found in a later generation, we promote it to |
| 200 // the first generation to let it survive longer in the cache. | 210 // the first generation to let it survive longer in the cache. |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 } | 439 } |
| 430 | 440 |
| 431 | 441 |
| 432 void CompilationCache::Disable() { | 442 void CompilationCache::Disable() { |
| 433 enabled_ = false; | 443 enabled_ = false; |
| 434 Clear(); | 444 Clear(); |
| 435 } | 445 } |
| 436 | 446 |
| 437 | 447 |
| 438 } } // namespace v8::internal | 448 } } // namespace v8::internal |
| OLD | NEW |