aoqi@0: /* aoqi@0: * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #include "precompiled.hpp" aoqi@0: #include "gc_implementation/shared/copyFailedInfo.hpp" aoqi@0: #include "gc_implementation/shared/gcHeapSummary.hpp" brutisso@6904: #include "gc_implementation/shared/gcId.hpp" aoqi@0: #include "gc_implementation/shared/gcTimer.hpp" aoqi@0: #include "gc_implementation/shared/gcTrace.hpp" aoqi@0: #include "gc_implementation/shared/objectCountEventSender.hpp" aoqi@0: #include "memory/heapInspection.hpp" aoqi@0: #include "memory/referenceProcessorStats.hpp" aoqi@0: #include "runtime/os.hpp" aoqi@0: #include "utilities/globalDefinitions.hpp" aoqi@0: #include "utilities/ticks.inline.hpp" aoqi@0: aoqi@0: #if INCLUDE_ALL_GCS aoqi@0: #include "gc_implementation/g1/evacuationInfo.hpp" aoqi@0: #endif aoqi@0: brutisso@6904: #define assert_unset_gc_id() assert(_shared_gc_info.gc_id().is_undefined(), "GC already started?") brutisso@6904: #define assert_set_gc_id() assert(!_shared_gc_info.gc_id().is_undefined(), "GC not started?") aoqi@0: aoqi@0: void GCTracer::report_gc_start_impl(GCCause::Cause cause, const Ticks& timestamp) { aoqi@0: assert_unset_gc_id(); aoqi@0: brutisso@6904: GCId gc_id = GCId::create(); brutisso@6904: _shared_gc_info.set_gc_id(gc_id); aoqi@0: _shared_gc_info.set_cause(cause); aoqi@0: _shared_gc_info.set_start_timestamp(timestamp); aoqi@0: } aoqi@0: aoqi@0: void GCTracer::report_gc_start(GCCause::Cause cause, const Ticks& timestamp) { aoqi@0: assert_unset_gc_id(); aoqi@0: aoqi@0: report_gc_start_impl(cause, timestamp); aoqi@0: } aoqi@0: aoqi@0: bool GCTracer::has_reported_gc_start() const { brutisso@6904: return !_shared_gc_info.gc_id().is_undefined(); aoqi@0: } aoqi@0: aoqi@0: void GCTracer::report_gc_end_impl(const Ticks& timestamp, TimePartitions* time_partitions) { aoqi@0: assert_set_gc_id(); aoqi@0: aoqi@0: _shared_gc_info.set_sum_of_pauses(time_partitions->sum_of_pauses()); aoqi@0: _shared_gc_info.set_longest_pause(time_partitions->longest_pause()); aoqi@0: _shared_gc_info.set_end_timestamp(timestamp); aoqi@0: aoqi@0: send_phase_events(time_partitions); aoqi@0: send_garbage_collection_event(); aoqi@0: } aoqi@0: aoqi@0: void GCTracer::report_gc_end(const Ticks& timestamp, TimePartitions* time_partitions) { aoqi@0: assert_set_gc_id(); aoqi@0: aoqi@0: report_gc_end_impl(timestamp, time_partitions); aoqi@0: brutisso@6904: _shared_gc_info.set_gc_id(GCId::undefined()); aoqi@0: } aoqi@0: aoqi@0: void GCTracer::report_gc_reference_stats(const ReferenceProcessorStats& rps) const { aoqi@0: assert_set_gc_id(); aoqi@0: aoqi@0: send_reference_stats_event(REF_SOFT, rps.soft_count()); aoqi@0: send_reference_stats_event(REF_WEAK, rps.weak_count()); aoqi@0: send_reference_stats_event(REF_FINAL, rps.final_count()); aoqi@0: send_reference_stats_event(REF_PHANTOM, rps.phantom_count()); aoqi@0: } aoqi@0: aoqi@0: #if INCLUDE_SERVICES aoqi@0: class ObjectCountEventSenderClosure : public KlassInfoClosure { aoqi@0: const GCId _gc_id; aoqi@0: const double _size_threshold_percentage; aoqi@0: const size_t _total_size_in_words; aoqi@0: const Ticks _timestamp; aoqi@0: aoqi@0: public: aoqi@0: ObjectCountEventSenderClosure(GCId gc_id, size_t total_size_in_words, const Ticks& timestamp) : aoqi@0: _gc_id(gc_id), aoqi@0: _size_threshold_percentage(ObjectCountCutOffPercent / 100), aoqi@0: _total_size_in_words(total_size_in_words), aoqi@0: _timestamp(timestamp) aoqi@0: {} aoqi@0: aoqi@0: virtual void do_cinfo(KlassInfoEntry* entry) { aoqi@0: if (should_send_event(entry)) { aoqi@0: ObjectCountEventSender::send(entry, _gc_id, _timestamp); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: private: aoqi@0: bool should_send_event(const KlassInfoEntry* entry) const { aoqi@0: double percentage_of_heap = ((double) entry->words()) / _total_size_in_words; aoqi@0: return percentage_of_heap >= _size_threshold_percentage; aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: void GCTracer::report_object_count_after_gc(BoolObjectClosure* is_alive_cl) { aoqi@0: assert_set_gc_id(); aoqi@0: assert(is_alive_cl != NULL, "Must supply function to check liveness"); aoqi@0: aoqi@0: if (ObjectCountEventSender::should_send_event()) { aoqi@0: ResourceMark rm; aoqi@0: aoqi@0: KlassInfoTable cit(false); aoqi@0: if (!cit.allocation_failed()) { aoqi@0: HeapInspection hi(false, false, false, NULL); aoqi@0: hi.populate_table(&cit, is_alive_cl); brutisso@6904: ObjectCountEventSenderClosure event_sender(_shared_gc_info.gc_id(), cit.size_of_instances_in_words(), Ticks::now()); aoqi@0: cit.iterate(&event_sender); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: #endif // INCLUDE_SERVICES aoqi@0: aoqi@0: void GCTracer::report_gc_heap_summary(GCWhen::Type when, const GCHeapSummary& heap_summary) const { aoqi@0: assert_set_gc_id(); aoqi@0: aoqi@0: send_gc_heap_summary_event(when, heap_summary); aoqi@0: } aoqi@0: aoqi@0: void GCTracer::report_metaspace_summary(GCWhen::Type when, const MetaspaceSummary& summary) const { aoqi@0: assert_set_gc_id(); aoqi@0: aoqi@0: send_meta_space_summary_event(when, summary); aoqi@0: aoqi@0: send_metaspace_chunk_free_list_summary(when, Metaspace::NonClassType, summary.metaspace_chunk_free_list_summary()); aoqi@0: if (UseCompressedClassPointers) { aoqi@0: send_metaspace_chunk_free_list_summary(when, Metaspace::ClassType, summary.class_chunk_free_list_summary()); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void YoungGCTracer::report_gc_end_impl(const Ticks& timestamp, TimePartitions* time_partitions) { aoqi@0: assert_set_gc_id(); aoqi@0: assert(_tenuring_threshold != UNSET_TENURING_THRESHOLD, "Tenuring threshold has not been reported"); aoqi@0: aoqi@0: GCTracer::report_gc_end_impl(timestamp, time_partitions); aoqi@0: send_young_gc_event(); aoqi@0: aoqi@0: _tenuring_threshold = UNSET_TENURING_THRESHOLD; aoqi@0: } aoqi@0: aoqi@0: void YoungGCTracer::report_promotion_failed(const PromotionFailedInfo& pf_info) { aoqi@0: assert_set_gc_id(); aoqi@0: aoqi@0: send_promotion_failed_event(pf_info); aoqi@0: } aoqi@0: aoqi@0: void YoungGCTracer::report_tenuring_threshold(const uint tenuring_threshold) { aoqi@0: _tenuring_threshold = tenuring_threshold; aoqi@0: } aoqi@0: aoqi@0: void OldGCTracer::report_gc_end_impl(const Ticks& timestamp, TimePartitions* time_partitions) { aoqi@0: assert_set_gc_id(); aoqi@0: aoqi@0: GCTracer::report_gc_end_impl(timestamp, time_partitions); aoqi@0: send_old_gc_event(); aoqi@0: } aoqi@0: aoqi@0: void ParallelOldTracer::report_gc_end_impl(const Ticks& timestamp, TimePartitions* time_partitions) { aoqi@0: assert_set_gc_id(); aoqi@0: aoqi@0: OldGCTracer::report_gc_end_impl(timestamp, time_partitions); aoqi@0: send_parallel_old_event(); aoqi@0: } aoqi@0: aoqi@0: void ParallelOldTracer::report_dense_prefix(void* dense_prefix) { aoqi@0: assert_set_gc_id(); aoqi@0: aoqi@0: _parallel_old_gc_info.report_dense_prefix(dense_prefix); aoqi@0: } aoqi@0: aoqi@0: void OldGCTracer::report_concurrent_mode_failure() { aoqi@0: assert_set_gc_id(); aoqi@0: aoqi@0: send_concurrent_mode_failure_event(); aoqi@0: } aoqi@0: aoqi@0: #if INCLUDE_ALL_GCS aoqi@0: void G1NewTracer::report_yc_type(G1YCType type) { aoqi@0: assert_set_gc_id(); aoqi@0: aoqi@0: _g1_young_gc_info.set_type(type); aoqi@0: } aoqi@0: aoqi@0: void G1NewTracer::report_gc_end_impl(const Ticks& timestamp, TimePartitions* time_partitions) { aoqi@0: assert_set_gc_id(); aoqi@0: aoqi@0: YoungGCTracer::report_gc_end_impl(timestamp, time_partitions); aoqi@0: send_g1_young_gc_event(); aoqi@0: } aoqi@0: aoqi@0: void G1NewTracer::report_evacuation_info(EvacuationInfo* info) { aoqi@0: assert_set_gc_id(); aoqi@0: aoqi@0: send_evacuation_info_event(info); aoqi@0: } aoqi@0: aoqi@0: void G1NewTracer::report_evacuation_failed(EvacuationFailedInfo& ef_info) { aoqi@0: assert_set_gc_id(); aoqi@0: aoqi@0: send_evacuation_failed_event(ef_info); aoqi@0: ef_info.reset(); aoqi@0: } aoqi@0: #endif