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/compilation-cache.h" | 5 #include "src/compilation-cache.h" |
6 | 6 |
7 #include "src/counters.h" | 7 #include "src/counters.h" |
8 #include "src/factory.h" | 8 #include "src/factory.h" |
9 #include "src/globals.h" | 9 #include "src/globals.h" |
10 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 } | 137 } |
138 | 138 |
139 | 139 |
140 // TODO(245): Need to allow identical code from different contexts to | 140 // TODO(245): Need to allow identical code from different contexts to |
141 // be cached in the same script generation. Currently the first use | 141 // be cached in the same script generation. Currently the first use |
142 // will be cached, but subsequent code from different source / line | 142 // will be cached, but subsequent code from different source / line |
143 // won't. | 143 // won't. |
144 Handle<SharedFunctionInfo> CompilationCacheScript::Lookup( | 144 Handle<SharedFunctionInfo> CompilationCacheScript::Lookup( |
145 Handle<String> source, Handle<Object> name, int line_offset, | 145 Handle<String> source, Handle<Object> name, int line_offset, |
146 int column_offset, ScriptOriginOptions resource_options, | 146 int column_offset, ScriptOriginOptions resource_options, |
147 Handle<Context> context, LanguageMode language_mode) { | 147 Handle<Context> context, LanguageMode language_mode, bool is_module) { |
148 Object* result = NULL; | 148 Object* result = NULL; |
149 int generation; | 149 int generation; |
150 | 150 |
151 // Probe the script generation tables. Make sure not to leak handles | 151 // Probe the script generation tables. Make sure not to leak handles |
152 // into the caller's handle scope. | 152 // into the caller's handle scope. |
153 { HandleScope scope(isolate()); | 153 { HandleScope scope(isolate()); |
154 for (generation = 0; generation < generations(); generation++) { | 154 for (generation = 0; generation < generations(); generation++) { |
155 Handle<CompilationCacheTable> table = GetTable(generation); | 155 Handle<CompilationCacheTable> table = GetTable(generation); |
156 Handle<Object> probe = table->Lookup(source, context, language_mode); | 156 Handle<Object> probe = |
| 157 table->Lookup(source, context, language_mode, is_module); |
157 if (probe->IsSharedFunctionInfo()) { | 158 if (probe->IsSharedFunctionInfo()) { |
158 Handle<SharedFunctionInfo> function_info = | 159 Handle<SharedFunctionInfo> function_info = |
159 Handle<SharedFunctionInfo>::cast(probe); | 160 Handle<SharedFunctionInfo>::cast(probe); |
160 // Break when we've found a suitable shared function info that | 161 // Break when we've found a suitable shared function info that |
161 // matches the origin. | 162 // matches the origin. |
162 if (HasOrigin(function_info, name, line_offset, column_offset, | 163 if (HasOrigin(function_info, name, line_offset, column_offset, |
163 resource_options)) { | 164 resource_options)) { |
164 result = *function_info; | 165 result = *function_info; |
165 break; | 166 break; |
166 } | 167 } |
167 } | 168 } |
168 } | 169 } |
169 } | 170 } |
170 | 171 |
171 // Once outside the manacles of the handle scope, we need to recheck | 172 // Once outside the manacles of the handle scope, we need to recheck |
172 // to see if we actually found a cached script. If so, we return a | 173 // to see if we actually found a cached script. If so, we return a |
173 // handle created in the caller's handle scope. | 174 // handle created in the caller's handle scope. |
174 if (result != NULL) { | 175 if (result != NULL) { |
175 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result), | 176 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result), |
176 isolate()); | 177 isolate()); |
177 DCHECK( | 178 DCHECK( |
178 HasOrigin(shared, name, line_offset, column_offset, resource_options)); | 179 HasOrigin(shared, name, line_offset, column_offset, resource_options)); |
179 // If the script was found in a later generation, we promote it to | 180 // If the script was found in a later generation, we promote it to |
180 // the first generation to let it survive longer in the cache. | 181 // the first generation to let it survive longer in the cache. |
181 if (generation != 0) Put(source, context, language_mode, shared); | 182 if (generation != 0) Put(source, context, language_mode, is_module, shared); |
182 isolate()->counters()->compilation_cache_hits()->Increment(); | 183 isolate()->counters()->compilation_cache_hits()->Increment(); |
183 return shared; | 184 return shared; |
184 } else { | 185 } else { |
185 isolate()->counters()->compilation_cache_misses()->Increment(); | 186 isolate()->counters()->compilation_cache_misses()->Increment(); |
186 return Handle<SharedFunctionInfo>::null(); | 187 return Handle<SharedFunctionInfo>::null(); |
187 } | 188 } |
188 } | 189 } |
189 | 190 |
190 | 191 void CompilationCacheScript::Put(Handle<String> source, Handle<Context> context, |
191 void CompilationCacheScript::Put(Handle<String> source, | 192 LanguageMode language_mode, bool is_module, |
192 Handle<Context> context, | |
193 LanguageMode language_mode, | |
194 Handle<SharedFunctionInfo> function_info) { | 193 Handle<SharedFunctionInfo> function_info) { |
195 HandleScope scope(isolate()); | 194 HandleScope scope(isolate()); |
196 Handle<CompilationCacheTable> table = GetFirstTable(); | 195 Handle<CompilationCacheTable> table = GetFirstTable(); |
197 SetFirstTable(CompilationCacheTable::Put(table, source, context, | 196 SetFirstTable(CompilationCacheTable::Put( |
198 language_mode, function_info)); | 197 table, source, context, language_mode, is_module, function_info)); |
199 } | 198 } |
200 | 199 |
201 | 200 |
202 MaybeHandle<SharedFunctionInfo> CompilationCacheEval::Lookup( | 201 MaybeHandle<SharedFunctionInfo> CompilationCacheEval::Lookup( |
203 Handle<String> source, Handle<SharedFunctionInfo> outer_info, | 202 Handle<String> source, Handle<SharedFunctionInfo> outer_info, |
204 LanguageMode language_mode, int scope_position) { | 203 LanguageMode language_mode, int scope_position) { |
205 HandleScope scope(isolate()); | 204 HandleScope scope(isolate()); |
206 // Make sure not to leak the table into the surrounding handle | 205 // Make sure not to leak the table into the surrounding handle |
207 // scope. Otherwise, we risk keeping old tables around even after | 206 // scope. Otherwise, we risk keeping old tables around even after |
208 // having cleared the cache. | 207 // having cleared the cache. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 | 278 |
280 | 279 |
281 void CompilationCache::Remove(Handle<SharedFunctionInfo> function_info) { | 280 void CompilationCache::Remove(Handle<SharedFunctionInfo> function_info) { |
282 if (!IsEnabled()) return; | 281 if (!IsEnabled()) return; |
283 | 282 |
284 eval_global_.Remove(function_info); | 283 eval_global_.Remove(function_info); |
285 eval_contextual_.Remove(function_info); | 284 eval_contextual_.Remove(function_info); |
286 script_.Remove(function_info); | 285 script_.Remove(function_info); |
287 } | 286 } |
288 | 287 |
289 | |
290 MaybeHandle<SharedFunctionInfo> CompilationCache::LookupScript( | 288 MaybeHandle<SharedFunctionInfo> CompilationCache::LookupScript( |
291 Handle<String> source, Handle<Object> name, int line_offset, | 289 Handle<String> source, Handle<Object> name, int line_offset, |
292 int column_offset, ScriptOriginOptions resource_options, | 290 int column_offset, ScriptOriginOptions resource_options, |
293 Handle<Context> context, LanguageMode language_mode) { | 291 Handle<Context> context, LanguageMode language_mode, bool is_script) { |
294 if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>(); | 292 if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>(); |
295 | 293 |
296 return script_.Lookup(source, name, line_offset, column_offset, | 294 return script_.Lookup(source, name, line_offset, column_offset, |
297 resource_options, context, language_mode); | 295 resource_options, context, language_mode, is_script); |
298 } | 296 } |
299 | 297 |
300 | 298 |
301 MaybeHandle<SharedFunctionInfo> CompilationCache::LookupEval( | 299 MaybeHandle<SharedFunctionInfo> CompilationCache::LookupEval( |
302 Handle<String> source, Handle<SharedFunctionInfo> outer_info, | 300 Handle<String> source, Handle<SharedFunctionInfo> outer_info, |
303 Handle<Context> context, LanguageMode language_mode, int scope_position) { | 301 Handle<Context> context, LanguageMode language_mode, int scope_position) { |
304 if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>(); | 302 if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>(); |
305 | 303 |
306 MaybeHandle<SharedFunctionInfo> result; | 304 MaybeHandle<SharedFunctionInfo> result; |
307 if (context->IsNativeContext()) { | 305 if (context->IsNativeContext()) { |
308 result = | 306 result = |
309 eval_global_.Lookup(source, outer_info, language_mode, scope_position); | 307 eval_global_.Lookup(source, outer_info, language_mode, scope_position); |
310 } else { | 308 } else { |
311 DCHECK(scope_position != kNoSourcePosition); | 309 DCHECK(scope_position != kNoSourcePosition); |
312 result = eval_contextual_.Lookup(source, outer_info, language_mode, | 310 result = eval_contextual_.Lookup(source, outer_info, language_mode, |
313 scope_position); | 311 scope_position); |
314 } | 312 } |
315 return result; | 313 return result; |
316 } | 314 } |
317 | 315 |
318 | 316 |
319 MaybeHandle<FixedArray> CompilationCache::LookupRegExp(Handle<String> source, | 317 MaybeHandle<FixedArray> CompilationCache::LookupRegExp(Handle<String> source, |
320 JSRegExp::Flags flags) { | 318 JSRegExp::Flags flags) { |
321 if (!IsEnabled()) return MaybeHandle<FixedArray>(); | 319 if (!IsEnabled()) return MaybeHandle<FixedArray>(); |
322 | 320 |
323 return reg_exp_.Lookup(source, flags); | 321 return reg_exp_.Lookup(source, flags); |
324 } | 322 } |
325 | 323 |
326 | 324 void CompilationCache::PutScript(Handle<String> source, Handle<Context> context, |
327 void CompilationCache::PutScript(Handle<String> source, | 325 LanguageMode language_mode, bool is_module, |
328 Handle<Context> context, | |
329 LanguageMode language_mode, | |
330 Handle<SharedFunctionInfo> function_info) { | 326 Handle<SharedFunctionInfo> function_info) { |
331 if (!IsEnabled()) return; | 327 if (!IsEnabled()) return; |
332 | 328 |
333 script_.Put(source, context, language_mode, function_info); | 329 script_.Put(source, context, language_mode, is_module, function_info); |
334 } | 330 } |
335 | 331 |
336 | 332 |
337 void CompilationCache::PutEval(Handle<String> source, | 333 void CompilationCache::PutEval(Handle<String> source, |
338 Handle<SharedFunctionInfo> outer_info, | 334 Handle<SharedFunctionInfo> outer_info, |
339 Handle<Context> context, | 335 Handle<Context> context, |
340 Handle<SharedFunctionInfo> function_info, | 336 Handle<SharedFunctionInfo> function_info, |
341 int scope_position) { | 337 int scope_position) { |
342 if (!IsEnabled()) return; | 338 if (!IsEnabled()) return; |
343 | 339 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 | 393 |
398 | 394 |
399 void CompilationCache::Disable() { | 395 void CompilationCache::Disable() { |
400 enabled_ = false; | 396 enabled_ = false; |
401 Clear(); | 397 Clear(); |
402 } | 398 } |
403 | 399 |
404 | 400 |
405 } // namespace internal | 401 } // namespace internal |
406 } // namespace v8 | 402 } // namespace v8 |
OLD | NEW |