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