OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/render_thread_impl.h" | 5 #include "content/renderer/render_thread_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <map> | 9 #include <map> |
10 #include <utility> | 10 #include <utility> |
(...skipping 1650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1661 if (!RendererIsHidden()) | 1661 if (!RendererIsHidden()) |
1662 return; | 1662 return; |
1663 | 1663 |
1664 // TODO(bashi): Enable the tab suspension when MemoryCoordinator is enabled. | 1664 // TODO(bashi): Enable the tab suspension when MemoryCoordinator is enabled. |
1665 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) | 1665 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) |
1666 return; | 1666 return; |
1667 | 1667 |
1668 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { | 1668 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { |
1669 // TODO(tasak): After enabling MemoryCoordinator, remove this Notify | 1669 // TODO(tasak): After enabling MemoryCoordinator, remove this Notify |
1670 // and follow MemoryCoordinator's request. | 1670 // and follow MemoryCoordinator's request. |
1671 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( | 1671 base::MemoryCoordinatorClientRegistry::GetInstance()->PurgeMemory(); |
1672 base::MemoryState::SUSPENDED); | |
1673 } | 1672 } |
1674 // Since purging is not a synchronous task (e.g. v8 GC, oilpan GC, ...), | 1673 // Since purging is not a synchronous task (e.g. v8 GC, oilpan GC, ...), |
1675 // we need to wait until the task is finished. So wait 15 seconds and | 1674 // we need to wait until the task is finished. So wait 15 seconds and |
1676 // update purge+suspend UMA histogram. | 1675 // update purge+suspend UMA histogram. |
1677 // TODO(tasak): use MemoryCoordinator's callback to report purge+suspend | 1676 // TODO(tasak): use MemoryCoordinator's callback to report purge+suspend |
1678 // UMA when MemoryCoordinator is available. | 1677 // UMA when MemoryCoordinator is available. |
1679 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( | 1678 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( |
1680 FROM_HERE, record_purge_suspend_metric_closure_.callback(), | 1679 FROM_HERE, record_purge_suspend_metric_closure_.callback(), |
1681 base::TimeDelta::FromSeconds(15)); | 1680 base::TimeDelta::FromSeconds(15)); |
1682 } | 1681 } |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1833 UMA_HISTOGRAM_MEMORY_MB( | 1832 UMA_HISTOGRAM_MEMORY_MB( |
1834 "PurgeAndSuspend.Experimental.MemoryGrowth.V8MainThreadIsolateKB", | 1833 "PurgeAndSuspend.Experimental.MemoryGrowth.V8MainThreadIsolateKB", |
1835 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, | 1834 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, |
1836 v8_main_thread_isolate_mb) * 1024); | 1835 v8_main_thread_isolate_mb) * 1024); |
1837 UMA_HISTOGRAM_MEMORY_MB( | 1836 UMA_HISTOGRAM_MEMORY_MB( |
1838 "PurgeAndSuspend.Experimental.MemoryGrowth.TotalAllocatedKB", | 1837 "PurgeAndSuspend.Experimental.MemoryGrowth.TotalAllocatedKB", |
1839 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, | 1838 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, |
1840 total_allocated_mb) * 1024); | 1839 total_allocated_mb) * 1024); |
1841 } | 1840 } |
1842 | 1841 |
1843 void RenderThreadImpl::OnProcessResume() { | |
1844 ChildThreadImpl::OnProcessResume(); | |
1845 | |
1846 if (!RendererIsHidden()) | |
1847 return; | |
1848 | |
1849 // TODO(bashi): Enable the tab suspension when MemoryCoordinator is enabled. | |
1850 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) | |
1851 return; | |
1852 | |
1853 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { | |
1854 // TODO(tasak): after enabling MemoryCoordinator, remove this Notify | |
1855 // and follow MemoryCoordinator's request. | |
1856 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( | |
1857 base::MemoryState::NORMAL); | |
1858 } | |
1859 } | |
1860 | |
1861 scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() { | 1842 scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() { |
1862 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync"); | 1843 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync"); |
1863 | 1844 |
1864 if (gpu_channel_) { | 1845 if (gpu_channel_) { |
1865 // Do nothing if we already have a GPU channel or are already | 1846 // Do nothing if we already have a GPU channel or are already |
1866 // establishing one. | 1847 // establishing one. |
1867 if (!gpu_channel_->IsLost()) | 1848 if (!gpu_channel_->IsLost()) |
1868 return gpu_channel_; | 1849 return gpu_channel_; |
1869 | 1850 |
1870 // Recreate the channel if it has been lost. | 1851 // Recreate the channel if it has been lost. |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2214 } | 2195 } |
2215 | 2196 |
2216 void RenderThreadImpl::OnMemoryStateChange(base::MemoryState state) { | 2197 void RenderThreadImpl::OnMemoryStateChange(base::MemoryState state) { |
2217 // TODO(hajimehoshi): Adjust the size of this memory usage according to | 2198 // TODO(hajimehoshi): Adjust the size of this memory usage according to |
2218 // |state|. RenderThreadImpl doesn't have a feature to limit memory usage at | 2199 // |state|. RenderThreadImpl doesn't have a feature to limit memory usage at |
2219 // present. | 2200 // present. |
2220 if (blink_platform_impl_) { | 2201 if (blink_platform_impl_) { |
2221 blink::WebMemoryCoordinator::onMemoryStateChange( | 2202 blink::WebMemoryCoordinator::onMemoryStateChange( |
2222 static_cast<blink::MemoryState>(state)); | 2203 static_cast<blink::MemoryState>(state)); |
2223 } | 2204 } |
2224 switch (state) { | 2205 } |
2225 case base::MemoryState::NORMAL: | 2206 |
2226 break; | 2207 void RenderThreadImpl::OnPurgeMemory() { |
2227 case base::MemoryState::THROTTLED: | 2208 OnTrimMemoryImmediately(); |
2228 // TODO(bashi): Figure out what kind of strategy is suitable on | 2209 ReleaseFreeMemory(); |
2229 // THROTTLED state. crbug.com/674815 | 2210 ClearMemory(); |
2230 #if defined(OS_ANDROID) | 2211 // TODO(bashi): Add onPurgeMemory() to blink::WebMemoryCoordinator. |
2231 OnTrimMemoryImmediately(); | 2212 // Notifies pseudo SUSPENDED state change to purge memory in blink. |
2232 #else | 2213 // crbug.com/684287 |
2233 OnSyncMemoryPressure( | 2214 OnMemoryStateChange(base::MemoryState::SUSPENDED); |
2234 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); | |
2235 #endif | |
2236 ReleaseFreeMemory(); | |
2237 break; | |
2238 case base::MemoryState::SUSPENDED: | |
2239 OnTrimMemoryImmediately(); | |
2240 ReleaseFreeMemory(); | |
2241 ClearMemory(); | |
2242 break; | |
2243 case base::MemoryState::UNKNOWN: | |
2244 NOTREACHED(); | |
2245 break; | |
2246 } | |
2247 } | 2215 } |
2248 | 2216 |
2249 void RenderThreadImpl::ClearMemory() { | 2217 void RenderThreadImpl::ClearMemory() { |
2250 // Do not call into blink if it is not initialized. | 2218 // Do not call into blink if it is not initialized. |
2251 if (blink_platform_impl_) { | 2219 if (blink_platform_impl_) { |
2252 // Purge Skia font cache, by setting it to 0 and then again to the | 2220 // Purge Skia font cache, by setting it to 0 and then again to the |
2253 // previous limit. | 2221 // previous limit. |
2254 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); | 2222 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); |
2255 SkGraphics::SetFontCacheLimit(font_cache_limit); | 2223 SkGraphics::SetFontCacheLimit(font_cache_limit); |
2256 } | 2224 } |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2436 } | 2404 } |
2437 } | 2405 } |
2438 | 2406 |
2439 void RenderThreadImpl::OnRendererInterfaceRequest( | 2407 void RenderThreadImpl::OnRendererInterfaceRequest( |
2440 mojom::RendererAssociatedRequest request) { | 2408 mojom::RendererAssociatedRequest request) { |
2441 DCHECK(!renderer_binding_.is_bound()); | 2409 DCHECK(!renderer_binding_.is_bound()); |
2442 renderer_binding_.Bind(std::move(request)); | 2410 renderer_binding_.Bind(std::move(request)); |
2443 } | 2411 } |
2444 | 2412 |
2445 } // namespace content | 2413 } // namespace content |
OLD | NEW |