Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 #ifndef VM_PAGES_H_ | 5 #ifndef VM_PAGES_H_ |
| 6 #define VM_PAGES_H_ | 6 #define VM_PAGES_H_ |
| 7 | 7 |
| 8 #include "vm/freelist.h" | 8 #include "vm/freelist.h" |
| 9 #include "vm/globals.h" | 9 #include "vm/globals.h" |
| 10 #include "vm/virtual_memory.h" | 10 #include "vm/virtual_memory.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 uword used_; | 69 uword used_; |
| 70 uword top_; | 70 uword top_; |
| 71 | 71 |
| 72 friend class PageSpace; | 72 friend class PageSpace; |
| 73 | 73 |
| 74 DISALLOW_ALLOCATION(); | 74 DISALLOW_ALLOCATION(); |
| 75 DISALLOW_IMPLICIT_CONSTRUCTORS(HeapPage); | 75 DISALLOW_IMPLICIT_CONSTRUCTORS(HeapPage); |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 | 78 |
| 79 // The history holds the timing information of the last garbage collection | |
| 80 // runs. | |
| 81 class PageSpaceGarbageCollectionHistory { | |
| 82 public: | |
| 83 PageSpaceGarbageCollectionHistory(); | |
| 84 ~PageSpaceGarbageCollectionHistory() {} | |
| 85 | |
| 86 void AddGarbageCollectionTime(uint64_t start, uint64_t end); | |
| 87 | |
| 88 int GarbageCollectionTimeFraction(); | |
| 89 | |
| 90 private: | |
| 91 static const uint32_t kHistoryLength = 16; | |
|
Ivan Posva
2012/05/29 23:27:37
I have the feeling (no data) that this longish his
cshapiro
2012/05/30 17:56:24
I have set this back to 4. I think 4 is too short
| |
| 92 uint64_t start_[kHistoryLength]; | |
| 93 uint64_t end_[kHistoryLength]; | |
| 94 uint32_t index_; | |
| 95 | |
| 96 DISALLOW_ALLOCATION(); | |
| 97 DISALLOW_COPY_AND_ASSIGN(PageSpaceGarbageCollectionHistory); | |
| 98 }; | |
| 99 | |
| 100 | |
| 101 // If GC is able to reclaim more than heap_growth_ratio (in percent) memory | |
| 102 // and if the relative GC time is below a given threshold, | |
| 103 // then the heap is not grown when the next GC decision is made. | |
| 104 // PageSpaceController controls the heap size. | |
| 105 class PageSpaceController { | |
| 106 public: | |
| 107 PageSpaceController(int heap_growth_ratio, | |
| 108 int heap_growth_rate, | |
| 109 int garbage_collection_time_ratio); | |
| 110 ~PageSpaceController(); | |
| 111 | |
| 112 bool CanGrowPageSpace(); | |
|
Ivan Posva
2012/05/29 23:27:37
Maybe this should be dependent on the amount of me
cshapiro
2012/05/30 17:56:24
Done.
| |
| 113 | |
| 114 // A garbage collection is considered as successful if more than | |
| 115 // heap_growth_ratio % of memory got deallocated by the garbage collector. | |
| 116 // In this case garbage collection will be performed next time. Otherwise | |
| 117 // the heap will grow. | |
| 118 void EvaluateGarbageCollection(size_t in_use_before, size_t in_use_after, | |
| 119 int64_t start, int64_t end); | |
| 120 | |
| 121 private: | |
| 122 // Heap growth control variable. | |
| 123 uword grow_heap_; | |
| 124 | |
| 125 // If the garbage collector was not able to free more than heap_growth_ratio_ | |
| 126 // memory, then the heap is grown. Otherwise garbage collection is performed. | |
| 127 int heap_growth_ratio_; | |
| 128 | |
| 129 // Number of pages we grow. | |
| 130 int heap_growth_rate_; | |
| 131 | |
| 132 // If the relative GC time stays below garbage_collection_time_ratio_ | |
| 133 // garbage collection can be performed. | |
| 134 int garbage_collection_time_ratio_; | |
| 135 | |
| 136 PageSpaceGarbageCollectionHistory history_; | |
| 137 | |
| 138 DISALLOW_IMPLICIT_CONSTRUCTORS(PageSpaceController); | |
| 139 }; | |
| 140 | |
| 141 | |
| 79 class PageSpace { | 142 class PageSpace { |
| 80 public: | 143 public: |
| 81 // TODO(iposva): Determine heap sizes and tune the page size accordingly. | 144 // TODO(iposva): Determine heap sizes and tune the page size accordingly. |
| 82 static const intptr_t kPageSize = 256 * KB; | 145 static const intptr_t kPageSize = 256 * KB; |
| 83 static const intptr_t kPageAlignment = kPageSize; | 146 static const intptr_t kPageAlignment = kPageSize; |
| 84 | 147 |
| 85 PageSpace(Heap* heap, intptr_t max_capacity, bool is_executable = false); | 148 PageSpace(Heap* heap, |
|
Ivan Posva
2012/05/29 23:27:37
?
cshapiro
2012/05/30 17:56:24
Noise. Done.
| |
| 149 intptr_t max_capacity, | |
| 150 bool is_executable = false); | |
| 86 ~PageSpace(); | 151 ~PageSpace(); |
| 87 | 152 |
| 88 uword TryAllocate(intptr_t size); | 153 uword TryAllocate(intptr_t size); |
| 89 | 154 |
| 90 intptr_t in_use() const { return in_use_; } | 155 intptr_t in_use() const { return in_use_; } |
| 91 intptr_t capacity() const { return capacity_; } | 156 intptr_t capacity() const { return capacity_; } |
| 92 | 157 |
| 93 bool Contains(uword addr) const; | 158 bool Contains(uword addr) const; |
| 94 bool IsValidAddress(uword addr) const { | 159 bool IsValidAddress(uword addr) const { |
| 95 return Contains(addr); | 160 return Contains(addr); |
| 96 } | 161 } |
| 97 static bool IsPageAllocatableSize(intptr_t size) { | 162 static bool IsPageAllocatableSize(intptr_t size) { |
| 98 return size <= kAllocatablePageSize; | 163 return size <= kAllocatablePageSize; |
| 99 } | 164 } |
| 100 | 165 |
| 101 void VisitObjectPointers(ObjectPointerVisitor* visitor) const; | 166 void VisitObjectPointers(ObjectPointerVisitor* visitor) const; |
| 102 | 167 |
| 103 RawObject* FindObject(FindObjectVisitor* visitor) const; | 168 RawObject* FindObject(FindObjectVisitor* visitor) const; |
| 104 | 169 |
| 105 // Collect the garbage in the page space using mark-sweep. | 170 // Collect the garbage in the page space using mark-sweep. |
| 106 void MarkSweep(bool invoke_api_callbacks); | 171 void MarkSweep(bool invoke_api_callbacks); |
| 107 | 172 |
| 108 static HeapPage* PageFor(RawObject* raw_obj) { | 173 static HeapPage* PageFor(RawObject* raw_obj) { |
| 109 return reinterpret_cast<HeapPage*>( | 174 return reinterpret_cast<HeapPage*>( |
| 110 RawObject::ToAddr(raw_obj) & ~(kPageSize -1)); | 175 RawObject::ToAddr(raw_obj) & ~(kPageSize -1)); |
| 111 } | 176 } |
| 112 | 177 |
| 178 void EnableGrowthControl() { | |
| 179 is_growth_controlled_ = true; | |
| 180 } | |
| 181 | |
| 113 private: | 182 private: |
| 114 static const intptr_t kAllocatablePageSize = kPageSize - sizeof(HeapPage); | 183 static const intptr_t kAllocatablePageSize = kPageSize - sizeof(HeapPage); |
| 115 | 184 |
| 116 void AllocatePage(); | 185 void AllocatePage(); |
| 117 void FreePage(HeapPage* page, HeapPage* previous_page); | 186 void FreePage(HeapPage* page, HeapPage* previous_page); |
| 118 HeapPage* AllocateLargePage(intptr_t size); | 187 HeapPage* AllocateLargePage(intptr_t size); |
| 119 void FreeLargePage(HeapPage* page, HeapPage* previous_page); | 188 void FreeLargePage(HeapPage* page, HeapPage* previous_page); |
| 120 void FreePages(HeapPage* pages); | 189 void FreePages(HeapPage* pages); |
| 121 | 190 |
| 122 static intptr_t LargePageSizeFor(intptr_t size); | 191 static intptr_t LargePageSizeFor(intptr_t size); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 149 intptr_t in_use_; | 218 intptr_t in_use_; |
| 150 | 219 |
| 151 // Old-gen GC cycle count. | 220 // Old-gen GC cycle count. |
| 152 int count_; | 221 int count_; |
| 153 | 222 |
| 154 bool is_executable_; | 223 bool is_executable_; |
| 155 | 224 |
| 156 // Keep track whether a MarkSweep is currently running. | 225 // Keep track whether a MarkSweep is currently running. |
| 157 bool sweeping_; | 226 bool sweeping_; |
| 158 | 227 |
| 228 // True if the page space controller regulates heap growth. | |
| 229 bool is_growth_controlled_; | |
|
Ivan Posva
2012/05/29 23:27:37
How about tracking this in the controller itself?
cshapiro
2012/05/30 17:56:24
Sure. Done.
| |
| 230 | |
| 231 PageSpaceController page_space_controller_; | |
| 232 | |
| 159 DISALLOW_IMPLICIT_CONSTRUCTORS(PageSpace); | 233 DISALLOW_IMPLICIT_CONSTRUCTORS(PageSpace); |
| 160 }; | 234 }; |
| 161 | 235 |
| 162 } // namespace dart | 236 } // namespace dart |
| 163 | 237 |
| 164 #endif // VM_PAGES_H_ | 238 #endif // VM_PAGES_H_ |
| OLD | NEW |