| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 12 matching lines...) Expand all Loading... |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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 "base/thread_task_runner_handle.h" | 31 #include "base/thread_task_runner_handle.h" |
| 32 #include "base/trace_event/memory_dump_manager.h" | 32 #include "base/trace_event/memory_dump_manager.h" |
| 33 #include "platform/Histogram.h" |
| 33 #include "platform/PartitionAllocMemoryDumpProvider.h" | 34 #include "platform/PartitionAllocMemoryDumpProvider.h" |
| 34 #include "platform/fonts/FontCacheMemoryDumpProvider.h" | 35 #include "platform/fonts/FontCacheMemoryDumpProvider.h" |
| 35 #include "platform/graphics/CompositorFactory.h" | 36 #include "platform/graphics/CompositorFactory.h" |
| 37 #include "platform/heap/GCTaskRunner.h" |
| 36 #include "platform/web_memory_dump_provider_adapter.h" | 38 #include "platform/web_memory_dump_provider_adapter.h" |
| 37 #include "public/platform/Platform.h" | 39 #include "public/platform/Platform.h" |
| 40 #include "public/platform/WebPrerenderingSupport.h" |
| 38 #include "wtf/HashMap.h" | 41 #include "wtf/HashMap.h" |
| 39 #include "wtf/OwnPtr.h" | 42 #include "wtf/OwnPtr.h" |
| 40 | 43 |
| 41 namespace blink { | 44 namespace blink { |
| 42 | 45 |
| 43 static Platform* s_platform = 0; | 46 static Platform* s_platform = nullptr; |
| 44 using ProviderToAdapterMap = HashMap<WebMemoryDumpProvider*, OwnPtr<WebMemoryDum
pProviderAdapter>>; | 47 using ProviderToAdapterMap = HashMap<WebMemoryDumpProvider*, OwnPtr<WebMemoryDum
pProviderAdapter>>; |
| 45 | 48 |
| 49 static GCTaskRunner* s_gcTaskRunner = nullptr; |
| 50 |
| 46 namespace { | 51 namespace { |
| 47 | 52 |
| 48 ProviderToAdapterMap& memoryDumpProviders() | 53 ProviderToAdapterMap& memoryDumpProviders() |
| 49 { | 54 { |
| 50 DEFINE_STATIC_LOCAL(ProviderToAdapterMap, providerToAdapterMap, ()); | 55 DEFINE_STATIC_LOCAL(ProviderToAdapterMap, providerToAdapterMap, ()); |
| 51 return providerToAdapterMap; | 56 return providerToAdapterMap; |
| 52 } | 57 } |
| 53 | 58 |
| 54 } // namespace | 59 } // namespace |
| 55 | 60 |
| 56 Platform::Platform() | 61 Platform::Platform() |
| 57 : m_mainThread(0) | 62 : m_mainThread(0) |
| 58 { | 63 { |
| 59 } | 64 } |
| 60 | 65 |
| 66 static void maxObservedSizeFunction(size_t sizeInMB) |
| 67 { |
| 68 const size_t supportedMaxSizeInMB = 4 * 1024; |
| 69 if (sizeInMB >= supportedMaxSizeInMB) |
| 70 sizeInMB = supportedMaxSizeInMB - 1; |
| 71 |
| 72 // Send a UseCounter only when we see the highest memory usage |
| 73 // we've ever seen. |
| 74 DEFINE_STATIC_LOCAL(EnumerationHistogram, committedSizeHistogram, ("Partitio
nAlloc.CommittedSize", supportedMaxSizeInMB)); |
| 75 committedSizeHistogram.count(sizeInMB); |
| 76 } |
| 77 |
| 78 static void callOnMainThreadFunction(WTF::MainThreadFunction function, void* con
text) |
| 79 { |
| 80 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FROM_H
ERE, threadSafeBind(function, AllowCrossThreadAccess(context))); |
| 81 } |
| 82 |
| 61 void Platform::initialize(Platform* platform) | 83 void Platform::initialize(Platform* platform) |
| 62 { | 84 { |
| 85 ASSERT(!s_platform); |
| 63 ASSERT(platform); | 86 ASSERT(platform); |
| 64 s_platform = platform; | 87 s_platform = platform; |
| 65 s_platform->m_mainThread = platform->currentThread(); | 88 s_platform->m_mainThread = platform->currentThread(); |
| 66 | 89 |
| 90 WTF::Partitions::initialize(maxObservedSizeFunction); |
| 91 WTF::initialize(); |
| 92 WTF::initializeMainThread(callOnMainThreadFunction); |
| 93 |
| 94 Heap::init(); |
| 95 |
| 96 ThreadState::attachMainThread(); |
| 97 |
| 67 // TODO(ssid): remove this check after fixing crbug.com/486782. | 98 // TODO(ssid): remove this check after fixing crbug.com/486782. |
| 68 if (s_platform->m_mainThread) { | 99 if (s_platform->m_mainThread) { |
| 100 ASSERT(!s_gcTaskRunner); |
| 101 s_gcTaskRunner = new GCTaskRunner(s_platform->m_mainThread); |
| 69 s_platform->registerMemoryDumpProvider(PartitionAllocMemoryDumpProvider:
:instance(), "PartitionAlloc"); | 102 s_platform->registerMemoryDumpProvider(PartitionAllocMemoryDumpProvider:
:instance(), "PartitionAlloc"); |
| 70 s_platform->registerMemoryDumpProvider(FontCacheMemoryDumpProvider::inst
ance(), "FontCaches"); | 103 s_platform->registerMemoryDumpProvider(FontCacheMemoryDumpProvider::inst
ance(), "FontCaches"); |
| 71 } | 104 } |
| 72 | 105 |
| 73 CompositorFactory::initializeDefault(); | 106 CompositorFactory::initializeDefault(); |
| 74 } | 107 } |
| 75 | 108 |
| 76 void Platform::shutdown() | 109 void Platform::shutdown() |
| 77 { | 110 { |
| 111 ASSERT(isMainThread()); |
| 78 CompositorFactory::shutdown(); | 112 CompositorFactory::shutdown(); |
| 79 | 113 |
| 80 if (s_platform->m_mainThread) { | 114 if (s_platform->m_mainThread) { |
| 81 s_platform->unregisterMemoryDumpProvider(FontCacheMemoryDumpProvider::in
stance()); | 115 s_platform->unregisterMemoryDumpProvider(FontCacheMemoryDumpProvider::in
stance()); |
| 82 s_platform->unregisterMemoryDumpProvider(PartitionAllocMemoryDumpProvide
r::instance()); | 116 s_platform->unregisterMemoryDumpProvider(PartitionAllocMemoryDumpProvide
r::instance()); |
| 117 ASSERT(s_gcTaskRunner); |
| 118 delete s_gcTaskRunner; |
| 119 s_gcTaskRunner = nullptr; |
| 83 } | 120 } |
| 84 | 121 |
| 122 // Detach the main thread before starting the shutdown sequence |
| 123 // so that the main thread won't get involved in a GC during the shutdown. |
| 124 ThreadState::detachMainThread(); |
| 125 |
| 126 Heap::shutdown(); |
| 127 |
| 128 WTF::shutdown(); |
| 129 WebPrerenderingSupport::shutdown(); |
| 130 WTF::Partitions::shutdown(); |
| 131 |
| 85 s_platform->m_mainThread = nullptr; | 132 s_platform->m_mainThread = nullptr; |
| 86 s_platform = nullptr; | 133 s_platform = nullptr; |
| 87 } | 134 } |
| 88 | 135 |
| 89 void Platform::setCurrentPlatformForTesting(Platform* platform) | 136 void Platform::setCurrentPlatformForTesting(Platform* platform) |
| 90 { | 137 { |
| 91 ASSERT(platform); | 138 ASSERT(platform); |
| 92 s_platform = platform; | 139 s_platform = platform; |
| 93 s_platform->m_mainThread = platform->currentThread(); | 140 s_platform->m_mainThread = platform->currentThread(); |
| 94 } | 141 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 ProviderToAdapterMap::iterator it = memoryDumpProviders().find(provider); | 173 ProviderToAdapterMap::iterator it = memoryDumpProviders().find(provider); |
| 127 if (it == memoryDumpProviders().end()) | 174 if (it == memoryDumpProviders().end()) |
| 128 return; | 175 return; |
| 129 WebMemoryDumpProviderAdapter* adapter = it->value.get(); | 176 WebMemoryDumpProviderAdapter* adapter = it->value.get(); |
| 130 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
adapter); | 177 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
adapter); |
| 131 adapter->set_is_registered(false); | 178 adapter->set_is_registered(false); |
| 132 memoryDumpProviders().remove(it); | 179 memoryDumpProviders().remove(it); |
| 133 } | 180 } |
| 134 | 181 |
| 135 } // namespace blink | 182 } // namespace blink |
| OLD | NEW |