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 #include "precompiled.hpp" 26 #include "gc/shared/copyFailedInfo.hpp" 27 #include "gc/shared/gcHeapSummary.hpp" 28 #include "gc/shared/gcId.hpp" 29 #include "gc/shared/gcTimer.hpp" 30 #include "gc/shared/gcTrace.hpp" 31 #include "gc/shared/objectCountEventSender.hpp" 32 #include "gc/shared/referenceProcessorStats.hpp" 33 #include "memory/heapInspection.hpp" 34 #include "memory/resourceArea.hpp" 35 #include "runtime/os.hpp" 36 #include "utilities/globalDefinitions.hpp" 37 #include "utilities/macros.hpp" 38 #include "utilities/ticks.inline.hpp" 39 #if INCLUDE_ALL_GCS 40 #include "gc/g1/evacuationInfo.hpp" 41 #endif 42 43 void GCTracer::report_gc_start_impl(GCCause::Cause cause, const Ticks& timestamp) { 44 _shared_gc_info.set_cause(cause); 45 _shared_gc_info.set_start_timestamp(timestamp); 46 } 47 48 void GCTracer::report_gc_start(GCCause::Cause cause, const Ticks& timestamp) { 49 report_gc_start_impl(cause, timestamp); 50 } 51 52 void GCTracer::report_gc_end_impl(const Ticks& timestamp, TimePartitions* time_partitions) { 53 _shared_gc_info.set_sum_of_pauses(time_partitions->sum_of_pauses()); 54 _shared_gc_info.set_longest_pause(time_partitions->longest_pause()); 55 _shared_gc_info.set_end_timestamp(timestamp); 56 57 send_phase_events(time_partitions); 58 send_garbage_collection_event(); 59 } 60 61 void GCTracer::report_gc_end(const Ticks& timestamp, TimePartitions* time_partitions) { 62 report_gc_end_impl(timestamp, time_partitions); 63 } 64 65 void GCTracer::report_gc_reference_stats(const ReferenceProcessorStats& rps) const { 66 send_reference_stats_event(REF_SOFT, rps.soft_count()); 67 send_reference_stats_event(REF_WEAK, rps.weak_count()); 68 send_reference_stats_event(REF_FINAL, rps.final_count()); 69 send_reference_stats_event(REF_PHANTOM, rps.phantom_count()); 70 send_reference_stats_event(REF_CLEANER, rps.cleaner_count()); 71 send_reference_stats_event(REF_JNI, rps.jni_weak_ref_count()); 72 } 73 74 #if INCLUDE_SERVICES 75 class ObjectCountEventSenderClosure : public KlassInfoClosure { 76 const double _size_threshold_percentage; 77 const size_t _total_size_in_words; 78 const Ticks _timestamp; 79 80 public: 81 ObjectCountEventSenderClosure(size_t total_size_in_words, const Ticks& timestamp) : 82 _size_threshold_percentage(ObjectCountCutOffPercent / 100), 83 _total_size_in_words(total_size_in_words), 84 _timestamp(timestamp) 85 {} 86 87 virtual void do_cinfo(KlassInfoEntry* entry) { 88 if (should_send_event(entry)) { 89 ObjectCountEventSender::send(entry, _timestamp); 90 } 91 } 92 93 private: 94 bool should_send_event(const KlassInfoEntry* entry) const { 95 double percentage_of_heap = ((double) entry->words()) / _total_size_in_words; 96 return percentage_of_heap >= _size_threshold_percentage; 97 } 98 }; 99 100 void GCTracer::report_object_count_after_gc(BoolObjectClosure* is_alive_cl) { 101 assert(is_alive_cl != NULL, "Must supply function to check liveness"); 102 103 if (ObjectCountEventSender::should_send_event()) { 104 ResourceMark rm; 105 106 KlassInfoTable cit(false); 107 if (!cit.allocation_failed()) { 108 HeapInspection hi(false, false, false, NULL); 109 hi.populate_table(&cit, is_alive_cl); 110 ObjectCountEventSenderClosure event_sender(cit.size_of_instances_in_words(), Ticks::now()); 111 cit.iterate(&event_sender); 112 } 113 } 114 } 115 #endif // INCLUDE_SERVICES 116 117 void GCTracer::report_gc_heap_summary(GCWhen::Type when, const GCHeapSummary& heap_summary) const { 118 send_gc_heap_summary_event(when, heap_summary); 119 } 120 121 void GCTracer::report_metaspace_summary(GCWhen::Type when, const MetaspaceSummary& summary) const { 122 send_meta_space_summary_event(when, summary); 123 124 send_metaspace_chunk_free_list_summary(when, Metaspace::NonClassType, summary.metaspace_chunk_free_list_summary()); 125 if (UseCompressedClassPointers) { 126 send_metaspace_chunk_free_list_summary(when, Metaspace::ClassType, summary.class_chunk_free_list_summary()); 127 } 128 } 129 130 void YoungGCTracer::report_gc_end_impl(const Ticks& timestamp, TimePartitions* time_partitions) { 131 assert(_tenuring_threshold != UNSET_TENURING_THRESHOLD, "Tenuring threshold has not been reported"); 132 133 GCTracer::report_gc_end_impl(timestamp, time_partitions); 134 send_young_gc_event(); 135 136 _tenuring_threshold = UNSET_TENURING_THRESHOLD; 137 } 138 139 void YoungGCTracer::report_promotion_failed(const PromotionFailedInfo& pf_info) const { 140 send_promotion_failed_event(pf_info); 141 } 142 143 void YoungGCTracer::report_tenuring_threshold(const uint tenuring_threshold) { 144 _tenuring_threshold = tenuring_threshold; 145 } 146 147 bool YoungGCTracer::should_report_promotion_events() const { 148 return should_report_promotion_in_new_plab_event() || 149 should_report_promotion_outside_plab_event(); 150 } 151 152 bool YoungGCTracer::should_report_promotion_in_new_plab_event() const { 153 return should_send_promotion_in_new_plab_event(); 154 } 155 156 bool YoungGCTracer::should_report_promotion_outside_plab_event() const { 157 return should_send_promotion_outside_plab_event(); 158 } 159 160 void YoungGCTracer::report_promotion_in_new_plab_event(Klass* klass, size_t obj_size, 161 uint age, bool tenured, 162 size_t plab_size) const { 163 send_promotion_in_new_plab_event(klass, obj_size, age, tenured, plab_size); 164 } 165 166 void YoungGCTracer::report_promotion_outside_plab_event(Klass* klass, size_t obj_size, 167 uint age, bool tenured) const { 168 send_promotion_outside_plab_event(klass, obj_size, age, tenured); 169 } 170 171 void OldGCTracer::report_gc_end_impl(const Ticks& timestamp, TimePartitions* time_partitions) { 172 GCTracer::report_gc_end_impl(timestamp, time_partitions); 173 send_old_gc_event(); 174 } 175 176 void ParallelOldTracer::report_gc_end_impl(const Ticks& timestamp, TimePartitions* time_partitions) { 177 OldGCTracer::report_gc_end_impl(timestamp, time_partitions); 178 send_parallel_old_event(); 179 } 180 181 void ParallelOldTracer::report_dense_prefix(void* dense_prefix) { 182 _parallel_old_gc_info.report_dense_prefix(dense_prefix); 183 } 184 185 void OldGCTracer::report_concurrent_mode_failure() { 186 send_concurrent_mode_failure_event(); 187 } 188 189 #if INCLUDE_ALL_GCS 190 void G1MMUTracer::report_mmu(double timeSlice, double gcTime, double maxTime) { 191 send_g1_mmu_event(timeSlice, gcTime, maxTime); 192 } 193 194 void G1NewTracer::report_yc_type(G1YCType type) { 195 _g1_young_gc_info.set_type(type); 196 } 197 198 void G1NewTracer::report_gc_end_impl(const Ticks& timestamp, TimePartitions* time_partitions) { 199 YoungGCTracer::report_gc_end_impl(timestamp, time_partitions); 200 send_g1_young_gc_event(); 201 } 202 203 void G1NewTracer::report_evacuation_info(EvacuationInfo* info) { 204 send_evacuation_info_event(info); 205 } 206 207 void G1NewTracer::report_evacuation_failed(EvacuationFailedInfo& ef_info) { 208 send_evacuation_failed_event(ef_info); 209 ef_info.reset(); 210 } 211 212 void G1NewTracer::report_evacuation_statistics(const G1EvacSummary& young_summary, const G1EvacSummary& old_summary) const { 213 send_young_evacuation_statistics(young_summary); 214 send_old_evacuation_statistics(old_summary); 215 } 216 217 #endif