OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 | 340 |
341 CompileRun("%OptimizeFunctionOnNextCall(f); f(fun1);"); | 341 CompileRun("%OptimizeFunctionOnNextCall(f); f(fun1);"); |
342 | 342 |
343 // Verify that the feedback is still "gathered" despite a recompilation | 343 // Verify that the feedback is still "gathered" despite a recompilation |
344 // of the full code. | 344 // of the full code. |
345 CHECK(f->shared()->has_deoptimization_support()); | 345 CHECK(f->shared()->has_deoptimization_support()); |
346 CHECK(f->shared()->feedback_vector()->get(0)->IsJSFunction()); | 346 CHECK(f->shared()->feedback_vector()->get(0)->IsJSFunction()); |
347 } | 347 } |
348 | 348 |
349 | 349 |
| 350 TEST(FeedbackVectorRecreatedOnScopeChanges) { |
| 351 if (i::FLAG_always_opt || !i::FLAG_lazy) return; |
| 352 CcTest::InitializeVM(); |
| 353 v8::HandleScope scope(CcTest::isolate()); |
| 354 |
| 355 CompileRun("function builder() {" |
| 356 " call_target = function() { return 3; };" |
| 357 " return (function() {" |
| 358 " eval('');" |
| 359 " return function() {" |
| 360 " 'use strict';" |
| 361 " call_target();" |
| 362 " }" |
| 363 " })();" |
| 364 "}" |
| 365 "morphing_call = builder();"); |
| 366 |
| 367 Handle<JSFunction> f = |
| 368 v8::Utils::OpenHandle( |
| 369 *v8::Handle<v8::Function>::Cast( |
| 370 CcTest::global()->Get(v8_str("morphing_call")))); |
| 371 |
| 372 // morphing_call should have one feedback vector slot for the call to |
| 373 // call_target(), scoping analysis having been performed. |
| 374 CHECK_EQ(1, f->shared()->feedback_vector()->length()); |
| 375 // And yet it's not compiled. |
| 376 CHECK(!f->shared()->is_compiled()); |
| 377 |
| 378 CompileRun("morphing_call();"); |
| 379 |
| 380 // On scoping analysis after lazy compile, the call is now a global |
| 381 // call which needs no feedback vector slot. |
| 382 CHECK_EQ(0, f->shared()->feedback_vector()->length()); |
| 383 CHECK(f->shared()->is_compiled()); |
| 384 } |
| 385 |
| 386 |
350 // Test that optimized code for different closures is actually shared | 387 // Test that optimized code for different closures is actually shared |
351 // immediately by the FastNewClosureStub when run in the same context. | 388 // immediately by the FastNewClosureStub when run in the same context. |
352 TEST(OptimizedCodeSharing) { | 389 TEST(OptimizedCodeSharing) { |
353 // Skip test if --cache-optimized-code is not activated by default because | 390 // Skip test if --cache-optimized-code is not activated by default because |
354 // FastNewClosureStub that is baked into the snapshot is incorrect. | 391 // FastNewClosureStub that is baked into the snapshot is incorrect. |
355 if (!FLAG_cache_optimized_code) return; | 392 if (!FLAG_cache_optimized_code) return; |
356 FLAG_stress_compaction = false; | 393 FLAG_stress_compaction = false; |
357 FLAG_allow_natives_syntax = true; | 394 FLAG_allow_natives_syntax = true; |
358 CcTest::InitializeVM(); | 395 CcTest::InitializeVM(); |
359 v8::HandleScope scope(CcTest::isolate()); | 396 v8::HandleScope scope(CcTest::isolate()); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 CompileRun("function f() { a = 12345678 }; f();"); | 465 CompileRun("function f() { a = 12345678 }; f();"); |
429 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 466 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
430 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); | 467 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); |
431 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 468 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
432 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); | 469 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); |
433 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 470 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
434 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); | 471 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); |
435 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 472 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
436 } | 473 } |
437 #endif | 474 #endif |
OLD | NEW |