23 */ |
23 */ |
24 |
24 |
25 #ifndef SHARE_VM_GC_SHARED_REFERENCEPROCESSORPHASETIMES_HPP |
25 #ifndef SHARE_VM_GC_SHARED_REFERENCEPROCESSORPHASETIMES_HPP |
26 #define SHARE_VM_GC_SHARED_REFERENCEPROCESSORPHASETIMES_HPP |
26 #define SHARE_VM_GC_SHARED_REFERENCEPROCESSORPHASETIMES_HPP |
27 |
27 |
|
28 #include "gc/shared/referenceProcessor.hpp" |
28 #include "gc/shared/referenceProcessorStats.hpp" |
29 #include "gc/shared/referenceProcessorStats.hpp" |
29 #include "gc/shared/workerDataArray.hpp" |
30 #include "gc/shared/workerDataArray.hpp" |
|
31 #include "memory/allocation.hpp" |
30 #include "memory/referenceType.hpp" |
32 #include "memory/referenceType.hpp" |
31 #include "utilities/ticks.hpp" |
33 #include "utilities/ticks.hpp" |
32 |
34 |
33 class DiscoveredList; |
35 class DiscoveredList; |
34 class GCTimer; |
36 class GCTimer; |
|
37 class LogStream; |
35 |
38 |
36 class ReferenceProcessorPhaseTimes : public CHeapObj<mtGC> { |
39 class ReferenceProcessorPhaseTimes : public CHeapObj<mtGC> { |
37 public: |
|
38 // Detailed phases that has parallel work. |
|
39 enum RefProcParPhases { |
|
40 SoftRefPhase1, |
|
41 SoftRefPhase2, |
|
42 SoftRefPhase3, |
|
43 WeakRefPhase2, |
|
44 WeakRefPhase3, |
|
45 FinalRefPhase2, |
|
46 FinalRefPhase3, |
|
47 PhantomRefPhase2, |
|
48 PhantomRefPhase3, |
|
49 RefParPhaseMax |
|
50 }; |
|
51 |
|
52 // Sub-phases that are used when processing each j.l.Reference types. |
|
53 // Only SoftReference has RefPhase1. |
|
54 enum RefProcPhaseNumbers { |
|
55 RefPhase1, |
|
56 RefPhase2, |
|
57 RefPhase3, |
|
58 RefPhaseMax |
|
59 }; |
|
60 |
|
61 private: |
|
62 static const int number_of_subclasses_of_ref = REF_PHANTOM - REF_OTHER; // 5 - 1 = 4 |
40 static const int number_of_subclasses_of_ref = REF_PHANTOM - REF_OTHER; // 5 - 1 = 4 |
63 |
41 |
64 // Records per thread information of each phase. |
42 // Records per thread time information of each sub phase. |
65 WorkerDataArray<double>* _worker_time_sec[RefParPhaseMax]; |
43 WorkerDataArray<double>* _sub_phases_worker_time_sec[ReferenceProcessor::RefSubPhaseMax]; |
66 // Records elapsed time of each phase. |
44 // Total time of each sub phase. |
67 double _par_phase_time_ms[RefParPhaseMax]; |
45 double _sub_phases_total_time_ms[ReferenceProcessor::RefSubPhaseMax]; |
68 |
46 |
69 // Total spent time for references. |
47 // Records total elapsed time for each phase. |
70 // e.g. _ref_proc_time_ms[0] = _par_phase_time_ms[SoftRefPhase1] + |
48 double _phases_time_ms[ReferenceProcessor::RefPhaseMax]; |
71 // _par_phase_time_ms[SoftRefPhase2] + |
49 // Records total queue balancing for each phase. |
72 // _par_phase_time_ms[SoftRefPhase3] + extra time. |
50 double _balance_queues_time_ms[ReferenceProcessor::RefPhaseMax]; |
73 double _ref_proc_time_ms[number_of_subclasses_of_ref]; |
|
74 |
51 |
|
52 WorkerDataArray<double>* _phase2_worker_time_sec; |
|
53 |
|
54 // Total spent time for reference processing. |
75 double _total_time_ms; |
55 double _total_time_ms; |
76 |
56 |
77 size_t _ref_cleared[number_of_subclasses_of_ref]; |
57 size_t _ref_cleared[number_of_subclasses_of_ref]; |
78 size_t _ref_discovered[number_of_subclasses_of_ref]; |
58 size_t _ref_discovered[number_of_subclasses_of_ref]; |
79 size_t _ref_enqueued[number_of_subclasses_of_ref]; |
|
80 double _balance_queues_time_ms[number_of_subclasses_of_ref]; |
|
81 |
59 |
82 bool _processing_is_mt; |
60 bool _processing_is_mt; |
83 |
61 |
84 // Currently processing reference type. |
|
85 ReferenceType _processing_ref_type; |
|
86 |
|
87 GCTimer* _gc_timer; |
62 GCTimer* _gc_timer; |
88 |
63 |
89 double par_phase_time_ms(RefProcParPhases phase) const; |
64 double phase_time_ms(ReferenceProcessor::RefProcPhases phase) const; |
90 double ref_proc_time_ms(ReferenceType ref_type) const; |
65 double sub_phase_total_time_ms(ReferenceProcessor::RefProcSubPhases sub_phase) const; |
91 |
66 |
92 double total_time_ms() const { return _total_time_ms; } |
67 double total_time_ms() const { return _total_time_ms; } |
93 |
68 |
94 size_t ref_cleared(ReferenceType ref_type) const; |
69 double balance_queues_time_ms(ReferenceProcessor::RefProcPhases phase) const; |
95 size_t ref_enqueued(ReferenceType ref_type) const; |
|
96 |
|
97 double balance_queues_time_ms(ReferenceType ref_type) const; |
|
98 |
70 |
99 void print_reference(ReferenceType ref_type, uint base_indent) const; |
71 void print_reference(ReferenceType ref_type, uint base_indent) const; |
100 void print_phase(RefProcParPhases phase, uint indent) const; |
|
101 |
72 |
|
73 void print_phase(ReferenceProcessor::RefProcPhases phase, uint indent) const; |
|
74 void print_balance_time(LogStream* ls, ReferenceProcessor::RefProcPhases phase, uint indent) const; |
|
75 void print_sub_phase(LogStream* ls, ReferenceProcessor::RefProcSubPhases sub_phase, uint indent) const; |
|
76 void print_worker_time(LogStream* ls, WorkerDataArray<double>* worker_time, const char* ser_title, uint indent) const; |
|
77 |
|
78 static double uninitialized() { return -1.0; } |
102 public: |
79 public: |
103 ReferenceProcessorPhaseTimes(GCTimer* gc_timer, uint max_gc_threads); |
80 ReferenceProcessorPhaseTimes(GCTimer* gc_timer, uint max_gc_threads); |
104 ~ReferenceProcessorPhaseTimes(); |
81 ~ReferenceProcessorPhaseTimes(); |
105 |
82 |
106 static double uninitialized() { return -1.0; } |
83 WorkerDataArray<double>* phase2_worker_time_sec() const { return _phase2_worker_time_sec; } |
|
84 WorkerDataArray<double>* sub_phase_worker_time_sec(ReferenceProcessor::RefProcSubPhases phase) const; |
|
85 void set_phase_time_ms(ReferenceProcessor::RefProcPhases phase, double par_phase_time_ms); |
107 |
86 |
108 WorkerDataArray<double>* worker_time_sec(RefProcParPhases phase) const; |
87 void set_sub_phase_total_phase_time_ms(ReferenceProcessor::RefProcSubPhases sub_phase, double ref_proc_time_ms); |
109 void set_par_phase_time_ms(RefProcParPhases phase, double par_phase_time_ms); |
|
110 |
|
111 void set_ref_proc_time_ms(ReferenceType ref_type, double ref_proc_time_ms); |
|
112 |
88 |
113 void set_total_time_ms(double total_time_ms) { _total_time_ms = total_time_ms; } |
89 void set_total_time_ms(double total_time_ms) { _total_time_ms = total_time_ms; } |
114 |
90 |
115 void set_ref_cleared(ReferenceType ref_type, size_t count); |
91 void add_ref_cleared(ReferenceType ref_type, size_t count); |
116 size_t ref_discovered(ReferenceType ref_type) const; |
|
117 void set_ref_discovered(ReferenceType ref_type, size_t count); |
92 void set_ref_discovered(ReferenceType ref_type, size_t count); |
118 void set_ref_enqueued(ReferenceType ref_type, size_t count); |
|
119 |
93 |
120 void set_balance_queues_time_ms(ReferenceType ref_type, double time_ms); |
94 void set_balance_queues_time_ms(ReferenceProcessor::RefProcPhases phase, double time_ms); |
121 |
95 |
122 void set_processing_is_mt(bool processing_is_mt) { _processing_is_mt = processing_is_mt; } |
96 void set_processing_is_mt(bool processing_is_mt) { _processing_is_mt = processing_is_mt; } |
123 |
|
124 ReferenceType processing_ref_type() const { return _processing_ref_type; } |
|
125 void set_processing_ref_type(ReferenceType processing_ref_type) { _processing_ref_type = processing_ref_type; } |
|
126 |
|
127 // Returns RefProcParPhases calculated from phase_number and _processing_ref_type. |
|
128 RefProcParPhases par_phase(RefProcPhaseNumbers phase_number) const; |
|
129 |
97 |
130 GCTimer* gc_timer() const { return _gc_timer; } |
98 GCTimer* gc_timer() const { return _gc_timer; } |
131 |
99 |
132 // Reset all fields. If not reset at next cycle, an assertion will fail. |
100 // Reset all fields. If not reset at next cycle, an assertion will fail. |
133 void reset(); |
101 void reset(); |
134 |
102 |
135 void print_all_references(uint base_indent = 0, bool print_total = true) const; |
103 void print_all_references(uint base_indent = 0, bool print_total = true) const; |
136 }; |
104 }; |
137 |
105 |
138 // Updates working time of each worker thread. |
106 class RefProcWorkerTimeTracker : public CHeapObj<mtGC> { |
139 class RefProcWorkerTimeTracker : public StackObj { |
|
140 protected: |
107 protected: |
141 WorkerDataArray<double>* _worker_time; |
108 WorkerDataArray<double>* _worker_time; |
142 double _start_time; |
109 double _start_time; |
143 uint _worker_id; |
110 uint _worker_id; |
|
111 public: |
|
112 RefProcWorkerTimeTracker(WorkerDataArray<double>* worker_time, uint worker_id); |
|
113 virtual ~RefProcWorkerTimeTracker(); |
|
114 }; |
144 |
115 |
|
116 // Updates working time of each worker thread for a given sub phase. |
|
117 class RefProcSubPhasesWorkerTimeTracker : public RefProcWorkerTimeTracker { |
145 public: |
118 public: |
146 RefProcWorkerTimeTracker(ReferenceProcessorPhaseTimes::RefProcPhaseNumbers number, |
119 RefProcSubPhasesWorkerTimeTracker(ReferenceProcessor::RefProcSubPhases phase, |
147 ReferenceProcessorPhaseTimes* phase_times, |
120 ReferenceProcessorPhaseTimes* phase_times, |
148 uint worker_id); |
121 uint worker_id); |
149 RefProcWorkerTimeTracker(ReferenceProcessorPhaseTimes::RefProcParPhases phase, |
122 ~RefProcSubPhasesWorkerTimeTracker(); |
150 ReferenceProcessorPhaseTimes* phase_times, |
|
151 uint worker_id); |
|
152 ~RefProcWorkerTimeTracker(); |
|
153 }; |
123 }; |
154 |
124 |
155 class RefProcPhaseTimeBaseTracker : public StackObj { |
125 class RefProcPhaseTimeBaseTracker : public StackObj { |
156 protected: |
126 protected: |
157 const char* _title; |
|
158 ReferenceProcessorPhaseTimes* _phase_times; |
127 ReferenceProcessorPhaseTimes* _phase_times; |
159 Ticks _start_ticks; |
128 Ticks _start_ticks; |
160 Ticks _end_ticks; |
129 Ticks _end_ticks; |
161 |
130 |
|
131 ReferenceProcessor::RefProcPhases _phase_number; |
|
132 |
162 Ticks end_ticks(); |
133 Ticks end_ticks(); |
163 double elapsed_time(); |
134 double elapsed_time(); |
164 ReferenceProcessorPhaseTimes* phase_times() const { return _phase_times; } |
135 ReferenceProcessorPhaseTimes* phase_times() const { return _phase_times; } |
165 // Print phase elapsed time with each worker information if MT processed. |
|
166 void print_phase(ReferenceProcessorPhaseTimes::RefProcParPhases phase, uint indent); |
|
167 |
136 |
168 public: |
137 public: |
169 RefProcPhaseTimeBaseTracker(const char* title, |
138 RefProcPhaseTimeBaseTracker(const char* title, |
|
139 ReferenceProcessor::RefProcPhases _phase_number, |
170 ReferenceProcessorPhaseTimes* phase_times); |
140 ReferenceProcessorPhaseTimes* phase_times); |
171 ~RefProcPhaseTimeBaseTracker(); |
141 ~RefProcPhaseTimeBaseTracker(); |
172 }; |
142 }; |
173 |
143 |
174 // Updates queue balance time at ReferenceProcessorPhaseTimes and |
144 // Updates queue balance time at ReferenceProcessorPhaseTimes and |
175 // save it into GCTimer. |
145 // save it into GCTimer. |
176 class RefProcBalanceQueuesTimeTracker : public RefProcPhaseTimeBaseTracker { |
146 class RefProcBalanceQueuesTimeTracker : public RefProcPhaseTimeBaseTracker { |
177 public: |
147 public: |
178 RefProcBalanceQueuesTimeTracker(ReferenceProcessorPhaseTimes* phase_times); |
148 RefProcBalanceQueuesTimeTracker(ReferenceProcessor::RefProcPhases phase_number, |
|
149 ReferenceProcessorPhaseTimes* phase_times); |
179 ~RefProcBalanceQueuesTimeTracker(); |
150 ~RefProcBalanceQueuesTimeTracker(); |
180 }; |
151 }; |
181 |
152 |
182 // Updates phase time at ReferenceProcessorPhaseTimes and save it into GCTimer. |
153 // Updates phase time at ReferenceProcessorPhaseTimes and save it into GCTimer. |
183 class RefProcParPhaseTimeTracker : public RefProcPhaseTimeBaseTracker { |
154 class RefProcPhaseTimeTracker : public RefProcPhaseTimeBaseTracker { |
184 ReferenceProcessorPhaseTimes::RefProcPhaseNumbers _phase_number; |
|
185 |
|
186 public: |
155 public: |
187 RefProcParPhaseTimeTracker(ReferenceProcessorPhaseTimes::RefProcPhaseNumbers phase_number, |
156 RefProcPhaseTimeTracker(ReferenceProcessor::RefProcPhases phase_number, |
188 ReferenceProcessorPhaseTimes* phase_times); |
157 ReferenceProcessorPhaseTimes* phase_times); |
189 ~RefProcParPhaseTimeTracker(); |
158 ~RefProcPhaseTimeTracker(); |
190 }; |
159 }; |
191 |
160 |
192 // Updates phase time related information. |
161 // Highest level time tracker. |
193 // - Each phase processing time, cleared/discovered reference counts and stats for each working threads if MT processed. |
162 class RefProcTotalPhaseTimesTracker : public RefProcPhaseTimeBaseTracker { |
194 class RefProcPhaseTimesTracker : public RefProcPhaseTimeBaseTracker { |
|
195 ReferenceProcessor* _rp; |
163 ReferenceProcessor* _rp; |
196 |
|
197 public: |
164 public: |
198 RefProcPhaseTimesTracker(ReferenceType ref_type, |
165 RefProcTotalPhaseTimesTracker(ReferenceProcessor::RefProcPhases phase_number, |
199 ReferenceProcessorPhaseTimes* phase_times, |
166 ReferenceProcessorPhaseTimes* phase_times, |
200 ReferenceProcessor* rp); |
167 ReferenceProcessor* rp); |
201 ~RefProcPhaseTimesTracker(); |
168 ~RefProcTotalPhaseTimesTracker(); |
202 }; |
169 }; |
203 |
170 |
204 #endif // SHARE_VM_GC_SHARED_REFERENCEPROCESSORPHASETIMES_HPP |
171 #endif // SHARE_VM_GC_SHARED_REFERENCEPROCESSORPHASETIMES_HPP |