OLD | NEW |
---|---|
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 #if defined(OS_ANDROID) | |
16 #include <sys/system_properties.h> | |
17 #endif | |
18 | |
15 #include "base/bind.h" | 19 #include "base/bind.h" |
16 #include "base/debug/trace_event.h" | 20 #include "base/debug/trace_event.h" |
17 #include "base/memory/singleton.h" | 21 #include "base/memory/singleton.h" |
18 #include "base/message_loop.h" | 22 #include "base/message_loop.h" |
19 #include "base/metrics/histogram.h" | 23 #include "base/metrics/histogram.h" |
20 #include "base/metrics/stats_counters.h" | 24 #include "base/metrics/stats_counters.h" |
21 #include "base/platform_file.h" | 25 #include "base/platform_file.h" |
22 #include "base/process_util.h" | 26 #include "base/process_util.h" |
23 #include "base/rand_util.h" | 27 #include "base/rand_util.h" |
24 #include "base/string_number_conversions.h" | 28 #include "base/string_number_conversions.h" |
25 #include "base/string_util.h" | 29 #include "base/string_util.h" |
26 #include "base/synchronization/lock.h" | 30 #include "base/synchronization/lock.h" |
27 #include "base/time.h" | 31 #include "base/time.h" |
28 #include "base/utf_string_conversions.h" | 32 #include "base/utf_string_conversions.h" |
29 #include "grit/webkit_chromium_resources.h" | 33 #include "grit/webkit_chromium_resources.h" |
30 #include "grit/webkit_resources.h" | 34 #include "grit/webkit_resources.h" |
31 #include "grit/webkit_strings.h" | 35 #include "grit/webkit_strings.h" |
32 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCookie.h" | 36 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCookie.h" |
33 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h" | 37 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h" |
34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" | 38 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" |
35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginListBuilder. h" | 39 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginListBuilder. h" |
36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" | 40 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" |
37 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 41 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
38 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" | 42 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" |
39 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" | 43 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" |
44 #if defined(OS_ANDROID) | |
45 #include "webkit/glue/dalvik_heap_size_android.h" | |
46 #endif | |
40 #include "webkit/glue/webkit_glue.h" | 47 #include "webkit/glue/webkit_glue.h" |
41 #include "webkit/glue/websocketstreamhandle_impl.h" | 48 #include "webkit/glue/websocketstreamhandle_impl.h" |
42 #include "webkit/glue/webthread_impl.h" | 49 #include "webkit/glue/webthread_impl.h" |
43 #include "webkit/glue/weburlloader_impl.h" | 50 #include "webkit/glue/weburlloader_impl.h" |
44 #include "webkit/glue/worker_task_runner.h" | 51 #include "webkit/glue/worker_task_runner.h" |
45 #include "webkit/media/audio_decoder.h" | 52 #include "webkit/media/audio_decoder.h" |
46 #include "webkit/plugins/npapi/plugin_instance.h" | 53 #include "webkit/plugins/npapi/plugin_instance.h" |
47 #include "webkit/plugins/webplugininfo.h" | 54 #include "webkit/plugins/webplugininfo.h" |
48 | 55 |
49 #if defined(OS_LINUX) | 56 #if defined(OS_LINUX) |
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
613 return 0; | 620 return 0; |
614 } | 621 } |
615 | 622 |
616 WebKit::WebString WebKitPlatformSupportImpl::signedPublicKeyAndChallengeString( | 623 WebKit::WebString WebKitPlatformSupportImpl::signedPublicKeyAndChallengeString( |
617 unsigned key_size_index, | 624 unsigned key_size_index, |
618 const WebKit::WebString& challenge, | 625 const WebKit::WebString& challenge, |
619 const WebKit::WebURL& url) { | 626 const WebKit::WebURL& url) { |
620 return WebKit::WebString(""); | 627 return WebKit::WebString(""); |
621 } | 628 } |
622 | 629 |
623 #if defined(OS_LINUX) | 630 #if defined(OS_LINUX) || defined(OS_ANDROID) |
624 static size_t memoryUsageMBLinux() { | 631 static size_t memoryUsageMB() { |
625 struct mallinfo minfo = mallinfo(); | 632 struct mallinfo minfo = mallinfo(); |
626 uint64_t mem_usage = | 633 uint64_t mem_usage = |
627 #if defined(USE_TCMALLOC) | 634 #if defined(USE_TCMALLOC) |
628 minfo.uordblks | 635 minfo.uordblks |
629 #else | 636 #else |
630 (minfo.hblkhd + minfo.arena) | 637 (minfo.hblkhd + minfo.arena) |
631 #endif | 638 #endif |
632 >> 20; | 639 >> 20; |
633 | 640 |
634 v8::HeapStatistics stat; | 641 v8::HeapStatistics stat; |
635 v8::V8::GetHeapStatistics(&stat); | 642 v8::V8::GetHeapStatistics(&stat); |
636 return mem_usage + (static_cast<uint64_t>(stat.total_heap_size()) >> 20); | 643 return mem_usage + (static_cast<uint64_t>(stat.total_heap_size()) >> 20); |
637 } | 644 } |
638 #endif | 645 #elif defined(OS_MACOSX) |
639 | 646 static size_t memoryUsageMB() { |
640 #if defined(OS_MACOSX) | |
641 static size_t memoryUsageMBMac() { | |
642 using base::ProcessMetrics; | 647 using base::ProcessMetrics; |
643 static ProcessMetrics* process_metrics = | 648 static ProcessMetrics* process_metrics = |
644 // The default port provider is sufficient to get data for the current | 649 // The default port provider is sufficient to get data for the current |
645 // process. | 650 // process. |
646 ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle(), | 651 ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle(), |
647 NULL); | 652 NULL); |
648 DCHECK(process_metrics); | 653 DCHECK(process_metrics); |
649 return process_metrics->GetWorkingSetSize() >> 20; | 654 return process_metrics->GetWorkingSetSize() >> 20; |
650 } | 655 } |
651 #endif | 656 #else |
652 | 657 static size_t memoryUsageMB() { |
653 #if !defined(OS_LINUX) && !defined(OS_MACOSX) | |
654 static size_t memoryUsageMBGeneric() { | |
655 using base::ProcessMetrics; | 658 using base::ProcessMetrics; |
656 static ProcessMetrics* process_metrics = | 659 static ProcessMetrics* process_metrics = |
657 ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle()); | 660 ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle()); |
658 DCHECK(process_metrics); | 661 DCHECK(process_metrics); |
659 return process_metrics->GetPagefileUsage() >> 20; | 662 return process_metrics->GetPagefileUsage() >> 20; |
660 } | 663 } |
661 #endif | 664 #endif |
662 | 665 |
663 static size_t getMemoryUsageMB(bool bypass_cache) { | 666 static size_t getMemoryUsageMB(bool bypass_cache) { |
664 size_t current_mem_usage = 0; | 667 size_t current_mem_usage = 0; |
665 MemoryUsageCache* mem_usage_cache_singleton = MemoryUsageCache::GetInstance(); | 668 MemoryUsageCache* mem_usage_cache_singleton = MemoryUsageCache::GetInstance(); |
666 if (!bypass_cache && | 669 if (!bypass_cache && |
667 mem_usage_cache_singleton->IsCachedValueValid(¤t_mem_usage)) | 670 mem_usage_cache_singleton->IsCachedValueValid(¤t_mem_usage)) |
668 return current_mem_usage; | 671 return current_mem_usage; |
669 | 672 |
670 current_mem_usage = | 673 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); | 674 mem_usage_cache_singleton->SetMemoryValue(current_mem_usage); |
679 return current_mem_usage; | 675 return current_mem_usage; |
680 } | 676 } |
681 | 677 |
682 size_t WebKitPlatformSupportImpl::memoryUsageMB() { | 678 size_t WebKitPlatformSupportImpl::memoryUsageMB() { |
683 return getMemoryUsageMB(false); | 679 return getMemoryUsageMB(false); |
684 } | 680 } |
685 | 681 |
686 size_t WebKitPlatformSupportImpl::actualMemoryUsageMB() { | 682 size_t WebKitPlatformSupportImpl::actualMemoryUsageMB() { |
687 return getMemoryUsageMB(true); | 683 return getMemoryUsageMB(true); |
688 } | 684 } |
689 | 685 |
686 #if defined(OS_ANDROID) | |
687 size_t WebKitPlatformSupportImpl::lowMemoryUsageMB() { | |
688 // If memory usage is below this threshold, do not bother forcing GC. | |
darin (slow to review)
2012/05/14 16:23:49
Are you expecting this function to be called on mu
ulan
2012/05/15 12:44:03
Thanks, converted DalvikHeapSize to LazyInstance s
| |
689 // Allow us to use up to our memory class value before V8's GC kicks in. | |
690 // These values have been determined by experimentation. | |
691 DalvikHeapSize* heap_size_singleton = DalvikHeapSize::GetInstance(); | |
692 return heap_size_singleton->HeapSizeMB() / 4; | |
693 } | |
694 | |
695 size_t WebKitPlatformSupportImpl::highMemoryUsageMB() { | |
696 // If memory usage is above this threshold, force GC more aggressively. | |
697 return lowMemoryUsageMB() * 2; | |
698 } | |
699 | |
700 size_t WebKitPlatformSupportImpl::highUsageDeltaMB() { | |
701 // Threshold of delta of memory usage growth (vs. last working set estimate) | |
702 // to force GC when memory usage is high. | |
703 // Avoid constant V8 GC when memory usage equals to working set estimate. | |
704 return lowMemoryUsageMB() / 2; | |
705 } | |
706 #endif | |
707 | |
690 void WebKitPlatformSupportImpl::SuspendSharedTimer() { | 708 void WebKitPlatformSupportImpl::SuspendSharedTimer() { |
691 ++shared_timer_suspended_; | 709 ++shared_timer_suspended_; |
692 } | 710 } |
693 | 711 |
694 void WebKitPlatformSupportImpl::ResumeSharedTimer() { | 712 void WebKitPlatformSupportImpl::ResumeSharedTimer() { |
695 // The shared timer may have fired or been adjusted while we were suspended. | 713 // The shared timer may have fired or been adjusted while we were suspended. |
696 if (--shared_timer_suspended_ == 0 && !shared_timer_.IsRunning()) { | 714 if (--shared_timer_suspended_ == 0 && !shared_timer_.IsRunning()) { |
697 setSharedTimerFireInterval( | 715 setSharedTimerFireInterval( |
698 shared_timer_fire_time_ - monotonicallyIncreasingTime()); | 716 shared_timer_fire_time_ - monotonicallyIncreasingTime()); |
699 } | 717 } |
(...skipping 12 matching lines...) Expand all Loading... | |
712 worker_task_runner->OnWorkerRunLoopStarted(runLoop); | 730 worker_task_runner->OnWorkerRunLoopStarted(runLoop); |
713 } | 731 } |
714 | 732 |
715 void WebKitPlatformSupportImpl::didStopWorkerRunLoop( | 733 void WebKitPlatformSupportImpl::didStopWorkerRunLoop( |
716 const WebKit::WebWorkerRunLoop& runLoop) { | 734 const WebKit::WebWorkerRunLoop& runLoop) { |
717 WorkerTaskRunner* worker_task_runner = WorkerTaskRunner::Instance(); | 735 WorkerTaskRunner* worker_task_runner = WorkerTaskRunner::Instance(); |
718 worker_task_runner->OnWorkerRunLoopStopped(runLoop); | 736 worker_task_runner->OnWorkerRunLoopStopped(runLoop); |
719 } | 737 } |
720 | 738 |
721 } // namespace webkit_glue | 739 } // namespace webkit_glue |
OLD | NEW |