src/share/vm/memory/generation.hpp

Thu, 12 Oct 2017 21:27:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 21:27:07 +0800
changeset 7535
7ae4e26cb1e0
parent 6978
30c99d8e0f02
parent 6876
710a3c8b516e
child 7994
04ff2f6cd0eb
permissions
-rw-r--r--

merge

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

mercurial