Mercurial > hg > graal-compiler
annotate src/share/vm/memory/generation.cpp @ 269:850fdf70db2b
Merge
author | jmasa |
---|---|
date | Mon, 28 Jul 2008 15:30:23 -0700 |
parents | d1605aabd0a1 12eea04c8b06 |
children | 818a18cd69a8 |
rev | line source |
---|---|
0 | 1 /* |
196 | 2 * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 # include "incls/_precompiled.incl" | |
26 # include "incls/_generation.cpp.incl" | |
27 | |
28 Generation::Generation(ReservedSpace rs, size_t initial_size, int level) : | |
29 _level(level), | |
30 _ref_processor(NULL) { | |
31 if (!_virtual_space.initialize(rs, initial_size)) { | |
32 vm_exit_during_initialization("Could not reserve enough space for " | |
33 "object heap"); | |
34 } | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
35 // Mangle all of the the initial generation. |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
36 if (ZapUnusedHeapArea) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
37 MemRegion mangle_region((HeapWord*)_virtual_space.low(), |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
38 (HeapWord*)_virtual_space.high()); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
39 SpaceMangler::mangle_region(mangle_region); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
40 } |
0 | 41 _reserved = MemRegion((HeapWord*)_virtual_space.low_boundary(), |
42 (HeapWord*)_virtual_space.high_boundary()); | |
43 } | |
44 | |
45 GenerationSpec* Generation::spec() { | |
46 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
47 assert(0 <= level() && level() < gch->_n_gens, "Bad gen level"); | |
48 return gch->_gen_specs[level()]; | |
49 } | |
50 | |
51 size_t Generation::max_capacity() const { | |
52 return reserved().byte_size(); | |
53 } | |
54 | |
55 void Generation::print_heap_change(size_t prev_used) const { | |
56 if (PrintGCDetails && Verbose) { | |
57 gclog_or_tty->print(" " SIZE_FORMAT | |
58 "->" SIZE_FORMAT | |
59 "(" SIZE_FORMAT ")", | |
60 prev_used, used(), capacity()); | |
61 } else { | |
62 gclog_or_tty->print(" " SIZE_FORMAT "K" | |
63 "->" SIZE_FORMAT "K" | |
64 "(" SIZE_FORMAT "K)", | |
65 prev_used / K, used() / K, capacity() / K); | |
66 } | |
67 } | |
68 | |
69 // By default we get a single threaded default reference processor; | |
70 // generations needing multi-threaded refs discovery override this method. | |
71 void Generation::ref_processor_init() { | |
72 assert(_ref_processor == NULL, "a reference processor already exists"); | |
73 assert(!_reserved.is_empty(), "empty generation?"); | |
74 _ref_processor = | |
75 new ReferenceProcessor(_reserved, // span | |
76 refs_discovery_is_atomic(), // atomic_discovery | |
77 refs_discovery_is_mt()); // mt_discovery | |
78 if (_ref_processor == NULL) { | |
79 vm_exit_during_initialization("Could not allocate ReferenceProcessor object"); | |
80 } | |
81 } | |
82 | |
83 void Generation::print() const { print_on(tty); } | |
84 | |
85 void Generation::print_on(outputStream* st) const { | |
86 st->print(" %-20s", name()); | |
87 st->print(" total " SIZE_FORMAT "K, used " SIZE_FORMAT "K", | |
88 capacity()/K, used()/K); | |
89 st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ")", | |
90 _virtual_space.low_boundary(), | |
91 _virtual_space.high(), | |
92 _virtual_space.high_boundary()); | |
93 } | |
94 | |
95 void Generation::print_summary_info() { print_summary_info_on(tty); } | |
96 | |
97 void Generation::print_summary_info_on(outputStream* st) { | |
98 StatRecord* sr = stat_record(); | |
99 double time = sr->accumulated_time.seconds(); | |
100 st->print_cr("[Accumulated GC generation %d time %3.7f secs, " | |
101 "%d GC's, avg GC time %3.7f]", | |
102 level(), time, sr->invocations, | |
103 sr->invocations > 0 ? time / sr->invocations : 0.0); | |
104 } | |
105 | |
106 // Utility iterator classes | |
107 | |
108 class GenerationIsInReservedClosure : public SpaceClosure { | |
109 public: | |
110 const void* _p; | |
111 Space* sp; | |
112 virtual void do_space(Space* s) { | |
113 if (sp == NULL) { | |
114 if (s->is_in_reserved(_p)) sp = s; | |
115 } | |
116 } | |
117 GenerationIsInReservedClosure(const void* p) : _p(p), sp(NULL) {} | |
118 }; | |
119 | |
120 class GenerationIsInClosure : public SpaceClosure { | |
121 public: | |
122 const void* _p; | |
123 Space* sp; | |
124 virtual void do_space(Space* s) { | |
125 if (sp == NULL) { | |
126 if (s->is_in(_p)) sp = s; | |
127 } | |
128 } | |
129 GenerationIsInClosure(const void* p) : _p(p), sp(NULL) {} | |
130 }; | |
131 | |
132 bool Generation::is_in(const void* p) const { | |
133 GenerationIsInClosure blk(p); | |
134 ((Generation*)this)->space_iterate(&blk); | |
135 return blk.sp != NULL; | |
136 } | |
137 | |
138 DefNewGeneration* Generation::as_DefNewGeneration() { | |
139 assert((kind() == Generation::DefNew) || | |
140 (kind() == Generation::ParNew) || | |
141 (kind() == Generation::ASParNew), | |
142 "Wrong youngest generation type"); | |
143 return (DefNewGeneration*) this; | |
144 } | |
145 | |
146 Generation* Generation::next_gen() const { | |
147 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
148 int next = level() + 1; | |
149 if (next < gch->_n_gens) { | |
150 return gch->_gens[next]; | |
151 } else { | |
152 return NULL; | |
153 } | |
154 } | |
155 | |
156 size_t Generation::max_contiguous_available() const { | |
157 // The largest number of contiguous free words in this or any higher generation. | |
158 size_t max = 0; | |
159 for (const Generation* gen = this; gen != NULL; gen = gen->next_gen()) { | |
160 size_t avail = gen->contiguous_available(); | |
161 if (avail > max) { | |
162 max = avail; | |
163 } | |
164 } | |
165 return max; | |
166 } | |
167 | |
168 bool Generation::promotion_attempt_is_safe(size_t promotion_in_bytes, | |
169 bool not_used) const { | |
170 if (PrintGC && Verbose) { | |
171 gclog_or_tty->print_cr("Generation::promotion_attempt_is_safe" | |
172 " contiguous_available: " SIZE_FORMAT | |
173 " promotion_in_bytes: " SIZE_FORMAT, | |
174 max_contiguous_available(), promotion_in_bytes); | |
175 } | |
176 return max_contiguous_available() >= promotion_in_bytes; | |
177 } | |
178 | |
179 // Ignores "ref" and calls allocate(). | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
180 oop Generation::promote(oop obj, size_t obj_size) { |
0 | 181 assert(obj_size == (size_t)obj->size(), "bad obj_size passed in"); |
182 | |
183 #ifndef PRODUCT | |
184 if (Universe::heap()->promotion_should_fail()) { | |
185 return NULL; | |
186 } | |
187 #endif // #ifndef PRODUCT | |
188 | |
189 HeapWord* result = allocate(obj_size, false); | |
190 if (result != NULL) { | |
191 Copy::aligned_disjoint_words((HeapWord*)obj, result, obj_size); | |
192 return oop(result); | |
193 } else { | |
194 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
195 return gch->handle_failed_promotion(this, obj, obj_size); |
0 | 196 } |
197 } | |
198 | |
199 oop Generation::par_promote(int thread_num, | |
200 oop obj, markOop m, size_t word_sz) { | |
201 // Could do a bad general impl here that gets a lock. But no. | |
202 ShouldNotCallThis(); | |
203 return NULL; | |
204 } | |
205 | |
206 void Generation::par_promote_alloc_undo(int thread_num, | |
207 HeapWord* obj, size_t word_sz) { | |
208 // Could do a bad general impl here that gets a lock. But no. | |
209 guarantee(false, "No good general implementation."); | |
210 } | |
211 | |
212 Space* Generation::space_containing(const void* p) const { | |
213 GenerationIsInReservedClosure blk(p); | |
214 // Cast away const | |
215 ((Generation*)this)->space_iterate(&blk); | |
216 return blk.sp; | |
217 } | |
218 | |
219 // Some of these are mediocre general implementations. Should be | |
220 // overridden to get better performance. | |
221 | |
222 class GenerationBlockStartClosure : public SpaceClosure { | |
223 public: | |
224 const void* _p; | |
225 HeapWord* _start; | |
226 virtual void do_space(Space* s) { | |
227 if (_start == NULL && s->is_in_reserved(_p)) { | |
228 _start = s->block_start(_p); | |
229 } | |
230 } | |
231 GenerationBlockStartClosure(const void* p) { _p = p; _start = NULL; } | |
232 }; | |
233 | |
234 HeapWord* Generation::block_start(const void* p) const { | |
235 GenerationBlockStartClosure blk(p); | |
236 // Cast away const | |
237 ((Generation*)this)->space_iterate(&blk); | |
238 return blk._start; | |
239 } | |
240 | |
241 class GenerationBlockSizeClosure : public SpaceClosure { | |
242 public: | |
243 const HeapWord* _p; | |
244 size_t size; | |
245 virtual void do_space(Space* s) { | |
246 if (size == 0 && s->is_in_reserved(_p)) { | |
247 size = s->block_size(_p); | |
248 } | |
249 } | |
250 GenerationBlockSizeClosure(const HeapWord* p) { _p = p; size = 0; } | |
251 }; | |
252 | |
253 size_t Generation::block_size(const HeapWord* p) const { | |
254 GenerationBlockSizeClosure blk(p); | |
255 // Cast away const | |
256 ((Generation*)this)->space_iterate(&blk); | |
257 assert(blk.size > 0, "seems reasonable"); | |
258 return blk.size; | |
259 } | |
260 | |
261 class GenerationBlockIsObjClosure : public SpaceClosure { | |
262 public: | |
263 const HeapWord* _p; | |
264 bool is_obj; | |
265 virtual void do_space(Space* s) { | |
266 if (!is_obj && s->is_in_reserved(_p)) { | |
267 is_obj |= s->block_is_obj(_p); | |
268 } | |
269 } | |
270 GenerationBlockIsObjClosure(const HeapWord* p) { _p = p; is_obj = false; } | |
271 }; | |
272 | |
273 bool Generation::block_is_obj(const HeapWord* p) const { | |
274 GenerationBlockIsObjClosure blk(p); | |
275 // Cast away const | |
276 ((Generation*)this)->space_iterate(&blk); | |
277 return blk.is_obj; | |
278 } | |
279 | |
280 class GenerationOopIterateClosure : public SpaceClosure { | |
281 public: | |
282 OopClosure* cl; | |
283 MemRegion mr; | |
284 virtual void do_space(Space* s) { | |
285 s->oop_iterate(mr, cl); | |
286 } | |
287 GenerationOopIterateClosure(OopClosure* _cl, MemRegion _mr) : | |
288 cl(_cl), mr(_mr) {} | |
289 }; | |
290 | |
291 void Generation::oop_iterate(OopClosure* cl) { | |
292 GenerationOopIterateClosure blk(cl, _reserved); | |
293 space_iterate(&blk); | |
294 } | |
295 | |
296 void Generation::oop_iterate(MemRegion mr, OopClosure* cl) { | |
297 GenerationOopIterateClosure blk(cl, mr); | |
298 space_iterate(&blk); | |
299 } | |
300 | |
301 void Generation::younger_refs_in_space_iterate(Space* sp, | |
302 OopsInGenClosure* cl) { | |
303 GenRemSet* rs = SharedHeap::heap()->rem_set(); | |
304 rs->younger_refs_in_space_iterate(sp, cl); | |
305 } | |
306 | |
307 class GenerationObjIterateClosure : public SpaceClosure { | |
308 private: | |
309 ObjectClosure* _cl; | |
310 public: | |
311 virtual void do_space(Space* s) { | |
312 s->object_iterate(_cl); | |
313 } | |
314 GenerationObjIterateClosure(ObjectClosure* cl) : _cl(cl) {} | |
315 }; | |
316 | |
317 void Generation::object_iterate(ObjectClosure* cl) { | |
318 GenerationObjIterateClosure blk(cl); | |
319 space_iterate(&blk); | |
320 } | |
321 | |
322 void Generation::prepare_for_compaction(CompactPoint* cp) { | |
323 // Generic implementation, can be specialized | |
324 CompactibleSpace* space = first_compaction_space(); | |
325 while (space != NULL) { | |
326 space->prepare_for_compaction(cp); | |
327 space = space->next_compaction_space(); | |
328 } | |
329 } | |
330 | |
331 class AdjustPointersClosure: public SpaceClosure { | |
332 public: | |
333 void do_space(Space* sp) { | |
334 sp->adjust_pointers(); | |
335 } | |
336 }; | |
337 | |
338 void Generation::adjust_pointers() { | |
339 // Note that this is done over all spaces, not just the compactible | |
340 // ones. | |
341 AdjustPointersClosure blk; | |
342 space_iterate(&blk, true); | |
343 } | |
344 | |
345 void Generation::compact() { | |
346 CompactibleSpace* sp = first_compaction_space(); | |
347 while (sp != NULL) { | |
348 sp->compact(); | |
349 sp = sp->next_compaction_space(); | |
350 } | |
351 } | |
352 | |
353 CardGeneration::CardGeneration(ReservedSpace rs, size_t initial_byte_size, | |
354 int level, | |
355 GenRemSet* remset) : | |
356 Generation(rs, initial_byte_size, level), _rs(remset) | |
357 { | |
358 HeapWord* start = (HeapWord*)rs.base(); | |
359 size_t reserved_byte_size = rs.size(); | |
360 assert((uintptr_t(start) & 3) == 0, "bad alignment"); | |
361 assert((reserved_byte_size & 3) == 0, "bad alignment"); | |
362 MemRegion reserved_mr(start, heap_word_size(reserved_byte_size)); | |
363 _bts = new BlockOffsetSharedArray(reserved_mr, | |
364 heap_word_size(initial_byte_size)); | |
365 MemRegion committed_mr(start, heap_word_size(initial_byte_size)); | |
366 _rs->resize_covered_region(committed_mr); | |
367 if (_bts == NULL) | |
368 vm_exit_during_initialization("Could not allocate a BlockOffsetArray"); | |
369 | |
370 // Verify that the start and end of this generation is the start of a card. | |
371 // If this wasn't true, a single card could span more than on generation, | |
372 // which would cause problems when we commit/uncommit memory, and when we | |
373 // clear and dirty cards. | |
374 guarantee(_rs->is_aligned(reserved_mr.start()), "generation must be card aligned"); | |
375 if (reserved_mr.end() != Universe::heap()->reserved_region().end()) { | |
376 // Don't check at the very end of the heap as we'll assert that we're probing off | |
377 // the end if we try. | |
378 guarantee(_rs->is_aligned(reserved_mr.end()), "generation must be card aligned"); | |
379 } | |
380 } | |
381 | |
382 | |
383 // No young generation references, clear this generation's cards. | |
384 void CardGeneration::clear_remembered_set() { | |
385 _rs->clear(reserved()); | |
386 } | |
387 | |
388 | |
389 // Objects in this generation may have moved, invalidate this | |
390 // generation's cards. | |
391 void CardGeneration::invalidate_remembered_set() { | |
392 _rs->invalidate(used_region()); | |
393 } | |
394 | |
395 | |
396 // Currently nothing to do. | |
397 void CardGeneration::prepare_for_verify() {} | |
398 | |
399 | |
400 void OneContigSpaceCardGeneration::collect(bool full, | |
401 bool clear_all_soft_refs, | |
402 size_t size, | |
403 bool is_tlab) { | |
404 SpecializationStats::clear(); | |
405 // Temporarily expand the span of our ref processor, so | |
406 // refs discovery is over the entire heap, not just this generation | |
407 ReferenceProcessorSpanMutator | |
408 x(ref_processor(), GenCollectedHeap::heap()->reserved_region()); | |
409 GenMarkSweep::invoke_at_safepoint(_level, ref_processor(), clear_all_soft_refs); | |
410 SpecializationStats::print(); | |
411 } | |
412 | |
413 HeapWord* | |
414 OneContigSpaceCardGeneration::expand_and_allocate(size_t word_size, | |
415 bool is_tlab, | |
416 bool parallel) { | |
417 assert(!is_tlab, "OneContigSpaceCardGeneration does not support TLAB allocation"); | |
418 if (parallel) { | |
419 MutexLocker x(ParGCRareEvent_lock); | |
420 HeapWord* result = NULL; | |
421 size_t byte_size = word_size * HeapWordSize; | |
422 while (true) { | |
423 expand(byte_size, _min_heap_delta_bytes); | |
424 if (GCExpandToAllocateDelayMillis > 0) { | |
425 os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false); | |
426 } | |
427 result = _the_space->par_allocate(word_size); | |
428 if ( result != NULL) { | |
429 return result; | |
430 } else { | |
431 // If there's not enough expansion space available, give up. | |
432 if (_virtual_space.uncommitted_size() < byte_size) { | |
433 return NULL; | |
434 } | |
435 // else try again | |
436 } | |
437 } | |
438 } else { | |
439 expand(word_size*HeapWordSize, _min_heap_delta_bytes); | |
440 return _the_space->allocate(word_size); | |
441 } | |
442 } | |
443 | |
444 void OneContigSpaceCardGeneration::expand(size_t bytes, size_t expand_bytes) { | |
445 GCMutexLocker x(ExpandHeap_lock); | |
446 size_t aligned_bytes = ReservedSpace::page_align_size_up(bytes); | |
447 size_t aligned_expand_bytes = ReservedSpace::page_align_size_up(expand_bytes); | |
448 bool success = false; | |
449 if (aligned_expand_bytes > aligned_bytes) { | |
450 success = grow_by(aligned_expand_bytes); | |
451 } | |
452 if (!success) { | |
453 success = grow_by(aligned_bytes); | |
454 } | |
455 if (!success) { | |
456 grow_to_reserved(); | |
457 } | |
458 if (GC_locker::is_active()) { | |
459 if (PrintGC && Verbose) { | |
460 gclog_or_tty->print_cr("Garbage collection disabled, expanded heap instead"); | |
461 } | |
462 } | |
463 } | |
464 | |
465 | |
466 void OneContigSpaceCardGeneration::shrink(size_t bytes) { | |
467 assert_locked_or_safepoint(ExpandHeap_lock); | |
468 size_t size = ReservedSpace::page_align_size_down(bytes); | |
469 if (size > 0) { | |
470 shrink_by(size); | |
471 } | |
472 } | |
473 | |
474 | |
475 size_t OneContigSpaceCardGeneration::capacity() const { | |
476 return _the_space->capacity(); | |
477 } | |
478 | |
479 | |
480 size_t OneContigSpaceCardGeneration::used() const { | |
481 return _the_space->used(); | |
482 } | |
483 | |
484 | |
485 size_t OneContigSpaceCardGeneration::free() const { | |
486 return _the_space->free(); | |
487 } | |
488 | |
489 MemRegion OneContigSpaceCardGeneration::used_region() const { | |
490 return the_space()->used_region(); | |
491 } | |
492 | |
493 size_t OneContigSpaceCardGeneration::unsafe_max_alloc_nogc() const { | |
494 return _the_space->free(); | |
495 } | |
496 | |
497 size_t OneContigSpaceCardGeneration::contiguous_available() const { | |
498 return _the_space->free() + _virtual_space.uncommitted_size(); | |
499 } | |
500 | |
501 bool OneContigSpaceCardGeneration::grow_by(size_t bytes) { | |
502 assert_locked_or_safepoint(ExpandHeap_lock); | |
503 bool result = _virtual_space.expand_by(bytes); | |
504 if (result) { | |
505 size_t new_word_size = | |
506 heap_word_size(_virtual_space.committed_size()); | |
507 MemRegion mr(_the_space->bottom(), new_word_size); | |
508 // Expand card table | |
509 Universe::heap()->barrier_set()->resize_covered_region(mr); | |
510 // Expand shared block offset array | |
511 _bts->resize(new_word_size); | |
512 | |
513 // Fix for bug #4668531 | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
514 if (ZapUnusedHeapArea) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
515 MemRegion mangle_region(_the_space->end(), |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
516 (HeapWord*)_virtual_space.high()); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
517 SpaceMangler::mangle_region(mangle_region); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
518 } |
0 | 519 |
520 // Expand space -- also expands space's BOT | |
521 // (which uses (part of) shared array above) | |
522 _the_space->set_end((HeapWord*)_virtual_space.high()); | |
523 | |
524 // update the space and generation capacity counters | |
525 update_counters(); | |
526 | |
527 if (Verbose && PrintGC) { | |
528 size_t new_mem_size = _virtual_space.committed_size(); | |
529 size_t old_mem_size = new_mem_size - bytes; | |
530 gclog_or_tty->print_cr("Expanding %s from " SIZE_FORMAT "K by " | |
531 SIZE_FORMAT "K to " SIZE_FORMAT "K", | |
532 name(), old_mem_size/K, bytes/K, new_mem_size/K); | |
533 } | |
534 } | |
535 return result; | |
536 } | |
537 | |
538 | |
539 bool OneContigSpaceCardGeneration::grow_to_reserved() { | |
540 assert_locked_or_safepoint(ExpandHeap_lock); | |
541 bool success = true; | |
542 const size_t remaining_bytes = _virtual_space.uncommitted_size(); | |
543 if (remaining_bytes > 0) { | |
544 success = grow_by(remaining_bytes); | |
545 DEBUG_ONLY(if (!success) warning("grow to reserved failed");) | |
546 } | |
547 return success; | |
548 } | |
549 | |
550 void OneContigSpaceCardGeneration::shrink_by(size_t bytes) { | |
551 assert_locked_or_safepoint(ExpandHeap_lock); | |
552 // Shrink committed space | |
553 _virtual_space.shrink_by(bytes); | |
554 // Shrink space; this also shrinks the space's BOT | |
555 _the_space->set_end((HeapWord*) _virtual_space.high()); | |
556 size_t new_word_size = heap_word_size(_the_space->capacity()); | |
557 // Shrink the shared block offset array | |
558 _bts->resize(new_word_size); | |
559 MemRegion mr(_the_space->bottom(), new_word_size); | |
560 // Shrink the card table | |
561 Universe::heap()->barrier_set()->resize_covered_region(mr); | |
562 | |
563 if (Verbose && PrintGC) { | |
564 size_t new_mem_size = _virtual_space.committed_size(); | |
565 size_t old_mem_size = new_mem_size + bytes; | |
566 gclog_or_tty->print_cr("Shrinking %s from " SIZE_FORMAT "K to " SIZE_FORMAT "K", | |
567 name(), old_mem_size/K, new_mem_size/K); | |
568 } | |
569 } | |
570 | |
571 // Currently nothing to do. | |
572 void OneContigSpaceCardGeneration::prepare_for_verify() {} | |
573 | |
574 | |
575 void OneContigSpaceCardGeneration::object_iterate(ObjectClosure* blk) { | |
576 _the_space->object_iterate(blk); | |
577 } | |
578 | |
579 void OneContigSpaceCardGeneration::space_iterate(SpaceClosure* blk, | |
580 bool usedOnly) { | |
581 blk->do_space(_the_space); | |
582 } | |
583 | |
584 void OneContigSpaceCardGeneration::object_iterate_since_last_GC(ObjectClosure* blk) { | |
585 // Deal with delayed initialization of _the_space, | |
586 // and lack of initialization of _last_gc. | |
587 if (_last_gc.space() == NULL) { | |
588 assert(the_space() != NULL, "shouldn't be NULL"); | |
589 _last_gc = the_space()->bottom_mark(); | |
590 } | |
591 the_space()->object_iterate_from(_last_gc, blk); | |
592 } | |
593 | |
594 void OneContigSpaceCardGeneration::younger_refs_iterate(OopsInGenClosure* blk) { | |
595 blk->set_generation(this); | |
596 younger_refs_in_space_iterate(_the_space, blk); | |
597 blk->reset_generation(); | |
598 } | |
599 | |
600 void OneContigSpaceCardGeneration::save_marks() { | |
601 _the_space->set_saved_mark(); | |
602 } | |
603 | |
604 | |
605 void OneContigSpaceCardGeneration::reset_saved_marks() { | |
606 _the_space->reset_saved_mark(); | |
607 } | |
608 | |
609 | |
610 bool OneContigSpaceCardGeneration::no_allocs_since_save_marks() { | |
611 return _the_space->saved_mark_at_top(); | |
612 } | |
613 | |
614 #define OneContig_SINCE_SAVE_MARKS_ITERATE_DEFN(OopClosureType, nv_suffix) \ | |
615 \ | |
616 void OneContigSpaceCardGeneration:: \ | |
617 oop_since_save_marks_iterate##nv_suffix(OopClosureType* blk) { \ | |
618 blk->set_generation(this); \ | |
619 _the_space->oop_since_save_marks_iterate##nv_suffix(blk); \ | |
620 blk->reset_generation(); \ | |
621 save_marks(); \ | |
622 } | |
623 | |
624 ALL_SINCE_SAVE_MARKS_CLOSURES(OneContig_SINCE_SAVE_MARKS_ITERATE_DEFN) | |
625 | |
626 #undef OneContig_SINCE_SAVE_MARKS_ITERATE_DEFN | |
627 | |
628 | |
629 void OneContigSpaceCardGeneration::gc_epilogue(bool full) { | |
630 _last_gc = WaterMark(the_space(), the_space()->top()); | |
631 | |
632 // update the generation and space performance counters | |
633 update_counters(); | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
634 if (ZapUnusedHeapArea) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
635 the_space()->check_mangled_unused_area_complete(); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
636 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
637 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
638 |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
639 void OneContigSpaceCardGeneration::record_spaces_top() { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
640 assert(ZapUnusedHeapArea, "Not mangling unused space"); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
641 the_space()->set_top_for_allocations(); |
0 | 642 } |
643 | |
644 void OneContigSpaceCardGeneration::verify(bool allow_dirty) { | |
645 the_space()->verify(allow_dirty); | |
646 } | |
647 | |
648 void OneContigSpaceCardGeneration::print_on(outputStream* st) const { | |
649 Generation::print_on(st); | |
650 st->print(" the"); | |
651 the_space()->print_on(st); | |
652 } |