Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/pages.h" | 5 #include "vm/pages.h" |
| 6 | 6 |
| 7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "vm/compiler_stats.h" | 8 #include "vm/compiler_stats.h" |
| 9 #include "vm/gc_marker.h" | 9 #include "vm/gc_marker.h" |
| 10 #include "vm/gc_sweeper.h" | 10 #include "vm/gc_sweeper.h" |
| (...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 763 | 763 |
| 764 // Done, reset the task count. | 764 // Done, reset the task count. |
| 765 { | 765 { |
| 766 MonitorLocker ml(tasks_lock()); | 766 MonitorLocker ml(tasks_lock()); |
| 767 set_tasks(tasks() - 1); | 767 set_tasks(tasks() - 1); |
| 768 ml.Notify(); | 768 ml.Notify(); |
| 769 } | 769 } |
| 770 } | 770 } |
| 771 | 771 |
| 772 | 772 |
| 773 uword PageSpace::TryAllocateDataBump(intptr_t size, | 773 template<bool is_locked> |
|
Ivan Posva
2014/09/04 21:50:47
Please use a real parameter instead.
koda
2014/09/05 00:24:53
Done.
| |
| 774 GrowthPolicy growth_policy) { | 774 uword PageSpace::TryAllocateDataBumpInternal(intptr_t size, |
| 775 GrowthPolicy growth_policy) { | |
| 775 ASSERT(size >= kObjectAlignment); | 776 ASSERT(size >= kObjectAlignment); |
| 776 ASSERT(Utils::IsAligned(size, kObjectAlignment)); | 777 ASSERT(Utils::IsAligned(size, kObjectAlignment)); |
| 777 intptr_t remaining = bump_end_ - bump_top_; | 778 intptr_t remaining = bump_end_ - bump_top_; |
| 778 if (remaining < size) { | 779 if (remaining < size) { |
| 779 // Checking this first would be logical, but needlessly slow. | 780 // Checking this first would be logical, but needlessly slow. |
| 780 if (size >= kAllocatablePageSize) { | 781 if (size >= kAllocatablePageSize) { |
| 781 return TryAllocate(size, HeapPage::kData, growth_policy); | 782 return is_locked ? |
| 783 TryAllocateDataLocked(size, growth_policy) : | |
| 784 TryAllocate(size, HeapPage::kData, growth_policy); | |
| 782 } | 785 } |
| 783 FreeListElement* block = freelist_[HeapPage::kData].TryAllocateLarge(size); | 786 FreeListElement* block = is_locked ? |
| 787 freelist_[HeapPage::kData].TryAllocateLargeLocked(size) : | |
| 788 freelist_[HeapPage::kData].TryAllocateLarge(size); | |
| 784 if (block == NULL) { | 789 if (block == NULL) { |
| 785 // Allocating from a new page (if growth policy allows) will have the | 790 // Allocating from a new page (if growth policy allows) will have the |
| 786 // side-effect of populating the freelist with a large block. The next | 791 // side-effect of populating the freelist with a large block. The next |
| 787 // bump allocation request will have a chance to consume that block. | 792 // bump allocation request will have a chance to consume that block. |
| 788 // TODO(koda): Could take freelist lock just once instead of twice. | 793 // TODO(koda): Could take freelist lock just once instead of twice. |
| 789 return TryAllocateInFreshPage(size, | 794 return TryAllocateInFreshPage(size, |
| 790 HeapPage::kData, | 795 HeapPage::kData, |
| 791 growth_policy, | 796 growth_policy, |
| 792 /* is_locked = */ false); | 797 is_locked); |
| 793 } | 798 } |
| 794 intptr_t block_size = block->Size(); | 799 intptr_t block_size = block->Size(); |
| 800 if (remaining > 0) { | |
| 801 if (is_locked) { | |
| 802 freelist_[HeapPage::kData].FreeLocked(bump_top_, remaining); | |
| 803 } else { | |
| 804 freelist_[HeapPage::kData].Free(bump_top_, remaining); | |
| 805 } | |
| 806 } | |
| 795 bump_top_ = reinterpret_cast<uword>(block); | 807 bump_top_ = reinterpret_cast<uword>(block); |
| 796 bump_end_ = bump_top_ + block_size; | 808 bump_end_ = bump_top_ + block_size; |
| 797 remaining = block_size; | 809 remaining = block_size; |
| 798 } | 810 } |
| 799 ASSERT(remaining >= size); | 811 ASSERT(remaining >= size); |
| 800 uword result = bump_top_; | 812 uword result = bump_top_; |
| 801 bump_top_ += size; | 813 bump_top_ += size; |
| 802 usage_.used_in_words += size >> kWordSizeLog2; | 814 usage_.used_in_words += size >> kWordSizeLog2; |
| 803 remaining -= size; | 815 remaining -= size; |
| 804 if (remaining > 0) { | 816 if (remaining > 0) { |
| 805 FreeListElement::AsElement(bump_top_, remaining); | 817 FreeListElement::AsElement(bump_top_, remaining); |
| 806 } | 818 } |
| 807 return result; | 819 return result; |
| 808 } | 820 } |
| 809 | 821 |
| 810 | 822 |
| 823 uword PageSpace::TryAllocateDataBump(intptr_t size, | |
| 824 GrowthPolicy growth_policy) { | |
| 825 return TryAllocateDataBumpInternal<false>(size, growth_policy); | |
| 826 } | |
| 827 | |
| 828 | |
| 829 uword PageSpace::TryAllocateDataBumpLocked(intptr_t size, | |
| 830 GrowthPolicy growth_policy) { | |
| 831 return TryAllocateDataBumpInternal<true>(size, growth_policy); | |
| 832 } | |
| 833 | |
| 834 | |
| 835 uword PageSpace::TryAllocatePromo(intptr_t size, GrowthPolicy growth_policy) { | |
|
Ivan Posva
2014/09/04 21:50:47
TryAllocatePromoLocked
koda
2014/09/05 00:24:52
Done.
| |
| 836 FreeList* freelist = &freelist_[HeapPage::kData]; | |
| 837 uword result; | |
| 838 if (size <= freelist->SmallSizeBound()) { | |
|
Ivan Posva
2014/09/04 21:50:47
Please roll these into a single API.
koda
2014/09/05 00:24:52
Done.
| |
| 839 result = freelist->TryAllocateSmall(size); | |
| 840 if (result != 0) { | |
| 841 usage_.used_in_words += size >> kWordSizeLog2; | |
| 842 return result; | |
| 843 } | |
| 844 } | |
| 845 result = TryAllocateDataBumpLocked(size, growth_policy); | |
| 846 if (result != 0) return result; | |
| 847 return TryAllocateDataLocked(size, growth_policy); | |
| 848 } | |
| 849 | |
| 850 | |
| 811 PageSpaceController::PageSpaceController(Heap* heap, | 851 PageSpaceController::PageSpaceController(Heap* heap, |
| 812 int heap_growth_ratio, | 852 int heap_growth_ratio, |
| 813 int heap_growth_max, | 853 int heap_growth_max, |
| 814 int garbage_collection_time_ratio) | 854 int garbage_collection_time_ratio) |
| 815 : heap_(heap), | 855 : heap_(heap), |
| 816 is_enabled_(false), | 856 is_enabled_(false), |
| 817 grow_heap_(heap_growth_max / 2), | 857 grow_heap_(heap_growth_max / 2), |
| 818 heap_growth_ratio_(heap_growth_ratio), | 858 heap_growth_ratio_(heap_growth_ratio), |
| 819 desired_utilization_((100.0 - heap_growth_ratio) / 100.0), | 859 desired_utilization_((100.0 - heap_growth_ratio) / 100.0), |
| 820 heap_growth_max_(heap_growth_max), | 860 heap_growth_max_(heap_growth_max), |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 933 return 0; | 973 return 0; |
| 934 } else { | 974 } else { |
| 935 ASSERT(total_time >= gc_time); | 975 ASSERT(total_time >= gc_time); |
| 936 int result= static_cast<int>((static_cast<double>(gc_time) / | 976 int result= static_cast<int>((static_cast<double>(gc_time) / |
| 937 static_cast<double>(total_time)) * 100); | 977 static_cast<double>(total_time)) * 100); |
| 938 return result; | 978 return result; |
| 939 } | 979 } |
| 940 } | 980 } |
| 941 | 981 |
| 942 } // namespace dart | 982 } // namespace dart |
| OLD | NEW |