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