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