sla@5237: /* sla@5237: * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. sla@5237: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. sla@5237: * sla@5237: * This code is free software; you can redistribute it and/or modify it sla@5237: * under the terms of the GNU General Public License version 2 only, as sla@5237: * published by the Free Software Foundation. sla@5237: * sla@5237: * This code is distributed in the hope that it will be useful, but WITHOUT sla@5237: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or sla@5237: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License sla@5237: * version 2 for more details (a copy is included in the LICENSE file that sla@5237: * accompanied this code). sla@5237: * sla@5237: * You should have received a copy of the GNU General Public License version sla@5237: * 2 along with this work; if not, write to the Free Software Foundation, sla@5237: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. sla@5237: * sla@5237: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA sla@5237: * or visit www.oracle.com if you need additional information or have any sla@5237: * questions. sla@5237: * sla@5237: */ sla@5237: sla@5237: #include "precompiled.hpp" sla@5237: #include "gc_implementation/shared/gcHeapSummary.hpp" sla@5237: #include "gc_implementation/shared/gcTimer.hpp" sla@5237: #include "gc_implementation/shared/gcTrace.hpp" sla@5237: #include "gc_implementation/shared/gcWhen.hpp" sla@5237: #include "gc_implementation/shared/copyFailedInfo.hpp" ehelin@5647: #include "runtime/os.hpp" sla@5237: #include "trace/tracing.hpp" sla@5237: #include "trace/traceBackend.hpp" sla@5237: #if INCLUDE_ALL_GCS sla@5237: #include "gc_implementation/g1/evacuationInfo.hpp" sla@5237: #include "gc_implementation/g1/g1YCTypes.hpp" sla@5237: #endif sla@5237: sla@5237: // All GC dependencies against the trace framework is contained within this file. sla@5237: sla@5237: typedef uintptr_t TraceAddress; sla@5237: sla@5237: void GCTracer::send_garbage_collection_event() const { sla@5237: EventGCGarbageCollection event(UNTIMED); sla@5237: if (event.should_commit()) { sla@5237: event.set_gcId(_shared_gc_info.id()); sla@5237: event.set_name(_shared_gc_info.name()); sla@5237: event.set_cause((u2) _shared_gc_info.cause()); sla@5237: event.set_sumOfPauses(_shared_gc_info.sum_of_pauses()); sla@5237: event.set_longestPause(_shared_gc_info.longest_pause()); sla@5237: event.set_starttime(_shared_gc_info.start_timestamp()); sla@5237: event.set_endtime(_shared_gc_info.end_timestamp()); sla@5237: event.commit(); sla@5237: } sla@5237: } sla@5237: sla@5237: void GCTracer::send_reference_stats_event(ReferenceType type, size_t count) const { mgronlun@6131: EventGCReferenceStatistics e; sla@5237: if (e.should_commit()) { sla@5237: e.set_gcId(_shared_gc_info.id()); sla@5237: e.set_type((u1)type); sla@5237: e.set_count(count); sla@5237: e.commit(); sla@5237: } sla@5237: } sla@5237: sla@5237: void ParallelOldTracer::send_parallel_old_event() const { sla@5237: EventGCParallelOld e(UNTIMED); sla@5237: if (e.should_commit()) { sla@5237: e.set_gcId(_shared_gc_info.id()); sla@5237: e.set_densePrefix((TraceAddress)_parallel_old_gc_info.dense_prefix()); sla@5237: e.set_starttime(_shared_gc_info.start_timestamp()); sla@5237: e.set_endtime(_shared_gc_info.end_timestamp()); sla@5237: e.commit(); sla@5237: } sla@5237: } sla@5237: sla@5237: void YoungGCTracer::send_young_gc_event() const { sla@5237: EventGCYoungGarbageCollection e(UNTIMED); sla@5237: if (e.should_commit()) { sla@5237: e.set_gcId(_shared_gc_info.id()); sla@5237: e.set_tenuringThreshold(_tenuring_threshold); sla@5237: e.set_starttime(_shared_gc_info.start_timestamp()); sla@5237: e.set_endtime(_shared_gc_info.end_timestamp()); sla@5237: e.commit(); sla@5237: } sla@5237: } sla@5237: sla@5237: void OldGCTracer::send_old_gc_event() const { sla@5237: EventGCOldGarbageCollection e(UNTIMED); sla@5237: if (e.should_commit()) { sla@5237: e.set_gcId(_shared_gc_info.id()); sla@5237: e.set_starttime(_shared_gc_info.start_timestamp()); sla@5237: e.set_endtime(_shared_gc_info.end_timestamp()); sla@5237: e.commit(); sla@5237: } sla@5237: } sla@5237: sla@5237: static TraceStructCopyFailed to_trace_struct(const CopyFailedInfo& cf_info) { sla@5237: TraceStructCopyFailed failed_info; sla@5237: failed_info.set_objectCount(cf_info.failed_count()); sla@5237: failed_info.set_firstSize(cf_info.first_size()); sla@5237: failed_info.set_smallestSize(cf_info.smallest_size()); sla@5237: failed_info.set_totalSize(cf_info.total_size()); sla@5237: return failed_info; sla@5237: } sla@5237: sla@5237: void YoungGCTracer::send_promotion_failed_event(const PromotionFailedInfo& pf_info) const { mgronlun@6131: EventPromotionFailed e; sla@5237: if (e.should_commit()) { sla@5237: e.set_gcId(_shared_gc_info.id()); sla@5237: e.set_data(to_trace_struct(pf_info)); sla@5237: e.set_thread(pf_info.thread()->thread_id()); sla@5237: e.commit(); sla@5237: } sla@5237: } sla@5237: sla@5237: // Common to CMS and G1 sla@5237: void OldGCTracer::send_concurrent_mode_failure_event() { mgronlun@6131: EventConcurrentModeFailure e; sla@5237: if (e.should_commit()) { sla@5237: e.set_gcId(_shared_gc_info.id()); sla@5237: e.commit(); sla@5237: } sla@5237: } sla@5237: sla@5237: #if INCLUDE_ALL_GCS sla@5237: void G1NewTracer::send_g1_young_gc_event() { sla@5237: EventGCG1GarbageCollection e(UNTIMED); sla@5237: if (e.should_commit()) { sla@5237: e.set_gcId(_shared_gc_info.id()); sla@5237: e.set_type(_g1_young_gc_info.type()); sla@5237: e.set_starttime(_shared_gc_info.start_timestamp()); sla@5237: e.set_endtime(_shared_gc_info.end_timestamp()); sla@5237: e.commit(); sla@5237: } sla@5237: } sla@5237: sla@5237: void G1NewTracer::send_evacuation_info_event(EvacuationInfo* info) { mgronlun@6131: EventEvacuationInfo e; sla@5237: if (e.should_commit()) { sla@5237: e.set_gcId(_shared_gc_info.id()); sla@5237: e.set_cSetRegions(info->collectionset_regions()); sla@5237: e.set_cSetUsedBefore(info->collectionset_used_before()); sla@5237: e.set_cSetUsedAfter(info->collectionset_used_after()); sla@5237: e.set_allocationRegions(info->allocation_regions()); sla@5237: e.set_allocRegionsUsedBefore(info->alloc_regions_used_before()); sla@5237: e.set_allocRegionsUsedAfter(info->alloc_regions_used_before() + info->bytes_copied()); sla@5237: e.set_bytesCopied(info->bytes_copied()); sla@5237: e.set_regionsFreed(info->regions_freed()); sla@5237: e.commit(); sla@5237: } sla@5237: } sla@5237: sla@5237: void G1NewTracer::send_evacuation_failed_event(const EvacuationFailedInfo& ef_info) const { mgronlun@6131: EventEvacuationFailed e; sla@5237: if (e.should_commit()) { sla@5237: e.set_gcId(_shared_gc_info.id()); sla@5237: e.set_data(to_trace_struct(ef_info)); sla@5237: e.commit(); sla@5237: } sla@5237: } sla@5237: #endif sla@5237: sla@5237: static TraceStructVirtualSpace to_trace_struct(const VirtualSpaceSummary& summary) { sla@5237: TraceStructVirtualSpace space; sla@5237: space.set_start((TraceAddress)summary.start()); sla@5237: space.set_committedEnd((TraceAddress)summary.committed_end()); sla@5237: space.set_committedSize(summary.committed_size()); sla@5237: space.set_reservedEnd((TraceAddress)summary.reserved_end()); sla@5237: space.set_reservedSize(summary.reserved_size()); sla@5237: return space; sla@5237: } sla@5237: sla@5237: static TraceStructObjectSpace to_trace_struct(const SpaceSummary& summary) { sla@5237: TraceStructObjectSpace space; sla@5237: space.set_start((TraceAddress)summary.start()); sla@5237: space.set_end((TraceAddress)summary.end()); sla@5237: space.set_used(summary.used()); sla@5237: space.set_size(summary.size()); sla@5237: return space; sla@5237: } sla@5237: sla@5237: class GCHeapSummaryEventSender : public GCHeapSummaryVisitor { sla@5237: GCId _id; sla@5237: GCWhen::Type _when; sla@5237: public: sla@5237: GCHeapSummaryEventSender(GCId id, GCWhen::Type when) : _id(id), _when(when) {} sla@5237: sla@5237: void visit(const GCHeapSummary* heap_summary) const { sla@5237: const VirtualSpaceSummary& heap_space = heap_summary->heap(); sla@5237: mgronlun@6131: EventGCHeapSummary e; sla@5237: if (e.should_commit()) { sla@5237: e.set_gcId(_id); sla@5237: e.set_when((u1)_when); sla@5237: e.set_heapSpace(to_trace_struct(heap_space)); sla@5237: e.set_heapUsed(heap_summary->used()); sla@5237: e.commit(); sla@5237: } sla@5237: } sla@5237: sla@5237: void visit(const PSHeapSummary* ps_heap_summary) const { sla@5237: visit((GCHeapSummary*)ps_heap_summary); sla@5237: sla@5237: const VirtualSpaceSummary& old_summary = ps_heap_summary->old(); sla@5237: const SpaceSummary& old_space = ps_heap_summary->old_space(); sla@5237: const VirtualSpaceSummary& young_summary = ps_heap_summary->young(); sla@5237: const SpaceSummary& eden_space = ps_heap_summary->eden(); sla@5237: const SpaceSummary& from_space = ps_heap_summary->from(); sla@5237: const SpaceSummary& to_space = ps_heap_summary->to(); sla@5237: mgronlun@6131: EventPSHeapSummary e; sla@5237: if (e.should_commit()) { sla@5237: e.set_gcId(_id); sla@5237: e.set_when((u1)_when); sla@5237: sla@5237: e.set_oldSpace(to_trace_struct(ps_heap_summary->old())); sla@5237: e.set_oldObjectSpace(to_trace_struct(ps_heap_summary->old_space())); sla@5237: e.set_youngSpace(to_trace_struct(ps_heap_summary->young())); sla@5237: e.set_edenSpace(to_trace_struct(ps_heap_summary->eden())); sla@5237: e.set_fromSpace(to_trace_struct(ps_heap_summary->from())); sla@5237: e.set_toSpace(to_trace_struct(ps_heap_summary->to())); sla@5237: e.commit(); sla@5237: } sla@5237: } sla@5237: }; sla@5237: sla@5237: void GCTracer::send_gc_heap_summary_event(GCWhen::Type when, const GCHeapSummary& heap_summary) const { sla@5237: GCHeapSummaryEventSender visitor(_shared_gc_info.id(), when); sla@5237: heap_summary.accept(&visitor); sla@5237: } sla@5237: sla@5237: static TraceStructMetaspaceSizes to_trace_struct(const MetaspaceSizes& sizes) { sla@5237: TraceStructMetaspaceSizes meta_sizes; sla@5237: sla@5237: meta_sizes.set_capacity(sizes.capacity()); sla@5237: meta_sizes.set_used(sizes.used()); sla@5237: meta_sizes.set_reserved(sizes.reserved()); sla@5237: sla@5237: return meta_sizes; sla@5237: } sla@5237: sla@5237: void GCTracer::send_meta_space_summary_event(GCWhen::Type when, const MetaspaceSummary& meta_space_summary) const { mgronlun@6131: EventMetaspaceSummary e; sla@5237: if (e.should_commit()) { sla@5237: e.set_gcId(_shared_gc_info.id()); sla@5237: e.set_when((u1) when); sla@5237: e.set_metaspace(to_trace_struct(meta_space_summary.meta_space())); sla@5237: e.set_dataSpace(to_trace_struct(meta_space_summary.data_space())); sla@5237: e.set_classSpace(to_trace_struct(meta_space_summary.class_space())); sla@5237: e.commit(); sla@5237: } sla@5237: } sla@5237: sla@5237: class PhaseSender : public PhaseVisitor { sla@5237: GCId _gc_id; sla@5237: public: sla@5237: PhaseSender(GCId gc_id) : _gc_id(gc_id) {} sla@5237: sla@5237: template sla@5237: void send_phase(PausePhase* pause) { sla@5237: T event(UNTIMED); sla@5237: if (event.should_commit()) { sla@5237: event.set_gcId(_gc_id); sla@5237: event.set_name(pause->name()); sla@5237: event.set_starttime(pause->start()); sla@5237: event.set_endtime(pause->end()); sla@5237: event.commit(); sla@5237: } sla@5237: } sla@5237: sla@5237: void visit(GCPhase* pause) { ShouldNotReachHere(); } sla@5237: void visit(ConcurrentPhase* pause) { Unimplemented(); } sla@5237: void visit(PausePhase* pause) { sla@5237: assert(PhasesStack::PHASE_LEVELS == 5, "Need more event types"); sla@5237: sla@5237: switch (pause->level()) { sla@5237: case 0: send_phase(pause); break; sla@5237: case 1: send_phase(pause); break; sla@5237: case 2: send_phase(pause); break; sla@5237: case 3: send_phase(pause); break; sla@5237: default: /* Ignore sending this phase */ break; sla@5237: } sla@5237: } sla@5237: }; sla@5237: sla@5237: void GCTracer::send_phase_events(TimePartitions* time_partitions) const { sla@5237: PhaseSender phase_reporter(_shared_gc_info.id()); sla@5237: sla@5237: TimePartitionPhasesIterator iter(time_partitions); sla@5237: while (iter.has_next()) { sla@5237: GCPhase* phase = iter.next(); sla@5237: phase->accept(&phase_reporter); sla@5237: } sla@5237: }