16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26
27 #include "gc/shared/blockOffsetTable.inline.hpp"
28 #include "gc/shared/cardGeneration.inline.hpp"
29 #include "gc/shared/cardTableRS.hpp"
30 #include "gc/shared/gcLocker.hpp"
31 #include "gc/shared/genOopClosures.inline.hpp"
32 #include "gc/shared/generationSpec.hpp"
33 #include "gc/shared/space.inline.hpp"
34 #include "memory/iterator.hpp"
35 #include "memory/memRegion.hpp"
36 #include "runtime/java.hpp"
37
38 CardGeneration::CardGeneration(ReservedSpace rs,
39 size_t initial_byte_size,
40 CardTableRS* remset) :
41 Generation(rs, initial_byte_size), _rs(remset),
42 _shrink_factor(0), _min_heap_delta_bytes(), _capacity_at_prologue(),
43 _used_at_prologue()
44 {
45 HeapWord* start = (HeapWord*)rs.base();
46 size_t reserved_byte_size = rs.size();
47 assert((uintptr_t(start) & 3) == 0, "bad alignment");
48 assert((reserved_byte_size & 3) == 0, "bad alignment");
49 MemRegion reserved_mr(start, heap_word_size(reserved_byte_size));
50 _bts = new BlockOffsetSharedArray(reserved_mr,
51 heap_word_size(initial_byte_size));
52 MemRegion committed_mr(start, heap_word_size(initial_byte_size));
53 _rs->resize_covered_region(committed_mr);
54 if (_bts == NULL) {
55 vm_exit_during_initialization("Could not allocate a BlockOffsetArray");
79 MemRegion mr(space()->bottom(), new_word_size);
80 // Expand card table
81 GenCollectedHeap::heap()->barrier_set()->resize_covered_region(mr);
82 // Expand shared block offset array
83 _bts->resize(new_word_size);
84
85 // Fix for bug #4668531
86 if (ZapUnusedHeapArea) {
87 MemRegion mangle_region(space()->end(),
88 (HeapWord*)_virtual_space.high());
89 SpaceMangler::mangle_region(mangle_region);
90 }
91
92 // Expand space -- also expands space's BOT
93 // (which uses (part of) shared array above)
94 space()->set_end((HeapWord*)_virtual_space.high());
95
96 // update the space and generation capacity counters
97 update_counters();
98
99 if (Verbose && PrintGC) {
100 size_t new_mem_size = _virtual_space.committed_size();
101 size_t old_mem_size = new_mem_size - bytes;
102 gclog_or_tty->print_cr("Expanding %s from " SIZE_FORMAT "K by "
103 SIZE_FORMAT "K to " SIZE_FORMAT "K",
104 name(), old_mem_size/K, bytes/K, new_mem_size/K);
105 }
106 }
107 return result;
108 }
109
110 bool CardGeneration::expand(size_t bytes, size_t expand_bytes) {
111 assert_locked_or_safepoint(Heap_lock);
112 if (bytes == 0) {
113 return true; // That's what grow_by(0) would return
114 }
115 size_t aligned_bytes = ReservedSpace::page_align_size_up(bytes);
116 if (aligned_bytes == 0){
117 // The alignment caused the number of bytes to wrap. An expand_by(0) will
118 // return true with the implication that an expansion was done when it
119 // was not. A call to expand implies a best effort to expand by "bytes"
120 // but not a guarantee. Align down to give a best effort. This is likely
121 // the most that the generation can expand since it has some capacity to
122 // start with.
123 aligned_bytes = ReservedSpace::page_align_size_down(bytes);
124 }
125 size_t aligned_expand_bytes = ReservedSpace::page_align_size_up(expand_bytes);
126 bool success = false;
127 if (aligned_expand_bytes > aligned_bytes) {
128 success = grow_by(aligned_expand_bytes);
129 }
130 if (!success) {
131 success = grow_by(aligned_bytes);
132 }
133 if (!success) {
134 success = grow_to_reserved();
135 }
136 if (PrintGC && Verbose) {
137 if (success && GC_locker::is_active_and_needs_gc()) {
138 gclog_or_tty->print_cr("Garbage collection disabled, expanded heap instead");
139 }
140 }
141
142 return success;
143 }
144
145 bool CardGeneration::grow_to_reserved() {
146 assert_correct_size_change_locking();
147 bool success = true;
148 const size_t remaining_bytes = _virtual_space.uncommitted_size();
149 if (remaining_bytes > 0) {
150 success = grow_by(remaining_bytes);
151 DEBUG_ONLY(if (!success) warning("grow to reserved failed");)
152 }
153 return success;
154 }
155
156 void CardGeneration::shrink(size_t bytes) {
157 assert_correct_size_change_locking();
158
159 size_t size = ReservedSpace::page_align_size_down(bytes);
160 if (size == 0) {
161 return;
162 }
163
164 // Shrink committed space
165 _virtual_space.shrink_by(size);
166 // Shrink space; this also shrinks the space's BOT
167 space()->set_end((HeapWord*) _virtual_space.high());
168 size_t new_word_size = heap_word_size(space()->capacity());
169 // Shrink the shared block offset array
170 _bts->resize(new_word_size);
171 MemRegion mr(space()->bottom(), new_word_size);
172 // Shrink the card table
173 GenCollectedHeap::heap()->barrier_set()->resize_covered_region(mr);
174
175 if (Verbose && PrintGC) {
176 size_t new_mem_size = _virtual_space.committed_size();
177 size_t old_mem_size = new_mem_size + size;
178 gclog_or_tty->print_cr("Shrinking %s from " SIZE_FORMAT "K to " SIZE_FORMAT "K",
179 name(), old_mem_size/K, new_mem_size/K);
180 }
181 }
182
183 // No young generation references, clear this generation's cards.
184 void CardGeneration::clear_remembered_set() {
185 _rs->clear(reserved());
186 }
187
188 // Objects in this generation may have moved, invalidate this
189 // generation's cards.
190 void CardGeneration::invalidate_remembered_set() {
191 _rs->invalidate(used_region());
192 }
193
194 void CardGeneration::compute_new_size() {
195 assert(_shrink_factor <= 100, "invalid shrink factor");
196 size_t current_shrink_factor = _shrink_factor;
197 _shrink_factor = 0;
198
199 // We don't have floating point command-line arguments
200 // Note: argument processing ensures that MinHeapFreeRatio < 100.
201 const double minimum_free_percentage = MinHeapFreeRatio / 100.0;
202 const double maximum_used_percentage = 1.0 - minimum_free_percentage;
203
204 // Compute some numbers about the state of the heap.
205 const size_t used_after_gc = used();
206 const size_t capacity_after_gc = capacity();
207
208 const double min_tmp = used_after_gc / maximum_used_percentage;
209 size_t minimum_desired_capacity = (size_t)MIN2(min_tmp, double(max_uintx));
210 // Don't shrink less than the initial generation size
211 minimum_desired_capacity = MAX2(minimum_desired_capacity, initial_size());
212 assert(used_after_gc <= minimum_desired_capacity, "sanity check");
213
214 if (PrintGC && Verbose) {
215 const size_t free_after_gc = free();
216 const double free_percentage = ((double)free_after_gc) / capacity_after_gc;
217 gclog_or_tty->print_cr("TenuredGeneration::compute_new_size: ");
218 gclog_or_tty->print_cr(" "
219 " minimum_free_percentage: %6.2f"
220 " maximum_used_percentage: %6.2f",
221 minimum_free_percentage,
222 maximum_used_percentage);
223 gclog_or_tty->print_cr(" "
224 " free_after_gc : %6.1fK"
225 " used_after_gc : %6.1fK"
226 " capacity_after_gc : %6.1fK",
227 free_after_gc / (double) K,
228 used_after_gc / (double) K,
229 capacity_after_gc / (double) K);
230 gclog_or_tty->print_cr(" "
231 " free_percentage: %6.2f",
232 free_percentage);
233 }
234
235 if (capacity_after_gc < minimum_desired_capacity) {
236 // If we have less free space than we want then expand
237 size_t expand_bytes = minimum_desired_capacity - capacity_after_gc;
238 // Don't expand unless it's significant
239 if (expand_bytes >= _min_heap_delta_bytes) {
240 expand(expand_bytes, 0); // safe if expansion fails
241 }
242 if (PrintGC && Verbose) {
243 gclog_or_tty->print_cr(" expanding:"
244 " minimum_desired_capacity: %6.1fK"
245 " expand_bytes: %6.1fK"
246 " _min_heap_delta_bytes: %6.1fK",
247 minimum_desired_capacity / (double) K,
248 expand_bytes / (double) K,
249 _min_heap_delta_bytes / (double) K);
250 }
251 return;
252 }
253
254 // No expansion, now see if we want to shrink
255 size_t shrink_bytes = 0;
256 // We would never want to shrink more than this
257 size_t max_shrink_bytes = capacity_after_gc - minimum_desired_capacity;
258
259 if (MaxHeapFreeRatio < 100) {
260 const double maximum_free_percentage = MaxHeapFreeRatio / 100.0;
261 const double minimum_used_percentage = 1.0 - maximum_free_percentage;
262 const double max_tmp = used_after_gc / minimum_used_percentage;
263 size_t maximum_desired_capacity = (size_t)MIN2(max_tmp, double(max_uintx));
264 maximum_desired_capacity = MAX2(maximum_desired_capacity, initial_size());
265 if (PrintGC && Verbose) {
266 gclog_or_tty->print_cr(" "
267 " maximum_free_percentage: %6.2f"
268 " minimum_used_percentage: %6.2f",
269 maximum_free_percentage,
270 minimum_used_percentage);
271 gclog_or_tty->print_cr(" "
272 " _capacity_at_prologue: %6.1fK"
273 " minimum_desired_capacity: %6.1fK"
274 " maximum_desired_capacity: %6.1fK",
275 _capacity_at_prologue / (double) K,
276 minimum_desired_capacity / (double) K,
277 maximum_desired_capacity / (double) K);
278 }
279 assert(minimum_desired_capacity <= maximum_desired_capacity,
280 "sanity check");
281
282 if (capacity_after_gc > maximum_desired_capacity) {
283 // Capacity too large, compute shrinking size
284 shrink_bytes = capacity_after_gc - maximum_desired_capacity;
285 // We don't want shrink all the way back to initSize if people call
286 // System.gc(), because some programs do that between "phases" and then
287 // we'd just have to grow the heap up again for the next phase. So we
288 // damp the shrinking: 0% on the first call, 10% on the second call, 40%
289 // on the third call, and 100% by the fourth call. But if we recompute
290 // size without shrinking, it goes back to 0%.
291 shrink_bytes = shrink_bytes / 100 * current_shrink_factor;
292 assert(shrink_bytes <= max_shrink_bytes, "invalid shrink size");
293 if (current_shrink_factor == 0) {
294 _shrink_factor = 10;
295 } else {
296 _shrink_factor = MIN2(current_shrink_factor * 4, (size_t) 100);
297 }
298 if (PrintGC && Verbose) {
299 gclog_or_tty->print_cr(" "
300 " shrinking:"
301 " initSize: %.1fK"
302 " maximum_desired_capacity: %.1fK",
303 initial_size() / (double) K,
304 maximum_desired_capacity / (double) K);
305 gclog_or_tty->print_cr(" "
306 " shrink_bytes: %.1fK"
307 " current_shrink_factor: " SIZE_FORMAT
308 " new shrink factor: " SIZE_FORMAT
309 " _min_heap_delta_bytes: %.1fK",
310 shrink_bytes / (double) K,
311 current_shrink_factor,
312 _shrink_factor,
313 _min_heap_delta_bytes / (double) K);
314 }
315 }
316 }
317
318 if (capacity_after_gc > _capacity_at_prologue) {
319 // We might have expanded for promotions, in which case we might want to
320 // take back that expansion if there's room after GC. That keeps us from
321 // stretching the heap with promotions when there's plenty of room.
322 size_t expansion_for_promotion = capacity_after_gc - _capacity_at_prologue;
323 expansion_for_promotion = MIN2(expansion_for_promotion, max_shrink_bytes);
324 // We have two shrinking computations, take the largest
325 shrink_bytes = MAX2(shrink_bytes, expansion_for_promotion);
326 assert(shrink_bytes <= max_shrink_bytes, "invalid shrink size");
327 if (PrintGC && Verbose) {
328 gclog_or_tty->print_cr(" "
329 " aggressive shrinking:"
330 " _capacity_at_prologue: %.1fK"
331 " capacity_after_gc: %.1fK"
332 " expansion_for_promotion: %.1fK"
333 " shrink_bytes: %.1fK",
334 capacity_after_gc / (double) K,
335 _capacity_at_prologue / (double) K,
336 expansion_for_promotion / (double) K,
337 shrink_bytes / (double) K);
338 }
339 }
340 // Don't shrink unless it's significant
341 if (shrink_bytes >= _min_heap_delta_bytes) {
342 shrink(shrink_bytes);
343 }
344 }
345
346 // Currently nothing to do.
347 void CardGeneration::prepare_for_verify() {}
348
349 void CardGeneration::space_iterate(SpaceClosure* blk,
350 bool usedOnly) {
351 blk->do_space(space());
352 }
353
354 void CardGeneration::younger_refs_iterate(OopsInGenClosure* blk, uint n_threads) {
355 blk->set_generation(this);
356 younger_refs_in_space_iterate(space(), blk, n_threads);
357 blk->reset_generation();
358 }
|
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26
27 #include "gc/shared/blockOffsetTable.inline.hpp"
28 #include "gc/shared/cardGeneration.inline.hpp"
29 #include "gc/shared/cardTableRS.hpp"
30 #include "gc/shared/gcLocker.hpp"
31 #include "gc/shared/genOopClosures.inline.hpp"
32 #include "gc/shared/generationSpec.hpp"
33 #include "gc/shared/space.inline.hpp"
34 #include "memory/iterator.hpp"
35 #include "memory/memRegion.hpp"
36 #include "logging/log.hpp"
37 #include "runtime/java.hpp"
38
39 CardGeneration::CardGeneration(ReservedSpace rs,
40 size_t initial_byte_size,
41 CardTableRS* remset) :
42 Generation(rs, initial_byte_size), _rs(remset),
43 _shrink_factor(0), _min_heap_delta_bytes(), _capacity_at_prologue(),
44 _used_at_prologue()
45 {
46 HeapWord* start = (HeapWord*)rs.base();
47 size_t reserved_byte_size = rs.size();
48 assert((uintptr_t(start) & 3) == 0, "bad alignment");
49 assert((reserved_byte_size & 3) == 0, "bad alignment");
50 MemRegion reserved_mr(start, heap_word_size(reserved_byte_size));
51 _bts = new BlockOffsetSharedArray(reserved_mr,
52 heap_word_size(initial_byte_size));
53 MemRegion committed_mr(start, heap_word_size(initial_byte_size));
54 _rs->resize_covered_region(committed_mr);
55 if (_bts == NULL) {
56 vm_exit_during_initialization("Could not allocate a BlockOffsetArray");
80 MemRegion mr(space()->bottom(), new_word_size);
81 // Expand card table
82 GenCollectedHeap::heap()->barrier_set()->resize_covered_region(mr);
83 // Expand shared block offset array
84 _bts->resize(new_word_size);
85
86 // Fix for bug #4668531
87 if (ZapUnusedHeapArea) {
88 MemRegion mangle_region(space()->end(),
89 (HeapWord*)_virtual_space.high());
90 SpaceMangler::mangle_region(mangle_region);
91 }
92
93 // Expand space -- also expands space's BOT
94 // (which uses (part of) shared array above)
95 space()->set_end((HeapWord*)_virtual_space.high());
96
97 // update the space and generation capacity counters
98 update_counters();
99
100 size_t new_mem_size = _virtual_space.committed_size();
101 size_t old_mem_size = new_mem_size - bytes;
102 log_trace(gc, heap)("Expanding %s from " SIZE_FORMAT "K by " SIZE_FORMAT "K to " SIZE_FORMAT "K",
103 name(), old_mem_size/K, bytes/K, new_mem_size/K);
104 }
105 return result;
106 }
107
108 bool CardGeneration::expand(size_t bytes, size_t expand_bytes) {
109 assert_locked_or_safepoint(Heap_lock);
110 if (bytes == 0) {
111 return true; // That's what grow_by(0) would return
112 }
113 size_t aligned_bytes = ReservedSpace::page_align_size_up(bytes);
114 if (aligned_bytes == 0){
115 // The alignment caused the number of bytes to wrap. An expand_by(0) will
116 // return true with the implication that an expansion was done when it
117 // was not. A call to expand implies a best effort to expand by "bytes"
118 // but not a guarantee. Align down to give a best effort. This is likely
119 // the most that the generation can expand since it has some capacity to
120 // start with.
121 aligned_bytes = ReservedSpace::page_align_size_down(bytes);
122 }
123 size_t aligned_expand_bytes = ReservedSpace::page_align_size_up(expand_bytes);
124 bool success = false;
125 if (aligned_expand_bytes > aligned_bytes) {
126 success = grow_by(aligned_expand_bytes);
127 }
128 if (!success) {
129 success = grow_by(aligned_bytes);
130 }
131 if (!success) {
132 success = grow_to_reserved();
133 }
134 if (success && GC_locker::is_active_and_needs_gc()) {
135 log_trace(gc, heap)("Garbage collection disabled, expanded heap instead");
136 }
137
138 return success;
139 }
140
141 bool CardGeneration::grow_to_reserved() {
142 assert_correct_size_change_locking();
143 bool success = true;
144 const size_t remaining_bytes = _virtual_space.uncommitted_size();
145 if (remaining_bytes > 0) {
146 success = grow_by(remaining_bytes);
147 DEBUG_ONLY(if (!success) warning("grow to reserved failed");)
148 }
149 return success;
150 }
151
152 void CardGeneration::shrink(size_t bytes) {
153 assert_correct_size_change_locking();
154
155 size_t size = ReservedSpace::page_align_size_down(bytes);
156 if (size == 0) {
157 return;
158 }
159
160 // Shrink committed space
161 _virtual_space.shrink_by(size);
162 // Shrink space; this also shrinks the space's BOT
163 space()->set_end((HeapWord*) _virtual_space.high());
164 size_t new_word_size = heap_word_size(space()->capacity());
165 // Shrink the shared block offset array
166 _bts->resize(new_word_size);
167 MemRegion mr(space()->bottom(), new_word_size);
168 // Shrink the card table
169 GenCollectedHeap::heap()->barrier_set()->resize_covered_region(mr);
170
171 size_t new_mem_size = _virtual_space.committed_size();
172 size_t old_mem_size = new_mem_size + size;
173 log_trace(gc, heap)("Shrinking %s from " SIZE_FORMAT "K to " SIZE_FORMAT "K",
174 name(), old_mem_size/K, new_mem_size/K);
175 }
176
177 // No young generation references, clear this generation's cards.
178 void CardGeneration::clear_remembered_set() {
179 _rs->clear(reserved());
180 }
181
182 // Objects in this generation may have moved, invalidate this
183 // generation's cards.
184 void CardGeneration::invalidate_remembered_set() {
185 _rs->invalidate(used_region());
186 }
187
188 void CardGeneration::compute_new_size() {
189 assert(_shrink_factor <= 100, "invalid shrink factor");
190 size_t current_shrink_factor = _shrink_factor;
191 _shrink_factor = 0;
192
193 // We don't have floating point command-line arguments
194 // Note: argument processing ensures that MinHeapFreeRatio < 100.
195 const double minimum_free_percentage = MinHeapFreeRatio / 100.0;
196 const double maximum_used_percentage = 1.0 - minimum_free_percentage;
197
198 // Compute some numbers about the state of the heap.
199 const size_t used_after_gc = used();
200 const size_t capacity_after_gc = capacity();
201
202 const double min_tmp = used_after_gc / maximum_used_percentage;
203 size_t minimum_desired_capacity = (size_t)MIN2(min_tmp, double(max_uintx));
204 // Don't shrink less than the initial generation size
205 minimum_desired_capacity = MAX2(minimum_desired_capacity, initial_size());
206 assert(used_after_gc <= minimum_desired_capacity, "sanity check");
207
208 const size_t free_after_gc = free();
209 const double free_percentage = ((double)free_after_gc) / capacity_after_gc;
210 log_trace(gc, heap)("TenuredGeneration::compute_new_size:");
211 log_trace(gc, heap)(" minimum_free_percentage: %6.2f maximum_used_percentage: %6.2f",
212 minimum_free_percentage,
213 maximum_used_percentage);
214 log_trace(gc, heap)(" free_after_gc : %6.1fK used_after_gc : %6.1fK capacity_after_gc : %6.1fK",
215 free_after_gc / (double) K,
216 used_after_gc / (double) K,
217 capacity_after_gc / (double) K);
218 log_trace(gc, heap)(" free_percentage: %6.2f", free_percentage);
219
220 if (capacity_after_gc < minimum_desired_capacity) {
221 // If we have less free space than we want then expand
222 size_t expand_bytes = minimum_desired_capacity - capacity_after_gc;
223 // Don't expand unless it's significant
224 if (expand_bytes >= _min_heap_delta_bytes) {
225 expand(expand_bytes, 0); // safe if expansion fails
226 }
227 log_trace(gc, heap)(" expanding: minimum_desired_capacity: %6.1fK expand_bytes: %6.1fK _min_heap_delta_bytes: %6.1fK",
228 minimum_desired_capacity / (double) K,
229 expand_bytes / (double) K,
230 _min_heap_delta_bytes / (double) K);
231 return;
232 }
233
234 // No expansion, now see if we want to shrink
235 size_t shrink_bytes = 0;
236 // We would never want to shrink more than this
237 size_t max_shrink_bytes = capacity_after_gc - minimum_desired_capacity;
238
239 if (MaxHeapFreeRatio < 100) {
240 const double maximum_free_percentage = MaxHeapFreeRatio / 100.0;
241 const double minimum_used_percentage = 1.0 - maximum_free_percentage;
242 const double max_tmp = used_after_gc / minimum_used_percentage;
243 size_t maximum_desired_capacity = (size_t)MIN2(max_tmp, double(max_uintx));
244 maximum_desired_capacity = MAX2(maximum_desired_capacity, initial_size());
245 log_trace(gc, heap)(" maximum_free_percentage: %6.2f minimum_used_percentage: %6.2f",
246 maximum_free_percentage, minimum_used_percentage);
247 log_trace(gc, heap)(" _capacity_at_prologue: %6.1fK minimum_desired_capacity: %6.1fK maximum_desired_capacity: %6.1fK",
248 _capacity_at_prologue / (double) K,
249 minimum_desired_capacity / (double) K,
250 maximum_desired_capacity / (double) K);
251 assert(minimum_desired_capacity <= maximum_desired_capacity,
252 "sanity check");
253
254 if (capacity_after_gc > maximum_desired_capacity) {
255 // Capacity too large, compute shrinking size
256 shrink_bytes = capacity_after_gc - maximum_desired_capacity;
257 // We don't want shrink all the way back to initSize if people call
258 // System.gc(), because some programs do that between "phases" and then
259 // we'd just have to grow the heap up again for the next phase. So we
260 // damp the shrinking: 0% on the first call, 10% on the second call, 40%
261 // on the third call, and 100% by the fourth call. But if we recompute
262 // size without shrinking, it goes back to 0%.
263 shrink_bytes = shrink_bytes / 100 * current_shrink_factor;
264 assert(shrink_bytes <= max_shrink_bytes, "invalid shrink size");
265 if (current_shrink_factor == 0) {
266 _shrink_factor = 10;
267 } else {
268 _shrink_factor = MIN2(current_shrink_factor * 4, (size_t) 100);
269 }
270 log_trace(gc, heap)(" shrinking: initSize: %.1fK maximum_desired_capacity: %.1fK",
271 initial_size() / (double) K, maximum_desired_capacity / (double) K);
272 log_trace(gc, heap)(" shrink_bytes: %.1fK current_shrink_factor: " SIZE_FORMAT " new shrink factor: " SIZE_FORMAT " _min_heap_delta_bytes: %.1fK",
273 shrink_bytes / (double) K,
274 current_shrink_factor,
275 _shrink_factor,
276 _min_heap_delta_bytes / (double) K);
277 }
278 }
279
280 if (capacity_after_gc > _capacity_at_prologue) {
281 // We might have expanded for promotions, in which case we might want to
282 // take back that expansion if there's room after GC. That keeps us from
283 // stretching the heap with promotions when there's plenty of room.
284 size_t expansion_for_promotion = capacity_after_gc - _capacity_at_prologue;
285 expansion_for_promotion = MIN2(expansion_for_promotion, max_shrink_bytes);
286 // We have two shrinking computations, take the largest
287 shrink_bytes = MAX2(shrink_bytes, expansion_for_promotion);
288 assert(shrink_bytes <= max_shrink_bytes, "invalid shrink size");
289 log_trace(gc, heap)(" aggressive shrinking: _capacity_at_prologue: %.1fK capacity_after_gc: %.1fK expansion_for_promotion: %.1fK shrink_bytes: %.1fK",
290 capacity_after_gc / (double) K,
291 _capacity_at_prologue / (double) K,
292 expansion_for_promotion / (double) K,
293 shrink_bytes / (double) K);
294 }
295 // Don't shrink unless it's significant
296 if (shrink_bytes >= _min_heap_delta_bytes) {
297 shrink(shrink_bytes);
298 }
299 }
300
301 // Currently nothing to do.
302 void CardGeneration::prepare_for_verify() {}
303
304 void CardGeneration::space_iterate(SpaceClosure* blk,
305 bool usedOnly) {
306 blk->do_space(space());
307 }
308
309 void CardGeneration::younger_refs_iterate(OopsInGenClosure* blk, uint n_threads) {
310 blk->set_generation(this);
311 younger_refs_in_space_iterate(space(), blk, n_threads);
312 blk->reset_generation();
313 }
|