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

Unified 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, 10 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 side-by-side diff with in-line comments
Download patch
« base/observer_list_threadsafe.h ('K') | « content/renderer/render_thread_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/render_thread_impl.cc
diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc
index 12e31bd84c93b5922bd24fa8094c46a8ead06434..d3e36869968d4fa513a6e753f398ed0992d59345 100644
--- a/content/renderer/render_thread_impl.cc
+++ b/content/renderer/render_thread_impl.cc
@@ -163,7 +163,6 @@
#include "third_party/skia/include/core/SkGraphics.h"
#include "ui/base/layout.h"
#include "ui/base/ui_base_switches.h"
-#include "v8/include/v8.h"
#if defined(OS_ANDROID)
#include <cpu-features.h>
@@ -818,7 +817,9 @@ void RenderThreadImpl::Init() {
#endif
memory_pressure_listener_.reset(new base::MemoryPressureListener(
- base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this))));
+ base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)),
+ base::Bind(&RenderThreadImpl::IsMemoryPressured,
+ base::Unretained(this))));
int num_raster_threads = 0;
std::string string_value =
@@ -2014,6 +2015,7 @@ void RenderThreadImpl::OnCreateNewSharedWorker(
void RenderThreadImpl::OnMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
+ TRACE_EVENT0("memory","RenderThreadImpl::OnMemoryPressure");
ReleaseFreeMemory();
// Do not call into blink if it is not initialized.
@@ -2026,7 +2028,11 @@ void RenderThreadImpl::OnMemoryPressure(
// This will potentially hang the renderer for a long time, however, when
// we receive a memory pressure notification, we might be about to be
// killed.
- blink::mainThreadIsolate()->LowMemoryNotification();
+ if (is_v8_need_gc_) {
+ blink::mainThreadIsolate()->LowMemoryNotification();
+ is_v8_need_gc_ = false;
+ }
+
RenderThread::Get()->PostTaskToAllWebWorkers(
base::Bind(&LowMemoryNotificationOnThisThread));
}
@@ -2185,4 +2191,18 @@ void RenderThreadImpl::PendingRenderFrameConnect::OnConnectionError() {
DCHECK_EQ(1u, erased);
}
+void RenderThreadImpl::OnV8InterruptCallback(v8::Isolate* isolate, void* data) {
+ RenderThreadImpl* pRenderThreadImpl =
+ reinterpret_cast<RenderThreadImpl*>(data);
+ if (!pRenderThreadImpl || !pRenderThreadImpl->is_v8_need_gc_)
+ return;
+ blink::mainThreadIsolate()->LowMemoryNotification();
esprehn 2016/03/01 22:15:07 Is this safe? You're using the LowMemoryNotificati
+ pRenderThreadImpl->is_v8_need_gc_ = false;
+}
+
+void RenderThreadImpl::IsMemoryPressured(bool memory_pressured) {
+ is_v8_need_gc_ = true;
+ blink::mainThreadIsolate()->RequestInterrupt(&OnV8InterruptCallback, this);
jochen (gone - plz use gerrit) 2016/03/02 07:59:38 the interrupt callback must not reenter V8.
+}
+
} // namespace content
« 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