src/share/vm/memory/genCollectedHeap.hpp

Tue, 17 Oct 2017 12:58:25 +0800

author
aoqi
date
Tue, 17 Oct 2017 12:58:25 +0800
changeset 7994
04ff2f6cd0eb
parent 7659
38d6febe66af
parent 7535
7ae4e26cb1e0
child 9703
2fdf635bcf28
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2000, 2013, 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_GENCOLLECTEDHEAP_HPP
aoqi@0 26 #define SHARE_VM_MEMORY_GENCOLLECTEDHEAP_HPP
aoqi@0 27
aoqi@0 28 #include "gc_implementation/shared/adaptiveSizePolicy.hpp"
aoqi@0 29 #include "memory/collectorPolicy.hpp"
aoqi@0 30 #include "memory/generation.hpp"
aoqi@0 31 #include "memory/sharedHeap.hpp"
aoqi@0 32
aoqi@0 33 class SubTasksDone;
aoqi@0 34
aoqi@0 35 // A "GenCollectedHeap" is a SharedHeap that uses generational
aoqi@0 36 // collection. It is represented with a sequence of Generation's.
aoqi@0 37 class GenCollectedHeap : public SharedHeap {
aoqi@0 38 friend class GenCollectorPolicy;
aoqi@0 39 friend class Generation;
aoqi@0 40 friend class DefNewGeneration;
aoqi@0 41 friend class TenuredGeneration;
aoqi@0 42 friend class ConcurrentMarkSweepGeneration;
aoqi@0 43 friend class CMSCollector;
aoqi@0 44 friend class GenMarkSweep;
aoqi@0 45 friend class VM_GenCollectForAllocation;
aoqi@0 46 friend class VM_GenCollectFull;
aoqi@0 47 friend class VM_GenCollectFullConcurrent;
aoqi@0 48 friend class VM_GC_HeapInspection;
aoqi@0 49 friend class VM_HeapDumper;
aoqi@0 50 friend class HeapInspection;
aoqi@0 51 friend class GCCauseSetter;
aoqi@0 52 friend class VMStructs;
aoqi@0 53 public:
aoqi@0 54 enum SomeConstants {
aoqi@0 55 max_gens = 10
aoqi@0 56 };
aoqi@0 57
aoqi@0 58 friend class VM_PopulateDumpSharedSpace;
aoqi@0 59
aoqi@0 60 protected:
aoqi@0 61 // Fields:
aoqi@0 62 static GenCollectedHeap* _gch;
aoqi@0 63
aoqi@0 64 private:
aoqi@0 65 int _n_gens;
aoqi@0 66 Generation* _gens[max_gens];
aoqi@0 67 GenerationSpec** _gen_specs;
aoqi@0 68
aoqi@0 69 // The generational collector policy.
aoqi@0 70 GenCollectorPolicy* _gen_policy;
aoqi@0 71
aoqi@0 72 // Indicates that the most recent previous incremental collection failed.
aoqi@0 73 // The flag is cleared when an action is taken that might clear the
aoqi@0 74 // condition that caused that incremental collection to fail.
aoqi@0 75 bool _incremental_collection_failed;
aoqi@0 76
aoqi@0 77 // In support of ExplicitGCInvokesConcurrent functionality
aoqi@0 78 unsigned int _full_collections_completed;
aoqi@0 79
aoqi@0 80 // Data structure for claiming the (potentially) parallel tasks in
stefank@6992 81 // (gen-specific) roots processing.
mgerdin@7659 82 SubTasksDone* _process_strong_tasks;
aoqi@0 83
aoqi@0 84 // In block contents verification, the number of header words to skip
aoqi@0 85 NOT_PRODUCT(static size_t _skip_header_HeapWords;)
aoqi@0 86
aoqi@0 87 protected:
aoqi@0 88 // Helper functions for allocation
aoqi@0 89 HeapWord* attempt_allocation(size_t size,
aoqi@0 90 bool is_tlab,
aoqi@0 91 bool first_only);
aoqi@0 92
aoqi@0 93 // Helper function for two callbacks below.
aoqi@0 94 // Considers collection of the first max_level+1 generations.
aoqi@0 95 void do_collection(bool full,
aoqi@0 96 bool clear_all_soft_refs,
aoqi@0 97 size_t size,
aoqi@0 98 bool is_tlab,
aoqi@0 99 int max_level);
aoqi@0 100
aoqi@0 101 // Callback from VM_GenCollectForAllocation operation.
aoqi@0 102 // This function does everything necessary/possible to satisfy an
aoqi@0 103 // allocation request that failed in the youngest generation that should
aoqi@0 104 // have handled it (including collection, expansion, etc.)
aoqi@0 105 HeapWord* satisfy_failed_allocation(size_t size, bool is_tlab);
aoqi@0 106
aoqi@0 107 // Callback from VM_GenCollectFull operation.
aoqi@0 108 // Perform a full collection of the first max_level+1 generations.
aoqi@0 109 virtual void do_full_collection(bool clear_all_soft_refs);
aoqi@0 110 void do_full_collection(bool clear_all_soft_refs, int max_level);
aoqi@0 111
aoqi@0 112 // Does the "cause" of GC indicate that
aoqi@0 113 // we absolutely __must__ clear soft refs?
aoqi@0 114 bool must_clear_all_soft_refs();
aoqi@0 115
aoqi@0 116 public:
aoqi@0 117 GenCollectedHeap(GenCollectorPolicy *policy);
aoqi@0 118
aoqi@0 119 GCStats* gc_stats(int level) const;
aoqi@0 120
aoqi@0 121 // Returns JNI_OK on success
aoqi@0 122 virtual jint initialize();
aoqi@0 123 char* allocate(size_t alignment,
aoqi@0 124 size_t* _total_reserved, int* _n_covered_regions,
aoqi@0 125 ReservedSpace* heap_rs);
aoqi@0 126
aoqi@0 127 // Does operations required after initialization has been done.
aoqi@0 128 void post_initialize();
aoqi@0 129
aoqi@0 130 // Initialize ("weak") refs processing support
aoqi@0 131 virtual void ref_processing_init();
aoqi@0 132
aoqi@0 133 virtual CollectedHeap::Name kind() const {
aoqi@0 134 return CollectedHeap::GenCollectedHeap;
aoqi@0 135 }
aoqi@0 136
aoqi@0 137 // The generational collector policy.
aoqi@0 138 GenCollectorPolicy* gen_policy() const { return _gen_policy; }
aoqi@0 139 virtual CollectorPolicy* collector_policy() const { return (CollectorPolicy*) gen_policy(); }
aoqi@0 140
aoqi@0 141 // Adaptive size policy
aoqi@0 142 virtual AdaptiveSizePolicy* size_policy() {
aoqi@0 143 return gen_policy()->size_policy();
aoqi@0 144 }
aoqi@0 145
aoqi@0 146 // Return the (conservative) maximum heap alignment
aoqi@0 147 static size_t conservative_max_heap_alignment() {
aoqi@0 148 return Generation::GenGrain;
aoqi@0 149 }
aoqi@0 150
aoqi@0 151 size_t capacity() const;
aoqi@0 152 size_t used() const;
aoqi@0 153
aoqi@0 154 // Save the "used_region" for generations level and lower.
aoqi@0 155 void save_used_regions(int level);
aoqi@0 156
aoqi@0 157 size_t max_capacity() const;
aoqi@0 158
aoqi@0 159 HeapWord* mem_allocate(size_t size,
aoqi@0 160 bool* gc_overhead_limit_was_exceeded);
aoqi@0 161
aoqi@0 162 // We may support a shared contiguous allocation area, if the youngest
aoqi@0 163 // generation does.
aoqi@0 164 bool supports_inline_contig_alloc() const;
aoqi@0 165 HeapWord** top_addr() const;
aoqi@0 166 HeapWord** end_addr() const;
aoqi@0 167
aoqi@0 168 // Does this heap support heap inspection? (+PrintClassHistogram)
aoqi@0 169 virtual bool supports_heap_inspection() const { return true; }
aoqi@0 170
aoqi@0 171 // Perform a full collection of the heap; intended for use in implementing
aoqi@0 172 // "System.gc". This implies as full a collection as the CollectedHeap
aoqi@0 173 // supports. Caller does not hold the Heap_lock on entry.
aoqi@0 174 void collect(GCCause::Cause cause);
aoqi@0 175
aoqi@0 176 // The same as above but assume that the caller holds the Heap_lock.
aoqi@0 177 void collect_locked(GCCause::Cause cause);
aoqi@0 178
aoqi@0 179 // Perform a full collection of the first max_level+1 generations.
aoqi@0 180 // Mostly used for testing purposes. Caller does not hold the Heap_lock on entry.
aoqi@0 181 void collect(GCCause::Cause cause, int max_level);
aoqi@0 182
aoqi@0 183 // Returns "TRUE" iff "p" points into the committed areas of the heap.
aoqi@0 184 // The methods is_in(), is_in_closed_subset() and is_in_youngest() may
aoqi@0 185 // be expensive to compute in general, so, to prevent
aoqi@0 186 // their inadvertent use in product jvm's, we restrict their use to
aoqi@0 187 // assertion checking or verification only.
aoqi@0 188 bool is_in(const void* p) const;
aoqi@0 189
aoqi@0 190 // override
aoqi@0 191 bool is_in_closed_subset(const void* p) const {
aoqi@0 192 if (UseConcMarkSweepGC) {
aoqi@0 193 return is_in_reserved(p);
aoqi@0 194 } else {
aoqi@0 195 return is_in(p);
aoqi@0 196 }
aoqi@0 197 }
aoqi@0 198
aoqi@0 199 // Returns true if the reference is to an object in the reserved space
aoqi@0 200 // for the young generation.
aoqi@0 201 // Assumes the the young gen address range is less than that of the old gen.
aoqi@0 202 bool is_in_young(oop p);
aoqi@0 203
aoqi@0 204 #ifdef ASSERT
aoqi@0 205 virtual bool is_in_partial_collection(const void* p);
aoqi@0 206 #endif
aoqi@0 207
aoqi@0 208 virtual bool is_scavengable(const void* addr) {
aoqi@0 209 return is_in_young((oop)addr);
aoqi@0 210 }
aoqi@0 211
aoqi@0 212 // Iteration functions.
aoqi@0 213 void oop_iterate(ExtendedOopClosure* cl);
aoqi@0 214 void object_iterate(ObjectClosure* cl);
aoqi@0 215 void safe_object_iterate(ObjectClosure* cl);
aoqi@0 216 Space* space_containing(const void* addr) const;
aoqi@0 217
aoqi@0 218 // A CollectedHeap is divided into a dense sequence of "blocks"; that is,
aoqi@0 219 // each address in the (reserved) heap is a member of exactly
aoqi@0 220 // one block. The defining characteristic of a block is that it is
aoqi@0 221 // possible to find its size, and thus to progress forward to the next
aoqi@0 222 // block. (Blocks may be of different sizes.) Thus, blocks may
aoqi@0 223 // represent Java objects, or they might be free blocks in a
aoqi@0 224 // free-list-based heap (or subheap), as long as the two kinds are
aoqi@0 225 // distinguishable and the size of each is determinable.
aoqi@0 226
aoqi@0 227 // Returns the address of the start of the "block" that contains the
aoqi@0 228 // address "addr". We say "blocks" instead of "object" since some heaps
aoqi@0 229 // may not pack objects densely; a chunk may either be an object or a
aoqi@0 230 // non-object.
aoqi@0 231 virtual HeapWord* block_start(const void* addr) const;
aoqi@0 232
aoqi@0 233 // Requires "addr" to be the start of a chunk, and returns its size.
aoqi@0 234 // "addr + size" is required to be the start of a new chunk, or the end
aoqi@0 235 // of the active area of the heap. Assumes (and verifies in non-product
aoqi@0 236 // builds) that addr is in the allocated part of the heap and is
aoqi@0 237 // the start of a chunk.
aoqi@0 238 virtual size_t block_size(const HeapWord* addr) const;
aoqi@0 239
aoqi@0 240 // Requires "addr" to be the start of a block, and returns "TRUE" iff
aoqi@0 241 // the block is an object. Assumes (and verifies in non-product
aoqi@0 242 // builds) that addr is in the allocated part of the heap and is
aoqi@0 243 // the start of a chunk.
aoqi@0 244 virtual bool block_is_obj(const HeapWord* addr) const;
aoqi@0 245
aoqi@0 246 // Section on TLAB's.
aoqi@0 247 virtual bool supports_tlab_allocation() const;
aoqi@0 248 virtual size_t tlab_capacity(Thread* thr) const;
aoqi@0 249 virtual size_t tlab_used(Thread* thr) const;
aoqi@0 250 virtual size_t unsafe_max_tlab_alloc(Thread* thr) const;
aoqi@0 251 virtual HeapWord* allocate_new_tlab(size_t size);
aoqi@0 252
aoqi@0 253 // Can a compiler initialize a new object without store barriers?
aoqi@0 254 // This permission only extends from the creation of a new object
aoqi@0 255 // via a TLAB up to the first subsequent safepoint.
aoqi@0 256 virtual bool can_elide_tlab_store_barriers() const {
aoqi@0 257 return true;
aoqi@0 258 }
aoqi@0 259
aoqi@0 260 virtual bool card_mark_must_follow_store() const {
aoqi@0 261 return UseConcMarkSweepGC;
aoqi@0 262 }
aoqi@0 263
aoqi@0 264 // We don't need barriers for stores to objects in the
aoqi@0 265 // young gen and, a fortiori, for initializing stores to
aoqi@0 266 // objects therein. This applies to {DefNew,ParNew}+{Tenured,CMS}
aoqi@0 267 // only and may need to be re-examined in case other
aoqi@0 268 // kinds of collectors are implemented in the future.
aoqi@0 269 virtual bool can_elide_initializing_store_barrier(oop new_obj) {
aoqi@0 270 // We wanted to assert that:-
aoqi@0 271 // assert(UseParNewGC || UseSerialGC || UseConcMarkSweepGC,
aoqi@0 272 // "Check can_elide_initializing_store_barrier() for this collector");
aoqi@0 273 // but unfortunately the flag UseSerialGC need not necessarily always
aoqi@0 274 // be set when DefNew+Tenured are being used.
aoqi@0 275 return is_in_young(new_obj);
aoqi@0 276 }
aoqi@0 277
aoqi@0 278 // The "requestor" generation is performing some garbage collection
aoqi@0 279 // action for which it would be useful to have scratch space. The
aoqi@0 280 // requestor promises to allocate no more than "max_alloc_words" in any
aoqi@0 281 // older generation (via promotion say.) Any blocks of space that can
aoqi@0 282 // be provided are returned as a list of ScratchBlocks, sorted by
aoqi@0 283 // decreasing size.
aoqi@0 284 ScratchBlock* gather_scratch(Generation* requestor, size_t max_alloc_words);
aoqi@0 285 // Allow each generation to reset any scratch space that it has
aoqi@0 286 // contributed as it needs.
aoqi@0 287 void release_scratch();
aoqi@0 288
aoqi@0 289 // Ensure parsability: override
aoqi@0 290 virtual void ensure_parsability(bool retire_tlabs);
aoqi@0 291
aoqi@0 292 // Time in ms since the longest time a collector ran in
aoqi@0 293 // in any generation.
aoqi@0 294 virtual jlong millis_since_last_gc();
aoqi@0 295
aoqi@0 296 // Total number of full collections completed.
aoqi@0 297 unsigned int total_full_collections_completed() {
aoqi@0 298 assert(_full_collections_completed <= _total_full_collections,
aoqi@0 299 "Can't complete more collections than were started");
aoqi@0 300 return _full_collections_completed;
aoqi@0 301 }
aoqi@0 302
aoqi@0 303 // Update above counter, as appropriate, at the end of a stop-world GC cycle
aoqi@0 304 unsigned int update_full_collections_completed();
aoqi@0 305 // Update above counter, as appropriate, at the end of a concurrent GC cycle
aoqi@0 306 unsigned int update_full_collections_completed(unsigned int count);
aoqi@0 307
aoqi@0 308 // Update "time of last gc" for all constituent generations
aoqi@0 309 // to "now".
aoqi@0 310 void update_time_of_last_gc(jlong now) {
aoqi@0 311 for (int i = 0; i < _n_gens; i++) {
aoqi@0 312 _gens[i]->update_time_of_last_gc(now);
aoqi@0 313 }
aoqi@0 314 }
aoqi@0 315
aoqi@0 316 // Update the gc statistics for each generation.
aoqi@0 317 // "level" is the level of the lastest collection
aoqi@0 318 void update_gc_stats(int current_level, bool full) {
aoqi@0 319 for (int i = 0; i < _n_gens; i++) {
aoqi@0 320 _gens[i]->update_gc_stats(current_level, full);
aoqi@0 321 }
aoqi@0 322 }
aoqi@0 323
aoqi@0 324 // Override.
aoqi@0 325 bool no_gc_in_progress() { return !is_gc_active(); }
aoqi@0 326
aoqi@0 327 // Override.
aoqi@0 328 void prepare_for_verify();
aoqi@0 329
aoqi@0 330 // Override.
aoqi@0 331 void verify(bool silent, VerifyOption option);
aoqi@0 332
aoqi@0 333 // Override.
aoqi@0 334 virtual void print_on(outputStream* st) const;
aoqi@0 335 virtual void print_gc_threads_on(outputStream* st) const;
aoqi@0 336 virtual void gc_threads_do(ThreadClosure* tc) const;
aoqi@0 337 virtual void print_tracing_info() const;
aoqi@0 338 virtual void print_on_error(outputStream* st) const;
aoqi@0 339
aoqi@0 340 // PrintGC, PrintGCDetails support
aoqi@0 341 void print_heap_change(size_t prev_used) const;
aoqi@0 342
aoqi@0 343 // The functions below are helper functions that a subclass of
aoqi@0 344 // "CollectedHeap" can use in the implementation of its virtual
aoqi@0 345 // functions.
aoqi@0 346
aoqi@0 347 class GenClosure : public StackObj {
aoqi@0 348 public:
aoqi@0 349 virtual void do_generation(Generation* gen) = 0;
aoqi@0 350 };
aoqi@0 351
aoqi@0 352 // Apply "cl.do_generation" to all generations in the heap
aoqi@0 353 // If "old_to_young" determines the order.
aoqi@0 354 void generation_iterate(GenClosure* cl, bool old_to_young);
aoqi@0 355
aoqi@0 356 void space_iterate(SpaceClosure* cl);
aoqi@0 357
aoqi@0 358 // Return "true" if all generations have reached the
aoqi@0 359 // maximal committed limit that they can reach, without a garbage
aoqi@0 360 // collection.
aoqi@0 361 virtual bool is_maximal_no_gc() const;
aoqi@0 362
aoqi@0 363 // Return the generation before "gen".
aoqi@0 364 Generation* prev_gen(Generation* gen) const {
aoqi@0 365 int l = gen->level();
aoqi@0 366 guarantee(l > 0, "Out of bounds");
aoqi@0 367 return _gens[l-1];
aoqi@0 368 }
aoqi@0 369
aoqi@0 370 // Return the generation after "gen".
aoqi@0 371 Generation* next_gen(Generation* gen) const {
aoqi@0 372 int l = gen->level() + 1;
aoqi@0 373 guarantee(l < _n_gens, "Out of bounds");
aoqi@0 374 return _gens[l];
aoqi@0 375 }
aoqi@0 376
aoqi@0 377 Generation* get_gen(int i) const {
aoqi@0 378 guarantee(i >= 0 && i < _n_gens, "Out of bounds");
aoqi@0 379 return _gens[i];
aoqi@0 380 }
aoqi@0 381
aoqi@0 382 int n_gens() const {
aoqi@0 383 assert(_n_gens == gen_policy()->number_of_generations(), "Sanity");
aoqi@0 384 return _n_gens;
aoqi@0 385 }
aoqi@0 386
aoqi@0 387 // Convenience function to be used in situations where the heap type can be
aoqi@0 388 // asserted to be this type.
aoqi@0 389 static GenCollectedHeap* heap();
aoqi@0 390
aoqi@0 391 void set_par_threads(uint t);
mgerdin@7659 392 void set_n_termination(uint t);
aoqi@0 393
aoqi@0 394 // Invoke the "do_oop" method of one of the closures "not_older_gens"
aoqi@0 395 // or "older_gens" on root locations for the generation at
aoqi@0 396 // "level". (The "older_gens" closure is used for scanning references
aoqi@0 397 // from older generations; "not_older_gens" is used everywhere else.)
aoqi@0 398 // If "younger_gens_as_roots" is false, younger generations are
aoqi@0 399 // not scanned as roots; in this case, the caller must be arranging to
aoqi@0 400 // scan the younger generations itself. (For example, a generation might
aoqi@0 401 // explicitly mark reachable objects in younger generations, to avoid
aoqi@0 402 // excess storage retention.)
aoqi@0 403 // The "so" argument determines which of the roots
aoqi@0 404 // the closure is applied to:
aoqi@0 405 // "SO_None" does none;
mgerdin@7659 406 enum ScanningOption {
mgerdin@7659 407 SO_None = 0x0,
mgerdin@7659 408 SO_AllCodeCache = 0x8,
mgerdin@7659 409 SO_ScavengeCodeCache = 0x10
mgerdin@7659 410 };
mgerdin@7659 411
stefank@6992 412 private:
mgerdin@7659 413 void process_roots(bool activate_scope,
mgerdin@7659 414 ScanningOption so,
mgerdin@7659 415 OopClosure* strong_roots,
mgerdin@7659 416 OopClosure* weak_roots,
mgerdin@7659 417 CLDClosure* strong_cld_closure,
mgerdin@7659 418 CLDClosure* weak_cld_closure,
mgerdin@7659 419 CodeBlobClosure* code_roots);
mgerdin@7659 420
stefank@6992 421 void gen_process_roots(int level,
stefank@6992 422 bool younger_gens_as_roots,
stefank@6992 423 bool activate_scope,
mgerdin@7659 424 ScanningOption so,
stefank@6992 425 OopsInGenClosure* not_older_gens,
stefank@6992 426 OopsInGenClosure* weak_roots,
stefank@6992 427 OopsInGenClosure* older_gens,
stefank@6992 428 CLDClosure* cld_closure,
stefank@6992 429 CLDClosure* weak_cld_closure,
stefank@6992 430 CodeBlobClosure* code_closure);
aoqi@0 431
stefank@6992 432 public:
stefank@6992 433 static const bool StrongAndWeakRoots = false;
stefank@6992 434 static const bool StrongRootsOnly = true;
stefank@6992 435
stefank@6992 436 void gen_process_roots(int level,
stefank@6992 437 bool younger_gens_as_roots,
stefank@6992 438 bool activate_scope,
mgerdin@7659 439 ScanningOption so,
stefank@6992 440 bool only_strong_roots,
stefank@6992 441 OopsInGenClosure* not_older_gens,
stefank@6992 442 OopsInGenClosure* older_gens,
stefank@6992 443 CLDClosure* cld_closure);
brutisso@6376 444
stefank@6971 445 // Apply "root_closure" to all the weak roots of the system.
stefank@6971 446 // These include JNI weak roots, string table,
stefank@6971 447 // and referents of reachable weak refs.
stefank@6971 448 void gen_process_weak_roots(OopClosure* root_closure);
aoqi@0 449
aoqi@0 450 // Set the saved marks of generations, if that makes sense.
aoqi@0 451 // In particular, if any generation might iterate over the oops
aoqi@0 452 // in other generations, it should call this method.
aoqi@0 453 void save_marks();
aoqi@0 454
aoqi@0 455 // Apply "cur->do_oop" or "older->do_oop" to all the oops in objects
aoqi@0 456 // allocated since the last call to save_marks in generations at or above
aoqi@0 457 // "level". The "cur" closure is
aoqi@0 458 // applied to references in the generation at "level", and the "older"
aoqi@0 459 // closure to older generations.
aoqi@0 460 #define GCH_SINCE_SAVE_MARKS_ITERATE_DECL(OopClosureType, nv_suffix) \
aoqi@0 461 void oop_since_save_marks_iterate(int level, \
aoqi@0 462 OopClosureType* cur, \
aoqi@0 463 OopClosureType* older);
aoqi@0 464
aoqi@0 465 ALL_SINCE_SAVE_MARKS_CLOSURES(GCH_SINCE_SAVE_MARKS_ITERATE_DECL)
aoqi@0 466
aoqi@0 467 #undef GCH_SINCE_SAVE_MARKS_ITERATE_DECL
aoqi@0 468
aoqi@0 469 // Returns "true" iff no allocations have occurred in any generation at
aoqi@0 470 // "level" or above since the last
aoqi@0 471 // call to "save_marks".
aoqi@0 472 bool no_allocs_since_save_marks(int level);
aoqi@0 473
aoqi@0 474 // Returns true if an incremental collection is likely to fail.
aoqi@0 475 // We optionally consult the young gen, if asked to do so;
aoqi@0 476 // otherwise we base our answer on whether the previous incremental
aoqi@0 477 // collection attempt failed with no corrective action as of yet.
aoqi@0 478 bool incremental_collection_will_fail(bool consult_young) {
aoqi@0 479 // Assumes a 2-generation system; the first disjunct remembers if an
aoqi@0 480 // incremental collection failed, even when we thought (second disjunct)
aoqi@0 481 // that it would not.
aoqi@0 482 assert(heap()->collector_policy()->is_two_generation_policy(),
aoqi@0 483 "the following definition may not be suitable for an n(>2)-generation system");
aoqi@0 484 return incremental_collection_failed() ||
aoqi@0 485 (consult_young && !get_gen(0)->collection_attempt_is_safe());
aoqi@0 486 }
aoqi@0 487
aoqi@0 488 // If a generation bails out of an incremental collection,
aoqi@0 489 // it sets this flag.
aoqi@0 490 bool incremental_collection_failed() const {
aoqi@0 491 return _incremental_collection_failed;
aoqi@0 492 }
aoqi@0 493 void set_incremental_collection_failed() {
aoqi@0 494 _incremental_collection_failed = true;
aoqi@0 495 }
aoqi@0 496 void clear_incremental_collection_failed() {
aoqi@0 497 _incremental_collection_failed = false;
aoqi@0 498 }
aoqi@0 499
aoqi@0 500 // Promotion of obj into gen failed. Try to promote obj to higher
aoqi@0 501 // gens in ascending order; return the new location of obj if successful.
aoqi@0 502 // Otherwise, try expand-and-allocate for obj in both the young and old
aoqi@0 503 // generation; return the new location of obj if successful. Otherwise, return NULL.
aoqi@0 504 oop handle_failed_promotion(Generation* old_gen,
aoqi@0 505 oop obj,
aoqi@0 506 size_t obj_size);
aoqi@0 507
aoqi@0 508 private:
aoqi@0 509 // Accessor for memory state verification support
aoqi@0 510 NOT_PRODUCT(
aoqi@0 511 static size_t skip_header_HeapWords() { return _skip_header_HeapWords; }
aoqi@0 512 )
aoqi@0 513
aoqi@0 514 // Override
aoqi@0 515 void check_for_non_bad_heap_word_value(HeapWord* addr,
aoqi@0 516 size_t size) PRODUCT_RETURN;
aoqi@0 517
aoqi@0 518 // For use by mark-sweep. As implemented, mark-sweep-compact is global
aoqi@0 519 // in an essential way: compaction is performed across generations, by
aoqi@0 520 // iterating over spaces.
aoqi@0 521 void prepare_for_compaction();
aoqi@0 522
aoqi@0 523 // Perform a full collection of the first max_level+1 generations.
aoqi@0 524 // This is the low level interface used by the public versions of
aoqi@0 525 // collect() and collect_locked(). Caller holds the Heap_lock on entry.
aoqi@0 526 void collect_locked(GCCause::Cause cause, int max_level);
aoqi@0 527
aoqi@0 528 // Returns success or failure.
aoqi@0 529 bool create_cms_collector();
aoqi@0 530
aoqi@0 531 // In support of ExplicitGCInvokesConcurrent functionality
aoqi@0 532 bool should_do_concurrent_full_gc(GCCause::Cause cause);
aoqi@0 533 void collect_mostly_concurrent(GCCause::Cause cause);
aoqi@0 534
aoqi@0 535 // Save the tops of the spaces in all generations
aoqi@0 536 void record_gen_tops_before_GC() PRODUCT_RETURN;
aoqi@0 537
aoqi@0 538 protected:
aoqi@0 539 virtual void gc_prologue(bool full);
aoqi@0 540 virtual void gc_epilogue(bool full);
aoqi@0 541 };
aoqi@0 542
aoqi@0 543 #endif // SHARE_VM_MEMORY_GENCOLLECTEDHEAP_HPP

mercurial