Path: blob/master/test/hotspot/jtreg/serviceability/sa/CDSJMapClstats.java
41152 views
/*1* Copyright (c) 2018, 2020, 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 820430826* @summary Test the jhsdb jmap -clstats command with CDS enabled27* @requires vm.hasSA & vm.cds28* @library /test/lib29* @run main/othervm/timeout=2400 CDSJMapClstats30*/3132import java.util.stream.Collectors;3334import jdk.test.lib.Utils;35import jdk.test.lib.cds.CDSTestUtils;36import jdk.test.lib.cds.CDSOptions;37import jdk.test.lib.apps.LingeredApp;38import jdk.test.lib.process.OutputAnalyzer;39import jdk.test.lib.process.ProcessTools;40import jdk.test.lib.JDKToolLauncher;41import jdk.test.lib.SA.SATestUtils;4243public class CDSJMapClstats {4445private static void runClstats(long lingeredAppPid) throws Exception {4647JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");48launcher.addVMArgs(Utils.getTestJavaOpts());49launcher.addToolArg("jmap");50launcher.addToolArg("--clstats");51launcher.addToolArg("--pid");52launcher.addToolArg(Long.toString(lingeredAppPid));5354ProcessBuilder processBuilder = SATestUtils.createProcessBuilder(launcher);55System.out.println(56processBuilder.command().stream().collect(Collectors.joining(" ")));5758OutputAnalyzer SAOutput = ProcessTools.executeProcess(processBuilder);59System.out.println(SAOutput.getOutput());60SAOutput.shouldHaveExitValue(0);61SAOutput.shouldContain("BootClassLoader");62}636465public static void main(String[] args) throws Exception {66System.out.println("Starting CDSJMapClstats test");67SATestUtils.skipIfCannotAttach(); // throws SkippedException if attach not expected to work.68String sharedArchiveName = "ArchiveForCDSJMapClstats.jsa";69LingeredApp theApp = null;7071try {72CDSOptions opts = (new CDSOptions()).setArchiveName(sharedArchiveName);73CDSTestUtils.createArchiveAndCheck(opts);7475theApp = LingeredApp.startApp(76"-XX:+UnlockDiagnosticVMOptions",77"-XX:SharedArchiveFile=" + sharedArchiveName,78"-Xshare:auto");79System.out.println("Started LingeredApp with pid " + theApp.getPid());80runClstats(theApp.getPid());81} catch (Exception ex) {82throw new RuntimeException("Test ERROR " + ex, ex);83} finally {84LingeredApp.stopApp(theApp);85}86System.out.println("Test PASSED");87}88}899091