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

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

Issue 1953483002: Revert of 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, 7 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 #include "third_party/WebKit/public/web/WebMemoryPressureListener.h" 154 #include "third_party/WebKit/public/web/WebMemoryPressureListener.h"
155 #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h" 155 #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h"
156 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" 156 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
157 #include "third_party/WebKit/public/web/WebScriptController.h" 157 #include "third_party/WebKit/public/web/WebScriptController.h"
158 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" 158 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
159 #include "third_party/WebKit/public/web/WebView.h" 159 #include "third_party/WebKit/public/web/WebView.h"
160 #include "third_party/icu/source/i18n/unicode/timezone.h" 160 #include "third_party/icu/source/i18n/unicode/timezone.h"
161 #include "third_party/skia/include/core/SkGraphics.h" 161 #include "third_party/skia/include/core/SkGraphics.h"
162 #include "ui/base/layout.h" 162 #include "ui/base/layout.h"
163 #include "ui/base/ui_base_switches.h" 163 #include "ui/base/ui_base_switches.h"
164 #include "v8/include/v8.h"
164 165
165 #if defined(OS_ANDROID) 166 #if defined(OS_ANDROID)
166 #include <cpu-features.h> 167 #include <cpu-features.h>
167 #include "content/renderer/android/synchronous_compositor_external_begin_frame_s ource.h" 168 #include "content/renderer/android/synchronous_compositor_external_begin_frame_s ource.h"
168 #include "content/renderer/android/synchronous_compositor_filter.h" 169 #include "content/renderer/android/synchronous_compositor_filter.h"
169 #include "content/renderer/media/android/renderer_demuxer_android.h" 170 #include "content/renderer/media/android/renderer_demuxer_android.h"
170 #include "content/renderer/media/android/stream_texture_factory.h" 171 #include "content/renderer/media/android/stream_texture_factory.h"
171 #include "media/base/android/media_codec_util.h" 172 #include "media/base/android/media_codec_util.h"
172 #endif 173 #endif
173 174
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 // require pre-scaling. Skia will fallback to a filter that doesn't 235 // require pre-scaling. Skia will fallback to a filter that doesn't
235 // require pre-scaling if the default filter would require an 236 // require pre-scaling if the default filter would require an
236 // allocation that exceeds this limit. 237 // allocation that exceeds this limit.
237 const size_t kImageCacheSingleAllocationByteLimit = 64 * 1024 * 1024; 238 const size_t kImageCacheSingleAllocationByteLimit = 64 * 1024 * 1024;
238 239
239 // Keep the global RenderThreadImpl in a TLS slot so it is impossible to access 240 // Keep the global RenderThreadImpl in a TLS slot so it is impossible to access
240 // incorrectly from the wrong thread. 241 // incorrectly from the wrong thread.
241 base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl> > 242 base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl> >
242 lazy_tls = LAZY_INSTANCE_INITIALIZER; 243 lazy_tls = LAZY_INSTANCE_INITIALIZER;
243 244
244 // v8::MemoryPressureLevel should correspond to base::MemoryPressureListener.
245 static_assert(static_cast<v8::MemoryPressureLevel>(
246 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) ==
247 v8::MemoryPressureLevel::kNone, "none level not align");
248 static_assert(static_cast<v8::MemoryPressureLevel>(
249 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE) ==
250 v8::MemoryPressureLevel::kModerate, "moderate level not align");
251 static_assert(static_cast<v8::MemoryPressureLevel>(
252 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) ==
253 v8::MemoryPressureLevel::kCritical, "critical level not align");
254
255 class WebThreadForCompositor : public WebThreadImplForWorkerScheduler { 245 class WebThreadForCompositor : public WebThreadImplForWorkerScheduler {
256 public: 246 public:
257 explicit WebThreadForCompositor(base::Thread::Options options) 247 explicit WebThreadForCompositor(base::Thread::Options options)
258 : WebThreadImplForWorkerScheduler("Compositor", options) { 248 : WebThreadImplForWorkerScheduler("Compositor", options) {
259 Init(); 249 Init();
260 } 250 }
261 ~WebThreadForCompositor() override {} 251 ~WebThreadForCompositor() override {}
262 252
263 private: 253 private:
264 // WebThreadImplForWorkerScheduler: 254 // WebThreadImplForWorkerScheduler:
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 blink::enableLogChannel(t.token().c_str()); 341 blink::enableLogChannel(t.token().c_str());
352 } 342 }
353 343
354 void NotifyTimezoneChangeOnThisThread() { 344 void NotifyTimezoneChangeOnThisThread() {
355 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 345 v8::Isolate* isolate = v8::Isolate::GetCurrent();
356 if (!isolate) 346 if (!isolate)
357 return; 347 return;
358 v8::Date::DateTimeConfigurationChangeNotification(isolate); 348 v8::Date::DateTimeConfigurationChangeNotification(isolate);
359 } 349 }
360 350
351 void LowMemoryNotificationOnThisThread() {
352 v8::Isolate* isolate = v8::Isolate::GetCurrent();
353 if (!isolate)
354 return;
355 isolate->LowMemoryNotification();
356 }
357
361 class RenderFrameSetupImpl : public mojom::RenderFrameSetup { 358 class RenderFrameSetupImpl : public mojom::RenderFrameSetup {
362 public: 359 public:
363 explicit RenderFrameSetupImpl( 360 explicit RenderFrameSetupImpl(
364 mojo::InterfaceRequest<mojom::RenderFrameSetup> request) 361 mojo::InterfaceRequest<mojom::RenderFrameSetup> request)
365 : routing_id_highmark_(-1), binding_(this, std::move(request)) {} 362 : routing_id_highmark_(-1), binding_(this, std::move(request)) {}
366 363
367 void ExchangeInterfaceProviders( 364 void ExchangeInterfaceProviders(
368 int32_t frame_routing_id, 365 int32_t frame_routing_id,
369 shell::mojom::InterfaceProviderRequest services, 366 shell::mojom::InterfaceProviderRequest services,
370 shell::mojom::InterfaceProviderPtr exposed_services) override { 367 shell::mojom::InterfaceProviderPtr exposed_services) override {
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 media::InitializeMediaLibrary(); 816 media::InitializeMediaLibrary();
820 817
821 #if defined(OS_ANDROID) 818 #if defined(OS_ANDROID)
822 if (!command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode) && 819 if (!command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode) &&
823 media::MediaCodecUtil::IsMediaCodecAvailable()) { 820 media::MediaCodecUtil::IsMediaCodecAvailable()) {
824 media::EnablePlatformDecoderSupport(); 821 media::EnablePlatformDecoderSupport();
825 } 822 }
826 #endif 823 #endif
827 824
828 memory_pressure_listener_.reset(new base::MemoryPressureListener( 825 memory_pressure_listener_.reset(new base::MemoryPressureListener(
829 base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)), 826 base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this))));
830 base::Bind(&RenderThreadImpl::OnSyncMemoryPressure,
831 base::Unretained(this))));
832 827
833 int num_raster_threads = 0; 828 int num_raster_threads = 0;
834 std::string string_value = 829 std::string string_value =
835 command_line.GetSwitchValueASCII(switches::kNumRasterThreads); 830 command_line.GetSwitchValueASCII(switches::kNumRasterThreads);
836 bool parsed_num_raster_threads = 831 bool parsed_num_raster_threads =
837 base::StringToInt(string_value, &num_raster_threads); 832 base::StringToInt(string_value, &num_raster_threads);
838 DCHECK(parsed_num_raster_threads) << string_value; 833 DCHECK(parsed_num_raster_threads) << string_value;
839 DCHECK_GT(num_raster_threads, 0); 834 DCHECK_GT(num_raster_threads, 0);
840 835
841 // TODO(vmpstr): If the flag sticks, we should clean it up and always have 836 // TODO(vmpstr): If the flag sticks, we should clean it up and always have
(...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after
1929 const WorkerProcessMsg_CreateWorker_Params& params) { 1924 const WorkerProcessMsg_CreateWorker_Params& params) {
1930 // EmbeddedSharedWorkerStub will self-destruct. 1925 // EmbeddedSharedWorkerStub will self-destruct.
1931 new EmbeddedSharedWorkerStub( 1926 new EmbeddedSharedWorkerStub(
1932 params.url, params.name, params.content_security_policy, 1927 params.url, params.name, params.content_security_policy,
1933 params.security_policy_type, params.creation_address_space, 1928 params.security_policy_type, params.creation_address_space,
1934 params.pause_on_start, params.route_id); 1929 params.pause_on_start, params.route_id);
1935 } 1930 }
1936 1931
1937 void RenderThreadImpl::OnMemoryPressure( 1932 void RenderThreadImpl::OnMemoryPressure(
1938 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { 1933 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
1939 TRACE_EVENT0("memory","RenderThreadImpl::OnMemoryPressure");
1940 ReleaseFreeMemory(); 1934 ReleaseFreeMemory();
1941 1935
1942 // Do not call into blink if it is not initialized. 1936 // Do not call into blink if it is not initialized.
1943 if (blink_platform_impl_) { 1937 if (blink_platform_impl_) {
1944 blink::WebMemoryPressureListener::onMemoryPressure( 1938 blink::WebMemoryPressureListener::onMemoryPressure(
1945 static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level)); 1939 static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level));
1946 1940
1941 if (blink::mainThreadIsolate()) {
1942 // Trigger full v8 garbage collection on memory pressure notifications.
1943 // This will potentially hang the renderer for a long time, however, when
1944 // we receive a memory pressure notification, we might be about to be
1945 // killed. Because of the janky hang don't do this to foreground
1946 // renderers.
1947 if (RendererIsHidden()) {
1948 blink::mainThreadIsolate()->LowMemoryNotification();
1949 RenderThread::Get()->PostTaskToAllWebWorkers(
1950 base::Bind(&LowMemoryNotificationOnThisThread));
1951 }
1952 }
1953
1947 if (memory_pressure_level == 1954 if (memory_pressure_level ==
1948 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { 1955 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) {
1949 // Purge Skia font cache, by setting it to 0 and then again to the 1956 // Purge Skia font cache, by setting it to 0 and then again to the
1950 // previous limit. 1957 // previous limit.
1951 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); 1958 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0);
1952 SkGraphics::SetFontCacheLimit(font_cache_limit); 1959 SkGraphics::SetFontCacheLimit(font_cache_limit);
1953 } 1960 }
1954 } 1961 }
1955 } 1962 }
1956 1963
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
2097 RenderThreadImpl::PendingRenderFrameConnect::~PendingRenderFrameConnect() { 2104 RenderThreadImpl::PendingRenderFrameConnect::~PendingRenderFrameConnect() {
2098 } 2105 }
2099 2106
2100 void RenderThreadImpl::PendingRenderFrameConnect::OnConnectionError() { 2107 void RenderThreadImpl::PendingRenderFrameConnect::OnConnectionError() {
2101 size_t erased = 2108 size_t erased =
2102 RenderThreadImpl::current()->pending_render_frame_connects_.erase( 2109 RenderThreadImpl::current()->pending_render_frame_connects_.erase(
2103 routing_id_); 2110 routing_id_);
2104 DCHECK_EQ(1u, erased); 2111 DCHECK_EQ(1u, erased);
2105 } 2112 }
2106 2113
2107 void RenderThreadImpl::OnSyncMemoryPressure(
2108 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
2109 if (!blink::mainThreadIsolate())
2110 return;
2111
2112 v8::MemoryPressureLevel v8_memory_pressure_level =
2113 static_cast<v8::MemoryPressureLevel>(memory_pressure_level);
2114
2115 // In order to reduce performance impact, translate critical level to
2116 // moderate level for foregroud renderer.
2117 if (!RendererIsHidden() &&
2118 v8_memory_pressure_level == v8::MemoryPressureLevel::kCritical)
2119 v8_memory_pressure_level = v8::MemoryPressureLevel::kModerate;
2120
2121 blink::mainThreadIsolate()->MemoryPressureNotification(
2122 v8_memory_pressure_level);
2123 blink::MemoryPressureNotificationToWorkerThreadIsolates(
2124 v8_memory_pressure_level);
2125 }
2126
2127 } // namespace content 2114 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_thread_impl.h ('k') | third_party/WebKit/Source/core/workers/WorkerBackingThread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698