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 60 WorkerDataArray<double>* worker_data(WeakProcessorPhase phase) const; 61 62 void log_st_phase(WeakProcessorPhase phase, uint indent) const; 63 void log_mt_phase_summary(WeakProcessorPhase phase, uint indent) const; 64 template <typename T> 65 void log_mt_phase_details(WorkerDataArray<T>* data, uint indent) const; 66 67 public: 68 WeakProcessorPhaseTimes(uint max_threads); 69 ~WeakProcessorPhaseTimes(); 70 71 uint max_threads() const; 72 uint active_workers() const; 73 void set_active_workers(uint n); 74 75 double total_time_sec() const; 76 double phase_time_sec(WeakProcessorPhase phase) const; 77 double worker_time_sec(uint worker_id, WeakProcessorPhase phase) const; 78 79 void record_total_time_sec(double time_sec); 80 void record_phase_time_sec(WeakProcessorPhase phase, double time_sec); 81 void record_phase_items(WeakProcessorPhase phase, size_t num_dead, size_t num_total); 82 void record_worker_time_sec(uint worker_id, WeakProcessorPhase phase, double time_sec); 83 void record_worker_items(uint worker_id, WeakProcessorPhase phase, size_t num_dead, size_t num_total); 84 85 void reset(); 86 87 void log_print(uint indent = 0) const; 88 void log_print_phases(uint indent = 0) const; 89 }; 90 91 // Record total weak processor time and worker count in times. 92 // Does nothing if times is NULL. 93 class WeakProcessorTimeTracker : StackObj { 94 WeakProcessorPhaseTimes* _times; 95 Ticks _start_time; 96 97 public: 98 WeakProcessorTimeTracker(WeakProcessorPhaseTimes* times); 99 ~WeakProcessorTimeTracker(); 100 }; 101 102 // Record phase time contribution for the current thread in phase times. 103 // Does nothing if phase times is NULL. 104 class WeakProcessorPhaseTimeTracker : StackObj { 105 private: 106 WeakProcessorPhaseTimes* _times; 107 WeakProcessorPhase _phase; 108 uint _worker_id; 109 Ticks _start_time; 110 111 public: 112 // For tracking serial phase times. 113 // Precondition: WeakProcessorPhases::is_serial(phase) 114 WeakProcessorPhaseTimeTracker(WeakProcessorPhaseTimes* times, 115 WeakProcessorPhase phase); 116 117 // For tracking possibly parallel phase times (even if processed by 118 // only one thread). 119 // Precondition: WeakProcessorPhases::is_oopstorage(phase) 120 // Precondition: worker_id < times->max_threads(). 121 WeakProcessorPhaseTimeTracker(WeakProcessorPhaseTimes* times, 122 WeakProcessorPhase phase, 123 uint worker_id); 124 125 ~WeakProcessorPhaseTimeTracker(); 126 }; 127 128 #endif // SHARE_GC_SHARED_WEAKPROCESSORPHASETIMES_HPP