1 /*
   2  * Copyright (c) 2012, 2015, 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_GCTRACE_HPP
  26 #define SHARE_VM_GC_SHARED_GCTRACE_HPP
  27 
  28 #include "gc/shared/copyFailedInfo.hpp"
  29 #include "gc/shared/gcCause.hpp"
  30 #include "gc/shared/gcId.hpp"
  31 #include "gc/shared/gcName.hpp"
  32 #include "gc/shared/gcWhen.hpp"
  33 #include "memory/allocation.hpp"
  34 #include "memory/metaspace.hpp"
  35 #include "memory/referenceType.hpp"
  36 #include "utilities/macros.hpp"
  37 #include "utilities/ticks.hpp"
  38 #if INCLUDE_ALL_GCS
  39 #include "gc/g1/g1YCTypes.hpp"
  40 #include "gcHeapSummary.hpp"
  41 #endif
  42 
  43 class EvacuationInfo;
  44 class GCHeapSummary;
  45 class MetaspaceChunkFreeListSummary;
  46 class MetaspaceSummary;
  47 class PSHeapSummary;
  48 class G1HeapSummary;
  49 class ReferenceProcessorStats;
  50 class TimePartitions;
  51 class BoolObjectClosure;
  52 
  53 class SharedGCInfo VALUE_OBJ_CLASS_SPEC {
  54  private:
  55   GCId _gc_id;
  56   GCName _name;
  57   GCCause::Cause _cause;
  58   Ticks     _start_timestamp;
  59   Ticks     _end_timestamp;
  60   Tickspan  _sum_of_pauses;
  61   Tickspan  _longest_pause;
  62 
  63  public:
  64   SharedGCInfo(GCName name) :
  65     _gc_id(GCId::undefined()),
  66     _name(name),
  67     _cause(GCCause::_last_gc_cause),
  68     _start_timestamp(),
  69     _end_timestamp(),
  70     _sum_of_pauses(),
  71     _longest_pause() {
  72   }
  73 
  74   void set_gc_id(GCId gc_id) { _gc_id = gc_id; }
  75   const GCId& gc_id() const { return _gc_id; }
  76 
  77   void set_start_timestamp(const Ticks& timestamp) { _start_timestamp = timestamp; }
  78   const Ticks start_timestamp() const { return _start_timestamp; }
  79 
  80   void set_end_timestamp(const Ticks& timestamp) { _end_timestamp = timestamp; }
  81   const Ticks end_timestamp() const { return _end_timestamp; }
  82 
  83   void set_name(GCName name) { _name = name; }
  84   GCName name() const { return _name; }
  85 
  86   void set_cause(GCCause::Cause cause) { _cause = cause; }
  87   GCCause::Cause cause() const { return _cause; }
  88 
  89   void set_sum_of_pauses(const Tickspan& duration) { _sum_of_pauses = duration; }
  90   const Tickspan sum_of_pauses() const { return _sum_of_pauses; }
  91 
  92   void set_longest_pause(const Tickspan& duration) { _longest_pause = duration; }
  93   const Tickspan longest_pause() const { return _longest_pause; }
  94 };
  95 
  96 class ParallelOldGCInfo VALUE_OBJ_CLASS_SPEC {
  97   void* _dense_prefix;
  98  public:
  99   ParallelOldGCInfo() : _dense_prefix(NULL) {}
 100   void report_dense_prefix(void* addr) {
 101     _dense_prefix = addr;
 102   }
 103   void* dense_prefix() const { return _dense_prefix; }
 104 };
 105 
 106 #if INCLUDE_ALL_GCS
 107 
 108 class G1YoungGCInfo VALUE_OBJ_CLASS_SPEC {
 109   G1YCType _type;
 110  public:
 111   G1YoungGCInfo() : _type(G1YCTypeEndSentinel) {}
 112   void set_type(G1YCType type) {
 113     _type = type;
 114   }
 115   G1YCType type() const { return _type; }
 116 };
 117 
 118 #endif // INCLUDE_ALL_GCS
 119 
 120 class GCTracer : public ResourceObj {
 121  protected:
 122   SharedGCInfo _shared_gc_info;
 123 
 124  public:
 125   void report_gc_start(GCCause::Cause cause, const Ticks& timestamp);
 126   void report_gc_end(const Ticks& timestamp, TimePartitions* time_partitions);
 127   void report_gc_heap_summary(GCWhen::Type when, const GCHeapSummary& heap_summary) const;
 128   void report_metaspace_summary(GCWhen::Type when, const MetaspaceSummary& metaspace_summary) const;
 129   void report_gc_reference_stats(const ReferenceProcessorStats& rp) const;
 130   void report_object_count_after_gc(BoolObjectClosure* object_filter) NOT_SERVICES_RETURN;
 131   bool has_reported_gc_start() const;
 132   const GCId& gc_id() { return _shared_gc_info.gc_id(); }
 133 
 134  protected:
 135   GCTracer(GCName name) : _shared_gc_info(name) {}
 136   void report_gc_start_impl(GCCause::Cause cause, const Ticks& timestamp);
 137   virtual void report_gc_end_impl(const Ticks& timestamp, TimePartitions* time_partitions);
 138 
 139  private:
 140   void send_garbage_collection_event() const;
 141   void send_gc_heap_summary_event(GCWhen::Type when, const GCHeapSummary& heap_summary) const;
 142   void send_meta_space_summary_event(GCWhen::Type when, const MetaspaceSummary& meta_space_summary) const;
 143   void send_metaspace_chunk_free_list_summary(GCWhen::Type when, Metaspace::MetadataType mdtype, const MetaspaceChunkFreeListSummary& summary) const;
 144   void send_reference_stats_event(ReferenceType type, size_t count) const;
 145   void send_phase_events(TimePartitions* time_partitions) const;
 146 };
 147 
 148 class YoungGCTracer : public GCTracer {
 149   static const uint UNSET_TENURING_THRESHOLD = (uint) -1;
 150 
 151   uint _tenuring_threshold;
 152 
 153  protected:
 154   YoungGCTracer(GCName name) : GCTracer(name), _tenuring_threshold(UNSET_TENURING_THRESHOLD) {}
 155   virtual void report_gc_end_impl(const Ticks& timestamp, TimePartitions* time_partitions);
 156 
 157  public:
 158   void report_promotion_failed(const PromotionFailedInfo& pf_info) const;
 159   void report_tenuring_threshold(const uint tenuring_threshold);
 160 
 161   /*
 162    * Methods for reporting Promotion in new or outside PLAB Events.
 163    *
 164    * The object age is always required as it is not certain that the mark word
 165    * of the oop can be trusted at this stage.
 166    *
 167    * obj_size is the size of the promoted object in bytes.
 168    *
 169    * tenured should be true if the object has been promoted to the old
 170    * space during this GC, if the object is copied to survivor space
 171    * from young space or survivor space (aging) tenured should be false.
 172    *
 173    * plab_size is the size of the newly allocated PLAB in bytes.
 174    */
 175   bool should_report_promotion_in_new_plab_event() const;
 176   bool should_report_promotion_outside_plab_event() const;
 177   void report_promotion_in_new_plab_event(Klass* klass, size_t obj_size,
 178                                           uint age, bool tenured,
 179                                           size_t plab_size) const;
 180   void report_promotion_outside_plab_event(Klass* klass, size_t obj_size,
 181                                            uint age, bool tenured) const;
 182 
 183  private:
 184   void send_young_gc_event() const;
 185   void send_promotion_failed_event(const PromotionFailedInfo& pf_info) const;
 186   bool should_send_promotion_in_new_plab_event() const;
 187   bool should_send_promotion_outside_plab_event() const;
 188   void send_promotion_in_new_plab_event(Klass* klass, size_t obj_size,
 189                                         uint age, bool tenured,
 190                                         size_t plab_size) const;
 191   void send_promotion_outside_plab_event(Klass* klass, size_t obj_size,
 192                                          uint age, bool tenured) const;
 193 };
 194 
 195 class OldGCTracer : public GCTracer {
 196  protected:
 197   OldGCTracer(GCName name) : GCTracer(name) {}
 198   virtual void report_gc_end_impl(const Ticks& timestamp, TimePartitions* time_partitions);
 199 
 200  public:
 201   void report_concurrent_mode_failure();
 202 
 203  private:
 204   void send_old_gc_event() const;
 205   void send_concurrent_mode_failure_event();
 206 };
 207 
 208 class ParallelOldTracer : public OldGCTracer {
 209   ParallelOldGCInfo _parallel_old_gc_info;
 210 
 211  public:
 212   ParallelOldTracer() : OldGCTracer(ParallelOld) {}
 213   void report_dense_prefix(void* dense_prefix);
 214 
 215  protected:
 216   void report_gc_end_impl(const Ticks& timestamp, TimePartitions* time_partitions);
 217 
 218  private:
 219   void send_parallel_old_event() const;
 220 };
 221 
 222 class SerialOldTracer : public OldGCTracer {
 223  public:
 224   SerialOldTracer() : OldGCTracer(SerialOld) {}
 225 };
 226 
 227 class ParallelScavengeTracer : public YoungGCTracer {
 228  public:
 229   ParallelScavengeTracer() : YoungGCTracer(ParallelScavenge) {}
 230 };
 231 
 232 class DefNewTracer : public YoungGCTracer {
 233  public:
 234   DefNewTracer() : YoungGCTracer(DefNew) {}
 235 };
 236 
 237 class ParNewTracer : public YoungGCTracer {
 238  public:
 239   ParNewTracer() : YoungGCTracer(ParNew) {}
 240 };
 241 
 242 #if INCLUDE_ALL_GCS
 243 class G1MMUTracer : public AllStatic {
 244   static void send_g1_mmu_event(const GCId& gcId, double timeSlice, double gcTime, double maxTime);
 245 
 246  public:
 247   static void report_mmu(const GCId& gcId, double timeSlice, double gcTime, double maxTime);
 248 };
 249 
 250 class G1NewTracer : public YoungGCTracer {
 251   G1YoungGCInfo _g1_young_gc_info;
 252 
 253  public:
 254   G1NewTracer() : YoungGCTracer(G1New) {}
 255 
 256   void report_yc_type(G1YCType type);
 257   void report_gc_end_impl(const Ticks& timestamp, TimePartitions* time_partitions);
 258   void report_evacuation_info(EvacuationInfo* info);
 259   void report_evacuation_failed(EvacuationFailedInfo& ef_info);
 260 
 261   void report_evacuation_statistics(const G1EvacSummary& young_summary, const G1EvacSummary& old_summary) const;
 262  private:
 263   void send_g1_young_gc_event();
 264   void send_evacuation_info_event(EvacuationInfo* info);
 265   void send_evacuation_failed_event(const EvacuationFailedInfo& ef_info) const;
 266 
 267   void send_young_evacuation_statistics(const G1EvacSummary& summary) const;
 268   void send_old_evacuation_statistics(const G1EvacSummary& summary) const;
 269 };
 270 #endif
 271 
 272 class CMSTracer : public OldGCTracer {
 273  public:
 274   CMSTracer() : OldGCTracer(ConcurrentMarkSweep) {}
 275 };
 276 
 277 class G1OldTracer : public OldGCTracer {
 278  public:
 279   G1OldTracer() : OldGCTracer(G1Old) {}
 280 };
 281 
 282 #endif // SHARE_VM_GC_SHARED_GCTRACE_HPP