Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/shared/gcTraceSend.cpp
38920 views
/*1* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "jfr/jfrEvents.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/gcWhen.hpp"30#include "gc_implementation/shared/copyFailedInfo.hpp"31#include "runtime/os.hpp"32#if INCLUDE_ALL_GCS33#include "gc_implementation/g1/evacuationInfo.hpp"34#include "gc_implementation/g1/g1YCTypes.hpp"35#endif3637// All GC dependencies against the trace framework is contained within this file.3839typedef uintptr_t TraceAddress;4041void GCTracer::send_garbage_collection_event() const {42EventGarbageCollection event(UNTIMED);43if (event.should_commit()) {44event.set_gcId(_shared_gc_info.gc_id().id());45event.set_name(_shared_gc_info.name());46event.set_cause((u2) _shared_gc_info.cause());47event.set_sumOfPauses(_shared_gc_info.sum_of_pauses());48event.set_longestPause(_shared_gc_info.longest_pause());49event.set_starttime(_shared_gc_info.start_timestamp());50event.set_endtime(_shared_gc_info.end_timestamp());51event.commit();52}53}5455void GCTracer::send_reference_stats_event(ReferenceType type, size_t count) const {56EventGCReferenceStatistics e;57if (e.should_commit()) {58e.set_gcId(_shared_gc_info.gc_id().id());59e.set_type((u1)type);60e.set_count(count);61e.commit();62}63}6465void GCTracer::send_metaspace_chunk_free_list_summary(GCWhen::Type when, Metaspace::MetadataType mdtype,66const MetaspaceChunkFreeListSummary& summary) const {67EventMetaspaceChunkFreeListSummary e;68if (e.should_commit()) {69e.set_gcId(_shared_gc_info.gc_id().id());70e.set_when(when);71e.set_metadataType(mdtype);7273e.set_specializedChunks(summary.num_specialized_chunks());74e.set_specializedChunksTotalSize(summary.specialized_chunks_size_in_bytes());7576e.set_smallChunks(summary.num_small_chunks());77e.set_smallChunksTotalSize(summary.small_chunks_size_in_bytes());7879e.set_mediumChunks(summary.num_medium_chunks());80e.set_mediumChunksTotalSize(summary.medium_chunks_size_in_bytes());8182e.set_humongousChunks(summary.num_humongous_chunks());83e.set_humongousChunksTotalSize(summary.humongous_chunks_size_in_bytes());8485e.commit();86}87}8889void ParallelOldTracer::send_parallel_old_event() const {90EventParallelOldGarbageCollection e(UNTIMED);91if (e.should_commit()) {92e.set_gcId(_shared_gc_info.gc_id().id());93e.set_densePrefix((TraceAddress)_parallel_old_gc_info.dense_prefix());94e.set_starttime(_shared_gc_info.start_timestamp());95e.set_endtime(_shared_gc_info.end_timestamp());96e.commit();97}98}99100void YoungGCTracer::send_young_gc_event() const {101EventYoungGarbageCollection e(UNTIMED);102if (e.should_commit()) {103e.set_gcId(_shared_gc_info.gc_id().id());104e.set_tenuringThreshold(_tenuring_threshold);105e.set_starttime(_shared_gc_info.start_timestamp());106e.set_endtime(_shared_gc_info.end_timestamp());107e.commit();108}109}110111bool YoungGCTracer::should_send_promotion_in_new_plab_event() const {112return EventPromoteObjectInNewPLAB::is_enabled();113}114115bool YoungGCTracer::should_send_promotion_outside_plab_event() const {116return EventPromoteObjectOutsidePLAB::is_enabled();117}118119void YoungGCTracer::send_promotion_in_new_plab_event(Klass* klass, size_t obj_size,120uint age, bool tenured,121size_t plab_size) const {122123EventPromoteObjectInNewPLAB event;124if (event.should_commit()) {125event.set_gcId(_shared_gc_info.gc_id().id());126event.set_objectClass(klass);127event.set_objectSize(obj_size);128event.set_tenured(tenured);129event.set_tenuringAge(age);130event.set_plabSize(plab_size);131event.commit();132}133}134135void YoungGCTracer::send_promotion_outside_plab_event(Klass* klass, size_t obj_size,136uint age, bool tenured) const {137138EventPromoteObjectOutsidePLAB event;139if (event.should_commit()) {140event.set_gcId(_shared_gc_info.gc_id().id());141event.set_objectClass(klass);142event.set_objectSize(obj_size);143event.set_tenured(tenured);144event.set_tenuringAge(age);145event.commit();146}147}148149void OldGCTracer::send_old_gc_event() const {150EventOldGarbageCollection e(UNTIMED);151if (e.should_commit()) {152e.set_gcId(_shared_gc_info.gc_id().id());153e.set_starttime(_shared_gc_info.start_timestamp());154e.set_endtime(_shared_gc_info.end_timestamp());155e.commit();156}157}158159static JfrStructCopyFailed to_struct(const CopyFailedInfo& cf_info) {160JfrStructCopyFailed failed_info;161failed_info.set_objectCount(cf_info.failed_count());162failed_info.set_firstSize(cf_info.first_size());163failed_info.set_smallestSize(cf_info.smallest_size());164failed_info.set_totalSize(cf_info.total_size());165return failed_info;166}167168void YoungGCTracer::send_promotion_failed_event(const PromotionFailedInfo& pf_info) const {169EventPromotionFailed e;170if (e.should_commit()) {171e.set_gcId(_shared_gc_info.gc_id().id());172e.set_promotionFailed(to_struct(pf_info));173e.set_thread(pf_info.thread()->thread_id());174e.commit();175}176}177178// Common to CMS and G1179void OldGCTracer::send_concurrent_mode_failure_event() {180EventConcurrentModeFailure e;181if (e.should_commit()) {182e.set_gcId(_shared_gc_info.gc_id().id());183e.commit();184}185}186187#if INCLUDE_ALL_GCS188void G1NewTracer::send_g1_young_gc_event() {189EventG1GarbageCollection e(UNTIMED);190if (e.should_commit()) {191e.set_gcId(_shared_gc_info.gc_id().id());192e.set_type(_g1_young_gc_info.type());193e.set_starttime(_shared_gc_info.start_timestamp());194e.set_endtime(_shared_gc_info.end_timestamp());195e.commit();196}197}198199void G1MMUTracer::send_g1_mmu_event(double time_slice_ms, double gc_time_ms, double max_time_ms) {200EventG1MMU e;201if (e.should_commit()) {202e.set_gcId(GCId::peek().id());203e.set_timeSlice((s8)time_slice_ms);204e.set_gcTime((s8)gc_time_ms);205e.set_pauseTarget((s8)max_time_ms);206e.commit();207}208}209210void G1NewTracer::send_evacuation_info_event(EvacuationInfo* info) {211EventEvacuationInformation e;212if (e.should_commit()) {213e.set_gcId(_shared_gc_info.gc_id().id());214e.set_cSetRegions(info->collectionset_regions());215e.set_cSetUsedBefore(info->collectionset_used_before());216e.set_cSetUsedAfter(info->collectionset_used_after());217e.set_allocationRegions(info->allocation_regions());218e.set_allocationRegionsUsedBefore(info->alloc_regions_used_before());219e.set_allocationRegionsUsedAfter(info->alloc_regions_used_before() + info->bytes_copied());220e.set_bytesCopied(info->bytes_copied());221e.set_regionsFreed(info->regions_freed());222e.commit();223}224}225226void G1NewTracer::send_evacuation_failed_event(const EvacuationFailedInfo& ef_info) const {227EventEvacuationFailed e;228if (e.should_commit()) {229e.set_gcId(_shared_gc_info.gc_id().id());230e.set_evacuationFailed(to_struct(ef_info));231e.commit();232}233}234235#endif // INCLUDE_ALL_GCS236237static JfrStructVirtualSpace to_struct(const VirtualSpaceSummary& summary) {238JfrStructVirtualSpace space;239space.set_start((TraceAddress)summary.start());240space.set_committedEnd((TraceAddress)summary.committed_end());241space.set_committedSize(summary.committed_size());242space.set_reservedEnd((TraceAddress)summary.reserved_end());243space.set_reservedSize(summary.reserved_size());244return space;245}246247static JfrStructObjectSpace to_struct(const SpaceSummary& summary) {248JfrStructObjectSpace space;249space.set_start((TraceAddress)summary.start());250space.set_end((TraceAddress)summary.end());251space.set_used(summary.used());252space.set_size(summary.size());253return space;254}255256class GCHeapSummaryEventSender : public GCHeapSummaryVisitor {257GCId _gc_id;258GCWhen::Type _when;259public:260GCHeapSummaryEventSender(GCId gc_id, GCWhen::Type when) : _gc_id(gc_id), _when(when) {}261262void visit(const GCHeapSummary* heap_summary) const {263const VirtualSpaceSummary& heap_space = heap_summary->heap();264265EventGCHeapSummary e;266if (e.should_commit()) {267e.set_gcId(_gc_id.id());268e.set_when((u1)_when);269e.set_heapSpace(to_struct(heap_space));270e.set_heapUsed(heap_summary->used());271e.commit();272}273}274275void visit(const G1HeapSummary* g1_heap_summary) const {276visit((GCHeapSummary*)g1_heap_summary);277278EventG1HeapSummary e;279if (e.should_commit()) {280e.set_gcId(_gc_id.id());281e.set_when((u1)_when);282e.set_edenUsedSize(g1_heap_summary->edenUsed());283e.set_edenTotalSize(g1_heap_summary->edenCapacity());284e.set_survivorUsedSize(g1_heap_summary->survivorUsed());285e.set_numberOfRegions(g1_heap_summary->numberOfRegions());286e.commit();287}288}289290void visit(const PSHeapSummary* ps_heap_summary) const {291visit((GCHeapSummary*)ps_heap_summary);292293const VirtualSpaceSummary& old_summary = ps_heap_summary->old();294const SpaceSummary& old_space = ps_heap_summary->old_space();295const VirtualSpaceSummary& young_summary = ps_heap_summary->young();296const SpaceSummary& eden_space = ps_heap_summary->eden();297const SpaceSummary& from_space = ps_heap_summary->from();298const SpaceSummary& to_space = ps_heap_summary->to();299300EventPSHeapSummary e;301if (e.should_commit()) {302e.set_gcId(_gc_id.id());303e.set_when((u1)_when);304305e.set_oldSpace(to_struct(ps_heap_summary->old()));306e.set_oldObjectSpace(to_struct(ps_heap_summary->old_space()));307e.set_youngSpace(to_struct(ps_heap_summary->young()));308e.set_edenSpace(to_struct(ps_heap_summary->eden()));309e.set_fromSpace(to_struct(ps_heap_summary->from()));310e.set_toSpace(to_struct(ps_heap_summary->to()));311e.commit();312}313}314};315316void GCTracer::send_gc_heap_summary_event(GCWhen::Type when, const GCHeapSummary& heap_summary) const {317GCHeapSummaryEventSender visitor(_shared_gc_info.gc_id(), when);318heap_summary.accept(&visitor);319}320321static JfrStructMetaspaceSizes to_struct(const MetaspaceSizes& sizes) {322JfrStructMetaspaceSizes meta_sizes;323324meta_sizes.set_committed(sizes.committed());325meta_sizes.set_used(sizes.used());326meta_sizes.set_reserved(sizes.reserved());327328return meta_sizes;329}330331void GCTracer::send_meta_space_summary_event(GCWhen::Type when, const MetaspaceSummary& meta_space_summary) const {332EventMetaspaceSummary e;333if (e.should_commit()) {334e.set_gcId(_shared_gc_info.gc_id().id());335e.set_when((u1) when);336e.set_gcThreshold(meta_space_summary.capacity_until_GC());337e.set_metaspace(to_struct(meta_space_summary.meta_space()));338e.set_dataSpace(to_struct(meta_space_summary.data_space()));339e.set_classSpace(to_struct(meta_space_summary.class_space()));340e.commit();341}342}343344class PhaseSender : public PhaseVisitor {345GCId _gc_id;346public:347PhaseSender(GCId gc_id) : _gc_id(gc_id) {}348349template<typename T>350void send_phase(GCPhase* phase) {351T event(UNTIMED);352if (event.should_commit()) {353event.set_gcId(_gc_id.id());354event.set_name(phase->name());355event.set_starttime(phase->start());356event.set_endtime(phase->end());357event.commit();358}359}360361void visit(GCPhase* pause) { ShouldNotReachHere(); }362void visit(ConcurrentPhase* pause) { Unimplemented(); }363void visit(PausePhase* pause) {364assert(PhasesStack::PHASE_LEVELS == 5, "Need more event types");365366switch (pause->level()) {367case 0: send_phase<EventGCPhasePause>(pause); break;368case 1: send_phase<EventGCPhasePauseLevel1>(pause); break;369case 2: send_phase<EventGCPhasePauseLevel2>(pause); break;370case 3: send_phase<EventGCPhasePauseLevel3>(pause); break;371default: /* Ignore sending this phase */ break;372}373}374};375376void GCTracer::send_phase_events(TimePartitions* time_partitions) const {377PhaseSender phase_reporter(_shared_gc_info.gc_id());378379TimePartitionPhasesIterator iter(time_partitions);380while (iter.has_next()) {381GCPhase* phase = iter.next();382phase->accept(&phase_reporter);383}384}385386387