jdk

Форк
0
/
weakProcessorTimes.cpp 
218 строк · 7.4 Кб
1
/*
2
 * Copyright (c) 2018, 2023, 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
#include "precompiled.hpp"
26
#include "gc/shared/oopStorage.hpp"
27
#include "gc/shared/weakProcessor.hpp"
28
#include "gc/shared/weakProcessorTimes.hpp"
29
#include "gc/shared/workerDataArray.inline.hpp"
30
#include "logging/log.hpp"
31
#include "logging/logStream.hpp"
32
#include "utilities/debug.hpp"
33
#include "utilities/enumIterator.hpp"
34
#include "utilities/globalDefinitions.hpp"
35
#include "utilities/ticks.hpp"
36

37
const double uninitialized_time = -1.0;
38

39
#ifdef ASSERT
40
static bool is_initialized_time(double t) { return t >= 0.0; }
41
#endif // ASSERT
42

43

44
WeakProcessorTimes::WeakProcessorTimes(uint max_threads) :
45
  _max_threads(max_threads),
46
  _active_workers(0),
47
  _total_time_sec(uninitialized_time),
48
  _worker_data()
49
{
50
  assert(_max_threads > 0, "max_threads must not be zero");
51

52
  WorkerDataArray<double>** wpt = _worker_data;
53
  for (auto id : EnumRange<OopStorageSet::WeakId>()) {
54
    assert(size_t(wpt - _worker_data) < ARRAY_SIZE(_worker_data), "invariant");
55
    const char* description = OopStorageSet::storage(id)->name();
56
    *wpt = new WorkerDataArray<double>(nullptr, description, _max_threads);
57
    (*wpt)->create_thread_work_items("Dead", DeadItems);
58
    (*wpt)->create_thread_work_items("Total", TotalItems);
59
    wpt++;
60
  }
61
  assert(size_t(wpt - _worker_data) == ARRAY_SIZE(_worker_data), "invariant");
62
}
63

64
WeakProcessorTimes::~WeakProcessorTimes() {
65
  for (size_t i = 0; i < ARRAY_SIZE(_worker_data); ++i) {
66
    delete _worker_data[i];
67
  }
68
}
69

70
uint WeakProcessorTimes::max_threads() const { return _max_threads; }
71

72
uint WeakProcessorTimes::active_workers() const {
73
  assert(_active_workers != 0, "active workers not set");
74
  return _active_workers;
75
}
76

77
void WeakProcessorTimes::set_active_workers(uint n) {
78
  assert(_active_workers == 0, "active workers already set");
79
  assert(n > 0, "active workers must be non-zero");
80
  assert(n <= _max_threads, "active workers must not exceed max threads");
81
  _active_workers = n;
82
}
83

84
void WeakProcessorTimes::reset() {
85
  _active_workers = 0;
86
  _total_time_sec = uninitialized_time;
87
  for (size_t i = 0; i < ARRAY_SIZE(_worker_data); ++i) {
88
    _worker_data[i]->reset();
89
  }
90
}
91

92
double WeakProcessorTimes::total_time_sec() const {
93
  assert(is_initialized_time(_total_time_sec), "Total time not set");
94
  return _total_time_sec;
95
}
96

97
void WeakProcessorTimes::record_total_time_sec(double time_sec) {
98
  assert(!is_initialized_time(_total_time_sec), "Already set total time");
99
  _total_time_sec = time_sec;
100
}
101

102
WorkerDataArray<double>* WeakProcessorTimes::worker_data(OopStorageSet::WeakId id) const {
103
  size_t index = EnumRange<OopStorageSet::WeakId>().index(id);
104
  assert(index < ARRAY_SIZE(_worker_data), "invalid phase");
105
  return _worker_data[index];
106
}
107

108
double WeakProcessorTimes::worker_time_sec(uint worker_id,
109
                                           OopStorageSet::WeakId id) const {
110
  assert(worker_id < active_workers(),
111
         "invalid worker id %u for %u", worker_id, active_workers());
112
  return worker_data(id)->get(worker_id);
113
}
114

115
void WeakProcessorTimes::record_worker_time_sec(uint worker_id,
116
                                                OopStorageSet::WeakId id,
117
                                                double time_sec) {
118
  worker_data(id)->set(worker_id, time_sec);
119
}
120

121
void WeakProcessorTimes::record_worker_items(uint worker_id,
122
                                             OopStorageSet::WeakId id,
123
                                             size_t num_dead,
124
                                             size_t num_total) {
125
  WorkerDataArray<double>* data = worker_data(id);
126
  data->set_or_add_thread_work_item(worker_id, num_dead, DeadItems);
127
  data->set_or_add_thread_work_item(worker_id, num_total, TotalItems);
128
}
129

130
static double elapsed_time_sec(Ticks start_time, Ticks end_time) {
131
  return (end_time - start_time).seconds();
132
}
133

134
WeakProcessorTimeTracker::WeakProcessorTimeTracker(WeakProcessorTimes* times) :
135
  _times(times),
136
  _start_time(Ticks::now())
137
{}
138

139
WeakProcessorTimeTracker::~WeakProcessorTimeTracker() {
140
  if (_times != nullptr) {
141
    Ticks end_time = Ticks::now();
142
    _times->record_total_time_sec(elapsed_time_sec(_start_time, end_time));
143
  }
144
}
145

146
WeakProcessorParTimeTracker::WeakProcessorParTimeTracker(WeakProcessorTimes* times,
147
                                                         OopStorageSet::WeakId storage_id,
148
                                                         uint worker_id) :
149
  _times(times),
150
  _storage_id(storage_id),
151
  _worker_id(worker_id),
152
  _start_time(Ticks::now())
153
{
154
  assert(_times == nullptr || worker_id < _times->active_workers(),
155
         "Invalid worker_id %u", worker_id);
156
}
157

158

159
WeakProcessorParTimeTracker::~WeakProcessorParTimeTracker() {
160
  if (_times != nullptr) {
161
    double time_sec = elapsed_time_sec(_start_time, Ticks::now());
162
    _times->record_worker_time_sec(_worker_id, _storage_id, time_sec);
163
  }
164
}
165

166
//////////////////////////////////////////////////////////////////////////////
167
// Printing times
168

169
const char* const indents[] = {"", "  ", "    ", "      ", "        "};
170
const size_t max_indents_index = ARRAY_SIZE(indents) - 1;
171

172
static const char* indent_str(size_t i) {
173
  return indents[MIN2(i, max_indents_index)];
174
}
175

176
#define TIME_FORMAT "%.2lfms"
177

178
void WeakProcessorTimes::log_summary(OopStorageSet::WeakId id, uint indent) const {
179
  LogTarget(Debug, gc, phases) lt;
180
  LogStream ls(lt);
181
  ls.print("%s", indents[indent]);
182
  worker_data(id)->print_summary_on(&ls, true);
183
  log_details(worker_data(id), indent + 1);
184

185
  for (uint i = 0; i < worker_data(id)->MaxThreadWorkItems; i++) {
186
    WorkerDataArray<size_t>* work_items = worker_data(id)->thread_work_items(i);
187
    if (work_items != nullptr) {
188
      ls.print("%s", indents[indent + 1]);
189
      work_items->print_summary_on(&ls, true);
190
      log_details(work_items, indent + 1);
191
    }
192
  }
193
}
194

195
template <typename T>
196
void WeakProcessorTimes::log_details(WorkerDataArray<T>* data, uint indent) const {
197
  LogTarget(Trace, gc, phases) lt;
198
  if (lt.is_enabled()) {
199
    LogStream ls(lt);
200
    ls.print("%s", indents[indent]);
201
    data->print_details_on(&ls);
202
  }
203
}
204

205
void WeakProcessorTimes::log_subtotals(uint indent) const {
206
  if (log_is_enabled(Debug, gc, phases)) {
207
    for (auto id : EnumRange<OopStorageSet::WeakId>()) {
208
      log_summary(id, indent);
209
    }
210
  }
211
}
212

213
void WeakProcessorTimes::log_total(uint indent) const {
214
  log_debug(gc, phases)("%s%s: " TIME_FORMAT,
215
                        indent_str(indent),
216
                        "Weak Processing",
217
                        total_time_sec() * MILLIUNITS);
218
}
219

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.