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