1 /* 2 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_GC_SHARED_WEAKPROCESSORPHASETIMES_HPP 26 #define SHARE_GC_SHARED_WEAKPROCESSORPHASETIMES_HPP 27 28 #include "gc/shared/oopStorageSet.hpp" 29 #include "gc/shared/weakProcessorPhases.hpp" 30 #include "memory/allocation.hpp" 31 #include "utilities/globalDefinitions.hpp" 32 #include "utilities/ticks.hpp" 33 34 template<typename T> class WorkerDataArray; 35 36 class WeakProcessorPhaseTimes : public CHeapObj<mtGC> { 37 enum { 38 DeadItems, 39 TotalItems 40 }; 41 uint _max_threads; 42 uint _active_workers; 43 44 // Total time for weak processor. 45 double _total_time_sec; 46 47 // Total time and associated items for each serially processed phase. 48 static const uint phase_data_count = WeakProcessorPhases::serial_phase_count; 49 // +1 because serial_phase_count == 0 in some build configurations. 50 // Simpler to always allocate extra space than conditionalize. 51 double _phase_times_sec[phase_data_count + 1]; 52 size_t _phase_dead_items[phase_data_count + 1]; 53 size_t _phase_total_items[phase_data_count + 1]; 54 void reset_phase_data(); 55 56 // Per-worker times and linked items. 57 static const uint worker_data_count = WeakProcessorPhases::oopstorage_phase_count; 58 WorkerDataArray<double>* _worker_data[worker_data_count]; 59 WorkerDataArray<size_t>* _worker_dead_items[worker_data_count]; 60 WorkerDataArray<size_t>* _worker_total_items[worker_data_count]; 61 62 WorkerDataArray<double>* worker_data(WeakProcessorPhase phase) const; 63 64 void log_st_phase(WeakProcessorPhase phase, uint indent) const; 65 void log_mt_phase_summary(WeakProcessorPhase phase, uint indent) const; 66 template <typename T> 67 void log_mt_phase_details(WorkerDataArray<T>* data, uint indent) const; 68 69 public: 70 WeakProcessorPhaseTimes(uint max_threads); 71 ~WeakProcessorPhaseTimes(); 72 73 uint max_threads() const; 74 uint active_workers() const; 75 void set_active_workers(uint n); 76 77 double total_time_sec() const; 78 double phase_time_sec(WeakProcessorPhase phase) const; 79 double worker_time_sec(uint worker_id, WeakProcessorPhase phase) const; 80 81 void record_total_time_sec(double time_sec); 82 void record_phase_time_sec(WeakProcessorPhase phase, double time_sec); 83 void record_phase_items(WeakProcessorPhase phase, size_t num_dead, size_t num_total); 84 void record_worker_time_sec(uint worker_id, WeakProcessorPhase phase, double time_sec); 85 void record_worker_items(uint worker_id, WeakProcessorPhase phase, size_t num_dead, size_t num_total); 86 87 void reset(); 88 89 void log_print(uint indent = 0) const; 90 void log_print_phases(uint indent = 0) const; 91 }; 92 93 // Record total weak processor time and worker count in times. 94 // Does nothing if times is NULL. 95 class WeakProcessorTimeTracker : StackObj { 96 WeakProcessorPhaseTimes* _times; 97 Ticks _start_time; 98 99 public: 100 WeakProcessorTimeTracker(WeakProcessorPhaseTimes* times); 101 ~WeakProcessorTimeTracker(); 102 }; 103 104 // Record phase time contribution for the current thread in phase times. 105 // Does nothing if phase times is NULL. 106 class WeakProcessorPhaseTimeTracker : StackObj { 107 private: 108 WeakProcessorPhaseTimes* _times; 109 WeakProcessorPhase _phase; 110 uint _worker_id; 111 Ticks _start_time; 112 113 public: 114 // For tracking serial phase times. 115 // Precondition: WeakProcessorPhases::is_serial(phase) 116 WeakProcessorPhaseTimeTracker(WeakProcessorPhaseTimes* times, 117 WeakProcessorPhase phase); 118 119 // For tracking possibly parallel phase times (even if processed by 120 // only one thread). 121 // Precondition: WeakProcessorPhases::is_oopstorage(phase) 122 // Precondition: worker_id < times->max_threads(). 123 WeakProcessorPhaseTimeTracker(WeakProcessorPhaseTimes* times, 124 WeakProcessorPhase phase, 125 uint worker_id); 126 127 ~WeakProcessorPhaseTimeTracker(); 128 }; 129 130 #endif // SHARE_GC_SHARED_WEAKPROCESSORPHASETIMES_HPP