|
| 1 | +/* |
| 2 | + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | + * accompanied this code). |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License version |
| 16 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + * |
| 19 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + */ |
| 23 | + |
| 24 | +/** |
| 25 | + * @test |
| 26 | + * @bug 8204308 |
| 27 | + * @summary Test the jhsdb jmap -clstats command with CDS enabled |
| 28 | + * @requires vm.hasSAandCanAttach & vm.cds |
| 29 | + * @library /test/lib |
| 30 | + * @run main/othervm/timeout=2400 CDSJMapClstats |
| 31 | + */ |
| 32 | + |
| 33 | +import java.util.List; |
| 34 | +import java.util.Arrays; |
| 35 | +import java.util.stream.Collectors; |
| 36 | +import jdk.test.lib.cds.CDSTestUtils; |
| 37 | +import jdk.test.lib.cds.CDSOptions; |
| 38 | +import jdk.test.lib.apps.LingeredApp; |
| 39 | +import jdk.test.lib.process.OutputAnalyzer; |
| 40 | +import jdk.test.lib.process.ProcessTools; |
| 41 | +import jdk.test.lib.JDKToolLauncher; |
| 42 | + |
| 43 | +public class CDSJMapClstats { |
| 44 | + |
| 45 | + private static void runClstats(long lingeredAppPid) throws Exception { |
| 46 | + |
| 47 | + JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb"); |
| 48 | + launcher.addToolArg("jmap"); |
| 49 | + launcher.addToolArg("--clstats"); |
| 50 | + launcher.addToolArg("--pid"); |
| 51 | + launcher.addToolArg(Long.toString(lingeredAppPid)); |
| 52 | + |
| 53 | + ProcessBuilder processBuilder = new ProcessBuilder(); |
| 54 | + processBuilder.command(launcher.getCommand()); |
| 55 | + System.out.println( |
| 56 | + processBuilder.command().stream().collect(Collectors.joining(" "))); |
| 57 | + |
| 58 | + OutputAnalyzer SAOutput = ProcessTools.executeProcess(processBuilder); |
| 59 | + System.out.println(SAOutput.getOutput()); |
| 60 | + SAOutput.shouldHaveExitValue(0); |
| 61 | + SAOutput.shouldContain("BootClassLoader"); |
| 62 | + } |
| 63 | + |
| 64 | + |
| 65 | + public static void main(String[] args) throws Exception { |
| 66 | + System.out.println("Starting CDSJMapClstats test"); |
| 67 | + String sharedArchiveName = "ArchiveForCDSJMapClstats.jsa"; |
| 68 | + LingeredApp theApp = null; |
| 69 | + |
| 70 | + try { |
| 71 | + CDSOptions opts = (new CDSOptions()).setArchiveName(sharedArchiveName); |
| 72 | + CDSTestUtils.createArchiveAndCheck(opts); |
| 73 | + |
| 74 | + List<String> vmArgs = Arrays.asList( |
| 75 | + "-XX:+UnlockDiagnosticVMOptions", |
| 76 | + "-XX:SharedArchiveFile=" + sharedArchiveName, |
| 77 | + "-Xshare:auto"); |
| 78 | + theApp = LingeredApp.startApp(vmArgs); |
| 79 | + System.out.println("Started LingeredApp with pid " + theApp.getPid()); |
| 80 | + runClstats(theApp.getPid()); |
| 81 | + } catch (Exception ex) { |
| 82 | + throw new RuntimeException("Test ERROR " + ex, ex); |
| 83 | + } finally { |
| 84 | + LingeredApp.stopApp(theApp); |
| 85 | + } |
| 86 | + System.out.println("Test PASSED"); |
| 87 | + } |
| 88 | +} |
0 commit comments