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