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

Side by Side Diff: src/heap/gc-idle-time-handler.cc

Issue 629903003: Check if there is still time before finalizing an incremental collection. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 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
« no previous file with comments | « src/heap/gc-idle-time-handler.h ('k') | src/heap/heap.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project 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 "src/heap/gc-idle-time-handler.h" 5 #include "src/heap/gc-idle-time-handler.h"
6 #include "src/heap/gc-tracer.h" 6 #include "src/heap/gc-tracer.h"
7 #include "src/utils.h" 7 #include "src/utils.h"
8 8
9 namespace v8 { 9 namespace v8 {
10 namespace internal { 10 namespace internal {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 56
57 if (marking_step_size > kMaximumMarkingStepSize) 57 if (marking_step_size > kMaximumMarkingStepSize)
58 return kMaximumMarkingStepSize; 58 return kMaximumMarkingStepSize;
59 59
60 return static_cast<size_t>(marking_step_size * kConservativeTimeRatio); 60 return static_cast<size_t>(marking_step_size * kConservativeTimeRatio);
61 } 61 }
62 62
63 63
64 size_t GCIdleTimeHandler::EstimateMarkCompactTime( 64 size_t GCIdleTimeHandler::EstimateMarkCompactTime(
65 size_t size_of_objects, size_t mark_compact_speed_in_bytes_per_ms) { 65 size_t size_of_objects, size_t mark_compact_speed_in_bytes_per_ms) {
66 // TODO(hpayer): Be more precise about the type of mark-compact event. It
67 // makes a huge difference if it is incremental or non-incremental and if
68 // compaction is happening.
66 if (mark_compact_speed_in_bytes_per_ms == 0) { 69 if (mark_compact_speed_in_bytes_per_ms == 0) {
67 mark_compact_speed_in_bytes_per_ms = kInitialConservativeMarkCompactSpeed; 70 mark_compact_speed_in_bytes_per_ms = kInitialConservativeMarkCompactSpeed;
68 } 71 }
69 size_t result = size_of_objects / mark_compact_speed_in_bytes_per_ms; 72 size_t result = size_of_objects / mark_compact_speed_in_bytes_per_ms;
70 return Min(result, kMaxMarkCompactTimeInMs); 73 return Min(result, kMaxMarkCompactTimeInMs);
71 } 74 }
72 75
73 76
74 bool GCIdleTimeHandler::DoScavenge( 77 bool GCIdleTimeHandler::ShouldDoScavenge(
75 size_t idle_time_in_ms, size_t new_space_size, size_t used_new_space_size, 78 size_t idle_time_in_ms, size_t new_space_size, size_t used_new_space_size,
76 size_t scavenge_speed_in_bytes_per_ms, 79 size_t scavenge_speed_in_bytes_per_ms,
77 size_t new_space_allocation_throughput_in_bytes_per_ms) { 80 size_t new_space_allocation_throughput_in_bytes_per_ms) {
78 size_t new_space_allocation_limit = 81 size_t new_space_allocation_limit =
79 kMaxFrameRenderingIdleTime * scavenge_speed_in_bytes_per_ms; 82 kMaxFrameRenderingIdleTime * scavenge_speed_in_bytes_per_ms;
80 83
81 // If the limit is larger than the new space size, then scavenging used to be 84 // If the limit is larger than the new space size, then scavenging used to be
82 // really fast. We can take advantage of the whole new space. 85 // really fast. We can take advantage of the whole new space.
83 if (new_space_allocation_limit > new_space_size) { 86 if (new_space_allocation_limit > new_space_size) {
84 new_space_allocation_limit = new_space_size; 87 new_space_allocation_limit = new_space_size;
(...skipping 18 matching lines...) Expand all
103 if (new_space_allocation_limit <= used_new_space_size) { 106 if (new_space_allocation_limit <= used_new_space_size) {
104 if (used_new_space_size / scavenge_speed_in_bytes_per_ms <= 107 if (used_new_space_size / scavenge_speed_in_bytes_per_ms <=
105 idle_time_in_ms) { 108 idle_time_in_ms) {
106 return true; 109 return true;
107 } 110 }
108 } 111 }
109 return false; 112 return false;
110 } 113 }
111 114
112 115
116 bool GCIdleTimeHandler::ShouldDoMarkCompact(
117 size_t idle_time_in_ms, size_t size_of_objects,
118 size_t mark_compact_speed_in_bytes_per_ms) {
119 return idle_time_in_ms >=
120 EstimateMarkCompactTime(size_of_objects,
121 mark_compact_speed_in_bytes_per_ms);
122 }
123
124
113 // The following logic is implemented by the controller: 125 // The following logic is implemented by the controller:
114 // (1) If the new space is almost full and we can affort a Scavenge or if the 126 // (1) If the new space is almost full and we can affort a Scavenge or if the
115 // next Scavenge will very likely take long, then a Scavenge is performed. 127 // next Scavenge will very likely take long, then a Scavenge is performed.
116 // (2) If there is currently no MarkCompact idle round going on, we start a 128 // (2) If there is currently no MarkCompact idle round going on, we start a
117 // new idle round if enough garbage was created or we received a context 129 // new idle round if enough garbage was created or we received a context
118 // disposal event. Otherwise we do not perform garbage collection to keep 130 // disposal event. Otherwise we do not perform garbage collection to keep
119 // system utilization low. 131 // system utilization low.
120 // (3) If incremental marking is done, we perform a full garbage collection 132 // (3) If incremental marking is done, we perform a full garbage collection
121 // if context was disposed or if we are allowed to still do full garbage 133 // if context was disposed or if we are allowed to still do full garbage
122 // collections during this idle round or if we are not allowed to start 134 // collections during this idle round or if we are not allowed to start
123 // incremental marking. Otherwise we do not perform garbage collection to 135 // incremental marking. Otherwise we do not perform garbage collection to
124 // keep system utilization low. 136 // keep system utilization low.
125 // (4) If sweeping is in progress and we received a large enough idle time 137 // (4) If sweeping is in progress and we received a large enough idle time
126 // request, we finalize sweeping here. 138 // request, we finalize sweeping here.
127 // (5) If incremental marking is in progress, we perform a marking step. Note, 139 // (5) If incremental marking is in progress, we perform a marking step. Note,
128 // that this currently may trigger a full garbage collection. 140 // that this currently may trigger a full garbage collection.
129 GCIdleTimeAction GCIdleTimeHandler::Compute(size_t idle_time_in_ms, 141 GCIdleTimeAction GCIdleTimeHandler::Compute(size_t idle_time_in_ms,
130 HeapState heap_state) { 142 HeapState heap_state) {
131 if (DoScavenge(idle_time_in_ms, heap_state.new_space_capacity, 143 if (ShouldDoScavenge(
132 heap_state.used_new_space_size, 144 idle_time_in_ms, heap_state.new_space_capacity,
133 heap_state.scavenge_speed_in_bytes_per_ms, 145 heap_state.used_new_space_size,
134 heap_state.new_space_allocation_throughput_in_bytes_per_ms)) { 146 heap_state.scavenge_speed_in_bytes_per_ms,
147 heap_state.new_space_allocation_throughput_in_bytes_per_ms)) {
135 return GCIdleTimeAction::Scavenge(); 148 return GCIdleTimeAction::Scavenge();
136 } 149 }
137 150
138 if (IsMarkCompactIdleRoundFinished()) { 151 if (IsMarkCompactIdleRoundFinished()) {
139 if (EnoughGarbageSinceLastIdleRound() || heap_state.contexts_disposed > 0) { 152 if (EnoughGarbageSinceLastIdleRound() || heap_state.contexts_disposed > 0) {
140 StartIdleRound(); 153 StartIdleRound();
141 } else { 154 } else {
142 return GCIdleTimeAction::Done(); 155 return GCIdleTimeAction::Done();
143 } 156 }
144 } 157 }
145 158
146 if (idle_time_in_ms == 0) { 159 if (idle_time_in_ms == 0) {
147 return GCIdleTimeAction::Nothing(); 160 return GCIdleTimeAction::Nothing();
148 } 161 }
149 162
150 if (heap_state.incremental_marking_stopped) { 163 if (heap_state.incremental_marking_stopped) {
151 size_t estimated_time_in_ms = 164 if (ShouldDoMarkCompact(idle_time_in_ms, heap_state.size_of_objects,
152 EstimateMarkCompactTime(heap_state.size_of_objects, 165 heap_state.mark_compact_speed_in_bytes_per_ms) ||
153 heap_state.mark_compact_speed_in_bytes_per_ms);
154 if (idle_time_in_ms >= estimated_time_in_ms ||
155 (heap_state.size_of_objects < kSmallHeapSize && 166 (heap_state.size_of_objects < kSmallHeapSize &&
156 heap_state.contexts_disposed > 0)) { 167 heap_state.contexts_disposed > 0)) {
157 // If there are no more than two GCs left in this idle round and we are 168 // If there are no more than two GCs left in this idle round and we are
158 // allowed to do a full GC, then make those GCs full in order to compact 169 // allowed to do a full GC, then make those GCs full in order to compact
159 // the code space. 170 // the code space.
160 // TODO(ulan): Once we enable code compaction for incremental marking, we 171 // TODO(ulan): Once we enable code compaction for incremental marking, we
161 // can get rid of this special case and always start incremental marking. 172 // can get rid of this special case and always start incremental marking.
162 int remaining_mark_sweeps = 173 int remaining_mark_sweeps =
163 kMaxMarkCompactsInIdleRound - mark_compacts_since_idle_round_started_; 174 kMaxMarkCompactsInIdleRound - mark_compacts_since_idle_round_started_;
164 if (heap_state.contexts_disposed > 0 || 175 if (heap_state.contexts_disposed > 0 ||
(...skipping 16 matching lines...) Expand all
181 if (heap_state.incremental_marking_stopped && 192 if (heap_state.incremental_marking_stopped &&
182 !heap_state.can_start_incremental_marking) { 193 !heap_state.can_start_incremental_marking) {
183 return GCIdleTimeAction::Nothing(); 194 return GCIdleTimeAction::Nothing();
184 } 195 }
185 size_t step_size = EstimateMarkingStepSize( 196 size_t step_size = EstimateMarkingStepSize(
186 idle_time_in_ms, heap_state.incremental_marking_speed_in_bytes_per_ms); 197 idle_time_in_ms, heap_state.incremental_marking_speed_in_bytes_per_ms);
187 return GCIdleTimeAction::IncrementalMarking(step_size); 198 return GCIdleTimeAction::IncrementalMarking(step_size);
188 } 199 }
189 } 200 }
190 } 201 }
OLDNEW
« no previous file with comments | « src/heap/gc-idle-time-handler.h ('k') | src/heap/heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698