1 /*
   2  * Copyright (c) 2012, 2013, 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_IMPLEMENTATION_SHARED_GCTRACE_HPP
  26 #define SHARE_VM_GC_IMPLEMENTATION_SHARED_GCTRACE_HPP
  27 
  28 #include "gc_interface/gcCause.hpp"
  29 #include "gc_interface/gcName.hpp"
  30 #include "gc_implementation/shared/gcWhen.hpp"
  31 #include "gc_implementation/shared/copyFailedInfo.hpp"
  32 #include "memory/allocation.hpp"
  33 #include "memory/metaspace.hpp"
  34 #include "memory/referenceType.hpp"
  35 #if INCLUDE_ALL_GCS
  36 #include "gc_implementation/g1/g1YCTypes.hpp"
  37 #endif
  38 #include "utilities/macros.hpp"
  39 #include "utilities/ticks.hpp"
  40 
  41 typedef uint GCId;
  42 
  43 class EvacuationInfo;
  44 class GCHeapSummary;
  45 class MetaspaceChunkFreeListSummary;
  46 class MetaspaceSummary;
  47 class PSHeapSummary;
  48 class ReferenceProcessorStats;
  49 class TimePartitions;
  50 class BoolObjectClosure;
  51 
  52 class SharedGCInfo VALUE_OBJ_CLASS_SPEC {
  53  public:
  54   static const GCId UNSET_GCID = (GCId)-1;
  55 
  56  private:
  57   GCId _id;
  58   GCName _name;
  59   GCCause::Cause _cause;
  60   Ticks     _start_timestamp;
  61   Ticks     _end_timestamp;
  62   Tickspan  _sum_of_pauses;
  63   Tickspan  _longest_pause;
  64 
  65  public:
  66   SharedGCInfo(GCName name) :
  67     _id(UNSET_GCID),
  68     _name(name),
  69     _cause(GCCause::_last_gc_cause),
  70     _start_timestamp(),
  71     _end_timestamp(),
  72     _sum_of_pauses(),
  73     _longest_pause() {
  74   }
  75 
  76   void set_id(GCId id) { _id = id; }
  77   GCId id() const { return _id; }
  78 
  79   void set_start_timestamp(const Ticks& timestamp) { _start_timestamp = timestamp; }
  80   const Ticks start_timestamp() const { return _start_timestamp; }
  81 
  82   void set_end_timestamp(const Ticks& timestamp) { _end_timestamp = timestamp; }
  83   const Ticks end_timestamp() const { return _end_timestamp; }
  84 
  85   void set_name(GCName name) { _name = name; }
  86   GCName name() const { return _name; }
  87 
  88   void set_cause(GCCause::Cause cause) { _cause = cause; }
  89   GCCause::Cause cause() const { return _cause; }
  90 
  91   void set_sum_of_pauses(const Tickspan& duration) { _sum_of_pauses = duration; }
  92   const Tickspan sum_of_pauses() const { return _sum_of_pauses; }
  93 
  94   void set_longest_pause(const Tickspan& duration) { _longest_pause = duration; }
  95   const Tickspan longest_pause() const { return _longest_pause; }
  96 };
  97 
  98 class ParallelOldGCInfo VALUE_OBJ_CLASS_SPEC {
  99   void* _dense_prefix;
 100  public:
 101   ParallelOldGCInfo() : _dense_prefix(NULL) {}
 102   void report_dense_prefix(void* addr) {
 103     _dense_prefix = addr;
 104   }
 105   void* dense_prefix() const { return _dense_prefix; }
 106 };
 107 
 108 #if INCLUDE_ALL_GCS
 109 
 110 class G1YoungGCInfo VALUE_OBJ_CLASS_SPEC {
 111   G1YCType _type;
 112  public:
 113   G1YoungGCInfo() : _type(G1YCTypeEndSentinel) {}
 114   void set_type(G1YCType type) {
 115     _type = type;
 116   }
 117   G1YCType type() const { return _type; }
 118 };
 119 
 120 #endif // INCLUDE_ALL_GCS
 121 
 122 class GCTracer : public ResourceObj {
 123  protected:
 124   SharedGCInfo _shared_gc_info;
 125 
 126  public:
 127   void report_gc_start(GCCause::Cause cause, const Ticks& timestamp);
 128   void report_gc_end(const Ticks& timestamp, TimePartitions* time_partitions);
 129   void report_gc_heap_summary(GCWhen::Type when, const GCHeapSummary& heap_summary) const;
 130   void report_metaspace_summary(GCWhen::Type when, const MetaspaceSummary& metaspace_summary) const;
 131   void report_gc_reference_stats(const ReferenceProcessorStats& rp) const;
 132   void report_object_count_after_gc(BoolObjectClosure* object_filter) NOT_SERVICES_RETURN;
 133   bool has_reported_gc_start() const;
 134 
 135  protected:
 136   GCTracer(GCName name) : _shared_gc_info(name) {}
 137   virtual void report_gc_start_impl(GCCause::Cause cause, const Ticks& timestamp);
 138   virtual void report_gc_end_impl(const Ticks& timestamp, TimePartitions* time_partitions);
 139 
 140  private:
 141   void send_garbage_collection_event() const;
 142   void send_gc_heap_summary_event(GCWhen::Type when, const GCHeapSummary& heap_summary) const;
 143   void send_meta_space_summary_event(GCWhen::Type when, const MetaspaceSummary& meta_space_summary) const;
 144   void send_metaspace_chunk_free_list_summary(GCWhen::Type when, Metaspace::MetadataType mdtype, const MetaspaceChunkFreeListSummary& summary) const;
 145   void send_reference_stats_event(ReferenceType type, size_t count) const;
 146   void send_phase_events(TimePartitions* time_partitions) const;
 147 };
 148 
 149 class YoungGCTracer : public GCTracer {
 150   static const uint UNSET_TENURING_THRESHOLD = (uint) -1;
 151 
 152   uint _tenuring_threshold;
 153 
 154  protected:
 155   YoungGCTracer(GCName name) : GCTracer(name), _tenuring_threshold(UNSET_TENURING_THRESHOLD) {}
 156   virtual void report_gc_end_impl(const Ticks& timestamp, TimePartitions* time_partitions);
 157 
 158  public:
 159   void report_promotion_failed(const PromotionFailedInfo& pf_info);
 160   void report_tenuring_threshold(const uint tenuring_threshold);
 161 
 162  private:
 163   void send_young_gc_event() const;
 164   void send_promotion_failed_event(const PromotionFailedInfo& pf_info) const;
 165 };
 166 
 167 class OldGCTracer : public GCTracer {
 168  protected:
 169   OldGCTracer(GCName name) : GCTracer(name) {}
 170   virtual void report_gc_end_impl(const Ticks& timestamp, TimePartitions* time_partitions);
 171 
 172  public:
 173   void report_concurrent_mode_failure();
 174 
 175  private:
 176   void send_old_gc_event() const;
 177   void send_concurrent_mode_failure_event();
 178 };
 179 
 180 class ParallelOldTracer : public OldGCTracer {
 181   ParallelOldGCInfo _parallel_old_gc_info;
 182 
 183  public:
 184   ParallelOldTracer() : OldGCTracer(ParallelOld) {}
 185   void report_dense_prefix(void* dense_prefix);
 186 
 187  protected:
 188   void report_gc_end_impl(const Ticks& timestamp, TimePartitions* time_partitions);
 189 
 190  private:
 191   void send_parallel_old_event() const;
 192 };
 193 
 194 class SerialOldTracer : public OldGCTracer {
 195  public:
 196   SerialOldTracer() : OldGCTracer(SerialOld) {}
 197 };
 198 
 199 class ParallelScavengeTracer : public YoungGCTracer {
 200  public:
 201   ParallelScavengeTracer() : YoungGCTracer(ParallelScavenge) {}
 202 };
 203 
 204 class DefNewTracer : public YoungGCTracer {
 205  public:
 206   DefNewTracer() : YoungGCTracer(DefNew) {}
 207 };
 208 
 209 class ParNewTracer : public YoungGCTracer {
 210  public:
 211   ParNewTracer() : YoungGCTracer(ParNew) {}
 212 };
 213 
 214 #if INCLUDE_ALL_GCS
 215 class G1NewTracer : public YoungGCTracer {
 216   G1YoungGCInfo _g1_young_gc_info;
 217 
 218  public:
 219   G1NewTracer() : YoungGCTracer(G1New) {}
 220 
 221   void report_yc_type(G1YCType type);
 222   void report_gc_end_impl(const Ticks& timestamp, TimePartitions* time_partitions);
 223   void report_evacuation_info(EvacuationInfo* info);
 224   void report_evacuation_failed(EvacuationFailedInfo& ef_info);
 225 
 226  private:
 227   void send_g1_young_gc_event();
 228   void send_evacuation_info_event(EvacuationInfo* info);
 229   void send_evacuation_failed_event(const EvacuationFailedInfo& ef_info) const;
 230 };
 231 #endif
 232 
 233 class CMSTracer : public OldGCTracer {
 234  public:
 235   CMSTracer() : OldGCTracer(ConcurrentMarkSweep) {}
 236 };
 237 
 238 class G1OldTracer : public OldGCTracer {
 239  public:
 240   G1OldTracer() : OldGCTracer(G1Old) {}
 241 };
 242 
 243 #endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_GCTRACE_HPP