| 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 #include "src/serialize.h" | 9 #include "src/serialize.h" |
| 10 | 10 |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 Handle<Context> context, | 214 Handle<Context> context, |
| 215 Handle<SharedFunctionInfo> function_info) { | 215 Handle<SharedFunctionInfo> function_info) { |
| 216 HandleScope scope(isolate()); | 216 HandleScope scope(isolate()); |
| 217 Handle<CompilationCacheTable> table = GetFirstTable(); | 217 Handle<CompilationCacheTable> table = GetFirstTable(); |
| 218 SetFirstTable( | 218 SetFirstTable( |
| 219 CompilationCacheTable::Put(table, source, context, function_info)); | 219 CompilationCacheTable::Put(table, source, context, function_info)); |
| 220 } | 220 } |
| 221 | 221 |
| 222 | 222 |
| 223 MaybeHandle<SharedFunctionInfo> CompilationCacheEval::Lookup( | 223 MaybeHandle<SharedFunctionInfo> CompilationCacheEval::Lookup( |
| 224 Handle<String> source, | 224 Handle<String> source, Handle<SharedFunctionInfo> outer_info, |
| 225 Handle<Context> context, | 225 StrictMode strict_mode, int scope_position) { |
| 226 StrictMode strict_mode, | |
| 227 int scope_position) { | |
| 228 HandleScope scope(isolate()); | 226 HandleScope scope(isolate()); |
| 229 // Make sure not to leak the table into the surrounding handle | 227 // Make sure not to leak the table into the surrounding handle |
| 230 // scope. Otherwise, we risk keeping old tables around even after | 228 // scope. Otherwise, we risk keeping old tables around even after |
| 231 // having cleared the cache. | 229 // having cleared the cache. |
| 232 Handle<Object> result = isolate()->factory()->undefined_value(); | 230 Handle<Object> result = isolate()->factory()->undefined_value(); |
| 233 int generation; | 231 int generation; |
| 234 for (generation = 0; generation < generations(); generation++) { | 232 for (generation = 0; generation < generations(); generation++) { |
| 235 Handle<CompilationCacheTable> table = GetTable(generation); | 233 Handle<CompilationCacheTable> table = GetTable(generation); |
| 236 result = table->LookupEval(source, context, strict_mode, scope_position); | 234 result = table->LookupEval(source, outer_info, strict_mode, scope_position); |
| 237 if (result->IsSharedFunctionInfo()) break; | 235 if (result->IsSharedFunctionInfo()) break; |
| 238 } | 236 } |
| 239 if (result->IsSharedFunctionInfo()) { | 237 if (result->IsSharedFunctionInfo()) { |
| 240 Handle<SharedFunctionInfo> function_info = | 238 Handle<SharedFunctionInfo> function_info = |
| 241 Handle<SharedFunctionInfo>::cast(result); | 239 Handle<SharedFunctionInfo>::cast(result); |
| 242 if (generation != 0) { | 240 if (generation != 0) { |
| 243 Put(source, context, function_info, scope_position); | 241 Put(source, outer_info, function_info, scope_position); |
| 244 } | 242 } |
| 245 isolate()->counters()->compilation_cache_hits()->Increment(); | 243 isolate()->counters()->compilation_cache_hits()->Increment(); |
| 246 return scope.CloseAndEscape(function_info); | 244 return scope.CloseAndEscape(function_info); |
| 247 } else { | 245 } else { |
| 248 isolate()->counters()->compilation_cache_misses()->Increment(); | 246 isolate()->counters()->compilation_cache_misses()->Increment(); |
| 249 return MaybeHandle<SharedFunctionInfo>(); | 247 return MaybeHandle<SharedFunctionInfo>(); |
| 250 } | 248 } |
| 251 } | 249 } |
| 252 | 250 |
| 253 | 251 |
| 254 void CompilationCacheEval::Put(Handle<String> source, | 252 void CompilationCacheEval::Put(Handle<String> source, |
| 255 Handle<Context> context, | 253 Handle<SharedFunctionInfo> outer_info, |
| 256 Handle<SharedFunctionInfo> function_info, | 254 Handle<SharedFunctionInfo> function_info, |
| 257 int scope_position) { | 255 int scope_position) { |
| 258 HandleScope scope(isolate()); | 256 HandleScope scope(isolate()); |
| 259 Handle<CompilationCacheTable> table = GetFirstTable(); | 257 Handle<CompilationCacheTable> table = GetFirstTable(); |
| 260 table = CompilationCacheTable::PutEval(table, source, context, | 258 table = CompilationCacheTable::PutEval(table, source, outer_info, |
| 261 function_info, scope_position); | 259 function_info, scope_position); |
| 262 SetFirstTable(table); | 260 SetFirstTable(table); |
| 263 } | 261 } |
| 264 | 262 |
| 265 | 263 |
| 266 MaybeHandle<FixedArray> CompilationCacheRegExp::Lookup( | 264 MaybeHandle<FixedArray> CompilationCacheRegExp::Lookup( |
| 267 Handle<String> source, | 265 Handle<String> source, |
| 268 JSRegExp::Flags flags) { | 266 JSRegExp::Flags flags) { |
| 269 HandleScope scope(isolate()); | 267 HandleScope scope(isolate()); |
| 270 // Make sure not to leak the table into the surrounding handle | 268 // Make sure not to leak the table into the surrounding handle |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 bool is_shared_cross_origin, | 315 bool is_shared_cross_origin, |
| 318 Handle<Context> context) { | 316 Handle<Context> context) { |
| 319 if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>(); | 317 if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>(); |
| 320 | 318 |
| 321 return script_.Lookup(source, name, line_offset, column_offset, | 319 return script_.Lookup(source, name, line_offset, column_offset, |
| 322 is_shared_cross_origin, context); | 320 is_shared_cross_origin, context); |
| 323 } | 321 } |
| 324 | 322 |
| 325 | 323 |
| 326 MaybeHandle<SharedFunctionInfo> CompilationCache::LookupEval( | 324 MaybeHandle<SharedFunctionInfo> CompilationCache::LookupEval( |
| 327 Handle<String> source, | 325 Handle<String> source, Handle<SharedFunctionInfo> outer_info, |
| 328 Handle<Context> context, | 326 Handle<Context> context, StrictMode strict_mode, int scope_position) { |
| 329 StrictMode strict_mode, | |
| 330 int scope_position) { | |
| 331 if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>(); | 327 if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>(); |
| 332 | 328 |
| 333 MaybeHandle<SharedFunctionInfo> result; | 329 MaybeHandle<SharedFunctionInfo> result; |
| 334 if (context->IsNativeContext()) { | 330 if (context->IsNativeContext()) { |
| 335 result = eval_global_.Lookup( | 331 result = |
| 336 source, context, strict_mode, scope_position); | 332 eval_global_.Lookup(source, outer_info, strict_mode, scope_position); |
| 337 } else { | 333 } else { |
| 338 DCHECK(scope_position != RelocInfo::kNoPosition); | 334 DCHECK(scope_position != RelocInfo::kNoPosition); |
| 339 result = eval_contextual_.Lookup( | 335 result = eval_contextual_.Lookup(source, outer_info, strict_mode, |
| 340 source, context, strict_mode, scope_position); | 336 scope_position); |
| 341 } | 337 } |
| 342 return result; | 338 return result; |
| 343 } | 339 } |
| 344 | 340 |
| 345 | 341 |
| 346 MaybeHandle<FixedArray> CompilationCache::LookupRegExp(Handle<String> source, | 342 MaybeHandle<FixedArray> CompilationCache::LookupRegExp(Handle<String> source, |
| 347 JSRegExp::Flags flags) { | 343 JSRegExp::Flags flags) { |
| 348 if (!IsEnabled()) return MaybeHandle<FixedArray>(); | 344 if (!IsEnabled()) return MaybeHandle<FixedArray>(); |
| 349 | 345 |
| 350 return reg_exp_.Lookup(source, flags); | 346 return reg_exp_.Lookup(source, flags); |
| 351 } | 347 } |
| 352 | 348 |
| 353 | 349 |
| 354 void CompilationCache::PutScript(Handle<String> source, | 350 void CompilationCache::PutScript(Handle<String> source, |
| 355 Handle<Context> context, | 351 Handle<Context> context, |
| 356 Handle<SharedFunctionInfo> function_info) { | 352 Handle<SharedFunctionInfo> function_info) { |
| 357 if (!IsEnabled()) return; | 353 if (!IsEnabled()) return; |
| 358 | 354 |
| 359 script_.Put(source, context, function_info); | 355 script_.Put(source, context, function_info); |
| 360 } | 356 } |
| 361 | 357 |
| 362 | 358 |
| 363 void CompilationCache::PutEval(Handle<String> source, | 359 void CompilationCache::PutEval(Handle<String> source, |
| 360 Handle<SharedFunctionInfo> outer_info, |
| 364 Handle<Context> context, | 361 Handle<Context> context, |
| 365 Handle<SharedFunctionInfo> function_info, | 362 Handle<SharedFunctionInfo> function_info, |
| 366 int scope_position) { | 363 int scope_position) { |
| 367 if (!IsEnabled()) return; | 364 if (!IsEnabled()) return; |
| 368 | 365 |
| 369 HandleScope scope(isolate()); | 366 HandleScope scope(isolate()); |
| 370 if (context->IsNativeContext()) { | 367 if (context->IsNativeContext()) { |
| 371 eval_global_.Put(source, context, function_info, scope_position); | 368 eval_global_.Put(source, outer_info, function_info, scope_position); |
| 372 } else { | 369 } else { |
| 373 DCHECK(scope_position != RelocInfo::kNoPosition); | 370 DCHECK(scope_position != RelocInfo::kNoPosition); |
| 374 eval_contextual_.Put(source, context, function_info, scope_position); | 371 eval_contextual_.Put(source, outer_info, function_info, scope_position); |
| 375 } | 372 } |
| 376 } | 373 } |
| 377 | 374 |
| 378 | 375 |
| 379 | 376 |
| 380 void CompilationCache::PutRegExp(Handle<String> source, | 377 void CompilationCache::PutRegExp(Handle<String> source, |
| 381 JSRegExp::Flags flags, | 378 JSRegExp::Flags flags, |
| 382 Handle<FixedArray> data) { | 379 Handle<FixedArray> data) { |
| 383 if (!IsEnabled()) { | 380 if (!IsEnabled()) { |
| 384 return; | 381 return; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 } | 418 } |
| 422 | 419 |
| 423 | 420 |
| 424 void CompilationCache::Disable() { | 421 void CompilationCache::Disable() { |
| 425 enabled_ = false; | 422 enabled_ = false; |
| 426 Clear(); | 423 Clear(); |
| 427 } | 424 } |
| 428 | 425 |
| 429 | 426 |
| 430 } } // namespace v8::internal | 427 } } // namespace v8::internal |
| OLD | NEW |