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" ehelin@5386: #include "gc_implementation/shared/copyFailedInfo.hpp" sla@5237: #include "gc_implementation/shared/gcHeapSummary.hpp" brutisso@6904: #include "gc_implementation/shared/gcId.hpp" sla@5237: #include "gc_implementation/shared/gcTimer.hpp" sla@5237: #include "gc_implementation/shared/gcTrace.hpp" ehelin@5386: #include "gc_implementation/shared/objectCountEventSender.hpp" sla@5237: #include "memory/heapInspection.hpp" sla@5237: #include "memory/referenceProcessorStats.hpp" ehelin@5388: #include "runtime/os.hpp" sla@5237: #include "utilities/globalDefinitions.hpp" mgronlun@6131: #include "utilities/ticks.inline.hpp" sla@5237: sla@5237: #if INCLUDE_ALL_GCS sla@5237: #include "gc_implementation/g1/evacuationInfo.hpp" sla@5237: #endif sla@5237: 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?") sla@5237: mgronlun@6131: void GCTracer::report_gc_start_impl(GCCause::Cause cause, const Ticks& timestamp) { sla@5237: assert_unset_gc_id(); sla@5237: brutisso@6904: GCId gc_id = GCId::create(); brutisso@6904: _shared_gc_info.set_gc_id(gc_id); sla@5237: _shared_gc_info.set_cause(cause); sla@5237: _shared_gc_info.set_start_timestamp(timestamp); sla@5237: } sla@5237: mgronlun@6131: void GCTracer::report_gc_start(GCCause::Cause cause, const Ticks& timestamp) { sla@5237: assert_unset_gc_id(); sla@5237: sla@5237: report_gc_start_impl(cause, timestamp); sla@5237: } sla@5237: sla@5237: bool GCTracer::has_reported_gc_start() const { brutisso@6904: return !_shared_gc_info.gc_id().is_undefined(); sla@5237: } sla@5237: mgronlun@6131: void GCTracer::report_gc_end_impl(const Ticks& timestamp, TimePartitions* time_partitions) { sla@5237: assert_set_gc_id(); sla@5237: sla@5237: _shared_gc_info.set_sum_of_pauses(time_partitions->sum_of_pauses()); sla@5237: _shared_gc_info.set_longest_pause(time_partitions->longest_pause()); sla@5237: _shared_gc_info.set_end_timestamp(timestamp); sla@5237: sla@5237: send_phase_events(time_partitions); sla@5237: send_garbage_collection_event(); sla@5237: } sla@5237: mgronlun@6131: void GCTracer::report_gc_end(const Ticks& timestamp, TimePartitions* time_partitions) { sla@5237: assert_set_gc_id(); sla@5237: sla@5237: report_gc_end_impl(timestamp, time_partitions); sla@5237: brutisso@6904: _shared_gc_info.set_gc_id(GCId::undefined()); sla@5237: } sla@5237: sla@5237: void GCTracer::report_gc_reference_stats(const ReferenceProcessorStats& rps) const { sla@5237: assert_set_gc_id(); sla@5237: sla@5237: send_reference_stats_event(REF_SOFT, rps.soft_count()); sla@5237: send_reference_stats_event(REF_WEAK, rps.weak_count()); sla@5237: send_reference_stats_event(REF_FINAL, rps.final_count()); sla@5237: send_reference_stats_event(REF_PHANTOM, rps.phantom_count()); sla@5237: } sla@5237: sla@5237: #if INCLUDE_SERVICES ehelin@5386: class ObjectCountEventSenderClosure : public KlassInfoClosure { ehelin@5386: const GCId _gc_id; ehelin@5386: const double _size_threshold_percentage; ehelin@5386: const size_t _total_size_in_words; mgronlun@6131: const Ticks _timestamp; ehelin@5386: ehelin@5386: public: mgronlun@6131: ObjectCountEventSenderClosure(GCId gc_id, size_t total_size_in_words, const Ticks& timestamp) : ehelin@5386: _gc_id(gc_id), ehelin@5386: _size_threshold_percentage(ObjectCountCutOffPercent / 100), ehelin@5388: _total_size_in_words(total_size_in_words), ehelin@5388: _timestamp(timestamp) ehelin@5386: {} ehelin@5386: ehelin@5386: virtual void do_cinfo(KlassInfoEntry* entry) { ehelin@5386: if (should_send_event(entry)) { ehelin@5388: ObjectCountEventSender::send(entry, _gc_id, _timestamp); ehelin@5386: } sla@5237: } sla@5237: ehelin@5386: private: ehelin@5386: bool should_send_event(const KlassInfoEntry* entry) const { ehelin@5386: double percentage_of_heap = ((double) entry->words()) / _total_size_in_words; ehelin@5386: return percentage_of_heap >= _size_threshold_percentage; ehelin@5386: } ehelin@5386: }; sla@5237: sla@5237: void GCTracer::report_object_count_after_gc(BoolObjectClosure* is_alive_cl) { sla@5237: assert_set_gc_id(); ehelin@5386: assert(is_alive_cl != NULL, "Must supply function to check liveness"); sla@5237: ehelin@5386: if (ObjectCountEventSender::should_send_event()) { sla@5237: ResourceMark rm; sla@5237: sla@5237: KlassInfoTable cit(false); sla@5237: if (!cit.allocation_failed()) { sla@5237: HeapInspection hi(false, false, false, NULL); sla@5237: 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()); sla@5237: cit.iterate(&event_sender); sla@5237: } sla@5237: } sla@5237: } ehelin@5386: #endif // INCLUDE_SERVICES sla@5237: ehelin@6420: void GCTracer::report_gc_heap_summary(GCWhen::Type when, const GCHeapSummary& heap_summary) const { sla@5237: assert_set_gc_id(); sla@5237: sla@5237: send_gc_heap_summary_event(when, heap_summary); ehelin@6420: } ehelin@6420: ehelin@6420: void GCTracer::report_metaspace_summary(GCWhen::Type when, const MetaspaceSummary& summary) const { ehelin@6420: assert_set_gc_id(); ehelin@6420: ehelin@6420: send_meta_space_summary_event(when, summary); ehelin@6420: ehelin@6420: send_metaspace_chunk_free_list_summary(when, Metaspace::NonClassType, summary.metaspace_chunk_free_list_summary()); ehelin@6420: if (UseCompressedClassPointers) { ehelin@6420: send_metaspace_chunk_free_list_summary(when, Metaspace::ClassType, summary.class_chunk_free_list_summary()); ehelin@6420: } sla@5237: } sla@5237: mgronlun@6131: void YoungGCTracer::report_gc_end_impl(const Ticks& timestamp, TimePartitions* time_partitions) { sla@5237: assert_set_gc_id(); sla@5237: assert(_tenuring_threshold != UNSET_TENURING_THRESHOLD, "Tenuring threshold has not been reported"); sla@5237: sla@5237: GCTracer::report_gc_end_impl(timestamp, time_partitions); sla@5237: send_young_gc_event(); sla@5237: sla@5237: _tenuring_threshold = UNSET_TENURING_THRESHOLD; sla@5237: } sla@5237: sla@5237: void YoungGCTracer::report_promotion_failed(const PromotionFailedInfo& pf_info) { sla@5237: assert_set_gc_id(); sla@5237: sla@5237: send_promotion_failed_event(pf_info); sla@5237: } sla@5237: sla@5237: void YoungGCTracer::report_tenuring_threshold(const uint tenuring_threshold) { sla@5237: _tenuring_threshold = tenuring_threshold; sla@5237: } sla@5237: mgronlun@6131: void OldGCTracer::report_gc_end_impl(const Ticks& timestamp, TimePartitions* time_partitions) { sla@5237: assert_set_gc_id(); sla@5237: sla@5237: GCTracer::report_gc_end_impl(timestamp, time_partitions); sla@5237: send_old_gc_event(); sla@5237: } sla@5237: mgronlun@6131: void ParallelOldTracer::report_gc_end_impl(const Ticks& timestamp, TimePartitions* time_partitions) { sla@5237: assert_set_gc_id(); sla@5237: sla@5237: OldGCTracer::report_gc_end_impl(timestamp, time_partitions); sla@5237: send_parallel_old_event(); sla@5237: } sla@5237: sla@5237: void ParallelOldTracer::report_dense_prefix(void* dense_prefix) { sla@5237: assert_set_gc_id(); sla@5237: sla@5237: _parallel_old_gc_info.report_dense_prefix(dense_prefix); sla@5237: } sla@5237: sla@5237: void OldGCTracer::report_concurrent_mode_failure() { sla@5237: assert_set_gc_id(); sla@5237: sla@5237: send_concurrent_mode_failure_event(); sla@5237: } sla@5237: sla@5237: #if INCLUDE_ALL_GCS sla@5237: void G1NewTracer::report_yc_type(G1YCType type) { sla@5237: assert_set_gc_id(); sla@5237: sla@5237: _g1_young_gc_info.set_type(type); sla@5237: } sla@5237: mgronlun@6131: void G1NewTracer::report_gc_end_impl(const Ticks& timestamp, TimePartitions* time_partitions) { sla@5237: assert_set_gc_id(); sla@5237: sla@5237: YoungGCTracer::report_gc_end_impl(timestamp, time_partitions); sla@5237: send_g1_young_gc_event(); sla@5237: } sla@5237: sla@5237: void G1NewTracer::report_evacuation_info(EvacuationInfo* info) { sla@5237: assert_set_gc_id(); sla@5237: sla@5237: send_evacuation_info_event(info); sla@5237: } sla@5237: sla@5237: void G1NewTracer::report_evacuation_failed(EvacuationFailedInfo& ef_info) { sla@5237: assert_set_gc_id(); sla@5237: sla@5237: send_evacuation_failed_event(ef_info); sla@5237: ef_info.reset(); sla@5237: } sla@5237: #endif