Chromium Code Reviews| 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 1761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1772 // TODO(tasak): after enabling MemoryCoordinator, remove this Notify | 1772 // TODO(tasak): after enabling MemoryCoordinator, remove this Notify |
| 1773 // and follow MemoryCoordinator's request. | 1773 // and follow MemoryCoordinator's request. |
| 1774 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) | 1774 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) |
| 1775 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( | 1775 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( |
| 1776 base::MemoryState::NORMAL); | 1776 base::MemoryState::NORMAL); |
| 1777 | 1777 |
| 1778 record_purge_suspend_metric_closure_.Cancel(); | 1778 record_purge_suspend_metric_closure_.Cancel(); |
| 1779 record_purge_suspend_metric_closure_.Reset( | 1779 record_purge_suspend_metric_closure_.Reset( |
| 1780 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMetrics, | 1780 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMetrics, |
| 1781 base::Unretained(this))); | 1781 base::Unretained(this))); |
| 1782 is_renderer_suspended_ = false; | |
| 1783 } | 1782 } |
| 1784 } | 1783 } |
| 1785 | 1784 |
| 1786 void RenderThreadImpl::OnProcessPurgeAndSuspend() { | 1785 void RenderThreadImpl::OnProcessPurgeAndSuspend() { |
| 1787 ChildThreadImpl::OnProcessPurgeAndSuspend(); | 1786 ChildThreadImpl::OnProcessPurgeAndSuspend(); |
| 1788 DCHECK(!is_renderer_suspended_); | 1787 DCHECK(!is_renderer_suspended_); |
| 1789 if (!RendererIsHidden()) | 1788 if (!RendererIsHidden()) |
| 1790 return; | 1789 return; |
| 1791 is_renderer_suspended_ = true; | |
| 1792 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { | 1790 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { |
| 1793 // TODO(tasak): After enabling MemoryCoordinator, remove this Notify | 1791 // TODO(tasak): After enabling MemoryCoordinator, remove this Notify |
| 1794 // and follow MemoryCoordinator's request. | 1792 // and follow MemoryCoordinator's request. |
| 1795 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( | 1793 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( |
| 1796 base::MemoryState::SUSPENDED); | 1794 base::MemoryState::SUSPENDED); |
| 1797 } | 1795 } |
| 1798 // Since purging is not a synchronous task (e.g. v8 GC, oilpan GC, ...), | 1796 // Since purging is not a synchronous task (e.g. v8 GC, oilpan GC, ...), |
| 1799 // we need to wait until the task is finished. So wait 15 seconds and | 1797 // we need to wait until the task is finished. So wait 15 seconds and |
| 1800 // update purge+suspend UMA histogram. | 1798 // update purge+suspend UMA histogram. |
| 1801 // TODO(tasak): use MemoryCoordinator's callback to report purge+suspend | 1799 // TODO(tasak): use MemoryCoordinator's callback to report purge+suspend |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1892 (blink_stats.partitionAllocTotalAllocatedBytes + | 1890 (blink_stats.partitionAllocTotalAllocatedBytes + |
| 1893 blink_stats.blinkGCTotalAllocatedBytes + | 1891 blink_stats.blinkGCTotalAllocatedBytes + |
| 1894 malloc_usage + v8_usage + discardable_usage) / | 1892 malloc_usage + v8_usage + discardable_usage) / |
| 1895 1024 / 1024); | 1893 1024 / 1024); |
| 1896 } | 1894 } |
| 1897 | 1895 |
| 1898 void RenderThreadImpl::OnProcessResume() { | 1896 void RenderThreadImpl::OnProcessResume() { |
| 1899 ChildThreadImpl::OnProcessResume(); | 1897 ChildThreadImpl::OnProcessResume(); |
| 1900 | 1898 |
| 1901 DCHECK(is_renderer_suspended_); | 1899 DCHECK(is_renderer_suspended_); |
| 1902 is_renderer_suspended_ = false; | |
| 1903 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { | 1900 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { |
| 1904 // TODO(tasak): after enabling MemoryCoordinator, remove this Notify | 1901 // TODO(tasak): after enabling MemoryCoordinator, remove this Notify |
| 1905 // and follow MemoryCoordinator's request. | 1902 // and follow MemoryCoordinator's request. |
| 1906 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( | 1903 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( |
| 1907 base::MemoryState::NORMAL); | 1904 base::MemoryState::NORMAL); |
| 1908 renderer_scheduler_->ResumeRenderer(); | |
| 1909 } | 1905 } |
| 1910 } | 1906 } |
| 1911 | 1907 |
| 1912 scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() { | 1908 scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() { |
| 1913 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync"); | 1909 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync"); |
| 1914 | 1910 |
| 1915 if (gpu_channel_) { | 1911 if (gpu_channel_) { |
| 1916 // Do nothing if we already have a GPU channel or are already | 1912 // Do nothing if we already have a GPU channel or are already |
| 1917 // establishing one. | 1913 // establishing one. |
| 1918 if (!gpu_channel_->IsLost()) | 1914 if (!gpu_channel_->IsLost()) |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2290 void RenderThreadImpl::OnMemoryStateChange(base::MemoryState state) { | 2286 void RenderThreadImpl::OnMemoryStateChange(base::MemoryState state) { |
| 2291 // TODO(hajimehoshi): Adjust the size of this memory usage according to | 2287 // TODO(hajimehoshi): Adjust the size of this memory usage according to |
| 2292 // |state|. RenderThreadImpl doesn't have a feature to limit memory usage at | 2288 // |state|. RenderThreadImpl doesn't have a feature to limit memory usage at |
| 2293 // present. | 2289 // present. |
| 2294 if (blink_platform_impl_) { | 2290 if (blink_platform_impl_) { |
| 2295 blink::WebMemoryCoordinator::onMemoryStateChange( | 2291 blink::WebMemoryCoordinator::onMemoryStateChange( |
| 2296 static_cast<blink::MemoryState>(state)); | 2292 static_cast<blink::MemoryState>(state)); |
| 2297 } | 2293 } |
| 2298 switch (state) { | 2294 switch (state) { |
| 2299 case base::MemoryState::NORMAL: | 2295 case base::MemoryState::NORMAL: |
| 2296 ResumeRendererIfNeeded(); | |
| 2300 break; | 2297 break; |
| 2301 case base::MemoryState::THROTTLED: | 2298 case base::MemoryState::THROTTLED: |
| 2299 ResumeRendererIfNeeded(); | |
| 2302 ReleaseFreeMemory(); | 2300 ReleaseFreeMemory(); |
| 2303 break; | 2301 break; |
| 2304 case base::MemoryState::SUSPENDED: | 2302 case base::MemoryState::SUSPENDED: |
| 2305 SuspendRenderer(); | 2303 SuspendRenderer(); |
| 2306 break; | 2304 break; |
| 2307 case base::MemoryState::UNKNOWN: | 2305 case base::MemoryState::UNKNOWN: |
| 2308 NOTREACHED(); | 2306 NOTREACHED(); |
| 2309 break; | 2307 break; |
| 2310 } | 2308 } |
| 2311 } | 2309 } |
| 2312 | 2310 |
| 2313 void RenderThreadImpl::SuspendRenderer() { | 2311 void RenderThreadImpl::SuspendRenderer() { |
| 2312 DCHECK(IsMainThread()); | |
| 2313 // |is_renderer_suspende_| shouldn't be true here, but it could due to IPC | |
| 2314 // message lag. | |
| 2315 if (is_renderer_suspended_) | |
|
bashi
2016/12/16 07:50:39
Chatted with tasak@ offline and he said we can't D
tasak
2016/12/16 07:55:15
I was trying to remove DCHECK related to is_render
bashi
2016/12/16 08:03:13
Thanks for the info. Then we should do early retur
| |
| 2316 return; | |
| 2314 OnTrimMemoryImmediately(); | 2317 OnTrimMemoryImmediately(); |
| 2315 ReleaseFreeMemory(); | 2318 ReleaseFreeMemory(); |
| 2316 ClearMemory(); | 2319 ClearMemory(); |
| 2320 is_renderer_suspended_ = true; | |
| 2317 renderer_scheduler_->SuspendRenderer(); | 2321 renderer_scheduler_->SuspendRenderer(); |
| 2318 } | 2322 } |
| 2319 | 2323 |
| 2324 void RenderThreadImpl::ResumeRendererIfNeeded() { | |
| 2325 DCHECK(IsMainThread()); | |
| 2326 if (!is_renderer_suspended_) | |
| 2327 return; | |
| 2328 renderer_scheduler_->ResumeRenderer(); | |
| 2329 is_renderer_suspended_ = false; | |
| 2330 } | |
| 2331 | |
| 2320 void RenderThreadImpl::ClearMemory() { | 2332 void RenderThreadImpl::ClearMemory() { |
| 2321 // Do not call into blink if it is not initialized. | 2333 // Do not call into blink if it is not initialized. |
| 2322 if (blink_platform_impl_) { | 2334 if (blink_platform_impl_) { |
| 2323 // Purge Skia font cache, by setting it to 0 and then again to the | 2335 // Purge Skia font cache, by setting it to 0 and then again to the |
| 2324 // previous limit. | 2336 // previous limit. |
| 2325 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); | 2337 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); |
| 2326 SkGraphics::SetFontCacheLimit(font_cache_limit); | 2338 SkGraphics::SetFontCacheLimit(font_cache_limit); |
| 2327 } | 2339 } |
| 2328 } | 2340 } |
| 2329 | 2341 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2507 } | 2519 } |
| 2508 } | 2520 } |
| 2509 | 2521 |
| 2510 void RenderThreadImpl::OnRendererInterfaceRequest( | 2522 void RenderThreadImpl::OnRendererInterfaceRequest( |
| 2511 mojom::RendererAssociatedRequest request) { | 2523 mojom::RendererAssociatedRequest request) { |
| 2512 DCHECK(!renderer_binding_.is_bound()); | 2524 DCHECK(!renderer_binding_.is_bound()); |
| 2513 renderer_binding_.Bind(std::move(request)); | 2525 renderer_binding_.Bind(std::move(request)); |
| 2514 } | 2526 } |
| 2515 | 2527 |
| 2516 } // namespace content | 2528 } // namespace content |
| OLD | NEW |