| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 SetFirstTable( | 247 SetFirstTable( |
| 248 CompilationCacheTable::Put(table, source, context, function_info)); | 248 CompilationCacheTable::Put(table, source, context, function_info)); |
| 249 } | 249 } |
| 250 | 250 |
| 251 | 251 |
| 252 MaybeHandle<SharedFunctionInfo> CompilationCacheEval::Lookup( | 252 MaybeHandle<SharedFunctionInfo> CompilationCacheEval::Lookup( |
| 253 Handle<String> source, | 253 Handle<String> source, |
| 254 Handle<Context> context, | 254 Handle<Context> context, |
| 255 StrictMode strict_mode, | 255 StrictMode strict_mode, |
| 256 int scope_position) { | 256 int scope_position) { |
| 257 HandleScope scope(isolate()); |
| 257 // Make sure not to leak the table into the surrounding handle | 258 // Make sure not to leak the table into the surrounding handle |
| 258 // scope. Otherwise, we risk keeping old tables around even after | 259 // scope. Otherwise, we risk keeping old tables around even after |
| 259 // having cleared the cache. | 260 // having cleared the cache. |
| 260 Handle<Object> result = isolate()->factory()->undefined_value(); | 261 Handle<Object> result = isolate()->factory()->undefined_value(); |
| 261 int generation; | 262 int generation; |
| 262 { HandleScope scope(isolate()); | 263 for (generation = 0; generation < generations(); generation++) { |
| 263 Handle<Object> temp = result; | 264 Handle<CompilationCacheTable> table = GetTable(generation); |
| 264 for (generation = 0; generation < generations(); generation++) { | 265 result = table->LookupEval(source, context, strict_mode, scope_position); |
| 265 Handle<CompilationCacheTable> table = GetTable(generation); | 266 if (result->IsSharedFunctionInfo()) break; |
| 266 temp = table->LookupEval(source, context, strict_mode, scope_position); | |
| 267 if (temp->IsSharedFunctionInfo()) break; | |
| 268 } | |
| 269 if (temp->IsSharedFunctionInfo()) result = scope.CloseAndEscape(temp); | |
| 270 } | 267 } |
| 271 if (result->IsSharedFunctionInfo()) { | 268 if (result->IsSharedFunctionInfo()) { |
| 272 Handle<SharedFunctionInfo> function_info = | 269 Handle<SharedFunctionInfo> function_info = |
| 273 Handle<SharedFunctionInfo>::cast(result); | 270 Handle<SharedFunctionInfo>::cast(result); |
| 274 if (generation != 0) { | 271 if (generation != 0) { |
| 275 Put(source, context, function_info, scope_position); | 272 Put(source, context, function_info, scope_position); |
| 276 } | 273 } |
| 277 isolate()->counters()->compilation_cache_hits()->Increment(); | 274 isolate()->counters()->compilation_cache_hits()->Increment(); |
| 278 return function_info; | 275 return scope.CloseAndEscape(function_info); |
| 279 } else { | 276 } else { |
| 280 isolate()->counters()->compilation_cache_misses()->Increment(); | 277 isolate()->counters()->compilation_cache_misses()->Increment(); |
| 281 return MaybeHandle<SharedFunctionInfo>(); | 278 return MaybeHandle<SharedFunctionInfo>(); |
| 282 } | 279 } |
| 283 } | 280 } |
| 284 | 281 |
| 285 | 282 |
| 286 void CompilationCacheEval::Put(Handle<String> source, | 283 void CompilationCacheEval::Put(Handle<String> source, |
| 287 Handle<Context> context, | 284 Handle<Context> context, |
| 288 Handle<SharedFunctionInfo> function_info, | 285 Handle<SharedFunctionInfo> function_info, |
| 289 int scope_position) { | 286 int scope_position) { |
| 290 HandleScope scope(isolate()); | 287 HandleScope scope(isolate()); |
| 291 Handle<CompilationCacheTable> table = GetFirstTable(); | 288 Handle<CompilationCacheTable> table = GetFirstTable(); |
| 292 table = CompilationCacheTable::PutEval(table, source, context, | 289 table = CompilationCacheTable::PutEval(table, source, context, |
| 293 function_info, scope_position); | 290 function_info, scope_position); |
| 294 SetFirstTable(table); | 291 SetFirstTable(table); |
| 295 } | 292 } |
| 296 | 293 |
| 297 | 294 |
| 298 MaybeHandle<FixedArray> CompilationCacheRegExp::Lookup( | 295 MaybeHandle<FixedArray> CompilationCacheRegExp::Lookup( |
| 299 Handle<String> source, | 296 Handle<String> source, |
| 300 JSRegExp::Flags flags) { | 297 JSRegExp::Flags flags) { |
| 298 HandleScope scope(isolate()); |
| 301 // Make sure not to leak the table into the surrounding handle | 299 // Make sure not to leak the table into the surrounding handle |
| 302 // scope. Otherwise, we risk keeping old tables around even after | 300 // scope. Otherwise, we risk keeping old tables around even after |
| 303 // having cleared the cache. | 301 // having cleared the cache. |
| 304 Handle<Object> result = isolate()->factory()->undefined_value(); | 302 Handle<Object> result = isolate()->factory()->undefined_value(); |
| 305 int generation; | 303 int generation; |
| 306 { HandleScope scope(isolate()); | 304 for (generation = 0; generation < generations(); generation++) { |
| 307 Handle<Object> temp = result; | 305 Handle<CompilationCacheTable> table = GetTable(generation); |
| 308 for (generation = 0; generation < generations(); generation++) { | 306 result = table->LookupRegExp(source, flags); |
| 309 Handle<CompilationCacheTable> table = GetTable(generation); | 307 if (result->IsFixedArray()) break; |
| 310 temp = table->LookupRegExp(source, flags); | |
| 311 if (temp->IsFixedArray()) { | |
| 312 break; | |
| 313 } | |
| 314 } | |
| 315 if (temp->IsSharedFunctionInfo()) result = scope.CloseAndEscape(temp); | |
| 316 } | 308 } |
| 317 if (result->IsFixedArray()) { | 309 if (result->IsFixedArray()) { |
| 318 Handle<FixedArray> data = Handle<FixedArray>::cast(result); | 310 Handle<FixedArray> data = Handle<FixedArray>::cast(result); |
| 319 if (generation != 0) { | 311 if (generation != 0) { |
| 320 Put(source, flags, data); | 312 Put(source, flags, data); |
| 321 } | 313 } |
| 322 isolate()->counters()->compilation_cache_hits()->Increment(); | 314 isolate()->counters()->compilation_cache_hits()->Increment(); |
| 323 return data; | 315 return scope.CloseAndEscape(data); |
| 324 } else { | 316 } else { |
| 325 isolate()->counters()->compilation_cache_misses()->Increment(); | 317 isolate()->counters()->compilation_cache_misses()->Increment(); |
| 326 return MaybeHandle<FixedArray>(); | 318 return MaybeHandle<FixedArray>(); |
| 327 } | 319 } |
| 328 } | 320 } |
| 329 | 321 |
| 330 | 322 |
| 331 void CompilationCacheRegExp::Put(Handle<String> source, | 323 void CompilationCacheRegExp::Put(Handle<String> source, |
| 332 JSRegExp::Flags flags, | 324 JSRegExp::Flags flags, |
| 333 Handle<FixedArray> data) { | 325 Handle<FixedArray> data) { |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 } | 450 } |
| 459 | 451 |
| 460 | 452 |
| 461 void CompilationCache::Disable() { | 453 void CompilationCache::Disable() { |
| 462 enabled_ = false; | 454 enabled_ = false; |
| 463 Clear(); | 455 Clear(); |
| 464 } | 456 } |
| 465 | 457 |
| 466 | 458 |
| 467 } } // namespace v8::internal | 459 } } // namespace v8::internal |
| OLD | NEW |