Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(410)

Side by Side Diff: runtime/vm/pages.h

Issue 10442073: Implement growth policy for old space using time and space signals. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address review comments Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 = 4;
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(intptr_t num_pages);
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 void Enable() {
122 is_disabled_ = false;
123 }
124
125 private:
126 bool is_disabled_;
127
128 // Heap growth control variable.
129 uword grow_heap_;
130
131 // If the garbage collector was not able to free more than heap_growth_ratio_
132 // memory, then the heap is grown. Otherwise garbage collection is performed.
133 int heap_growth_ratio_;
134
135 // Number of pages we grow.
136 int heap_growth_rate_;
137
138 // If the relative GC time stays below garbage_collection_time_ratio_
139 // garbage collection can be performed.
140 int garbage_collection_time_ratio_;
141
142 PageSpaceGarbageCollectionHistory history_;
143
144 DISALLOW_IMPLICIT_CONSTRUCTORS(PageSpaceController);
145 };
146
147
79 class PageSpace { 148 class PageSpace {
80 public: 149 public:
81 // TODO(iposva): Determine heap sizes and tune the page size accordingly. 150 // TODO(iposva): Determine heap sizes and tune the page size accordingly.
82 static const intptr_t kPageSize = 256 * KB; 151 static const intptr_t kPageSize = 256 * KB;
83 static const intptr_t kPageAlignment = kPageSize; 152 static const intptr_t kPageAlignment = kPageSize;
84 153
85 PageSpace(Heap* heap, intptr_t max_capacity, bool is_executable = false); 154 PageSpace(Heap* heap, intptr_t max_capacity, bool is_executable = false);
86 ~PageSpace(); 155 ~PageSpace();
87 156
88 uword TryAllocate(intptr_t size); 157 uword TryAllocate(intptr_t size);
(...skipping 14 matching lines...) Expand all
103 RawObject* FindObject(FindObjectVisitor* visitor) const; 172 RawObject* FindObject(FindObjectVisitor* visitor) const;
104 173
105 // Collect the garbage in the page space using mark-sweep. 174 // Collect the garbage in the page space using mark-sweep.
106 void MarkSweep(bool invoke_api_callbacks); 175 void MarkSweep(bool invoke_api_callbacks);
107 176
108 static HeapPage* PageFor(RawObject* raw_obj) { 177 static HeapPage* PageFor(RawObject* raw_obj) {
109 return reinterpret_cast<HeapPage*>( 178 return reinterpret_cast<HeapPage*>(
110 RawObject::ToAddr(raw_obj) & ~(kPageSize -1)); 179 RawObject::ToAddr(raw_obj) & ~(kPageSize -1));
111 } 180 }
112 181
182 void EnableGrowthControl() {
183 page_space_controller_.Enable();
184 }
185
113 private: 186 private:
114 static const intptr_t kAllocatablePageSize = kPageSize - sizeof(HeapPage); 187 static const intptr_t kAllocatablePageSize = kPageSize - sizeof(HeapPage);
115 188
116 void AllocatePage(); 189 void AllocatePage();
117 void FreePage(HeapPage* page, HeapPage* previous_page); 190 void FreePage(HeapPage* page, HeapPage* previous_page);
118 HeapPage* AllocateLargePage(intptr_t size); 191 HeapPage* AllocateLargePage(intptr_t size);
119 void FreeLargePage(HeapPage* page, HeapPage* previous_page); 192 void FreeLargePage(HeapPage* page, HeapPage* previous_page);
120 void FreePages(HeapPage* pages); 193 void FreePages(HeapPage* pages);
121 194
122 static intptr_t LargePageSizeFor(intptr_t size); 195 static intptr_t LargePageSizeFor(intptr_t size);
(...skipping 26 matching lines...) Expand all
149 intptr_t in_use_; 222 intptr_t in_use_;
150 223
151 // Old-gen GC cycle count. 224 // Old-gen GC cycle count.
152 int count_; 225 int count_;
153 226
154 bool is_executable_; 227 bool is_executable_;
155 228
156 // Keep track whether a MarkSweep is currently running. 229 // Keep track whether a MarkSweep is currently running.
157 bool sweeping_; 230 bool sweeping_;
158 231
232 PageSpaceController page_space_controller_;
233
159 DISALLOW_IMPLICIT_CONSTRUCTORS(PageSpace); 234 DISALLOW_IMPLICIT_CONSTRUCTORS(PageSpace);
160 }; 235 };
161 236
162 } // namespace dart 237 } // namespace dart
163 238
164 #endif // VM_PAGES_H_ 239 #endif // VM_PAGES_H_
OLDNEW
« no previous file with comments | « runtime/vm/heap.cc ('k') | runtime/vm/pages.cc » ('j') | runtime/vm/pages.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698