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