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

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, 8 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
« no previous file with comments | « content/renderer/render_thread_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 #include "third_party/WebKit/public/web/WebMemoryPressureListener.h" 153 #include "third_party/WebKit/public/web/WebMemoryPressureListener.h"
154 #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h" 154 #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h"
155 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" 155 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
156 #include "third_party/WebKit/public/web/WebScriptController.h" 156 #include "third_party/WebKit/public/web/WebScriptController.h"
157 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" 157 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
158 #include "third_party/WebKit/public/web/WebView.h" 158 #include "third_party/WebKit/public/web/WebView.h"
159 #include "third_party/icu/source/i18n/unicode/timezone.h" 159 #include "third_party/icu/source/i18n/unicode/timezone.h"
160 #include "third_party/skia/include/core/SkGraphics.h" 160 #include "third_party/skia/include/core/SkGraphics.h"
161 #include "ui/base/layout.h" 161 #include "ui/base/layout.h"
162 #include "ui/base/ui_base_switches.h" 162 #include "ui/base/ui_base_switches.h"
163 #include "v8/include/v8.h"
164 163
165 #if defined(OS_ANDROID) 164 #if defined(OS_ANDROID)
166 #include <cpu-features.h> 165 #include <cpu-features.h>
167 #include "content/renderer/android/synchronous_compositor_external_begin_frame_s ource.h" 166 #include "content/renderer/android/synchronous_compositor_external_begin_frame_s ource.h"
168 #include "content/renderer/android/synchronous_compositor_factory.h" 167 #include "content/renderer/android/synchronous_compositor_factory.h"
169 #include "content/renderer/android/synchronous_compositor_filter.h" 168 #include "content/renderer/android/synchronous_compositor_filter.h"
170 #include "content/renderer/media/android/renderer_demuxer_android.h" 169 #include "content/renderer/media/android/renderer_demuxer_android.h"
171 #include "content/renderer/media/android/stream_texture_factory_impl.h" 170 #include "content/renderer/media/android/stream_texture_factory_impl.h"
172 #include "media/base/android/media_codec_util.h" 171 #include "media/base/android/media_codec_util.h"
173 #endif 172 #endif
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 blink::enableLogChannel(t.token().c_str()); 347 blink::enableLogChannel(t.token().c_str());
349 } 348 }
350 349
351 void NotifyTimezoneChangeOnThisThread() { 350 void NotifyTimezoneChangeOnThisThread() {
352 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 351 v8::Isolate* isolate = v8::Isolate::GetCurrent();
353 if (!isolate) 352 if (!isolate)
354 return; 353 return;
355 v8::Date::DateTimeConfigurationChangeNotification(isolate); 354 v8::Date::DateTimeConfigurationChangeNotification(isolate);
356 } 355 }
357 356
358 void LowMemoryNotificationOnThisThread() { 357 void LowMemoryNotificationOnThisThread(
358 v8::MemoryPressureLevel memory_pressure_level) {
359 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 359 v8::Isolate* isolate = v8::Isolate::GetCurrent();
360 if (!isolate) 360 if (!isolate)
361 return; 361 return;
362 isolate->LowMemoryNotification(); 362 isolate->MemoryPressureNotification(memory_pressure_level);
363 } 363 }
364 364
365 class RenderFrameSetupImpl : public mojom::RenderFrameSetup { 365 class RenderFrameSetupImpl : public mojom::RenderFrameSetup {
366 public: 366 public:
367 explicit RenderFrameSetupImpl( 367 explicit RenderFrameSetupImpl(
368 mojo::InterfaceRequest<mojom::RenderFrameSetup> request) 368 mojo::InterfaceRequest<mojom::RenderFrameSetup> request)
369 : routing_id_highmark_(-1), binding_(this, std::move(request)) {} 369 : routing_id_highmark_(-1), binding_(this, std::move(request)) {}
370 370
371 void ExchangeInterfaceProviders( 371 void ExchangeInterfaceProviders(
372 int32_t frame_routing_id, 372 int32_t frame_routing_id,
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 media::InitializeMediaLibrary(); 804 media::InitializeMediaLibrary();
805 805
806 #if defined(OS_ANDROID) 806 #if defined(OS_ANDROID)
807 if (!command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode) && 807 if (!command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode) &&
808 media::MediaCodecUtil::IsMediaCodecAvailable()) { 808 media::MediaCodecUtil::IsMediaCodecAvailable()) {
809 media::EnablePlatformDecoderSupport(); 809 media::EnablePlatformDecoderSupport();
810 } 810 }
811 #endif 811 #endif
812 812
813 memory_pressure_listener_.reset(new base::MemoryPressureListener( 813 memory_pressure_listener_.reset(new base::MemoryPressureListener(
814 base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)))); 814 base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)),
815 base::Bind(&RenderThreadImpl::OnSyncMemoryPressure,
816 base::Unretained(this))));
815 817
816 int num_raster_threads = 0; 818 int num_raster_threads = 0;
817 std::string string_value = 819 std::string string_value =
818 command_line.GetSwitchValueASCII(switches::kNumRasterThreads); 820 command_line.GetSwitchValueASCII(switches::kNumRasterThreads);
819 bool parsed_num_raster_threads = 821 bool parsed_num_raster_threads =
820 base::StringToInt(string_value, &num_raster_threads); 822 base::StringToInt(string_value, &num_raster_threads);
821 DCHECK(parsed_num_raster_threads) << string_value; 823 DCHECK(parsed_num_raster_threads) << string_value;
822 DCHECK_GT(num_raster_threads, 0); 824 DCHECK_GT(num_raster_threads, 0);
823 825
824 // TODO(vmpstr): If the flag sticks, we should clean it up and always have 826 // TODO(vmpstr): If the flag sticks, we should clean it up and always have
(...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1999 const WorkerProcessMsg_CreateWorker_Params& params) { 2001 const WorkerProcessMsg_CreateWorker_Params& params) {
2000 // EmbeddedSharedWorkerStub will self-destruct. 2002 // EmbeddedSharedWorkerStub will self-destruct.
2001 new EmbeddedSharedWorkerStub( 2003 new EmbeddedSharedWorkerStub(
2002 params.url, params.name, params.content_security_policy, 2004 params.url, params.name, params.content_security_policy,
2003 params.security_policy_type, params.creation_address_space, 2005 params.security_policy_type, params.creation_address_space,
2004 params.pause_on_start, params.route_id); 2006 params.pause_on_start, params.route_id);
2005 } 2007 }
2006 2008
2007 void RenderThreadImpl::OnMemoryPressure( 2009 void RenderThreadImpl::OnMemoryPressure(
2008 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { 2010 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
2011 TRACE_EVENT0("memory","RenderThreadImpl::OnMemoryPressure");
2009 ReleaseFreeMemory(); 2012 ReleaseFreeMemory();
2010 2013
2011 // Do not call into blink if it is not initialized. 2014 // Do not call into blink if it is not initialized.
2012 if (blink_platform_impl_) { 2015 if (blink_platform_impl_) {
2013 blink::WebMemoryPressureListener::onMemoryPressure( 2016 blink::WebMemoryPressureListener::onMemoryPressure(
2014 static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level)); 2017 static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level));
2015 2018
2016 if (blink::mainThreadIsolate()) {
2017 // Trigger full v8 garbage collection on memory pressure notifications.
2018 // This will potentially hang the renderer for a long time, however, when
2019 // we receive a memory pressure notification, we might be about to be
2020 // killed. Because of the janky hang don't do this to foreground
2021 // renderers.
2022 if (RendererIsHidden()) {
2023 blink::mainThreadIsolate()->LowMemoryNotification();
2024 RenderThread::Get()->PostTaskToAllWebWorkers(
2025 base::Bind(&LowMemoryNotificationOnThisThread));
2026 }
2027 }
2028
2029 if (memory_pressure_level == 2019 if (memory_pressure_level ==
2030 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { 2020 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) {
2031 // Purge Skia font cache, by setting it to 0 and then again to the 2021 // Purge Skia font cache, by setting it to 0 and then again to the
2032 // previous limit. 2022 // previous limit.
2033 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); 2023 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0);
2034 SkGraphics::SetFontCacheLimit(font_cache_limit); 2024 SkGraphics::SetFontCacheLimit(font_cache_limit);
2035 } 2025 }
2036 } 2026 }
2037 } 2027 }
2038 2028
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
2173 RenderThreadImpl::PendingRenderFrameConnect::~PendingRenderFrameConnect() { 2163 RenderThreadImpl::PendingRenderFrameConnect::~PendingRenderFrameConnect() {
2174 } 2164 }
2175 2165
2176 void RenderThreadImpl::PendingRenderFrameConnect::OnConnectionError() { 2166 void RenderThreadImpl::PendingRenderFrameConnect::OnConnectionError() {
2177 size_t erased = 2167 size_t erased =
2178 RenderThreadImpl::current()->pending_render_frame_connects_.erase( 2168 RenderThreadImpl::current()->pending_render_frame_connects_.erase(
2179 routing_id_); 2169 routing_id_);
2180 DCHECK_EQ(1u, erased); 2170 DCHECK_EQ(1u, erased);
2181 } 2171 }
2182 2172
2173 void RenderThreadImpl::OnSyncMemoryPressure(
2174 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
2175 if (blink::mainThreadIsolate()) {
2176 static_assert(
2177 static_cast<v8::MemoryPressureLevel>(
2178 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) ==
2179 v8::MemoryPressureLevel::kNone, "none level not align");
2180 static_assert(
2181 static_cast<v8::MemoryPressureLevel>(
2182 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE) ==
2183 v8::MemoryPressureLevel::kModerate, "moderate level not align");
2184 static_assert(
2185 static_cast<v8::MemoryPressureLevel>(
2186 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) ==
2187 v8::MemoryPressureLevel::kCritical, "critical level not align");
2188
2189 v8::MemoryPressureLevel v8_memory_pressure_level =
2190 static_cast<v8::MemoryPressureLevel>(memory_pressure_level);
2191
2192 blink::mainThreadIsolate()->MemoryPressureNotification(
2193 v8_memory_pressure_level);
2194 RenderThread::Get()->PostTaskToAllWebWorkers(
jochen (gone - plz use gerrit) 2016/04/03 11:21:36 it would be nicer if we'd also synchrounously noti
hong.zheng 2016/04/07 10:55:49 Done.
2195 base::Bind(&LowMemoryNotificationOnThisThread,
2196 v8_memory_pressure_level));
2197 }
2198 }
2199
2183 } // namespace content 2200 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_thread_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698