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

Unified Diff: third_party/WebKit/Source/bindings/core/v8/V8GCForContextDispose.cpp

Issue 2948983002: Low memory page navigation GC for low end devices (Closed)
Patch Set: fix Created 3 years, 6 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
Index: third_party/WebKit/Source/bindings/core/v8/V8GCForContextDispose.cpp
diff --git a/third_party/WebKit/Source/bindings/core/v8/V8GCForContextDispose.cpp b/third_party/WebKit/Source/bindings/core/v8/V8GCForContextDispose.cpp
index deca64c5ee5773498a32c574de0a5dbd4732bfce..000898deed644ad1925e7f111d3d86ab464c0657 100644
--- a/third_party/WebKit/Source/bindings/core/v8/V8GCForContextDispose.cpp
+++ b/third_party/WebKit/Source/bindings/core/v8/V8GCForContextDispose.cpp
@@ -30,12 +30,26 @@
#include "bindings/core/v8/V8GCForContextDispose.h"
+#include "platform/Histogram.h"
+#include "platform/MemoryCoordinator.h"
#include "platform/bindings/V8PerIsolateData.h"
#include "platform/wtf/CurrentTime.h"
+#include "platform/wtf/ProcessMetrics.h"
#include "platform/wtf/StdLibExtras.h"
#include "public/platform/Platform.h"
#include "v8/include/v8.h"
+size_t GetMemoryUsage() {
+ size_t usage = WTF::GetMallocUsage() + WTF::Partitions::TotalActiveBytes() +
+ blink::ProcessHeap::TotalAllocatedObjectSize() +
+ blink::ProcessHeap::TotalMarkedObjectSize();
+ v8::HeapStatistics v8_heap_statistics;
+ blink::V8PerIsolateData::MainThreadIsolate()->GetHeapStatistics(
+ &v8_heap_statistics);
+ usage = v8_heap_statistics.total_heap_size();
+ return usage;
+}
+
namespace blink {
V8GCForContextDispose::V8GCForContextDispose()
@@ -43,9 +57,30 @@ V8GCForContextDispose::V8GCForContextDispose()
Reset();
}
-void V8GCForContextDispose::NotifyContextDisposed(bool is_main_frame) {
+void V8GCForContextDispose::NotifyContextDisposed(
+ bool is_main_frame,
+ WindowProxy::FrameReuseStatus frame_reuse_status) {
did_dispose_context_for_main_frame_ = is_main_frame;
last_context_disposal_time_ = WTF::CurrentTime();
+#if OS(ANDROID)
+ // When a low end device is in a low memory situation we should prioritize
+ // memory use and trigger a V8+Blink GC. However, on Android, if the frame
+ // will not be reused, the process will likely to be killed soon so skip this.
+ if (is_main_frame && frame_reuse_status == WindowProxy::kFrameWillBeReused &&
+ MemoryCoordinator::IsLowEndDevice() &&
+ MemoryCoordinator::IsCurrentlyLowMemory()) {
+ size_t pre_gc_memory_usage = GetMemoryUsage();
+ V8PerIsolateData::MainThreadIsolate()->MemoryPressureNotification(
+ v8::MemoryPressureLevel::kCritical);
+ size_t post_gc_memory_usage = GetMemoryUsage();
+ int reduction = static_cast<int>(pre_gc_memory_usage) -
+ static_cast<int>(post_gc_memory_usage);
+ DEFINE_STATIC_LOCAL(
+ CustomCountHistogram, reduction_histogram,
+ ("BlinkGC.LowMemoryPageNavigationGC.Reduction", 1, 512, 50));
+ reduction_histogram.Count(reduction / 1024 / 1024);
+ }
+#endif
V8PerIsolateData::MainThreadIsolate()->ContextDisposedNotification(
!is_main_frame);
pseudo_idle_timer_.Stop();

Powered by Google App Engine
This is Rietveld 408576698