Path: blob/master/test/hotspot/jtreg/serviceability/sa/ClhsdbClasses.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.util.HashMap;24import java.util.List;25import java.util.Map;2627import jdk.test.lib.apps.LingeredApp;28import jtreg.SkippedException;2930/**31* @test32* @bug 824214233* @summary Test clhsdb class and classes commands34* @requires vm.hasSA35* @library /test/lib36* @run main/othervm ClhsdbClasses37*/3839public class ClhsdbClasses {40static final String APP_DOT_CLASSNAME = LingeredApp.class.getName();41static final String APP_SLASH_CLASSNAME = APP_DOT_CLASSNAME.replace('.', '/');4243public static void main(String[] args) throws Exception {44System.out.println("Starting ClhsdbClasses test");4546LingeredApp theApp = null;47try {48ClhsdbLauncher test = new ClhsdbLauncher();49String classCmdOutput;5051theApp = LingeredApp.startApp();52System.out.println("Started LingeredApp with pid " + theApp.getPid());5354// Run "class jdk/test/lib/apps/LingeredApp"55{56String cmd = "class " + APP_SLASH_CLASSNAME;57List<String> cmds = List.of(cmd);58Map<String, List<String>> expStrMap = new HashMap<>();59expStrMap.put(cmd, List.of(APP_SLASH_CLASSNAME + " @0x"));60classCmdOutput = test.run(theApp.getPid(), cmds, expStrMap, null);61}6263// Run "print <addr>" on the address printed above for LingeredApp. Also64// run "classes" command to verify LingeredApp and java.lang.Class are65// in the list of classes. Note we can't do the above "class LingeredApp"66// command as part of this command because then we won't have the address67// for the LingeredApp class, which we need for the print command and also68// to verify it matches the address in the classes commands.69{70String classAddress = classCmdOutput.substring(classCmdOutput.indexOf("@0x")+1);71String[] lines = classAddress.split("\\R");72classAddress = lines[0];73String printCmd = "print " + classAddress;74String classesCmd = "classes";75List<String> cmds = List.of(printCmd, classesCmd);76Map<String, List<String>> expStrMap = new HashMap<>();77expStrMap.put(printCmd,78List.of("public class " + APP_DOT_CLASSNAME + " @" + classAddress));79expStrMap.put(classesCmd, List.of(80APP_SLASH_CLASSNAME + " @" + classAddress, // check for app class at right address81"java/lang/Class @0x", // check for java/lang/Class82"java/lang/Object @0x", // check for java/lang/Object83"java/lang/Cloneable @0x", // check for an interface type84"\\[Ljava/lang/String; @0x", // check for array type85"\\[J @0x", "\\[I @0x", "\\[Z @0x")); // check for array of a few pimitive types86test.run(theApp.getPid(), cmds, expStrMap, null);87}88} catch (SkippedException se) {89throw se;90} catch (Exception ex) {91throw new RuntimeException("Test ERROR " + ex, ex);92} finally {93LingeredApp.stopApp(theApp);94}95System.out.println("Test PASSED");96}97}9899100