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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
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 648ac5128c2e7591af92b4c70b3456027cd6088c..fdba7c596ae48e0f141bcbae111a34a971994741 100644
--- a/content/renderer/render_thread_impl.cc
+++ b/content/renderer/render_thread_impl.cc
@@ -161,6 +161,7 @@
#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>
@@ -240,17 +241,6 @@
// incorrectly from the wrong thread.
base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl> >
lazy_tls = LAZY_INSTANCE_INITIALIZER;
-
-// v8::MemoryPressureLevel should correspond to base::MemoryPressureListener.
-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");
class WebThreadForCompositor : public WebThreadImplForWorkerScheduler {
public:
@@ -356,6 +346,13 @@
if (!isolate)
return;
v8::Date::DateTimeConfigurationChangeNotification(isolate);
+}
+
+void LowMemoryNotificationOnThisThread() {
+ v8::Isolate* isolate = v8::Isolate::GetCurrent();
+ if (!isolate)
+ return;
+ isolate->LowMemoryNotification();
}
class RenderFrameSetupImpl : public mojom::RenderFrameSetup {
@@ -826,9 +823,7 @@
#endif
memory_pressure_listener_.reset(new base::MemoryPressureListener(
- base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)),
- base::Bind(&RenderThreadImpl::OnSyncMemoryPressure,
- base::Unretained(this))));
+ base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this))));
int num_raster_threads = 0;
std::string string_value =
@@ -1936,13 +1931,25 @@
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.
if (blink_platform_impl_) {
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) {
@@ -2104,24 +2111,4 @@
DCHECK_EQ(1u, erased);
}
-void RenderThreadImpl::OnSyncMemoryPressure(
- base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
- if (!blink::mainThreadIsolate())
- return;
-
- v8::MemoryPressureLevel v8_memory_pressure_level =
- static_cast<v8::MemoryPressureLevel>(memory_pressure_level);
-
- // In order to reduce performance impact, translate critical level to
- // moderate level for foregroud renderer.
- if (!RendererIsHidden() &&
- v8_memory_pressure_level == v8::MemoryPressureLevel::kCritical)
- v8_memory_pressure_level = v8::MemoryPressureLevel::kModerate;
-
- blink::mainThreadIsolate()->MemoryPressureNotification(
- v8_memory_pressure_level);
- blink::MemoryPressureNotificationToWorkerThreadIsolates(
- v8_memory_pressure_level);
-}
-
} // namespace content
« 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