< prev index next >

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

Print this page
rev 60513 : webrev12


  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


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




 410   // Keep alive an object that was loaded with AS_NO_KEEPALIVE.
 411   virtual void keep_alive(oop obj) {}
 412 
 413   // Perform any cleanup actions necessary before allowing a verification.
 414   virtual void prepare_for_verify() = 0;
 415 
 416   // Returns the longest time (in ms) that has elapsed since the last
 417   // time that the whole heap has been examined by a garbage collection.
 418   jlong millis_since_last_whole_heap_examined();
 419   // GC should call this when the next whole heap analysis has completed to
 420   // satisfy above requirement.
 421   void record_whole_heap_examined_timestamp();
 422 
 423  private:
 424   // Generate any dumps preceding or following a full gc
 425   void full_gc_dump(GCTimer* timer, bool before);
 426 
 427   virtual void initialize_serviceability() = 0;
 428 
 429  public:


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



 458 
 459   // Print any relevant tracing info that flags imply.
 460   // Default implementation does nothing.
 461   virtual void print_tracing_info() const = 0;
 462 
 463   void print_heap_before_gc();
 464   void print_heap_after_gc();
 465 
 466   // Registering and unregistering an nmethod (compiled code) with the heap.
 467   virtual void register_nmethod(nmethod* nm) = 0;
 468   virtual void unregister_nmethod(nmethod* nm) = 0;
 469   // Callback for when nmethod is about to be deleted.
 470   virtual void flush_nmethod(nmethod* nm) = 0;
 471   virtual void verify_nmethod(nmethod* nm) = 0;
 472 
 473   void trace_heap_before_gc(const GCTracer* gc_tracer);
 474   void trace_heap_after_gc(const GCTracer* gc_tracer);
 475 
 476   // Heap verification
 477   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


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


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


< prev index next >