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 uword PageSpace::TryAllocateDataBumpInternal(intptr_t size, |
774 GrowthPolicy growth_policy) { | 774 GrowthPolicy growth_policy, |
| 775 bool is_locked) { |
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(size, growth_policy, false); |
| 826 } |
| 827 |
| 828 |
| 829 uword PageSpace::TryAllocateDataBumpLocked(intptr_t size, |
| 830 GrowthPolicy growth_policy) { |
| 831 return TryAllocateDataBumpInternal(size, growth_policy, true); |
| 832 } |
| 833 |
| 834 |
| 835 uword PageSpace::TryAllocatePromoLocked(intptr_t size, |
| 836 GrowthPolicy growth_policy) { |
| 837 FreeList* freelist = &freelist_[HeapPage::kData]; |
| 838 uword result = freelist->TryAllocateSmallLocked(size); |
| 839 if (result != 0) { |
| 840 usage_.used_in_words += size >> kWordSizeLog2; |
| 841 return result; |
| 842 } |
| 843 result = TryAllocateDataBumpLocked(size, growth_policy); |
| 844 if (result != 0) return result; |
| 845 return TryAllocateDataLocked(size, growth_policy); |
| 846 } |
| 847 |
| 848 |
811 PageSpaceController::PageSpaceController(Heap* heap, | 849 PageSpaceController::PageSpaceController(Heap* heap, |
812 int heap_growth_ratio, | 850 int heap_growth_ratio, |
813 int heap_growth_max, | 851 int heap_growth_max, |
814 int garbage_collection_time_ratio) | 852 int garbage_collection_time_ratio) |
815 : heap_(heap), | 853 : heap_(heap), |
816 is_enabled_(false), | 854 is_enabled_(false), |
817 grow_heap_(heap_growth_max / 2), | 855 grow_heap_(heap_growth_max / 2), |
818 heap_growth_ratio_(heap_growth_ratio), | 856 heap_growth_ratio_(heap_growth_ratio), |
819 desired_utilization_((100.0 - heap_growth_ratio) / 100.0), | 857 desired_utilization_((100.0 - heap_growth_ratio) / 100.0), |
820 heap_growth_max_(heap_growth_max), | 858 heap_growth_max_(heap_growth_max), |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 return 0; | 971 return 0; |
934 } else { | 972 } else { |
935 ASSERT(total_time >= gc_time); | 973 ASSERT(total_time >= gc_time); |
936 int result= static_cast<int>((static_cast<double>(gc_time) / | 974 int result= static_cast<int>((static_cast<double>(gc_time) / |
937 static_cast<double>(total_time)) * 100); | 975 static_cast<double>(total_time)) * 100); |
938 return result; | 976 return result; |
939 } | 977 } |
940 } | 978 } |
941 | 979 |
942 } // namespace dart | 980 } // namespace dart |
OLD | NEW |