src/share/vm/gc_interface/collectedHeap.hpp

Sat, 01 Sep 2012 13:25:18 -0400

author
coleenp
date
Sat, 01 Sep 2012 13:25:18 -0400
changeset 4037
da91efe96a93
parent 3900
d2a62e0f25eb
child 4295
59c790074993
permissions
-rw-r--r--

6964458: Reimplement class meta-data storage to use native memory
Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>

     1 /*
     2  * Copyright (c) 2001, 2012, 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  */
    25 #ifndef SHARE_VM_GC_INTERFACE_COLLECTEDHEAP_HPP
    26 #define SHARE_VM_GC_INTERFACE_COLLECTEDHEAP_HPP
    28 #include "gc_interface/gcCause.hpp"
    29 #include "memory/allocation.hpp"
    30 #include "memory/barrierSet.hpp"
    31 #include "runtime/handles.hpp"
    32 #include "runtime/perfData.hpp"
    33 #include "runtime/safepoint.hpp"
    34 #include "utilities/events.hpp"
    36 // A "CollectedHeap" is an implementation of a java heap for HotSpot.  This
    37 // is an abstract class: there may be many different kinds of heaps.  This
    38 // class defines the functions that a heap must implement, and contains
    39 // infrastructure common to all heaps.
    41 class BarrierSet;
    42 class ThreadClosure;
    43 class AdaptiveSizePolicy;
    44 class Thread;
    45 class CollectorPolicy;
    47 class GCMessage : public FormatBuffer<1024> {
    48  public:
    49   bool is_before;
    51  public:
    52   GCMessage() {}
    53 };
    55 class GCHeapLog : public EventLogBase<GCMessage> {
    56  private:
    57   void log_heap(bool before);
    59  public:
    60   GCHeapLog() : EventLogBase<GCMessage>("GC Heap History") {}
    62   void log_heap_before() {
    63     log_heap(true);
    64   }
    65   void log_heap_after() {
    66     log_heap(false);
    67   }
    68 };
    70 //
    71 // CollectedHeap
    72 //   SharedHeap
    73 //     GenCollectedHeap
    74 //     G1CollectedHeap
    75 //   ParallelScavengeHeap
    76 //
    77 class CollectedHeap : public CHeapObj<mtInternal> {
    78   friend class VMStructs;
    79   friend class IsGCActiveMark; // Block structured external access to _is_gc_active
    81 #ifdef ASSERT
    82   static int       _fire_out_of_memory_count;
    83 #endif
    85   // Used for filler objects (static, but initialized in ctor).
    86   static size_t _filler_array_max_size;
    88   GCHeapLog* _gc_heap_log;
    90   // Used in support of ReduceInitialCardMarks; only consulted if COMPILER2 is being used
    91   bool _defer_initial_card_mark;
    93  protected:
    94   MemRegion _reserved;
    95   BarrierSet* _barrier_set;
    96   bool _is_gc_active;
    97   uint _n_par_threads;
    99   unsigned int _total_collections;          // ... started
   100   unsigned int _total_full_collections;     // ... started
   101   NOT_PRODUCT(volatile size_t _promotion_failure_alot_count;)
   102   NOT_PRODUCT(volatile size_t _promotion_failure_alot_gc_number;)
   104   // Reason for current garbage collection.  Should be set to
   105   // a value reflecting no collection between collections.
   106   GCCause::Cause _gc_cause;
   107   GCCause::Cause _gc_lastcause;
   108   PerfStringVariable* _perf_gc_cause;
   109   PerfStringVariable* _perf_gc_lastcause;
   111   // Constructor
   112   CollectedHeap();
   114   // Do common initializations that must follow instance construction,
   115   // for example, those needing virtual calls.
   116   // This code could perhaps be moved into initialize() but would
   117   // be slightly more awkward because we want the latter to be a
   118   // pure virtual.
   119   void pre_initialize();
   121   // Create a new tlab. All TLAB allocations must go through this.
   122   virtual HeapWord* allocate_new_tlab(size_t size);
   124   // Accumulate statistics on all tlabs.
   125   virtual void accumulate_statistics_all_tlabs();
   127   // Reinitialize tlabs before resuming mutators.
   128   virtual void resize_all_tlabs();
   130   // Allocate from the current thread's TLAB, with broken-out slow path.
   131   inline static HeapWord* allocate_from_tlab(Thread* thread, size_t size);
   132   static HeapWord* allocate_from_tlab_slow(Thread* thread, size_t size);
   134   // Allocate an uninitialized block of the given size, or returns NULL if
   135   // this is impossible.
   136   inline static HeapWord* common_mem_allocate_noinit(size_t size, TRAPS);
   138   // Like allocate_init, but the block returned by a successful allocation
   139   // is guaranteed initialized to zeros.
   140   inline static HeapWord* common_mem_allocate_init(size_t size, TRAPS);
   142   // Helper functions for (VM) allocation.
   143   inline static void post_allocation_setup_common(KlassHandle klass, HeapWord* obj);
   144   inline static void post_allocation_setup_no_klass_install(KlassHandle klass,
   145                                                             HeapWord* objPtr);
   147   inline static void post_allocation_setup_obj(KlassHandle klass, HeapWord* obj);
   149   inline static void post_allocation_setup_array(KlassHandle klass,
   150                                                  HeapWord* obj, int length);
   152   // Clears an allocated object.
   153   inline static void init_obj(HeapWord* obj, size_t size);
   155   // Filler object utilities.
   156   static inline size_t filler_array_hdr_size();
   157   static inline size_t filler_array_min_size();
   159   DEBUG_ONLY(static void fill_args_check(HeapWord* start, size_t words);)
   160   DEBUG_ONLY(static void zap_filler_array(HeapWord* start, size_t words, bool zap = true);)
   162   // Fill with a single array; caller must ensure filler_array_min_size() <=
   163   // words <= filler_array_max_size().
   164   static inline void fill_with_array(HeapWord* start, size_t words, bool zap = true);
   166   // Fill with a single object (either an int array or a java.lang.Object).
   167   static inline void fill_with_object_impl(HeapWord* start, size_t words, bool zap = true);
   169   // Verification functions
   170   virtual void check_for_bad_heap_word_value(HeapWord* addr, size_t size)
   171     PRODUCT_RETURN;
   172   virtual void check_for_non_bad_heap_word_value(HeapWord* addr, size_t size)
   173     PRODUCT_RETURN;
   174   debug_only(static void check_for_valid_allocation_state();)
   176  public:
   177   enum Name {
   178     Abstract,
   179     SharedHeap,
   180     GenCollectedHeap,
   181     ParallelScavengeHeap,
   182     G1CollectedHeap
   183   };
   185   static inline size_t filler_array_max_size() {
   186     return _filler_array_max_size;
   187   }
   189   virtual CollectedHeap::Name kind() const { return CollectedHeap::Abstract; }
   191   /**
   192    * Returns JNI error code JNI_ENOMEM if memory could not be allocated,
   193    * and JNI_OK on success.
   194    */
   195   virtual jint initialize() = 0;
   197   // In many heaps, there will be a need to perform some initialization activities
   198   // after the Universe is fully formed, but before general heap allocation is allowed.
   199   // This is the correct place to place such initialization methods.
   200   virtual void post_initialize() = 0;
   202   MemRegion reserved_region() const { return _reserved; }
   203   address base() const { return (address)reserved_region().start(); }
   205   // Future cleanup here. The following functions should specify bytes or
   206   // heapwords as part of their signature.
   207   virtual size_t capacity() const = 0;
   208   virtual size_t used() const = 0;
   210   // Return "true" if the part of the heap that allocates Java
   211   // objects has reached the maximal committed limit that it can
   212   // reach, without a garbage collection.
   213   virtual bool is_maximal_no_gc() const = 0;
   215   // Support for java.lang.Runtime.maxMemory():  return the maximum amount of
   216   // memory that the vm could make available for storing 'normal' java objects.
   217   // This is based on the reserved address space, but should not include space
   218   // that the vm uses internally for bookkeeping or temporary storage
   219   // (e.g., in the case of the young gen, one of the survivor
   220   // spaces).
   221   virtual size_t max_capacity() const = 0;
   223   // Returns "TRUE" if "p" points into the reserved area of the heap.
   224   bool is_in_reserved(const void* p) const {
   225     return _reserved.contains(p);
   226   }
   228   bool is_in_reserved_or_null(const void* p) const {
   229     return p == NULL || is_in_reserved(p);
   230   }
   232   // Returns "TRUE" iff "p" points into the committed areas of the heap.
   233   // Since this method can be expensive in general, we restrict its
   234   // use to assertion checking only.
   235   virtual bool is_in(const void* p) const = 0;
   237   bool is_in_or_null(const void* p) const {
   238     return p == NULL || is_in(p);
   239   }
   241   bool is_in_place(Metadata** p) {
   242     return !Universe::heap()->is_in(p);
   243   }
   244   bool is_in_place(oop* p) { return Universe::heap()->is_in(p); }
   245   bool is_in_place(narrowOop* p) {
   246     oop o = oopDesc::load_decode_heap_oop_not_null(p);
   247     return Universe::heap()->is_in((const void*)o);
   248   }
   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."
   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.
   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   }
   278   bool is_in_closed_subset_or_null(const void* p) const {
   279     return p == NULL || is_in_closed_subset(p);
   280   }
   282 #ifdef ASSERT
   283   // Returns true if "p" is in the part of the
   284   // heap being collected.
   285   virtual bool is_in_partial_collection(const void *p) = 0;
   286 #endif
   288   // An object is scavengable if its location may move during a scavenge.
   289   // (A scavenge is a GC which is not a full GC.)
   290   virtual bool is_scavengable(const void *p) = 0;
   292   // Returns "TRUE" if "p" is a method oop in the
   293   // current heap, with high probability. This predicate
   294   // is not stable, in general.
   295   bool is_valid_method(Method* p) const;
   297   void set_gc_cause(GCCause::Cause v) {
   298      if (UsePerfData) {
   299        _gc_lastcause = _gc_cause;
   300        _perf_gc_lastcause->set_value(GCCause::to_string(_gc_lastcause));
   301        _perf_gc_cause->set_value(GCCause::to_string(v));
   302      }
   303     _gc_cause = v;
   304   }
   305   GCCause::Cause gc_cause() { return _gc_cause; }
   307   // Number of threads currently working on GC tasks.
   308   uint n_par_threads() { return _n_par_threads; }
   310   // May be overridden to set additional parallelism.
   311   virtual void set_par_threads(uint t) { _n_par_threads = t; };
   313   // Allocate and initialize instances of Class
   314   static oop Class_obj_allocate(KlassHandle klass, int size, KlassHandle real_klass, TRAPS);
   316   // General obj/array allocation facilities.
   317   inline static oop obj_allocate(KlassHandle klass, int size, TRAPS);
   318   inline static oop array_allocate(KlassHandle klass, int size, int length, TRAPS);
   319   inline static oop array_allocate_nozero(KlassHandle klass, int size, int length, TRAPS);
   321   inline static void post_allocation_install_obj_klass(KlassHandle klass,
   322                                                        oop obj);
   324   // Raw memory allocation facilities
   325   // The obj and array allocate methods are covers for these methods.
   326   // mem_allocate() should never be
   327   // called to allocate TLABs, only individual objects.
   328   virtual HeapWord* mem_allocate(size_t size,
   329                                  bool* gc_overhead_limit_was_exceeded) = 0;
   331   // Utilities for turning raw memory into filler objects.
   332   //
   333   // min_fill_size() is the smallest region that can be filled.
   334   // fill_with_objects() can fill arbitrary-sized regions of the heap using
   335   // multiple objects.  fill_with_object() is for regions known to be smaller
   336   // than the largest array of integers; it uses a single object to fill the
   337   // region and has slightly less overhead.
   338   static size_t min_fill_size() {
   339     return size_t(align_object_size(oopDesc::header_size()));
   340   }
   342   static void fill_with_objects(HeapWord* start, size_t words, bool zap = true);
   344   static void fill_with_object(HeapWord* start, size_t words, bool zap = true);
   345   static void fill_with_object(MemRegion region, bool zap = true) {
   346     fill_with_object(region.start(), region.word_size(), zap);
   347   }
   348   static void fill_with_object(HeapWord* start, HeapWord* end, bool zap = true) {
   349     fill_with_object(start, pointer_delta(end, start), zap);
   350   }
   352   // Some heaps may offer a contiguous region for shared non-blocking
   353   // allocation, via inlined code (by exporting the address of the top and
   354   // end fields defining the extent of the contiguous allocation region.)
   356   // This function returns "true" iff the heap supports this kind of
   357   // allocation.  (Default is "no".)
   358   virtual bool supports_inline_contig_alloc() const {
   359     return false;
   360   }
   361   // These functions return the addresses of the fields that define the
   362   // boundaries of the contiguous allocation area.  (These fields should be
   363   // physically near to one another.)
   364   virtual HeapWord** top_addr() const {
   365     guarantee(false, "inline contiguous allocation not supported");
   366     return NULL;
   367   }
   368   virtual HeapWord** end_addr() const {
   369     guarantee(false, "inline contiguous allocation not supported");
   370     return NULL;
   371   }
   373   // Some heaps may be in an unparseable state at certain times between
   374   // collections. This may be necessary for efficient implementation of
   375   // certain allocation-related activities. Calling this function before
   376   // attempting to parse a heap ensures that the heap is in a parsable
   377   // state (provided other concurrent activity does not introduce
   378   // unparsability). It is normally expected, therefore, that this
   379   // method is invoked with the world stopped.
   380   // NOTE: if you override this method, make sure you call
   381   // super::ensure_parsability so that the non-generational
   382   // part of the work gets done. See implementation of
   383   // CollectedHeap::ensure_parsability and, for instance,
   384   // that of GenCollectedHeap::ensure_parsability().
   385   // The argument "retire_tlabs" controls whether existing TLABs
   386   // are merely filled or also retired, thus preventing further
   387   // allocation from them and necessitating allocation of new TLABs.
   388   virtual void ensure_parsability(bool retire_tlabs);
   390   // Return an estimate of the maximum allocation that could be performed
   391   // without triggering any collection or expansion activity.  In a
   392   // generational collector, for example, this is probably the largest
   393   // allocation that could be supported (without expansion) in the youngest
   394   // generation.  It is "unsafe" because no locks are taken; the result
   395   // should be treated as an approximation, not a guarantee, for use in
   396   // heuristic resizing decisions.
   397   virtual size_t unsafe_max_alloc() = 0;
   399   // Section on thread-local allocation buffers (TLABs)
   400   // If the heap supports thread-local allocation buffers, it should override
   401   // the following methods:
   402   // Returns "true" iff the heap supports thread-local allocation buffers.
   403   // The default is "no".
   404   virtual bool supports_tlab_allocation() const {
   405     return false;
   406   }
   407   // The amount of space available for thread-local allocation buffers.
   408   virtual size_t tlab_capacity(Thread *thr) const {
   409     guarantee(false, "thread-local allocation buffers not supported");
   410     return 0;
   411   }
   412   // An estimate of the maximum allocation that could be performed
   413   // for thread-local allocation buffers without triggering any
   414   // collection or expansion activity.
   415   virtual size_t unsafe_max_tlab_alloc(Thread *thr) const {
   416     guarantee(false, "thread-local allocation buffers not supported");
   417     return 0;
   418   }
   420   // Can a compiler initialize a new object without store barriers?
   421   // This permission only extends from the creation of a new object
   422   // via a TLAB up to the first subsequent safepoint. If such permission
   423   // is granted for this heap type, the compiler promises to call
   424   // defer_store_barrier() below on any slow path allocation of
   425   // a new object for which such initializing store barriers will
   426   // have been elided.
   427   virtual bool can_elide_tlab_store_barriers() const = 0;
   429   // If a compiler is eliding store barriers for TLAB-allocated objects,
   430   // there is probably a corresponding slow path which can produce
   431   // an object allocated anywhere.  The compiler's runtime support
   432   // promises to call this function on such a slow-path-allocated
   433   // object before performing initializations that have elided
   434   // store barriers. Returns new_obj, or maybe a safer copy thereof.
   435   virtual oop new_store_pre_barrier(JavaThread* thread, oop new_obj);
   437   // Answers whether an initializing store to a new object currently
   438   // allocated at the given address doesn't need a store
   439   // barrier. Returns "true" if it doesn't need an initializing
   440   // store barrier; answers "false" if it does.
   441   virtual bool can_elide_initializing_store_barrier(oop new_obj) = 0;
   443   // If a compiler is eliding store barriers for TLAB-allocated objects,
   444   // we will be informed of a slow-path allocation by a call
   445   // to new_store_pre_barrier() above. Such a call precedes the
   446   // initialization of the object itself, and no post-store-barriers will
   447   // be issued. Some heap types require that the barrier strictly follows
   448   // the initializing stores. (This is currently implemented by deferring the
   449   // barrier until the next slow-path allocation or gc-related safepoint.)
   450   // This interface answers whether a particular heap type needs the card
   451   // mark to be thus strictly sequenced after the stores.
   452   virtual bool card_mark_must_follow_store() const = 0;
   454   // If the CollectedHeap was asked to defer a store barrier above,
   455   // this informs it to flush such a deferred store barrier to the
   456   // remembered set.
   457   virtual void flush_deferred_store_barrier(JavaThread* thread);
   459   // Does this heap support heap inspection (+PrintClassHistogram?)
   460   virtual bool supports_heap_inspection() const = 0;
   462   // Perform a collection of the heap; intended for use in implementing
   463   // "System.gc".  This probably implies as full a collection as the
   464   // "CollectedHeap" supports.
   465   virtual void collect(GCCause::Cause cause) = 0;
   467   // Perform a full collection
   468   virtual void do_full_collection(bool clear_all_soft_refs) = 0;
   470   // This interface assumes that it's being called by the
   471   // vm thread. It collects the heap assuming that the
   472   // heap lock is already held and that we are executing in
   473   // the context of the vm thread.
   474   virtual void collect_as_vm_thread(GCCause::Cause cause);
   476   // Callback from VM_CollectForMetadataAllocation operation.
   477   MetaWord* satisfy_failed_metadata_allocation(ClassLoaderData* loader_data,
   478                                                size_t size,
   479                                                Metaspace::MetadataType mdtype);
   481   // Returns the barrier set for this heap
   482   BarrierSet* barrier_set() { return _barrier_set; }
   484   // Returns "true" iff there is a stop-world GC in progress.  (I assume
   485   // that it should answer "false" for the concurrent part of a concurrent
   486   // collector -- dld).
   487   bool is_gc_active() const { return _is_gc_active; }
   489   // Total number of GC collections (started)
   490   unsigned int total_collections() const { return _total_collections; }
   491   unsigned int total_full_collections() const { return _total_full_collections;}
   493   // Increment total number of GC collections (started)
   494   // Should be protected but used by PSMarkSweep - cleanup for 1.4.2
   495   void increment_total_collections(bool full = false) {
   496     _total_collections++;
   497     if (full) {
   498       increment_total_full_collections();
   499     }
   500   }
   502   void increment_total_full_collections() { _total_full_collections++; }
   504   // Return the AdaptiveSizePolicy for the heap.
   505   virtual AdaptiveSizePolicy* size_policy() = 0;
   507   // Return the CollectorPolicy for the heap
   508   virtual CollectorPolicy* collector_policy() const = 0;
   510   void oop_iterate_no_header(OopClosure* cl);
   512   // Iterate over all the ref-containing fields of all objects, calling
   513   // "cl.do_oop" on each.
   514   virtual void oop_iterate(ExtendedOopClosure* cl) = 0;
   516   // Iterate over all objects, calling "cl.do_object" on each.
   517   virtual void object_iterate(ObjectClosure* cl) = 0;
   519   // Similar to object_iterate() except iterates only
   520   // over live objects.
   521   virtual void safe_object_iterate(ObjectClosure* cl) = 0;
   523   // NOTE! There is no requirement that a collector implement these
   524   // functions.
   525   //
   526   // A CollectedHeap is divided into a dense sequence of "blocks"; that is,
   527   // each address in the (reserved) heap is a member of exactly
   528   // one block.  The defining characteristic of a block is that it is
   529   // possible to find its size, and thus to progress forward to the next
   530   // block.  (Blocks may be of different sizes.)  Thus, blocks may
   531   // represent Java objects, or they might be free blocks in a
   532   // free-list-based heap (or subheap), as long as the two kinds are
   533   // distinguishable and the size of each is determinable.
   535   // Returns the address of the start of the "block" that contains the
   536   // address "addr".  We say "blocks" instead of "object" since some heaps
   537   // may not pack objects densely; a chunk may either be an object or a
   538   // non-object.
   539   virtual HeapWord* block_start(const void* addr) const = 0;
   541   // Requires "addr" to be the start of a chunk, and returns its size.
   542   // "addr + size" is required to be the start of a new chunk, or the end
   543   // of the active area of the heap.
   544   virtual size_t block_size(const HeapWord* addr) const = 0;
   546   // Requires "addr" to be the start of a block, and returns "TRUE" iff
   547   // the block is an object.
   548   virtual bool block_is_obj(const HeapWord* addr) const = 0;
   550   // Returns the longest time (in ms) that has elapsed since the last
   551   // time that any part of the heap was examined by a garbage collection.
   552   virtual jlong millis_since_last_gc() = 0;
   554   // Perform any cleanup actions necessary before allowing a verification.
   555   virtual void prepare_for_verify() = 0;
   557   // Generate any dumps preceding or following a full gc
   558   void pre_full_gc_dump();
   559   void post_full_gc_dump();
   561   // Print heap information on the given outputStream.
   562   virtual void print_on(outputStream* st) const = 0;
   563   // The default behavior is to call print_on() on tty.
   564   virtual void print() const {
   565     print_on(tty);
   566   }
   567   // Print more detailed heap information on the given
   568   // outputStream. The default behaviour is to call print_on(). It is
   569   // up to each subclass to override it and add any additional output
   570   // it needs.
   571   virtual void print_extended_on(outputStream* st) const {
   572     print_on(st);
   573   }
   575   // Print all GC threads (other than the VM thread)
   576   // used by this heap.
   577   virtual void print_gc_threads_on(outputStream* st) const = 0;
   578   // The default behavior is to call print_gc_threads_on() on tty.
   579   void print_gc_threads() {
   580     print_gc_threads_on(tty);
   581   }
   582   // Iterator for all GC threads (other than VM thread)
   583   virtual void gc_threads_do(ThreadClosure* tc) const = 0;
   585   // Print any relevant tracing info that flags imply.
   586   // Default implementation does nothing.
   587   virtual void print_tracing_info() const = 0;
   589   // If PrintHeapAtGC is set call the appropriate routi
   590   void print_heap_before_gc() {
   591     if (PrintHeapAtGC) {
   592       Universe::print_heap_before_gc();
   593     }
   594     if (_gc_heap_log != NULL) {
   595       _gc_heap_log->log_heap_before();
   596     }
   597   }
   598   void print_heap_after_gc() {
   599     if (PrintHeapAtGC) {
   600       Universe::print_heap_after_gc();
   601     }
   602     if (_gc_heap_log != NULL) {
   603       _gc_heap_log->log_heap_after();
   604     }
   605   }
   607   // Heap verification
   608   virtual void verify(bool silent, VerifyOption option) = 0;
   610   // Non product verification and debugging.
   611 #ifndef PRODUCT
   612   // Support for PromotionFailureALot.  Return true if it's time to cause a
   613   // promotion failure.  The no-argument version uses
   614   // this->_promotion_failure_alot_count as the counter.
   615   inline bool promotion_should_fail(volatile size_t* count);
   616   inline bool promotion_should_fail();
   618   // Reset the PromotionFailureALot counters.  Should be called at the end of a
   619   // GC in which promotion failure ocurred.
   620   inline void reset_promotion_should_fail(volatile size_t* count);
   621   inline void reset_promotion_should_fail();
   622 #endif  // #ifndef PRODUCT
   624 #ifdef ASSERT
   625   static int fired_fake_oom() {
   626     return (CIFireOOMAt > 1 && _fire_out_of_memory_count >= CIFireOOMAt);
   627   }
   628 #endif
   630  public:
   631   // This is a convenience method that is used in cases where
   632   // the actual number of GC worker threads is not pertinent but
   633   // only whether there more than 0.  Use of this method helps
   634   // reduce the occurrence of ParallelGCThreads to uses where the
   635   // actual number may be germane.
   636   static bool use_parallel_gc_threads() { return ParallelGCThreads > 0; }
   638   /////////////// Unit tests ///////////////
   640   NOT_PRODUCT(static void test_is_in();)
   641 };
   643 // Class to set and reset the GC cause for a CollectedHeap.
   645 class GCCauseSetter : StackObj {
   646   CollectedHeap* _heap;
   647   GCCause::Cause _previous_cause;
   648  public:
   649   GCCauseSetter(CollectedHeap* heap, GCCause::Cause cause) {
   650     assert(SafepointSynchronize::is_at_safepoint(),
   651            "This method manipulates heap state without locking");
   652     _heap = heap;
   653     _previous_cause = _heap->gc_cause();
   654     _heap->set_gc_cause(cause);
   655   }
   657   ~GCCauseSetter() {
   658     assert(SafepointSynchronize::is_at_safepoint(),
   659           "This method manipulates heap state without locking");
   660     _heap->set_gc_cause(_previous_cause);
   661   }
   662 };
   664 #endif // SHARE_VM_GC_INTERFACE_COLLECTEDHEAP_HPP

mercurial