Path: blob/master/test/hotspot/jtreg/serviceability/sa/TestClassDump.java
41149 views
/*1* Copyright (c) 2017, 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.IOException;24import java.nio.file.Files;25import java.nio.file.Paths;2627import jdk.test.lib.apps.LingeredApp;28import jdk.test.lib.Platform;29import jdk.test.lib.process.OutputAnalyzer;30import jdk.test.lib.process.ProcessTools;31import jdk.test.lib.SA.SATestUtils;3233/**34* @test35* @bug 818498236* @summary Test ClassDump tool37* @requires vm.hasSA38* @library /test/lib39* @run driver TestClassDump40*/4142public class TestClassDump {4344private static void dumpClass(long lingeredAppPid)45throws IOException {4647ProcessBuilder pb;48OutputAnalyzer output;4950pb = ProcessTools.createJavaProcessBuilder(51"-Dsun.jvm.hotspot.tools.jcore.outputDir=jtreg_classes",52"-m", "jdk.hotspot.agent/sun.jvm.hotspot.tools.jcore.ClassDump", String.valueOf(lingeredAppPid));53SATestUtils.addPrivilegesIfNeeded(pb);54output = new OutputAnalyzer(pb.start());55output.shouldHaveExitValue(0);56if (!Files.isDirectory(Paths.get("jtreg_classes"))) {57throw new RuntimeException("jtreg_classes directory not found");58}59if (Files.notExists(Paths.get("jtreg_classes", "java", "lang", "Integer.class"))) {60throw new RuntimeException("jtreg_classes/java/lang/Integer.class not found");61}62if (Files.notExists(Paths.get("jtreg_classes", "jdk", "test", "lib", "apps", "LingeredApp.class"))) {63throw new RuntimeException("jtreg_classes/jdk/test/lib/apps/LingeredApp.class not found");64}65if (Files.notExists(Paths.get("jtreg_classes", "sun", "net", "util", "URLUtil.class"))) {66throw new RuntimeException("jtreg_classes/sun/net/util/URLUtil.class not found");67}6869pb = ProcessTools.createJavaProcessBuilder(70"-Dsun.jvm.hotspot.tools.jcore.outputDir=jtreg_classes2",71"-Dsun.jvm.hotspot.tools.jcore.PackageNameFilter.pkgList=jdk,sun",72"-m", "jdk.hotspot.agent/sun.jvm.hotspot.tools.jcore.ClassDump", String.valueOf(lingeredAppPid));73SATestUtils.addPrivilegesIfNeeded(pb);74output = new OutputAnalyzer(pb.start());75output.shouldHaveExitValue(0);76if (Files.exists(Paths.get("jtreg_classes2", "java", "math", "BigInteger.class"))) {77throw new RuntimeException("jtreg_classes2/java/math/BigInteger.class not expected");78}79if (Files.notExists(Paths.get("jtreg_classes2", "sun", "util", "calendar", "BaseCalendar.class"))) {80throw new RuntimeException("jtreg_classes2/sun/util/calendar/BaseCalendar.class not found");81}82if (Files.notExists(Paths.get("jtreg_classes2", "jdk", "internal", "loader", "BootLoader.class"))) {83throw new RuntimeException("jtreg_classes2/jdk/internal/loader/BootLoader.class not found");84}85}8687public static void main(String[] args) throws Exception {88SATestUtils.skipIfCannotAttach(); // throws SkippedException if attach not expected to work.89LingeredApp theApp = null;90try {91theApp = LingeredApp.startApp();92long pid = theApp.getPid();93System.out.println("Started LingeredApp with pid " + pid);94dumpClass(pid);95} catch (Exception ex) {96throw new RuntimeException("Test ERROR " + ex, ex);97} finally {98LingeredApp.stopApp(theApp);99}100System.out.println("Test PASSED");101}102}103104105