Tue, 08 Aug 2017 15:57:29 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | * |
aoqi@0 | 23 | */ |
aoqi@0 | 24 | |
aoqi@0 | 25 | #include "precompiled.hpp" |
aoqi@0 | 26 | #include "gc_implementation/shared/gcTimer.hpp" |
aoqi@0 | 27 | #include "utilities/growableArray.hpp" |
aoqi@0 | 28 | #include "utilities/ticks.inline.hpp" |
aoqi@0 | 29 | |
aoqi@0 | 30 | // the "time" parameter for most functions |
aoqi@0 | 31 | // has a default value set by Ticks::now() |
aoqi@0 | 32 | |
aoqi@0 | 33 | void GCTimer::register_gc_start(const Ticks& time) { |
aoqi@0 | 34 | _time_partitions.clear(); |
aoqi@0 | 35 | _gc_start = time; |
aoqi@0 | 36 | } |
aoqi@0 | 37 | |
aoqi@0 | 38 | void GCTimer::register_gc_end(const Ticks& time) { |
aoqi@0 | 39 | assert(!_time_partitions.has_active_phases(), |
aoqi@0 | 40 | "We should have ended all started phases, before ending the GC"); |
aoqi@0 | 41 | |
aoqi@0 | 42 | _gc_end = time; |
aoqi@0 | 43 | } |
aoqi@0 | 44 | |
aoqi@0 | 45 | void GCTimer::register_gc_pause_start(const char* name, const Ticks& time) { |
aoqi@0 | 46 | _time_partitions.report_gc_phase_start(name, time); |
aoqi@0 | 47 | } |
aoqi@0 | 48 | |
aoqi@0 | 49 | void GCTimer::register_gc_pause_end(const Ticks& time) { |
aoqi@0 | 50 | _time_partitions.report_gc_phase_end(time); |
aoqi@0 | 51 | } |
aoqi@0 | 52 | |
aoqi@0 | 53 | void GCTimer::register_gc_phase_start(const char* name, const Ticks& time) { |
aoqi@0 | 54 | _time_partitions.report_gc_phase_start(name, time); |
aoqi@0 | 55 | } |
aoqi@0 | 56 | |
aoqi@0 | 57 | void GCTimer::register_gc_phase_end(const Ticks& time) { |
aoqi@0 | 58 | _time_partitions.report_gc_phase_end(time); |
aoqi@0 | 59 | } |
aoqi@0 | 60 | |
aoqi@0 | 61 | void STWGCTimer::register_gc_start(const Ticks& time) { |
aoqi@0 | 62 | GCTimer::register_gc_start(time); |
aoqi@0 | 63 | register_gc_pause_start("GC Pause", time); |
aoqi@0 | 64 | } |
aoqi@0 | 65 | |
aoqi@0 | 66 | void STWGCTimer::register_gc_end(const Ticks& time) { |
aoqi@0 | 67 | register_gc_pause_end(time); |
aoqi@0 | 68 | GCTimer::register_gc_end(time); |
aoqi@0 | 69 | } |
aoqi@0 | 70 | |
aoqi@0 | 71 | void ConcurrentGCTimer::register_gc_pause_start(const char* name) { |
aoqi@0 | 72 | GCTimer::register_gc_pause_start(name); |
aoqi@0 | 73 | } |
aoqi@0 | 74 | |
aoqi@0 | 75 | void ConcurrentGCTimer::register_gc_pause_end() { |
aoqi@0 | 76 | GCTimer::register_gc_pause_end(); |
aoqi@0 | 77 | } |
aoqi@0 | 78 | |
aoqi@0 | 79 | void PhasesStack::clear() { |
aoqi@0 | 80 | _next_phase_level = 0; |
aoqi@0 | 81 | } |
aoqi@0 | 82 | |
aoqi@0 | 83 | void PhasesStack::push(int phase_index) { |
aoqi@0 | 84 | assert(_next_phase_level < PHASE_LEVELS, "Overflow"); |
aoqi@0 | 85 | |
aoqi@0 | 86 | _phase_indices[_next_phase_level] = phase_index; |
aoqi@0 | 87 | |
aoqi@0 | 88 | _next_phase_level++; |
aoqi@0 | 89 | } |
aoqi@0 | 90 | |
aoqi@0 | 91 | int PhasesStack::pop() { |
aoqi@0 | 92 | assert(_next_phase_level > 0, "Underflow"); |
aoqi@0 | 93 | |
aoqi@0 | 94 | _next_phase_level--; |
aoqi@0 | 95 | |
aoqi@0 | 96 | return _phase_indices[_next_phase_level]; |
aoqi@0 | 97 | } |
aoqi@0 | 98 | |
aoqi@0 | 99 | int PhasesStack::count() const { |
aoqi@0 | 100 | return _next_phase_level; |
aoqi@0 | 101 | } |
aoqi@0 | 102 | |
aoqi@0 | 103 | |
aoqi@0 | 104 | TimePartitions::TimePartitions() { |
aoqi@0 | 105 | _phases = new (ResourceObj::C_HEAP, mtGC) GrowableArray<PausePhase>(INITIAL_CAPACITY, true, mtGC); |
aoqi@0 | 106 | clear(); |
aoqi@0 | 107 | } |
aoqi@0 | 108 | |
aoqi@0 | 109 | TimePartitions::~TimePartitions() { |
aoqi@0 | 110 | delete _phases; |
aoqi@0 | 111 | _phases = NULL; |
aoqi@0 | 112 | } |
aoqi@0 | 113 | |
aoqi@0 | 114 | void TimePartitions::clear() { |
aoqi@0 | 115 | _phases->clear(); |
aoqi@0 | 116 | _active_phases.clear(); |
aoqi@0 | 117 | _sum_of_pauses = Tickspan(); |
aoqi@0 | 118 | _longest_pause = Tickspan(); |
aoqi@0 | 119 | } |
aoqi@0 | 120 | |
aoqi@0 | 121 | void TimePartitions::report_gc_phase_start(const char* name, const Ticks& time) { |
aoqi@0 | 122 | assert(_phases->length() <= 1000, "Too many recored phases?"); |
aoqi@0 | 123 | |
aoqi@0 | 124 | int level = _active_phases.count(); |
aoqi@0 | 125 | |
aoqi@0 | 126 | PausePhase phase; |
aoqi@0 | 127 | phase.set_level(level); |
aoqi@0 | 128 | phase.set_name(name); |
aoqi@0 | 129 | phase.set_start(time); |
aoqi@0 | 130 | |
aoqi@0 | 131 | int index = _phases->append(phase); |
aoqi@0 | 132 | |
aoqi@0 | 133 | _active_phases.push(index); |
aoqi@0 | 134 | } |
aoqi@0 | 135 | |
aoqi@0 | 136 | void TimePartitions::update_statistics(GCPhase* phase) { |
aoqi@0 | 137 | // FIXME: This should only be done for pause phases |
aoqi@0 | 138 | if (phase->level() == 0) { |
aoqi@0 | 139 | const Tickspan pause = phase->end() - phase->start(); |
aoqi@0 | 140 | _sum_of_pauses += pause; |
aoqi@0 | 141 | _longest_pause = MAX2(pause, _longest_pause); |
aoqi@0 | 142 | } |
aoqi@0 | 143 | } |
aoqi@0 | 144 | |
aoqi@0 | 145 | void TimePartitions::report_gc_phase_end(const Ticks& time) { |
aoqi@0 | 146 | int phase_index = _active_phases.pop(); |
aoqi@0 | 147 | GCPhase* phase = _phases->adr_at(phase_index); |
aoqi@0 | 148 | phase->set_end(time); |
aoqi@0 | 149 | update_statistics(phase); |
aoqi@0 | 150 | } |
aoqi@0 | 151 | |
aoqi@0 | 152 | int TimePartitions::num_phases() const { |
aoqi@0 | 153 | return _phases->length(); |
aoqi@0 | 154 | } |
aoqi@0 | 155 | |
aoqi@0 | 156 | GCPhase* TimePartitions::phase_at(int index) const { |
aoqi@0 | 157 | assert(index >= 0, "Out of bounds"); |
aoqi@0 | 158 | assert(index < _phases->length(), "Out of bounds"); |
aoqi@0 | 159 | |
aoqi@0 | 160 | return _phases->adr_at(index); |
aoqi@0 | 161 | } |
aoqi@0 | 162 | |
aoqi@0 | 163 | bool TimePartitions::has_active_phases() { |
aoqi@0 | 164 | return _active_phases.count() > 0; |
aoqi@0 | 165 | } |
aoqi@0 | 166 | |
aoqi@0 | 167 | bool TimePartitionPhasesIterator::has_next() { |
aoqi@0 | 168 | return _next < _time_partitions->num_phases(); |
aoqi@0 | 169 | } |
aoqi@0 | 170 | |
aoqi@0 | 171 | GCPhase* TimePartitionPhasesIterator::next() { |
aoqi@0 | 172 | assert(has_next(), "Must have phases left"); |
aoqi@0 | 173 | return _time_partitions->phase_at(_next++); |
aoqi@0 | 174 | } |
aoqi@0 | 175 | |
aoqi@0 | 176 | |
aoqi@0 | 177 | /////////////// Unit tests /////////////// |
aoqi@0 | 178 | |
aoqi@0 | 179 | #ifndef PRODUCT |
aoqi@0 | 180 | |
aoqi@0 | 181 | class TimePartitionPhasesIteratorTest { |
aoqi@0 | 182 | public: |
aoqi@0 | 183 | static void all() { |
aoqi@0 | 184 | one_pause(); |
aoqi@0 | 185 | two_pauses(); |
aoqi@0 | 186 | one_sub_pause_phase(); |
aoqi@0 | 187 | many_sub_pause_phases(); |
aoqi@0 | 188 | many_sub_pause_phases2(); |
aoqi@0 | 189 | max_nested_pause_phases(); |
aoqi@0 | 190 | } |
aoqi@0 | 191 | |
aoqi@0 | 192 | static void validate_pause_phase(GCPhase* phase, int level, const char* name, const Ticks& start, const Ticks& end) { |
aoqi@0 | 193 | assert(phase->level() == level, "Incorrect level"); |
aoqi@0 | 194 | assert(strcmp(phase->name(), name) == 0, "Incorrect name"); |
aoqi@0 | 195 | assert(phase->start() == start, "Incorrect start"); |
aoqi@0 | 196 | assert(phase->end() == end, "Incorrect end"); |
aoqi@0 | 197 | } |
aoqi@0 | 198 | |
aoqi@0 | 199 | static void one_pause() { |
aoqi@0 | 200 | TimePartitions time_partitions; |
aoqi@0 | 201 | time_partitions.report_gc_phase_start("PausePhase", 2); |
aoqi@0 | 202 | time_partitions.report_gc_phase_end(8); |
aoqi@0 | 203 | |
aoqi@0 | 204 | TimePartitionPhasesIterator iter(&time_partitions); |
aoqi@0 | 205 | |
aoqi@0 | 206 | validate_pause_phase(iter.next(), 0, "PausePhase", 2, 8); |
aoqi@0 | 207 | assert(time_partitions.sum_of_pauses() == Ticks(8) - Ticks(2), "Incorrect"); |
aoqi@0 | 208 | assert(time_partitions.longest_pause() == Ticks(8) - Ticks(2), "Incorrect"); |
aoqi@0 | 209 | |
aoqi@0 | 210 | assert(!iter.has_next(), "Too many elements"); |
aoqi@0 | 211 | } |
aoqi@0 | 212 | |
aoqi@0 | 213 | static void two_pauses() { |
aoqi@0 | 214 | TimePartitions time_partitions; |
aoqi@0 | 215 | time_partitions.report_gc_phase_start("PausePhase1", 2); |
aoqi@0 | 216 | time_partitions.report_gc_phase_end(3); |
aoqi@0 | 217 | time_partitions.report_gc_phase_start("PausePhase2", 4); |
aoqi@0 | 218 | time_partitions.report_gc_phase_end(6); |
aoqi@0 | 219 | |
aoqi@0 | 220 | TimePartitionPhasesIterator iter(&time_partitions); |
aoqi@0 | 221 | |
aoqi@0 | 222 | validate_pause_phase(iter.next(), 0, "PausePhase1", 2, 3); |
aoqi@0 | 223 | validate_pause_phase(iter.next(), 0, "PausePhase2", 4, 6); |
aoqi@0 | 224 | |
aoqi@0 | 225 | assert(time_partitions.sum_of_pauses() == Ticks(3) - Ticks(0), "Incorrect"); |
aoqi@0 | 226 | assert(time_partitions.longest_pause() == Ticks(2) - Ticks(0), "Incorrect"); |
aoqi@0 | 227 | |
aoqi@0 | 228 | assert(!iter.has_next(), "Too many elements"); |
aoqi@0 | 229 | } |
aoqi@0 | 230 | |
aoqi@0 | 231 | static void one_sub_pause_phase() { |
aoqi@0 | 232 | TimePartitions time_partitions; |
aoqi@0 | 233 | time_partitions.report_gc_phase_start("PausePhase", 2); |
aoqi@0 | 234 | time_partitions.report_gc_phase_start("SubPhase", 3); |
aoqi@0 | 235 | time_partitions.report_gc_phase_end(4); |
aoqi@0 | 236 | time_partitions.report_gc_phase_end(5); |
aoqi@0 | 237 | |
aoqi@0 | 238 | TimePartitionPhasesIterator iter(&time_partitions); |
aoqi@0 | 239 | |
aoqi@0 | 240 | validate_pause_phase(iter.next(), 0, "PausePhase", 2, 5); |
aoqi@0 | 241 | validate_pause_phase(iter.next(), 1, "SubPhase", 3, 4); |
aoqi@0 | 242 | |
aoqi@0 | 243 | assert(time_partitions.sum_of_pauses() == Ticks(3) - Ticks(0), "Incorrect"); |
aoqi@0 | 244 | assert(time_partitions.longest_pause() == Ticks(3) - Ticks(0), "Incorrect"); |
aoqi@0 | 245 | |
aoqi@0 | 246 | assert(!iter.has_next(), "Too many elements"); |
aoqi@0 | 247 | } |
aoqi@0 | 248 | |
aoqi@0 | 249 | static void max_nested_pause_phases() { |
aoqi@0 | 250 | TimePartitions time_partitions; |
aoqi@0 | 251 | time_partitions.report_gc_phase_start("PausePhase", 2); |
aoqi@0 | 252 | time_partitions.report_gc_phase_start("SubPhase1", 3); |
aoqi@0 | 253 | time_partitions.report_gc_phase_start("SubPhase2", 4); |
aoqi@0 | 254 | time_partitions.report_gc_phase_start("SubPhase3", 5); |
aoqi@0 | 255 | time_partitions.report_gc_phase_end(6); |
aoqi@0 | 256 | time_partitions.report_gc_phase_end(7); |
aoqi@0 | 257 | time_partitions.report_gc_phase_end(8); |
aoqi@0 | 258 | time_partitions.report_gc_phase_end(9); |
aoqi@0 | 259 | |
aoqi@0 | 260 | TimePartitionPhasesIterator iter(&time_partitions); |
aoqi@0 | 261 | |
aoqi@0 | 262 | validate_pause_phase(iter.next(), 0, "PausePhase", 2, 9); |
aoqi@0 | 263 | validate_pause_phase(iter.next(), 1, "SubPhase1", 3, 8); |
aoqi@0 | 264 | validate_pause_phase(iter.next(), 2, "SubPhase2", 4, 7); |
aoqi@0 | 265 | validate_pause_phase(iter.next(), 3, "SubPhase3", 5, 6); |
aoqi@0 | 266 | |
aoqi@0 | 267 | assert(time_partitions.sum_of_pauses() == Ticks(7) - Ticks(0), "Incorrect"); |
aoqi@0 | 268 | assert(time_partitions.longest_pause() == Ticks(7) - Ticks(0), "Incorrect"); |
aoqi@0 | 269 | |
aoqi@0 | 270 | assert(!iter.has_next(), "Too many elements"); |
aoqi@0 | 271 | } |
aoqi@0 | 272 | |
aoqi@0 | 273 | static void many_sub_pause_phases() { |
aoqi@0 | 274 | TimePartitions time_partitions; |
aoqi@0 | 275 | time_partitions.report_gc_phase_start("PausePhase", 2); |
aoqi@0 | 276 | |
aoqi@0 | 277 | time_partitions.report_gc_phase_start("SubPhase1", 3); |
aoqi@0 | 278 | time_partitions.report_gc_phase_end(4); |
aoqi@0 | 279 | time_partitions.report_gc_phase_start("SubPhase2", 5); |
aoqi@0 | 280 | time_partitions.report_gc_phase_end(6); |
aoqi@0 | 281 | time_partitions.report_gc_phase_start("SubPhase3", 7); |
aoqi@0 | 282 | time_partitions.report_gc_phase_end(8); |
aoqi@0 | 283 | time_partitions.report_gc_phase_start("SubPhase4", 9); |
aoqi@0 | 284 | time_partitions.report_gc_phase_end(10); |
aoqi@0 | 285 | |
aoqi@0 | 286 | time_partitions.report_gc_phase_end(11); |
aoqi@0 | 287 | |
aoqi@0 | 288 | TimePartitionPhasesIterator iter(&time_partitions); |
aoqi@0 | 289 | |
aoqi@0 | 290 | validate_pause_phase(iter.next(), 0, "PausePhase", 2, 11); |
aoqi@0 | 291 | validate_pause_phase(iter.next(), 1, "SubPhase1", 3, 4); |
aoqi@0 | 292 | validate_pause_phase(iter.next(), 1, "SubPhase2", 5, 6); |
aoqi@0 | 293 | validate_pause_phase(iter.next(), 1, "SubPhase3", 7, 8); |
aoqi@0 | 294 | validate_pause_phase(iter.next(), 1, "SubPhase4", 9, 10); |
aoqi@0 | 295 | |
aoqi@0 | 296 | assert(time_partitions.sum_of_pauses() == Ticks(9) - Ticks(0), "Incorrect"); |
aoqi@0 | 297 | assert(time_partitions.longest_pause() == Ticks(9) - Ticks(0), "Incorrect"); |
aoqi@0 | 298 | |
aoqi@0 | 299 | assert(!iter.has_next(), "Too many elements"); |
aoqi@0 | 300 | } |
aoqi@0 | 301 | |
aoqi@0 | 302 | static void many_sub_pause_phases2() { |
aoqi@0 | 303 | TimePartitions time_partitions; |
aoqi@0 | 304 | time_partitions.report_gc_phase_start("PausePhase", 2); |
aoqi@0 | 305 | |
aoqi@0 | 306 | time_partitions.report_gc_phase_start("SubPhase1", 3); |
aoqi@0 | 307 | time_partitions.report_gc_phase_start("SubPhase11", 4); |
aoqi@0 | 308 | time_partitions.report_gc_phase_end(5); |
aoqi@0 | 309 | time_partitions.report_gc_phase_start("SubPhase12", 6); |
aoqi@0 | 310 | time_partitions.report_gc_phase_end(7); |
aoqi@0 | 311 | time_partitions.report_gc_phase_end(8); |
aoqi@0 | 312 | time_partitions.report_gc_phase_start("SubPhase2", 9); |
aoqi@0 | 313 | time_partitions.report_gc_phase_start("SubPhase21", 10); |
aoqi@0 | 314 | time_partitions.report_gc_phase_end(11); |
aoqi@0 | 315 | time_partitions.report_gc_phase_start("SubPhase22", 12); |
aoqi@0 | 316 | time_partitions.report_gc_phase_end(13); |
aoqi@0 | 317 | time_partitions.report_gc_phase_end(14); |
aoqi@0 | 318 | time_partitions.report_gc_phase_start("SubPhase3", 15); |
aoqi@0 | 319 | time_partitions.report_gc_phase_end(16); |
aoqi@0 | 320 | |
aoqi@0 | 321 | time_partitions.report_gc_phase_end(17); |
aoqi@0 | 322 | |
aoqi@0 | 323 | TimePartitionPhasesIterator iter(&time_partitions); |
aoqi@0 | 324 | |
aoqi@0 | 325 | validate_pause_phase(iter.next(), 0, "PausePhase", 2, 17); |
aoqi@0 | 326 | validate_pause_phase(iter.next(), 1, "SubPhase1", 3, 8); |
aoqi@0 | 327 | validate_pause_phase(iter.next(), 2, "SubPhase11", 4, 5); |
aoqi@0 | 328 | validate_pause_phase(iter.next(), 2, "SubPhase12", 6, 7); |
aoqi@0 | 329 | validate_pause_phase(iter.next(), 1, "SubPhase2", 9, 14); |
aoqi@0 | 330 | validate_pause_phase(iter.next(), 2, "SubPhase21", 10, 11); |
aoqi@0 | 331 | validate_pause_phase(iter.next(), 2, "SubPhase22", 12, 13); |
aoqi@0 | 332 | validate_pause_phase(iter.next(), 1, "SubPhase3", 15, 16); |
aoqi@0 | 333 | |
aoqi@0 | 334 | assert(time_partitions.sum_of_pauses() == Ticks(15) - Ticks(0), "Incorrect"); |
aoqi@0 | 335 | assert(time_partitions.longest_pause() == Ticks(15) - Ticks(0), "Incorrect"); |
aoqi@0 | 336 | |
aoqi@0 | 337 | assert(!iter.has_next(), "Too many elements"); |
aoqi@0 | 338 | } |
aoqi@0 | 339 | }; |
aoqi@0 | 340 | |
aoqi@0 | 341 | class GCTimerTest { |
aoqi@0 | 342 | public: |
aoqi@0 | 343 | static void all() { |
aoqi@0 | 344 | gc_start(); |
aoqi@0 | 345 | gc_end(); |
aoqi@0 | 346 | } |
aoqi@0 | 347 | |
aoqi@0 | 348 | static void gc_start() { |
aoqi@0 | 349 | GCTimer gc_timer; |
aoqi@0 | 350 | gc_timer.register_gc_start(1); |
aoqi@0 | 351 | |
aoqi@0 | 352 | assert(gc_timer.gc_start() == 1, "Incorrect"); |
aoqi@0 | 353 | } |
aoqi@0 | 354 | |
aoqi@0 | 355 | static void gc_end() { |
aoqi@0 | 356 | GCTimer gc_timer; |
aoqi@0 | 357 | gc_timer.register_gc_start(1); |
aoqi@0 | 358 | gc_timer.register_gc_end(2); |
aoqi@0 | 359 | |
aoqi@0 | 360 | assert(gc_timer.gc_end() == 2, "Incorrect"); |
aoqi@0 | 361 | } |
aoqi@0 | 362 | }; |
aoqi@0 | 363 | |
aoqi@0 | 364 | void GCTimerAllTest::all() { |
aoqi@0 | 365 | GCTimerTest::all(); |
aoqi@0 | 366 | TimePartitionPhasesIteratorTest::all(); |
aoqi@0 | 367 | } |
aoqi@0 | 368 | |
aoqi@0 | 369 | #endif |