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 3616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3627 for (int i = 0; i < 4; i++) { | 3627 for (int i = 0; i < 4; i++) { |
3628 heap->CollectAllGarbage(false); | 3628 heap->CollectAllGarbage(false); |
3629 } | 3629 } |
3630 | 3630 |
3631 // The site still exists because of our global handle, but the code is no | 3631 // The site still exists because of our global handle, but the code is no |
3632 // longer referred to by dependent_code(). | 3632 // longer referred to by dependent_code(). |
3633 DependentCode::GroupStartIndexes starts(site->dependent_code()); | 3633 DependentCode::GroupStartIndexes starts(site->dependent_code()); |
3634 int index = starts.at(DependentCode::kAllocationSiteTransitionChangedGroup); | 3634 int index = starts.at(DependentCode::kAllocationSiteTransitionChangedGroup); |
3635 CHECK(!(site->dependent_code()->is_code_at(index))); | 3635 CHECK(!(site->dependent_code()->is_code_at(index))); |
3636 } | 3636 } |
| 3637 |
| 3638 |
| 3639 TEST(CellsInOptimizedCodeAreWeak) { |
| 3640 if (i::FLAG_always_opt || !i::FLAG_crankshaft) return; |
| 3641 i::FLAG_weak_embedded_objects_in_optimized_code = true; |
| 3642 i::FLAG_allow_natives_syntax = true; |
| 3643 CcTest::InitializeVM(); |
| 3644 Isolate* isolate = CcTest::i_isolate(); |
| 3645 v8::internal::Heap* heap = CcTest::heap(); |
| 3646 |
| 3647 if (!isolate->use_crankshaft()) return; |
| 3648 HandleScope outer_scope(heap->isolate()); |
| 3649 Handle<Code> code; |
| 3650 { |
| 3651 LocalContext context; |
| 3652 HandleScope scope(heap->isolate()); |
| 3653 |
| 3654 CompileRun("bar = (function() {" |
| 3655 " function bar() {" |
| 3656 " return foo(1);" |
| 3657 " };" |
| 3658 " var foo = function(x) { with (x) { return 1 + x; } };" |
| 3659 " bar(foo);" |
| 3660 " bar(foo);" |
| 3661 " bar(foo);" |
| 3662 " %OptimizeFunctionOnNextCall(bar);" |
| 3663 " bar(foo);" |
| 3664 " return bar;})();"); |
| 3665 |
| 3666 Handle<JSFunction> bar = |
| 3667 v8::Utils::OpenHandle( |
| 3668 *v8::Handle<v8::Function>::Cast( |
| 3669 CcTest::global()->Get(v8_str("bar")))); |
| 3670 code = scope.CloseAndEscape(Handle<Code>(bar->code())); |
| 3671 } |
| 3672 |
| 3673 // Now make sure that a gc should get rid of the function |
| 3674 for (int i = 0; i < 10; i++) { |
| 3675 heap->CollectAllGarbage(false); |
| 3676 } |
| 3677 |
| 3678 ASSERT(code->marked_for_deoptimization()); |
| 3679 } |
| 3680 |
| 3681 |
| 3682 TEST(ObjectsInOptimizedCodeAreWeak) { |
| 3683 if (i::FLAG_always_opt || !i::FLAG_crankshaft) return; |
| 3684 i::FLAG_weak_embedded_objects_in_optimized_code = true; |
| 3685 i::FLAG_allow_natives_syntax = true; |
| 3686 CcTest::InitializeVM(); |
| 3687 Isolate* isolate = CcTest::i_isolate(); |
| 3688 v8::internal::Heap* heap = CcTest::heap(); |
| 3689 |
| 3690 if (!isolate->use_crankshaft()) return; |
| 3691 HandleScope outer_scope(heap->isolate()); |
| 3692 Handle<Code> code; |
| 3693 { |
| 3694 LocalContext context; |
| 3695 HandleScope scope(heap->isolate()); |
| 3696 |
| 3697 CompileRun("function bar() {" |
| 3698 " return foo(1);" |
| 3699 "};" |
| 3700 "function foo(x) { with (x) { return 1 + x; } };" |
| 3701 "bar();" |
| 3702 "bar();" |
| 3703 "bar();" |
| 3704 "%OptimizeFunctionOnNextCall(bar);" |
| 3705 "bar();"); |
| 3706 |
| 3707 Handle<JSFunction> bar = |
| 3708 v8::Utils::OpenHandle( |
| 3709 *v8::Handle<v8::Function>::Cast( |
| 3710 CcTest::global()->Get(v8_str("bar")))); |
| 3711 code = scope.CloseAndEscape(Handle<Code>(bar->code())); |
| 3712 } |
| 3713 |
| 3714 // Now make sure that a gc should get rid of the function |
| 3715 for (int i = 0; i < 4; i++) { |
| 3716 heap->CollectAllGarbage(false); |
| 3717 } |
| 3718 |
| 3719 ASSERT(code->marked_for_deoptimization()); |
| 3720 } |
OLD | NEW |