Path: blob/master/test/hotspot/jtreg/serviceability/sa/ClhsdbDumpclass.java
41152 views
/*1* Copyright (c) 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*/2223import java.io.File;24import java.util.Arrays;25import java.util.HashMap;26import java.util.List;27import java.util.Map;2829import jdk.test.lib.Utils;30import jdk.test.lib.apps.LingeredApp;31import jdk.test.lib.JDKToolLauncher;32import jdk.test.lib.process.OutputAnalyzer;33import jtreg.SkippedException;3435/**36* @test37* @bug 824099038* @summary Test clhsdb dumpclass command39* @requires vm.hasSA40* @library /test/lib41* @run main/othervm ClhsdbDumpclass42*/4344public class ClhsdbDumpclass {45static final String APP_DOT_CLASSNAME = LingeredApp.class.getName();46static final String APP_SLASH_CLASSNAME = APP_DOT_CLASSNAME.replace('.', '/');4748public static void main(String[] args) throws Exception {49System.out.println("Starting ClhsdbDumpclass test");5051LingeredApp theApp = null;52try {53ClhsdbLauncher test = new ClhsdbLauncher();5455theApp = LingeredApp.startApp();56System.out.println("Started LingeredApp with pid " + theApp.getPid());5758// Run "dumpclass jdk/test/lib/apps/LingeredApp"59String cmd = "dumpclass " + APP_DOT_CLASSNAME;60List<String> cmds = List.of(cmd);61Map<String, List<String>> unExpStrMap = new HashMap<>();62unExpStrMap.put(cmd, List.of("class not found"));63test.run(theApp.getPid(), cmds, null, unExpStrMap);64File classFile = new File(APP_SLASH_CLASSNAME + ".class");65if (!classFile.exists()) {66throw new RuntimeException("FAILED: Cannot find dumped .class file");67}6869// Run javap on the generated class file to make sure it's valid.70JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("javap");71launcher.addVMArgs(Utils.getTestJavaOpts());72launcher.addToolArg(APP_DOT_CLASSNAME);73System.out.println("> javap " + APP_DOT_CLASSNAME);74List<String> cmdStringList = Arrays.asList(launcher.getCommand());75ProcessBuilder pb = new ProcessBuilder(cmdStringList);76Process javap = pb.start();77OutputAnalyzer out = new OutputAnalyzer(javap);78javap.waitFor();79System.out.println(out.getStdout());80System.err.println(out.getStderr());81out.shouldHaveExitValue(0);82out.shouldMatch("public class " + APP_DOT_CLASSNAME);83} catch (SkippedException se) {84throw se;85} catch (Exception ex) {86throw new RuntimeException("Test ERROR " + ex, ex);87} finally {88LingeredApp.stopApp(theApp);89}90System.out.println("Test PASSED");91}92}939495