Path: blob/master/test/hotspot/gtest/logging/test_gcTraceTime.cpp
41144 views
/*1* Copyright (c) 2015, 2021, 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*22*/23#include "precompiled.hpp"24#include "jvm.h"25#include "gc/shared/gcTraceTime.inline.hpp"26#include "logTestFixture.hpp"27#include "logTestUtils.inline.hpp"28#include "logging/log.hpp"29#include "runtime/interfaceSupport.inline.hpp"30#include "unittest.hpp"3132class GCTraceTimeTest : public LogTestFixture {33};3435TEST_VM_F(GCTraceTimeTest, full) {36set_log_config(TestLogFileName, "gc=debug,gc+start=debug");3738LogTarget(Debug, gc) gc_debug;39LogTarget(Debug, gc, start) gc_start_debug;4041EXPECT_TRUE(gc_debug.is_enabled());42EXPECT_TRUE(gc_start_debug.is_enabled());4344{45ThreadInVMfromNative tvn(JavaThread::current());46MutexLocker lock(Heap_lock); // Needed to read heap usage47GCTraceTime(Debug, gc) timer("Test GC", NULL, GCCause::_allocation_failure, true);48}4950const char* expected[] = {51"[gc,start", "] Test GC (Allocation Failure)",52"[gc", "] Test GC (Allocation Failure) ", "M) ", "ms",53NULL54};55EXPECT_TRUE(file_contains_substrings_in_order(TestLogFileName, expected));56}5758TEST_VM_F(GCTraceTimeTest, full_multitag) {59set_log_config(TestLogFileName, "gc+ref=debug,gc+ref+start=debug");6061LogTarget(Debug, gc, ref) gc_debug;62LogTarget(Debug, gc, ref, start) gc_start_debug;6364EXPECT_TRUE(gc_debug.is_enabled());65EXPECT_TRUE(gc_start_debug.is_enabled());6667{68ThreadInVMfromNative tvn(JavaThread::current());69MutexLocker lock(Heap_lock); // Needed to read heap usage70GCTraceTime(Debug, gc, ref) timer("Test GC", NULL, GCCause::_allocation_failure, true);71}7273const char* expected[] = {74"[gc,ref,start", "] Test GC (Allocation Failure)",75"[gc,ref", "] Test GC (Allocation Failure) ", "M) ", "ms",76NULL77};78EXPECT_TRUE(file_contains_substrings_in_order(TestLogFileName, expected));79}8081TEST_VM_F(GCTraceTimeTest, no_heap) {82set_log_config(TestLogFileName, "gc=debug,gc+start=debug");8384LogTarget(Debug, gc) gc_debug;85LogTarget(Debug, gc, start) gc_start_debug;8687EXPECT_TRUE(gc_debug.is_enabled());88EXPECT_TRUE(gc_start_debug.is_enabled());8990{91GCTraceTime(Debug, gc) timer("Test GC", NULL, GCCause::_allocation_failure, false);92}9394const char* expected[] = {95// [2.975s][debug][gc,start] Test GC (Allocation Failure)96"[gc,start", "] Test GC (Allocation Failure)",97// [2.975s][debug][gc ] Test GC (Allocation Failure) 0.026ms98"[gc", "] Test GC (Allocation Failure) ", "ms",99NULL100};101EXPECT_TRUE(file_contains_substrings_in_order(TestLogFileName, expected));102103const char* not_expected[] = {104// [2.975s][debug][gc ] Test GC 59M->59M(502M) 0.026ms105"[gc", "] Test GC ", "M) ", "ms",106};107EXPECT_FALSE(file_contains_substrings_in_order(TestLogFileName, not_expected));108}109110TEST_VM_F(GCTraceTimeTest, no_cause) {111set_log_config(TestLogFileName, "gc=debug,gc+start=debug");112113LogTarget(Debug, gc) gc_debug;114LogTarget(Debug, gc, start) gc_start_debug;115116EXPECT_TRUE(gc_debug.is_enabled());117EXPECT_TRUE(gc_start_debug.is_enabled());118119{120ThreadInVMfromNative tvn(JavaThread::current());121MutexLocker lock(Heap_lock); // Needed to read heap usage122GCTraceTime(Debug, gc) timer("Test GC", NULL, GCCause::_no_gc, true);123}124125const char* expected[] = {126// [2.975s][debug][gc,start] Test GC127"[gc,start", "] Test GC",128// [2.975s][debug][gc ] Test GC 59M->59M(502M) 0.026ms129"[gc", "] Test GC ", "M) ", "ms",130NULL131};132EXPECT_TRUE(file_contains_substrings_in_order(TestLogFileName, expected));133}134135TEST_VM_F(GCTraceTimeTest, no_heap_no_cause) {136set_log_config(TestLogFileName, "gc=debug,gc+start=debug");137138LogTarget(Debug, gc) gc_debug;139LogTarget(Debug, gc, start) gc_start_debug;140141EXPECT_TRUE(gc_debug.is_enabled());142EXPECT_TRUE(gc_start_debug.is_enabled());143144{145GCTraceTime(Debug, gc) timer("Test GC", NULL, GCCause::_no_gc, false);146}147148const char* expected[] = {149// [2.975s][debug][gc,start] Test GC150"[gc,start", "] Test GC",151// [2.975s][debug][gc ] Test GC 0.026ms152"[gc", "] Test GC ", "ms",153NULL154};155EXPECT_TRUE(file_contains_substrings_in_order(TestLogFileName, expected));156157const char* not_expected[] = {158// [2.975s][debug][gc ] Test GC 59M->59M(502M) 0.026ms159"[gc", "] Test GC ", "M) ", "ms",160};161EXPECT_FALSE(file_contains_substrings_in_order(TestLogFileName, not_expected));162}163164165