| 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 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 global_handles->Destroy(h4.location()); | 390 global_handles->Destroy(h4.location()); |
| 391 } | 391 } |
| 392 | 392 |
| 393 | 393 |
| 394 static bool WeakPointerCleared = false; | 394 static bool WeakPointerCleared = false; |
| 395 | 395 |
| 396 static void TestWeakGlobalHandleCallback(v8::Isolate* isolate, | 396 static void TestWeakGlobalHandleCallback(v8::Isolate* isolate, |
| 397 v8::Persistent<v8::Value>* handle, | 397 v8::Persistent<v8::Value>* handle, |
| 398 void* id) { | 398 void* id) { |
| 399 if (1234 == reinterpret_cast<intptr_t>(id)) WeakPointerCleared = true; | 399 if (1234 == reinterpret_cast<intptr_t>(id)) WeakPointerCleared = true; |
| 400 handle->Dispose(); | 400 handle->Reset(); |
| 401 } | 401 } |
| 402 | 402 |
| 403 | 403 |
| 404 TEST(WeakGlobalHandlesScavenge) { | 404 TEST(WeakGlobalHandlesScavenge) { |
| 405 i::FLAG_stress_compaction = false; | 405 i::FLAG_stress_compaction = false; |
| 406 CcTest::InitializeVM(); | 406 CcTest::InitializeVM(); |
| 407 Isolate* isolate = CcTest::i_isolate(); | 407 Isolate* isolate = CcTest::i_isolate(); |
| 408 Heap* heap = isolate->heap(); | 408 Heap* heap = isolate->heap(); |
| 409 Factory* factory = isolate->factory(); | 409 Factory* factory = isolate->factory(); |
| 410 GlobalHandles* global_handles = isolate->global_handles(); | 410 GlobalHandles* global_handles = isolate->global_handles(); |
| (...skipping 1369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1780 ctx2->Global()->Set(v8_str("o"), v); | 1780 ctx2->Global()->Set(v8_str("o"), v); |
| 1781 v8::Local<v8::Value> res = CompileRun( | 1781 v8::Local<v8::Value> res = CompileRun( |
| 1782 "function f() { return o.x; }" | 1782 "function f() { return o.x; }" |
| 1783 "for (var i = 0; i < 10; ++i) f();" | 1783 "for (var i = 0; i < 10; ++i) f();" |
| 1784 "%OptimizeFunctionOnNextCall(f);" | 1784 "%OptimizeFunctionOnNextCall(f);" |
| 1785 "f();"); | 1785 "f();"); |
| 1786 CHECK_EQ(42, res->Int32Value()); | 1786 CHECK_EQ(42, res->Int32Value()); |
| 1787 ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0)); | 1787 ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0)); |
| 1788 ctx2->Exit(); | 1788 ctx2->Exit(); |
| 1789 v8::Local<v8::Context>::New(isolate, ctx1)->Exit(); | 1789 v8::Local<v8::Context>::New(isolate, ctx1)->Exit(); |
| 1790 ctx1p.Dispose(); | 1790 ctx1p.Reset(); |
| 1791 v8::V8::ContextDisposedNotification(); | 1791 v8::V8::ContextDisposedNotification(); |
| 1792 } | 1792 } |
| 1793 CcTest::heap()->CollectAllAvailableGarbage(); | 1793 CcTest::heap()->CollectAllAvailableGarbage(); |
| 1794 CHECK_EQ(2, NumberOfGlobalObjects()); | 1794 CHECK_EQ(2, NumberOfGlobalObjects()); |
| 1795 ctx2p.Dispose(); | 1795 ctx2p.Reset(); |
| 1796 CcTest::heap()->CollectAllAvailableGarbage(); | 1796 CcTest::heap()->CollectAllAvailableGarbage(); |
| 1797 CHECK_EQ(0, NumberOfGlobalObjects()); | 1797 CHECK_EQ(0, NumberOfGlobalObjects()); |
| 1798 } | 1798 } |
| 1799 | 1799 |
| 1800 | 1800 |
| 1801 // Test that we don't embed functions from foreign contexts into | 1801 // Test that we don't embed functions from foreign contexts into |
| 1802 // optimized code. | 1802 // optimized code. |
| 1803 TEST(LeakNativeContextViaFunction) { | 1803 TEST(LeakNativeContextViaFunction) { |
| 1804 i::FLAG_allow_natives_syntax = true; | 1804 i::FLAG_allow_natives_syntax = true; |
| 1805 v8::Isolate* isolate = CcTest::isolate(); | 1805 v8::Isolate* isolate = CcTest::isolate(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1826 ctx2->Global()->Set(v8_str("o"), v); | 1826 ctx2->Global()->Set(v8_str("o"), v); |
| 1827 v8::Local<v8::Value> res = CompileRun( | 1827 v8::Local<v8::Value> res = CompileRun( |
| 1828 "function f(x) { return x(); }" | 1828 "function f(x) { return x(); }" |
| 1829 "for (var i = 0; i < 10; ++i) f(o);" | 1829 "for (var i = 0; i < 10; ++i) f(o);" |
| 1830 "%OptimizeFunctionOnNextCall(f);" | 1830 "%OptimizeFunctionOnNextCall(f);" |
| 1831 "f(o);"); | 1831 "f(o);"); |
| 1832 CHECK_EQ(42, res->Int32Value()); | 1832 CHECK_EQ(42, res->Int32Value()); |
| 1833 ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0)); | 1833 ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0)); |
| 1834 ctx2->Exit(); | 1834 ctx2->Exit(); |
| 1835 ctx1->Exit(); | 1835 ctx1->Exit(); |
| 1836 ctx1p.Dispose(); | 1836 ctx1p.Reset(); |
| 1837 v8::V8::ContextDisposedNotification(); | 1837 v8::V8::ContextDisposedNotification(); |
| 1838 } | 1838 } |
| 1839 CcTest::heap()->CollectAllAvailableGarbage(); | 1839 CcTest::heap()->CollectAllAvailableGarbage(); |
| 1840 CHECK_EQ(2, NumberOfGlobalObjects()); | 1840 CHECK_EQ(2, NumberOfGlobalObjects()); |
| 1841 ctx2p.Dispose(); | 1841 ctx2p.Reset(); |
| 1842 CcTest::heap()->CollectAllAvailableGarbage(); | 1842 CcTest::heap()->CollectAllAvailableGarbage(); |
| 1843 CHECK_EQ(0, NumberOfGlobalObjects()); | 1843 CHECK_EQ(0, NumberOfGlobalObjects()); |
| 1844 } | 1844 } |
| 1845 | 1845 |
| 1846 | 1846 |
| 1847 TEST(LeakNativeContextViaMapKeyed) { | 1847 TEST(LeakNativeContextViaMapKeyed) { |
| 1848 i::FLAG_allow_natives_syntax = true; | 1848 i::FLAG_allow_natives_syntax = true; |
| 1849 v8::Isolate* isolate = CcTest::isolate(); | 1849 v8::Isolate* isolate = CcTest::isolate(); |
| 1850 v8::HandleScope outer_scope(isolate); | 1850 v8::HandleScope outer_scope(isolate); |
| 1851 v8::Persistent<v8::Context> ctx1p; | 1851 v8::Persistent<v8::Context> ctx1p; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1870 ctx2->Global()->Set(v8_str("o"), v); | 1870 ctx2->Global()->Set(v8_str("o"), v); |
| 1871 v8::Local<v8::Value> res = CompileRun( | 1871 v8::Local<v8::Value> res = CompileRun( |
| 1872 "function f() { return o[0]; }" | 1872 "function f() { return o[0]; }" |
| 1873 "for (var i = 0; i < 10; ++i) f();" | 1873 "for (var i = 0; i < 10; ++i) f();" |
| 1874 "%OptimizeFunctionOnNextCall(f);" | 1874 "%OptimizeFunctionOnNextCall(f);" |
| 1875 "f();"); | 1875 "f();"); |
| 1876 CHECK_EQ(42, res->Int32Value()); | 1876 CHECK_EQ(42, res->Int32Value()); |
| 1877 ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0)); | 1877 ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0)); |
| 1878 ctx2->Exit(); | 1878 ctx2->Exit(); |
| 1879 ctx1->Exit(); | 1879 ctx1->Exit(); |
| 1880 ctx1p.Dispose(); | 1880 ctx1p.Reset(); |
| 1881 v8::V8::ContextDisposedNotification(); | 1881 v8::V8::ContextDisposedNotification(); |
| 1882 } | 1882 } |
| 1883 CcTest::heap()->CollectAllAvailableGarbage(); | 1883 CcTest::heap()->CollectAllAvailableGarbage(); |
| 1884 CHECK_EQ(2, NumberOfGlobalObjects()); | 1884 CHECK_EQ(2, NumberOfGlobalObjects()); |
| 1885 ctx2p.Dispose(); | 1885 ctx2p.Reset(); |
| 1886 CcTest::heap()->CollectAllAvailableGarbage(); | 1886 CcTest::heap()->CollectAllAvailableGarbage(); |
| 1887 CHECK_EQ(0, NumberOfGlobalObjects()); | 1887 CHECK_EQ(0, NumberOfGlobalObjects()); |
| 1888 } | 1888 } |
| 1889 | 1889 |
| 1890 | 1890 |
| 1891 TEST(LeakNativeContextViaMapProto) { | 1891 TEST(LeakNativeContextViaMapProto) { |
| 1892 i::FLAG_allow_natives_syntax = true; | 1892 i::FLAG_allow_natives_syntax = true; |
| 1893 v8::Isolate* isolate = CcTest::isolate(); | 1893 v8::Isolate* isolate = CcTest::isolate(); |
| 1894 v8::HandleScope outer_scope(isolate); | 1894 v8::HandleScope outer_scope(isolate); |
| 1895 v8::Persistent<v8::Context> ctx1p; | 1895 v8::Persistent<v8::Context> ctx1p; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1918 " p.__proto__ = o;" | 1918 " p.__proto__ = o;" |
| 1919 " return p.x;" | 1919 " return p.x;" |
| 1920 "}" | 1920 "}" |
| 1921 "for (var i = 0; i < 10; ++i) f();" | 1921 "for (var i = 0; i < 10; ++i) f();" |
| 1922 "%OptimizeFunctionOnNextCall(f);" | 1922 "%OptimizeFunctionOnNextCall(f);" |
| 1923 "f();"); | 1923 "f();"); |
| 1924 CHECK_EQ(42, res->Int32Value()); | 1924 CHECK_EQ(42, res->Int32Value()); |
| 1925 ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0)); | 1925 ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0)); |
| 1926 ctx2->Exit(); | 1926 ctx2->Exit(); |
| 1927 ctx1->Exit(); | 1927 ctx1->Exit(); |
| 1928 ctx1p.Dispose(); | 1928 ctx1p.Reset(); |
| 1929 v8::V8::ContextDisposedNotification(); | 1929 v8::V8::ContextDisposedNotification(); |
| 1930 } | 1930 } |
| 1931 CcTest::heap()->CollectAllAvailableGarbage(); | 1931 CcTest::heap()->CollectAllAvailableGarbage(); |
| 1932 CHECK_EQ(2, NumberOfGlobalObjects()); | 1932 CHECK_EQ(2, NumberOfGlobalObjects()); |
| 1933 ctx2p.Dispose(); | 1933 ctx2p.Reset(); |
| 1934 CcTest::heap()->CollectAllAvailableGarbage(); | 1934 CcTest::heap()->CollectAllAvailableGarbage(); |
| 1935 CHECK_EQ(0, NumberOfGlobalObjects()); | 1935 CHECK_EQ(0, NumberOfGlobalObjects()); |
| 1936 } | 1936 } |
| 1937 | 1937 |
| 1938 | 1938 |
| 1939 TEST(InstanceOfStubWriteBarrier) { | 1939 TEST(InstanceOfStubWriteBarrier) { |
| 1940 i::FLAG_allow_natives_syntax = true; | 1940 i::FLAG_allow_natives_syntax = true; |
| 1941 #ifdef VERIFY_HEAP | 1941 #ifdef VERIFY_HEAP |
| 1942 i::FLAG_verify_heap = true; | 1942 i::FLAG_verify_heap = true; |
| 1943 #endif | 1943 #endif |
| (...skipping 1666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3610 for (int i = 0; i < 4; i++) { | 3610 for (int i = 0; i < 4; i++) { |
| 3611 heap->CollectAllGarbage(false); | 3611 heap->CollectAllGarbage(false); |
| 3612 } | 3612 } |
| 3613 | 3613 |
| 3614 // The site still exists because of our global handle, but the code is no | 3614 // The site still exists because of our global handle, but the code is no |
| 3615 // longer referred to by dependent_code(). | 3615 // longer referred to by dependent_code(). |
| 3616 DependentCode::GroupStartIndexes starts(site->dependent_code()); | 3616 DependentCode::GroupStartIndexes starts(site->dependent_code()); |
| 3617 int index = starts.at(DependentCode::kAllocationSiteTransitionChangedGroup); | 3617 int index = starts.at(DependentCode::kAllocationSiteTransitionChangedGroup); |
| 3618 CHECK(!(site->dependent_code()->is_code_at(index))); | 3618 CHECK(!(site->dependent_code()->is_code_at(index))); |
| 3619 } | 3619 } |
| OLD | NEW |