< prev index next >

src/hotspot/share/gc/shared/collectedHeap.hpp

Print this page




  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_GC_SHARED_COLLECTEDHEAP_HPP
  26 #define SHARE_GC_SHARED_COLLECTEDHEAP_HPP
  27 
  28 #include "gc/shared/gcCause.hpp"
  29 #include "gc/shared/gcWhen.hpp"
  30 #include "gc/shared/verifyOption.hpp"
  31 #include "memory/allocation.hpp"

  32 #include "memory/universe.hpp"
  33 #include "runtime/handles.hpp"
  34 #include "runtime/perfData.hpp"
  35 #include "runtime/safepoint.hpp"
  36 #include "services/memoryUsage.hpp"
  37 #include "utilities/debug.hpp"
  38 #include "utilities/events.hpp"
  39 #include "utilities/formatBuffer.hpp"
  40 #include "utilities/growableArray.hpp"
  41 
  42 // A "CollectedHeap" is an implementation of a java heap for HotSpot.  This
  43 // is an abstract class: there may be many different kinds of heaps.  This
  44 // class defines the functions that a heap must implement, and contains
  45 // infrastructure common to all heaps.
  46 

  47 class AdaptiveSizePolicy;
  48 class BarrierSet;
  49 class GCHeapSummary;
  50 class GCTimer;
  51 class GCTracer;
  52 class GCMemoryManager;
  53 class MemoryPool;
  54 class MetaspaceSummary;
  55 class ReservedHeapSpace;
  56 class SoftRefPolicy;
  57 class Thread;
  58 class ThreadClosure;
  59 class VirtualSpaceSummary;
  60 class WorkGang;
  61 class nmethod;
  62 
  63 class GCMessage : public FormatBuffer<1024> {
  64  public:
  65   bool is_before;
  66 


  68   GCMessage() {}
  69 };
  70 
  71 class CollectedHeap;
  72 
  73 class GCHeapLog : public EventLogBase<GCMessage> {
  74  private:
  75   void log_heap(CollectedHeap* heap, bool before);
  76 
  77  public:
  78   GCHeapLog() : EventLogBase<GCMessage>("GC Heap History", "gc") {}
  79 
  80   void log_heap_before(CollectedHeap* heap) {
  81     log_heap(heap, true);
  82   }
  83   void log_heap_after(CollectedHeap* heap) {
  84     log_heap(heap, false);
  85   }
  86 };
  87 





  88 //
  89 // CollectedHeap
  90 //   GenCollectedHeap
  91 //     SerialHeap
  92 //   G1CollectedHeap
  93 //   ParallelScavengeHeap
  94 //   ShenandoahHeap
  95 //   ZCollectedHeap
  96 //
  97 class CollectedHeap : public CHeapObj<mtInternal> {
  98   friend class VMStructs;
  99   friend class JVMCIVMStructs;
 100   friend class IsGCActiveMark; // Block structured external access to _is_gc_active
 101   friend class MemAllocator;
 102 
 103  private:
 104   GCHeapLog* _gc_heap_log;
 105 
 106  protected:
 107   // Not used by all GCs


 384   // Increment total number of GC collections (started)
 385   void increment_total_collections(bool full = false) {
 386     _total_collections++;
 387     if (full) {
 388       increment_total_full_collections();
 389     }
 390   }
 391 
 392   void increment_total_full_collections() { _total_full_collections++; }
 393 
 394   // Return the SoftRefPolicy for the heap;
 395   virtual SoftRefPolicy* soft_ref_policy() = 0;
 396 
 397   virtual MemoryUsage memory_usage();
 398   virtual GrowableArray<GCMemoryManager*> memory_managers() = 0;
 399   virtual GrowableArray<MemoryPool*> memory_pools() = 0;
 400 
 401   // Iterate over all objects, calling "cl.do_object" on each.
 402   virtual void object_iterate(ObjectClosure* cl) = 0;
 403 




 404   // Keep alive an object that was loaded with AS_NO_KEEPALIVE.
 405   virtual void keep_alive(oop obj) {}
 406 
 407   // Returns the longest time (in ms) that has elapsed since the last
 408   // time that any part of the heap was examined by a garbage collection.
 409   virtual jlong millis_since_last_gc() = 0;
 410 
 411   // Perform any cleanup actions necessary before allowing a verification.
 412   virtual void prepare_for_verify() = 0;
 413 
 414   // Generate any dumps preceding or following a full gc
 415  private:
 416   void full_gc_dump(GCTimer* timer, bool before);
 417 
 418   virtual void initialize_serviceability() = 0;
 419 
 420  public:
 421   void pre_full_gc_dump(GCTimer* timer);
 422   void post_full_gc_dump(GCTimer* timer);
 423 


 429   // Print heap information on the given outputStream.
 430   virtual void print_on(outputStream* st) const = 0;
 431   // The default behavior is to call print_on() on tty.
 432   virtual void print() const;
 433 
 434   // Print more detailed heap information on the given
 435   // outputStream. The default behavior is to call print_on(). It is
 436   // up to each subclass to override it and add any additional output
 437   // it needs.
 438   virtual void print_extended_on(outputStream* st) const {
 439     print_on(st);
 440   }
 441 
 442   virtual void print_on_error(outputStream* st) const;
 443 
 444   // Used to print information about locations in the hs_err file.
 445   virtual bool print_location(outputStream* st, void* addr) const = 0;
 446 
 447   // Iterator for all GC threads (other than VM thread)
 448   virtual void gc_threads_do(ThreadClosure* tc) const = 0;



 449 
 450   // Print any relevant tracing info that flags imply.
 451   // Default implementation does nothing.
 452   virtual void print_tracing_info() const = 0;
 453 
 454   void print_heap_before_gc();
 455   void print_heap_after_gc();
 456 
 457   // Registering and unregistering an nmethod (compiled code) with the heap.
 458   virtual void register_nmethod(nmethod* nm) = 0;
 459   virtual void unregister_nmethod(nmethod* nm) = 0;
 460   // Callback for when nmethod is about to be deleted.
 461   virtual void flush_nmethod(nmethod* nm) = 0;
 462   virtual void verify_nmethod(nmethod* nm) = 0;
 463 
 464   void trace_heap_before_gc(const GCTracer* gc_tracer);
 465   void trace_heap_after_gc(const GCTracer* gc_tracer);
 466 
 467   // Heap verification
 468   virtual void verify(VerifyOption option) = 0;




  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_GC_SHARED_COLLECTEDHEAP_HPP
  26 #define SHARE_GC_SHARED_COLLECTEDHEAP_HPP
  27 
  28 #include "gc/shared/gcCause.hpp"
  29 #include "gc/shared/gcWhen.hpp"
  30 #include "gc/shared/verifyOption.hpp"
  31 #include "memory/allocation.hpp"
  32 #include "memory/heapInspection.hpp"
  33 #include "memory/universe.hpp"
  34 #include "runtime/handles.hpp"
  35 #include "runtime/perfData.hpp"
  36 #include "runtime/safepoint.hpp"
  37 #include "services/memoryUsage.hpp"
  38 #include "utilities/debug.hpp"
  39 #include "utilities/events.hpp"
  40 #include "utilities/formatBuffer.hpp"
  41 #include "utilities/growableArray.hpp"
  42 
  43 // A "CollectedHeap" is an implementation of a java heap for HotSpot.  This
  44 // is an abstract class: there may be many different kinds of heaps.  This
  45 // class defines the functions that a heap must implement, and contains
  46 // infrastructure common to all heaps.
  47 
  48 class AbstractGangTask;
  49 class AdaptiveSizePolicy;
  50 class BarrierSet;
  51 class GCHeapSummary;
  52 class GCTimer;
  53 class GCTracer;
  54 class GCMemoryManager;
  55 class MemoryPool;
  56 class MetaspaceSummary;
  57 class ReservedHeapSpace;
  58 class SoftRefPolicy;
  59 class Thread;
  60 class ThreadClosure;
  61 class VirtualSpaceSummary;
  62 class WorkGang;
  63 class nmethod;
  64 
  65 class GCMessage : public FormatBuffer<1024> {
  66  public:
  67   bool is_before;
  68 


  70   GCMessage() {}
  71 };
  72 
  73 class CollectedHeap;
  74 
  75 class GCHeapLog : public EventLogBase<GCMessage> {
  76  private:
  77   void log_heap(CollectedHeap* heap, bool before);
  78 
  79  public:
  80   GCHeapLog() : EventLogBase<GCMessage>("GC Heap History", "gc") {}
  81 
  82   void log_heap_before(CollectedHeap* heap) {
  83     log_heap(heap, true);
  84   }
  85   void log_heap_after(CollectedHeap* heap) {
  86     log_heap(heap, false);
  87   }
  88 };
  89 
  90 class ParallelObjectIterator : public CHeapObj<mtGC> {
  91 public:
  92   virtual void object_iterate(ObjectClosure* cl, uint worker_id) = 0;
  93 };
  94 
  95 //
  96 // CollectedHeap
  97 //   GenCollectedHeap
  98 //     SerialHeap
  99 //   G1CollectedHeap
 100 //   ParallelScavengeHeap
 101 //   ShenandoahHeap
 102 //   ZCollectedHeap
 103 //
 104 class CollectedHeap : public CHeapObj<mtInternal> {
 105   friend class VMStructs;
 106   friend class JVMCIVMStructs;
 107   friend class IsGCActiveMark; // Block structured external access to _is_gc_active
 108   friend class MemAllocator;
 109 
 110  private:
 111   GCHeapLog* _gc_heap_log;
 112 
 113  protected:
 114   // Not used by all GCs


 391   // Increment total number of GC collections (started)
 392   void increment_total_collections(bool full = false) {
 393     _total_collections++;
 394     if (full) {
 395       increment_total_full_collections();
 396     }
 397   }
 398 
 399   void increment_total_full_collections() { _total_full_collections++; }
 400 
 401   // Return the SoftRefPolicy for the heap;
 402   virtual SoftRefPolicy* soft_ref_policy() = 0;
 403 
 404   virtual MemoryUsage memory_usage();
 405   virtual GrowableArray<GCMemoryManager*> memory_managers() = 0;
 406   virtual GrowableArray<MemoryPool*> memory_pools() = 0;
 407 
 408   // Iterate over all objects, calling "cl.do_object" on each.
 409   virtual void object_iterate(ObjectClosure* cl) = 0;
 410 
 411   virtual ParallelObjectIterator* parallel_object_iterator(uint thread_num) {
 412     return NULL;
 413   }
 414 
 415   // Keep alive an object that was loaded with AS_NO_KEEPALIVE.
 416   virtual void keep_alive(oop obj) {}
 417 
 418   // Returns the longest time (in ms) that has elapsed since the last
 419   // time that any part of the heap was examined by a garbage collection.
 420   virtual jlong millis_since_last_gc() = 0;
 421 
 422   // Perform any cleanup actions necessary before allowing a verification.
 423   virtual void prepare_for_verify() = 0;
 424 
 425   // Generate any dumps preceding or following a full gc
 426  private:
 427   void full_gc_dump(GCTimer* timer, bool before);
 428 
 429   virtual void initialize_serviceability() = 0;
 430 
 431  public:
 432   void pre_full_gc_dump(GCTimer* timer);
 433   void post_full_gc_dump(GCTimer* timer);
 434 


 440   // Print heap information on the given outputStream.
 441   virtual void print_on(outputStream* st) const = 0;
 442   // The default behavior is to call print_on() on tty.
 443   virtual void print() const;
 444 
 445   // Print more detailed heap information on the given
 446   // outputStream. The default behavior is to call print_on(). It is
 447   // up to each subclass to override it and add any additional output
 448   // it needs.
 449   virtual void print_extended_on(outputStream* st) const {
 450     print_on(st);
 451   }
 452 
 453   virtual void print_on_error(outputStream* st) const;
 454 
 455   // Used to print information about locations in the hs_err file.
 456   virtual bool print_location(outputStream* st, void* addr) const = 0;
 457 
 458   // Iterator for all GC threads (other than VM thread)
 459   virtual void gc_threads_do(ThreadClosure* tc) const = 0;
 460 
 461   // Run given task. Possibly in parallel if the GC supports it.
 462   virtual void run_task(AbstractGangTask* task) = 0;
 463 
 464   // Print any relevant tracing info that flags imply.
 465   // Default implementation does nothing.
 466   virtual void print_tracing_info() const = 0;
 467 
 468   void print_heap_before_gc();
 469   void print_heap_after_gc();
 470 
 471   // Registering and unregistering an nmethod (compiled code) with the heap.
 472   virtual void register_nmethod(nmethod* nm) = 0;
 473   virtual void unregister_nmethod(nmethod* nm) = 0;
 474   // Callback for when nmethod is about to be deleted.
 475   virtual void flush_nmethod(nmethod* nm) = 0;
 476   virtual void verify_nmethod(nmethod* nm) = 0;
 477 
 478   void trace_heap_before_gc(const GCTracer* gc_tracer);
 479   void trace_heap_after_gc(const GCTracer* gc_tracer);
 480 
 481   // Heap verification
 482   virtual void verify(VerifyOption option) = 0;


< prev index next >