| 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 3569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3580 CcTest::global()->Set(v8_str("fun2"), fun2); | 3580 CcTest::global()->Set(v8_str("fun2"), fun2); |
| 3581 CompileRun("function f(a, b) { a(); b(); } f(fun1, fun2);"); | 3581 CompileRun("function f(a, b) { a(); b(); } f(fun1, fun2);"); |
| 3582 | 3582 |
| 3583 Handle<JSFunction> f = | 3583 Handle<JSFunction> f = |
| 3584 v8::Utils::OpenHandle( | 3584 v8::Utils::OpenHandle( |
| 3585 *v8::Handle<v8::Function>::Cast( | 3585 *v8::Handle<v8::Function>::Cast( |
| 3586 CcTest::global()->Get(v8_str("f")))); | 3586 CcTest::global()->Get(v8_str("f")))); |
| 3587 | 3587 |
| 3588 Handle<TypeFeedbackVector> feedback_vector(f->shared()->feedback_vector()); | 3588 Handle<TypeFeedbackVector> feedback_vector(f->shared()->feedback_vector()); |
| 3589 | 3589 |
| 3590 int expected_slots = 3; | 3590 int expected_slots = 2; |
| 3591 CHECK_EQ(expected_slots, feedback_vector->ICSlots()); | 3591 CHECK_EQ(expected_slots, feedback_vector->ICSlots()); |
| 3592 int slot1 = 1; | 3592 int slot1 = 0; |
| 3593 int slot2 = 2; | 3593 int slot2 = 1; |
| 3594 CHECK(feedback_vector->Get(FeedbackVectorICSlot(slot1))->IsWeakCell()); | 3594 CHECK(feedback_vector->Get(FeedbackVectorICSlot(slot1))->IsWeakCell()); |
| 3595 CHECK(feedback_vector->Get(FeedbackVectorICSlot(slot2))->IsWeakCell()); | 3595 CHECK(feedback_vector->Get(FeedbackVectorICSlot(slot2))->IsWeakCell()); |
| 3596 | 3596 |
| 3597 SimulateIncrementalMarking(CcTest::heap()); | 3597 SimulateIncrementalMarking(CcTest::heap()); |
| 3598 CcTest::heap()->CollectAllGarbage(); | 3598 CcTest::heap()->CollectAllGarbage(); |
| 3599 | 3599 |
| 3600 CHECK(!WeakCell::cast(feedback_vector->Get(FeedbackVectorICSlot(slot1))) | 3600 CHECK(!WeakCell::cast(feedback_vector->Get(FeedbackVectorICSlot(slot1))) |
| 3601 ->cleared()); | 3601 ->cleared()); |
| 3602 CHECK(!WeakCell::cast(feedback_vector->Get(FeedbackVectorICSlot(slot2))) | 3602 CHECK(!WeakCell::cast(feedback_vector->Get(FeedbackVectorICSlot(slot2))) |
| 3603 ->cleared()); | 3603 ->cleared()); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3706 // Prepare function f that contains a monomorphic IC for object | 3706 // Prepare function f that contains a monomorphic IC for object |
| 3707 // originating from the same native context. | 3707 // originating from the same native context. |
| 3708 CompileRun("function fun() { this.x = 1; }; var obj = new fun();" | 3708 CompileRun("function fun() { this.x = 1; }; var obj = new fun();" |
| 3709 "function f(o) { return o.x; } f(obj); f(obj);"); | 3709 "function f(o) { return o.x; } f(obj); f(obj);"); |
| 3710 Handle<JSFunction> f = | 3710 Handle<JSFunction> f = |
| 3711 v8::Utils::OpenHandle( | 3711 v8::Utils::OpenHandle( |
| 3712 *v8::Handle<v8::Function>::Cast( | 3712 *v8::Handle<v8::Function>::Cast( |
| 3713 CcTest::global()->Get(v8_str("f")))); | 3713 CcTest::global()->Get(v8_str("f")))); |
| 3714 | 3714 |
| 3715 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 3715 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
| 3716 CheckVectorIC(f, 1, MONOMORPHIC); | 3716 CheckVectorIC(f, 0, MONOMORPHIC); |
| 3717 CHECK(ic_before->ic_state() == DEFAULT); | 3717 CHECK(ic_before->ic_state() == DEFAULT); |
| 3718 | 3718 |
| 3719 SimulateIncrementalMarking(CcTest::heap()); | 3719 SimulateIncrementalMarking(CcTest::heap()); |
| 3720 CcTest::heap()->CollectAllGarbage(); | 3720 CcTest::heap()->CollectAllGarbage(); |
| 3721 | 3721 |
| 3722 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 3722 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
| 3723 CheckVectorIC(f, 1, MONOMORPHIC); | 3723 CheckVectorIC(f, 0, MONOMORPHIC); |
| 3724 CHECK(ic_after->ic_state() == DEFAULT); | 3724 CHECK(ic_after->ic_state() == DEFAULT); |
| 3725 } | 3725 } |
| 3726 | 3726 |
| 3727 | 3727 |
| 3728 TEST(IncrementalMarkingClearsMonomorphicIC) { | 3728 TEST(IncrementalMarkingClearsMonomorphicIC) { |
| 3729 if (i::FLAG_always_opt) return; | 3729 if (i::FLAG_always_opt) return; |
| 3730 CcTest::InitializeVM(); | 3730 CcTest::InitializeVM(); |
| 3731 v8::HandleScope scope(CcTest::isolate()); | 3731 v8::HandleScope scope(CcTest::isolate()); |
| 3732 v8::Local<v8::Value> obj1; | 3732 v8::Local<v8::Value> obj1; |
| 3733 | 3733 |
| 3734 { | 3734 { |
| 3735 LocalContext env; | 3735 LocalContext env; |
| 3736 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); | 3736 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); |
| 3737 obj1 = env->Global()->Get(v8_str("obj")); | 3737 obj1 = env->Global()->Get(v8_str("obj")); |
| 3738 } | 3738 } |
| 3739 | 3739 |
| 3740 // Prepare function f that contains a monomorphic IC for object | 3740 // Prepare function f that contains a monomorphic IC for object |
| 3741 // originating from a different native context. | 3741 // originating from a different native context. |
| 3742 CcTest::global()->Set(v8_str("obj1"), obj1); | 3742 CcTest::global()->Set(v8_str("obj1"), obj1); |
| 3743 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1);"); | 3743 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1);"); |
| 3744 Handle<JSFunction> f = v8::Utils::OpenHandle( | 3744 Handle<JSFunction> f = v8::Utils::OpenHandle( |
| 3745 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); | 3745 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); |
| 3746 | 3746 |
| 3747 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 3747 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
| 3748 CheckVectorIC(f, 1, MONOMORPHIC); | 3748 CheckVectorIC(f, 0, MONOMORPHIC); |
| 3749 CHECK(ic_before->ic_state() == DEFAULT); | 3749 CHECK(ic_before->ic_state() == DEFAULT); |
| 3750 | 3750 |
| 3751 // Fire context dispose notification. | 3751 // Fire context dispose notification. |
| 3752 CcTest::isolate()->ContextDisposedNotification(); | 3752 CcTest::isolate()->ContextDisposedNotification(); |
| 3753 SimulateIncrementalMarking(CcTest::heap()); | 3753 SimulateIncrementalMarking(CcTest::heap()); |
| 3754 CcTest::heap()->CollectAllGarbage(); | 3754 CcTest::heap()->CollectAllGarbage(); |
| 3755 | 3755 |
| 3756 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 3756 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
| 3757 CheckVectorICCleared(f, 1); | 3757 CheckVectorICCleared(f, 0); |
| 3758 CHECK(ic_after->ic_state() == DEFAULT); | 3758 CHECK(ic_after->ic_state() == DEFAULT); |
| 3759 } | 3759 } |
| 3760 | 3760 |
| 3761 | 3761 |
| 3762 TEST(IncrementalMarkingPreservesPolymorphicIC) { | 3762 TEST(IncrementalMarkingPreservesPolymorphicIC) { |
| 3763 if (i::FLAG_always_opt) return; | 3763 if (i::FLAG_always_opt) return; |
| 3764 CcTest::InitializeVM(); | 3764 CcTest::InitializeVM(); |
| 3765 v8::HandleScope scope(CcTest::isolate()); | 3765 v8::HandleScope scope(CcTest::isolate()); |
| 3766 v8::Local<v8::Value> obj1, obj2; | 3766 v8::Local<v8::Value> obj1, obj2; |
| 3767 | 3767 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3779 | 3779 |
| 3780 // Prepare function f that contains a polymorphic IC for objects | 3780 // Prepare function f that contains a polymorphic IC for objects |
| 3781 // originating from two different native contexts. | 3781 // originating from two different native contexts. |
| 3782 CcTest::global()->Set(v8_str("obj1"), obj1); | 3782 CcTest::global()->Set(v8_str("obj1"), obj1); |
| 3783 CcTest::global()->Set(v8_str("obj2"), obj2); | 3783 CcTest::global()->Set(v8_str("obj2"), obj2); |
| 3784 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1); f(obj2);"); | 3784 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1); f(obj2);"); |
| 3785 Handle<JSFunction> f = v8::Utils::OpenHandle( | 3785 Handle<JSFunction> f = v8::Utils::OpenHandle( |
| 3786 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); | 3786 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); |
| 3787 | 3787 |
| 3788 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 3788 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
| 3789 CheckVectorIC(f, 1, POLYMORPHIC); | 3789 CheckVectorIC(f, 0, POLYMORPHIC); |
| 3790 CHECK(ic_before->ic_state() == DEFAULT); | 3790 CHECK(ic_before->ic_state() == DEFAULT); |
| 3791 | 3791 |
| 3792 // Fire context dispose notification. | 3792 // Fire context dispose notification. |
| 3793 SimulateIncrementalMarking(CcTest::heap()); | 3793 SimulateIncrementalMarking(CcTest::heap()); |
| 3794 CcTest::heap()->CollectAllGarbage(); | 3794 CcTest::heap()->CollectAllGarbage(); |
| 3795 | 3795 |
| 3796 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 3796 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
| 3797 CheckVectorIC(f, 1, POLYMORPHIC); | 3797 CheckVectorIC(f, 0, POLYMORPHIC); |
| 3798 CHECK(ic_after->ic_state() == DEFAULT); | 3798 CHECK(ic_after->ic_state() == DEFAULT); |
| 3799 } | 3799 } |
| 3800 | 3800 |
| 3801 | 3801 |
| 3802 TEST(IncrementalMarkingClearsPolymorphicIC) { | 3802 TEST(IncrementalMarkingClearsPolymorphicIC) { |
| 3803 if (i::FLAG_always_opt) return; | 3803 if (i::FLAG_always_opt) return; |
| 3804 CcTest::InitializeVM(); | 3804 CcTest::InitializeVM(); |
| 3805 v8::HandleScope scope(CcTest::isolate()); | 3805 v8::HandleScope scope(CcTest::isolate()); |
| 3806 v8::Local<v8::Value> obj1, obj2; | 3806 v8::Local<v8::Value> obj1, obj2; |
| 3807 | 3807 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3819 | 3819 |
| 3820 // Prepare function f that contains a polymorphic IC for objects | 3820 // Prepare function f that contains a polymorphic IC for objects |
| 3821 // originating from two different native contexts. | 3821 // originating from two different native contexts. |
| 3822 CcTest::global()->Set(v8_str("obj1"), obj1); | 3822 CcTest::global()->Set(v8_str("obj1"), obj1); |
| 3823 CcTest::global()->Set(v8_str("obj2"), obj2); | 3823 CcTest::global()->Set(v8_str("obj2"), obj2); |
| 3824 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1); f(obj2);"); | 3824 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1); f(obj2);"); |
| 3825 Handle<JSFunction> f = v8::Utils::OpenHandle( | 3825 Handle<JSFunction> f = v8::Utils::OpenHandle( |
| 3826 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); | 3826 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); |
| 3827 | 3827 |
| 3828 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 3828 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
| 3829 CheckVectorIC(f, 1, POLYMORPHIC); | 3829 CheckVectorIC(f, 0, POLYMORPHIC); |
| 3830 CHECK(ic_before->ic_state() == DEFAULT); | 3830 CHECK(ic_before->ic_state() == DEFAULT); |
| 3831 | 3831 |
| 3832 // Fire context dispose notification. | 3832 // Fire context dispose notification. |
| 3833 CcTest::isolate()->ContextDisposedNotification(); | 3833 CcTest::isolate()->ContextDisposedNotification(); |
| 3834 SimulateIncrementalMarking(CcTest::heap()); | 3834 SimulateIncrementalMarking(CcTest::heap()); |
| 3835 CcTest::heap()->CollectAllGarbage(); | 3835 CcTest::heap()->CollectAllGarbage(); |
| 3836 | 3836 |
| 3837 CheckVectorICCleared(f, 1); | 3837 CheckVectorICCleared(f, 0); |
| 3838 CHECK(ic_before->ic_state() == DEFAULT); | 3838 CHECK(ic_before->ic_state() == DEFAULT); |
| 3839 } | 3839 } |
| 3840 | 3840 |
| 3841 | 3841 |
| 3842 class SourceResource : public v8::String::ExternalOneByteStringResource { | 3842 class SourceResource : public v8::String::ExternalOneByteStringResource { |
| 3843 public: | 3843 public: |
| 3844 explicit SourceResource(const char* data) | 3844 explicit SourceResource(const char* data) |
| 3845 : data_(data), length_(strlen(data)) { } | 3845 : data_(data), length_(strlen(data)) { } |
| 3846 | 3846 |
| 3847 virtual void Dispose() { | 3847 virtual void Dispose() { |
| (...skipping 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4976 " loadIC(obj);" | 4976 " loadIC(obj);" |
| 4977 " loadIC(obj);" | 4977 " loadIC(obj);" |
| 4978 " return proto;" | 4978 " return proto;" |
| 4979 "};"); | 4979 "};"); |
| 4980 Handle<JSFunction> loadIC = GetFunctionByName(isolate, "loadIC"); | 4980 Handle<JSFunction> loadIC = GetFunctionByName(isolate, "loadIC"); |
| 4981 { | 4981 { |
| 4982 v8::HandleScope scope(CcTest::isolate()); | 4982 v8::HandleScope scope(CcTest::isolate()); |
| 4983 CompileRun("(testIC())"); | 4983 CompileRun("(testIC())"); |
| 4984 } | 4984 } |
| 4985 heap->CollectAllGarbage(); | 4985 heap->CollectAllGarbage(); |
| 4986 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 1, MONOMORPHIC); | 4986 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 0, MONOMORPHIC); |
| 4987 { | 4987 { |
| 4988 v8::HandleScope scope(CcTest::isolate()); | 4988 v8::HandleScope scope(CcTest::isolate()); |
| 4989 CompileRun("(testIC())"); | 4989 CompileRun("(testIC())"); |
| 4990 } | 4990 } |
| 4991 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 1, MONOMORPHIC); | 4991 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 0, MONOMORPHIC); |
| 4992 } | 4992 } |
| 4993 | 4993 |
| 4994 | 4994 |
| 4995 TEST(PolymorphicStaysPolymorphicAfterGC) { | 4995 TEST(PolymorphicStaysPolymorphicAfterGC) { |
| 4996 if (FLAG_always_opt) return; | 4996 if (FLAG_always_opt) return; |
| 4997 CcTest::InitializeVM(); | 4997 CcTest::InitializeVM(); |
| 4998 Isolate* isolate = CcTest::i_isolate(); | 4998 Isolate* isolate = CcTest::i_isolate(); |
| 4999 Heap* heap = isolate->heap(); | 4999 Heap* heap = isolate->heap(); |
| 5000 v8::HandleScope scope(CcTest::isolate()); | 5000 v8::HandleScope scope(CcTest::isolate()); |
| 5001 CompileRun( | 5001 CompileRun( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 5012 " poly.x = true;" | 5012 " poly.x = true;" |
| 5013 " loadIC(poly);" | 5013 " loadIC(poly);" |
| 5014 " return proto;" | 5014 " return proto;" |
| 5015 "};"); | 5015 "};"); |
| 5016 Handle<JSFunction> loadIC = GetFunctionByName(isolate, "loadIC"); | 5016 Handle<JSFunction> loadIC = GetFunctionByName(isolate, "loadIC"); |
| 5017 { | 5017 { |
| 5018 v8::HandleScope scope(CcTest::isolate()); | 5018 v8::HandleScope scope(CcTest::isolate()); |
| 5019 CompileRun("(testIC())"); | 5019 CompileRun("(testIC())"); |
| 5020 } | 5020 } |
| 5021 heap->CollectAllGarbage(); | 5021 heap->CollectAllGarbage(); |
| 5022 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 1, POLYMORPHIC); | 5022 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 0, POLYMORPHIC); |
| 5023 { | 5023 { |
| 5024 v8::HandleScope scope(CcTest::isolate()); | 5024 v8::HandleScope scope(CcTest::isolate()); |
| 5025 CompileRun("(testIC())"); | 5025 CompileRun("(testIC())"); |
| 5026 } | 5026 } |
| 5027 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 1, POLYMORPHIC); | 5027 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 0, POLYMORPHIC); |
| 5028 } | 5028 } |
| 5029 | 5029 |
| 5030 | 5030 |
| 5031 TEST(WeakCell) { | 5031 TEST(WeakCell) { |
| 5032 CcTest::InitializeVM(); | 5032 CcTest::InitializeVM(); |
| 5033 Isolate* isolate = CcTest::i_isolate(); | 5033 Isolate* isolate = CcTest::i_isolate(); |
| 5034 v8::internal::Heap* heap = CcTest::heap(); | 5034 v8::internal::Heap* heap = CcTest::heap(); |
| 5035 v8::internal::Factory* factory = isolate->factory(); | 5035 v8::internal::Factory* factory = isolate->factory(); |
| 5036 | 5036 |
| 5037 HandleScope outer_scope(isolate); | 5037 HandleScope outer_scope(isolate); |
| (...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5898 size_t counter2 = 2000; | 5898 size_t counter2 = 2000; |
| 5899 tracer->SampleAllocation(time2, counter2, counter2); | 5899 tracer->SampleAllocation(time2, counter2, counter2); |
| 5900 size_t throughput = tracer->AllocationThroughputInBytesPerMillisecond(100); | 5900 size_t throughput = tracer->AllocationThroughputInBytesPerMillisecond(100); |
| 5901 CHECK_EQ(2 * (counter2 - counter1) / (time2 - time1), throughput); | 5901 CHECK_EQ(2 * (counter2 - counter1) / (time2 - time1), throughput); |
| 5902 int time3 = 1000; | 5902 int time3 = 1000; |
| 5903 size_t counter3 = 30000; | 5903 size_t counter3 = 30000; |
| 5904 tracer->SampleAllocation(time3, counter3, counter3); | 5904 tracer->SampleAllocation(time3, counter3, counter3); |
| 5905 throughput = tracer->AllocationThroughputInBytesPerMillisecond(100); | 5905 throughput = tracer->AllocationThroughputInBytesPerMillisecond(100); |
| 5906 CHECK_EQ(2 * (counter3 - counter1) / (time3 - time1), throughput); | 5906 CHECK_EQ(2 * (counter3 - counter1) / (time3 - time1), throughput); |
| 5907 } | 5907 } |
| OLD | NEW |