Mon, 17 Jun 2013 11:17:49 +0100
Merge
duke@435 | 1 | /* |
brutisso@3711 | 2 | * Copyright (c) 1997, 2012, 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; |
ysr@2651 | 86 | // generations needing multi-threaded refs processing or 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?"); |
ysr@2651 | 90 | _ref_processor = new ReferenceProcessor(_reserved); // a vanilla reference processor |
duke@435 | 91 | if (_ref_processor == NULL) { |
duke@435 | 92 | vm_exit_during_initialization("Could not allocate ReferenceProcessor object"); |
duke@435 | 93 | } |
duke@435 | 94 | } |
duke@435 | 95 | |
duke@435 | 96 | void Generation::print() const { print_on(tty); } |
duke@435 | 97 | |
duke@435 | 98 | void Generation::print_on(outputStream* st) const { |
duke@435 | 99 | st->print(" %-20s", name()); |
duke@435 | 100 | st->print(" total " SIZE_FORMAT "K, used " SIZE_FORMAT "K", |
duke@435 | 101 | capacity()/K, used()/K); |
duke@435 | 102 | st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ")", |
duke@435 | 103 | _virtual_space.low_boundary(), |
duke@435 | 104 | _virtual_space.high(), |
duke@435 | 105 | _virtual_space.high_boundary()); |
duke@435 | 106 | } |
duke@435 | 107 | |
duke@435 | 108 | void Generation::print_summary_info() { print_summary_info_on(tty); } |
duke@435 | 109 | |
duke@435 | 110 | void Generation::print_summary_info_on(outputStream* st) { |
duke@435 | 111 | StatRecord* sr = stat_record(); |
duke@435 | 112 | double time = sr->accumulated_time.seconds(); |
duke@435 | 113 | st->print_cr("[Accumulated GC generation %d time %3.7f secs, " |
duke@435 | 114 | "%d GC's, avg GC time %3.7f]", |
duke@435 | 115 | level(), time, sr->invocations, |
duke@435 | 116 | sr->invocations > 0 ? time / sr->invocations : 0.0); |
duke@435 | 117 | } |
duke@435 | 118 | |
duke@435 | 119 | // Utility iterator classes |
duke@435 | 120 | |
duke@435 | 121 | class GenerationIsInReservedClosure : public SpaceClosure { |
duke@435 | 122 | public: |
duke@435 | 123 | const void* _p; |
duke@435 | 124 | Space* sp; |
duke@435 | 125 | virtual void do_space(Space* s) { |
duke@435 | 126 | if (sp == NULL) { |
duke@435 | 127 | if (s->is_in_reserved(_p)) sp = s; |
duke@435 | 128 | } |
duke@435 | 129 | } |
duke@435 | 130 | GenerationIsInReservedClosure(const void* p) : _p(p), sp(NULL) {} |
duke@435 | 131 | }; |
duke@435 | 132 | |
duke@435 | 133 | class GenerationIsInClosure : public SpaceClosure { |
duke@435 | 134 | public: |
duke@435 | 135 | const void* _p; |
duke@435 | 136 | Space* sp; |
duke@435 | 137 | virtual void do_space(Space* s) { |
duke@435 | 138 | if (sp == NULL) { |
duke@435 | 139 | if (s->is_in(_p)) sp = s; |
duke@435 | 140 | } |
duke@435 | 141 | } |
duke@435 | 142 | GenerationIsInClosure(const void* p) : _p(p), sp(NULL) {} |
duke@435 | 143 | }; |
duke@435 | 144 | |
duke@435 | 145 | bool Generation::is_in(const void* p) const { |
duke@435 | 146 | GenerationIsInClosure blk(p); |
duke@435 | 147 | ((Generation*)this)->space_iterate(&blk); |
duke@435 | 148 | return blk.sp != NULL; |
duke@435 | 149 | } |
duke@435 | 150 | |
duke@435 | 151 | DefNewGeneration* Generation::as_DefNewGeneration() { |
duke@435 | 152 | assert((kind() == Generation::DefNew) || |
duke@435 | 153 | (kind() == Generation::ParNew) || |
duke@435 | 154 | (kind() == Generation::ASParNew), |
duke@435 | 155 | "Wrong youngest generation type"); |
duke@435 | 156 | return (DefNewGeneration*) this; |
duke@435 | 157 | } |
duke@435 | 158 | |
duke@435 | 159 | Generation* Generation::next_gen() const { |
duke@435 | 160 | GenCollectedHeap* gch = GenCollectedHeap::heap(); |
duke@435 | 161 | int next = level() + 1; |
duke@435 | 162 | if (next < gch->_n_gens) { |
duke@435 | 163 | return gch->_gens[next]; |
duke@435 | 164 | } else { |
duke@435 | 165 | return NULL; |
duke@435 | 166 | } |
duke@435 | 167 | } |
duke@435 | 168 | |
duke@435 | 169 | size_t Generation::max_contiguous_available() const { |
duke@435 | 170 | // The largest number of contiguous free words in this or any higher generation. |
duke@435 | 171 | size_t max = 0; |
duke@435 | 172 | for (const Generation* gen = this; gen != NULL; gen = gen->next_gen()) { |
duke@435 | 173 | size_t avail = gen->contiguous_available(); |
duke@435 | 174 | if (avail > max) { |
duke@435 | 175 | max = avail; |
duke@435 | 176 | } |
duke@435 | 177 | } |
duke@435 | 178 | return max; |
duke@435 | 179 | } |
duke@435 | 180 | |
ysr@2243 | 181 | bool Generation::promotion_attempt_is_safe(size_t max_promotion_in_bytes) const { |
ysr@2243 | 182 | size_t available = max_contiguous_available(); |
ysr@2243 | 183 | bool res = (available >= max_promotion_in_bytes); |
duke@435 | 184 | if (PrintGC && Verbose) { |
ysr@2243 | 185 | gclog_or_tty->print_cr( |
ysr@2243 | 186 | "Generation: promo attempt is%s safe: available("SIZE_FORMAT") %s max_promo("SIZE_FORMAT")", |
ysr@2243 | 187 | res? "":" not", available, res? ">=":"<", |
ysr@2243 | 188 | max_promotion_in_bytes); |
duke@435 | 189 | } |
ysr@2243 | 190 | return res; |
duke@435 | 191 | } |
duke@435 | 192 | |
duke@435 | 193 | // Ignores "ref" and calls allocate(). |
coleenp@548 | 194 | oop Generation::promote(oop obj, size_t obj_size) { |
duke@435 | 195 | assert(obj_size == (size_t)obj->size(), "bad obj_size passed in"); |
duke@435 | 196 | |
duke@435 | 197 | #ifndef PRODUCT |
duke@435 | 198 | if (Universe::heap()->promotion_should_fail()) { |
duke@435 | 199 | return NULL; |
duke@435 | 200 | } |
duke@435 | 201 | #endif // #ifndef PRODUCT |
duke@435 | 202 | |
duke@435 | 203 | HeapWord* result = allocate(obj_size, false); |
duke@435 | 204 | if (result != NULL) { |
duke@435 | 205 | Copy::aligned_disjoint_words((HeapWord*)obj, result, obj_size); |
duke@435 | 206 | return oop(result); |
duke@435 | 207 | } else { |
duke@435 | 208 | GenCollectedHeap* gch = GenCollectedHeap::heap(); |
coleenp@548 | 209 | return gch->handle_failed_promotion(this, obj, obj_size); |
duke@435 | 210 | } |
duke@435 | 211 | } |
duke@435 | 212 | |
duke@435 | 213 | oop Generation::par_promote(int thread_num, |
duke@435 | 214 | oop obj, markOop m, size_t word_sz) { |
duke@435 | 215 | // Could do a bad general impl here that gets a lock. But no. |
duke@435 | 216 | ShouldNotCallThis(); |
duke@435 | 217 | return NULL; |
duke@435 | 218 | } |
duke@435 | 219 | |
duke@435 | 220 | void Generation::par_promote_alloc_undo(int thread_num, |
duke@435 | 221 | HeapWord* obj, size_t word_sz) { |
duke@435 | 222 | // Could do a bad general impl here that gets a lock. But no. |
duke@435 | 223 | guarantee(false, "No good general implementation."); |
duke@435 | 224 | } |
duke@435 | 225 | |
duke@435 | 226 | Space* Generation::space_containing(const void* p) const { |
duke@435 | 227 | GenerationIsInReservedClosure blk(p); |
duke@435 | 228 | // Cast away const |
duke@435 | 229 | ((Generation*)this)->space_iterate(&blk); |
duke@435 | 230 | return blk.sp; |
duke@435 | 231 | } |
duke@435 | 232 | |
duke@435 | 233 | // Some of these are mediocre general implementations. Should be |
duke@435 | 234 | // overridden to get better performance. |
duke@435 | 235 | |
duke@435 | 236 | class GenerationBlockStartClosure : public SpaceClosure { |
duke@435 | 237 | public: |
duke@435 | 238 | const void* _p; |
duke@435 | 239 | HeapWord* _start; |
duke@435 | 240 | virtual void do_space(Space* s) { |
duke@435 | 241 | if (_start == NULL && s->is_in_reserved(_p)) { |
duke@435 | 242 | _start = s->block_start(_p); |
duke@435 | 243 | } |
duke@435 | 244 | } |
duke@435 | 245 | GenerationBlockStartClosure(const void* p) { _p = p; _start = NULL; } |
duke@435 | 246 | }; |
duke@435 | 247 | |
duke@435 | 248 | HeapWord* Generation::block_start(const void* p) const { |
duke@435 | 249 | GenerationBlockStartClosure blk(p); |
duke@435 | 250 | // Cast away const |
duke@435 | 251 | ((Generation*)this)->space_iterate(&blk); |
duke@435 | 252 | return blk._start; |
duke@435 | 253 | } |
duke@435 | 254 | |
duke@435 | 255 | class GenerationBlockSizeClosure : public SpaceClosure { |
duke@435 | 256 | public: |
duke@435 | 257 | const HeapWord* _p; |
duke@435 | 258 | size_t size; |
duke@435 | 259 | virtual void do_space(Space* s) { |
duke@435 | 260 | if (size == 0 && s->is_in_reserved(_p)) { |
duke@435 | 261 | size = s->block_size(_p); |
duke@435 | 262 | } |
duke@435 | 263 | } |
duke@435 | 264 | GenerationBlockSizeClosure(const HeapWord* p) { _p = p; size = 0; } |
duke@435 | 265 | }; |
duke@435 | 266 | |
duke@435 | 267 | size_t Generation::block_size(const HeapWord* p) const { |
duke@435 | 268 | GenerationBlockSizeClosure blk(p); |
duke@435 | 269 | // Cast away const |
duke@435 | 270 | ((Generation*)this)->space_iterate(&blk); |
duke@435 | 271 | assert(blk.size > 0, "seems reasonable"); |
duke@435 | 272 | return blk.size; |
duke@435 | 273 | } |
duke@435 | 274 | |
duke@435 | 275 | class GenerationBlockIsObjClosure : public SpaceClosure { |
duke@435 | 276 | public: |
duke@435 | 277 | const HeapWord* _p; |
duke@435 | 278 | bool is_obj; |
duke@435 | 279 | virtual void do_space(Space* s) { |
duke@435 | 280 | if (!is_obj && s->is_in_reserved(_p)) { |
duke@435 | 281 | is_obj |= s->block_is_obj(_p); |
duke@435 | 282 | } |
duke@435 | 283 | } |
duke@435 | 284 | GenerationBlockIsObjClosure(const HeapWord* p) { _p = p; is_obj = false; } |
duke@435 | 285 | }; |
duke@435 | 286 | |
duke@435 | 287 | bool Generation::block_is_obj(const HeapWord* p) const { |
duke@435 | 288 | GenerationBlockIsObjClosure blk(p); |
duke@435 | 289 | // Cast away const |
duke@435 | 290 | ((Generation*)this)->space_iterate(&blk); |
duke@435 | 291 | return blk.is_obj; |
duke@435 | 292 | } |
duke@435 | 293 | |
duke@435 | 294 | class GenerationOopIterateClosure : public SpaceClosure { |
duke@435 | 295 | public: |
coleenp@4037 | 296 | ExtendedOopClosure* cl; |
duke@435 | 297 | MemRegion mr; |
duke@435 | 298 | virtual void do_space(Space* s) { |
duke@435 | 299 | s->oop_iterate(mr, cl); |
duke@435 | 300 | } |
coleenp@4037 | 301 | GenerationOopIterateClosure(ExtendedOopClosure* _cl, MemRegion _mr) : |
duke@435 | 302 | cl(_cl), mr(_mr) {} |
duke@435 | 303 | }; |
duke@435 | 304 | |
coleenp@4037 | 305 | void Generation::oop_iterate(ExtendedOopClosure* cl) { |
duke@435 | 306 | GenerationOopIterateClosure blk(cl, _reserved); |
duke@435 | 307 | space_iterate(&blk); |
duke@435 | 308 | } |
duke@435 | 309 | |
coleenp@4037 | 310 | void Generation::oop_iterate(MemRegion mr, ExtendedOopClosure* cl) { |
duke@435 | 311 | GenerationOopIterateClosure blk(cl, mr); |
duke@435 | 312 | space_iterate(&blk); |
duke@435 | 313 | } |
duke@435 | 314 | |
duke@435 | 315 | void Generation::younger_refs_in_space_iterate(Space* sp, |
duke@435 | 316 | OopsInGenClosure* cl) { |
duke@435 | 317 | GenRemSet* rs = SharedHeap::heap()->rem_set(); |
duke@435 | 318 | rs->younger_refs_in_space_iterate(sp, cl); |
duke@435 | 319 | } |
duke@435 | 320 | |
duke@435 | 321 | class GenerationObjIterateClosure : public SpaceClosure { |
duke@435 | 322 | private: |
duke@435 | 323 | ObjectClosure* _cl; |
duke@435 | 324 | public: |
duke@435 | 325 | virtual void do_space(Space* s) { |
duke@435 | 326 | s->object_iterate(_cl); |
duke@435 | 327 | } |
duke@435 | 328 | GenerationObjIterateClosure(ObjectClosure* cl) : _cl(cl) {} |
duke@435 | 329 | }; |
duke@435 | 330 | |
duke@435 | 331 | void Generation::object_iterate(ObjectClosure* cl) { |
duke@435 | 332 | GenerationObjIterateClosure blk(cl); |
duke@435 | 333 | space_iterate(&blk); |
duke@435 | 334 | } |
duke@435 | 335 | |
jmasa@952 | 336 | class GenerationSafeObjIterateClosure : public SpaceClosure { |
jmasa@952 | 337 | private: |
jmasa@952 | 338 | ObjectClosure* _cl; |
jmasa@952 | 339 | public: |
jmasa@952 | 340 | virtual void do_space(Space* s) { |
jmasa@952 | 341 | s->safe_object_iterate(_cl); |
jmasa@952 | 342 | } |
jmasa@952 | 343 | GenerationSafeObjIterateClosure(ObjectClosure* cl) : _cl(cl) {} |
jmasa@952 | 344 | }; |
jmasa@952 | 345 | |
jmasa@952 | 346 | void Generation::safe_object_iterate(ObjectClosure* cl) { |
jmasa@952 | 347 | GenerationSafeObjIterateClosure blk(cl); |
jmasa@952 | 348 | space_iterate(&blk); |
jmasa@952 | 349 | } |
jmasa@952 | 350 | |
duke@435 | 351 | void Generation::prepare_for_compaction(CompactPoint* cp) { |
duke@435 | 352 | // Generic implementation, can be specialized |
duke@435 | 353 | CompactibleSpace* space = first_compaction_space(); |
duke@435 | 354 | while (space != NULL) { |
duke@435 | 355 | space->prepare_for_compaction(cp); |
duke@435 | 356 | space = space->next_compaction_space(); |
duke@435 | 357 | } |
duke@435 | 358 | } |
duke@435 | 359 | |
duke@435 | 360 | class AdjustPointersClosure: public SpaceClosure { |
duke@435 | 361 | public: |
duke@435 | 362 | void do_space(Space* sp) { |
duke@435 | 363 | sp->adjust_pointers(); |
duke@435 | 364 | } |
duke@435 | 365 | }; |
duke@435 | 366 | |
duke@435 | 367 | void Generation::adjust_pointers() { |
duke@435 | 368 | // Note that this is done over all spaces, not just the compactible |
duke@435 | 369 | // ones. |
duke@435 | 370 | AdjustPointersClosure blk; |
duke@435 | 371 | space_iterate(&blk, true); |
duke@435 | 372 | } |
duke@435 | 373 | |
duke@435 | 374 | void Generation::compact() { |
duke@435 | 375 | CompactibleSpace* sp = first_compaction_space(); |
duke@435 | 376 | while (sp != NULL) { |
duke@435 | 377 | sp->compact(); |
duke@435 | 378 | sp = sp->next_compaction_space(); |
duke@435 | 379 | } |
duke@435 | 380 | } |
duke@435 | 381 | |
duke@435 | 382 | CardGeneration::CardGeneration(ReservedSpace rs, size_t initial_byte_size, |
duke@435 | 383 | int level, |
duke@435 | 384 | GenRemSet* remset) : |
jmasa@4900 | 385 | Generation(rs, initial_byte_size, level), _rs(remset), |
jmasa@4900 | 386 | _shrink_factor(0), _min_heap_delta_bytes(), _capacity_at_prologue(), |
jmasa@4900 | 387 | _used_at_prologue() |
duke@435 | 388 | { |
duke@435 | 389 | HeapWord* start = (HeapWord*)rs.base(); |
duke@435 | 390 | size_t reserved_byte_size = rs.size(); |
duke@435 | 391 | assert((uintptr_t(start) & 3) == 0, "bad alignment"); |
duke@435 | 392 | assert((reserved_byte_size & 3) == 0, "bad alignment"); |
duke@435 | 393 | MemRegion reserved_mr(start, heap_word_size(reserved_byte_size)); |
duke@435 | 394 | _bts = new BlockOffsetSharedArray(reserved_mr, |
duke@435 | 395 | heap_word_size(initial_byte_size)); |
duke@435 | 396 | MemRegion committed_mr(start, heap_word_size(initial_byte_size)); |
duke@435 | 397 | _rs->resize_covered_region(committed_mr); |
duke@435 | 398 | if (_bts == NULL) |
duke@435 | 399 | vm_exit_during_initialization("Could not allocate a BlockOffsetArray"); |
duke@435 | 400 | |
duke@435 | 401 | // Verify that the start and end of this generation is the start of a card. |
duke@435 | 402 | // If this wasn't true, a single card could span more than on generation, |
duke@435 | 403 | // which would cause problems when we commit/uncommit memory, and when we |
duke@435 | 404 | // clear and dirty cards. |
duke@435 | 405 | guarantee(_rs->is_aligned(reserved_mr.start()), "generation must be card aligned"); |
duke@435 | 406 | if (reserved_mr.end() != Universe::heap()->reserved_region().end()) { |
duke@435 | 407 | // Don't check at the very end of the heap as we'll assert that we're probing off |
duke@435 | 408 | // the end if we try. |
duke@435 | 409 | guarantee(_rs->is_aligned(reserved_mr.end()), "generation must be card aligned"); |
duke@435 | 410 | } |
jmasa@4900 | 411 | _min_heap_delta_bytes = MinHeapDeltaBytes; |
jmasa@4900 | 412 | _capacity_at_prologue = initial_byte_size; |
jmasa@4900 | 413 | _used_at_prologue = 0; |
duke@435 | 414 | } |
duke@435 | 415 | |
jmasa@706 | 416 | bool CardGeneration::expand(size_t bytes, size_t expand_bytes) { |
jmasa@706 | 417 | assert_locked_or_safepoint(Heap_lock); |
jmasa@706 | 418 | if (bytes == 0) { |
jmasa@706 | 419 | return true; // That's what grow_by(0) would return |
jmasa@706 | 420 | } |
jmasa@706 | 421 | size_t aligned_bytes = ReservedSpace::page_align_size_up(bytes); |
jmasa@706 | 422 | if (aligned_bytes == 0){ |
jmasa@706 | 423 | // The alignment caused the number of bytes to wrap. An expand_by(0) will |
jmasa@706 | 424 | // return true with the implication that an expansion was done when it |
jmasa@706 | 425 | // was not. A call to expand implies a best effort to expand by "bytes" |
jmasa@706 | 426 | // but not a guarantee. Align down to give a best effort. This is likely |
jmasa@706 | 427 | // the most that the generation can expand since it has some capacity to |
jmasa@706 | 428 | // start with. |
jmasa@706 | 429 | aligned_bytes = ReservedSpace::page_align_size_down(bytes); |
jmasa@706 | 430 | } |
jmasa@706 | 431 | size_t aligned_expand_bytes = ReservedSpace::page_align_size_up(expand_bytes); |
jmasa@706 | 432 | bool success = false; |
jmasa@706 | 433 | if (aligned_expand_bytes > aligned_bytes) { |
jmasa@706 | 434 | success = grow_by(aligned_expand_bytes); |
jmasa@706 | 435 | } |
jmasa@706 | 436 | if (!success) { |
jmasa@706 | 437 | success = grow_by(aligned_bytes); |
jmasa@706 | 438 | } |
jmasa@706 | 439 | if (!success) { |
jmasa@706 | 440 | success = grow_to_reserved(); |
jmasa@706 | 441 | } |
jmasa@706 | 442 | if (PrintGC && Verbose) { |
coleenp@4037 | 443 | if (success && GC_locker::is_active_and_needs_gc()) { |
jmasa@706 | 444 | gclog_or_tty->print_cr("Garbage collection disabled, expanded heap instead"); |
jmasa@706 | 445 | } |
jmasa@706 | 446 | } |
jmasa@706 | 447 | |
jmasa@706 | 448 | return success; |
jmasa@706 | 449 | } |
jmasa@706 | 450 | |
duke@435 | 451 | |
duke@435 | 452 | // No young generation references, clear this generation's cards. |
duke@435 | 453 | void CardGeneration::clear_remembered_set() { |
duke@435 | 454 | _rs->clear(reserved()); |
duke@435 | 455 | } |
duke@435 | 456 | |
duke@435 | 457 | |
duke@435 | 458 | // Objects in this generation may have moved, invalidate this |
duke@435 | 459 | // generation's cards. |
duke@435 | 460 | void CardGeneration::invalidate_remembered_set() { |
duke@435 | 461 | _rs->invalidate(used_region()); |
duke@435 | 462 | } |
duke@435 | 463 | |
duke@435 | 464 | |
jmasa@4900 | 465 | void CardGeneration::compute_new_size() { |
jmasa@4900 | 466 | assert(_shrink_factor <= 100, "invalid shrink factor"); |
jmasa@4900 | 467 | size_t current_shrink_factor = _shrink_factor; |
jmasa@4900 | 468 | _shrink_factor = 0; |
jmasa@4900 | 469 | |
jmasa@4900 | 470 | // We don't have floating point command-line arguments |
jmasa@4900 | 471 | // Note: argument processing ensures that MinHeapFreeRatio < 100. |
jmasa@4900 | 472 | const double minimum_free_percentage = MinHeapFreeRatio / 100.0; |
jmasa@4900 | 473 | const double maximum_used_percentage = 1.0 - minimum_free_percentage; |
jmasa@4900 | 474 | |
jmasa@4900 | 475 | // Compute some numbers about the state of the heap. |
jmasa@4900 | 476 | const size_t used_after_gc = used(); |
jmasa@4900 | 477 | const size_t capacity_after_gc = capacity(); |
jmasa@4900 | 478 | |
jmasa@4900 | 479 | const double min_tmp = used_after_gc / maximum_used_percentage; |
jmasa@4900 | 480 | size_t minimum_desired_capacity = (size_t)MIN2(min_tmp, double(max_uintx)); |
jmasa@4900 | 481 | // Don't shrink less than the initial generation size |
jmasa@4900 | 482 | minimum_desired_capacity = MAX2(minimum_desired_capacity, |
jmasa@4900 | 483 | spec()->init_size()); |
jmasa@4900 | 484 | assert(used_after_gc <= minimum_desired_capacity, "sanity check"); |
jmasa@4900 | 485 | |
jmasa@4900 | 486 | if (PrintGC && Verbose) { |
jmasa@4900 | 487 | const size_t free_after_gc = free(); |
jmasa@4900 | 488 | const double free_percentage = ((double)free_after_gc) / capacity_after_gc; |
jmasa@4900 | 489 | gclog_or_tty->print_cr("TenuredGeneration::compute_new_size: "); |
jmasa@4900 | 490 | gclog_or_tty->print_cr(" " |
jmasa@4900 | 491 | " minimum_free_percentage: %6.2f" |
jmasa@4900 | 492 | " maximum_used_percentage: %6.2f", |
jmasa@4900 | 493 | minimum_free_percentage, |
jmasa@4900 | 494 | maximum_used_percentage); |
jmasa@4900 | 495 | gclog_or_tty->print_cr(" " |
jmasa@4900 | 496 | " free_after_gc : %6.1fK" |
jmasa@4900 | 497 | " used_after_gc : %6.1fK" |
jmasa@4900 | 498 | " capacity_after_gc : %6.1fK", |
jmasa@4900 | 499 | free_after_gc / (double) K, |
jmasa@4900 | 500 | used_after_gc / (double) K, |
jmasa@4900 | 501 | capacity_after_gc / (double) K); |
jmasa@4900 | 502 | gclog_or_tty->print_cr(" " |
jmasa@4900 | 503 | " free_percentage: %6.2f", |
jmasa@4900 | 504 | free_percentage); |
jmasa@4900 | 505 | } |
jmasa@4900 | 506 | |
jmasa@4900 | 507 | if (capacity_after_gc < minimum_desired_capacity) { |
jmasa@4900 | 508 | // If we have less free space than we want then expand |
jmasa@4900 | 509 | size_t expand_bytes = minimum_desired_capacity - capacity_after_gc; |
jmasa@4900 | 510 | // Don't expand unless it's significant |
jmasa@4900 | 511 | if (expand_bytes >= _min_heap_delta_bytes) { |
jmasa@4900 | 512 | expand(expand_bytes, 0); // safe if expansion fails |
jmasa@4900 | 513 | } |
jmasa@4900 | 514 | if (PrintGC && Verbose) { |
jmasa@4900 | 515 | gclog_or_tty->print_cr(" expanding:" |
jmasa@4900 | 516 | " minimum_desired_capacity: %6.1fK" |
jmasa@4900 | 517 | " expand_bytes: %6.1fK" |
jmasa@4900 | 518 | " _min_heap_delta_bytes: %6.1fK", |
jmasa@4900 | 519 | minimum_desired_capacity / (double) K, |
jmasa@4900 | 520 | expand_bytes / (double) K, |
jmasa@4900 | 521 | _min_heap_delta_bytes / (double) K); |
jmasa@4900 | 522 | } |
jmasa@4900 | 523 | return; |
jmasa@4900 | 524 | } |
jmasa@4900 | 525 | |
jmasa@4900 | 526 | // No expansion, now see if we want to shrink |
jmasa@4900 | 527 | size_t shrink_bytes = 0; |
jmasa@4900 | 528 | // We would never want to shrink more than this |
jmasa@4900 | 529 | size_t max_shrink_bytes = capacity_after_gc - minimum_desired_capacity; |
jmasa@4900 | 530 | |
jmasa@4900 | 531 | if (MaxHeapFreeRatio < 100) { |
jmasa@4900 | 532 | const double maximum_free_percentage = MaxHeapFreeRatio / 100.0; |
jmasa@4900 | 533 | const double minimum_used_percentage = 1.0 - maximum_free_percentage; |
jmasa@4900 | 534 | const double max_tmp = used_after_gc / minimum_used_percentage; |
jmasa@4900 | 535 | size_t maximum_desired_capacity = (size_t)MIN2(max_tmp, double(max_uintx)); |
jmasa@4900 | 536 | maximum_desired_capacity = MAX2(maximum_desired_capacity, |
jmasa@4900 | 537 | spec()->init_size()); |
jmasa@4900 | 538 | if (PrintGC && Verbose) { |
jmasa@4900 | 539 | gclog_or_tty->print_cr(" " |
jmasa@4900 | 540 | " maximum_free_percentage: %6.2f" |
jmasa@4900 | 541 | " minimum_used_percentage: %6.2f", |
jmasa@4900 | 542 | maximum_free_percentage, |
jmasa@4900 | 543 | minimum_used_percentage); |
jmasa@4900 | 544 | gclog_or_tty->print_cr(" " |
jmasa@4900 | 545 | " _capacity_at_prologue: %6.1fK" |
jmasa@4900 | 546 | " minimum_desired_capacity: %6.1fK" |
jmasa@4900 | 547 | " maximum_desired_capacity: %6.1fK", |
jmasa@4900 | 548 | _capacity_at_prologue / (double) K, |
jmasa@4900 | 549 | minimum_desired_capacity / (double) K, |
jmasa@4900 | 550 | maximum_desired_capacity / (double) K); |
jmasa@4900 | 551 | } |
jmasa@4900 | 552 | assert(minimum_desired_capacity <= maximum_desired_capacity, |
jmasa@4900 | 553 | "sanity check"); |
jmasa@4900 | 554 | |
jmasa@4900 | 555 | if (capacity_after_gc > maximum_desired_capacity) { |
jmasa@4900 | 556 | // Capacity too large, compute shrinking size |
jmasa@4900 | 557 | shrink_bytes = capacity_after_gc - maximum_desired_capacity; |
jmasa@4900 | 558 | // We don't want shrink all the way back to initSize if people call |
jmasa@4900 | 559 | // System.gc(), because some programs do that between "phases" and then |
jmasa@4900 | 560 | // we'd just have to grow the heap up again for the next phase. So we |
jmasa@4900 | 561 | // damp the shrinking: 0% on the first call, 10% on the second call, 40% |
jmasa@4900 | 562 | // on the third call, and 100% by the fourth call. But if we recompute |
jmasa@4900 | 563 | // size without shrinking, it goes back to 0%. |
jmasa@4900 | 564 | shrink_bytes = shrink_bytes / 100 * current_shrink_factor; |
jmasa@4900 | 565 | assert(shrink_bytes <= max_shrink_bytes, "invalid shrink size"); |
jmasa@4900 | 566 | if (current_shrink_factor == 0) { |
jmasa@4900 | 567 | _shrink_factor = 10; |
jmasa@4900 | 568 | } else { |
jmasa@4900 | 569 | _shrink_factor = MIN2(current_shrink_factor * 4, (size_t) 100); |
jmasa@4900 | 570 | } |
jmasa@4900 | 571 | if (PrintGC && Verbose) { |
jmasa@4900 | 572 | gclog_or_tty->print_cr(" " |
jmasa@4900 | 573 | " shrinking:" |
jmasa@4900 | 574 | " initSize: %.1fK" |
jmasa@4900 | 575 | " maximum_desired_capacity: %.1fK", |
jmasa@4900 | 576 | spec()->init_size() / (double) K, |
jmasa@4900 | 577 | maximum_desired_capacity / (double) K); |
jmasa@4900 | 578 | gclog_or_tty->print_cr(" " |
jmasa@4900 | 579 | " shrink_bytes: %.1fK" |
jmasa@4900 | 580 | " current_shrink_factor: %d" |
jmasa@4900 | 581 | " new shrink factor: %d" |
jmasa@4900 | 582 | " _min_heap_delta_bytes: %.1fK", |
jmasa@4900 | 583 | shrink_bytes / (double) K, |
jmasa@4900 | 584 | current_shrink_factor, |
jmasa@4900 | 585 | _shrink_factor, |
jmasa@4900 | 586 | _min_heap_delta_bytes / (double) K); |
jmasa@4900 | 587 | } |
jmasa@4900 | 588 | } |
jmasa@4900 | 589 | } |
jmasa@4900 | 590 | |
jmasa@4900 | 591 | if (capacity_after_gc > _capacity_at_prologue) { |
jmasa@4900 | 592 | // We might have expanded for promotions, in which case we might want to |
jmasa@4900 | 593 | // take back that expansion if there's room after GC. That keeps us from |
jmasa@4900 | 594 | // stretching the heap with promotions when there's plenty of room. |
jmasa@4900 | 595 | size_t expansion_for_promotion = capacity_after_gc - _capacity_at_prologue; |
jmasa@4900 | 596 | expansion_for_promotion = MIN2(expansion_for_promotion, max_shrink_bytes); |
jmasa@4900 | 597 | // We have two shrinking computations, take the largest |
jmasa@4900 | 598 | shrink_bytes = MAX2(shrink_bytes, expansion_for_promotion); |
jmasa@4900 | 599 | assert(shrink_bytes <= max_shrink_bytes, "invalid shrink size"); |
jmasa@4900 | 600 | if (PrintGC && Verbose) { |
jmasa@4900 | 601 | gclog_or_tty->print_cr(" " |
jmasa@4900 | 602 | " aggressive shrinking:" |
jmasa@4900 | 603 | " _capacity_at_prologue: %.1fK" |
jmasa@4900 | 604 | " capacity_after_gc: %.1fK" |
jmasa@4900 | 605 | " expansion_for_promotion: %.1fK" |
jmasa@4900 | 606 | " shrink_bytes: %.1fK", |
jmasa@4900 | 607 | capacity_after_gc / (double) K, |
jmasa@4900 | 608 | _capacity_at_prologue / (double) K, |
jmasa@4900 | 609 | expansion_for_promotion / (double) K, |
jmasa@4900 | 610 | shrink_bytes / (double) K); |
jmasa@4900 | 611 | } |
jmasa@4900 | 612 | } |
jmasa@4900 | 613 | // Don't shrink unless it's significant |
jmasa@4900 | 614 | if (shrink_bytes >= _min_heap_delta_bytes) { |
jmasa@4900 | 615 | shrink(shrink_bytes); |
jmasa@4900 | 616 | } |
jmasa@4900 | 617 | } |
jmasa@4900 | 618 | |
duke@435 | 619 | // Currently nothing to do. |
duke@435 | 620 | void CardGeneration::prepare_for_verify() {} |
duke@435 | 621 | |
duke@435 | 622 | |
duke@435 | 623 | void OneContigSpaceCardGeneration::collect(bool full, |
duke@435 | 624 | bool clear_all_soft_refs, |
duke@435 | 625 | size_t size, |
duke@435 | 626 | bool is_tlab) { |
duke@435 | 627 | SpecializationStats::clear(); |
duke@435 | 628 | // Temporarily expand the span of our ref processor, so |
duke@435 | 629 | // refs discovery is over the entire heap, not just this generation |
duke@435 | 630 | ReferenceProcessorSpanMutator |
duke@435 | 631 | x(ref_processor(), GenCollectedHeap::heap()->reserved_region()); |
duke@435 | 632 | GenMarkSweep::invoke_at_safepoint(_level, ref_processor(), clear_all_soft_refs); |
duke@435 | 633 | SpecializationStats::print(); |
duke@435 | 634 | } |
duke@435 | 635 | |
duke@435 | 636 | HeapWord* |
duke@435 | 637 | OneContigSpaceCardGeneration::expand_and_allocate(size_t word_size, |
duke@435 | 638 | bool is_tlab, |
duke@435 | 639 | bool parallel) { |
duke@435 | 640 | assert(!is_tlab, "OneContigSpaceCardGeneration does not support TLAB allocation"); |
duke@435 | 641 | if (parallel) { |
duke@435 | 642 | MutexLocker x(ParGCRareEvent_lock); |
duke@435 | 643 | HeapWord* result = NULL; |
duke@435 | 644 | size_t byte_size = word_size * HeapWordSize; |
duke@435 | 645 | while (true) { |
duke@435 | 646 | expand(byte_size, _min_heap_delta_bytes); |
duke@435 | 647 | if (GCExpandToAllocateDelayMillis > 0) { |
duke@435 | 648 | os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false); |
duke@435 | 649 | } |
duke@435 | 650 | result = _the_space->par_allocate(word_size); |
duke@435 | 651 | if ( result != NULL) { |
duke@435 | 652 | return result; |
duke@435 | 653 | } else { |
duke@435 | 654 | // If there's not enough expansion space available, give up. |
duke@435 | 655 | if (_virtual_space.uncommitted_size() < byte_size) { |
duke@435 | 656 | return NULL; |
duke@435 | 657 | } |
duke@435 | 658 | // else try again |
duke@435 | 659 | } |
duke@435 | 660 | } |
duke@435 | 661 | } else { |
duke@435 | 662 | expand(word_size*HeapWordSize, _min_heap_delta_bytes); |
duke@435 | 663 | return _the_space->allocate(word_size); |
duke@435 | 664 | } |
duke@435 | 665 | } |
duke@435 | 666 | |
jmasa@706 | 667 | bool OneContigSpaceCardGeneration::expand(size_t bytes, size_t expand_bytes) { |
duke@435 | 668 | GCMutexLocker x(ExpandHeap_lock); |
jmasa@706 | 669 | return CardGeneration::expand(bytes, expand_bytes); |
duke@435 | 670 | } |
duke@435 | 671 | |
duke@435 | 672 | |
duke@435 | 673 | void OneContigSpaceCardGeneration::shrink(size_t bytes) { |
duke@435 | 674 | assert_locked_or_safepoint(ExpandHeap_lock); |
duke@435 | 675 | size_t size = ReservedSpace::page_align_size_down(bytes); |
duke@435 | 676 | if (size > 0) { |
duke@435 | 677 | shrink_by(size); |
duke@435 | 678 | } |
duke@435 | 679 | } |
duke@435 | 680 | |
duke@435 | 681 | |
duke@435 | 682 | size_t OneContigSpaceCardGeneration::capacity() const { |
duke@435 | 683 | return _the_space->capacity(); |
duke@435 | 684 | } |
duke@435 | 685 | |
duke@435 | 686 | |
duke@435 | 687 | size_t OneContigSpaceCardGeneration::used() const { |
duke@435 | 688 | return _the_space->used(); |
duke@435 | 689 | } |
duke@435 | 690 | |
duke@435 | 691 | |
duke@435 | 692 | size_t OneContigSpaceCardGeneration::free() const { |
duke@435 | 693 | return _the_space->free(); |
duke@435 | 694 | } |
duke@435 | 695 | |
duke@435 | 696 | MemRegion OneContigSpaceCardGeneration::used_region() const { |
duke@435 | 697 | return the_space()->used_region(); |
duke@435 | 698 | } |
duke@435 | 699 | |
duke@435 | 700 | size_t OneContigSpaceCardGeneration::unsafe_max_alloc_nogc() const { |
duke@435 | 701 | return _the_space->free(); |
duke@435 | 702 | } |
duke@435 | 703 | |
duke@435 | 704 | size_t OneContigSpaceCardGeneration::contiguous_available() const { |
duke@435 | 705 | return _the_space->free() + _virtual_space.uncommitted_size(); |
duke@435 | 706 | } |
duke@435 | 707 | |
duke@435 | 708 | bool OneContigSpaceCardGeneration::grow_by(size_t bytes) { |
duke@435 | 709 | assert_locked_or_safepoint(ExpandHeap_lock); |
duke@435 | 710 | bool result = _virtual_space.expand_by(bytes); |
duke@435 | 711 | if (result) { |
duke@435 | 712 | size_t new_word_size = |
duke@435 | 713 | heap_word_size(_virtual_space.committed_size()); |
duke@435 | 714 | MemRegion mr(_the_space->bottom(), new_word_size); |
duke@435 | 715 | // Expand card table |
duke@435 | 716 | Universe::heap()->barrier_set()->resize_covered_region(mr); |
duke@435 | 717 | // Expand shared block offset array |
duke@435 | 718 | _bts->resize(new_word_size); |
duke@435 | 719 | |
duke@435 | 720 | // Fix for bug #4668531 |
jmasa@698 | 721 | if (ZapUnusedHeapArea) { |
jmasa@698 | 722 | MemRegion mangle_region(_the_space->end(), |
jmasa@698 | 723 | (HeapWord*)_virtual_space.high()); |
jmasa@698 | 724 | SpaceMangler::mangle_region(mangle_region); |
jmasa@698 | 725 | } |
duke@435 | 726 | |
duke@435 | 727 | // Expand space -- also expands space's BOT |
duke@435 | 728 | // (which uses (part of) shared array above) |
duke@435 | 729 | _the_space->set_end((HeapWord*)_virtual_space.high()); |
duke@435 | 730 | |
duke@435 | 731 | // update the space and generation capacity counters |
duke@435 | 732 | update_counters(); |
duke@435 | 733 | |
duke@435 | 734 | if (Verbose && PrintGC) { |
duke@435 | 735 | size_t new_mem_size = _virtual_space.committed_size(); |
duke@435 | 736 | size_t old_mem_size = new_mem_size - bytes; |
duke@435 | 737 | gclog_or_tty->print_cr("Expanding %s from " SIZE_FORMAT "K by " |
duke@435 | 738 | SIZE_FORMAT "K to " SIZE_FORMAT "K", |
duke@435 | 739 | name(), old_mem_size/K, bytes/K, new_mem_size/K); |
duke@435 | 740 | } |
duke@435 | 741 | } |
duke@435 | 742 | return result; |
duke@435 | 743 | } |
duke@435 | 744 | |
duke@435 | 745 | |
duke@435 | 746 | bool OneContigSpaceCardGeneration::grow_to_reserved() { |
duke@435 | 747 | assert_locked_or_safepoint(ExpandHeap_lock); |
duke@435 | 748 | bool success = true; |
duke@435 | 749 | const size_t remaining_bytes = _virtual_space.uncommitted_size(); |
duke@435 | 750 | if (remaining_bytes > 0) { |
duke@435 | 751 | success = grow_by(remaining_bytes); |
duke@435 | 752 | DEBUG_ONLY(if (!success) warning("grow to reserved failed");) |
duke@435 | 753 | } |
duke@435 | 754 | return success; |
duke@435 | 755 | } |
duke@435 | 756 | |
duke@435 | 757 | void OneContigSpaceCardGeneration::shrink_by(size_t bytes) { |
duke@435 | 758 | assert_locked_or_safepoint(ExpandHeap_lock); |
duke@435 | 759 | // Shrink committed space |
duke@435 | 760 | _virtual_space.shrink_by(bytes); |
duke@435 | 761 | // Shrink space; this also shrinks the space's BOT |
duke@435 | 762 | _the_space->set_end((HeapWord*) _virtual_space.high()); |
duke@435 | 763 | size_t new_word_size = heap_word_size(_the_space->capacity()); |
duke@435 | 764 | // Shrink the shared block offset array |
duke@435 | 765 | _bts->resize(new_word_size); |
duke@435 | 766 | MemRegion mr(_the_space->bottom(), new_word_size); |
duke@435 | 767 | // Shrink the card table |
duke@435 | 768 | Universe::heap()->barrier_set()->resize_covered_region(mr); |
duke@435 | 769 | |
duke@435 | 770 | if (Verbose && PrintGC) { |
duke@435 | 771 | size_t new_mem_size = _virtual_space.committed_size(); |
duke@435 | 772 | size_t old_mem_size = new_mem_size + bytes; |
duke@435 | 773 | gclog_or_tty->print_cr("Shrinking %s from " SIZE_FORMAT "K to " SIZE_FORMAT "K", |
duke@435 | 774 | name(), old_mem_size/K, new_mem_size/K); |
duke@435 | 775 | } |
duke@435 | 776 | } |
duke@435 | 777 | |
duke@435 | 778 | // Currently nothing to do. |
duke@435 | 779 | void OneContigSpaceCardGeneration::prepare_for_verify() {} |
duke@435 | 780 | |
duke@435 | 781 | |
ysr@1486 | 782 | // Override for a card-table generation with one contiguous |
ysr@1486 | 783 | // space. NOTE: For reasons that are lost in the fog of history, |
ysr@1486 | 784 | // this code is used when you iterate over perm gen objects, |
ysr@1486 | 785 | // even when one uses CDS, where the perm gen has a couple of |
ysr@1486 | 786 | // other spaces; this is because CompactingPermGenGen derives |
ysr@1486 | 787 | // from OneContigSpaceCardGeneration. This should be cleaned up, |
ysr@1486 | 788 | // see CR 6897789.. |
duke@435 | 789 | void OneContigSpaceCardGeneration::object_iterate(ObjectClosure* blk) { |
duke@435 | 790 | _the_space->object_iterate(blk); |
duke@435 | 791 | } |
duke@435 | 792 | |
duke@435 | 793 | void OneContigSpaceCardGeneration::space_iterate(SpaceClosure* blk, |
duke@435 | 794 | bool usedOnly) { |
duke@435 | 795 | blk->do_space(_the_space); |
duke@435 | 796 | } |
duke@435 | 797 | |
duke@435 | 798 | void OneContigSpaceCardGeneration::object_iterate_since_last_GC(ObjectClosure* blk) { |
duke@435 | 799 | // Deal with delayed initialization of _the_space, |
duke@435 | 800 | // and lack of initialization of _last_gc. |
duke@435 | 801 | if (_last_gc.space() == NULL) { |
duke@435 | 802 | assert(the_space() != NULL, "shouldn't be NULL"); |
duke@435 | 803 | _last_gc = the_space()->bottom_mark(); |
duke@435 | 804 | } |
duke@435 | 805 | the_space()->object_iterate_from(_last_gc, blk); |
duke@435 | 806 | } |
duke@435 | 807 | |
duke@435 | 808 | void OneContigSpaceCardGeneration::younger_refs_iterate(OopsInGenClosure* blk) { |
duke@435 | 809 | blk->set_generation(this); |
duke@435 | 810 | younger_refs_in_space_iterate(_the_space, blk); |
duke@435 | 811 | blk->reset_generation(); |
duke@435 | 812 | } |
duke@435 | 813 | |
duke@435 | 814 | void OneContigSpaceCardGeneration::save_marks() { |
duke@435 | 815 | _the_space->set_saved_mark(); |
duke@435 | 816 | } |
duke@435 | 817 | |
duke@435 | 818 | |
duke@435 | 819 | void OneContigSpaceCardGeneration::reset_saved_marks() { |
duke@435 | 820 | _the_space->reset_saved_mark(); |
duke@435 | 821 | } |
duke@435 | 822 | |
duke@435 | 823 | |
duke@435 | 824 | bool OneContigSpaceCardGeneration::no_allocs_since_save_marks() { |
duke@435 | 825 | return _the_space->saved_mark_at_top(); |
duke@435 | 826 | } |
duke@435 | 827 | |
duke@435 | 828 | #define OneContig_SINCE_SAVE_MARKS_ITERATE_DEFN(OopClosureType, nv_suffix) \ |
duke@435 | 829 | \ |
duke@435 | 830 | void OneContigSpaceCardGeneration:: \ |
duke@435 | 831 | oop_since_save_marks_iterate##nv_suffix(OopClosureType* blk) { \ |
duke@435 | 832 | blk->set_generation(this); \ |
duke@435 | 833 | _the_space->oop_since_save_marks_iterate##nv_suffix(blk); \ |
duke@435 | 834 | blk->reset_generation(); \ |
duke@435 | 835 | save_marks(); \ |
duke@435 | 836 | } |
duke@435 | 837 | |
duke@435 | 838 | ALL_SINCE_SAVE_MARKS_CLOSURES(OneContig_SINCE_SAVE_MARKS_ITERATE_DEFN) |
duke@435 | 839 | |
duke@435 | 840 | #undef OneContig_SINCE_SAVE_MARKS_ITERATE_DEFN |
duke@435 | 841 | |
duke@435 | 842 | |
duke@435 | 843 | void OneContigSpaceCardGeneration::gc_epilogue(bool full) { |
duke@435 | 844 | _last_gc = WaterMark(the_space(), the_space()->top()); |
duke@435 | 845 | |
duke@435 | 846 | // update the generation and space performance counters |
duke@435 | 847 | update_counters(); |
jmasa@698 | 848 | if (ZapUnusedHeapArea) { |
jmasa@698 | 849 | the_space()->check_mangled_unused_area_complete(); |
jmasa@698 | 850 | } |
jmasa@698 | 851 | } |
jmasa@698 | 852 | |
jmasa@698 | 853 | void OneContigSpaceCardGeneration::record_spaces_top() { |
jmasa@698 | 854 | assert(ZapUnusedHeapArea, "Not mangling unused space"); |
jmasa@698 | 855 | the_space()->set_top_for_allocations(); |
duke@435 | 856 | } |
duke@435 | 857 | |
brutisso@3711 | 858 | void OneContigSpaceCardGeneration::verify() { |
brutisso@3711 | 859 | the_space()->verify(); |
duke@435 | 860 | } |
duke@435 | 861 | |
duke@435 | 862 | void OneContigSpaceCardGeneration::print_on(outputStream* st) const { |
duke@435 | 863 | Generation::print_on(st); |
duke@435 | 864 | st->print(" the"); |
duke@435 | 865 | the_space()->print_on(st); |
duke@435 | 866 | } |