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 8174994 27 * @summary Test the clhsdb commands 'jstack', 'printall' with CDS enabled 28 * @requires vm.cds 29 * @library /test/lib 30 * @run main/othervm/timeout=2400 -Xmx1g ClhsdbCDSJstackPrintAll 31 */ 32 33 import java.util.List; 34 import java.util.Arrays; 35 import java.util.Map; 36 import java.util.HashMap; 37 import jdk.test.lib.cds.CDSTestUtils; 38 import jdk.test.lib.cds.CDSOptions; 39 import jdk.test.lib.apps.LingeredApp; 40 41 public class ClhsdbCDSJstackPrintAll { 42 43 public static void main(String[] args) throws Exception { 44 System.out.println("Starting ClhsdbCDSJstackPrintAll test"); 45 String sharedArchiveName = "ArchiveForClhsdbJstackPrintAll.jsa"; 46 LingeredApp theApp = null; 47 48 try { 49 CDSOptions opts = (new CDSOptions()).setArchiveName(sharedArchiveName); 50 CDSTestUtils.createArchiveAndCheck(opts); 51 52 ClhsdbLauncher test = new ClhsdbLauncher(); 53 List<String> vmArgs = Arrays.asList( 54 "-XX:+UnlockDiagnosticVMOptions", 55 "-XX:SharedArchiveFile=" + sharedArchiveName, 56 "-Xshare:auto"); 57 theApp = LingeredApp.startApp(vmArgs); 58 System.out.println("Started LingeredApp with pid " + theApp.getPid()); 59 60 // Ensure that UseSharedSpaces is turned on. 61 List<String> cmds = List.of("flags UseSharedSpaces"); 62 63 String useSharedSpacesOutput = test.run(theApp.getPid(), cmds, 64 null, null); 65 66 if (useSharedSpacesOutput == null) { 67 // Attach permission issues. 68 System.out.println("Could not determine the UseSharedSpaces value - test skipped."); 69 LingeredApp.stopApp(theApp); 70 return; 71 } 72 73 if (useSharedSpacesOutput.contains("true") == false) { 74 // CDS archive is not mapped. Skip the rest of the test. 75 System.out.println("The CDS archive is not mapped - test skipped."); 76 LingeredApp.stopApp(theApp); 77 return; 78 } 79 80 cmds = List.of("jstack -v", "printall"); 81 82 Map<String, List<String>> expStrMap = new HashMap<>(); 83 Map<String, List<String>> unExpStrMap = new HashMap<>(); 84 expStrMap.put("jstack -v", List.of( 85 "No deadlocks found", 86 "Common-Cleaner", 87 "Signal Dispatcher", 88 "Method*", 89 "LingeredApp.main")); 90 unExpStrMap.put("jstack -v", List.of( 91 "sun.jvm.hotspot.types.WrongTypeException", 92 "No suitable match for type of address")); 93 expStrMap.put("printall", List.of( 94 "aload_0", 95 "Constant Pool of", 96 "public static void main(java.lang.String[])", 97 "Bytecode", 98 "invokevirtual", 99 "checkcast", 100 "Exception Table", 101 "invokedynamic")); 102 unExpStrMap.put("printall", List.of( 103 "No suitable match for type of address")); 104 test.run(theApp.getPid(), cmds, expStrMap, unExpStrMap); 105 } catch (Exception ex) { 106 throw new RuntimeException("Test ERROR " + ex, ex); 107 } finally { 108 LingeredApp.stopApp(theApp); 109 } 110 System.out.println("Test PASSED"); 111 } 112 }