annotate src/share/vm/memory/generation.hpp @ 5743:fc7177e457bf

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