| 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 3072 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3083 Isolate* isolate = CcTest::i_isolate(); | 3083 Isolate* isolate = CcTest::i_isolate(); |
| 3084 Heap* heap = isolate->heap(); | 3084 Heap* heap = isolate->heap(); |
| 3085 HandleScope scope(isolate); | 3085 HandleScope scope(isolate); |
| 3086 | 3086 |
| 3087 // First make sure that the uninitialized CallIC stub is on a single page | 3087 // First make sure that the uninitialized CallIC stub is on a single page |
| 3088 // that will later be selected as an evacuation candidate. | 3088 // that will later be selected as an evacuation candidate. |
| 3089 { | 3089 { |
| 3090 HandleScope inner_scope(isolate); | 3090 HandleScope inner_scope(isolate); |
| 3091 AlwaysAllocateScope always_allocate; | 3091 AlwaysAllocateScope always_allocate; |
| 3092 SimulateFullSpace(heap->code_space()); | 3092 SimulateFullSpace(heap->code_space()); |
| 3093 isolate->stub_cache()->ComputeCallInitialize(9, NOT_CONTEXTUAL); | 3093 isolate->stub_cache()->ComputeCallInitialize(9); |
| 3094 } | 3094 } |
| 3095 | 3095 |
| 3096 // Second compile a CallIC and execute it once so that it gets patched to | 3096 // Second compile a CallIC and execute it once so that it gets patched to |
| 3097 // the pre-monomorphic stub. These code objects are on yet another page. | 3097 // the pre-monomorphic stub. These code objects are on yet another page. |
| 3098 { | 3098 { |
| 3099 HandleScope inner_scope(isolate); | 3099 HandleScope inner_scope(isolate); |
| 3100 AlwaysAllocateScope always_allocate; | 3100 AlwaysAllocateScope always_allocate; |
| 3101 SimulateFullSpace(heap->code_space()); | 3101 SimulateFullSpace(heap->code_space()); |
| 3102 CompileRun("var o = { f:function(a,b,c,d,e,f,g,h,i) {}};" | 3102 CompileRun("var o = { f:function(a,b,c,d,e,f,g,h,i) {}};" |
| 3103 "function call() { o.f(1,2,3,4,5,6,7,8,9); };" | 3103 "function call() { o.f(1,2,3,4,5,6,7,8,9); };" |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3525 public: | 3525 public: |
| 3526 void VisitPointers(Object** start, Object** end) { } | 3526 void VisitPointers(Object** start, Object** end) { } |
| 3527 }; | 3527 }; |
| 3528 | 3528 |
| 3529 | 3529 |
| 3530 TEST(DeferredHandles) { | 3530 TEST(DeferredHandles) { |
| 3531 CcTest::InitializeVM(); | 3531 CcTest::InitializeVM(); |
| 3532 Isolate* isolate = CcTest::i_isolate(); | 3532 Isolate* isolate = CcTest::i_isolate(); |
| 3533 Heap* heap = isolate->heap(); | 3533 Heap* heap = isolate->heap(); |
| 3534 v8::HandleScope scope(reinterpret_cast<v8::Isolate*>(isolate)); | 3534 v8::HandleScope scope(reinterpret_cast<v8::Isolate*>(isolate)); |
| 3535 v8::ImplementationUtilities::HandleScopeData* data = | 3535 HandleScopeData* data = isolate->handle_scope_data(); |
| 3536 isolate->handle_scope_data(); | |
| 3537 Handle<Object> init(heap->empty_string(), isolate); | 3536 Handle<Object> init(heap->empty_string(), isolate); |
| 3538 while (data->next < data->limit) { | 3537 while (data->next < data->limit) { |
| 3539 Handle<Object> obj(heap->empty_string(), isolate); | 3538 Handle<Object> obj(heap->empty_string(), isolate); |
| 3540 } | 3539 } |
| 3541 // An entire block of handles has been filled. | 3540 // An entire block of handles has been filled. |
| 3542 // Next handle would require a new block. | 3541 // Next handle would require a new block. |
| 3543 ASSERT(data->next == data->limit); | 3542 ASSERT(data->next == data->limit); |
| 3544 | 3543 |
| 3545 DeferredHandleScope deferred(isolate); | 3544 DeferredHandleScope deferred(isolate); |
| 3546 DummyVisitor visitor; | 3545 DummyVisitor visitor; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3657 for (int i = 0; i < 4; i++) { | 3656 for (int i = 0; i < 4; i++) { |
| 3658 heap->CollectAllGarbage(false); | 3657 heap->CollectAllGarbage(false); |
| 3659 } | 3658 } |
| 3660 | 3659 |
| 3661 // The site still exists because of our global handle, but the code is no | 3660 // The site still exists because of our global handle, but the code is no |
| 3662 // longer referred to by dependent_code(). | 3661 // longer referred to by dependent_code(). |
| 3663 DependentCode::GroupStartIndexes starts(site->dependent_code()); | 3662 DependentCode::GroupStartIndexes starts(site->dependent_code()); |
| 3664 int index = starts.at(DependentCode::kAllocationSiteTransitionChangedGroup); | 3663 int index = starts.at(DependentCode::kAllocationSiteTransitionChangedGroup); |
| 3665 CHECK(!(site->dependent_code()->is_code_at(index))); | 3664 CHECK(!(site->dependent_code()->is_code_at(index))); |
| 3666 } | 3665 } |
| 3666 |
| 3667 |
| 3668 TEST(CellsInOptimizedCodeAreWeak) { |
| 3669 if (i::FLAG_always_opt || !i::FLAG_crankshaft) return; |
| 3670 i::FLAG_weak_embedded_objects_in_optimized_code = true; |
| 3671 i::FLAG_allow_natives_syntax = true; |
| 3672 CcTest::InitializeVM(); |
| 3673 Isolate* isolate = CcTest::i_isolate(); |
| 3674 v8::internal::Heap* heap = CcTest::heap(); |
| 3675 |
| 3676 if (!isolate->use_crankshaft()) return; |
| 3677 HandleScope outer_scope(heap->isolate()); |
| 3678 Handle<Code> code; |
| 3679 { |
| 3680 LocalContext context; |
| 3681 HandleScope scope(heap->isolate()); |
| 3682 |
| 3683 CompileRun("bar = (function() {" |
| 3684 " function bar() {" |
| 3685 " return foo(1);" |
| 3686 " };" |
| 3687 " var foo = function(x) { with (x) { return 1 + x; } };" |
| 3688 " bar(foo);" |
| 3689 " bar(foo);" |
| 3690 " bar(foo);" |
| 3691 " %OptimizeFunctionOnNextCall(bar);" |
| 3692 " bar(foo);" |
| 3693 " return bar;})();"); |
| 3694 |
| 3695 Handle<JSFunction> bar = |
| 3696 v8::Utils::OpenHandle( |
| 3697 *v8::Handle<v8::Function>::Cast( |
| 3698 CcTest::global()->Get(v8_str("bar")))); |
| 3699 code = scope.CloseAndEscape(Handle<Code>(bar->code())); |
| 3700 } |
| 3701 |
| 3702 // Now make sure that a gc should get rid of the function |
| 3703 for (int i = 0; i < 4; i++) { |
| 3704 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
| 3705 } |
| 3706 |
| 3707 ASSERT(code->marked_for_deoptimization()); |
| 3708 } |
| 3709 |
| 3710 |
| 3711 TEST(ObjectsInOptimizedCodeAreWeak) { |
| 3712 if (i::FLAG_always_opt || !i::FLAG_crankshaft) return; |
| 3713 i::FLAG_weak_embedded_objects_in_optimized_code = true; |
| 3714 i::FLAG_allow_natives_syntax = true; |
| 3715 CcTest::InitializeVM(); |
| 3716 Isolate* isolate = CcTest::i_isolate(); |
| 3717 v8::internal::Heap* heap = CcTest::heap(); |
| 3718 |
| 3719 if (!isolate->use_crankshaft()) return; |
| 3720 HandleScope outer_scope(heap->isolate()); |
| 3721 Handle<Code> code; |
| 3722 { |
| 3723 LocalContext context; |
| 3724 HandleScope scope(heap->isolate()); |
| 3725 |
| 3726 CompileRun("function bar() {" |
| 3727 " return foo(1);" |
| 3728 "};" |
| 3729 "function foo(x) { with (x) { return 1 + x; } };" |
| 3730 "bar();" |
| 3731 "bar();" |
| 3732 "bar();" |
| 3733 "%OptimizeFunctionOnNextCall(bar);" |
| 3734 "bar();"); |
| 3735 |
| 3736 Handle<JSFunction> bar = |
| 3737 v8::Utils::OpenHandle( |
| 3738 *v8::Handle<v8::Function>::Cast( |
| 3739 CcTest::global()->Get(v8_str("bar")))); |
| 3740 code = scope.CloseAndEscape(Handle<Code>(bar->code())); |
| 3741 } |
| 3742 |
| 3743 // Now make sure that a gc should get rid of the function |
| 3744 for (int i = 0; i < 4; i++) { |
| 3745 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
| 3746 } |
| 3747 |
| 3748 ASSERT(code->marked_for_deoptimization()); |
| 3749 } |
| OLD | NEW |