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

Side by Side Diff: webkit/glue/webkitplatformsupport_impl.cc

Issue 10113009: Set Android/V8 memory limits from dalvik.vm.heapsize. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments, rebase Created 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/glue/webkitplatformsupport_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "webkit/glue/webkitplatformsupport_impl.h" 5 #include "webkit/glue/webkitplatformsupport_impl.h"
6 6
7 #if defined(OS_LINUX) 7 #if defined(OS_LINUX)
8 #include <malloc.h> 8 #include <malloc.h>
9 #endif 9 #endif
10 10
11 #include <math.h> 11 #include <math.h>
12 12
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/bind.h" 15 #include "base/bind.h"
16 #include "base/debug/trace_event.h" 16 #include "base/debug/trace_event.h"
17 #include "base/memory/singleton.h" 17 #include "base/memory/singleton.h"
18 #include "base/message_loop.h" 18 #include "base/message_loop.h"
19 #include "base/metrics/histogram.h" 19 #include "base/metrics/histogram.h"
20 #include "base/metrics/stats_counters.h" 20 #include "base/metrics/stats_counters.h"
21 #include "base/platform_file.h" 21 #include "base/platform_file.h"
22 #include "base/process_util.h" 22 #include "base/process_util.h"
23 #include "base/rand_util.h" 23 #include "base/rand_util.h"
24 #include "base/string_number_conversions.h" 24 #include "base/string_number_conversions.h"
25 #include "base/string_util.h" 25 #include "base/string_util.h"
26 #include "base/synchronization/lock.h" 26 #include "base/synchronization/lock.h"
27 #include "base/sys_info.h"
27 #include "base/time.h" 28 #include "base/time.h"
28 #include "base/utf_string_conversions.h" 29 #include "base/utf_string_conversions.h"
29 #include "grit/webkit_chromium_resources.h" 30 #include "grit/webkit_chromium_resources.h"
30 #include "grit/webkit_resources.h" 31 #include "grit/webkit_resources.h"
31 #include "grit/webkit_strings.h" 32 #include "grit/webkit_strings.h"
32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h"
33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginListBuilder. h" 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginListBuilder. h"
34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
35 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCookie.h" 36 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCookie.h"
36 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h" 37 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h"
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 return 0; 662 return 0;
662 } 663 }
663 664
664 WebKit::WebString WebKitPlatformSupportImpl::signedPublicKeyAndChallengeString( 665 WebKit::WebString WebKitPlatformSupportImpl::signedPublicKeyAndChallengeString(
665 unsigned key_size_index, 666 unsigned key_size_index,
666 const WebKit::WebString& challenge, 667 const WebKit::WebString& challenge,
667 const WebKit::WebURL& url) { 668 const WebKit::WebURL& url) {
668 return WebKit::WebString(""); 669 return WebKit::WebString("");
669 } 670 }
670 671
671 #if defined(OS_LINUX) 672 #if defined(OS_LINUX) || defined(OS_ANDROID)
672 static size_t memoryUsageMBLinux() { 673 static size_t memoryUsageMB() {
673 struct mallinfo minfo = mallinfo(); 674 struct mallinfo minfo = mallinfo();
674 uint64_t mem_usage = 675 uint64_t mem_usage =
675 #if defined(USE_TCMALLOC) 676 #if defined(USE_TCMALLOC)
676 minfo.uordblks 677 minfo.uordblks
677 #else 678 #else
678 (minfo.hblkhd + minfo.arena) 679 (minfo.hblkhd + minfo.arena)
679 #endif 680 #endif
680 >> 20; 681 >> 20;
681 682
682 v8::HeapStatistics stat; 683 v8::HeapStatistics stat;
683 v8::V8::GetHeapStatistics(&stat); 684 v8::V8::GetHeapStatistics(&stat);
684 return mem_usage + (static_cast<uint64_t>(stat.total_heap_size()) >> 20); 685 return mem_usage + (static_cast<uint64_t>(stat.total_heap_size()) >> 20);
685 } 686 }
686 #endif 687 #elif defined(OS_MACOSX)
687 688 static size_t memoryUsageMB() {
688 #if defined(OS_MACOSX)
689 static size_t memoryUsageMBMac() {
690 using base::ProcessMetrics; 689 using base::ProcessMetrics;
691 static ProcessMetrics* process_metrics = 690 static ProcessMetrics* process_metrics =
692 // The default port provider is sufficient to get data for the current 691 // The default port provider is sufficient to get data for the current
693 // process. 692 // process.
694 ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle(), 693 ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle(),
695 NULL); 694 NULL);
696 DCHECK(process_metrics); 695 DCHECK(process_metrics);
697 return process_metrics->GetWorkingSetSize() >> 20; 696 return process_metrics->GetWorkingSetSize() >> 20;
698 } 697 }
699 #endif 698 #else
700 699 static size_t memoryUsageMB() {
701 #if !defined(OS_LINUX) && !defined(OS_MACOSX)
702 static size_t memoryUsageMBGeneric() {
703 using base::ProcessMetrics; 700 using base::ProcessMetrics;
704 static ProcessMetrics* process_metrics = 701 static ProcessMetrics* process_metrics =
705 ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle()); 702 ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle());
706 DCHECK(process_metrics); 703 DCHECK(process_metrics);
707 return process_metrics->GetPagefileUsage() >> 20; 704 return process_metrics->GetPagefileUsage() >> 20;
708 } 705 }
709 #endif 706 #endif
710 707
711 static size_t getMemoryUsageMB(bool bypass_cache) { 708 static size_t getMemoryUsageMB(bool bypass_cache) {
712 size_t current_mem_usage = 0; 709 size_t current_mem_usage = 0;
713 MemoryUsageCache* mem_usage_cache_singleton = MemoryUsageCache::GetInstance(); 710 MemoryUsageCache* mem_usage_cache_singleton = MemoryUsageCache::GetInstance();
714 if (!bypass_cache && 711 if (!bypass_cache &&
715 mem_usage_cache_singleton->IsCachedValueValid(&current_mem_usage)) 712 mem_usage_cache_singleton->IsCachedValueValid(&current_mem_usage))
716 return current_mem_usage; 713 return current_mem_usage;
717 714
718 current_mem_usage = 715 current_mem_usage = memoryUsageMB();
719 #if defined(OS_LINUX)
720 memoryUsageMBLinux();
721 #elif defined(OS_MACOSX)
722 memoryUsageMBMac();
723 #else
724 memoryUsageMBGeneric();
725 #endif
726 mem_usage_cache_singleton->SetMemoryValue(current_mem_usage); 716 mem_usage_cache_singleton->SetMemoryValue(current_mem_usage);
727 return current_mem_usage; 717 return current_mem_usage;
728 } 718 }
729 719
730 size_t WebKitPlatformSupportImpl::memoryUsageMB() { 720 size_t WebKitPlatformSupportImpl::memoryUsageMB() {
731 return getMemoryUsageMB(false); 721 return getMemoryUsageMB(false);
732 } 722 }
733 723
734 size_t WebKitPlatformSupportImpl::actualMemoryUsageMB() { 724 size_t WebKitPlatformSupportImpl::actualMemoryUsageMB() {
735 return getMemoryUsageMB(true); 725 return getMemoryUsageMB(true);
736 } 726 }
737 727
728 #if defined(OS_ANDROID)
729 size_t WebKitPlatformSupportImpl::lowMemoryUsageMB() {
730 // If memory usage is below this threshold, do not bother forcing GC.
731 // Allow us to use up to our memory class value before V8's GC kicks in.
732 // These values have been determined by experimentation.
733 return base::SysInfo::DalvikHeapSizeMB() / 2;
734 }
735
736 size_t WebKitPlatformSupportImpl::highMemoryUsageMB() {
737 // If memory usage is above this threshold, force GC more aggressively.
738 return base::SysInfo::DalvikHeapSizeMB() * 3 / 4;
739 }
740
741 size_t WebKitPlatformSupportImpl::highUsageDeltaMB() {
742 // If memory usage is above highMemoryUsageMB() and memory usage increased by
743 // more than highUsageDeltaMB() since the last GC, then force GC.
744 // Note that this limit should be greater than the amount of memory for V8
745 // internal data structures that are released on GC and reallocated during JS
746 // execution (about 8MB). Otherwise, it will cause too aggressive GCs.
747 return base::SysInfo::DalvikHeapSizeMB() / 8;
748 }
749 #endif
750
738 void WebKitPlatformSupportImpl::SuspendSharedTimer() { 751 void WebKitPlatformSupportImpl::SuspendSharedTimer() {
739 ++shared_timer_suspended_; 752 ++shared_timer_suspended_;
740 } 753 }
741 754
742 void WebKitPlatformSupportImpl::ResumeSharedTimer() { 755 void WebKitPlatformSupportImpl::ResumeSharedTimer() {
743 // The shared timer may have fired or been adjusted while we were suspended. 756 // The shared timer may have fired or been adjusted while we were suspended.
744 if (--shared_timer_suspended_ == 0 && !shared_timer_.IsRunning()) { 757 if (--shared_timer_suspended_ == 0 && !shared_timer_.IsRunning()) {
745 setSharedTimerFireInterval( 758 setSharedTimerFireInterval(
746 shared_timer_fire_time_ - monotonicallyIncreasingTime()); 759 shared_timer_fire_time_ - monotonicallyIncreasingTime());
747 } 760 }
(...skipping 12 matching lines...) Expand all
760 worker_task_runner->OnWorkerRunLoopStarted(runLoop); 773 worker_task_runner->OnWorkerRunLoopStarted(runLoop);
761 } 774 }
762 775
763 void WebKitPlatformSupportImpl::didStopWorkerRunLoop( 776 void WebKitPlatformSupportImpl::didStopWorkerRunLoop(
764 const WebKit::WebWorkerRunLoop& runLoop) { 777 const WebKit::WebWorkerRunLoop& runLoop) {
765 WorkerTaskRunner* worker_task_runner = WorkerTaskRunner::Instance(); 778 WorkerTaskRunner* worker_task_runner = WorkerTaskRunner::Instance();
766 worker_task_runner->OnWorkerRunLoopStopped(runLoop); 779 worker_task_runner->OnWorkerRunLoopStopped(runLoop);
767 } 780 }
768 781
769 } // namespace webkit_glue 782 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « webkit/glue/webkitplatformsupport_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698