src/share/vm/memory/generation.cpp

Wed, 01 Dec 2010 15:04:06 +0100

author
stefank
date
Wed, 01 Dec 2010 15:04:06 +0100
changeset 2325
c760f78e0a53
parent 2314
f95d63e2154a
child 2651
92da084fefc9
permissions
-rw-r--r--

7003125: precompiled.hpp is included when precompiled headers are not used
Summary: Added an ifndef DONT_USE_PRECOMPILED_HEADER to precompiled.hpp. Set up DONT_USE_PRECOMPILED_HEADER when compiling with Sun Studio or when the user specifies USE_PRECOMPILED_HEADER=0. Fixed broken include dependencies.
Reviewed-by: coleenp, kvn

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

mercurial