| 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 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 global_handles->Destroy(h4.location()); | 391 global_handles->Destroy(h4.location()); |
| 392 } | 392 } |
| 393 | 393 |
| 394 | 394 |
| 395 static bool WeakPointerCleared = false; | 395 static bool WeakPointerCleared = false; |
| 396 | 396 |
| 397 static void TestWeakGlobalHandleCallback(v8::Isolate* isolate, | 397 static void TestWeakGlobalHandleCallback(v8::Isolate* isolate, |
| 398 v8::Persistent<v8::Value>* handle, | 398 v8::Persistent<v8::Value>* handle, |
| 399 void* id) { | 399 void* id) { |
| 400 if (1234 == reinterpret_cast<intptr_t>(id)) WeakPointerCleared = true; | 400 if (1234 == reinterpret_cast<intptr_t>(id)) WeakPointerCleared = true; |
| 401 handle->Dispose(isolate); | 401 handle->Dispose(); |
| 402 } | 402 } |
| 403 | 403 |
| 404 | 404 |
| 405 TEST(WeakGlobalHandlesScavenge) { | 405 TEST(WeakGlobalHandlesScavenge) { |
| 406 i::FLAG_stress_compaction = false; | 406 i::FLAG_stress_compaction = false; |
| 407 CcTest::InitializeVM(); | 407 CcTest::InitializeVM(); |
| 408 Isolate* isolate = Isolate::Current(); | 408 Isolate* isolate = Isolate::Current(); |
| 409 Heap* heap = isolate->heap(); | 409 Heap* heap = isolate->heap(); |
| 410 Factory* factory = isolate->factory(); | 410 Factory* factory = isolate->factory(); |
| 411 GlobalHandles* global_handles = isolate->global_handles(); | 411 GlobalHandles* global_handles = isolate->global_handles(); |
| (...skipping 1301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1713 ctx2->Global()->Set(v8_str("o"), v); | 1713 ctx2->Global()->Set(v8_str("o"), v); |
| 1714 v8::Local<v8::Value> res = CompileRun( | 1714 v8::Local<v8::Value> res = CompileRun( |
| 1715 "function f() { return o.x; }" | 1715 "function f() { return o.x; }" |
| 1716 "for (var i = 0; i < 10; ++i) f();" | 1716 "for (var i = 0; i < 10; ++i) f();" |
| 1717 "%OptimizeFunctionOnNextCall(f);" | 1717 "%OptimizeFunctionOnNextCall(f);" |
| 1718 "f();"); | 1718 "f();"); |
| 1719 CHECK_EQ(42, res->Int32Value()); | 1719 CHECK_EQ(42, res->Int32Value()); |
| 1720 ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0)); | 1720 ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0)); |
| 1721 ctx2->Exit(); | 1721 ctx2->Exit(); |
| 1722 v8::Local<v8::Context>::New(isolate, ctx1)->Exit(); | 1722 v8::Local<v8::Context>::New(isolate, ctx1)->Exit(); |
| 1723 ctx1p.Dispose(isolate); | 1723 ctx1p.Dispose(); |
| 1724 v8::V8::ContextDisposedNotification(); | 1724 v8::V8::ContextDisposedNotification(); |
| 1725 } | 1725 } |
| 1726 HEAP->CollectAllAvailableGarbage(); | 1726 HEAP->CollectAllAvailableGarbage(); |
| 1727 CHECK_EQ(2, NumberOfGlobalObjects()); | 1727 CHECK_EQ(2, NumberOfGlobalObjects()); |
| 1728 ctx2p.Dispose(isolate); | 1728 ctx2p.Dispose(); |
| 1729 HEAP->CollectAllAvailableGarbage(); | 1729 HEAP->CollectAllAvailableGarbage(); |
| 1730 CHECK_EQ(0, NumberOfGlobalObjects()); | 1730 CHECK_EQ(0, NumberOfGlobalObjects()); |
| 1731 } | 1731 } |
| 1732 | 1732 |
| 1733 | 1733 |
| 1734 // Test that we don't embed functions from foreign contexts into | 1734 // Test that we don't embed functions from foreign contexts into |
| 1735 // optimized code. | 1735 // optimized code. |
| 1736 TEST(LeakNativeContextViaFunction) { | 1736 TEST(LeakNativeContextViaFunction) { |
| 1737 i::FLAG_allow_natives_syntax = true; | 1737 i::FLAG_allow_natives_syntax = true; |
| 1738 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 1738 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1759 ctx2->Global()->Set(v8_str("o"), v); | 1759 ctx2->Global()->Set(v8_str("o"), v); |
| 1760 v8::Local<v8::Value> res = CompileRun( | 1760 v8::Local<v8::Value> res = CompileRun( |
| 1761 "function f(x) { return x(); }" | 1761 "function f(x) { return x(); }" |
| 1762 "for (var i = 0; i < 10; ++i) f(o);" | 1762 "for (var i = 0; i < 10; ++i) f(o);" |
| 1763 "%OptimizeFunctionOnNextCall(f);" | 1763 "%OptimizeFunctionOnNextCall(f);" |
| 1764 "f(o);"); | 1764 "f(o);"); |
| 1765 CHECK_EQ(42, res->Int32Value()); | 1765 CHECK_EQ(42, res->Int32Value()); |
| 1766 ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0)); | 1766 ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0)); |
| 1767 ctx2->Exit(); | 1767 ctx2->Exit(); |
| 1768 ctx1->Exit(); | 1768 ctx1->Exit(); |
| 1769 ctx1p.Dispose(ctx1->GetIsolate()); | 1769 ctx1p.Dispose(); |
| 1770 v8::V8::ContextDisposedNotification(); | 1770 v8::V8::ContextDisposedNotification(); |
| 1771 } | 1771 } |
| 1772 HEAP->CollectAllAvailableGarbage(); | 1772 HEAP->CollectAllAvailableGarbage(); |
| 1773 CHECK_EQ(2, NumberOfGlobalObjects()); | 1773 CHECK_EQ(2, NumberOfGlobalObjects()); |
| 1774 ctx2p.Dispose(isolate); | 1774 ctx2p.Dispose(); |
| 1775 HEAP->CollectAllAvailableGarbage(); | 1775 HEAP->CollectAllAvailableGarbage(); |
| 1776 CHECK_EQ(0, NumberOfGlobalObjects()); | 1776 CHECK_EQ(0, NumberOfGlobalObjects()); |
| 1777 } | 1777 } |
| 1778 | 1778 |
| 1779 | 1779 |
| 1780 TEST(LeakNativeContextViaMapKeyed) { | 1780 TEST(LeakNativeContextViaMapKeyed) { |
| 1781 i::FLAG_allow_natives_syntax = true; | 1781 i::FLAG_allow_natives_syntax = true; |
| 1782 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 1782 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 1783 v8::HandleScope outer_scope(isolate); | 1783 v8::HandleScope outer_scope(isolate); |
| 1784 v8::Persistent<v8::Context> ctx1p; | 1784 v8::Persistent<v8::Context> ctx1p; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1803 ctx2->Global()->Set(v8_str("o"), v); | 1803 ctx2->Global()->Set(v8_str("o"), v); |
| 1804 v8::Local<v8::Value> res = CompileRun( | 1804 v8::Local<v8::Value> res = CompileRun( |
| 1805 "function f() { return o[0]; }" | 1805 "function f() { return o[0]; }" |
| 1806 "for (var i = 0; i < 10; ++i) f();" | 1806 "for (var i = 0; i < 10; ++i) f();" |
| 1807 "%OptimizeFunctionOnNextCall(f);" | 1807 "%OptimizeFunctionOnNextCall(f);" |
| 1808 "f();"); | 1808 "f();"); |
| 1809 CHECK_EQ(42, res->Int32Value()); | 1809 CHECK_EQ(42, res->Int32Value()); |
| 1810 ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0)); | 1810 ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0)); |
| 1811 ctx2->Exit(); | 1811 ctx2->Exit(); |
| 1812 ctx1->Exit(); | 1812 ctx1->Exit(); |
| 1813 ctx1p.Dispose(ctx1->GetIsolate()); | 1813 ctx1p.Dispose(); |
| 1814 v8::V8::ContextDisposedNotification(); | 1814 v8::V8::ContextDisposedNotification(); |
| 1815 } | 1815 } |
| 1816 HEAP->CollectAllAvailableGarbage(); | 1816 HEAP->CollectAllAvailableGarbage(); |
| 1817 CHECK_EQ(2, NumberOfGlobalObjects()); | 1817 CHECK_EQ(2, NumberOfGlobalObjects()); |
| 1818 ctx2p.Dispose(isolate); | 1818 ctx2p.Dispose(); |
| 1819 HEAP->CollectAllAvailableGarbage(); | 1819 HEAP->CollectAllAvailableGarbage(); |
| 1820 CHECK_EQ(0, NumberOfGlobalObjects()); | 1820 CHECK_EQ(0, NumberOfGlobalObjects()); |
| 1821 } | 1821 } |
| 1822 | 1822 |
| 1823 | 1823 |
| 1824 TEST(LeakNativeContextViaMapProto) { | 1824 TEST(LeakNativeContextViaMapProto) { |
| 1825 i::FLAG_allow_natives_syntax = true; | 1825 i::FLAG_allow_natives_syntax = true; |
| 1826 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 1826 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 1827 v8::HandleScope outer_scope(isolate); | 1827 v8::HandleScope outer_scope(isolate); |
| 1828 v8::Persistent<v8::Context> ctx1p; | 1828 v8::Persistent<v8::Context> ctx1p; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1851 " p.__proto__ = o;" | 1851 " p.__proto__ = o;" |
| 1852 " return p.x;" | 1852 " return p.x;" |
| 1853 "}" | 1853 "}" |
| 1854 "for (var i = 0; i < 10; ++i) f();" | 1854 "for (var i = 0; i < 10; ++i) f();" |
| 1855 "%OptimizeFunctionOnNextCall(f);" | 1855 "%OptimizeFunctionOnNextCall(f);" |
| 1856 "f();"); | 1856 "f();"); |
| 1857 CHECK_EQ(42, res->Int32Value()); | 1857 CHECK_EQ(42, res->Int32Value()); |
| 1858 ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0)); | 1858 ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0)); |
| 1859 ctx2->Exit(); | 1859 ctx2->Exit(); |
| 1860 ctx1->Exit(); | 1860 ctx1->Exit(); |
| 1861 ctx1p.Dispose(isolate); | 1861 ctx1p.Dispose(); |
| 1862 v8::V8::ContextDisposedNotification(); | 1862 v8::V8::ContextDisposedNotification(); |
| 1863 } | 1863 } |
| 1864 HEAP->CollectAllAvailableGarbage(); | 1864 HEAP->CollectAllAvailableGarbage(); |
| 1865 CHECK_EQ(2, NumberOfGlobalObjects()); | 1865 CHECK_EQ(2, NumberOfGlobalObjects()); |
| 1866 ctx2p.Dispose(isolate); | 1866 ctx2p.Dispose(); |
| 1867 HEAP->CollectAllAvailableGarbage(); | 1867 HEAP->CollectAllAvailableGarbage(); |
| 1868 CHECK_EQ(0, NumberOfGlobalObjects()); | 1868 CHECK_EQ(0, NumberOfGlobalObjects()); |
| 1869 } | 1869 } |
| 1870 | 1870 |
| 1871 | 1871 |
| 1872 TEST(InstanceOfStubWriteBarrier) { | 1872 TEST(InstanceOfStubWriteBarrier) { |
| 1873 i::FLAG_allow_natives_syntax = true; | 1873 i::FLAG_allow_natives_syntax = true; |
| 1874 #ifdef VERIFY_HEAP | 1874 #ifdef VERIFY_HEAP |
| 1875 i::FLAG_verify_heap = true; | 1875 i::FLAG_verify_heap = true; |
| 1876 #endif | 1876 #endif |
| (...skipping 1569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3446 " var a = new Array(n);" | 3446 " var a = new Array(n);" |
| 3447 " for (var i = 0; i < n; i += 100) a[i] = i;" | 3447 " for (var i = 0; i < n; i += 100) a[i] = i;" |
| 3448 "};" | 3448 "};" |
| 3449 "f(10 * 1024 * 1024);"); | 3449 "f(10 * 1024 * 1024);"); |
| 3450 IncrementalMarking* marking = HEAP->incremental_marking(); | 3450 IncrementalMarking* marking = HEAP->incremental_marking(); |
| 3451 if (marking->IsStopped()) marking->Start(); | 3451 if (marking->IsStopped()) marking->Start(); |
| 3452 // This big step should be sufficient to mark the whole array. | 3452 // This big step should be sufficient to mark the whole array. |
| 3453 marking->Step(100 * MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); | 3453 marking->Step(100 * MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); |
| 3454 ASSERT(marking->IsComplete()); | 3454 ASSERT(marking->IsComplete()); |
| 3455 } | 3455 } |
| OLD | NEW |