| OLD | NEW | 
|---|
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "src/v8.h" | 5 #include "src/v8.h" | 
| 6 | 6 | 
| 7 #include "src/assembler.h" | 7 #include "src/assembler.h" | 
| 8 #include "src/compilation-cache.h" | 8 #include "src/compilation-cache.h" | 
| 9 | 9 | 
| 10 namespace v8 { | 10 namespace v8 { | 
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 106                                                int generations) | 106                                                int generations) | 
| 107     : CompilationSubCache(isolate, generations) {} | 107     : CompilationSubCache(isolate, generations) {} | 
| 108 | 108 | 
| 109 | 109 | 
| 110 // We only re-use a cached function for some script source code if the | 110 // We only re-use a cached function for some script source code if the | 
| 111 // script originates from the same place. This is to avoid issues | 111 // script originates from the same place. This is to avoid issues | 
| 112 // when reporting errors, etc. | 112 // when reporting errors, etc. | 
| 113 bool CompilationCacheScript::HasOrigin(Handle<SharedFunctionInfo> function_info, | 113 bool CompilationCacheScript::HasOrigin(Handle<SharedFunctionInfo> function_info, | 
| 114                                        Handle<Object> name, int line_offset, | 114                                        Handle<Object> name, int line_offset, | 
| 115                                        int column_offset, | 115                                        int column_offset, | 
| 116                                        bool is_embedder_debug_script, | 116                                        ScriptOriginOptions resource_options) { | 
| 117                                        bool is_shared_cross_origin) { |  | 
| 118   Handle<Script> script = | 117   Handle<Script> script = | 
| 119       Handle<Script>(Script::cast(function_info->script()), isolate()); | 118       Handle<Script>(Script::cast(function_info->script()), isolate()); | 
| 120   // If the script name isn't set, the boilerplate script should have | 119   // If the script name isn't set, the boilerplate script should have | 
| 121   // an undefined name to have the same origin. | 120   // an undefined name to have the same origin. | 
| 122   if (name.is_null()) { | 121   if (name.is_null()) { | 
| 123     return script->name()->IsUndefined(); | 122     return script->name()->IsUndefined(); | 
| 124   } | 123   } | 
| 125   // Do the fast bailout checks first. | 124   // Do the fast bailout checks first. | 
| 126   if (line_offset != script->line_offset()->value()) return false; | 125   if (line_offset != script->line_offset()->value()) return false; | 
| 127   if (column_offset != script->column_offset()->value()) return false; | 126   if (column_offset != script->column_offset()->value()) return false; | 
| 128   // Check that both names are strings. If not, no match. | 127   // Check that both names are strings. If not, no match. | 
| 129   if (!name->IsString() || !script->name()->IsString()) return false; | 128   if (!name->IsString() || !script->name()->IsString()) return false; | 
| 130   // Were both scripts tagged by the embedder as being internal script? | 129   // Are the origin_options same? | 
| 131   if (is_embedder_debug_script != script->is_embedder_debug_script()) { | 130   if (resource_options.Flags() != script->origin_options().Flags()) | 
| 132     return false; | 131     return false; | 
| 133   } |  | 
| 134   // Were both scripts tagged by the embedder as being shared cross-origin? |  | 
| 135   if (is_shared_cross_origin != script->is_shared_cross_origin()) return false; |  | 
| 136   // Compare the two name strings for equality. | 132   // Compare the two name strings for equality. | 
| 137   return String::Equals(Handle<String>::cast(name), | 133   return String::Equals(Handle<String>::cast(name), | 
| 138                         Handle<String>(String::cast(script->name()))); | 134                         Handle<String>(String::cast(script->name()))); | 
| 139 } | 135 } | 
| 140 | 136 | 
| 141 | 137 | 
| 142 // TODO(245): Need to allow identical code from different contexts to | 138 // TODO(245): Need to allow identical code from different contexts to | 
| 143 // be cached in the same script generation. Currently the first use | 139 // be cached in the same script generation. Currently the first use | 
| 144 // will be cached, but subsequent code from different source / line | 140 // will be cached, but subsequent code from different source / line | 
| 145 // won't. | 141 // won't. | 
| 146 Handle<SharedFunctionInfo> CompilationCacheScript::Lookup( | 142 Handle<SharedFunctionInfo> CompilationCacheScript::Lookup( | 
| 147     Handle<String> source, Handle<Object> name, int line_offset, | 143     Handle<String> source, Handle<Object> name, int line_offset, | 
| 148     int column_offset, bool is_embedder_debug_script, | 144     int column_offset, ScriptOriginOptions resource_options, | 
| 149     bool is_shared_cross_origin, Handle<Context> context, | 145     Handle<Context> context, LanguageMode language_mode) { | 
| 150     LanguageMode language_mode) { |  | 
| 151   Object* result = NULL; | 146   Object* result = NULL; | 
| 152   int generation; | 147   int generation; | 
| 153 | 148 | 
| 154   // Probe the script generation tables. Make sure not to leak handles | 149   // Probe the script generation tables. Make sure not to leak handles | 
| 155   // into the caller's handle scope. | 150   // into the caller's handle scope. | 
| 156   { HandleScope scope(isolate()); | 151   { HandleScope scope(isolate()); | 
| 157     for (generation = 0; generation < generations(); generation++) { | 152     for (generation = 0; generation < generations(); generation++) { | 
| 158       Handle<CompilationCacheTable> table = GetTable(generation); | 153       Handle<CompilationCacheTable> table = GetTable(generation); | 
| 159       Handle<Object> probe = table->Lookup(source, context, language_mode); | 154       Handle<Object> probe = table->Lookup(source, context, language_mode); | 
| 160       if (probe->IsSharedFunctionInfo()) { | 155       if (probe->IsSharedFunctionInfo()) { | 
| 161         Handle<SharedFunctionInfo> function_info = | 156         Handle<SharedFunctionInfo> function_info = | 
| 162             Handle<SharedFunctionInfo>::cast(probe); | 157             Handle<SharedFunctionInfo>::cast(probe); | 
| 163         // Break when we've found a suitable shared function info that | 158         // Break when we've found a suitable shared function info that | 
| 164         // matches the origin. | 159         // matches the origin. | 
| 165         if (HasOrigin(function_info, name, line_offset, column_offset, | 160         if (HasOrigin(function_info, name, line_offset, column_offset, | 
| 166                       is_embedder_debug_script, is_shared_cross_origin)) { | 161                       resource_options)) { | 
| 167           result = *function_info; | 162           result = *function_info; | 
| 168           break; | 163           break; | 
| 169         } | 164         } | 
| 170       } | 165       } | 
| 171     } | 166     } | 
| 172   } | 167   } | 
| 173 | 168 | 
| 174   // Once outside the manacles of the handle scope, we need to recheck | 169   // Once outside the manacles of the handle scope, we need to recheck | 
| 175   // to see if we actually found a cached script. If so, we return a | 170   // to see if we actually found a cached script. If so, we return a | 
| 176   // handle created in the caller's handle scope. | 171   // handle created in the caller's handle scope. | 
| 177   if (result != NULL) { | 172   if (result != NULL) { | 
| 178     Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result), | 173     Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result), | 
| 179                                       isolate()); | 174                                       isolate()); | 
| 180     DCHECK(HasOrigin(shared, name, line_offset, column_offset, | 175     DCHECK( | 
| 181                      is_embedder_debug_script, is_shared_cross_origin)); | 176         HasOrigin(shared, name, line_offset, column_offset, resource_options)); | 
| 182     // If the script was found in a later generation, we promote it to | 177     // If the script was found in a later generation, we promote it to | 
| 183     // the first generation to let it survive longer in the cache. | 178     // the first generation to let it survive longer in the cache. | 
| 184     if (generation != 0) Put(source, context, language_mode, shared); | 179     if (generation != 0) Put(source, context, language_mode, shared); | 
| 185     isolate()->counters()->compilation_cache_hits()->Increment(); | 180     isolate()->counters()->compilation_cache_hits()->Increment(); | 
| 186     return shared; | 181     return shared; | 
| 187   } else { | 182   } else { | 
| 188     isolate()->counters()->compilation_cache_misses()->Increment(); | 183     isolate()->counters()->compilation_cache_misses()->Increment(); | 
| 189     return Handle<SharedFunctionInfo>::null(); | 184     return Handle<SharedFunctionInfo>::null(); | 
| 190   } | 185   } | 
| 191 } | 186 } | 
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 285   if (!IsEnabled()) return; | 280   if (!IsEnabled()) return; | 
| 286 | 281 | 
| 287   eval_global_.Remove(function_info); | 282   eval_global_.Remove(function_info); | 
| 288   eval_contextual_.Remove(function_info); | 283   eval_contextual_.Remove(function_info); | 
| 289   script_.Remove(function_info); | 284   script_.Remove(function_info); | 
| 290 } | 285 } | 
| 291 | 286 | 
| 292 | 287 | 
| 293 MaybeHandle<SharedFunctionInfo> CompilationCache::LookupScript( | 288 MaybeHandle<SharedFunctionInfo> CompilationCache::LookupScript( | 
| 294     Handle<String> source, Handle<Object> name, int line_offset, | 289     Handle<String> source, Handle<Object> name, int line_offset, | 
| 295     int column_offset, bool is_embedder_debug_script, | 290     int column_offset, ScriptOriginOptions resource_options, | 
| 296     bool is_shared_cross_origin, Handle<Context> context, | 291     Handle<Context> context, LanguageMode language_mode) { | 
| 297     LanguageMode language_mode) { |  | 
| 298   if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>(); | 292   if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>(); | 
| 299 | 293 | 
| 300   return script_.Lookup(source, name, line_offset, column_offset, | 294   return script_.Lookup(source, name, line_offset, column_offset, | 
| 301                         is_embedder_debug_script, is_shared_cross_origin, | 295                         resource_options, context, language_mode); | 
| 302                         context, language_mode); |  | 
| 303 } | 296 } | 
| 304 | 297 | 
| 305 | 298 | 
| 306 MaybeHandle<SharedFunctionInfo> CompilationCache::LookupEval( | 299 MaybeHandle<SharedFunctionInfo> CompilationCache::LookupEval( | 
| 307     Handle<String> source, Handle<SharedFunctionInfo> outer_info, | 300     Handle<String> source, Handle<SharedFunctionInfo> outer_info, | 
| 308     Handle<Context> context, LanguageMode language_mode, int scope_position) { | 301     Handle<Context> context, LanguageMode language_mode, int scope_position) { | 
| 309   if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>(); | 302   if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>(); | 
| 310 | 303 | 
| 311   MaybeHandle<SharedFunctionInfo> result; | 304   MaybeHandle<SharedFunctionInfo> result; | 
| 312   if (context->IsNativeContext()) { | 305   if (context->IsNativeContext()) { | 
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 401 } | 394 } | 
| 402 | 395 | 
| 403 | 396 | 
| 404 void CompilationCache::Disable() { | 397 void CompilationCache::Disable() { | 
| 405   enabled_ = false; | 398   enabled_ = false; | 
| 406   Clear(); | 399   Clear(); | 
| 407 } | 400 } | 
| 408 | 401 | 
| 409 | 402 | 
| 410 } }  // namespace v8::internal | 403 } }  // namespace v8::internal | 
| OLD | NEW | 
|---|