Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Side by Side Diff: content/renderer/render_thread_impl.cc

Issue 1749073002: Do V8 GC ASAP if system memory is pressured (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 #include "third_party/WebKit/public/web/WebMemoryPressureListener.h" 156 #include "third_party/WebKit/public/web/WebMemoryPressureListener.h"
157 #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h" 157 #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h"
158 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" 158 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
159 #include "third_party/WebKit/public/web/WebScriptController.h" 159 #include "third_party/WebKit/public/web/WebScriptController.h"
160 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" 160 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
161 #include "third_party/WebKit/public/web/WebView.h" 161 #include "third_party/WebKit/public/web/WebView.h"
162 #include "third_party/icu/source/i18n/unicode/timezone.h" 162 #include "third_party/icu/source/i18n/unicode/timezone.h"
163 #include "third_party/skia/include/core/SkGraphics.h" 163 #include "third_party/skia/include/core/SkGraphics.h"
164 #include "ui/base/layout.h" 164 #include "ui/base/layout.h"
165 #include "ui/base/ui_base_switches.h" 165 #include "ui/base/ui_base_switches.h"
166 #include "v8/include/v8.h"
167 166
168 #if defined(OS_ANDROID) 167 #if defined(OS_ANDROID)
169 #include <cpu-features.h> 168 #include <cpu-features.h>
170 #include "content/renderer/android/synchronous_compositor_external_begin_frame_s ource.h" 169 #include "content/renderer/android/synchronous_compositor_external_begin_frame_s ource.h"
171 #include "content/renderer/android/synchronous_compositor_factory.h" 170 #include "content/renderer/android/synchronous_compositor_factory.h"
172 #include "content/renderer/android/synchronous_compositor_filter.h" 171 #include "content/renderer/android/synchronous_compositor_filter.h"
173 #include "content/renderer/media/android/renderer_demuxer_android.h" 172 #include "content/renderer/media/android/renderer_demuxer_android.h"
174 #include "content/renderer/media/android/stream_texture_factory_impl.h" 173 #include "content/renderer/media/android/stream_texture_factory_impl.h"
175 #include "media/base/android/media_codec_util.h" 174 #include "media/base/android/media_codec_util.h"
176 #endif 175 #endif
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 media::InitializeMediaLibrary(); 810 media::InitializeMediaLibrary();
812 811
813 #if defined(OS_ANDROID) 812 #if defined(OS_ANDROID)
814 if (!command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode) && 813 if (!command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode) &&
815 media::MediaCodecUtil::IsMediaCodecAvailable()) { 814 media::MediaCodecUtil::IsMediaCodecAvailable()) {
816 media::EnablePlatformDecoderSupport(); 815 media::EnablePlatformDecoderSupport();
817 } 816 }
818 #endif 817 #endif
819 818
820 memory_pressure_listener_.reset(new base::MemoryPressureListener( 819 memory_pressure_listener_.reset(new base::MemoryPressureListener(
821 base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)))); 820 base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)),
821 base::Bind(&RenderThreadImpl::IsMemoryPressured,
822 base::Unretained(this))));
822 823
823 int num_raster_threads = 0; 824 int num_raster_threads = 0;
824 std::string string_value = 825 std::string string_value =
825 command_line.GetSwitchValueASCII(switches::kNumRasterThreads); 826 command_line.GetSwitchValueASCII(switches::kNumRasterThreads);
826 bool parsed_num_raster_threads = 827 bool parsed_num_raster_threads =
827 base::StringToInt(string_value, &num_raster_threads); 828 base::StringToInt(string_value, &num_raster_threads);
828 DCHECK(parsed_num_raster_threads) << string_value; 829 DCHECK(parsed_num_raster_threads) << string_value;
829 DCHECK_GT(num_raster_threads, 0); 830 DCHECK_GT(num_raster_threads, 0);
830 831
831 #if defined(OS_ANDROID) 832 #if defined(OS_ANDROID)
(...skipping 1175 matching lines...) Expand 10 before | Expand all | Expand 10 after
2007 new EmbeddedSharedWorkerStub(params.url, 2008 new EmbeddedSharedWorkerStub(params.url,
2008 params.name, 2009 params.name,
2009 params.content_security_policy, 2010 params.content_security_policy,
2010 params.security_policy_type, 2011 params.security_policy_type,
2011 params.pause_on_start, 2012 params.pause_on_start,
2012 params.route_id); 2013 params.route_id);
2013 } 2014 }
2014 2015
2015 void RenderThreadImpl::OnMemoryPressure( 2016 void RenderThreadImpl::OnMemoryPressure(
2016 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { 2017 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
2018 TRACE_EVENT0("memory","RenderThreadImpl::OnMemoryPressure");
2017 ReleaseFreeMemory(); 2019 ReleaseFreeMemory();
2018 2020
2019 // Do not call into blink if it is not initialized. 2021 // Do not call into blink if it is not initialized.
2020 if (blink_platform_impl_) { 2022 if (blink_platform_impl_) {
2021 blink::WebMemoryPressureListener::onMemoryPressure( 2023 blink::WebMemoryPressureListener::onMemoryPressure(
2022 static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level)); 2024 static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level));
2023 2025
2024 if (blink::mainThreadIsolate()) { 2026 if (blink::mainThreadIsolate()) {
2025 // Trigger full v8 garbage collection on memory pressure notifications. 2027 // Trigger full v8 garbage collection on memory pressure notifications.
2026 // This will potentially hang the renderer for a long time, however, when 2028 // This will potentially hang the renderer for a long time, however, when
2027 // we receive a memory pressure notification, we might be about to be 2029 // we receive a memory pressure notification, we might be about to be
2028 // killed. 2030 // killed.
2029 blink::mainThreadIsolate()->LowMemoryNotification(); 2031 if (is_v8_need_gc_) {
2032 blink::mainThreadIsolate()->LowMemoryNotification();
2033 is_v8_need_gc_ = false;
2034 }
2035
2030 RenderThread::Get()->PostTaskToAllWebWorkers( 2036 RenderThread::Get()->PostTaskToAllWebWorkers(
2031 base::Bind(&LowMemoryNotificationOnThisThread)); 2037 base::Bind(&LowMemoryNotificationOnThisThread));
2032 } 2038 }
2033 2039
2034 if (memory_pressure_level == 2040 if (memory_pressure_level ==
2035 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { 2041 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) {
2036 // Purge Skia font cache, by setting it to 0 and then again to the 2042 // Purge Skia font cache, by setting it to 0 and then again to the
2037 // previous limit. 2043 // previous limit.
2038 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); 2044 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0);
2039 SkGraphics::SetFontCacheLimit(font_cache_limit); 2045 SkGraphics::SetFontCacheLimit(font_cache_limit);
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
2178 RenderThreadImpl::PendingRenderFrameConnect::~PendingRenderFrameConnect() { 2184 RenderThreadImpl::PendingRenderFrameConnect::~PendingRenderFrameConnect() {
2179 } 2185 }
2180 2186
2181 void RenderThreadImpl::PendingRenderFrameConnect::OnConnectionError() { 2187 void RenderThreadImpl::PendingRenderFrameConnect::OnConnectionError() {
2182 size_t erased = 2188 size_t erased =
2183 RenderThreadImpl::current()->pending_render_frame_connects_.erase( 2189 RenderThreadImpl::current()->pending_render_frame_connects_.erase(
2184 routing_id_); 2190 routing_id_);
2185 DCHECK_EQ(1u, erased); 2191 DCHECK_EQ(1u, erased);
2186 } 2192 }
2187 2193
2194 void RenderThreadImpl::OnV8InterruptCallback(v8::Isolate* isolate, void* data) {
2195 RenderThreadImpl* pRenderThreadImpl =
2196 reinterpret_cast<RenderThreadImpl*>(data);
2197 if (!pRenderThreadImpl || !pRenderThreadImpl->is_v8_need_gc_)
2198 return;
2199 blink::mainThreadIsolate()->LowMemoryNotification();
esprehn 2016/03/01 22:15:07 Is this safe? You're using the LowMemoryNotificati
2200 pRenderThreadImpl->is_v8_need_gc_ = false;
2201 }
2202
2203 void RenderThreadImpl::IsMemoryPressured(bool memory_pressured) {
2204 is_v8_need_gc_ = true;
2205 blink::mainThreadIsolate()->RequestInterrupt(&OnV8InterruptCallback, this);
jochen (gone - plz use gerrit) 2016/03/02 07:59:38 the interrupt callback must not reenter V8.
2206 }
2207
2188 } // namespace content 2208 } // namespace content
OLDNEW
« base/observer_list_threadsafe.h ('K') | « content/renderer/render_thread_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698