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