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