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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 Handle<SharedFunctionInfo> function_info, | 187 Handle<SharedFunctionInfo> function_info, |
188 Handle<Cell> literals) { | 188 Handle<Cell> literals) { |
189 HandleScope scope(isolate()); | 189 HandleScope scope(isolate()); |
190 Handle<CompilationCacheTable> table = GetFirstTable(); | 190 Handle<CompilationCacheTable> table = GetFirstTable(); |
191 SetFirstTable(CompilationCacheTable::PutScript( | 191 SetFirstTable(CompilationCacheTable::PutScript( |
192 table, source, context, language_mode, function_info, literals)); | 192 table, source, context, language_mode, function_info, literals)); |
193 } | 193 } |
194 | 194 |
195 InfoVectorPair CompilationCacheEval::Lookup( | 195 InfoVectorPair CompilationCacheEval::Lookup( |
196 Handle<String> source, Handle<SharedFunctionInfo> outer_info, | 196 Handle<String> source, Handle<SharedFunctionInfo> outer_info, |
197 Handle<Context> native_context, LanguageMode language_mode, | 197 Handle<Context> native_context, LanguageMode language_mode, int position) { |
198 int scope_position) { | |
199 HandleScope scope(isolate()); | 198 HandleScope scope(isolate()); |
200 // Make sure not to leak the table into the surrounding handle | 199 // Make sure not to leak the table into the surrounding handle |
201 // scope. Otherwise, we risk keeping old tables around even after | 200 // scope. Otherwise, we risk keeping old tables around even after |
202 // having cleared the cache. | 201 // having cleared the cache. |
203 InfoVectorPair result; | 202 InfoVectorPair result; |
204 const int generation = 0; | 203 const int generation = 0; |
205 DCHECK(generations() == 1); | 204 DCHECK(generations() == 1); |
206 Handle<CompilationCacheTable> table = GetTable(generation); | 205 Handle<CompilationCacheTable> table = GetTable(generation); |
207 result = table->LookupEval(source, outer_info, native_context, language_mode, | 206 result = table->LookupEval(source, outer_info, native_context, language_mode, |
208 scope_position); | 207 position); |
209 if (result.has_shared()) { | 208 if (result.has_shared()) { |
210 isolate()->counters()->compilation_cache_hits()->Increment(); | 209 isolate()->counters()->compilation_cache_hits()->Increment(); |
211 } else { | 210 } else { |
212 isolate()->counters()->compilation_cache_misses()->Increment(); | 211 isolate()->counters()->compilation_cache_misses()->Increment(); |
213 } | 212 } |
214 return result; | 213 return result; |
215 } | 214 } |
216 | 215 |
217 void CompilationCacheEval::Put(Handle<String> source, | 216 void CompilationCacheEval::Put(Handle<String> source, |
218 Handle<SharedFunctionInfo> outer_info, | 217 Handle<SharedFunctionInfo> outer_info, |
219 Handle<SharedFunctionInfo> function_info, | 218 Handle<SharedFunctionInfo> function_info, |
220 Handle<Context> native_context, | 219 Handle<Context> native_context, |
221 Handle<Cell> literals, int scope_position) { | 220 Handle<Cell> literals, int position) { |
222 HandleScope scope(isolate()); | 221 HandleScope scope(isolate()); |
223 Handle<CompilationCacheTable> table = GetFirstTable(); | 222 Handle<CompilationCacheTable> table = GetFirstTable(); |
224 table = | 223 table = |
225 CompilationCacheTable::PutEval(table, source, outer_info, function_info, | 224 CompilationCacheTable::PutEval(table, source, outer_info, function_info, |
226 native_context, literals, scope_position); | 225 native_context, literals, position); |
227 SetFirstTable(table); | 226 SetFirstTable(table); |
228 } | 227 } |
229 | 228 |
230 | 229 |
231 MaybeHandle<FixedArray> CompilationCacheRegExp::Lookup( | 230 MaybeHandle<FixedArray> CompilationCacheRegExp::Lookup( |
232 Handle<String> source, | 231 Handle<String> source, |
233 JSRegExp::Flags flags) { | 232 JSRegExp::Flags flags) { |
234 HandleScope scope(isolate()); | 233 HandleScope scope(isolate()); |
235 // Make sure not to leak the table into the surrounding handle | 234 // Make sure not to leak the table into the surrounding handle |
236 // scope. Otherwise, we risk keeping old tables around even after | 235 // scope. Otherwise, we risk keeping old tables around even after |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 Handle<Context> context, LanguageMode language_mode) { | 278 Handle<Context> context, LanguageMode language_mode) { |
280 InfoVectorPair empty_result; | 279 InfoVectorPair empty_result; |
281 if (!IsEnabled()) return empty_result; | 280 if (!IsEnabled()) return empty_result; |
282 | 281 |
283 return script_.Lookup(source, name, line_offset, column_offset, | 282 return script_.Lookup(source, name, line_offset, column_offset, |
284 resource_options, context, language_mode); | 283 resource_options, context, language_mode); |
285 } | 284 } |
286 | 285 |
287 InfoVectorPair CompilationCache::LookupEval( | 286 InfoVectorPair CompilationCache::LookupEval( |
288 Handle<String> source, Handle<SharedFunctionInfo> outer_info, | 287 Handle<String> source, Handle<SharedFunctionInfo> outer_info, |
289 Handle<Context> context, LanguageMode language_mode, int scope_position) { | 288 Handle<Context> context, LanguageMode language_mode, int position) { |
290 InfoVectorPair result; | 289 InfoVectorPair result; |
291 if (!IsEnabled()) return result; | 290 if (!IsEnabled()) return result; |
292 | 291 |
293 if (context->IsNativeContext()) { | 292 if (context->IsNativeContext()) { |
294 result = eval_global_.Lookup(source, outer_info, context, language_mode, | 293 result = eval_global_.Lookup(source, outer_info, context, language_mode, |
295 scope_position); | 294 position); |
296 } else { | 295 } else { |
297 DCHECK(scope_position != kNoSourcePosition); | 296 DCHECK(position != kNoSourcePosition); |
298 Handle<Context> native_context(context->native_context(), isolate()); | 297 Handle<Context> native_context(context->native_context(), isolate()); |
299 result = eval_contextual_.Lookup(source, outer_info, native_context, | 298 result = eval_contextual_.Lookup(source, outer_info, native_context, |
300 language_mode, scope_position); | 299 language_mode, position); |
301 } | 300 } |
302 | 301 |
303 return result; | 302 return result; |
304 } | 303 } |
305 | 304 |
306 | 305 |
307 MaybeHandle<FixedArray> CompilationCache::LookupRegExp(Handle<String> source, | 306 MaybeHandle<FixedArray> CompilationCache::LookupRegExp(Handle<String> source, |
308 JSRegExp::Flags flags) { | 307 JSRegExp::Flags flags) { |
309 if (!IsEnabled()) return MaybeHandle<FixedArray>(); | 308 if (!IsEnabled()) return MaybeHandle<FixedArray>(); |
310 | 309 |
311 return reg_exp_.Lookup(source, flags); | 310 return reg_exp_.Lookup(source, flags); |
312 } | 311 } |
313 | 312 |
314 void CompilationCache::PutScript(Handle<String> source, Handle<Context> context, | 313 void CompilationCache::PutScript(Handle<String> source, Handle<Context> context, |
315 LanguageMode language_mode, | 314 LanguageMode language_mode, |
316 Handle<SharedFunctionInfo> function_info, | 315 Handle<SharedFunctionInfo> function_info, |
317 Handle<Cell> literals) { | 316 Handle<Cell> literals) { |
318 if (!IsEnabled()) return; | 317 if (!IsEnabled()) return; |
319 | 318 |
320 script_.Put(source, context, language_mode, function_info, literals); | 319 script_.Put(source, context, language_mode, function_info, literals); |
321 } | 320 } |
322 | 321 |
323 void CompilationCache::PutEval(Handle<String> source, | 322 void CompilationCache::PutEval(Handle<String> source, |
324 Handle<SharedFunctionInfo> outer_info, | 323 Handle<SharedFunctionInfo> outer_info, |
325 Handle<Context> context, | 324 Handle<Context> context, |
326 Handle<SharedFunctionInfo> function_info, | 325 Handle<SharedFunctionInfo> function_info, |
327 Handle<Cell> literals, int scope_position) { | 326 Handle<Cell> literals, int position) { |
328 if (!IsEnabled()) return; | 327 if (!IsEnabled()) return; |
329 | 328 |
330 HandleScope scope(isolate()); | 329 HandleScope scope(isolate()); |
331 if (context->IsNativeContext()) { | 330 if (context->IsNativeContext()) { |
332 eval_global_.Put(source, outer_info, function_info, context, literals, | 331 eval_global_.Put(source, outer_info, function_info, context, literals, |
333 scope_position); | 332 position); |
334 } else { | 333 } else { |
335 DCHECK(scope_position != kNoSourcePosition); | 334 DCHECK(position != kNoSourcePosition); |
336 Handle<Context> native_context(context->native_context(), isolate()); | 335 Handle<Context> native_context(context->native_context(), isolate()); |
337 eval_contextual_.Put(source, outer_info, function_info, native_context, | 336 eval_contextual_.Put(source, outer_info, function_info, native_context, |
338 literals, scope_position); | 337 literals, position); |
339 } | 338 } |
340 } | 339 } |
341 | 340 |
342 | 341 |
343 | 342 |
344 void CompilationCache::PutRegExp(Handle<String> source, | 343 void CompilationCache::PutRegExp(Handle<String> source, |
345 JSRegExp::Flags flags, | 344 JSRegExp::Flags flags, |
346 Handle<FixedArray> data) { | 345 Handle<FixedArray> data) { |
347 if (!IsEnabled()) { | 346 if (!IsEnabled()) { |
348 return; | 347 return; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 | 385 |
387 | 386 |
388 void CompilationCache::Disable() { | 387 void CompilationCache::Disable() { |
389 enabled_ = false; | 388 enabled_ = false; |
390 Clear(); | 389 Clear(); |
391 } | 390 } |
392 | 391 |
393 | 392 |
394 } // namespace internal | 393 } // namespace internal |
395 } // namespace v8 | 394 } // namespace v8 |
OLD | NEW |