< prev index next >

src/hotspot/share/gc/shared/gcTimer.cpp

Print this page
rev 52044 : 8157728: Covert GCTimer_test to GTest
Reviewed-by: duke


 167   assert(index >= 0, "Out of bounds");
 168   assert(index < _phases->length(), "Out of bounds");
 169 
 170   return _phases->adr_at(index);
 171 }
 172 
 173 bool TimePartitions::has_active_phases() {
 174   return _active_phases.count() > 0;
 175 }
 176 
 177 bool TimePartitionPhasesIterator::has_next() {
 178   return _next < _time_partitions->num_phases();
 179 }
 180 
 181 GCPhase* TimePartitionPhasesIterator::next() {
 182   assert(has_next(), "Must have phases left");
 183   return _time_partitions->phase_at(_next++);
 184 }
 185 
 186 
 187 /////////////// Unit tests ///////////////
 188 
 189 #ifndef PRODUCT
 190 
 191 class TimePartitionPhasesIteratorTest {
 192  public:
 193   static void all() {
 194     one_pause();
 195     two_pauses();
 196     one_sub_pause_phase();
 197     many_sub_pause_phases();
 198     many_sub_pause_phases2();
 199     max_nested_pause_phases();
 200     one_concurrent();
 201   }
 202 
 203   static void validate_gc_phase(GCPhase* phase, int level, const char* name, const Ticks& start, const Ticks& end) {
 204     assert(phase->level() == level, "Incorrect level");
 205     assert(strcmp(phase->name(), name) == 0, "Incorrect name");
 206     assert(phase->start() == start, "Incorrect start");
 207     assert(phase->end() == end, "Incorrect end");
 208   }
 209 
 210   static void one_pause() {
 211     TimePartitions time_partitions;
 212     time_partitions.report_gc_phase_start("PausePhase", 2);
 213     time_partitions.report_gc_phase_end(8);
 214 
 215     TimePartitionPhasesIterator iter(&time_partitions);
 216 
 217     validate_gc_phase(iter.next(), 0, "PausePhase", 2, 8);
 218     assert(time_partitions.sum_of_pauses() == Ticks(8) - Ticks(2), "Incorrect");
 219     assert(time_partitions.longest_pause() == Ticks(8) - Ticks(2), "Incorrect");
 220 
 221     assert(!iter.has_next(), "Too many elements");
 222   }
 223 
 224   static void two_pauses() {
 225     TimePartitions time_partitions;
 226     time_partitions.report_gc_phase_start("PausePhase1", 2);
 227     time_partitions.report_gc_phase_end(3);
 228     time_partitions.report_gc_phase_start("PausePhase2", 4);
 229     time_partitions.report_gc_phase_end(6);
 230 
 231     TimePartitionPhasesIterator iter(&time_partitions);
 232 
 233     validate_gc_phase(iter.next(), 0, "PausePhase1", 2, 3);
 234     validate_gc_phase(iter.next(), 0, "PausePhase2", 4, 6);
 235 
 236     assert(time_partitions.sum_of_pauses() == Ticks(3) - Ticks(0), "Incorrect");
 237     assert(time_partitions.longest_pause() == Ticks(2) - Ticks(0), "Incorrect");
 238 
 239     assert(!iter.has_next(), "Too many elements");
 240   }
 241 
 242   static void one_sub_pause_phase() {
 243     TimePartitions time_partitions;
 244     time_partitions.report_gc_phase_start("PausePhase", 2);
 245     time_partitions.report_gc_phase_start("SubPhase", 3);
 246     time_partitions.report_gc_phase_end(4);
 247     time_partitions.report_gc_phase_end(5);
 248 
 249     TimePartitionPhasesIterator iter(&time_partitions);
 250 
 251     validate_gc_phase(iter.next(), 0, "PausePhase", 2, 5);
 252     validate_gc_phase(iter.next(), 1, "SubPhase", 3, 4);
 253 
 254     assert(time_partitions.sum_of_pauses() == Ticks(3) - Ticks(0), "Incorrect");
 255     assert(time_partitions.longest_pause() == Ticks(3) - Ticks(0), "Incorrect");
 256 
 257     assert(!iter.has_next(), "Too many elements");
 258   }
 259 
 260   static void max_nested_pause_phases() {
 261     TimePartitions time_partitions;
 262     time_partitions.report_gc_phase_start("PausePhase", 2);
 263     time_partitions.report_gc_phase_start("SubPhase1", 3);
 264     time_partitions.report_gc_phase_start("SubPhase2", 4);
 265     time_partitions.report_gc_phase_start("SubPhase3", 5);
 266     time_partitions.report_gc_phase_end(6);
 267     time_partitions.report_gc_phase_end(7);
 268     time_partitions.report_gc_phase_end(8);
 269     time_partitions.report_gc_phase_end(9);
 270 
 271     TimePartitionPhasesIterator iter(&time_partitions);
 272 
 273     validate_gc_phase(iter.next(), 0, "PausePhase", 2, 9);
 274     validate_gc_phase(iter.next(), 1, "SubPhase1", 3, 8);
 275     validate_gc_phase(iter.next(), 2, "SubPhase2", 4, 7);
 276     validate_gc_phase(iter.next(), 3, "SubPhase3", 5, 6);
 277 
 278     assert(time_partitions.sum_of_pauses() == Ticks(7) - Ticks(0), "Incorrect");
 279     assert(time_partitions.longest_pause() == Ticks(7) - Ticks(0), "Incorrect");
 280 
 281     assert(!iter.has_next(), "Too many elements");
 282   }
 283 
 284   static void many_sub_pause_phases() {
 285     TimePartitions time_partitions;
 286     time_partitions.report_gc_phase_start("PausePhase", 2);
 287 
 288     time_partitions.report_gc_phase_start("SubPhase1", 3);
 289     time_partitions.report_gc_phase_end(4);
 290     time_partitions.report_gc_phase_start("SubPhase2", 5);
 291     time_partitions.report_gc_phase_end(6);
 292     time_partitions.report_gc_phase_start("SubPhase3", 7);
 293     time_partitions.report_gc_phase_end(8);
 294     time_partitions.report_gc_phase_start("SubPhase4", 9);
 295     time_partitions.report_gc_phase_end(10);
 296 
 297     time_partitions.report_gc_phase_end(11);
 298 
 299     TimePartitionPhasesIterator iter(&time_partitions);
 300 
 301     validate_gc_phase(iter.next(), 0, "PausePhase", 2, 11);
 302     validate_gc_phase(iter.next(), 1, "SubPhase1", 3, 4);
 303     validate_gc_phase(iter.next(), 1, "SubPhase2", 5, 6);
 304     validate_gc_phase(iter.next(), 1, "SubPhase3", 7, 8);
 305     validate_gc_phase(iter.next(), 1, "SubPhase4", 9, 10);
 306 
 307     assert(time_partitions.sum_of_pauses() == Ticks(9) - Ticks(0), "Incorrect");
 308     assert(time_partitions.longest_pause() == Ticks(9) - Ticks(0), "Incorrect");
 309 
 310     assert(!iter.has_next(), "Too many elements");
 311   }
 312 
 313   static void many_sub_pause_phases2() {
 314     TimePartitions time_partitions;
 315     time_partitions.report_gc_phase_start("PausePhase", 2);
 316 
 317     time_partitions.report_gc_phase_start("SubPhase1", 3);
 318     time_partitions.report_gc_phase_start("SubPhase11", 4);
 319     time_partitions.report_gc_phase_end(5);
 320     time_partitions.report_gc_phase_start("SubPhase12", 6);
 321     time_partitions.report_gc_phase_end(7);
 322     time_partitions.report_gc_phase_end(8);
 323     time_partitions.report_gc_phase_start("SubPhase2", 9);
 324     time_partitions.report_gc_phase_start("SubPhase21", 10);
 325     time_partitions.report_gc_phase_end(11);
 326     time_partitions.report_gc_phase_start("SubPhase22", 12);
 327     time_partitions.report_gc_phase_end(13);
 328     time_partitions.report_gc_phase_end(14);
 329     time_partitions.report_gc_phase_start("SubPhase3", 15);
 330     time_partitions.report_gc_phase_end(16);
 331 
 332     time_partitions.report_gc_phase_end(17);
 333 
 334     TimePartitionPhasesIterator iter(&time_partitions);
 335 
 336     validate_gc_phase(iter.next(), 0, "PausePhase", 2, 17);
 337     validate_gc_phase(iter.next(), 1, "SubPhase1", 3, 8);
 338     validate_gc_phase(iter.next(), 2, "SubPhase11", 4, 5);
 339     validate_gc_phase(iter.next(), 2, "SubPhase12", 6, 7);
 340     validate_gc_phase(iter.next(), 1, "SubPhase2", 9, 14);
 341     validate_gc_phase(iter.next(), 2, "SubPhase21", 10, 11);
 342     validate_gc_phase(iter.next(), 2, "SubPhase22", 12, 13);
 343     validate_gc_phase(iter.next(), 1, "SubPhase3", 15, 16);
 344 
 345     assert(time_partitions.sum_of_pauses() == Ticks(15) - Ticks(0), "Incorrect");
 346     assert(time_partitions.longest_pause() == Ticks(15) - Ticks(0), "Incorrect");
 347 
 348     assert(!iter.has_next(), "Too many elements");
 349   }
 350 
 351   static void one_concurrent() {
 352     TimePartitions time_partitions;
 353     time_partitions.report_gc_phase_start("ConcurrentPhase", 2, GCPhase::ConcurrentPhaseType);
 354     time_partitions.report_gc_phase_end(8, GCPhase::ConcurrentPhaseType);
 355 
 356     TimePartitionPhasesIterator iter(&time_partitions);
 357 
 358     validate_gc_phase(iter.next(), 0, "ConcurrentPhase", 2, 8);
 359     // ConcurrentPhaseType should not affect to both 'sum_of_pauses()' and 'longest_pause()'.
 360     assert(time_partitions.sum_of_pauses() == Tickspan(), "Incorrect");
 361     assert(time_partitions.longest_pause() == Tickspan(), "Incorrect");
 362 
 363     assert(!iter.has_next(), "Too many elements");
 364   }
 365 };
 366 
 367 class GCTimerTest {
 368 public:
 369   static void all() {
 370     gc_start();
 371     gc_end();
 372   }
 373 
 374   static void gc_start() {
 375     GCTimer gc_timer;
 376     gc_timer.register_gc_start(1);
 377 
 378     assert(gc_timer.gc_start() == Ticks(1), "Incorrect");
 379   }
 380 
 381   static void gc_end() {
 382     GCTimer gc_timer;
 383     gc_timer.register_gc_start(1);
 384     gc_timer.register_gc_end(2);
 385 
 386     assert(gc_timer.gc_end() == Ticks(2), "Incorrect");
 387   }
 388 };
 389 
 390 void GCTimer_test() {
 391   GCTimerTest::all();
 392   TimePartitionPhasesIteratorTest::all();
 393 }
 394 
 395 #endif


 167   assert(index >= 0, "Out of bounds");
 168   assert(index < _phases->length(), "Out of bounds");
 169 
 170   return _phases->adr_at(index);
 171 }
 172 
 173 bool TimePartitions::has_active_phases() {
 174   return _active_phases.count() > 0;
 175 }
 176 
 177 bool TimePartitionPhasesIterator::has_next() {
 178   return _next < _time_partitions->num_phases();
 179 }
 180 
 181 GCPhase* TimePartitionPhasesIterator::next() {
 182   assert(has_next(), "Must have phases left");
 183   return _time_partitions->phase_at(_next++);
 184 }
 185 
 186 

















































































































































































































< prev index next >