Path: blob/master/test/hotspot/jtreg/serviceability/sa/ClhsdbCDSCore.java
41152 views
/*1* Copyright (c) 2018, 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 8174994 820061326* @summary Test the clhsdb commands 'printmdo', 'printall', 'jstack' on a CDS enabled corefile.27* @requires vm.cds28* @requires vm.hasSA29* @requires vm.flavor == "server"30* @library /test/lib31* @modules java.base/jdk.internal.misc32* @run driver/timeout=2400 ClhsdbCDSCore33*/3435import java.io.File;36import java.io.IOException;37import java.nio.file.Files;38import java.nio.file.Paths;39import java.util.ArrayList;40import java.util.Arrays;41import java.util.HashMap;42import java.util.List;43import java.util.Map;4445import jdk.internal.misc.Unsafe;4647import jdk.test.lib.Asserts;48import jdk.test.lib.Platform;49import jdk.test.lib.cds.CDSOptions;50import jdk.test.lib.cds.CDSTestUtils;51import jdk.test.lib.process.OutputAnalyzer;52import jdk.test.lib.process.ProcessTools;53import jdk.test.lib.util.CoreUtils;54import jdk.test.lib.Utils;5556import jtreg.SkippedException;5758class CrashApp {59public static void main(String[] args) {60Unsafe.getUnsafe().putInt(0L, 0);61}62}6364public class ClhsdbCDSCore {65private static final String SHARED_ARCHIVE_NAME = "ArchiveForClhsdbCDSCore.jsa";66private static String coreFileName;6768public static void main(String[] args) throws Exception {69System.out.println("Starting ClhsdbCDSCore test");70cleanup();7172try {73CDSOptions opts = (new CDSOptions()).setArchiveName(SHARED_ARCHIVE_NAME);74CDSTestUtils.createArchiveAndCheck(opts);7576String[] jArgs = {77"-Xmx512m",78"-XX:+UnlockDiagnosticVMOptions",79"-XX:SharedArchiveFile=" + SHARED_ARCHIVE_NAME,80"-XX:+CreateCoredumpOnCrash",81"-Xshare:auto",82"-XX:+ProfileInterpreter",83"--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED",84CrashApp.class.getName()85};8687OutputAnalyzer crashOutput;88try {89List<String> options = new ArrayList<>();90options.addAll(Arrays.asList(jArgs));91ProcessBuilder pb = ProcessTools.createTestJvm(options);92// Add "ulimit -c unlimited" if we can since we are generating a core file.93pb = CoreUtils.addCoreUlimitCommand(pb);94crashOutput = ProcessTools.executeProcess(pb);95} catch (Throwable t) {96throw new Error("Can't execute the java cds process.", t);97}9899try {100coreFileName = CoreUtils.getCoreFileLocation(crashOutput.getStdout(), crashOutput.pid());101} catch (Exception e) {102cleanup();103throw e;104}105106ClhsdbLauncher test = new ClhsdbLauncher();107108// Ensure that UseSharedSpaces is turned on.109List<String> cmds = List.of("flags UseSharedSpaces");110111String useSharedSpacesOutput = test.runOnCore(coreFileName, cmds, null, null);112113if (useSharedSpacesOutput == null) {114// Output could be null due to attach permission issues.115cleanup();116throw new SkippedException("Could not determine the UseSharedSpaces value");117}118119if (useSharedSpacesOutput.contains("UseSharedSpaces = false")) {120// CDS archive is not mapped. Skip the rest of the test.121cleanup();122throw new SkippedException("The CDS archive is not mapped");123}124125List testJavaOpts = Arrays.asList(Utils.getTestJavaOpts());126127if (testJavaOpts.contains("-Xcomp") && testJavaOpts.contains("-XX:TieredStopAtLevel=1")) {128// No MDOs are allocated in -XX:TieredStopAtLevel=1 + -Xcomp mode129// The reason is methods being compiled aren't hot enough130// Let's not call printmdo in such scenario131cmds = List.of("printall", "jstack -v");132} else {133cmds = List.of("printmdo -a", "printall", "jstack -v");134}135136Map<String, List<String>> expStrMap = new HashMap<>();137Map<String, List<String>> unExpStrMap = new HashMap<>();138expStrMap.put("printmdo -a", List.of(139"CounterData",140"BranchData"));141unExpStrMap.put("printmdo -a", List.of(142"No suitable match for type of address"));143expStrMap.put("printall", List.of(144"aload_0",145"_nofast_aload_0",146"_nofast_getfield",147"_nofast_putfield",148"Constant Pool of",149"public static void main\\(java.lang.String\\[\\]\\)",150"Bytecode",151"invokevirtual",152"checkcast",153"Exception Table",154"invokedynamic"));155unExpStrMap.put("printall", List.of(156"sun.jvm.hotspot.types.WrongTypeException",157"illegal code",158"Failure occurred at bci",159"No suitable match for type of address"));160expStrMap.put("jstack -v", List.of(161"Common-Cleaner",162"Method*"));163unExpStrMap.put("jstack -v", List.of(164"sun.jvm.hotspot.debugger.UnmappedAddressException"));165test.runOnCore(coreFileName, cmds, expStrMap, unExpStrMap);166} catch (SkippedException e) {167throw e;168} catch (Exception ex) {169throw new RuntimeException("Test ERROR " + ex, ex);170}171cleanup();172System.out.println("Test PASSED");173}174175private static void cleanup() {176remove(SHARED_ARCHIVE_NAME);177}178179private static void remove(String item) {180File toDelete = new File(item);181toDelete.delete();182}183}184185186