1 /*
   2  * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_GC_SHARED_COLLECTEDHEAP_HPP
  26 #define SHARE_VM_GC_SHARED_COLLECTEDHEAP_HPP
  27 
  28 #include "gc/shared/gcCause.hpp"
  29 #include "gc/shared/gcWhen.hpp"
  30 #include "memory/allocation.hpp"
  31 #include "runtime/handles.hpp"
  32 #include "runtime/perfData.hpp"
  33 #include "runtime/safepoint.hpp"
  34 #include "utilities/debug.hpp"
  35 #include "utilities/events.hpp"
  36 #include "utilities/formatBuffer.hpp"
  37 #include "utilities/growableArray.hpp"
  38 
  39 // A "CollectedHeap" is an implementation of a java heap for HotSpot.  This
  40 // is an abstract class: there may be many different kinds of heaps.  This
  41 // class defines the functions that a heap must implement, and contains
  42 // infrastructure common to all heaps.
  43 
  44 class AdaptiveSizePolicy;
  45 class BarrierSet;
  46 class CollectorPolicy;
  47 class GCHeapSummary;
  48 class GCTimer;
  49 class GCTracer;
  50 class GCMemoryManager;
  51 class MemoryPool;
  52 class MetaspaceSummary;
  53 class SoftRefPolicy;
  54 class Thread;
  55 class ThreadClosure;
  56 class VirtualSpaceSummary;
  57 class WorkGang;
  58 class nmethod;
  59 
  60 class GCMessage : public FormatBuffer<1024> {
  61  public:
  62   bool is_before;
  63 
  64  public:
  65   GCMessage() {}
  66 };
  67 
  68 class CollectedHeap;
  69 
  70 class GCHeapLog : public EventLogBase<GCMessage> {
  71  private:
  72   void log_heap(CollectedHeap* heap, bool before);
  73 
  74  public:
  75   GCHeapLog() : EventLogBase<GCMessage>("GC Heap History") {}
  76 
  77   void log_heap_before(CollectedHeap* heap) {
  78     log_heap(heap, true);
  79   }
  80   void log_heap_after(CollectedHeap* heap) {
  81     log_heap(heap, false);
  82   }
  83 };
  84 
  85 //
  86 // CollectedHeap
  87 //   GenCollectedHeap
  88 //     SerialHeap
  89 //     CMSHeap
  90 //   G1CollectedHeap
  91 //   ShenandoahHeap
  92 //   ParallelScavengeHeap
  93 //
  94 class CollectedHeap : public CHeapObj<mtInternal> {
  95   friend class VMStructs;
  96   friend class JVMCIVMStructs;
  97   friend class IsGCActiveMark; // Block structured external access to _is_gc_active
  98 
  99  private:
 100 #ifdef ASSERT
 101   static int       _fire_out_of_memory_count;
 102 #endif
 103 
 104   GCHeapLog* _gc_heap_log;
 105 
 106   MemRegion _reserved;
 107 
 108  protected:
 109   bool _is_gc_active;
 110 
 111   // Used for filler objects (static, but initialized in ctor).
 112   static size_t _filler_array_max_size;
 113 
 114   unsigned int _total_collections;          // ... started
 115   unsigned int _total_full_collections;     // ... started
 116   NOT_PRODUCT(volatile size_t _promotion_failure_alot_count;)
 117   NOT_PRODUCT(volatile size_t _promotion_failure_alot_gc_number;)
 118 
 119   // Reason for current garbage collection.  Should be set to
 120   // a value reflecting no collection between collections.
 121   GCCause::Cause _gc_cause;
 122   GCCause::Cause _gc_lastcause;
 123   PerfStringVariable* _perf_gc_cause;
 124   PerfStringVariable* _perf_gc_lastcause;
 125 
 126   // Constructor
 127   CollectedHeap();
 128 
 129   // Create a new tlab. All TLAB allocations must go through this.
 130   virtual HeapWord* allocate_new_tlab(size_t size);
 131 
 132   // Accumulate statistics on all tlabs.
 133   virtual void accumulate_statistics_all_tlabs();
 134 
 135   // Reinitialize tlabs before resuming mutators.
 136   virtual void resize_all_tlabs();
 137 
 138   // Allocate from the current thread's TLAB, with broken-out slow path.
 139   inline static HeapWord* allocate_from_tlab(Klass* klass, Thread* thread, size_t size);
 140   static HeapWord* allocate_from_tlab_slow(Klass* klass, Thread* thread, size_t size);
 141 
 142   // Allocate an uninitialized block of the given size, or returns NULL if
 143   // this is impossible.
 144   inline static HeapWord* common_mem_allocate_noinit(Klass* klass, size_t size, TRAPS);
 145 
 146   // Like allocate_init, but the block returned by a successful allocation
 147   // is guaranteed initialized to zeros.
 148   inline static HeapWord* common_mem_allocate_init(Klass* klass, size_t size, TRAPS);
 149 
 150   // Helper functions for (VM) allocation.
 151   inline static void post_allocation_setup_common(Klass* klass, HeapWord* obj);
 152   inline static void post_allocation_setup_no_klass_install(Klass* klass,
 153                                                             HeapWord* objPtr);
 154 
 155   inline static void post_allocation_setup_obj(Klass* klass, HeapWord* obj, int size);
 156 
 157   inline static void post_allocation_setup_array(Klass* klass,
 158                                                  HeapWord* obj, int length);
 159 
 160   inline static void post_allocation_setup_class(Klass* klass, HeapWord* obj, int size);
 161 
 162   // Clears an allocated object.
 163   inline static void init_obj(HeapWord* obj, size_t size);
 164 
 165   // Filler object utilities.
 166   static inline size_t filler_array_hdr_size();
 167   static inline size_t filler_array_min_size();
 168 
 169   DEBUG_ONLY(static void fill_args_check(HeapWord* start, size_t words);)
 170   DEBUG_ONLY(static void zap_filler_array(HeapWord* start, size_t words, bool zap = true);)
 171 
 172   // Fill with a single array; caller must ensure filler_array_min_size() <=
 173   // words <= filler_array_max_size().
 174   static inline void fill_with_array(HeapWord* start, size_t words, bool zap = true);
 175 
 176   // Fill with a single object (either an int array or a java.lang.Object).
 177   static inline void fill_with_object_impl(HeapWord* start, size_t words, bool zap = true);
 178 
 179   virtual void trace_heap(GCWhen::Type when, const GCTracer* tracer);
 180 
 181   // Verification functions
 182   virtual void check_for_bad_heap_word_value(HeapWord* addr, size_t size)
 183     PRODUCT_RETURN;
 184   virtual void check_for_non_bad_heap_word_value(HeapWord* addr, size_t size)
 185     PRODUCT_RETURN;
 186   debug_only(static void check_for_valid_allocation_state();)
 187 
 188  public:
 189   enum Name {
 190     None,
 191     Serial,
 192     Parallel,
 193     CMS,
 194     G1,
 195     Shenandoah
 196   };
 197 
 198   static inline size_t filler_array_max_size() {
 199     return _filler_array_max_size;
 200   }
 201 
 202   virtual Name kind() const = 0;
 203 
 204   virtual HeapWord* tlab_post_allocation_setup(HeapWord* obj);
 205 
 206   virtual const char* name() const = 0;
 207 
 208   /**
 209    * Returns JNI error code JNI_ENOMEM if memory could not be allocated,
 210    * and JNI_OK on success.
 211    */
 212   virtual jint initialize() = 0;
 213 
 214   // In many heaps, there will be a need to perform some initialization activities
 215   // after the Universe is fully formed, but before general heap allocation is allowed.
 216   // This is the correct place to place such initialization methods.
 217   virtual void post_initialize();
 218 
 219   // Stop any onging concurrent work and prepare for exit.
 220   virtual void stop() {}
 221 
 222   // Stop and resume concurrent GC threads interfering with safepoint operations
 223   virtual void safepoint_synchronize_begin() {}
 224   virtual void safepoint_synchronize_end() {}
 225 
 226   void initialize_reserved_region(HeapWord *start, HeapWord *end);
 227   MemRegion reserved_region() const { return _reserved; }
 228   address base() const { return (address)reserved_region().start(); }
 229 
 230   virtual size_t capacity() const = 0;
 231   virtual size_t used() const = 0;
 232 
 233   // Return "true" if the part of the heap that allocates Java
 234   // objects has reached the maximal committed limit that it can
 235   // reach, without a garbage collection.
 236   virtual bool is_maximal_no_gc() const = 0;
 237 
 238   // Support for java.lang.Runtime.maxMemory():  return the maximum amount of
 239   // memory that the vm could make available for storing 'normal' java objects.
 240   // This is based on the reserved address space, but should not include space
 241   // that the vm uses internally for bookkeeping or temporary storage
 242   // (e.g., in the case of the young gen, one of the survivor
 243   // spaces).
 244   virtual size_t max_capacity() const = 0;
 245 
 246   // Returns "TRUE" if "p" points into the reserved area of the heap.
 247   bool is_in_reserved(const void* p) const {
 248     return _reserved.contains(p);
 249   }
 250 
 251   bool is_in_reserved_or_null(const void* p) const {
 252     return p == NULL || is_in_reserved(p);
 253   }
 254 
 255   // Returns "TRUE" iff "p" points into the committed areas of the heap.
 256   // This method can be expensive so avoid using it in performance critical
 257   // code.
 258   virtual bool is_in(const void* p) const = 0;
 259 
 260   DEBUG_ONLY(bool is_in_or_null(const void* p) const { return p == NULL || is_in(p); })
 261 
 262   // Let's define some terms: a "closed" subset of a heap is one that
 263   //
 264   // 1) contains all currently-allocated objects, and
 265   //
 266   // 2) is closed under reference: no object in the closed subset
 267   //    references one outside the closed subset.
 268   //
 269   // Membership in a heap's closed subset is useful for assertions.
 270   // Clearly, the entire heap is a closed subset, so the default
 271   // implementation is to use "is_in_reserved".  But this may not be too
 272   // liberal to perform useful checking.  Also, the "is_in" predicate
 273   // defines a closed subset, but may be too expensive, since "is_in"
 274   // verifies that its argument points to an object head.  The
 275   // "closed_subset" method allows a heap to define an intermediate
 276   // predicate, allowing more precise checking than "is_in_reserved" at
 277   // lower cost than "is_in."
 278 
 279   // One important case is a heap composed of disjoint contiguous spaces,
 280   // such as the Garbage-First collector.  Such heaps have a convenient
 281   // closed subset consisting of the allocated portions of those
 282   // contiguous spaces.
 283 
 284   // Return "TRUE" iff the given pointer points into the heap's defined
 285   // closed subset (which defaults to the entire heap).
 286   virtual bool is_in_closed_subset(const void* p) const {
 287     return is_in_reserved(p);
 288   }
 289 
 290   bool is_in_closed_subset_or_null(const void* p) const {
 291     return p == NULL || is_in_closed_subset(p);
 292   }
 293 
 294   void set_gc_cause(GCCause::Cause v) {
 295      if (UsePerfData) {
 296        _gc_lastcause = _gc_cause;
 297        _perf_gc_lastcause->set_value(GCCause::to_string(_gc_lastcause));
 298        _perf_gc_cause->set_value(GCCause::to_string(v));
 299      }
 300     _gc_cause = v;
 301   }
 302   GCCause::Cause gc_cause() { return _gc_cause; }
 303 
 304   // General obj/array allocation facilities.
 305   inline static oop obj_allocate(Klass* klass, int size, TRAPS);
 306   inline static oop array_allocate(Klass* klass, int size, int length, TRAPS);
 307   inline static oop array_allocate_nozero(Klass* klass, int size, int length, TRAPS);
 308   inline static oop class_allocate(Klass* klass, int size, TRAPS);
 309 
 310   virtual uint oop_extra_words();
 311 
 312 #ifndef CC_INTERP
 313   virtual void compile_prepare_oop(MacroAssembler* masm, Register obj);
 314 #endif
 315 
 316   // Raw memory allocation facilities
 317   // The obj and array allocate methods are covers for these methods.
 318   // mem_allocate() should never be
 319   // called to allocate TLABs, only individual objects.
 320   virtual HeapWord* mem_allocate(size_t size,
 321                                  bool* gc_overhead_limit_was_exceeded) = 0;
 322 
 323   // Utilities for turning raw memory into filler objects.
 324   //
 325   // min_fill_size() is the smallest region that can be filled.
 326   // fill_with_objects() can fill arbitrary-sized regions of the heap using
 327   // multiple objects.  fill_with_object() is for regions known to be smaller
 328   // than the largest array of integers; it uses a single object to fill the
 329   // region and has slightly less overhead.
 330   static size_t min_fill_size() {
 331     return size_t(align_object_size(oopDesc::header_size()));
 332   }
 333 
 334   static void fill_with_objects(HeapWord* start, size_t words, bool zap = true);
 335 
 336   static void fill_with_object(HeapWord* start, size_t words, bool zap = true);
 337   static void fill_with_object(MemRegion region, bool zap = true) {
 338     fill_with_object(region.start(), region.word_size(), zap);
 339   }
 340   static void fill_with_object(HeapWord* start, HeapWord* end, bool zap = true) {
 341     fill_with_object(start, pointer_delta(end, start), zap);
 342   }
 343 
 344   // Return the address "addr" aligned by "alignment_in_bytes" if such
 345   // an address is below "end".  Return NULL otherwise.
 346   inline static HeapWord* align_allocation_or_fail(HeapWord* addr,
 347                                                    HeapWord* end,
 348                                                    unsigned short alignment_in_bytes);
 349 
 350   // Some heaps may offer a contiguous region for shared non-blocking
 351   // allocation, via inlined code (by exporting the address of the top and
 352   // end fields defining the extent of the contiguous allocation region.)
 353 
 354   // This function returns "true" iff the heap supports this kind of
 355   // allocation.  (Default is "no".)
 356   virtual bool supports_inline_contig_alloc() const {
 357     return false;
 358   }
 359   // These functions return the addresses of the fields that define the
 360   // boundaries of the contiguous allocation area.  (These fields should be
 361   // physically near to one another.)
 362   virtual HeapWord* volatile* top_addr() const {
 363     guarantee(false, "inline contiguous allocation not supported");
 364     return NULL;
 365   }
 366   virtual HeapWord** end_addr() const {
 367     guarantee(false, "inline contiguous allocation not supported");
 368     return NULL;
 369   }
 370 
 371   // Some heaps may be in an unparseable state at certain times between
 372   // collections. This may be necessary for efficient implementation of
 373   // certain allocation-related activities. Calling this function before
 374   // attempting to parse a heap ensures that the heap is in a parsable
 375   // state (provided other concurrent activity does not introduce
 376   // unparsability). It is normally expected, therefore, that this
 377   // method is invoked with the world stopped.
 378   // NOTE: if you override this method, make sure you call
 379   // super::ensure_parsability so that the non-generational
 380   // part of the work gets done. See implementation of
 381   // CollectedHeap::ensure_parsability and, for instance,
 382   // that of GenCollectedHeap::ensure_parsability().
 383   // The argument "retire_tlabs" controls whether existing TLABs
 384   // are merely filled or also retired, thus preventing further
 385   // allocation from them and necessitating allocation of new TLABs.
 386   virtual void ensure_parsability(bool retire_tlabs);
 387 
 388   // Section on thread-local allocation buffers (TLABs)
 389   // If the heap supports thread-local allocation buffers, it should override
 390   // the following methods:
 391   // Returns "true" iff the heap supports thread-local allocation buffers.
 392   // The default is "no".
 393   virtual bool supports_tlab_allocation() const = 0;
 394 
 395   // The amount of space available for thread-local allocation buffers.
 396   virtual size_t tlab_capacity(Thread *thr) const = 0;
 397 
 398   // The amount of used space for thread-local allocation buffers for the given thread.
 399   virtual size_t tlab_used(Thread *thr) const = 0;
 400 
 401   virtual size_t max_tlab_size() const;
 402 
 403   // An estimate of the maximum allocation that could be performed
 404   // for thread-local allocation buffers without triggering any
 405   // collection or expansion activity.
 406   virtual size_t unsafe_max_tlab_alloc(Thread *thr) const {
 407     guarantee(false, "thread-local allocation buffers not supported");
 408     return 0;
 409   }
 410 
 411   // Perform a collection of the heap; intended for use in implementing
 412   // "System.gc".  This probably implies as full a collection as the
 413   // "CollectedHeap" supports.
 414   virtual void collect(GCCause::Cause cause) = 0;
 415 
 416   // Perform a full collection
 417   virtual void do_full_collection(bool clear_all_soft_refs) = 0;
 418 
 419   // This interface assumes that it's being called by the
 420   // vm thread. It collects the heap assuming that the
 421   // heap lock is already held and that we are executing in
 422   // the context of the vm thread.
 423   virtual void collect_as_vm_thread(GCCause::Cause cause);
 424 
 425   virtual MetaWord* satisfy_failed_metadata_allocation(ClassLoaderData* loader_data,
 426                                                        size_t size,
 427                                                        Metaspace::MetadataType mdtype);
 428 
 429   // Returns "true" iff there is a stop-world GC in progress.  (I assume
 430   // that it should answer "false" for the concurrent part of a concurrent
 431   // collector -- dld).
 432   bool is_gc_active() const { return _is_gc_active; }
 433 
 434   // Total number of GC collections (started)
 435   unsigned int total_collections() const { return _total_collections; }
 436   unsigned int total_full_collections() const { return _total_full_collections;}
 437 
 438   // Increment total number of GC collections (started)
 439   // Should be protected but used by PSMarkSweep - cleanup for 1.4.2
 440   void increment_total_collections(bool full = false) {
 441     _total_collections++;
 442     if (full) {
 443       increment_total_full_collections();
 444     }
 445   }
 446 
 447   void increment_total_full_collections() { _total_full_collections++; }
 448 
 449   // Return the CollectorPolicy for the heap
 450   virtual CollectorPolicy* collector_policy() const = 0;
 451 
 452   // Return the SoftRefPolicy for the heap;
 453   virtual SoftRefPolicy* soft_ref_policy() = 0;
 454 
 455   virtual GrowableArray<GCMemoryManager*> memory_managers() = 0;
 456   virtual GrowableArray<MemoryPool*> memory_pools() = 0;
 457 
 458   // Iterate over all objects, calling "cl.do_object" on each.
 459   virtual void object_iterate(ObjectClosure* cl) = 0;
 460 
 461   // Similar to object_iterate() except iterates only
 462   // over live objects.
 463   virtual void safe_object_iterate(ObjectClosure* cl) = 0;
 464 
 465   // NOTE! There is no requirement that a collector implement these
 466   // functions.
 467   //
 468   // A CollectedHeap is divided into a dense sequence of "blocks"; that is,
 469   // each address in the (reserved) heap is a member of exactly
 470   // one block.  The defining characteristic of a block is that it is
 471   // possible to find its size, and thus to progress forward to the next
 472   // block.  (Blocks may be of different sizes.)  Thus, blocks may
 473   // represent Java objects, or they might be free blocks in a
 474   // free-list-based heap (or subheap), as long as the two kinds are
 475   // distinguishable and the size of each is determinable.
 476 
 477   // Returns the address of the start of the "block" that contains the
 478   // address "addr".  We say "blocks" instead of "object" since some heaps
 479   // may not pack objects densely; a chunk may either be an object or a
 480   // non-object.
 481   virtual HeapWord* block_start(const void* addr) const = 0;
 482 
 483   // Requires "addr" to be the start of a chunk, and returns its size.
 484   // "addr + size" is required to be the start of a new chunk, or the end
 485   // of the active area of the heap.
 486   virtual size_t block_size(const HeapWord* addr) const = 0;
 487 
 488   // Requires "addr" to be the start of a block, and returns "TRUE" iff
 489   // the block is an object.
 490   virtual bool block_is_obj(const HeapWord* addr) const = 0;
 491 
 492   // Returns the longest time (in ms) that has elapsed since the last
 493   // time that any part of the heap was examined by a garbage collection.
 494   virtual jlong millis_since_last_gc() = 0;
 495 
 496   // Perform any cleanup actions necessary before allowing a verification.
 497   virtual void prepare_for_verify() = 0;
 498 
 499   // Generate any dumps preceding or following a full gc
 500  private:
 501   void full_gc_dump(GCTimer* timer, bool before);
 502 
 503   virtual void initialize_serviceability() = 0;
 504 
 505  public:
 506   void pre_full_gc_dump(GCTimer* timer);
 507   void post_full_gc_dump(GCTimer* timer);
 508 
 509   virtual VirtualSpaceSummary create_heap_space_summary();
 510   GCHeapSummary create_heap_summary();
 511 
 512   MetaspaceSummary create_metaspace_summary();
 513 
 514   // Print heap information on the given outputStream.
 515   virtual void print_on(outputStream* st) const = 0;
 516   // The default behavior is to call print_on() on tty.
 517   virtual void print() const {
 518     print_on(tty);
 519   }
 520   // Print more detailed heap information on the given
 521   // outputStream. The default behavior is to call print_on(). It is
 522   // up to each subclass to override it and add any additional output
 523   // it needs.
 524   virtual void print_extended_on(outputStream* st) const {
 525     print_on(st);
 526   }
 527 
 528   virtual void print_on_error(outputStream* st) const;
 529 
 530   // Print all GC threads (other than the VM thread)
 531   // used by this heap.
 532   virtual void print_gc_threads_on(outputStream* st) const = 0;
 533   // The default behavior is to call print_gc_threads_on() on tty.
 534   void print_gc_threads() {
 535     print_gc_threads_on(tty);
 536   }
 537   // Iterator for all GC threads (other than VM thread)
 538   virtual void gc_threads_do(ThreadClosure* tc) const = 0;
 539 
 540   // Print any relevant tracing info that flags imply.
 541   // Default implementation does nothing.
 542   virtual void print_tracing_info() const = 0;
 543 
 544   void print_heap_before_gc();
 545   void print_heap_after_gc();
 546 
 547   // An object is scavengable if its location may move during a scavenge.
 548   // (A scavenge is a GC which is not a full GC.)
 549   virtual bool is_scavengable(oop obj) = 0;
 550   // Registering and unregistering an nmethod (compiled code) with the heap.
 551   // Override with specific mechanism for each specialized heap type.
 552   virtual void register_nmethod(nmethod* nm) {}
 553   virtual void unregister_nmethod(nmethod* nm) {}
 554   virtual void verify_nmethod(nmethod* nmethod) {}
 555 
 556   void trace_heap_before_gc(const GCTracer* gc_tracer);
 557   void trace_heap_after_gc(const GCTracer* gc_tracer);
 558 
 559   // Heap verification
 560   virtual void verify(VerifyOption option) = 0;
 561 
 562   // Return true if concurrent phase control (via
 563   // request_concurrent_phase_control) is supported by this collector.
 564   // The default implementation returns false.
 565   virtual bool supports_concurrent_phase_control() const;
 566 
 567   // Return a NULL terminated array of concurrent phase names provided
 568   // by this collector.  Supports Whitebox testing.  These are the
 569   // names recognized by request_concurrent_phase(). The default
 570   // implementation returns an array of one NULL element.
 571   virtual const char* const* concurrent_phases() const;
 572 
 573   // Request the collector enter the indicated concurrent phase, and
 574   // wait until it does so.  Supports WhiteBox testing.  Only one
 575   // request may be active at a time.  Phases are designated by name;
 576   // the set of names and their meaning is GC-specific.  Once the
 577   // requested phase has been reached, the collector will attempt to
 578   // avoid transitioning to a new phase until a new request is made.
 579   // [Note: A collector might not be able to remain in a given phase.
 580   // For example, a full collection might cancel an in-progress
 581   // concurrent collection.]
 582   //
 583   // Returns true when the phase is reached.  Returns false for an
 584   // unknown phase.  The default implementation returns false.
 585   virtual bool request_concurrent_phase(const char* phase);
 586 
 587   // Provides a thread pool to SafepointSynchronize to use
 588   // for parallel safepoint cleanup.
 589   // GCs that use a GC worker thread pool may want to share
 590   // it for use during safepoint cleanup. This is only possible
 591   // if the GC can pause and resume concurrent work (e.g. G1
 592   // concurrent marking) for an intermittent non-GC safepoint.
 593   // If this method returns NULL, SafepointSynchronize will
 594   // perform cleanup tasks serially in the VMThread.
 595   virtual WorkGang* get_safepoint_workers() { return NULL; }
 596 
 597   // Support for object pinning. This is used by JNI Get*Critical()
 598   // and Release*Critical() family of functions. If supported, the GC
 599   // must guarantee that pinned objects never move.
 600   virtual bool supports_object_pinning() const;
 601   virtual oop pin_object(JavaThread* thread, oop obj);
 602   virtual void unpin_object(JavaThread* thread, oop obj);
 603 
 604   // Non product verification and debugging.
 605 #ifndef PRODUCT
 606   // Support for PromotionFailureALot.  Return true if it's time to cause a
 607   // promotion failure.  The no-argument version uses
 608   // this->_promotion_failure_alot_count as the counter.
 609   bool promotion_should_fail(volatile size_t* count);
 610   bool promotion_should_fail();
 611 
 612   // Reset the PromotionFailureALot counters.  Should be called at the end of a
 613   // GC in which promotion failure occurred.
 614   void reset_promotion_should_fail(volatile size_t* count);
 615   void reset_promotion_should_fail();
 616 #endif  // #ifndef PRODUCT
 617 
 618 #ifdef ASSERT
 619   static int fired_fake_oom() {
 620     return (CIFireOOMAt > 1 && _fire_out_of_memory_count >= CIFireOOMAt);
 621   }
 622 #endif
 623 };
 624 
 625 // Class to set and reset the GC cause for a CollectedHeap.
 626 
 627 class GCCauseSetter : StackObj {
 628   CollectedHeap* _heap;
 629   GCCause::Cause _previous_cause;
 630  public:
 631   GCCauseSetter(CollectedHeap* heap, GCCause::Cause cause) {
 632     _heap = heap;
 633     _previous_cause = _heap->gc_cause();
 634     _heap->set_gc_cause(cause);
 635   }
 636 
 637   ~GCCauseSetter() {
 638     _heap->set_gc_cause(_previous_cause);
 639   }
 640 };
 641 
 642 #endif // SHARE_VM_GC_SHARED_COLLECTEDHEAP_HPP