| 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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 v8::Utils::OpenHandle( | 306 v8::Utils::OpenHandle( |
| 307 *v8::Handle<v8::Function>::Cast( | 307 *v8::Handle<v8::Function>::Cast( |
| 308 CcTest::global()->Get(v8_str("f")))); | 308 CcTest::global()->Get(v8_str("f")))); |
| 309 | 309 |
| 310 // We shouldn't have deoptimization support. We want to recompile and | 310 // We shouldn't have deoptimization support. We want to recompile and |
| 311 // verify that our feedback vector preserves information. | 311 // verify that our feedback vector preserves information. |
| 312 CHECK(!f->shared()->has_deoptimization_support()); | 312 CHECK(!f->shared()->has_deoptimization_support()); |
| 313 Handle<FixedArray> feedback_vector(f->shared()->feedback_vector()); | 313 Handle<FixedArray> feedback_vector(f->shared()->feedback_vector()); |
| 314 | 314 |
| 315 // Verify that we gathered feedback. | 315 // Verify that we gathered feedback. |
| 316 CHECK_EQ(1, feedback_vector->length()); | 316 int expected_count = FLAG_vector_ics ? 2 : 1; |
| 317 CHECK(feedback_vector->get(0)->IsJSFunction()); | 317 CHECK_EQ(expected_count, feedback_vector->length()); |
| 318 CHECK(feedback_vector->get(expected_count - 1)->IsJSFunction()); |
| 318 | 319 |
| 319 CompileRun("%OptimizeFunctionOnNextCall(f); f(fun1);"); | 320 CompileRun("%OptimizeFunctionOnNextCall(f); f(fun1);"); |
| 320 | 321 |
| 321 // Verify that the feedback is still "gathered" despite a recompilation | 322 // Verify that the feedback is still "gathered" despite a recompilation |
| 322 // of the full code. | 323 // of the full code. |
| 323 CHECK(f->IsOptimized()); | 324 CHECK(f->IsOptimized()); |
| 324 CHECK(f->shared()->has_deoptimization_support()); | 325 CHECK(f->shared()->has_deoptimization_support()); |
| 325 CHECK(f->shared()->feedback_vector()->get(0)->IsJSFunction()); | 326 CHECK(f->shared()->feedback_vector()-> |
| 327 get(expected_count - 1)->IsJSFunction()); |
| 326 } | 328 } |
| 327 | 329 |
| 328 | 330 |
| 329 TEST(FeedbackVectorUnaffectedByScopeChanges) { | 331 TEST(FeedbackVectorUnaffectedByScopeChanges) { |
| 330 if (i::FLAG_always_opt || !i::FLAG_lazy) return; | 332 if (i::FLAG_always_opt || !i::FLAG_lazy) return; |
| 331 CcTest::InitializeVM(); | 333 CcTest::InitializeVM(); |
| 332 v8::HandleScope scope(CcTest::isolate()); | 334 v8::HandleScope scope(CcTest::isolate()); |
| 333 | 335 |
| 334 CompileRun("function builder() {" | 336 CompileRun("function builder() {" |
| 335 " call_target = function() { return 3; };" | 337 " call_target = function() { return 3; };" |
| 336 " return (function() {" | 338 " return (function() {" |
| 337 " eval('');" | 339 " eval('');" |
| 338 " return function() {" | 340 " return function() {" |
| 339 " 'use strict';" | 341 " 'use strict';" |
| 340 " call_target();" | 342 " call_target();" |
| 341 " }" | 343 " }" |
| 342 " })();" | 344 " })();" |
| 343 "}" | 345 "}" |
| 344 "morphing_call = builder();"); | 346 "morphing_call = builder();"); |
| 345 | 347 |
| 346 Handle<JSFunction> f = | 348 Handle<JSFunction> f = |
| 347 v8::Utils::OpenHandle( | 349 v8::Utils::OpenHandle( |
| 348 *v8::Handle<v8::Function>::Cast( | 350 *v8::Handle<v8::Function>::Cast( |
| 349 CcTest::global()->Get(v8_str("morphing_call")))); | 351 CcTest::global()->Get(v8_str("morphing_call")))); |
| 350 | 352 |
| 351 // morphing_call should have one feedback vector slot for the call to | 353 int expected_count = FLAG_vector_ics ? 2 : 1; |
| 352 // call_target(). | 354 CHECK_EQ(expected_count, f->shared()->feedback_vector()->length()); |
| 353 CHECK_EQ(1, f->shared()->feedback_vector()->length()); | |
| 354 // And yet it's not compiled. | 355 // And yet it's not compiled. |
| 355 CHECK(!f->shared()->is_compiled()); | 356 CHECK(!f->shared()->is_compiled()); |
| 356 | 357 |
| 357 CompileRun("morphing_call();"); | 358 CompileRun("morphing_call();"); |
| 358 | 359 |
| 359 // The vector should have the same size despite the new scoping. | 360 // The vector should have the same size despite the new scoping. |
| 360 CHECK_EQ(1, f->shared()->feedback_vector()->length()); | 361 CHECK_EQ(expected_count, f->shared()->feedback_vector()->length()); |
| 361 CHECK(f->shared()->is_compiled()); | 362 CHECK(f->shared()->is_compiled()); |
| 362 } | 363 } |
| 363 | 364 |
| 364 | 365 |
| 365 // Test that optimized code for different closures is actually shared | 366 // Test that optimized code for different closures is actually shared |
| 366 // immediately by the FastNewClosureStub when run in the same context. | 367 // immediately by the FastNewClosureStub when run in the same context. |
| 367 TEST(OptimizedCodeSharing) { | 368 TEST(OptimizedCodeSharing) { |
| 368 // Skip test if --cache-optimized-code is not activated by default because | 369 // Skip test if --cache-optimized-code is not activated by default because |
| 369 // FastNewClosureStub that is baked into the snapshot is incorrect. | 370 // FastNewClosureStub that is baked into the snapshot is incorrect. |
| 370 if (!FLAG_cache_optimized_code) return; | 371 if (!FLAG_cache_optimized_code) return; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 CompileRun("function f() { a = 12345678 }; f();"); | 444 CompileRun("function f() { a = 12345678 }; f();"); |
| 444 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 445 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
| 445 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); | 446 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); |
| 446 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 447 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
| 447 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); | 448 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); |
| 448 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 449 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
| 449 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); | 450 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); |
| 450 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 451 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
| 451 } | 452 } |
| 452 #endif | 453 #endif |
| OLD | NEW |