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 3799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3810 CcTest::InitializeVM(); | 3810 CcTest::InitializeVM(); |
3811 v8::HandleScope scope(CcTest::isolate()); | 3811 v8::HandleScope scope(CcTest::isolate()); |
3812 | 3812 |
3813 // Prepare function f that contains a monomorphic IC for object | 3813 // Prepare function f that contains a monomorphic IC for object |
3814 // originating from the same native context. | 3814 // originating from the same native context. |
3815 CompileRun("function fun() { this.x = 1; }; var obj = new fun();" | 3815 CompileRun("function fun() { this.x = 1; }; var obj = new fun();" |
3816 "function f(o) { return o.x; } f(obj); f(obj);"); | 3816 "function f(o) { return o.x; } f(obj); f(obj);"); |
3817 Handle<JSFunction> f = Handle<JSFunction>::cast(v8::Utils::OpenHandle( | 3817 Handle<JSFunction> f = Handle<JSFunction>::cast(v8::Utils::OpenHandle( |
3818 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f"))))); | 3818 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f"))))); |
3819 | 3819 |
3820 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | |
3821 CheckVectorIC(f, 0, MONOMORPHIC); | 3820 CheckVectorIC(f, 0, MONOMORPHIC); |
3822 CHECK(ic_before->ic_state() == DEFAULT); | |
3823 | 3821 |
3824 SimulateIncrementalMarking(CcTest::heap()); | 3822 SimulateIncrementalMarking(CcTest::heap()); |
3825 CcTest::heap()->CollectAllGarbage(); | 3823 CcTest::heap()->CollectAllGarbage(); |
3826 | 3824 |
3827 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | |
3828 CheckVectorIC(f, 0, MONOMORPHIC); | 3825 CheckVectorIC(f, 0, MONOMORPHIC); |
3829 CHECK(ic_after->ic_state() == DEFAULT); | |
3830 } | 3826 } |
3831 | 3827 |
3832 | 3828 |
3833 TEST(IncrementalMarkingClearsMonomorphicIC) { | 3829 TEST(IncrementalMarkingClearsMonomorphicIC) { |
3834 if (i::FLAG_always_opt) return; | 3830 if (i::FLAG_always_opt) return; |
3835 CcTest::InitializeVM(); | 3831 CcTest::InitializeVM(); |
3836 v8::HandleScope scope(CcTest::isolate()); | 3832 v8::HandleScope scope(CcTest::isolate()); |
3837 v8::Local<v8::Value> obj1; | 3833 v8::Local<v8::Value> obj1; |
3838 | 3834 |
3839 { | 3835 { |
3840 LocalContext env; | 3836 LocalContext env; |
3841 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); | 3837 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); |
3842 obj1 = env->Global()->Get(v8_str("obj")); | 3838 obj1 = env->Global()->Get(v8_str("obj")); |
3843 } | 3839 } |
3844 | 3840 |
3845 // Prepare function f that contains a monomorphic IC for object | 3841 // Prepare function f that contains a monomorphic IC for object |
3846 // originating from a different native context. | 3842 // originating from a different native context. |
3847 CcTest::global()->Set(v8_str("obj1"), obj1); | 3843 CcTest::global()->Set(v8_str("obj1"), obj1); |
3848 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1);"); | 3844 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1);"); |
3849 Handle<JSFunction> f = Handle<JSFunction>::cast(v8::Utils::OpenHandle( | 3845 Handle<JSFunction> f = Handle<JSFunction>::cast(v8::Utils::OpenHandle( |
3850 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f"))))); | 3846 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f"))))); |
3851 | 3847 |
3852 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | |
3853 CheckVectorIC(f, 0, MONOMORPHIC); | 3848 CheckVectorIC(f, 0, MONOMORPHIC); |
3854 CHECK(ic_before->ic_state() == DEFAULT); | |
3855 | 3849 |
3856 // Fire context dispose notification. | 3850 // Fire context dispose notification. |
3857 CcTest::isolate()->ContextDisposedNotification(); | 3851 CcTest::isolate()->ContextDisposedNotification(); |
3858 SimulateIncrementalMarking(CcTest::heap()); | 3852 SimulateIncrementalMarking(CcTest::heap()); |
3859 CcTest::heap()->CollectAllGarbage(); | 3853 CcTest::heap()->CollectAllGarbage(); |
3860 | 3854 |
3861 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | |
3862 CheckVectorICCleared(f, 0); | 3855 CheckVectorICCleared(f, 0); |
3863 CHECK(ic_after->ic_state() == DEFAULT); | |
3864 } | 3856 } |
3865 | 3857 |
3866 | 3858 |
3867 TEST(IncrementalMarkingPreservesPolymorphicIC) { | 3859 TEST(IncrementalMarkingPreservesPolymorphicIC) { |
3868 if (i::FLAG_always_opt) return; | 3860 if (i::FLAG_always_opt) return; |
3869 CcTest::InitializeVM(); | 3861 CcTest::InitializeVM(); |
3870 v8::HandleScope scope(CcTest::isolate()); | 3862 v8::HandleScope scope(CcTest::isolate()); |
3871 v8::Local<v8::Value> obj1, obj2; | 3863 v8::Local<v8::Value> obj1, obj2; |
3872 | 3864 |
3873 { | 3865 { |
3874 LocalContext env; | 3866 LocalContext env; |
3875 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); | 3867 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); |
3876 obj1 = env->Global()->Get(v8_str("obj")); | 3868 obj1 = env->Global()->Get(v8_str("obj")); |
3877 } | 3869 } |
3878 | 3870 |
3879 { | 3871 { |
3880 LocalContext env; | 3872 LocalContext env; |
3881 CompileRun("function fun() { this.x = 2; }; var obj = new fun();"); | 3873 CompileRun("function fun() { this.x = 2; }; var obj = new fun();"); |
3882 obj2 = env->Global()->Get(v8_str("obj")); | 3874 obj2 = env->Global()->Get(v8_str("obj")); |
3883 } | 3875 } |
3884 | 3876 |
3885 // Prepare function f that contains a polymorphic IC for objects | 3877 // Prepare function f that contains a polymorphic IC for objects |
3886 // originating from two different native contexts. | 3878 // originating from two different native contexts. |
3887 CcTest::global()->Set(v8_str("obj1"), obj1); | 3879 CcTest::global()->Set(v8_str("obj1"), obj1); |
3888 CcTest::global()->Set(v8_str("obj2"), obj2); | 3880 CcTest::global()->Set(v8_str("obj2"), obj2); |
3889 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1); f(obj2);"); | 3881 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1); f(obj2);"); |
3890 Handle<JSFunction> f = Handle<JSFunction>::cast(v8::Utils::OpenHandle( | 3882 Handle<JSFunction> f = Handle<JSFunction>::cast(v8::Utils::OpenHandle( |
3891 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f"))))); | 3883 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f"))))); |
3892 | 3884 |
3893 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | |
3894 CheckVectorIC(f, 0, POLYMORPHIC); | 3885 CheckVectorIC(f, 0, POLYMORPHIC); |
3895 CHECK(ic_before->ic_state() == DEFAULT); | |
3896 | 3886 |
3897 // Fire context dispose notification. | 3887 // Fire context dispose notification. |
3898 SimulateIncrementalMarking(CcTest::heap()); | 3888 SimulateIncrementalMarking(CcTest::heap()); |
3899 CcTest::heap()->CollectAllGarbage(); | 3889 CcTest::heap()->CollectAllGarbage(); |
3900 | 3890 |
3901 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | |
3902 CheckVectorIC(f, 0, POLYMORPHIC); | 3891 CheckVectorIC(f, 0, POLYMORPHIC); |
3903 CHECK(ic_after->ic_state() == DEFAULT); | |
3904 } | 3892 } |
3905 | 3893 |
3906 | 3894 |
3907 TEST(IncrementalMarkingClearsPolymorphicIC) { | 3895 TEST(IncrementalMarkingClearsPolymorphicIC) { |
3908 if (i::FLAG_always_opt) return; | 3896 if (i::FLAG_always_opt) return; |
3909 CcTest::InitializeVM(); | 3897 CcTest::InitializeVM(); |
3910 v8::HandleScope scope(CcTest::isolate()); | 3898 v8::HandleScope scope(CcTest::isolate()); |
3911 v8::Local<v8::Value> obj1, obj2; | 3899 v8::Local<v8::Value> obj1, obj2; |
3912 | 3900 |
3913 { | 3901 { |
3914 LocalContext env; | 3902 LocalContext env; |
3915 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); | 3903 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); |
3916 obj1 = env->Global()->Get(v8_str("obj")); | 3904 obj1 = env->Global()->Get(v8_str("obj")); |
3917 } | 3905 } |
3918 | 3906 |
3919 { | 3907 { |
3920 LocalContext env; | 3908 LocalContext env; |
3921 CompileRun("function fun() { this.x = 2; }; var obj = new fun();"); | 3909 CompileRun("function fun() { this.x = 2; }; var obj = new fun();"); |
3922 obj2 = env->Global()->Get(v8_str("obj")); | 3910 obj2 = env->Global()->Get(v8_str("obj")); |
3923 } | 3911 } |
3924 | 3912 |
3925 // Prepare function f that contains a polymorphic IC for objects | 3913 // Prepare function f that contains a polymorphic IC for objects |
3926 // originating from two different native contexts. | 3914 // originating from two different native contexts. |
3927 CcTest::global()->Set(v8_str("obj1"), obj1); | 3915 CcTest::global()->Set(v8_str("obj1"), obj1); |
3928 CcTest::global()->Set(v8_str("obj2"), obj2); | 3916 CcTest::global()->Set(v8_str("obj2"), obj2); |
3929 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1); f(obj2);"); | 3917 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1); f(obj2);"); |
3930 Handle<JSFunction> f = Handle<JSFunction>::cast(v8::Utils::OpenHandle( | 3918 Handle<JSFunction> f = Handle<JSFunction>::cast(v8::Utils::OpenHandle( |
3931 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f"))))); | 3919 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f"))))); |
3932 | 3920 |
3933 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | |
3934 CheckVectorIC(f, 0, POLYMORPHIC); | 3921 CheckVectorIC(f, 0, POLYMORPHIC); |
3935 CHECK(ic_before->ic_state() == DEFAULT); | |
3936 | 3922 |
3937 // Fire context dispose notification. | 3923 // Fire context dispose notification. |
3938 CcTest::isolate()->ContextDisposedNotification(); | 3924 CcTest::isolate()->ContextDisposedNotification(); |
3939 SimulateIncrementalMarking(CcTest::heap()); | 3925 SimulateIncrementalMarking(CcTest::heap()); |
3940 CcTest::heap()->CollectAllGarbage(); | 3926 CcTest::heap()->CollectAllGarbage(); |
3941 | 3927 |
3942 CheckVectorICCleared(f, 0); | 3928 CheckVectorICCleared(f, 0); |
3943 CHECK(ic_before->ic_state() == DEFAULT); | |
3944 } | 3929 } |
3945 | 3930 |
3946 | 3931 |
3947 class SourceResource : public v8::String::ExternalOneByteStringResource { | 3932 class SourceResource : public v8::String::ExternalOneByteStringResource { |
3948 public: | 3933 public: |
3949 explicit SourceResource(const char* data) | 3934 explicit SourceResource(const char* data) |
3950 : data_(data), length_(strlen(data)) { } | 3935 : data_(data), length_(strlen(data)) { } |
3951 | 3936 |
3952 virtual void Dispose() { | 3937 virtual void Dispose() { |
3953 i::DeleteArray(data_); | 3938 i::DeleteArray(data_); |
(...skipping 2315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6269 // The CollectGarbage call above starts sweeper threads. | 6254 // The CollectGarbage call above starts sweeper threads. |
6270 // The crash will happen if the following two functions | 6255 // The crash will happen if the following two functions |
6271 // are called before sweeping finishes. | 6256 // are called before sweeping finishes. |
6272 heap->StartIncrementalMarking(); | 6257 heap->StartIncrementalMarking(); |
6273 heap->FinalizeIncrementalMarkingIfComplete("test"); | 6258 heap->FinalizeIncrementalMarkingIfComplete("test"); |
6274 } | 6259 } |
6275 | 6260 |
6276 | 6261 |
6277 } // namespace internal | 6262 } // namespace internal |
6278 } // namespace v8 | 6263 } // namespace v8 |
OLD | NEW |