1 #ifdef USE_PRAGMA_IDENT_HDR 2 #pragma ident "@(#)generation.hpp 1.195 07/05/17 15:55:02 JVM" 3 #endif 4 /* 5 * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7 * 8 * This code is free software; you can redistribute it and/or modify it 9 * under the terms of the GNU General Public License version 2 only, as 10 * published by the Free Software Foundation. 11 * 12 * This code is distributed in the hope that it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * version 2 for more details (a copy is included in the LICENSE file that 16 * accompanied this code). 17 * 18 * You should have received a copy of the GNU General Public License version 19 * 2 along with this work; if not, write to the Free Software Foundation, 20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21 * 22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 23 * CA 95054 USA or visit www.sun.com if you need additional information or 24 * have any questions. 25 * 26 */ 27 28 // A Generation models a heap area for similarly-aged objects. 29 // It will contain one ore more spaces holding the actual objects. 30 // 31 // The Generation class hierarchy: 32 // 33 // Generation - abstract base class 34 // - DefNewGeneration - allocation area (copy collected) 35 // - ParNewGeneration - a DefNewGeneration that is collected by 36 // several threads 37 // - CardGeneration - abstract class adding offset array behavior 38 // - OneContigSpaceCardGeneration - abstract class holding a single 39 // contiguous space with card marking 40 // - TenuredGeneration - tenured (old object) space (markSweepCompact) 41 // - CompactingPermGenGen - reflective object area (klasses, methods, symbols, ...) 42 // - ConcurrentMarkSweepGeneration - Mostly Concurrent Mark Sweep Generation 43 // (Detlefs-Printezis refinement of 44 // Boehm-Demers-Schenker) 45 // 46 // The system configurations currently allowed are: 47 // 48 // DefNewGeneration + TenuredGeneration + PermGeneration 49 // DefNewGeneration + ConcurrentMarkSweepGeneration + ConcurrentMarkSweepPermGen 50 // 51 // ParNewGeneration + TenuredGeneration + PermGeneration 52 // ParNewGeneration + ConcurrentMarkSweepGeneration + ConcurrentMarkSweepPermGen 53 // 54 55 class DefNewGeneration; 56 class GenerationSpec; 57 class CompactibleSpace; 58 class ContiguousSpace; 59 class CompactPoint; 60 class OopsInGenClosure; 61 class OopClosure; 62 class ScanClosure; 63 class FastScanClosure; 64 class GenCollectedHeap; 65 class GenRemSet; 66 class GCStats; 67 68 // A "ScratchBlock" represents a block of memory in one generation usable by 69 // another. It represents "num_words" free words, starting at and including 70 // the address of "this". 71 struct ScratchBlock { 72 ScratchBlock* next; 73 size_t num_words; 74 HeapWord scratch_space[1]; // Actually, of size "num_words-2" (assuming 75 // first two fields are word-sized.) 76 }; 77 78 79 class Generation: public CHeapObj { 80 friend class VMStructs; 81 private: 82 jlong _time_of_last_gc; // time when last gc on this generation happened (ms) 83 MemRegion _prev_used_region; // for collectors that want to "remember" a value for 84 // used region at some specific point during collection. 85 86 protected: 87 // Minimum and maximum addresses for memory reserved (not necessarily 88 // committed) for generation. 89 // Used by card marking code. Must not overlap with address ranges of 90 // other generations. 91 MemRegion _reserved; 92 93 // Memory area reserved for generation 94 VirtualSpace _virtual_space; 95 96 // Level in the generation hierarchy. 97 int _level; 98 99 // ("Weak") Reference processing support 100 ReferenceProcessor* _ref_processor; 101 102 // Performance Counters 103 CollectorCounters* _gc_counters; 104 105 // Statistics for garbage collection 106 GCStats* _gc_stats; 107 108 // Returns the next generation in the configuration, or else NULL if this 109 // is the highest generation. 110 Generation* next_gen() const; 111 112 // Initialize the generation. 113 Generation(ReservedSpace rs, size_t initial_byte_size, int level); 114 115 // Apply "cl->do_oop" to (the address of) (exactly) all the ref fields in 116 // "sp" that point into younger generations. 117 // The iteration is only over objects allocated at the start of the 118 // iterations; objects allocated as a result of applying the closure are 119 // not included. 120 void younger_refs_in_space_iterate(Space* sp, OopsInGenClosure* cl); 121 122 public: 123 // The set of possible generation kinds. 124 enum Name { 125 ASParNew, 126 ASConcurrentMarkSweep, 127 DefNew, 128 ParNew, 129 MarkSweepCompact, 130 ConcurrentMarkSweep, 131 Other 132 }; 133 134 enum SomePublicConstants { 135 // Generations are GenGrain-aligned and have size that are multiples of 136 // GenGrain. 137 LogOfGenGrain = 16, 138 GenGrain = 1 << LogOfGenGrain 139 }; 140 141 // allocate and initialize ("weak") refs processing support 142 virtual void ref_processor_init(); 143 void set_ref_processor(ReferenceProcessor* rp) { 144 assert(_ref_processor == NULL, "clobbering existing _ref_processor"); 145 _ref_processor = rp; 146 } 147 148 virtual Generation::Name kind() { return Generation::Other; } 149 GenerationSpec* spec(); 150 151 // This properly belongs in the collector, but for now this 152 // will do. 153 virtual bool refs_discovery_is_atomic() const { return true; } 154 virtual bool refs_discovery_is_mt() const { return false; } 155 156 // Space enquiries (results in bytes) 157 virtual size_t capacity() const = 0; // The maximum number of object bytes the 158 // generation can currently hold. 159 virtual size_t used() const = 0; // The number of used bytes in the gen. 160 virtual size_t free() const = 0; // The number of free bytes in the gen. 161 162 // Support for java.lang.Runtime.maxMemory(); see CollectedHeap. 163 // Returns the total number of bytes available in a generation 164 // for the allocation of objects. 165 virtual size_t max_capacity() const; 166 167 // If this is a young generation, the maximum number of bytes that can be 168 // allocated in this generation before a GC is triggered. 169 virtual size_t capacity_before_gc() const { return 0; } 170 171 // The largest number of contiguous free bytes in the generation, 172 // including expansion (Assumes called at a safepoint.) 173 virtual size_t contiguous_available() const = 0; 174 // The largest number of contiguous free bytes in this or any higher generation. 175 virtual size_t max_contiguous_available() const; 176 177 // Returns true if promotions of the specified amount can 178 // be attempted safely (without a vm failure). 179 // Promotion of the full amount is not guaranteed but 180 // can be attempted. 181 // younger_handles_promotion_failure 182 // is true if the younger generation handles a promotion 183 // failure. 184 virtual bool promotion_attempt_is_safe(size_t promotion_in_bytes, 185 bool younger_handles_promotion_failure) const; 186 187 // Return an estimate of the maximum allocation that could be performed 188 // in the generation without triggering any collection or expansion 189 // activity. It is "unsafe" because no locks are taken; the result 190 // should be treated as an approximation, not a guarantee, for use in 191 // heuristic resizing decisions. 192 virtual size_t unsafe_max_alloc_nogc() const = 0; 193 194 // Returns true if this generation cannot be expanded further 195 // without a GC. Override as appropriate. 196 virtual bool is_maximal_no_gc() const { 197 return _virtual_space.uncommitted_size() == 0; 198 } 199 200 MemRegion reserved() const { return _reserved; } 201 202 // Returns a region guaranteed to contain all the objects in the 203 // generation. 204 virtual MemRegion used_region() const { return _reserved; } 205 206 MemRegion prev_used_region() const { return _prev_used_region; } 207 virtual void save_used_region() { _prev_used_region = used_region(); } 208 209 // Returns "TRUE" iff "p" points into an allocated object in the generation. 210 // For some kinds of generations, this may be an expensive operation. 211 // To avoid performance problems stemming from its inadvertent use in 212 // product jvm's, we restrict its use to assertion checking or 213 // verification only. 214 virtual bool is_in(const void* p) const; 215 216 /* Returns "TRUE" iff "p" points into the reserved area of the generation. */ 217 bool is_in_reserved(const void* p) const { 218 return _reserved.contains(p); 219 } 220 221 // Check that the generation kind is DefNewGeneration or a sub 222 // class of DefNewGeneration and return a DefNewGeneration* 223 DefNewGeneration* as_DefNewGeneration(); 224 225 // If some space in the generation contains the given "addr", return a 226 // pointer to that space, else return "NULL". 227 virtual Space* space_containing(const void* addr) const; 228 229 // Iteration - do not use for time critical operations 230 virtual void space_iterate(SpaceClosure* blk, bool usedOnly = false) = 0; 231 232 // Returns the first space, if any, in the generation that can participate 233 // in compaction, or else "NULL". 234 virtual CompactibleSpace* first_compaction_space() const = 0; 235 236 // Returns "true" iff this generation should be used to allocate an 237 // object of the given size. Young generations might 238 // wish to exclude very large objects, for example, since, if allocated 239 // often, they would greatly increase the frequency of young-gen 240 // collection. 241 virtual bool should_allocate(size_t word_size, bool is_tlab) { 242 bool result = false; 243 size_t overflow_limit = (size_t)1 << (BitsPerSize_t - LogHeapWordSize); 244 if (!is_tlab || supports_tlab_allocation()) { 245 result = (word_size > 0) && (word_size < overflow_limit); 246 } 247 return result; 248 } 249 250 // Allocate and returns a block of the requested size, or returns "NULL". 251 // Assumes the caller has done any necessary locking. 252 virtual HeapWord* allocate(size_t word_size, bool is_tlab) = 0; 253 254 // Like "allocate", but performs any necessary locking internally. 255 virtual HeapWord* par_allocate(size_t word_size, bool is_tlab) = 0; 256 257 // A 'younger' gen has reached an allocation limit, and uses this to notify 258 // the next older gen. The return value is a new limit, or NULL if none. The 259 // caller must do the necessary locking. 260 virtual HeapWord* allocation_limit_reached(Space* space, HeapWord* top, 261 size_t word_size) { 262 return NULL; 263 } 264 265 // Some generation may offer a region for shared, contiguous allocation, 266 // via inlined code (by exporting the address of the top and end fields 267 // defining the extent of the contiguous allocation region.) 268 269 // This function returns "true" iff the heap supports this kind of 270 // allocation. (More precisely, this means the style of allocation that 271 // increments *top_addr()" with a CAS.) (Default is "no".) 272 // A generation that supports this allocation style must use lock-free 273 // allocation for *all* allocation, since there are times when lock free 274 // allocation will be concurrent with plain "allocate" calls. 275 virtual bool supports_inline_contig_alloc() const { return false; } 276 277 // These functions return the addresses of the fields that define the 278 // boundaries of the contiguous allocation area. (These fields should be 279 // physicall near to one another.) 280 virtual HeapWord** top_addr() const { return NULL; } 281 virtual HeapWord** end_addr() const { return NULL; } 282 283 // Thread-local allocation buffers 284 virtual bool supports_tlab_allocation() const { return false; } 285 virtual size_t tlab_capacity() const { 286 guarantee(false, "Generation doesn't support thread local allocation buffers"); 287 return 0; 288 } 289 virtual size_t unsafe_max_tlab_alloc() const { 290 guarantee(false, "Generation doesn't support thread local allocation buffers"); 291 return 0; 292 } 293 294 // "obj" is the address of an object in a younger generation. Allocate space 295 // for "obj" in the current (or some higher) generation, and copy "obj" into 296 // the newly allocated space, if possible, returning the result (or NULL if 297 // the allocation failed). 298 // 299 // The "obj_size" argument is just obj->size(), passed along so the caller can 300 // avoid repeating the virtual call to retrieve it. 301 virtual oop promote(oop obj, size_t obj_size); 302 303 // Thread "thread_num" (0 <= i < ParalleGCThreads) wants to promote 304 // object "obj", whose original mark word was "m", and whose size is 305 // "word_sz". If possible, allocate space for "obj", copy obj into it 306 // (taking care to copy "m" into the mark word when done, since the mark 307 // word of "obj" may have been overwritten with a forwarding pointer, and 308 // also taking care to copy the klass pointer *last*. Returns the new 309 // object if successful, or else NULL. 310 virtual oop par_promote(int thread_num, 311 oop obj, markOop m, size_t word_sz); 312 313 // Undo, if possible, the most recent par_promote_alloc allocation by 314 // "thread_num" ("obj", of "word_sz"). 315 virtual void par_promote_alloc_undo(int thread_num, 316 HeapWord* obj, size_t word_sz); 317 318 // Informs the current generation that all par_promote_alloc's in the 319 // collection have been completed; any supporting data structures can be 320 // reset. Default is to do nothing. 321 virtual void par_promote_alloc_done(int thread_num) {} 322 323 // Informs the current generation that all oop_since_save_marks_iterates 324 // performed by "thread_num" in the current collection, if any, have been 325 // completed; any supporting data structures can be reset. Default is to 326 // do nothing. 327 virtual void par_oop_since_save_marks_iterate_done(int thread_num) {} 328 329 // This generation will collect all younger generations 330 // during a full collection. 331 virtual bool full_collects_younger_generations() const { return false; } 332 333 // This generation does in-place marking, meaning that mark words 334 // are mutated during the marking phase and presumably reinitialized 335 // to a canonical value after the GC. This is currently used by the 336 // biased locking implementation to determine whether additional 337 // work is required during the GC prologue and epilogue. 338 virtual bool performs_in_place_marking() const { return true; } 339 340 // Returns "true" iff collect() should subsequently be called on this 341 // this generation. See comment below. 342 // This is a generic implementation which can be overridden. 343 // 344 // Note: in the current (1.4) implementation, when genCollectedHeap's 345 // incremental_collection_will_fail flag is set, all allocations are 346 // slow path (the only fast-path place to allocate is DefNew, which 347 // will be full if the flag is set). 348 // Thus, older generations which collect younger generations should 349 // test this flag and collect if it is set. 350 virtual bool should_collect(bool full, 351 size_t word_size, 352 bool is_tlab) { 353 return (full || should_allocate(word_size, is_tlab)); 354 } 355 356 // Perform a garbage collection. 357 // If full is true attempt a full garbage collection of this generation. 358 // Otherwise, attempting to (at least) free enough space to support an 359 // allocation of the given "word_size". 360 virtual void collect(bool full, 361 bool clear_all_soft_refs, 362 size_t word_size, 363 bool is_tlab) = 0; 364 365 // Perform a heap collection, attempting to create (at least) enough 366 // space to support an allocation of the given "word_size". If 367 // successful, perform the allocation and return the resulting 368 // "oop" (initializing the allocated block). If the allocation is 369 // still unsuccessful, return "NULL". 370 virtual HeapWord* expand_and_allocate(size_t word_size, 371 bool is_tlab, 372 bool parallel = false) = 0; 373 374 // Some generations may require some cleanup or preparation actions before 375 // allowing a collection. The default is to do nothing. 376 virtual void gc_prologue(bool full) {}; 377 378 // Some generations may require some cleanup actions after a collection. 379 // The default is to do nothing. 380 virtual void gc_epilogue(bool full) {}; 381 382 // Save the high water marks for the used space in a generation. 383 virtual void record_spaces_top() {}; 384 385 // Some generations may need to be "fixed-up" after some allocation 386 // activity to make them parsable again. The default is to do nothing. 387 virtual void ensure_parsability() {}; 388 389 // Time (in ms) when we were last collected or now if a collection is 390 // in progress. 391 virtual jlong time_of_last_gc(jlong now) { 392 // XXX See note in genCollectedHeap::millis_since_last_gc() 393 NOT_PRODUCT( 394 if (now < _time_of_last_gc) { 395 warning("time warp: %d to %d", _time_of_last_gc, now); 396 } 397 ) 398 return _time_of_last_gc; 399 } 400 401 virtual void update_time_of_last_gc(jlong now) { 402 _time_of_last_gc = now; 403 } 404 405 // Generations may keep statistics about collection. This 406 // method updates those statistics. current_level is 407 // the level of the collection that has most recently 408 // occurred. This allows the generation to decide what 409 // statistics are valid to collect. For example, the 410 // generation can decide to gather the amount of promoted data 411 // if the collection of the younger generations has completed. 412 GCStats* gc_stats() const { return _gc_stats; } 413 virtual void update_gc_stats(int current_level, bool full) {} 414 415 // Mark sweep support phase2 416 virtual void prepare_for_compaction(CompactPoint* cp); 417 // Mark sweep support phase3 418 virtual void pre_adjust_pointers() {ShouldNotReachHere();} 419 virtual void adjust_pointers(); 420 // Mark sweep support phase4 421 virtual void compact(); 422 virtual void post_compact() {ShouldNotReachHere();} 423 424 // Support for CMS's rescan. In this general form we return a pointer 425 // to an abstract object that can be used, based on specific previously 426 // decided protocols, to exchange information between generations, 427 // information that may be useful for speeding up certain types of 428 // garbage collectors. A NULL value indicates to the client that 429 // no data recording is expected by the provider. The data-recorder is 430 // expected to be GC worker thread-local, with the worker index 431 // indicated by "thr_num". 432 virtual void* get_data_recorder(int thr_num) { return NULL; } 433 434 // Some generations may require some cleanup actions before allowing 435 // a verification. 436 virtual void prepare_for_verify() {}; 437 438 // Accessing "marks". 439 440 // This function gives a generation a chance to note a point between 441 // collections. For example, a contiguous generation might note the 442 // beginning allocation point post-collection, which might allow some later 443 // operations to be optimized. 444 virtual void save_marks() {} 445 446 // This function allows generations to initialize any "saved marks". That 447 // is, should only be called when the generation is empty. 448 virtual void reset_saved_marks() {} 449 450 // This function is "true" iff any no allocations have occurred in the 451 // generation since the last call to "save_marks". 452 virtual bool no_allocs_since_save_marks() = 0; 453 454 // Apply "cl->apply" to (the addresses of) all reference fields in objects 455 // allocated in the current generation since the last call to "save_marks". 456 // If more objects are allocated in this generation as a result of applying 457 // the closure, iterates over reference fields in those objects as well. 458 // Calls "save_marks" at the end of the iteration. 459 // General signature... 460 virtual void oop_since_save_marks_iterate_v(OopsInGenClosure* cl) = 0; 461 // ...and specializations for de-virtualization. (The general 462 // implemention of the _nv versions call the virtual version. 463 // Note that the _nv suffix is not really semantically necessary, 464 // but it avoids some not-so-useful warnings on Solaris.) 465 #define Generation_SINCE_SAVE_MARKS_DECL(OopClosureType, nv_suffix) \ 466 virtual void oop_since_save_marks_iterate##nv_suffix(OopClosureType* cl) { \ 467 oop_since_save_marks_iterate_v((OopsInGenClosure*)cl); \ 468 } 469 SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(Generation_SINCE_SAVE_MARKS_DECL) 470 471 #undef Generation_SINCE_SAVE_MARKS_DECL 472 473 // The "requestor" generation is performing some garbage collection 474 // action for which it would be useful to have scratch space. If 475 // the target is not the requestor, no gc actions will be required 476 // of the target. The requestor promises to allocate no more than 477 // "max_alloc_words" in the target generation (via promotion say, 478 // if the requestor is a young generation and the target is older). 479 // If the target generation can provide any scratch space, it adds 480 // it to "list", leaving "list" pointing to the head of the 481 // augmented list. The default is to offer no space. 482 virtual void contribute_scratch(ScratchBlock*& list, Generation* requestor, 483 size_t max_alloc_words) {} 484 485 // Give each generation an opportunity to do clean up for any 486 // contributed scratch. 487 virtual void reset_scratch() {}; 488 489 // When an older generation has been collected, and perhaps resized, 490 // this method will be invoked on all younger generations (from older to 491 // younger), allowing them to resize themselves as appropriate. 492 virtual void compute_new_size() = 0; 493 494 // Printing 495 virtual const char* name() const = 0; 496 virtual const char* short_name() const = 0; 497 498 int level() const { return _level; } 499 500 // Attributes 501 502 // True iff the given generation may only be the youngest generation. 503 virtual bool must_be_youngest() const = 0; 504 // True iff the given generation may only be the oldest generation. 505 virtual bool must_be_oldest() const = 0; 506 507 // Reference Processing accessor 508 ReferenceProcessor* const ref_processor() { return _ref_processor; } 509 510 // Iteration. 511 512 // Iterate over all the ref-containing fields of all objects in the 513 // generation, calling "cl.do_oop" on each. 514 virtual void oop_iterate(OopClosure* cl); 515 516 // Same as above, restricted to the intersection of a memory region and 517 // the generation. 518 virtual void oop_iterate(MemRegion mr, OopClosure* cl); 519 520 // Iterate over all objects in the generation, calling "cl.do_object" on 521 // each. 522 virtual void object_iterate(ObjectClosure* cl); 523 524 // Iterate over all objects allocated in the generation since the last 525 // collection, calling "cl.do_object" on each. The generation must have 526 // been initialized properly to support this function, or else this call 527 // will fail. 528 virtual void object_iterate_since_last_GC(ObjectClosure* cl) = 0; 529 530 // Apply "cl->do_oop" to (the address of) all and only all the ref fields 531 // in the current generation that contain pointers to objects in younger 532 // generations. Objects allocated since the last "save_marks" call are 533 // excluded. 534 virtual void younger_refs_iterate(OopsInGenClosure* cl) = 0; 535 536 // Inform a generation that it longer contains references to objects 537 // in any younger generation. [e.g. Because younger gens are empty, 538 // clear the card table.] 539 virtual void clear_remembered_set() { } 540 541 // Inform a generation that some of its objects have moved. [e.g. The 542 // generation's spaces were compacted, invalidating the card table.] 543 virtual void invalidate_remembered_set() { } 544 545 // Block abstraction. 546 547 // Returns the address of the start of the "block" that contains the 548 // address "addr". We say "blocks" instead of "object" since some heaps 549 // may not pack objects densely; a chunk may either be an object or a 550 // non-object. 551 virtual HeapWord* block_start(const void* addr) const; 552 553 // Requires "addr" to be the start of a chunk, and returns its size. 554 // "addr + size" is required to be the start of a new chunk, or the end 555 // of the active area of the heap. 556 virtual size_t block_size(const HeapWord* addr) const ; 557 558 // Requires "addr" to be the start of a block, and returns "TRUE" iff 559 // the block is an object. 560 virtual bool block_is_obj(const HeapWord* addr) const; 561 562 563 // PrintGC, PrintGCDetails support 564 void print_heap_change(size_t prev_used) const; 565 566 // PrintHeapAtGC support 567 virtual void print() const; 568 virtual void print_on(outputStream* st) const; 569 570 virtual void verify(bool allow_dirty) = 0; 571 572 struct StatRecord { 573 int invocations; 574 elapsedTimer accumulated_time; 575 StatRecord() : 576 invocations(0), 577 accumulated_time(elapsedTimer()) {} 578 }; 579 private: 580 StatRecord _stat_record; 581 public: 582 StatRecord* stat_record() { return &_stat_record; } 583 584 virtual void print_summary_info(); 585 virtual void print_summary_info_on(outputStream* st); 586 587 // Performance Counter support 588 virtual void update_counters() = 0; 589 virtual CollectorCounters* counters() { return _gc_counters; } 590 }; 591 592 // Class CardGeneration is a generation that is covered by a card table, 593 // and uses a card-size block-offset array to implement block_start. 594 595 // class BlockOffsetArray; 596 // class BlockOffsetArrayContigSpace; 597 class BlockOffsetSharedArray; 598 599 class CardGeneration: public Generation { 600 friend class VMStructs; 601 protected: 602 // This is shared with other generations. 603 GenRemSet* _rs; 604 // This is local to this generation. 605 BlockOffsetSharedArray* _bts; 606 607 CardGeneration(ReservedSpace rs, size_t initial_byte_size, int level, 608 GenRemSet* remset); 609 610 public: 611 612 // Attempt to expand the generation by "bytes". Expand by at a 613 // minimum "expand_bytes". Return true if some amount (not 614 // necessarily the full "bytes") was done. 615 virtual bool expand(size_t bytes, size_t expand_bytes); 616 617 virtual void clear_remembered_set(); 618 619 virtual void invalidate_remembered_set(); 620 621 virtual void prepare_for_verify(); 622 623 // Grow generation with specified size (returns false if unable to grow) 624 virtual bool grow_by(size_t bytes) = 0; 625 // Grow generation to reserved size. 626 virtual bool grow_to_reserved() = 0; 627 }; 628 629 // OneContigSpaceCardGeneration models a heap of old objects contained in a single 630 // contiguous space. 631 // 632 // Garbage collection is performed using mark-compact. 633 634 class OneContigSpaceCardGeneration: public CardGeneration { 635 friend class VMStructs; 636 // Abstractly, this is a subtype that gets access to protected fields. 637 friend class CompactingPermGen; 638 friend class VM_PopulateDumpSharedSpace; 639 640 protected: 641 size_t _min_heap_delta_bytes; // Minimum amount to expand. 642 ContiguousSpace* _the_space; // actual space holding objects 643 WaterMark _last_gc; // watermark between objects allocated before 644 // and after last GC. 645 646 // Grow generation with specified size (returns false if unable to grow) 647 virtual bool grow_by(size_t bytes); 648 // Grow generation to reserved size. 649 virtual bool grow_to_reserved(); 650 // Shrink generation with specified size (returns false if unable to shrink) 651 void shrink_by(size_t bytes); 652 653 // Allocation failure 654 virtual bool expand(size_t bytes, size_t expand_bytes); 655 void shrink(size_t bytes); 656 657 // Accessing spaces 658 ContiguousSpace* the_space() const { return _the_space; } 659 660 public: 661 OneContigSpaceCardGeneration(ReservedSpace rs, size_t initial_byte_size, 662 size_t min_heap_delta_bytes, 663 int level, GenRemSet* remset, 664 ContiguousSpace* space) : 665 CardGeneration(rs, initial_byte_size, level, remset), 666 _the_space(space), _min_heap_delta_bytes(min_heap_delta_bytes) 667 {} 668 669 inline bool is_in(const void* p) const; 670 671 // Space enquiries 672 size_t capacity() const; 673 size_t used() const; 674 size_t free() const; 675 676 MemRegion used_region() const; 677 678 size_t unsafe_max_alloc_nogc() const; 679 size_t contiguous_available() const; 680 681 // Iteration 682 void object_iterate(ObjectClosure* blk); 683 void space_iterate(SpaceClosure* blk, bool usedOnly = false); 684 void object_iterate_since_last_GC(ObjectClosure* cl); 685 686 void younger_refs_iterate(OopsInGenClosure* blk); 687 688 inline CompactibleSpace* first_compaction_space() const; 689 690 virtual inline HeapWord* allocate(size_t word_size, bool is_tlab); 691 virtual inline HeapWord* par_allocate(size_t word_size, bool is_tlab); 692 693 // Accessing marks 694 inline WaterMark top_mark(); 695 inline WaterMark bottom_mark(); 696 697 #define OneContig_SINCE_SAVE_MARKS_DECL(OopClosureType, nv_suffix) \ 698 void oop_since_save_marks_iterate##nv_suffix(OopClosureType* cl); 699 OneContig_SINCE_SAVE_MARKS_DECL(OopsInGenClosure,_v) 700 SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(OneContig_SINCE_SAVE_MARKS_DECL) 701 702 void save_marks(); 703 void reset_saved_marks(); 704 bool no_allocs_since_save_marks(); 705 706 inline size_t block_size(const HeapWord* addr) const; 707 708 inline bool block_is_obj(const HeapWord* addr) const; 709 710 virtual void collect(bool full, 711 bool clear_all_soft_refs, 712 size_t size, 713 bool is_tlab); 714 HeapWord* expand_and_allocate(size_t size, 715 bool is_tlab, 716 bool parallel = false); 717 718 virtual void prepare_for_verify(); 719 720 virtual void gc_epilogue(bool full); 721 722 virtual void record_spaces_top(); 723 724 virtual void verify(bool allow_dirty); 725 virtual void print_on(outputStream* st) const; 726 };