/* * Copyright (c) 2013, 2014 Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. * */ #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1GCPHASETIMESLOG_HPP #define SHARE_VM_GC_IMPLEMENTATION_G1_G1GCPHASETIMESLOG_HPP #include "gc_interface/gcCause.hpp" class LineBuffer; template class WorkerDataArray : public CHeapObj { friend class G1GCPhasePrinter; T* _data; uint _length; const char* _title; bool _print_sum; int _log_level; uint _indent_level; bool _enabled; WorkerDataArray* _sub_count; NOT_PRODUCT(T uninitialized();) // We are caching the sum and average to only have to calculate them once. // This is not done in an MT-safe way. It is intended to allow single // threaded code to call sum() and average() multiple times in any order // without having to worry about the cost. bool _has_new_data; T _sum; T _min; T _max; double _average; public: WorkerDataArray(uint length, const char* title, bool print_sum, int log_level, uint indent_level); ~WorkerDataArray(); void link_sub_count_array(WorkerDataArray* sub_count) { _sub_count = sub_count; } WorkerDataArray* sub_count() { return _sub_count; } void set(uint worker_i, T value) { assert(worker_i < _length, err_msg("Worker %d is greater than max: %d", worker_i, _length)); assert(_data[worker_i] == WorkerDataArray::uninitialized(), err_msg("Overwriting data for worker %d in %s", worker_i, _title)); _data[worker_i] = value; _has_new_data = true; } void set_sub_count(uint worker_i, size_t value) { assert(_sub_count != NULL, "No sub count"); _sub_count->set(worker_i, value); } T get(uint worker_i) { assert(worker_i < _length, err_msg("Worker %d is greater than max: %d", worker_i, _length)); assert(_data[worker_i] != WorkerDataArray::uninitialized(), err_msg("No data to add to for worker %d", worker_i)); return _data[worker_i]; } void add(uint worker_i, T value) { assert(worker_i < _length, err_msg("Worker %d is greater than max: %d", worker_i, _length)); assert(_data[worker_i] != WorkerDataArray::uninitialized(), err_msg("No data to add to for worker %d", worker_i)); _data[worker_i] += value; _has_new_data = true; } double average(){ calculate_totals(); return _average; } T sum() { calculate_totals(); return _sum; } T minimum() { calculate_totals(); return _min; } T maximum() { calculate_totals(); return _max; } void reset() PRODUCT_RETURN; void verify() PRODUCT_RETURN; void set_enabled(bool enabled) { _enabled = enabled; } int log_level() { return _log_level; } private: void calculate_totals(){ if (!_has_new_data) { return; } _sum = (T)0; _min = _data[0]; _max = _min; for (uint i = 0; i < _length; ++i) { T val = _data[i]; _sum += val; _min = MIN2(_min, val); _max = MAX2(_max, val); } _average = (double)_sum / (double)_length; _has_new_data = false; } }; class G1GCPhaseTimes : public CHeapObj { friend class G1GCPhasePrinter; uint _active_gc_threads; uint _max_gc_threads; public: enum GCPhases { GCWorkerStart, ExtRootScan, SATBFiltering, UpdateRS, ScanRS, CodeRoots, ObjCopy, Termination, Other, GCWorkerTotal, GCWorkerEnd, StringDedupQueueFixup, StringDedupTableFixup, RedirtyCards, Sentinel }; private: // Markers for grouping the phases in the GCPhases enum above static const int GCMainPhasesLast = GCWorkerEnd; static const int StringDedupPhasesFirst = StringDedupQueueFixup; static const int StringDedupPhasesLast = StringDedupTableFixup; WorkerDataArray* _gc_phases[Sentinel]; WorkerDataArray* _update_rs_processed_buffers; WorkerDataArray* _termination_attempts; WorkerDataArray* _redirtied_cards; double _cur_collection_par_time_ms; double _cur_collection_code_root_fixup_time_ms; double _cur_strong_code_root_purge_time_ms; double _cur_evac_fail_recalc_used; double _cur_evac_fail_restore_remsets; double _cur_evac_fail_remove_self_forwards; double _cur_string_dedup_fixup_time_ms; double _cur_clear_ct_time_ms; double _cur_ref_proc_time_ms; double _cur_ref_enq_time_ms; double _cur_collection_start_sec; double _root_region_scan_wait_time_ms; double _recorded_young_cset_choice_time_ms; double _recorded_non_young_cset_choice_time_ms; double _recorded_redirty_logged_cards_time_ms; double _recorded_young_free_cset_time_ms; double _recorded_non_young_free_cset_time_ms; double _cur_fast_reclaim_humongous_time_ms; double _cur_fast_reclaim_humongous_register_time_ms; size_t _cur_fast_reclaim_humongous_total; size_t _cur_fast_reclaim_humongous_candidates; size_t _cur_fast_reclaim_humongous_reclaimed; double _cur_verify_before_time_ms; double _cur_verify_after_time_ms; // Helper methods for detailed logging void print_stats(int level, const char* str, double value); void print_stats(int level, const char* str, size_t value); void print_stats(int level, const char* str, double value, uint workers); public: G1GCPhaseTimes(uint max_gc_threads); void note_gc_start(uint active_gc_threads, bool mark_in_progress); void note_gc_end(); void print(double pause_time_sec); // record the time a phase took in seconds void record_time_secs(GCPhases phase, uint worker_i, double secs) { _gc_phases[phase]->set(worker_i, secs); } // add a number of seconds to a phase void add_time_secs(GCPhases phase, uint worker_i, double secs) { _gc_phases[phase]->add(worker_i, secs); } void record_sub_count(GCPhases phase, uint worker_i, size_t count) { _gc_phases[phase]->set_sub_count(worker_i, count); } // return the average time for a phase in milliseconds double average_time_ms(GCPhases phase) { return _gc_phases[phase]->average() * 1000.0; } size_t sub_count_sum(GCPhases phase) { assert(_gc_phases[phase]->sub_count() != NULL, "No sub count"); return _gc_phases[phase]->sub_count()->sum(); } private: double get_time_ms(GCPhases phase, uint worker_i) { return _gc_phases[phase]->get(worker_i) * 1000.0; } double sum_time_ms(GCPhases phase) { return _gc_phases[phase]->sum() * 1000.0; } double min_time_ms(GCPhases phase) { return _gc_phases[phase]->minimum() * 1000.0; } double max_time_ms(GCPhases phase) { return _gc_phases[phase]->maximum() * 1000.0; } size_t get_sub_count(GCPhases phase, uint worker_i) { assert(_gc_phases[phase]->sub_count() != NULL, "No sub count"); return _gc_phases[phase]->sub_count()->get(worker_i); } size_t sum_sub_count(GCPhases phase) { assert(_gc_phases[phase]->sub_count() != NULL, "No sub count"); return _gc_phases[phase]->sub_count()->sum(); } double average_sub_count(GCPhases phase) { assert(_gc_phases[phase]->sub_count() != NULL, "No sub count"); return _gc_phases[phase]->sub_count()->average(); } size_t min_sub_count(GCPhases phase) { assert(_gc_phases[phase]->sub_count() != NULL, "No sub count"); return _gc_phases[phase]->sub_count()->minimum(); } size_t max_sub_count(GCPhases phase) { assert(_gc_phases[phase]->sub_count() != NULL, "No sub count"); return _gc_phases[phase]->sub_count()->maximum(); } public: void record_clear_ct_time(double ms) { _cur_clear_ct_time_ms = ms; } void record_par_time(double ms) { _cur_collection_par_time_ms = ms; } void record_code_root_fixup_time(double ms) { _cur_collection_code_root_fixup_time_ms = ms; } void record_strong_code_root_purge_time(double ms) { _cur_strong_code_root_purge_time_ms = ms; } void record_evac_fail_recalc_used_time(double ms) { _cur_evac_fail_recalc_used = ms; } void record_evac_fail_restore_remsets(double ms) { _cur_evac_fail_restore_remsets = ms; } void record_evac_fail_remove_self_forwards(double ms) { _cur_evac_fail_remove_self_forwards = ms; } void record_string_dedup_fixup_time(double ms) { _cur_string_dedup_fixup_time_ms = ms; } void record_ref_proc_time(double ms) { _cur_ref_proc_time_ms = ms; } void record_ref_enq_time(double ms) { _cur_ref_enq_time_ms = ms; } void record_root_region_scan_wait_time(double time_ms) { _root_region_scan_wait_time_ms = time_ms; } void record_young_free_cset_time_ms(double time_ms) { _recorded_young_free_cset_time_ms = time_ms; } void record_non_young_free_cset_time_ms(double time_ms) { _recorded_non_young_free_cset_time_ms = time_ms; } void record_fast_reclaim_humongous_stats(double time_ms, size_t total, size_t candidates) { _cur_fast_reclaim_humongous_register_time_ms = time_ms; _cur_fast_reclaim_humongous_total = total; _cur_fast_reclaim_humongous_candidates = candidates; } void record_fast_reclaim_humongous_time_ms(double value, size_t reclaimed) { _cur_fast_reclaim_humongous_time_ms = value; _cur_fast_reclaim_humongous_reclaimed = reclaimed; } void record_young_cset_choice_time_ms(double time_ms) { _recorded_young_cset_choice_time_ms = time_ms; } void record_non_young_cset_choice_time_ms(double time_ms) { _recorded_non_young_cset_choice_time_ms = time_ms; } void record_redirty_logged_cards_time_ms(double time_ms) { _recorded_redirty_logged_cards_time_ms = time_ms; } void record_cur_collection_start_sec(double time_ms) { _cur_collection_start_sec = time_ms; } void record_verify_before_time_ms(double time_ms) { _cur_verify_before_time_ms = time_ms; } void record_verify_after_time_ms(double time_ms) { _cur_verify_after_time_ms = time_ms; } double accounted_time_ms(); double cur_collection_start_sec() { return _cur_collection_start_sec; } double cur_collection_par_time_ms() { return _cur_collection_par_time_ms; } double cur_clear_ct_time_ms() { return _cur_clear_ct_time_ms; } double root_region_scan_wait_time_ms() { return _root_region_scan_wait_time_ms; } double young_cset_choice_time_ms() { return _recorded_young_cset_choice_time_ms; } double young_free_cset_time_ms() { return _recorded_young_free_cset_time_ms; } double non_young_cset_choice_time_ms() { return _recorded_non_young_cset_choice_time_ms; } double non_young_free_cset_time_ms() { return _recorded_non_young_free_cset_time_ms; } double fast_reclaim_humongous_time_ms() { return _cur_fast_reclaim_humongous_time_ms; } }; class G1GCPhaseTimesTracker : public StackObj { double _start_time; G1GCPhaseTimes::GCPhases _phase; G1GCPhaseTimes* _phase_times; uint _worker_id; public: G1GCPhaseTimesTracker(G1GCPhaseTimes* phase_times, G1GCPhaseTimes::GCPhases phase, uint worker_id); ~G1GCPhaseTimesTracker(); }; class G1GCPhasePrinter : public StackObj { G1GCPhaseTimes* _phase_times; void print_single_length(G1GCPhaseTimes::GCPhases phase_id, WorkerDataArray* phase); void print_multi_length(G1GCPhaseTimes::GCPhases phase_id, WorkerDataArray* phase); void print_sub_count(G1GCPhaseTimes::GCPhases phase_id, WorkerDataArray* sub_count); void print_time_values(LineBuffer& buf, G1GCPhaseTimes::GCPhases phase_id, WorkerDataArray* phase); void print_count_values(LineBuffer& buf, G1GCPhaseTimes::GCPhases phase_id, WorkerDataArray* phase); public: G1GCPhasePrinter(G1GCPhaseTimes* phase_times) : _phase_times(phase_times) {} void print(G1GCPhaseTimes::GCPhases phase_id); }; #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1GCPHASETIMESLOG_HPP