| 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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 CHECK(!f->shared()->is_compiled()); | 357 CHECK(!f->shared()->is_compiled()); |
| 358 CHECK(f->shared()->feedback_vector()->is_empty()); | 358 CHECK(f->shared()->feedback_vector()->is_empty()); |
| 359 | 359 |
| 360 CompileRun("morphing_call();"); | 360 CompileRun("morphing_call();"); |
| 361 | 361 |
| 362 // Now a feedback vector is allocated. | 362 // Now a feedback vector is allocated. |
| 363 CHECK(f->shared()->is_compiled()); | 363 CHECK(f->shared()->is_compiled()); |
| 364 CHECK(!f->shared()->feedback_vector()->is_empty()); | 364 CHECK(!f->shared()->feedback_vector()->is_empty()); |
| 365 } | 365 } |
| 366 | 366 |
| 367 // Test that optimized code for different closures is actually shared. | 367 |
| 368 // Test that optimized code for different closures is actually shared |
| 369 // immediately by the FastNewClosureStub when run in the same context. |
| 368 TEST(OptimizedCodeSharing1) { | 370 TEST(OptimizedCodeSharing1) { |
| 369 FLAG_stress_compaction = false; | 371 FLAG_stress_compaction = false; |
| 370 FLAG_allow_natives_syntax = true; | 372 FLAG_allow_natives_syntax = true; |
| 371 CcTest::InitializeVM(); | 373 CcTest::InitializeVM(); |
| 372 v8::HandleScope scope(CcTest::isolate()); | 374 v8::HandleScope scope(CcTest::isolate()); |
| 373 for (int i = 0; i < 3; i++) { | 375 for (int i = 0; i < 3; i++) { |
| 374 LocalContext env; | 376 LocalContext env; |
| 375 env->Global() | 377 env->Global() |
| 376 ->Set(env.local(), v8_str("x"), v8::Integer::New(CcTest::isolate(), i)) | 378 ->Set(env.local(), v8_str("x"), v8::Integer::New(CcTest::isolate(), i)) |
| 377 .FromJust(); | 379 .FromJust(); |
| 378 CompileRun( | 380 CompileRun( |
| 379 "function MakeClosure() {" | 381 "function MakeClosure() {" |
| 380 " return function() { return x; };" | 382 " return function() { return x; };" |
| 381 "}" | 383 "}" |
| 382 "var closure0 = MakeClosure();" | 384 "var closure0 = MakeClosure();" |
| 383 "%DebugPrint(closure0());" | 385 "%DebugPrint(closure0());" |
| 384 "%OptimizeFunctionOnNextCall(closure0);" | 386 "%OptimizeFunctionOnNextCall(closure0);" |
| 385 "%DebugPrint(closure0());" | 387 "%DebugPrint(closure0());" |
| 386 "var closure1 = MakeClosure(); closure1();" | 388 "var closure1 = MakeClosure();" |
| 387 "var closure2 = MakeClosure(); closure2();"); | 389 "var closure2 = MakeClosure();"); |
| 388 Handle<JSFunction> fun1 = Handle<JSFunction>::cast( | 390 Handle<JSFunction> fun1 = Handle<JSFunction>::cast( |
| 389 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 391 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
| 390 env->Global() | 392 env->Global() |
| 391 ->Get(env.local(), v8_str("closure1")) | 393 ->Get(env.local(), v8_str("closure1")) |
| 392 .ToLocalChecked()))); | 394 .ToLocalChecked()))); |
| 393 Handle<JSFunction> fun2 = Handle<JSFunction>::cast( | 395 Handle<JSFunction> fun2 = Handle<JSFunction>::cast( |
| 394 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 396 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
| 395 env->Global() | 397 env->Global() |
| 396 ->Get(env.local(), v8_str("closure2")) | 398 ->Get(env.local(), v8_str("closure2")) |
| 397 .ToLocalChecked()))); | 399 .ToLocalChecked()))); |
| 398 CHECK(fun1->IsOptimized() || !CcTest::i_isolate()->use_crankshaft()); | 400 CHECK(fun1->IsOptimized() || !CcTest::i_isolate()->use_crankshaft()); |
| 399 CHECK(fun2->IsOptimized() || !CcTest::i_isolate()->use_crankshaft()); | 401 CHECK(fun2->IsOptimized() || !CcTest::i_isolate()->use_crankshaft()); |
| 400 CHECK_EQ(fun1->code(), fun2->code()); | 402 CHECK_EQ(fun1->code(), fun2->code()); |
| 401 } | 403 } |
| 402 } | 404 } |
| 403 | 405 |
| 404 // Test that optimized code for different closures is actually shared. | 406 |
| 407 // Test that optimized code for different closures is actually shared |
| 408 // immediately by the FastNewClosureStub when run different contexts. |
| 405 TEST(OptimizedCodeSharing2) { | 409 TEST(OptimizedCodeSharing2) { |
| 406 if (FLAG_stress_compaction) return; | 410 if (FLAG_stress_compaction) return; |
| 407 FLAG_allow_natives_syntax = true; | 411 FLAG_allow_natives_syntax = true; |
| 408 FLAG_native_context_specialization = false; | 412 FLAG_native_context_specialization = false; |
| 409 FLAG_turbo_cache_shared_code = true; | 413 FLAG_turbo_cache_shared_code = true; |
| 410 const char* flag = "--turbo-filter=*"; | 414 const char* flag = "--turbo-filter=*"; |
| 411 FlagList::SetFlagsFromString(flag, StrLength(flag)); | 415 FlagList::SetFlagsFromString(flag, StrLength(flag)); |
| 412 CcTest::InitializeVM(); | 416 CcTest::InitializeVM(); |
| 413 v8::HandleScope scope(CcTest::isolate()); | 417 v8::HandleScope scope(CcTest::isolate()); |
| 414 v8::Local<v8::Script> script = v8_compile( | 418 v8::Local<v8::Script> script = v8_compile( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 445 .FromJust(); | 449 .FromJust(); |
| 446 script->GetUnboundScript() | 450 script->GetUnboundScript() |
| 447 ->BindToCurrentContext() | 451 ->BindToCurrentContext() |
| 448 ->Run(env.local()) | 452 ->Run(env.local()) |
| 449 .ToLocalChecked(); | 453 .ToLocalChecked(); |
| 450 CompileRun( | 454 CompileRun( |
| 451 "var closure0 = MakeClosure();" | 455 "var closure0 = MakeClosure();" |
| 452 "%DebugPrint(closure0());" | 456 "%DebugPrint(closure0());" |
| 453 "%OptimizeFunctionOnNextCall(closure0);" | 457 "%OptimizeFunctionOnNextCall(closure0);" |
| 454 "%DebugPrint(closure0());" | 458 "%DebugPrint(closure0());" |
| 455 "var closure1 = MakeClosure(); closure1();" | 459 "var closure1 = MakeClosure();" |
| 456 "var closure2 = MakeClosure(); closure2();"); | 460 "var closure2 = MakeClosure();"); |
| 457 Handle<JSFunction> fun1 = Handle<JSFunction>::cast( | 461 Handle<JSFunction> fun1 = Handle<JSFunction>::cast( |
| 458 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 462 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
| 459 env->Global() | 463 env->Global() |
| 460 ->Get(env.local(), v8_str("closure1")) | 464 ->Get(env.local(), v8_str("closure1")) |
| 461 .ToLocalChecked()))); | 465 .ToLocalChecked()))); |
| 462 Handle<JSFunction> fun2 = Handle<JSFunction>::cast( | 466 Handle<JSFunction> fun2 = Handle<JSFunction>::cast( |
| 463 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 467 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
| 464 env->Global() | 468 env->Global() |
| 465 ->Get(env.local(), v8_str("closure2")) | 469 ->Get(env.local(), v8_str("closure2")) |
| 466 .ToLocalChecked()))); | 470 .ToLocalChecked()))); |
| 467 CHECK(fun1->IsOptimized() || !CcTest::i_isolate()->use_crankshaft()); | 471 CHECK(fun1->IsOptimized() || !CcTest::i_isolate()->use_crankshaft()); |
| 468 CHECK(fun2->IsOptimized() || !CcTest::i_isolate()->use_crankshaft()); | 472 CHECK(fun2->IsOptimized() || !CcTest::i_isolate()->use_crankshaft()); |
| 469 CHECK_EQ(*reference_code, fun1->code()); | 473 CHECK_EQ(*reference_code, fun1->code()); |
| 470 CHECK_EQ(*reference_code, fun2->code()); | 474 CHECK_EQ(*reference_code, fun2->code()); |
| 471 } | 475 } |
| 472 } | 476 } |
| 473 | 477 |
| 474 // Test that optimized code for different closures is actually shared. | 478 |
| 479 // Test that optimized code for different closures is actually shared |
| 480 // immediately by the FastNewClosureStub without context-dependent entries. |
| 475 TEST(OptimizedCodeSharing3) { | 481 TEST(OptimizedCodeSharing3) { |
| 476 if (FLAG_stress_compaction) return; | 482 if (FLAG_stress_compaction) return; |
| 477 FLAG_allow_natives_syntax = true; | 483 FLAG_allow_natives_syntax = true; |
| 478 FLAG_native_context_specialization = false; | 484 FLAG_native_context_specialization = false; |
| 479 FLAG_turbo_cache_shared_code = true; | 485 FLAG_turbo_cache_shared_code = true; |
| 480 const char* flag = "--turbo-filter=*"; | 486 const char* flag = "--turbo-filter=*"; |
| 481 FlagList::SetFlagsFromString(flag, StrLength(flag)); | 487 FlagList::SetFlagsFromString(flag, StrLength(flag)); |
| 482 CcTest::InitializeVM(); | 488 CcTest::InitializeVM(); |
| 483 v8::HandleScope scope(CcTest::isolate()); | 489 v8::HandleScope scope(CcTest::isolate()); |
| 484 v8::Local<v8::Script> script = v8_compile( | 490 v8::Local<v8::Script> script = v8_compile( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 .FromJust(); | 524 .FromJust(); |
| 519 script->GetUnboundScript() | 525 script->GetUnboundScript() |
| 520 ->BindToCurrentContext() | 526 ->BindToCurrentContext() |
| 521 ->Run(env.local()) | 527 ->Run(env.local()) |
| 522 .ToLocalChecked(); | 528 .ToLocalChecked(); |
| 523 CompileRun( | 529 CompileRun( |
| 524 "var closure0 = MakeClosure();" | 530 "var closure0 = MakeClosure();" |
| 525 "%DebugPrint(closure0());" | 531 "%DebugPrint(closure0());" |
| 526 "%OptimizeFunctionOnNextCall(closure0);" | 532 "%OptimizeFunctionOnNextCall(closure0);" |
| 527 "%DebugPrint(closure0());" | 533 "%DebugPrint(closure0());" |
| 528 "var closure1 = MakeClosure(); closure1();" | 534 "var closure1 = MakeClosure();" |
| 529 "var closure2 = MakeClosure(); closure2();"); | 535 "var closure2 = MakeClosure();"); |
| 530 Handle<JSFunction> fun1 = Handle<JSFunction>::cast( | 536 Handle<JSFunction> fun1 = Handle<JSFunction>::cast( |
| 531 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 537 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
| 532 env->Global() | 538 env->Global() |
| 533 ->Get(env.local(), v8_str("closure1")) | 539 ->Get(env.local(), v8_str("closure1")) |
| 534 .ToLocalChecked()))); | 540 .ToLocalChecked()))); |
| 535 Handle<JSFunction> fun2 = Handle<JSFunction>::cast( | 541 Handle<JSFunction> fun2 = Handle<JSFunction>::cast( |
| 536 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 542 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
| 537 env->Global() | 543 env->Global() |
| 538 ->Get(env.local(), v8_str("closure2")) | 544 ->Get(env.local(), v8_str("closure2")) |
| 539 .ToLocalChecked()))); | 545 .ToLocalChecked()))); |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 CompileRun("function f() { a = 12345678 }; f();"); | 756 CompileRun("function f() { a = 12345678 }; f();"); |
| 751 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 757 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
| 752 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); | 758 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); |
| 753 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 759 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
| 754 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); | 760 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); |
| 755 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 761 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
| 756 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); | 762 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); |
| 757 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 763 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
| 758 } | 764 } |
| 759 #endif | 765 #endif |
| OLD | NEW |