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

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: Remove redundant includes Created 8 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 unified diff | Download patch | Annotate | Revision Log
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/platform/WebCookie.h" 33 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCookie.h"
33 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h" 34 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h"
34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h"
35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginListBuilder. h" 36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginListBuilder. h"
36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" 37 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 return 0; 614 return 0;
614 } 615 }
615 616
616 WebKit::WebString WebKitPlatformSupportImpl::signedPublicKeyAndChallengeString( 617 WebKit::WebString WebKitPlatformSupportImpl::signedPublicKeyAndChallengeString(
617 unsigned key_size_index, 618 unsigned key_size_index,
618 const WebKit::WebString& challenge, 619 const WebKit::WebString& challenge,
619 const WebKit::WebURL& url) { 620 const WebKit::WebURL& url) {
620 return WebKit::WebString(""); 621 return WebKit::WebString("");
621 } 622 }
622 623
623 #if defined(OS_LINUX) 624 #if defined(OS_LINUX) || defined(OS_ANDROID)
624 static size_t memoryUsageMBLinux() { 625 static size_t memoryUsageMB() {
625 struct mallinfo minfo = mallinfo(); 626 struct mallinfo minfo = mallinfo();
626 uint64_t mem_usage = 627 uint64_t mem_usage =
627 #if defined(USE_TCMALLOC) 628 #if defined(USE_TCMALLOC)
628 minfo.uordblks 629 minfo.uordblks
629 #else 630 #else
630 (minfo.hblkhd + minfo.arena) 631 (minfo.hblkhd + minfo.arena)
631 #endif 632 #endif
632 >> 20; 633 >> 20;
633 634
634 v8::HeapStatistics stat; 635 v8::HeapStatistics stat;
635 v8::V8::GetHeapStatistics(&stat); 636 v8::V8::GetHeapStatistics(&stat);
636 return mem_usage + (static_cast<uint64_t>(stat.total_heap_size()) >> 20); 637 return mem_usage + (static_cast<uint64_t>(stat.total_heap_size()) >> 20);
637 } 638 }
638 #endif 639 #elif defined(OS_MACOSX)
639 640 static size_t memoryUsageMB() {
640 #if defined(OS_MACOSX)
641 static size_t memoryUsageMBMac() {
642 using base::ProcessMetrics; 641 using base::ProcessMetrics;
643 static ProcessMetrics* process_metrics = 642 static ProcessMetrics* process_metrics =
644 // The default port provider is sufficient to get data for the current 643 // The default port provider is sufficient to get data for the current
645 // process. 644 // process.
646 ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle(), 645 ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle(),
647 NULL); 646 NULL);
648 DCHECK(process_metrics); 647 DCHECK(process_metrics);
649 return process_metrics->GetWorkingSetSize() >> 20; 648 return process_metrics->GetWorkingSetSize() >> 20;
650 } 649 }
651 #endif 650 #else
652 651 static size_t memoryUsageMB() {
653 #if !defined(OS_LINUX) && !defined(OS_MACOSX)
654 static size_t memoryUsageMBGeneric() {
655 using base::ProcessMetrics; 652 using base::ProcessMetrics;
656 static ProcessMetrics* process_metrics = 653 static ProcessMetrics* process_metrics =
657 ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle()); 654 ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle());
658 DCHECK(process_metrics); 655 DCHECK(process_metrics);
659 return process_metrics->GetPagefileUsage() >> 20; 656 return process_metrics->GetPagefileUsage() >> 20;
660 } 657 }
661 #endif 658 #endif
662 659
663 static size_t getMemoryUsageMB(bool bypass_cache) { 660 static size_t getMemoryUsageMB(bool bypass_cache) {
664 size_t current_mem_usage = 0; 661 size_t current_mem_usage = 0;
665 MemoryUsageCache* mem_usage_cache_singleton = MemoryUsageCache::GetInstance(); 662 MemoryUsageCache* mem_usage_cache_singleton = MemoryUsageCache::GetInstance();
666 if (!bypass_cache && 663 if (!bypass_cache &&
667 mem_usage_cache_singleton->IsCachedValueValid(&current_mem_usage)) 664 mem_usage_cache_singleton->IsCachedValueValid(&current_mem_usage))
668 return current_mem_usage; 665 return current_mem_usage;
669 666
670 current_mem_usage = 667 current_mem_usage = memoryUsageMB();
671 #if defined(OS_LINUX)
672 memoryUsageMBLinux();
673 #elif defined(OS_MACOSX)
674 memoryUsageMBMac();
675 #else
676 memoryUsageMBGeneric();
677 #endif
678 mem_usage_cache_singleton->SetMemoryValue(current_mem_usage); 668 mem_usage_cache_singleton->SetMemoryValue(current_mem_usage);
679 return current_mem_usage; 669 return current_mem_usage;
680 } 670 }
681 671
682 size_t WebKitPlatformSupportImpl::memoryUsageMB() { 672 size_t WebKitPlatformSupportImpl::memoryUsageMB() {
683 return getMemoryUsageMB(false); 673 return getMemoryUsageMB(false);
684 } 674 }
685 675
686 size_t WebKitPlatformSupportImpl::actualMemoryUsageMB() { 676 size_t WebKitPlatformSupportImpl::actualMemoryUsageMB() {
687 return getMemoryUsageMB(true); 677 return getMemoryUsageMB(true);
688 } 678 }
689 679
680 #if defined(OS_ANDROID)
681 size_t WebKitPlatformSupportImpl::lowMemoryUsageMB() {
682 // If memory usage is below this threshold, do not bother forcing GC.
683 // Allow us to use up to our memory class value before V8's GC kicks in.
684 // These values have been determined by experimentation.
685 return base::SysInfo::DalvikHeapSizeMB() / 4;
Xianzhu 2012/05/15 17:18:03 This seems too conservative. We ever used the dalv
Xianzhu 2012/05/15 17:53:23 After further testing, I found that the change abo
686 }
687
688 size_t WebKitPlatformSupportImpl::highMemoryUsageMB() {
689 // If memory usage is above this threshold, force GC more aggressively.
690 return lowMemoryUsageMB() * 2;
691 }
692
693 size_t WebKitPlatformSupportImpl::highUsageDeltaMB() {
694 // Threshold of delta of memory usage growth (vs. last working set estimate)
695 // to force GC when memory usage is high.
696 // Avoid constant V8 GC when memory usage equals to working set estimate.
697 return lowMemoryUsageMB() / 2;
698 }
699 #endif
700
690 void WebKitPlatformSupportImpl::SuspendSharedTimer() { 701 void WebKitPlatformSupportImpl::SuspendSharedTimer() {
691 ++shared_timer_suspended_; 702 ++shared_timer_suspended_;
692 } 703 }
693 704
694 void WebKitPlatformSupportImpl::ResumeSharedTimer() { 705 void WebKitPlatformSupportImpl::ResumeSharedTimer() {
695 // The shared timer may have fired or been adjusted while we were suspended. 706 // The shared timer may have fired or been adjusted while we were suspended.
696 if (--shared_timer_suspended_ == 0 && !shared_timer_.IsRunning()) { 707 if (--shared_timer_suspended_ == 0 && !shared_timer_.IsRunning()) {
697 setSharedTimerFireInterval( 708 setSharedTimerFireInterval(
698 shared_timer_fire_time_ - monotonicallyIncreasingTime()); 709 shared_timer_fire_time_ - monotonicallyIncreasingTime());
699 } 710 }
(...skipping 12 matching lines...) Expand all
712 worker_task_runner->OnWorkerRunLoopStarted(runLoop); 723 worker_task_runner->OnWorkerRunLoopStarted(runLoop);
713 } 724 }
714 725
715 void WebKitPlatformSupportImpl::didStopWorkerRunLoop( 726 void WebKitPlatformSupportImpl::didStopWorkerRunLoop(
716 const WebKit::WebWorkerRunLoop& runLoop) { 727 const WebKit::WebWorkerRunLoop& runLoop) {
717 WorkerTaskRunner* worker_task_runner = WorkerTaskRunner::Instance(); 728 WorkerTaskRunner* worker_task_runner = WorkerTaskRunner::Instance();
718 worker_task_runner->OnWorkerRunLoopStopped(runLoop); 729 worker_task_runner->OnWorkerRunLoopStopped(runLoop);
719 } 730 }
720 731
721 } // namespace webkit_glue 732 } // namespace webkit_glue
OLDNEW
« base/android/dalvik_heap_size.cc ('K') | « webkit/glue/webkitplatformsupport_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698