src/share/vm/memory/generation.hpp

Fri, 17 May 2013 06:01:10 +0200

author
jwilhelm
date
Fri, 17 May 2013 06:01:10 +0200
changeset 5125
2958af1d8c5a
parent 4900
8617e38bb4cb
child 5369
71180a6e5080
permissions
-rw-r--r--

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

mercurial