| 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 1302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1313 | 1313 |
| 1314 Isolate* isolate = Isolate::Current(); | 1314 Isolate* isolate = Isolate::Current(); |
| 1315 Heap* heap = isolate->heap(); | 1315 Heap* heap = isolate->heap(); |
| 1316 HandleScope scope(isolate); | 1316 HandleScope scope(isolate); |
| 1317 v8::Handle<v8::Context> ctx[kNumTestContexts]; | 1317 v8::Handle<v8::Context> ctx[kNumTestContexts]; |
| 1318 | 1318 |
| 1319 CHECK_EQ(0, CountNativeContexts()); | 1319 CHECK_EQ(0, CountNativeContexts()); |
| 1320 | 1320 |
| 1321 // Create a number of global contests which gets linked together. | 1321 // Create a number of global contests which gets linked together. |
| 1322 for (int i = 0; i < kNumTestContexts; i++) { | 1322 for (int i = 0; i < kNumTestContexts; i++) { |
| 1323 ctx[i] = v8::Context::New(v8::Isolate::GetCurrent()); | 1323 ctx[i] = v8::Context::New(CcTest::isolate()); |
| 1324 | 1324 |
| 1325 // Collect garbage that might have been created by one of the | 1325 // Collect garbage that might have been created by one of the |
| 1326 // installed extensions. | 1326 // installed extensions. |
| 1327 isolate->compilation_cache()->Clear(); | 1327 isolate->compilation_cache()->Clear(); |
| 1328 heap->CollectAllGarbage(Heap::kNoGCFlags); | 1328 heap->CollectAllGarbage(Heap::kNoGCFlags); |
| 1329 | 1329 |
| 1330 bool opt = (FLAG_always_opt && isolate->use_crankshaft()); | 1330 bool opt = (FLAG_always_opt && isolate->use_crankshaft()); |
| 1331 | 1331 |
| 1332 CHECK_EQ(i + 1, CountNativeContexts()); | 1332 CHECK_EQ(i + 1, CountNativeContexts()); |
| 1333 | 1333 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1459 static const int kNumTestContexts = 10; | 1459 static const int kNumTestContexts = 10; |
| 1460 | 1460 |
| 1461 HandleScope scope(isolate); | 1461 HandleScope scope(isolate); |
| 1462 v8::Handle<v8::Context> ctx[kNumTestContexts]; | 1462 v8::Handle<v8::Context> ctx[kNumTestContexts]; |
| 1463 | 1463 |
| 1464 CHECK_EQ(0, CountNativeContexts()); | 1464 CHECK_EQ(0, CountNativeContexts()); |
| 1465 | 1465 |
| 1466 // Create an number of contexts and check the length of the weak list both | 1466 // Create an number of contexts and check the length of the weak list both |
| 1467 // with and without GCs while iterating the list. | 1467 // with and without GCs while iterating the list. |
| 1468 for (int i = 0; i < kNumTestContexts; i++) { | 1468 for (int i = 0; i < kNumTestContexts; i++) { |
| 1469 ctx[i] = v8::Context::New(v8::Isolate::GetCurrent()); | 1469 ctx[i] = v8::Context::New(CcTest::isolate()); |
| 1470 CHECK_EQ(i + 1, CountNativeContexts()); | 1470 CHECK_EQ(i + 1, CountNativeContexts()); |
| 1471 CHECK_EQ(i + 1, CountNativeContextsWithGC(isolate, i / 2 + 1)); | 1471 CHECK_EQ(i + 1, CountNativeContextsWithGC(isolate, i / 2 + 1)); |
| 1472 } | 1472 } |
| 1473 | 1473 |
| 1474 bool opt = (FLAG_always_opt && isolate->use_crankshaft()); | 1474 bool opt = (FLAG_always_opt && isolate->use_crankshaft()); |
| 1475 | 1475 |
| 1476 // Compile a number of functions the length of the weak list of optimized | 1476 // Compile a number of functions the length of the weak list of optimized |
| 1477 // functions both with and without GCs while iterating the list. | 1477 // functions both with and without GCs while iterating the list. |
| 1478 ctx[0]->Enter(); | 1478 ctx[0]->Enter(); |
| 1479 const char* source = "function f1() { };" | 1479 const char* source = "function f1() { };" |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1677 if (obj->IsGlobalObject()) count++; | 1677 if (obj->IsGlobalObject()) count++; |
| 1678 } | 1678 } |
| 1679 return count; | 1679 return count; |
| 1680 } | 1680 } |
| 1681 | 1681 |
| 1682 | 1682 |
| 1683 // Test that we don't embed maps from foreign contexts into | 1683 // Test that we don't embed maps from foreign contexts into |
| 1684 // optimized code. | 1684 // optimized code. |
| 1685 TEST(LeakNativeContextViaMap) { | 1685 TEST(LeakNativeContextViaMap) { |
| 1686 i::FLAG_allow_natives_syntax = true; | 1686 i::FLAG_allow_natives_syntax = true; |
| 1687 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 1687 v8::Isolate* isolate = CcTest::isolate(); |
| 1688 v8::HandleScope outer_scope(isolate); | 1688 v8::HandleScope outer_scope(isolate); |
| 1689 v8::Persistent<v8::Context> ctx1p; | 1689 v8::Persistent<v8::Context> ctx1p; |
| 1690 v8::Persistent<v8::Context> ctx2p; | 1690 v8::Persistent<v8::Context> ctx2p; |
| 1691 { | 1691 { |
| 1692 v8::HandleScope scope(isolate); | 1692 v8::HandleScope scope(isolate); |
| 1693 ctx1p.Reset(isolate, v8::Context::New(isolate)); | 1693 ctx1p.Reset(isolate, v8::Context::New(isolate)); |
| 1694 ctx2p.Reset(isolate, v8::Context::New(isolate)); | 1694 ctx2p.Reset(isolate, v8::Context::New(isolate)); |
| 1695 v8::Local<v8::Context>::New(isolate, ctx1p)->Enter(); | 1695 v8::Local<v8::Context>::New(isolate, ctx1p)->Enter(); |
| 1696 } | 1696 } |
| 1697 | 1697 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1723 ctx2p.Dispose(); | 1723 ctx2p.Dispose(); |
| 1724 HEAP->CollectAllAvailableGarbage(); | 1724 HEAP->CollectAllAvailableGarbage(); |
| 1725 CHECK_EQ(0, NumberOfGlobalObjects()); | 1725 CHECK_EQ(0, NumberOfGlobalObjects()); |
| 1726 } | 1726 } |
| 1727 | 1727 |
| 1728 | 1728 |
| 1729 // Test that we don't embed functions from foreign contexts into | 1729 // Test that we don't embed functions from foreign contexts into |
| 1730 // optimized code. | 1730 // optimized code. |
| 1731 TEST(LeakNativeContextViaFunction) { | 1731 TEST(LeakNativeContextViaFunction) { |
| 1732 i::FLAG_allow_natives_syntax = true; | 1732 i::FLAG_allow_natives_syntax = true; |
| 1733 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 1733 v8::Isolate* isolate = CcTest::isolate(); |
| 1734 v8::HandleScope outer_scope(isolate); | 1734 v8::HandleScope outer_scope(isolate); |
| 1735 v8::Persistent<v8::Context> ctx1p; | 1735 v8::Persistent<v8::Context> ctx1p; |
| 1736 v8::Persistent<v8::Context> ctx2p; | 1736 v8::Persistent<v8::Context> ctx2p; |
| 1737 { | 1737 { |
| 1738 v8::HandleScope scope(isolate); | 1738 v8::HandleScope scope(isolate); |
| 1739 ctx1p.Reset(isolate, v8::Context::New(isolate)); | 1739 ctx1p.Reset(isolate, v8::Context::New(isolate)); |
| 1740 ctx2p.Reset(isolate, v8::Context::New(isolate)); | 1740 ctx2p.Reset(isolate, v8::Context::New(isolate)); |
| 1741 v8::Local<v8::Context>::New(isolate, ctx1p)->Enter(); | 1741 v8::Local<v8::Context>::New(isolate, ctx1p)->Enter(); |
| 1742 } | 1742 } |
| 1743 | 1743 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1767 HEAP->CollectAllAvailableGarbage(); | 1767 HEAP->CollectAllAvailableGarbage(); |
| 1768 CHECK_EQ(2, NumberOfGlobalObjects()); | 1768 CHECK_EQ(2, NumberOfGlobalObjects()); |
| 1769 ctx2p.Dispose(); | 1769 ctx2p.Dispose(); |
| 1770 HEAP->CollectAllAvailableGarbage(); | 1770 HEAP->CollectAllAvailableGarbage(); |
| 1771 CHECK_EQ(0, NumberOfGlobalObjects()); | 1771 CHECK_EQ(0, NumberOfGlobalObjects()); |
| 1772 } | 1772 } |
| 1773 | 1773 |
| 1774 | 1774 |
| 1775 TEST(LeakNativeContextViaMapKeyed) { | 1775 TEST(LeakNativeContextViaMapKeyed) { |
| 1776 i::FLAG_allow_natives_syntax = true; | 1776 i::FLAG_allow_natives_syntax = true; |
| 1777 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 1777 v8::Isolate* isolate = CcTest::isolate(); |
| 1778 v8::HandleScope outer_scope(isolate); | 1778 v8::HandleScope outer_scope(isolate); |
| 1779 v8::Persistent<v8::Context> ctx1p; | 1779 v8::Persistent<v8::Context> ctx1p; |
| 1780 v8::Persistent<v8::Context> ctx2p; | 1780 v8::Persistent<v8::Context> ctx2p; |
| 1781 { | 1781 { |
| 1782 v8::HandleScope scope(isolate); | 1782 v8::HandleScope scope(isolate); |
| 1783 ctx1p.Reset(isolate, v8::Context::New(isolate)); | 1783 ctx1p.Reset(isolate, v8::Context::New(isolate)); |
| 1784 ctx2p.Reset(isolate, v8::Context::New(isolate)); | 1784 ctx2p.Reset(isolate, v8::Context::New(isolate)); |
| 1785 v8::Local<v8::Context>::New(isolate, ctx1p)->Enter(); | 1785 v8::Local<v8::Context>::New(isolate, ctx1p)->Enter(); |
| 1786 } | 1786 } |
| 1787 | 1787 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1811 HEAP->CollectAllAvailableGarbage(); | 1811 HEAP->CollectAllAvailableGarbage(); |
| 1812 CHECK_EQ(2, NumberOfGlobalObjects()); | 1812 CHECK_EQ(2, NumberOfGlobalObjects()); |
| 1813 ctx2p.Dispose(); | 1813 ctx2p.Dispose(); |
| 1814 HEAP->CollectAllAvailableGarbage(); | 1814 HEAP->CollectAllAvailableGarbage(); |
| 1815 CHECK_EQ(0, NumberOfGlobalObjects()); | 1815 CHECK_EQ(0, NumberOfGlobalObjects()); |
| 1816 } | 1816 } |
| 1817 | 1817 |
| 1818 | 1818 |
| 1819 TEST(LeakNativeContextViaMapProto) { | 1819 TEST(LeakNativeContextViaMapProto) { |
| 1820 i::FLAG_allow_natives_syntax = true; | 1820 i::FLAG_allow_natives_syntax = true; |
| 1821 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 1821 v8::Isolate* isolate = CcTest::isolate(); |
| 1822 v8::HandleScope outer_scope(isolate); | 1822 v8::HandleScope outer_scope(isolate); |
| 1823 v8::Persistent<v8::Context> ctx1p; | 1823 v8::Persistent<v8::Context> ctx1p; |
| 1824 v8::Persistent<v8::Context> ctx2p; | 1824 v8::Persistent<v8::Context> ctx2p; |
| 1825 { | 1825 { |
| 1826 v8::HandleScope scope(isolate); | 1826 v8::HandleScope scope(isolate); |
| 1827 ctx1p.Reset(isolate, v8::Context::New(isolate)); | 1827 ctx1p.Reset(isolate, v8::Context::New(isolate)); |
| 1828 ctx2p.Reset(isolate, v8::Context::New(isolate)); | 1828 ctx2p.Reset(isolate, v8::Context::New(isolate)); |
| 1829 v8::Local<v8::Context>::New(isolate, ctx1p)->Enter(); | 1829 v8::Local<v8::Context>::New(isolate, ctx1p)->Enter(); |
| 1830 } | 1830 } |
| 1831 | 1831 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1866 | 1866 |
| 1867 TEST(InstanceOfStubWriteBarrier) { | 1867 TEST(InstanceOfStubWriteBarrier) { |
| 1868 i::FLAG_allow_natives_syntax = true; | 1868 i::FLAG_allow_natives_syntax = true; |
| 1869 #ifdef VERIFY_HEAP | 1869 #ifdef VERIFY_HEAP |
| 1870 i::FLAG_verify_heap = true; | 1870 i::FLAG_verify_heap = true; |
| 1871 #endif | 1871 #endif |
| 1872 | 1872 |
| 1873 CcTest::InitializeVM(); | 1873 CcTest::InitializeVM(); |
| 1874 if (!i::Isolate::Current()->use_crankshaft()) return; | 1874 if (!i::Isolate::Current()->use_crankshaft()) return; |
| 1875 if (i::FLAG_force_marking_deque_overflows) return; | 1875 if (i::FLAG_force_marking_deque_overflows) return; |
| 1876 v8::HandleScope outer_scope(v8::Isolate::GetCurrent()); | 1876 v8::HandleScope outer_scope(CcTest::isolate()); |
| 1877 | 1877 |
| 1878 { | 1878 { |
| 1879 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 1879 v8::HandleScope scope(CcTest::isolate()); |
| 1880 CompileRun( | 1880 CompileRun( |
| 1881 "function foo () { }" | 1881 "function foo () { }" |
| 1882 "function mkbar () { return new (new Function(\"\")) (); }" | 1882 "function mkbar () { return new (new Function(\"\")) (); }" |
| 1883 "function f (x) { return (x instanceof foo); }" | 1883 "function f (x) { return (x instanceof foo); }" |
| 1884 "function g () { f(mkbar()); }" | 1884 "function g () { f(mkbar()); }" |
| 1885 "f(new foo()); f(new foo());" | 1885 "f(new foo()); f(new foo());" |
| 1886 "%OptimizeFunctionOnNextCall(f);" | 1886 "%OptimizeFunctionOnNextCall(f);" |
| 1887 "f(new foo()); g();"); | 1887 "f(new foo()); g();"); |
| 1888 } | 1888 } |
| 1889 | 1889 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1901 while (!Marking::IsBlack(Marking::MarkBitFrom(f->code())) && | 1901 while (!Marking::IsBlack(Marking::MarkBitFrom(f->code())) && |
| 1902 !marking->IsStopped()) { | 1902 !marking->IsStopped()) { |
| 1903 // Discard any pending GC requests otherwise we will get GC when we enter | 1903 // Discard any pending GC requests otherwise we will get GC when we enter |
| 1904 // code below. | 1904 // code below. |
| 1905 marking->Step(MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); | 1905 marking->Step(MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); |
| 1906 } | 1906 } |
| 1907 | 1907 |
| 1908 CHECK(marking->IsMarking()); | 1908 CHECK(marking->IsMarking()); |
| 1909 | 1909 |
| 1910 { | 1910 { |
| 1911 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 1911 v8::HandleScope scope(CcTest::isolate()); |
| 1912 v8::Handle<v8::Object> global = v8::Context::GetCurrent()->Global(); | 1912 v8::Handle<v8::Object> global = v8::Context::GetCurrent()->Global(); |
| 1913 v8::Handle<v8::Function> g = | 1913 v8::Handle<v8::Function> g = |
| 1914 v8::Handle<v8::Function>::Cast(global->Get(v8_str("g"))); | 1914 v8::Handle<v8::Function>::Cast(global->Get(v8_str("g"))); |
| 1915 g->Call(global, 0, NULL); | 1915 g->Call(global, 0, NULL); |
| 1916 } | 1916 } |
| 1917 | 1917 |
| 1918 HEAP->incremental_marking()->set_should_hurry(true); | 1918 HEAP->incremental_marking()->set_should_hurry(true); |
| 1919 HEAP->CollectGarbage(OLD_POINTER_SPACE); | 1919 HEAP->CollectGarbage(OLD_POINTER_SPACE); |
| 1920 } | 1920 } |
| 1921 | 1921 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1982 | 1982 |
| 1983 TEST(ResetSharedFunctionInfoCountersDuringIncrementalMarking) { | 1983 TEST(ResetSharedFunctionInfoCountersDuringIncrementalMarking) { |
| 1984 i::FLAG_stress_compaction = false; | 1984 i::FLAG_stress_compaction = false; |
| 1985 i::FLAG_allow_natives_syntax = true; | 1985 i::FLAG_allow_natives_syntax = true; |
| 1986 #ifdef VERIFY_HEAP | 1986 #ifdef VERIFY_HEAP |
| 1987 i::FLAG_verify_heap = true; | 1987 i::FLAG_verify_heap = true; |
| 1988 #endif | 1988 #endif |
| 1989 | 1989 |
| 1990 CcTest::InitializeVM(); | 1990 CcTest::InitializeVM(); |
| 1991 if (!i::Isolate::Current()->use_crankshaft()) return; | 1991 if (!i::Isolate::Current()->use_crankshaft()) return; |
| 1992 v8::HandleScope outer_scope(v8::Isolate::GetCurrent()); | 1992 v8::HandleScope outer_scope(CcTest::isolate()); |
| 1993 | 1993 |
| 1994 { | 1994 { |
| 1995 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 1995 v8::HandleScope scope(CcTest::isolate()); |
| 1996 CompileRun( | 1996 CompileRun( |
| 1997 "function f () {" | 1997 "function f () {" |
| 1998 " var s = 0;" | 1998 " var s = 0;" |
| 1999 " for (var i = 0; i < 100; i++) s += i;" | 1999 " for (var i = 0; i < 100; i++) s += i;" |
| 2000 " return s;" | 2000 " return s;" |
| 2001 "}" | 2001 "}" |
| 2002 "f(); f();" | 2002 "f(); f();" |
| 2003 "%OptimizeFunctionOnNextCall(f);" | 2003 "%OptimizeFunctionOnNextCall(f);" |
| 2004 "f();"); | 2004 "f();"); |
| 2005 } | 2005 } |
| (...skipping 1430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3436 " var a = new Array(n);" | 3436 " var a = new Array(n);" |
| 3437 " for (var i = 0; i < n; i += 100) a[i] = i;" | 3437 " for (var i = 0; i < n; i += 100) a[i] = i;" |
| 3438 "};" | 3438 "};" |
| 3439 "f(10 * 1024 * 1024);"); | 3439 "f(10 * 1024 * 1024);"); |
| 3440 IncrementalMarking* marking = HEAP->incremental_marking(); | 3440 IncrementalMarking* marking = HEAP->incremental_marking(); |
| 3441 if (marking->IsStopped()) marking->Start(); | 3441 if (marking->IsStopped()) marking->Start(); |
| 3442 // This big step should be sufficient to mark the whole array. | 3442 // This big step should be sufficient to mark the whole array. |
| 3443 marking->Step(100 * MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); | 3443 marking->Step(100 * MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); |
| 3444 ASSERT(marking->IsComplete()); | 3444 ASSERT(marking->IsComplete()); |
| 3445 } | 3445 } |
| OLD | NEW |