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 #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 Loading... |
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(¤t_mem_usage)) | 664 mem_usage_cache_singleton->IsCachedValueValid(¤t_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() / 2; |
| 686 } |
| 687 |
| 688 size_t WebKitPlatformSupportImpl::highMemoryUsageMB() { |
| 689 // If memory usage is above this threshold, force GC more aggressively. |
| 690 return base::SysInfo::DalvikHeapSizeMB() * 3 / 4; |
| 691 } |
| 692 |
| 693 size_t WebKitPlatformSupportImpl::highUsageDeltaMB() { |
| 694 // If memory usage is above highMemoryUsageMB() and memory usage increased by |
| 695 // more than highUsageDeltaMB() since the last GC, then force GC. |
| 696 // Note that this limit should be greater than the amount of memory for V8 |
| 697 // internal data structures that are released on GC and reallocated during JS |
| 698 // execution (about 8MB). Otherwise, it will cause too aggressive GCs. |
| 699 return base::SysInfo::DalvikHeapSizeMB() / 8; |
| 700 } |
| 701 #endif |
| 702 |
690 void WebKitPlatformSupportImpl::SuspendSharedTimer() { | 703 void WebKitPlatformSupportImpl::SuspendSharedTimer() { |
691 ++shared_timer_suspended_; | 704 ++shared_timer_suspended_; |
692 } | 705 } |
693 | 706 |
694 void WebKitPlatformSupportImpl::ResumeSharedTimer() { | 707 void WebKitPlatformSupportImpl::ResumeSharedTimer() { |
695 // The shared timer may have fired or been adjusted while we were suspended. | 708 // The shared timer may have fired or been adjusted while we were suspended. |
696 if (--shared_timer_suspended_ == 0 && !shared_timer_.IsRunning()) { | 709 if (--shared_timer_suspended_ == 0 && !shared_timer_.IsRunning()) { |
697 setSharedTimerFireInterval( | 710 setSharedTimerFireInterval( |
698 shared_timer_fire_time_ - monotonicallyIncreasingTime()); | 711 shared_timer_fire_time_ - monotonicallyIncreasingTime()); |
699 } | 712 } |
(...skipping 12 matching lines...) Expand all Loading... |
712 worker_task_runner->OnWorkerRunLoopStarted(runLoop); | 725 worker_task_runner->OnWorkerRunLoopStarted(runLoop); |
713 } | 726 } |
714 | 727 |
715 void WebKitPlatformSupportImpl::didStopWorkerRunLoop( | 728 void WebKitPlatformSupportImpl::didStopWorkerRunLoop( |
716 const WebKit::WebWorkerRunLoop& runLoop) { | 729 const WebKit::WebWorkerRunLoop& runLoop) { |
717 WorkerTaskRunner* worker_task_runner = WorkerTaskRunner::Instance(); | 730 WorkerTaskRunner* worker_task_runner = WorkerTaskRunner::Instance(); |
718 worker_task_runner->OnWorkerRunLoopStopped(runLoop); | 731 worker_task_runner->OnWorkerRunLoopStopped(runLoop); |
719 } | 732 } |
720 | 733 |
721 } // namespace webkit_glue | 734 } // namespace webkit_glue |
OLD | NEW |