Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
|
Jakob Kummerow
2011/11/10 11:53:23
2011
Steven
2011/11/14 08:57:21
Done.
| |
| 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 |
| 11 // with the distribution. | 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
| 15 // | 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include "v8.h" | 28 #include "v8.h" |
| 29 | 29 |
| 30 #include "assembler.h" | |
| 30 #include "compilation-cache.h" | 31 #include "compilation-cache.h" |
| 31 #include "serialize.h" | 32 #include "serialize.h" |
| 32 | 33 |
| 33 namespace v8 { | 34 namespace v8 { |
| 34 namespace internal { | 35 namespace internal { |
| 35 | 36 |
| 36 | 37 |
| 37 // The number of generations for each sub cache. | 38 // The number of generations for each sub cache. |
| 38 // The number of ScriptGenerations is carefully chosen based on histograms. | 39 // The number of ScriptGenerations is carefully chosen based on histograms. |
| 39 // See issue 458: http://code.google.com/p/v8/issues/detail?id=458 | 40 // See issue 458: http://code.google.com/p/v8/issues/detail?id=458 |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 void CompilationCacheScript::Put(Handle<String> source, | 244 void CompilationCacheScript::Put(Handle<String> source, |
| 244 Handle<SharedFunctionInfo> function_info) { | 245 Handle<SharedFunctionInfo> function_info) { |
| 245 HandleScope scope(isolate()); | 246 HandleScope scope(isolate()); |
| 246 SetFirstTable(TablePut(source, function_info)); | 247 SetFirstTable(TablePut(source, function_info)); |
| 247 } | 248 } |
| 248 | 249 |
| 249 | 250 |
| 250 Handle<SharedFunctionInfo> CompilationCacheEval::Lookup( | 251 Handle<SharedFunctionInfo> CompilationCacheEval::Lookup( |
| 251 Handle<String> source, | 252 Handle<String> source, |
| 252 Handle<Context> context, | 253 Handle<Context> context, |
| 253 StrictModeFlag strict_mode) { | 254 StrictModeFlag strict_mode, |
| 255 int scope_position) { | |
| 254 // Make sure not to leak the table into the surrounding handle | 256 // Make sure not to leak the table into the surrounding handle |
| 255 // scope. Otherwise, we risk keeping old tables around even after | 257 // scope. Otherwise, we risk keeping old tables around even after |
| 256 // having cleared the cache. | 258 // having cleared the cache. |
| 257 Object* result = NULL; | 259 Object* result = NULL; |
| 258 int generation; | 260 int generation; |
| 259 { HandleScope scope(isolate()); | 261 { HandleScope scope(isolate()); |
| 260 for (generation = 0; generation < generations(); generation++) { | 262 for (generation = 0; generation < generations(); generation++) { |
| 261 Handle<CompilationCacheTable> table = GetTable(generation); | 263 Handle<CompilationCacheTable> table = GetTable(generation); |
| 262 result = table->LookupEval(*source, *context, strict_mode); | 264 result = table->LookupEval( |
| 265 *source, *context, strict_mode, scope_position); | |
| 263 if (result->IsSharedFunctionInfo()) { | 266 if (result->IsSharedFunctionInfo()) { |
| 264 break; | 267 break; |
| 265 } | 268 } |
| 266 } | 269 } |
| 267 } | 270 } |
| 268 if (result->IsSharedFunctionInfo()) { | 271 if (result->IsSharedFunctionInfo()) { |
| 269 Handle<SharedFunctionInfo> | 272 Handle<SharedFunctionInfo> |
| 270 function_info(SharedFunctionInfo::cast(result), isolate()); | 273 function_info(SharedFunctionInfo::cast(result), isolate()); |
| 271 if (generation != 0) { | 274 if (generation != 0) { |
| 272 Put(source, context, function_info); | 275 Put(source, context, function_info, scope_position); |
| 273 } | 276 } |
| 274 isolate()->counters()->compilation_cache_hits()->Increment(); | 277 isolate()->counters()->compilation_cache_hits()->Increment(); |
| 275 return function_info; | 278 return function_info; |
| 276 } else { | 279 } else { |
| 277 isolate()->counters()->compilation_cache_misses()->Increment(); | 280 isolate()->counters()->compilation_cache_misses()->Increment(); |
| 278 return Handle<SharedFunctionInfo>::null(); | 281 return Handle<SharedFunctionInfo>::null(); |
| 279 } | 282 } |
| 280 } | 283 } |
| 281 | 284 |
| 282 | 285 |
| 283 MaybeObject* CompilationCacheEval::TryTablePut( | 286 MaybeObject* CompilationCacheEval::TryTablePut( |
| 284 Handle<String> source, | 287 Handle<String> source, |
| 285 Handle<Context> context, | 288 Handle<Context> context, |
| 286 Handle<SharedFunctionInfo> function_info) { | 289 Handle<SharedFunctionInfo> function_info, |
| 290 int scope_position) { | |
| 287 Handle<CompilationCacheTable> table = GetFirstTable(); | 291 Handle<CompilationCacheTable> table = GetFirstTable(); |
| 288 return table->PutEval(*source, *context, *function_info); | 292 return table->PutEval(*source, *context, *function_info, scope_position); |
| 289 } | 293 } |
| 290 | 294 |
| 291 | 295 |
| 292 Handle<CompilationCacheTable> CompilationCacheEval::TablePut( | 296 Handle<CompilationCacheTable> CompilationCacheEval::TablePut( |
| 293 Handle<String> source, | 297 Handle<String> source, |
| 294 Handle<Context> context, | 298 Handle<Context> context, |
| 295 Handle<SharedFunctionInfo> function_info) { | 299 Handle<SharedFunctionInfo> function_info, |
| 300 int scope_position) { | |
| 296 CALL_HEAP_FUNCTION(isolate(), | 301 CALL_HEAP_FUNCTION(isolate(), |
| 297 TryTablePut(source, context, function_info), | 302 TryTablePut( |
| 303 source, context, function_info, scope_position), | |
| 298 CompilationCacheTable); | 304 CompilationCacheTable); |
| 299 } | 305 } |
| 300 | 306 |
| 301 | 307 |
| 302 void CompilationCacheEval::Put(Handle<String> source, | 308 void CompilationCacheEval::Put(Handle<String> source, |
| 303 Handle<Context> context, | 309 Handle<Context> context, |
| 304 Handle<SharedFunctionInfo> function_info) { | 310 Handle<SharedFunctionInfo> function_info, |
| 311 int scope_position) { | |
| 305 HandleScope scope(isolate()); | 312 HandleScope scope(isolate()); |
| 306 SetFirstTable(TablePut(source, context, function_info)); | 313 SetFirstTable(TablePut(source, context, function_info, scope_position)); |
| 307 } | 314 } |
| 308 | 315 |
| 309 | 316 |
| 310 Handle<FixedArray> CompilationCacheRegExp::Lookup(Handle<String> source, | 317 Handle<FixedArray> CompilationCacheRegExp::Lookup(Handle<String> source, |
| 311 JSRegExp::Flags flags) { | 318 JSRegExp::Flags flags) { |
| 312 // Make sure not to leak the table into the surrounding handle | 319 // Make sure not to leak the table into the surrounding handle |
| 313 // scope. Otherwise, we risk keeping old tables around even after | 320 // scope. Otherwise, we risk keeping old tables around even after |
| 314 // having cleared the cache. | 321 // having cleared the cache. |
| 315 Object* result = NULL; | 322 Object* result = NULL; |
| 316 int generation; | 323 int generation; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 } | 389 } |
| 383 | 390 |
| 384 return script_.Lookup(source, name, line_offset, column_offset); | 391 return script_.Lookup(source, name, line_offset, column_offset); |
| 385 } | 392 } |
| 386 | 393 |
| 387 | 394 |
| 388 Handle<SharedFunctionInfo> CompilationCache::LookupEval( | 395 Handle<SharedFunctionInfo> CompilationCache::LookupEval( |
| 389 Handle<String> source, | 396 Handle<String> source, |
| 390 Handle<Context> context, | 397 Handle<Context> context, |
| 391 bool is_global, | 398 bool is_global, |
| 392 StrictModeFlag strict_mode) { | 399 StrictModeFlag strict_mode, |
| 400 int scope_position) { | |
| 393 if (!IsEnabled()) { | 401 if (!IsEnabled()) { |
| 394 return Handle<SharedFunctionInfo>::null(); | 402 return Handle<SharedFunctionInfo>::null(); |
| 395 } | 403 } |
| 396 | 404 |
| 397 Handle<SharedFunctionInfo> result; | 405 Handle<SharedFunctionInfo> result; |
| 398 if (is_global) { | 406 if (is_global) { |
| 399 result = eval_global_.Lookup(source, context, strict_mode); | 407 result = eval_global_.Lookup(source, context, strict_mode, scope_position); |
| 400 } else { | 408 } else { |
| 401 result = eval_contextual_.Lookup(source, context, strict_mode); | 409 ASSERT(scope_position != RelocInfo::kNoPosition); |
| 410 result = eval_contextual_.Lookup( | |
| 411 source, context, strict_mode, scope_position); | |
| 402 } | 412 } |
| 403 return result; | 413 return result; |
| 404 } | 414 } |
| 405 | 415 |
| 406 | 416 |
| 407 Handle<FixedArray> CompilationCache::LookupRegExp(Handle<String> source, | 417 Handle<FixedArray> CompilationCache::LookupRegExp(Handle<String> source, |
| 408 JSRegExp::Flags flags) { | 418 JSRegExp::Flags flags) { |
| 409 if (!IsEnabled()) { | 419 if (!IsEnabled()) { |
| 410 return Handle<FixedArray>::null(); | 420 return Handle<FixedArray>::null(); |
| 411 } | 421 } |
| 412 | 422 |
| 413 return reg_exp_.Lookup(source, flags); | 423 return reg_exp_.Lookup(source, flags); |
| 414 } | 424 } |
| 415 | 425 |
| 416 | 426 |
| 417 void CompilationCache::PutScript(Handle<String> source, | 427 void CompilationCache::PutScript(Handle<String> source, |
| 418 Handle<SharedFunctionInfo> function_info) { | 428 Handle<SharedFunctionInfo> function_info) { |
| 419 if (!IsEnabled()) { | 429 if (!IsEnabled()) { |
| 420 return; | 430 return; |
| 421 } | 431 } |
| 422 | 432 |
| 423 script_.Put(source, function_info); | 433 script_.Put(source, function_info); |
| 424 } | 434 } |
| 425 | 435 |
| 426 | 436 |
| 427 void CompilationCache::PutEval(Handle<String> source, | 437 void CompilationCache::PutEval(Handle<String> source, |
| 428 Handle<Context> context, | 438 Handle<Context> context, |
| 429 bool is_global, | 439 bool is_global, |
| 430 Handle<SharedFunctionInfo> function_info) { | 440 Handle<SharedFunctionInfo> function_info, |
| 441 int scope_position) { | |
| 431 if (!IsEnabled()) { | 442 if (!IsEnabled()) { |
| 432 return; | 443 return; |
| 433 } | 444 } |
| 434 | 445 |
| 435 HandleScope scope(isolate()); | 446 HandleScope scope(isolate()); |
| 436 if (is_global) { | 447 if (is_global) { |
| 437 eval_global_.Put(source, context, function_info); | 448 eval_global_.Put(source, context, function_info, scope_position); |
| 438 } else { | 449 } else { |
| 439 eval_contextual_.Put(source, context, function_info); | 450 ASSERT(scope_position != RelocInfo::kNoPosition); |
| 451 eval_contextual_.Put(source, context, function_info, scope_position); | |
| 440 } | 452 } |
| 441 } | 453 } |
| 442 | 454 |
| 443 | 455 |
| 444 | 456 |
| 445 void CompilationCache::PutRegExp(Handle<String> source, | 457 void CompilationCache::PutRegExp(Handle<String> source, |
| 446 JSRegExp::Flags flags, | 458 JSRegExp::Flags flags, |
| 447 Handle<FixedArray> data) { | 459 Handle<FixedArray> data) { |
| 448 if (!IsEnabled()) { | 460 if (!IsEnabled()) { |
| 449 return; | 461 return; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 486 } | 498 } |
| 487 | 499 |
| 488 | 500 |
| 489 void CompilationCache::Disable() { | 501 void CompilationCache::Disable() { |
| 490 enabled_ = false; | 502 enabled_ = false; |
| 491 Clear(); | 503 Clear(); |
| 492 } | 504 } |
| 493 | 505 |
| 494 | 506 |
| 495 } } // namespace v8::internal | 507 } } // namespace v8::internal |
| OLD | NEW |