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 3830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3841 immortal->set_next_code_link(*mortal); | 3841 immortal->set_next_code_link(*mortal); |
3842 context->set(Context::OPTIMIZED_CODE_LIST, *immortal); | 3842 context->set(Context::OPTIMIZED_CODE_LIST, *immortal); |
3843 new_head = scope.CloseAndEscape(immortal); | 3843 new_head = scope.CloseAndEscape(immortal); |
3844 } | 3844 } |
3845 heap->CollectAllAvailableGarbage(); | 3845 heap->CollectAllAvailableGarbage(); |
3846 // Now mortal code should be dead. | 3846 // Now mortal code should be dead. |
3847 CHECK_EQ(*old_head, new_head->next_code_link()); | 3847 CHECK_EQ(*old_head, new_head->next_code_link()); |
3848 } | 3848 } |
3849 | 3849 |
3850 | 3850 |
| 3851 static bool weak_ic_cleared = false; |
| 3852 |
| 3853 static void ClearWeakIC(const v8::WeakCallbackData<v8::Object, void>& data) { |
| 3854 printf("clear weak is called\n"); |
| 3855 weak_ic_cleared = true; |
| 3856 v8::Persistent<v8::Value>* p = |
| 3857 reinterpret_cast<v8::Persistent<v8::Value>*>(data.GetParameter()); |
| 3858 CHECK(p->IsNearDeath()); |
| 3859 p->Reset(); |
| 3860 } |
| 3861 |
| 3862 |
| 3863 // Checks that the value returned by execution of the source is weak. |
| 3864 void CheckWeakness(const char* source) { |
| 3865 i::FLAG_stress_compaction = false; |
| 3866 CcTest::InitializeVM(); |
| 3867 v8::Isolate* isolate = CcTest::isolate(); |
| 3868 v8::HandleScope scope(isolate); |
| 3869 v8::Persistent<v8::Object> garbage; |
| 3870 { |
| 3871 v8::HandleScope scope(isolate); |
| 3872 garbage.Reset(isolate, CompileRun(source)->ToObject()); |
| 3873 } |
| 3874 weak_ic_cleared = false; |
| 3875 garbage.SetWeak(static_cast<void*>(&garbage), &ClearWeakIC); |
| 3876 Heap* heap = CcTest::i_isolate()->heap(); |
| 3877 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
| 3878 CHECK(weak_ic_cleared); |
| 3879 } |
| 3880 |
| 3881 |
| 3882 // Each of the following "weak IC" tests creates an IC that embeds a map with |
| 3883 // the prototype pointing to _proto_ and checks that the _proto_ dies on GC. |
| 3884 TEST(WeakMapInMonomorphicLoadIC) { |
| 3885 CheckWeakness("function loadIC(obj) {" |
| 3886 " return obj.name;" |
| 3887 "}" |
| 3888 " (function() {" |
| 3889 " var proto = {'name' : 'weak'};" |
| 3890 " var obj = Object.create(proto);" |
| 3891 " loadIC(obj);" |
| 3892 " loadIC(obj);" |
| 3893 " loadIC(obj);" |
| 3894 " return proto;" |
| 3895 " })();"); |
| 3896 } |
| 3897 |
| 3898 |
| 3899 TEST(WeakMapInMonomorphicKeyedLoadIC) { |
| 3900 CheckWeakness("function keyedLoadIC(obj, field) {" |
| 3901 " return obj[field];" |
| 3902 "}" |
| 3903 " (function() {" |
| 3904 " var proto = {'name' : 'weak'};" |
| 3905 " var obj = Object.create(proto);" |
| 3906 " keyedLoadIC(obj, 'name');" |
| 3907 " keyedLoadIC(obj, 'name');" |
| 3908 " keyedLoadIC(obj, 'name');" |
| 3909 " return proto;" |
| 3910 " })();"); |
| 3911 } |
| 3912 |
| 3913 |
| 3914 TEST(WeakMapInMonomorphicStoreIC) { |
| 3915 CheckWeakness("function storeIC(obj, value) {" |
| 3916 " obj.name = value;" |
| 3917 "}" |
| 3918 " (function() {" |
| 3919 " var proto = {'name' : 'weak'};" |
| 3920 " var obj = Object.create(proto);" |
| 3921 " storeIC(obj, 'x');" |
| 3922 " storeIC(obj, 'x');" |
| 3923 " storeIC(obj, 'x');" |
| 3924 " return proto;" |
| 3925 " })();"); |
| 3926 } |
| 3927 |
| 3928 |
| 3929 TEST(WeakMapInMonomorphicKeyedStoreIC) { |
| 3930 CheckWeakness("function keyedStoreIC(obj, field, value) {" |
| 3931 " obj[field] = value;" |
| 3932 "}" |
| 3933 " (function() {" |
| 3934 " var proto = {'name' : 'weak'};" |
| 3935 " var obj = Object.create(proto);" |
| 3936 " keyedStoreIC(obj, 'x');" |
| 3937 " keyedStoreIC(obj, 'x');" |
| 3938 " keyedStoreIC(obj, 'x');" |
| 3939 " return proto;" |
| 3940 " })();"); |
| 3941 } |
| 3942 |
| 3943 |
| 3944 TEST(WeakMapInMonomorphicCompareNilIC) { |
| 3945 CheckWeakness("function compareNilIC(obj) {" |
| 3946 " return obj == null;" |
| 3947 "}" |
| 3948 " (function() {" |
| 3949 " var proto = {'name' : 'weak'};" |
| 3950 " var obj = Object.create(proto);" |
| 3951 " compareNilIC(obj);" |
| 3952 " compareNilIC(obj);" |
| 3953 " compareNilIC(obj);" |
| 3954 " return proto;" |
| 3955 " })();"); |
| 3956 } |
| 3957 |
| 3958 |
3851 #ifdef DEBUG | 3959 #ifdef DEBUG |
3852 TEST(AddInstructionChangesNewSpacePromotion) { | 3960 TEST(AddInstructionChangesNewSpacePromotion) { |
3853 i::FLAG_allow_natives_syntax = true; | 3961 i::FLAG_allow_natives_syntax = true; |
3854 i::FLAG_expose_gc = true; | 3962 i::FLAG_expose_gc = true; |
3855 i::FLAG_stress_compaction = true; | 3963 i::FLAG_stress_compaction = true; |
3856 i::FLAG_gc_interval = 1000; | 3964 i::FLAG_gc_interval = 1000; |
3857 CcTest::InitializeVM(); | 3965 CcTest::InitializeVM(); |
3858 if (!i::FLAG_allocation_site_pretenuring) return; | 3966 if (!i::FLAG_allocation_site_pretenuring) return; |
3859 v8::HandleScope scope(CcTest::isolate()); | 3967 v8::HandleScope scope(CcTest::isolate()); |
3860 Isolate* isolate = CcTest::i_isolate(); | 3968 Isolate* isolate = CcTest::i_isolate(); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3935 v8::Context::Scope cscope(context); | 4043 v8::Context::Scope cscope(context); |
3936 | 4044 |
3937 v8::Local<v8::Value> result = CompileRun( | 4045 v8::Local<v8::Value> result = CompileRun( |
3938 "var locals = '';" | 4046 "var locals = '';" |
3939 "for (var i = 0; i < 512; i++) locals += 'var v' + i + '= 42;';" | 4047 "for (var i = 0; i < 512; i++) locals += 'var v' + i + '= 42;';" |
3940 "eval('function f() {' + locals + 'return function() { return v0; }; }');" | 4048 "eval('function f() {' + locals + 'return function() { return v0; }; }');" |
3941 "interrupt();" // This triggers a fake stack overflow in f. | 4049 "interrupt();" // This triggers a fake stack overflow in f. |
3942 "f()()"); | 4050 "f()()"); |
3943 CHECK_EQ(42.0, result->ToNumber()->Value()); | 4051 CHECK_EQ(42.0, result->ToNumber()->Value()); |
3944 } | 4052 } |
OLD | NEW |