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

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, 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « 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 d3ee4b8dce527ffa822c17609e5400d8b4f9489a..7753e26cfb39c44a83524e8a2f7a2a4e8d28a228 100644
--- a/content/renderer/render_thread_impl.cc
+++ b/content/renderer/render_thread_impl.cc
@@ -160,7 +160,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>
@@ -355,11 +354,12 @@ void NotifyTimezoneChangeOnThisThread() {
v8::Date::DateTimeConfigurationChangeNotification(isolate);
}
-void LowMemoryNotificationOnThisThread() {
+void LowMemoryNotificationOnThisThread(
+ v8::MemoryPressureLevel memory_pressure_level) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
if (!isolate)
return;
- isolate->LowMemoryNotification();
+ isolate->MemoryPressureNotification(memory_pressure_level);
}
class RenderFrameSetupImpl : public mojom::RenderFrameSetup {
@@ -811,7 +811,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::OnSyncMemoryPressure,
+ base::Unretained(this))));
int num_raster_threads = 0;
std::string string_value =
@@ -2006,6 +2008,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.
@@ -2013,19 +2016,6 @@ void RenderThreadImpl::OnMemoryPressure(
blink::WebMemoryPressureListener::onMemoryPressure(
static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level));
- if (blink::mainThreadIsolate()) {
- // Trigger full v8 garbage collection on memory pressure notifications.
- // 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. Because of the janky hang don't do this to foreground
- // renderers.
- if (RendererIsHidden()) {
- blink::mainThreadIsolate()->LowMemoryNotification();
- RenderThread::Get()->PostTaskToAllWebWorkers(
- base::Bind(&LowMemoryNotificationOnThisThread));
- }
- }
-
if (memory_pressure_level ==
base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) {
// Purge Skia font cache, by setting it to 0 and then again to the
@@ -2180,4 +2170,31 @@ void RenderThreadImpl::PendingRenderFrameConnect::OnConnectionError() {
DCHECK_EQ(1u, erased);
}
+void RenderThreadImpl::OnSyncMemoryPressure(
+ base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
+ if (blink::mainThreadIsolate()) {
+ static_assert(
+ static_cast<v8::MemoryPressureLevel>(
+ base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) ==
+ v8::MemoryPressureLevel::kNone, "none level not align");
+ static_assert(
+ static_cast<v8::MemoryPressureLevel>(
+ base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE) ==
+ v8::MemoryPressureLevel::kModerate, "moderate level not align");
+ static_assert(
+ static_cast<v8::MemoryPressureLevel>(
+ base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) ==
+ v8::MemoryPressureLevel::kCritical, "critical level not align");
+
+ v8::MemoryPressureLevel v8_memory_pressure_level =
+ static_cast<v8::MemoryPressureLevel>(memory_pressure_level);
+
+ blink::mainThreadIsolate()->MemoryPressureNotification(
+ v8_memory_pressure_level);
+ 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.
+ base::Bind(&LowMemoryNotificationOnThisThread,
+ v8_memory_pressure_level));
+ }
+}
+
} // namespace content
« 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