Chromium Code Reviews| 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 16 matching lines...) Expand all Loading... | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "platform/heap/Heap.h" | 32 #include "platform/heap/Heap.h" |
| 33 | 33 |
| 34 #include "platform/ScriptForbiddenScope.h" | 34 #include "platform/ScriptForbiddenScope.h" |
| 35 #include "platform/Task.h" | 35 #include "platform/Task.h" |
| 36 #include "platform/TraceEvent.h" | 36 #include "platform/TraceEvent.h" |
| 37 #include "platform/heap/BlinkGCMemoryDumpProvider.h" | |
| 37 #include "platform/heap/CallbackStack.h" | 38 #include "platform/heap/CallbackStack.h" |
| 38 #include "platform/heap/MarkingVisitor.h" | 39 #include "platform/heap/MarkingVisitor.h" |
| 39 #include "platform/heap/PageMemory.h" | 40 #include "platform/heap/PageMemory.h" |
| 40 #include "platform/heap/PagePool.h" | 41 #include "platform/heap/PagePool.h" |
| 41 #include "platform/heap/SafePoint.h" | 42 #include "platform/heap/SafePoint.h" |
| 42 #include "platform/heap/ThreadState.h" | 43 #include "platform/heap/ThreadState.h" |
| 43 #include "public/platform/Platform.h" | 44 #include "public/platform/Platform.h" |
| 45 #include "public/platform/WebMemoryAllocatorDump.h" | |
| 46 #include "public/platform/WebProcessMemoryDump.h" | |
|
Primiano Tucci (use gerrit)
2015/05/22 19:45:57
I think you don't need this anymore
ssid
2015/05/26 11:08:43
Done.
| |
| 44 #include "wtf/Assertions.h" | 47 #include "wtf/Assertions.h" |
| 45 #include "wtf/ContainerAnnotations.h" | 48 #include "wtf/ContainerAnnotations.h" |
| 46 #include "wtf/LeakAnnotations.h" | 49 #include "wtf/LeakAnnotations.h" |
| 47 #include "wtf/MainThread.h" | 50 #include "wtf/MainThread.h" |
| 48 #include "wtf/PageAllocator.h" | 51 #include "wtf/PageAllocator.h" |
| 49 #include "wtf/Partitions.h" | 52 #include "wtf/Partitions.h" |
| 50 #include "wtf/PassOwnPtr.h" | 53 #include "wtf/PassOwnPtr.h" |
| 51 #if ENABLE(GC_PROFILING) | 54 #if ENABLE(GC_PROFILING) |
| 52 #include "platform/TracedValue.h" | 55 #include "platform/TracedValue.h" |
| 53 #include "wtf/HashMap.h" | 56 #include "wtf/HashMap.h" |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 | 209 |
| 207 ASSERT(!m_firstUnsweptPage); | 210 ASSERT(!m_firstUnsweptPage); |
| 208 // Add the BaseHeap's pages to the orphanedPagePool. | 211 // Add the BaseHeap's pages to the orphanedPagePool. |
| 209 for (BasePage* page = m_firstPage; page; page = page->next()) { | 212 for (BasePage* page = m_firstPage; page; page = page->next()) { |
| 210 Heap::decreaseAllocatedSpace(page->size()); | 213 Heap::decreaseAllocatedSpace(page->size()); |
| 211 Heap::orphanedPagePool()->addOrphanedPage(heapIndex(), page); | 214 Heap::orphanedPagePool()->addOrphanedPage(heapIndex(), page); |
| 212 } | 215 } |
| 213 m_firstPage = nullptr; | 216 m_firstPage = nullptr; |
| 214 } | 217 } |
| 215 | 218 |
| 219 void BaseHeap::dumpMemory(const String& dumpBaseName) | |
| 220 { | |
| 221 size_t pageCount = 0; | |
| 222 for (BasePage* page = m_firstPage; page; page = page->next()) { | |
| 223 pageCount++; | |
| 224 } | |
| 225 WebMemoryAllocatorDump* allocatorDump = BlinkGCMemoryDumpProvider::instance( )->createMemoryAllocatorDumpForLastGC(dumpBaseName); | |
| 226 allocatorDump->AddScalar("blink_page_count", "objects", pageCount); | |
| 227 } | |
| 228 | |
| 216 #if ENABLE(ASSERT) || ENABLE(GC_PROFILING) | 229 #if ENABLE(ASSERT) || ENABLE(GC_PROFILING) |
| 217 BasePage* BaseHeap::findPageFromAddress(Address address) | 230 BasePage* BaseHeap::findPageFromAddress(Address address) |
| 218 { | 231 { |
| 219 for (BasePage* page = m_firstPage; page; page = page->next()) { | 232 for (BasePage* page = m_firstPage; page; page = page->next()) { |
| 220 if (page->contains(address)) | 233 if (page->contains(address)) |
| 221 return page; | 234 return page; |
| 222 } | 235 } |
| 223 for (BasePage* page = m_firstUnsweptPage; page; page = page->next()) { | 236 for (BasePage* page = m_firstUnsweptPage; page; page = page->next()) { |
| 224 if (page->contains(address)) | 237 if (page->contains(address)) |
| 225 return page; | 238 return page; |
| (...skipping 1392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1618 s_heapDoesNotContainCache = new HeapDoesNotContainCache(); | 1631 s_heapDoesNotContainCache = new HeapDoesNotContainCache(); |
| 1619 s_markingVisitor = new MarkingVisitor<Visitor::GlobalMarking>(); | 1632 s_markingVisitor = new MarkingVisitor<Visitor::GlobalMarking>(); |
| 1620 s_freePagePool = new FreePagePool(); | 1633 s_freePagePool = new FreePagePool(); |
| 1621 s_orphanedPagePool = new OrphanedPagePool(); | 1634 s_orphanedPagePool = new OrphanedPagePool(); |
| 1622 s_allocatedObjectSize = 0; | 1635 s_allocatedObjectSize = 0; |
| 1623 s_allocatedSpace = 0; | 1636 s_allocatedSpace = 0; |
| 1624 s_markedObjectSize = 0; | 1637 s_markedObjectSize = 0; |
| 1625 s_estimatedMarkingTimePerByte = 0.0; | 1638 s_estimatedMarkingTimePerByte = 0.0; |
| 1626 | 1639 |
| 1627 GCInfoTable::init(); | 1640 GCInfoTable::init(); |
| 1641 | |
| 1642 if (Platform::current()->mainThread()) | |
|
Primiano Tucci (use gerrit)
2015/05/22 19:45:57
Question for haraken@: for production (i.e. non te
ssid
2015/05/26 11:08:43
changed it.
| |
| 1643 Platform::current()->registerMemoryDumpProvider(BlinkGCMemoryDumpProvide r::instance()); | |
| 1628 } | 1644 } |
| 1629 | 1645 |
| 1630 void Heap::shutdown() | 1646 void Heap::shutdown() |
| 1631 { | 1647 { |
| 1648 if (Platform::current()->mainThread()) | |
| 1649 Platform::current()->unregisterMemoryDumpProvider(BlinkGCMemoryDumpProvi der::instance()); | |
| 1650 | |
| 1632 s_shutdownCalled = true; | 1651 s_shutdownCalled = true; |
| 1633 ThreadState::shutdownHeapIfNecessary(); | 1652 ThreadState::shutdownHeapIfNecessary(); |
| 1634 } | 1653 } |
| 1635 | 1654 |
| 1636 void Heap::doShutdown() | 1655 void Heap::doShutdown() |
| 1637 { | 1656 { |
| 1638 // We don't want to call doShutdown() twice. | 1657 // We don't want to call doShutdown() twice. |
| 1639 if (!s_markingVisitor) | 1658 if (!s_markingVisitor) |
| 1640 return; | 1659 return; |
| 1641 | 1660 |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1856 | 1875 |
| 1857 void Heap::preGC() | 1876 void Heap::preGC() |
| 1858 { | 1877 { |
| 1859 ASSERT(!ThreadState::current()->isInGC()); | 1878 ASSERT(!ThreadState::current()->isInGC()); |
| 1860 for (ThreadState* state : ThreadState::attachedThreads()) | 1879 for (ThreadState* state : ThreadState::attachedThreads()) |
| 1861 state->preGC(); | 1880 state->preGC(); |
| 1862 } | 1881 } |
| 1863 | 1882 |
| 1864 void Heap::postGC(ThreadState::GCType gcType) | 1883 void Heap::postGC(ThreadState::GCType gcType) |
| 1865 { | 1884 { |
| 1885 // TODO(ssid): Change this to use api from memory-infra to check tracing | |
| 1886 // memory_tracing_enabled (crbug.com/490087). | |
| 1887 bool enabled; | |
|
Primiano Tucci (use gerrit)
2015/05/22 19:45:57
Can you encapsulate this into a "static inline boo
ssid
2015/05/26 11:08:43
Done.
| |
| 1888 TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("memory-infra") , &enabled); | |
| 1889 if (enabled) | |
| 1890 BlinkGCMemoryDumpProvider::instance()->clearLastProcessMemoryDump(); | |
| 1891 | |
| 1866 ASSERT(ThreadState::current()->isInGC()); | 1892 ASSERT(ThreadState::current()->isInGC()); |
| 1867 for (ThreadState* state : ThreadState::attachedThreads()) | 1893 for (ThreadState* state : ThreadState::attachedThreads()) { |
| 1894 if (enabled) | |
| 1895 state->dumpMemory(); | |
| 1896 | |
| 1868 state->postGC(gcType); | 1897 state->postGC(gcType); |
| 1898 } | |
| 1899 | |
| 1900 // TODO(ssid): Request global dump from blink when support is available | |
| 1901 // (crbug.com/490087). For the moment the dump is periodically invoked by | |
| 1902 // the MemoryDumpManager every X secs. | |
| 1869 } | 1903 } |
| 1870 | 1904 |
| 1871 const char* Heap::gcReasonString(GCReason reason) | 1905 const char* Heap::gcReasonString(GCReason reason) |
| 1872 { | 1906 { |
| 1873 switch (reason) { | 1907 switch (reason) { |
| 1874 #define STRINGIFY_REASON(reason) case reason: return #reason; | 1908 #define STRINGIFY_REASON(reason) case reason: return #reason; |
| 1875 STRINGIFY_REASON(IdleGC); | 1909 STRINGIFY_REASON(IdleGC); |
| 1876 STRINGIFY_REASON(PreciseGC); | 1910 STRINGIFY_REASON(PreciseGC); |
| 1877 STRINGIFY_REASON(ConservativeGC); | 1911 STRINGIFY_REASON(ConservativeGC); |
| 1878 STRINGIFY_REASON(ForcedGC); | 1912 STRINGIFY_REASON(ForcedGC); |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2235 size_t Heap::s_allocatedObjectSize = 0; | 2269 size_t Heap::s_allocatedObjectSize = 0; |
| 2236 size_t Heap::s_allocatedSpace = 0; | 2270 size_t Heap::s_allocatedSpace = 0; |
| 2237 size_t Heap::s_markedObjectSize = 0; | 2271 size_t Heap::s_markedObjectSize = 0; |
| 2238 // We don't want to use 0 KB for the initial value because it may end up | 2272 // We don't want to use 0 KB for the initial value because it may end up |
| 2239 // triggering the first GC of some thread too prematurely. | 2273 // triggering the first GC of some thread too prematurely. |
| 2240 size_t Heap::s_estimatedLiveObjectSize = 512 * 1024; | 2274 size_t Heap::s_estimatedLiveObjectSize = 512 * 1024; |
| 2241 size_t Heap::s_externalObjectSizeAtLastGC = 0; | 2275 size_t Heap::s_externalObjectSizeAtLastGC = 0; |
| 2242 double Heap::s_estimatedMarkingTimePerByte = 0.0; | 2276 double Heap::s_estimatedMarkingTimePerByte = 0.0; |
| 2243 | 2277 |
| 2244 } // namespace blink | 2278 } // namespace blink |
| OLD | NEW |