Path: blob/master/test/hotspot/gtest/gc/shared/test_gcTimer.cpp
41149 views
/*1* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223#include "precompiled.hpp"24#include "gc/shared/gcTimer.hpp"25#include "utilities/ticks.hpp"26#include "unittest.hpp"2728class GCTimerTest {29public:30static void register_gc_start(GCTimer* const timer, jlong ticks) {31timer->register_gc_start(Ticks(ticks));32}33static void register_gc_end(GCTimer* const timer, jlong ticks) {34timer->register_gc_end(Ticks(ticks));35}36static void register_gc_pause_start(GCTimer* const timer, jlong ticks) {37timer->register_gc_pause_start("pause", Ticks(ticks));38}39static void register_gc_pause_end(GCTimer* const timer, jlong ticks) {40timer->register_gc_pause_end(Ticks(ticks));41}42static void register_gc_concurrent_start(ConcurrentGCTimer* const timer, jlong ticks) {43timer->register_gc_concurrent_start("concurrent", Ticks(ticks));44}45static void register_gc_concurrent_end(ConcurrentGCTimer* const timer, jlong ticks) {46timer->register_gc_concurrent_end(Ticks(ticks));47}4849static Tickspan duration(jlong ticks) { return Ticks(ticks) - Ticks(0); }50};5152static Tickspan duration(jlong ticks) { return GCTimerTest::duration(ticks); }5354TEST(GCTimer, start) {55GCTimer gc_timer;56GCTimerTest::register_gc_start(&gc_timer, 1);5758EXPECT_EQ(1, gc_timer.gc_start().value());59}6061TEST(GCTimer, end) {62GCTimer gc_timer;6364GCTimerTest::register_gc_start(&gc_timer, 1);65GCTimerTest::register_gc_end(&gc_timer, 2);6667EXPECT_EQ(2, gc_timer.gc_end().value());68}6970TEST(GCTimer, pause) {71GCTimer gc_timer;7273GCTimerTest::register_gc_start(&gc_timer, 1);74GCTimerTest::register_gc_pause_start(&gc_timer, 2);75GCTimerTest::register_gc_pause_end(&gc_timer, 4);76GCTimerTest::register_gc_end(&gc_timer, 5);7778TimePartitions* partitions = gc_timer.time_partitions();79EXPECT_EQ(1, partitions->num_phases());80EXPECT_EQ(duration(2), partitions->sum_of_pauses());8182EXPECT_EQ(5, gc_timer.gc_end().value());83}8485TEST(ConcurrentGCTimer, pause) {86ConcurrentGCTimer gc_timer;8788GCTimerTest::register_gc_start(&gc_timer, 1);89GCTimerTest::register_gc_pause_start(&gc_timer, 2);90GCTimerTest::register_gc_pause_end(&gc_timer, 4);91GCTimerTest::register_gc_end(&gc_timer, 7);9293TimePartitions* partitions = gc_timer.time_partitions();94EXPECT_EQ(1, partitions->num_phases());95EXPECT_EQ(duration(2), partitions->sum_of_pauses());9697EXPECT_EQ(7, gc_timer.gc_end().value());98}99100TEST(ConcurrentGCTimer, concurrent) {101ConcurrentGCTimer gc_timer;102103GCTimerTest::register_gc_start(&gc_timer, 1);104GCTimerTest::register_gc_concurrent_start(&gc_timer, 2);105GCTimerTest::register_gc_concurrent_end(&gc_timer, 4);106GCTimerTest::register_gc_end(&gc_timer, 5);107108TimePartitions* partitions = gc_timer.time_partitions();109EXPECT_EQ(1, partitions->num_phases());110EXPECT_EQ(duration(0), partitions->sum_of_pauses());111112EXPECT_EQ(5, gc_timer.gc_end().value());113}114115class TimePartitionsTest {116public:117118static void validate_gc_phase(GCPhase* phase, int level, const char* name, const jlong& start, const jlong& end) {119EXPECT_EQ(level, phase->level());120EXPECT_STREQ(name, phase->name());121EXPECT_EQ(start, phase->start().value());122EXPECT_EQ(end, phase->end().value());123}124125static void validate_pauses(const TimePartitions& time_partitions, const Tickspan& expected_sum_of_pauses, const Tickspan& expected_longest_pause) {126EXPECT_EQ(expected_sum_of_pauses, time_partitions.sum_of_pauses());127EXPECT_EQ(expected_longest_pause, time_partitions.longest_pause());128}129static void validate_pauses(const TimePartitions& time_partitions, const Tickspan& expected_pause) {130validate_pauses(time_partitions, expected_pause, expected_pause);131}132static void validate_pauses(const TimePartitions& time_partitions, jlong end, jlong start) {133validate_pauses(time_partitions, Ticks(end) - Ticks(start));134}135static void validate_pauses(const TimePartitions& time_partitions, jlong all_end, jlong all_start, jlong longest_end, jlong longest_start) {136validate_pauses(time_partitions, Ticks(all_end) - Ticks(all_start), Ticks(longest_end) - Ticks(longest_start));137}138139static void report_gc_phase_start(TimePartitions* const partitions, const char* name, jlong ticks, GCPhase::PhaseType type=GCPhase::PausePhaseType) {140partitions->report_gc_phase_start(name, Ticks(ticks), type);141}142143static void report_gc_phase_end(TimePartitions* const partitions, jlong ticks) {144partitions->report_gc_phase_end(Ticks(ticks));145}146};147148TEST(TimePartitionPhasesIterator, one_pause) {149TimePartitions time_partitions;150TimePartitionsTest::report_gc_phase_start(&time_partitions, "PausePhase", 2);151TimePartitionsTest::report_gc_phase_end(&time_partitions, 8);152153TimePartitionPhasesIterator iter(&time_partitions);154155EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 0, "PausePhase", 2, 8));156157EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_pauses(time_partitions, 8, 2));158159EXPECT_FALSE(iter.has_next()) << "Too many elements";160}161162TEST(TimePartitionPhasesIterator, two_pauses) {163TimePartitions time_partitions;164TimePartitionsTest::report_gc_phase_start(&time_partitions, "PausePhase1", 2);165TimePartitionsTest::report_gc_phase_end(&time_partitions, 3);166TimePartitionsTest::report_gc_phase_start(&time_partitions, "PausePhase2", 4);167TimePartitionsTest::report_gc_phase_end(&time_partitions, 6);168169TimePartitionPhasesIterator iter(&time_partitions);170171EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 0, "PausePhase1", 2, 3));172EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 0, "PausePhase2", 4, 6));173174EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_pauses(time_partitions, 3, 0, 2, 0));175176EXPECT_FALSE(iter.has_next()) << "Too many elements";177}178179TEST(TimePartitionPhasesIterator, one_sub_pause_phase) {180TimePartitions time_partitions;181TimePartitionsTest::report_gc_phase_start(&time_partitions, "PausePhase", 2);182TimePartitionsTest::report_gc_phase_start(&time_partitions, "SubPhase", 3);183TimePartitionsTest::report_gc_phase_end(&time_partitions, 4);184TimePartitionsTest::report_gc_phase_end(&time_partitions, 5);185186TimePartitionPhasesIterator iter(&time_partitions);187188EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 0, "PausePhase", 2, 5));189EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 1, "SubPhase", 3, 4));190191EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_pauses(time_partitions, 3, 0));192193EXPECT_FALSE(iter.has_next()) << "Too many elements";194}195196TEST(TimePartitionPhasesIterator, max_nested_pause_phases) {197TimePartitions time_partitions;198TimePartitionsTest::report_gc_phase_start(&time_partitions, "PausePhase", 2);199TimePartitionsTest::report_gc_phase_start(&time_partitions, "SubPhase1", 3);200TimePartitionsTest::report_gc_phase_start(&time_partitions, "SubPhase2", 4);201TimePartitionsTest::report_gc_phase_start(&time_partitions, "SubPhase3", 5);202TimePartitionsTest::report_gc_phase_end(&time_partitions, 6);203TimePartitionsTest::report_gc_phase_end(&time_partitions, 7);204TimePartitionsTest::report_gc_phase_end(&time_partitions, 8);205TimePartitionsTest::report_gc_phase_end(&time_partitions, 9);206207TimePartitionPhasesIterator iter(&time_partitions);208209EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 0, "PausePhase", 2, 9));210EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 1, "SubPhase1", 3, 8));211EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 2, "SubPhase2", 4, 7));212EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 3, "SubPhase3", 5, 6));213214EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_pauses(time_partitions, 7, 0));215216EXPECT_FALSE(iter.has_next()) << "Too many elements";217}218219TEST(TimePartitionPhasesIterator, many_sub_pause_phases) {220TimePartitions time_partitions;221TimePartitionsTest::report_gc_phase_start(&time_partitions, "PausePhase", 2);222223TimePartitionsTest::report_gc_phase_start(&time_partitions, "SubPhase1", 3);224TimePartitionsTest::report_gc_phase_end(&time_partitions, 4);225TimePartitionsTest::report_gc_phase_start(&time_partitions, "SubPhase2", 5);226TimePartitionsTest::report_gc_phase_end(&time_partitions, 6);227TimePartitionsTest::report_gc_phase_start(&time_partitions, "SubPhase3", 7);228TimePartitionsTest::report_gc_phase_end(&time_partitions, 8);229TimePartitionsTest::report_gc_phase_start(&time_partitions, "SubPhase4", 9);230TimePartitionsTest::report_gc_phase_end(&time_partitions, 10);231232TimePartitionsTest::report_gc_phase_end(&time_partitions, 11);233234TimePartitionPhasesIterator iter(&time_partitions);235236EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 0, "PausePhase", 2, 11));237EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 1, "SubPhase1", 3, 4));238EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 1, "SubPhase2", 5, 6));239EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 1, "SubPhase3", 7, 8));240EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 1, "SubPhase4", 9, 10));241242EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_pauses(time_partitions, 9, 0));243244EXPECT_FALSE(iter.has_next()) << "Too many elements";245}246247TEST(TimePartitionPhasesIterator, many_sub_pause_phases2) {248TimePartitions time_partitions;249TimePartitionsTest::report_gc_phase_start(&time_partitions, "PausePhase", 2);250251TimePartitionsTest::report_gc_phase_start(&time_partitions, "SubPhase1", 3);252TimePartitionsTest::report_gc_phase_start(&time_partitions, "SubPhase11", 4);253TimePartitionsTest::report_gc_phase_end(&time_partitions, 5);254TimePartitionsTest::report_gc_phase_start(&time_partitions, "SubPhase12", 6);255TimePartitionsTest::report_gc_phase_end(&time_partitions, 7);256TimePartitionsTest::report_gc_phase_end(&time_partitions, 8);257258TimePartitionsTest::report_gc_phase_start(&time_partitions, "SubPhase2", 9);259TimePartitionsTest::report_gc_phase_start(&time_partitions, "SubPhase21", 10);260TimePartitionsTest::report_gc_phase_end(&time_partitions, 11);261TimePartitionsTest::report_gc_phase_start(&time_partitions, "SubPhase22", 12);262TimePartitionsTest::report_gc_phase_end(&time_partitions, 13);263TimePartitionsTest::report_gc_phase_end(&time_partitions, 14);264265TimePartitionsTest::report_gc_phase_start(&time_partitions, "SubPhase3", 15);266TimePartitionsTest::report_gc_phase_end(&time_partitions, 16);267268TimePartitionsTest::report_gc_phase_end(&time_partitions, 17);269270TimePartitionPhasesIterator iter(&time_partitions);271272EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 0, "PausePhase", 2, 17));273EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 1, "SubPhase1", 3, 8));274EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 2, "SubPhase11", 4, 5));275EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 2, "SubPhase12", 6, 7));276EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 1, "SubPhase2", 9, 14));277EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 2, "SubPhase21", 10, 11));278EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 2, "SubPhase22", 12, 13));279EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 1, "SubPhase3", 15, 16));280281EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_pauses(time_partitions, 15, 0));282283EXPECT_FALSE(iter.has_next()) << "Too many elements";284}285286TEST(TimePartitionPhasesIterator, one_concurrent) {287TimePartitions time_partitions;288TimePartitionsTest::report_gc_phase_start(&time_partitions, "ConcurrentPhase", 2, GCPhase::ConcurrentPhaseType);289TimePartitionsTest::report_gc_phase_end(&time_partitions, 8);290291TimePartitionPhasesIterator iter(&time_partitions);292293EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 0, "ConcurrentPhase", 2, 8));294// ConcurrentPhaseType should not affect to both 'sum_of_pauses()' and 'longest_pause()'.295EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_pauses(time_partitions, Tickspan()));296297EXPECT_FALSE(iter.has_next()) << "Too many elements";298}299300301