Path: blob/master/test/hotspot/jtreg/compiler/rtm/print/TestPrintPreciseRTMLockingStatistics.java
41153 views
/*1* Copyright (c) 2014, 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*/2223/**24* @test25* @bug 803132026* @summary Verify that rtm locking statistics contain proper information27* on overall aborts and locks count and count of aborts of28* different types. Test also verify that VM output does not29* contain rtm locking statistics when it should not.30* @library /test/lib /31* @modules java.base/jdk.internal.misc32* java.management33* @requires vm.rtm.cpu & vm.rtm.compiler34* @build sun.hotspot.WhiteBox35* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox36* @run main/othervm/native -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions37* -XX:+WhiteBoxAPI38* compiler.rtm.print.TestPrintPreciseRTMLockingStatistics39*/404142package compiler.rtm.print;4344import compiler.testlibrary.rtm.AbortProvoker;45import compiler.testlibrary.rtm.AbortType;46import compiler.testlibrary.rtm.RTMLockingStatistics;47import compiler.testlibrary.rtm.RTMTestBase;48import jdk.test.lib.Asserts;49import jdk.test.lib.process.OutputAnalyzer;5051import java.util.Collections;52import java.util.LinkedList;53import java.util.List;5455/**56* Test verifies that VM output does not contain RTM locking statistics when it57* should not (when PrintPreciseRTMLockingStatistics is off) and that with58* -XX:+PrintPreciseRTMLockingStatistics locking statistics contains sane59* total locks and aborts count as well as for specific abort types.60*/61public class TestPrintPreciseRTMLockingStatistics {6263public void runTestCases() throws Throwable {64verifyNoStatistics();65verifyStatistics();66}6768// verify that VM output does not contain69// rtm locking statistics70private void verifyNoStatistics() throws Throwable {71verifyNoStatistics(AbortType.XABORT);7273verifyNoStatistics(AbortType.XABORT,74"-XX:-PrintPreciseRTMLockingStatistics");7576verifyNoStatistics(AbortType.XABORT, "-XX:-UseRTMLocking",77"-XX:+PrintPreciseRTMLockingStatistics");78}7980// verify that rtm locking statistics contain information81// about each type of aborts82private void verifyStatistics() throws Throwable {83verifyAbortsCount(AbortType.XABORT);84verifyAbortsCount(AbortType.MEM_CONFLICT);85verifyAbortsCount(AbortType.BUF_OVERFLOW);86verifyAbortsCount(AbortType.NESTED_ABORT);87}8889private void verifyNoStatistics(AbortType abortProvokerType,90String... vmOpts) throws Throwable {91AbortProvoker provoker = abortProvokerType.provoker();92List<String> finalVMOpts = new LinkedList<>();93Collections.addAll(finalVMOpts, vmOpts);94Collections.addAll(finalVMOpts, AbortProvoker.class.getName(),95abortProvokerType.toString());9697OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest(provoker,98finalVMOpts.toArray(new String[finalVMOpts.size()]));99100outputAnalyzer.shouldHaveExitValue(0);101102List<RTMLockingStatistics> statistics = RTMLockingStatistics.fromString(103outputAnalyzer.getOutput());104105Asserts.assertEQ(statistics.size(), 0, "VM output should not contain "106+ "any RTM locking statistics");107}108109private void verifyAbortsCount(AbortType abortType) throws Throwable {110AbortProvoker provoker = abortType.provoker();111112OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest(113provoker,114"-XX:+PrintPreciseRTMLockingStatistics",115AbortProvoker.class.getName(),116abortType.toString());117118outputAnalyzer.shouldHaveExitValue(0);119120List<RTMLockingStatistics> statistics = RTMLockingStatistics.fromString(121provoker.getMethodWithLockName(),outputAnalyzer.getOutput());122123Asserts.assertGT(statistics.size(), 0, "VM output should contain one "124+ "rtm locking statistics entry for method "125+ provoker.getMethodWithLockName());126127RTMLockingStatistics lock = statistics.get(0);128129Asserts.assertGT(lock.getTotalAborts(), 0L,130"RTM locking statistics should contain non zero total aborts "131+ "count");132133Asserts.assertGT(lock.getAborts(abortType), 0L, String.format(134"RTM locking statistics should contain non zero aborts count "135+ "for abort reason %s", abortType));136}137138public static void main(String args[]) throws Throwable {139new TestPrintPreciseRTMLockingStatistics().runTestCases();140}141}142143144