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 #include "precompiled.hpp" 26 #include "gc_implementation/shared/gcHeapSummary.hpp" 27 #include "gc_implementation/shared/gcTimer.hpp" 28 #include "gc_implementation/shared/gcTrace.hpp" 29 #include "gc_implementation/shared/promotionFailedInfo.hpp" 30 #include "memory/heapInspection.hpp" 31 #include "memory/iterator.hpp" 32 #include "memory/referenceProcessorStats.hpp" 33 #include "utilities/globalDefinitions.hpp" 34 35 #define assert_unset_gc_id() assert(_shared_gc_info.id() == SharedGCInfo::UNSET_GCID, "GC already started?") 36 #define assert_set_gc_id() assert(_shared_gc_info.id() != SharedGCInfo::UNSET_GCID, "GC not started?") 37 38 static jlong GCTracer_next_gc_id = 0; 39 static GCId create_new_gc_id() { 40 return GCTracer_next_gc_id++; 41 } 42 43 void GCTracer::report_gc_start_impl(GCCause::Cause cause, jlong timestamp) { 44 assert_unset_gc_id(); 45 46 GCId gc_id = create_new_gc_id(); 47 _shared_gc_info.set_id(gc_id); 48 _shared_gc_info.set_cause(cause); 49 _shared_gc_info.set_start_timestamp(timestamp); 50 } 51 52 void GCTracer::report_gc_start(GCCause::Cause cause, jlong timestamp) { 53 assert_unset_gc_id(); 54 55 report_gc_start_impl(cause, timestamp); 56 } 57 58 bool GCTracer::has_reported_gc_start() const { 59 return _shared_gc_info.id() != SharedGCInfo::UNSET_GCID; 60 } 61 62 void GCTracer::report_gc_end_impl(jlong timestamp, TimePartitions* time_partitions) { 63 assert_set_gc_id(); 64 65 _shared_gc_info.set_sum_of_pauses(time_partitions->sum_of_pauses()); 66 _shared_gc_info.set_longest_pause(time_partitions->longest_pause()); 67 _shared_gc_info.set_end_timestamp(timestamp); 68 69 send_phase_events(time_partitions); 70 send_garbage_collection_event(); 71 } 72 73 void GCTracer::report_gc_end(jlong timestamp, TimePartitions* time_partitions) { 74 assert_set_gc_id(); 75 76 report_gc_end_impl(timestamp, time_partitions); 77 78 _shared_gc_info.set_id(SharedGCInfo::UNSET_GCID); 79 } 80 81 void GCTracer::report_gc_reference_stats(const ReferenceProcessorStats& rps) const { 82 assert_set_gc_id(); 83 84 send_reference_stats_event(REF_SOFT, rps.soft_count()); 85 send_reference_stats_event(REF_WEAK, rps.weak_count()); 86 send_reference_stats_event(REF_FINAL, rps.final_count()); 87 send_reference_stats_event(REF_PHANTOM, rps.phantom_count()); 88 } 89 90 class ObjectCountEventSenderClosure : public KlassInfoClosure { 91 GCTracer* _gc_tracer; 92 public: 93 ObjectCountEventSenderClosure(GCTracer* gc_tracer) : _gc_tracer(gc_tracer) {} 94 private: 95 void do_cinfo(KlassInfoEntry* entry) { 96 _gc_tracer->send_object_count_after_gc_event(entry->klass(), entry->count(), 97 entry->words() * BytesPerWord); 98 } 99 }; 100 101 void GCTracer::report_object_count_after_gc(BoolObjectClosure *is_alive_cl) { 102 if (should_send_object_count_after_gc_event()) { 103 ResourceMark rm; 104 105 KlassInfoTable cit(HeapInspection::start_of_perm_gen()); 106 if (!cit.allocation_failed()) { 107 ObjectCountEventSenderClosure event_sender(this); 108 HeapInspection::instance_inspection(&cit, &event_sender, false, is_alive_cl); 109 } 110 } 111 } 112 113 void GCTracer::report_gc_heap_summary(GCWhen::Type when, const GCHeapSummary& heap_summary, const PermGenSummary& perm_gen_summary) const { 114 assert_set_gc_id(); 115 116 send_gc_heap_summary_event(when, heap_summary); 117 send_perm_gen_summary_event(when, perm_gen_summary); 118 } 119 120 void YoungGCTracer::report_gc_end_impl(jlong timestamp, TimePartitions* time_partitions) { 121 assert_set_gc_id(); 122 123 GCTracer::report_gc_end_impl(timestamp, time_partitions); 124 send_young_gc_event(); 125 } 126 127 void YoungGCTracer::report_promotion_failed(const PromotionFailedInfo& pf_info) { 128 assert_set_gc_id(); 129 130 send_promotion_failed_event(pf_info); 131 } 132 133 134 void OldGCTracer::report_gc_end_impl(jlong timestamp, TimePartitions* time_partitions) { 135 assert_set_gc_id(); 136 137 GCTracer::report_gc_end_impl(timestamp, time_partitions); 138 send_old_gc_event(); 139 } 140 141 void ParallelOldTracer::report_gc_end_impl(jlong timestamp, TimePartitions* time_partitions) { 142 assert_set_gc_id(); 143 144 OldGCTracer::report_gc_end_impl(timestamp, time_partitions); 145 send_parallel_old_event(); 146 } 147 148 void ParallelOldTracer::report_dense_prefix(void* dense_prefix) { 149 assert_set_gc_id(); 150 151 _parallel_old_gc_info.report_dense_prefix(dense_prefix); 152 } 153 154 #ifndef SERIALGC 155 void G1NewTracer::report_yc_type(G1YCType type) { 156 assert_set_gc_id(); 157 158 _g1_young_gc_info.set_type(type); 159 } 160 161 void G1NewTracer::report_gc_end_impl(jlong timestamp, TimePartitions* time_partitions) { 162 assert_set_gc_id(); 163 164 YoungGCTracer::report_gc_end_impl(timestamp, time_partitions); 165 send_g1_young_gc_event(); 166 } 167 #endif