1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/gc_implementation/shared/gcTraceSend.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,321 @@ 1.4 +/* 1.5 + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "precompiled.hpp" 1.29 +#include "gc_implementation/shared/gcHeapSummary.hpp" 1.30 +#include "gc_implementation/shared/gcTimer.hpp" 1.31 +#include "gc_implementation/shared/gcTrace.hpp" 1.32 +#include "gc_implementation/shared/gcWhen.hpp" 1.33 +#include "gc_implementation/shared/copyFailedInfo.hpp" 1.34 +#include "runtime/os.hpp" 1.35 +#include "trace/tracing.hpp" 1.36 +#include "trace/traceBackend.hpp" 1.37 +#if INCLUDE_ALL_GCS 1.38 +#include "gc_implementation/g1/evacuationInfo.hpp" 1.39 +#include "gc_implementation/g1/g1YCTypes.hpp" 1.40 +#endif 1.41 + 1.42 +// All GC dependencies against the trace framework is contained within this file. 1.43 + 1.44 +typedef uintptr_t TraceAddress; 1.45 + 1.46 +void GCTracer::send_garbage_collection_event() const { 1.47 + EventGCGarbageCollection event(UNTIMED); 1.48 + if (event.should_commit()) { 1.49 + event.set_gcId(_shared_gc_info.id()); 1.50 + event.set_name(_shared_gc_info.name()); 1.51 + event.set_cause((u2) _shared_gc_info.cause()); 1.52 + event.set_sumOfPauses(_shared_gc_info.sum_of_pauses()); 1.53 + event.set_longestPause(_shared_gc_info.longest_pause()); 1.54 + event.set_starttime(_shared_gc_info.start_timestamp()); 1.55 + event.set_endtime(_shared_gc_info.end_timestamp()); 1.56 + event.commit(); 1.57 + } 1.58 +} 1.59 + 1.60 +void GCTracer::send_reference_stats_event(ReferenceType type, size_t count) const { 1.61 + EventGCReferenceStatistics e; 1.62 + if (e.should_commit()) { 1.63 + e.set_gcId(_shared_gc_info.id()); 1.64 + e.set_type((u1)type); 1.65 + e.set_count(count); 1.66 + e.commit(); 1.67 + } 1.68 +} 1.69 + 1.70 +void GCTracer::send_metaspace_chunk_free_list_summary(GCWhen::Type when, Metaspace::MetadataType mdtype, 1.71 + const MetaspaceChunkFreeListSummary& summary) const { 1.72 + EventMetaspaceChunkFreeListSummary e; 1.73 + if (e.should_commit()) { 1.74 + e.set_gcId(_shared_gc_info.id()); 1.75 + e.set_when(when); 1.76 + e.set_metadataType(mdtype); 1.77 + 1.78 + e.set_specializedChunks(summary.num_specialized_chunks()); 1.79 + e.set_specializedChunksTotalSize(summary.specialized_chunks_size_in_bytes()); 1.80 + 1.81 + e.set_smallChunks(summary.num_small_chunks()); 1.82 + e.set_smallChunksTotalSize(summary.small_chunks_size_in_bytes()); 1.83 + 1.84 + e.set_mediumChunks(summary.num_medium_chunks()); 1.85 + e.set_mediumChunksTotalSize(summary.medium_chunks_size_in_bytes()); 1.86 + 1.87 + e.set_humongousChunks(summary.num_humongous_chunks()); 1.88 + e.set_humongousChunksTotalSize(summary.humongous_chunks_size_in_bytes()); 1.89 + 1.90 + e.commit(); 1.91 + } 1.92 +} 1.93 + 1.94 +void ParallelOldTracer::send_parallel_old_event() const { 1.95 + EventGCParallelOld e(UNTIMED); 1.96 + if (e.should_commit()) { 1.97 + e.set_gcId(_shared_gc_info.id()); 1.98 + e.set_densePrefix((TraceAddress)_parallel_old_gc_info.dense_prefix()); 1.99 + e.set_starttime(_shared_gc_info.start_timestamp()); 1.100 + e.set_endtime(_shared_gc_info.end_timestamp()); 1.101 + e.commit(); 1.102 + } 1.103 +} 1.104 + 1.105 +void YoungGCTracer::send_young_gc_event() const { 1.106 + EventGCYoungGarbageCollection e(UNTIMED); 1.107 + if (e.should_commit()) { 1.108 + e.set_gcId(_shared_gc_info.id()); 1.109 + e.set_tenuringThreshold(_tenuring_threshold); 1.110 + e.set_starttime(_shared_gc_info.start_timestamp()); 1.111 + e.set_endtime(_shared_gc_info.end_timestamp()); 1.112 + e.commit(); 1.113 + } 1.114 +} 1.115 + 1.116 +void OldGCTracer::send_old_gc_event() const { 1.117 + EventGCOldGarbageCollection e(UNTIMED); 1.118 + if (e.should_commit()) { 1.119 + e.set_gcId(_shared_gc_info.id()); 1.120 + e.set_starttime(_shared_gc_info.start_timestamp()); 1.121 + e.set_endtime(_shared_gc_info.end_timestamp()); 1.122 + e.commit(); 1.123 + } 1.124 +} 1.125 + 1.126 +static TraceStructCopyFailed to_trace_struct(const CopyFailedInfo& cf_info) { 1.127 + TraceStructCopyFailed failed_info; 1.128 + failed_info.set_objectCount(cf_info.failed_count()); 1.129 + failed_info.set_firstSize(cf_info.first_size()); 1.130 + failed_info.set_smallestSize(cf_info.smallest_size()); 1.131 + failed_info.set_totalSize(cf_info.total_size()); 1.132 + return failed_info; 1.133 +} 1.134 + 1.135 +void YoungGCTracer::send_promotion_failed_event(const PromotionFailedInfo& pf_info) const { 1.136 + EventPromotionFailed e; 1.137 + if (e.should_commit()) { 1.138 + e.set_gcId(_shared_gc_info.id()); 1.139 + e.set_data(to_trace_struct(pf_info)); 1.140 + e.set_thread(pf_info.thread()->thread_id()); 1.141 + e.commit(); 1.142 + } 1.143 +} 1.144 + 1.145 +// Common to CMS and G1 1.146 +void OldGCTracer::send_concurrent_mode_failure_event() { 1.147 + EventConcurrentModeFailure e; 1.148 + if (e.should_commit()) { 1.149 + e.set_gcId(_shared_gc_info.id()); 1.150 + e.commit(); 1.151 + } 1.152 +} 1.153 + 1.154 +#if INCLUDE_ALL_GCS 1.155 +void G1NewTracer::send_g1_young_gc_event() { 1.156 + EventGCG1GarbageCollection e(UNTIMED); 1.157 + if (e.should_commit()) { 1.158 + e.set_gcId(_shared_gc_info.id()); 1.159 + e.set_type(_g1_young_gc_info.type()); 1.160 + e.set_starttime(_shared_gc_info.start_timestamp()); 1.161 + e.set_endtime(_shared_gc_info.end_timestamp()); 1.162 + e.commit(); 1.163 + } 1.164 +} 1.165 + 1.166 +void G1NewTracer::send_evacuation_info_event(EvacuationInfo* info) { 1.167 + EventEvacuationInfo e; 1.168 + if (e.should_commit()) { 1.169 + e.set_gcId(_shared_gc_info.id()); 1.170 + e.set_cSetRegions(info->collectionset_regions()); 1.171 + e.set_cSetUsedBefore(info->collectionset_used_before()); 1.172 + e.set_cSetUsedAfter(info->collectionset_used_after()); 1.173 + e.set_allocationRegions(info->allocation_regions()); 1.174 + e.set_allocRegionsUsedBefore(info->alloc_regions_used_before()); 1.175 + e.set_allocRegionsUsedAfter(info->alloc_regions_used_before() + info->bytes_copied()); 1.176 + e.set_bytesCopied(info->bytes_copied()); 1.177 + e.set_regionsFreed(info->regions_freed()); 1.178 + e.commit(); 1.179 + } 1.180 +} 1.181 + 1.182 +void G1NewTracer::send_evacuation_failed_event(const EvacuationFailedInfo& ef_info) const { 1.183 + EventEvacuationFailed e; 1.184 + if (e.should_commit()) { 1.185 + e.set_gcId(_shared_gc_info.id()); 1.186 + e.set_data(to_trace_struct(ef_info)); 1.187 + e.commit(); 1.188 + } 1.189 +} 1.190 +#endif 1.191 + 1.192 +static TraceStructVirtualSpace to_trace_struct(const VirtualSpaceSummary& summary) { 1.193 + TraceStructVirtualSpace space; 1.194 + space.set_start((TraceAddress)summary.start()); 1.195 + space.set_committedEnd((TraceAddress)summary.committed_end()); 1.196 + space.set_committedSize(summary.committed_size()); 1.197 + space.set_reservedEnd((TraceAddress)summary.reserved_end()); 1.198 + space.set_reservedSize(summary.reserved_size()); 1.199 + return space; 1.200 +} 1.201 + 1.202 +static TraceStructObjectSpace to_trace_struct(const SpaceSummary& summary) { 1.203 + TraceStructObjectSpace space; 1.204 + space.set_start((TraceAddress)summary.start()); 1.205 + space.set_end((TraceAddress)summary.end()); 1.206 + space.set_used(summary.used()); 1.207 + space.set_size(summary.size()); 1.208 + return space; 1.209 +} 1.210 + 1.211 +class GCHeapSummaryEventSender : public GCHeapSummaryVisitor { 1.212 + GCId _id; 1.213 + GCWhen::Type _when; 1.214 + public: 1.215 + GCHeapSummaryEventSender(GCId id, GCWhen::Type when) : _id(id), _when(when) {} 1.216 + 1.217 + void visit(const GCHeapSummary* heap_summary) const { 1.218 + const VirtualSpaceSummary& heap_space = heap_summary->heap(); 1.219 + 1.220 + EventGCHeapSummary e; 1.221 + if (e.should_commit()) { 1.222 + e.set_gcId(_id); 1.223 + e.set_when((u1)_when); 1.224 + e.set_heapSpace(to_trace_struct(heap_space)); 1.225 + e.set_heapUsed(heap_summary->used()); 1.226 + e.commit(); 1.227 + } 1.228 + } 1.229 + 1.230 + void visit(const PSHeapSummary* ps_heap_summary) const { 1.231 + visit((GCHeapSummary*)ps_heap_summary); 1.232 + 1.233 + const VirtualSpaceSummary& old_summary = ps_heap_summary->old(); 1.234 + const SpaceSummary& old_space = ps_heap_summary->old_space(); 1.235 + const VirtualSpaceSummary& young_summary = ps_heap_summary->young(); 1.236 + const SpaceSummary& eden_space = ps_heap_summary->eden(); 1.237 + const SpaceSummary& from_space = ps_heap_summary->from(); 1.238 + const SpaceSummary& to_space = ps_heap_summary->to(); 1.239 + 1.240 + EventPSHeapSummary e; 1.241 + if (e.should_commit()) { 1.242 + e.set_gcId(_id); 1.243 + e.set_when((u1)_when); 1.244 + 1.245 + e.set_oldSpace(to_trace_struct(ps_heap_summary->old())); 1.246 + e.set_oldObjectSpace(to_trace_struct(ps_heap_summary->old_space())); 1.247 + e.set_youngSpace(to_trace_struct(ps_heap_summary->young())); 1.248 + e.set_edenSpace(to_trace_struct(ps_heap_summary->eden())); 1.249 + e.set_fromSpace(to_trace_struct(ps_heap_summary->from())); 1.250 + e.set_toSpace(to_trace_struct(ps_heap_summary->to())); 1.251 + e.commit(); 1.252 + } 1.253 + } 1.254 +}; 1.255 + 1.256 +void GCTracer::send_gc_heap_summary_event(GCWhen::Type when, const GCHeapSummary& heap_summary) const { 1.257 + GCHeapSummaryEventSender visitor(_shared_gc_info.id(), when); 1.258 + heap_summary.accept(&visitor); 1.259 +} 1.260 + 1.261 +static TraceStructMetaspaceSizes to_trace_struct(const MetaspaceSizes& sizes) { 1.262 + TraceStructMetaspaceSizes meta_sizes; 1.263 + 1.264 + meta_sizes.set_committed(sizes.committed()); 1.265 + meta_sizes.set_used(sizes.used()); 1.266 + meta_sizes.set_reserved(sizes.reserved()); 1.267 + 1.268 + return meta_sizes; 1.269 +} 1.270 + 1.271 +void GCTracer::send_meta_space_summary_event(GCWhen::Type when, const MetaspaceSummary& meta_space_summary) const { 1.272 + EventMetaspaceSummary e; 1.273 + if (e.should_commit()) { 1.274 + e.set_gcId(_shared_gc_info.id()); 1.275 + e.set_when((u1) when); 1.276 + e.set_gcThreshold(meta_space_summary.capacity_until_GC()); 1.277 + e.set_metaspace(to_trace_struct(meta_space_summary.meta_space())); 1.278 + e.set_dataSpace(to_trace_struct(meta_space_summary.data_space())); 1.279 + e.set_classSpace(to_trace_struct(meta_space_summary.class_space())); 1.280 + e.commit(); 1.281 + } 1.282 +} 1.283 + 1.284 +class PhaseSender : public PhaseVisitor { 1.285 + GCId _gc_id; 1.286 + public: 1.287 + PhaseSender(GCId gc_id) : _gc_id(gc_id) {} 1.288 + 1.289 + template<typename T> 1.290 + void send_phase(PausePhase* pause) { 1.291 + T event(UNTIMED); 1.292 + if (event.should_commit()) { 1.293 + event.set_gcId(_gc_id); 1.294 + event.set_name(pause->name()); 1.295 + event.set_starttime(pause->start()); 1.296 + event.set_endtime(pause->end()); 1.297 + event.commit(); 1.298 + } 1.299 + } 1.300 + 1.301 + void visit(GCPhase* pause) { ShouldNotReachHere(); } 1.302 + void visit(ConcurrentPhase* pause) { Unimplemented(); } 1.303 + void visit(PausePhase* pause) { 1.304 + assert(PhasesStack::PHASE_LEVELS == 5, "Need more event types"); 1.305 + 1.306 + switch (pause->level()) { 1.307 + case 0: send_phase<EventGCPhasePause>(pause); break; 1.308 + case 1: send_phase<EventGCPhasePauseLevel1>(pause); break; 1.309 + case 2: send_phase<EventGCPhasePauseLevel2>(pause); break; 1.310 + case 3: send_phase<EventGCPhasePauseLevel3>(pause); break; 1.311 + default: /* Ignore sending this phase */ break; 1.312 + } 1.313 + } 1.314 +}; 1.315 + 1.316 +void GCTracer::send_phase_events(TimePartitions* time_partitions) const { 1.317 + PhaseSender phase_reporter(_shared_gc_info.id()); 1.318 + 1.319 + TimePartitionPhasesIterator iter(time_partitions); 1.320 + while (iter.has_next()) { 1.321 + GCPhase* phase = iter.next(); 1.322 + phase->accept(&phase_reporter); 1.323 + } 1.324 +}