| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 1822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1833 Persistent<SimpleFinalizedObject> finalized = SimpleFinalizedObject::cre
ate(); | 1833 Persistent<SimpleFinalizedObject> finalized = SimpleFinalizedObject::cre
ate(); |
| 1834 EXPECT_EQ(0, SimpleFinalizedObject::s_destructorCalls); | 1834 EXPECT_EQ(0, SimpleFinalizedObject::s_destructorCalls); |
| 1835 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GC
WithSweep, Heap::ForcedGC); | 1835 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GC
WithSweep, Heap::ForcedGC); |
| 1836 EXPECT_EQ(0, SimpleFinalizedObject::s_destructorCalls); | 1836 EXPECT_EQ(0, SimpleFinalizedObject::s_destructorCalls); |
| 1837 } | 1837 } |
| 1838 | 1838 |
| 1839 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
Sweep, Heap::ForcedGC); | 1839 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
Sweep, Heap::ForcedGC); |
| 1840 EXPECT_EQ(1, SimpleFinalizedObject::s_destructorCalls); | 1840 EXPECT_EQ(1, SimpleFinalizedObject::s_destructorCalls); |
| 1841 } | 1841 } |
| 1842 | 1842 |
| 1843 #if ENABLE(ASSERT) || defined(LEAK_SANITIZER) || defined(ADDRESS_SANITIZER) | |
| 1844 TEST(HeapTest, FreelistReuse) | |
| 1845 { | |
| 1846 clearOutOldGarbage(); | |
| 1847 | |
| 1848 for (int i = 0; i < 100; i++) | |
| 1849 new IntWrapper(i); | |
| 1850 IntWrapper* p1 = new IntWrapper(100); | |
| 1851 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
Sweep, Heap::ForcedGC); | |
| 1852 // In non-production builds, we delay reusing freed memory for at least | |
| 1853 // one GC cycle. | |
| 1854 for (int i = 0; i < 100; i++) { | |
| 1855 IntWrapper* p2 = new IntWrapper(i); | |
| 1856 EXPECT_NE(p1, p2); | |
| 1857 } | |
| 1858 | |
| 1859 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
Sweep, Heap::ForcedGC); | |
| 1860 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
Sweep, Heap::ForcedGC); | |
| 1861 // Now the freed memory in the first GC should be reused. | |
| 1862 bool reusedMemoryFound = false; | |
| 1863 for (int i = 0; i < 10000; i++) { | |
| 1864 IntWrapper* p2 = new IntWrapper(i); | |
| 1865 if (p1 == p2) { | |
| 1866 reusedMemoryFound = true; | |
| 1867 break; | |
| 1868 } | |
| 1869 } | |
| 1870 EXPECT_TRUE(reusedMemoryFound); | |
| 1871 } | |
| 1872 #endif | |
| 1873 | |
| 1874 #if ENABLE(LAZY_SWEEPING) | 1843 #if ENABLE(LAZY_SWEEPING) |
| 1875 TEST(HeapTest, LazySweepingPages) | 1844 TEST(HeapTest, LazySweepingPages) |
| 1876 { | 1845 { |
| 1877 clearOutOldGarbage(); | 1846 clearOutOldGarbage(); |
| 1878 | 1847 |
| 1879 SimpleFinalizedObject::s_destructorCalls = 0; | 1848 SimpleFinalizedObject::s_destructorCalls = 0; |
| 1880 EXPECT_EQ(0, SimpleFinalizedObject::s_destructorCalls); | 1849 EXPECT_EQ(0, SimpleFinalizedObject::s_destructorCalls); |
| 1881 for (int i = 0; i < 1000; i++) | 1850 for (int i = 0; i < 1000; i++) |
| 1882 SimpleFinalizedObject::create(); | 1851 SimpleFinalizedObject::create(); |
| 1883 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
outSweep, Heap::ForcedGC); | 1852 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
outSweep, Heap::ForcedGC); |
| 1884 EXPECT_EQ(0, SimpleFinalizedObject::s_destructorCalls); | 1853 EXPECT_EQ(0, SimpleFinalizedObject::s_destructorCalls); |
| 1885 for (int i = 0; i < 10000; i++) | 1854 for (int i = 0; i < 10000; i++) |
| 1886 SimpleFinalizedObject::create(); | 1855 SimpleFinalizedObject::create(); |
| 1887 EXPECT_EQ(1000, SimpleFinalizedObject::s_destructorCalls); | 1856 EXPECT_EQ(1000, SimpleFinalizedObject::s_destructorCalls); |
| 1888 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
Sweep, Heap::ForcedGC); | 1857 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
Sweep, Heap::ForcedGC); |
| 1889 EXPECT_EQ(11000, SimpleFinalizedObject::s_destructorCalls); | 1858 EXPECT_EQ(11000, SimpleFinalizedObject::s_destructorCalls); |
| 1890 } | 1859 } |
| 1891 | 1860 |
| 1892 TEST(HeapTest, LazySweepingLargeObjectPages) | 1861 TEST(HeapTest, LazySweepingLargeObjectPages) |
| 1893 { | 1862 { |
| 1894 clearOutOldGarbage(); | 1863 clearOutOldGarbage(); |
| 1895 | 1864 |
| 1896 // Create free lists that can be reused for IntWrappers created in | |
| 1897 // LargeHeapObject::create(). | |
| 1898 Persistent<IntWrapper> p1 = new IntWrapper(1); | |
| 1899 for (int i = 0; i < 100; i++) { | |
| 1900 new IntWrapper(i); | |
| 1901 } | |
| 1902 Persistent<IntWrapper> p2 = new IntWrapper(2); | |
| 1903 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
Sweep, Heap::ForcedGC); | |
| 1904 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
Sweep, Heap::ForcedGC); | |
| 1905 | |
| 1906 LargeHeapObject::s_destructorCalls = 0; | 1865 LargeHeapObject::s_destructorCalls = 0; |
| 1907 EXPECT_EQ(0, LargeHeapObject::s_destructorCalls); | 1866 EXPECT_EQ(0, LargeHeapObject::s_destructorCalls); |
| 1908 for (int i = 0; i < 10; i++) | 1867 for (int i = 0; i < 10; i++) |
| 1909 LargeHeapObject::create(); | 1868 LargeHeapObject::create(); |
| 1910 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
outSweep, Heap::ForcedGC); | 1869 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
outSweep, Heap::ForcedGC); |
| 1911 EXPECT_EQ(0, LargeHeapObject::s_destructorCalls); | |
| 1912 for (int i = 0; i < 10; i++) { | 1870 for (int i = 0; i < 10; i++) { |
| 1913 LargeHeapObject::create(); | 1871 LargeHeapObject::create(); |
| 1914 EXPECT_EQ(i + 1, LargeHeapObject::s_destructorCalls); | 1872 EXPECT_EQ(i + 1, LargeHeapObject::s_destructorCalls); |
| 1915 } | 1873 } |
| 1916 LargeHeapObject::create(); | 1874 LargeHeapObject::create(); |
| 1917 LargeHeapObject::create(); | 1875 LargeHeapObject::create(); |
| 1918 EXPECT_EQ(10, LargeHeapObject::s_destructorCalls); | 1876 EXPECT_EQ(10, LargeHeapObject::s_destructorCalls); |
| 1919 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
outSweep, Heap::ForcedGC); | 1877 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
outSweep, Heap::ForcedGC); |
| 1920 EXPECT_EQ(10, LargeHeapObject::s_destructorCalls); | 1878 EXPECT_EQ(10, LargeHeapObject::s_destructorCalls); |
| 1921 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
Sweep, Heap::ForcedGC); | 1879 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
Sweep, Heap::ForcedGC); |
| (...skipping 4244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6166 { | 6124 { |
| 6167 Persistent<ClassWithMember> object = ClassWithMember::create(); | 6125 Persistent<ClassWithMember> object = ClassWithMember::create(); |
| 6168 EXPECT_EQ(0, object->traceCount()); | 6126 EXPECT_EQ(0, object->traceCount()); |
| 6169 TestMixinAllocatingObject* mixin = TestMixinAllocatingObject::create(object.
get()); | 6127 TestMixinAllocatingObject* mixin = TestMixinAllocatingObject::create(object.
get()); |
| 6170 EXPECT_TRUE(mixin); | 6128 EXPECT_TRUE(mixin); |
| 6171 EXPECT_GT(object->traceCount(), 0); | 6129 EXPECT_GT(object->traceCount(), 0); |
| 6172 EXPECT_GT(mixin->traceCount(), 0); | 6130 EXPECT_GT(mixin->traceCount(), 0); |
| 6173 } | 6131 } |
| 6174 | 6132 |
| 6175 } // namespace blink | 6133 } // namespace blink |
| OLD | NEW |