Path: blob/master/test/hotspot/jtreg/serviceability/sa/ClhsdbSymbol.java
41152 views
/*1* Copyright (c) 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*/2223import jdk.test.lib.apps.LingeredApp;24import jtreg.SkippedException;2526import java.util.HashMap;27import java.util.List;28import java.util.Map;2930/**31* @test32* @bug 826109533* @summary Test the clhsdb 'symbol' command on live process34* @requires vm.hasSA35* @library /test/lib36* @run main/othervm ClhsdbSymbol37*/3839public class ClhsdbSymbol {4041public static void main(String[] args) throws Exception {42System.out.println("Starting the ClhsdbSymbol test");43LingeredApp theApp = null;4445try {46List<String> cmds = null;47String cmdStr = null;48Map<String, List<String>> expStrMap = null;49ClhsdbLauncher test = new ClhsdbLauncher();50theApp = LingeredApp.startApp();51System.out.println("Started LingeredApp with pid " + theApp.getPid());5253// Use command "class java.lang.Thread" to get the address of the InstanceKlass for java.lang.Thread54cmdStr = "class java.lang.Thread";55cmds = List.of(cmdStr);56expStrMap = new HashMap<>();57expStrMap.put(cmdStr, List.of("java/lang/Thread"));58String classOutput = test.run(theApp.getPid(), cmds, expStrMap, null);5960// Extract the thread InstanceKlass address from the output, which looks similar to the following:61// java/lang/Thread @0x000000080001d94062String threadAddress = classOutput.lines()63.filter(part -> part.startsWith("java/lang/Thread"))64.map(part -> part.split(" @"))65.findFirst()66.map(addresses -> addresses[1])67.orElseThrow(() -> new RuntimeException(68"Cannot find address of the InstanceKlass for java.lang.Thread in output"));697071// Use "inspect" on the thread address we extracted in the previous step72cmdStr = "inspect " + threadAddress;73cmds = List.of(cmdStr);74expStrMap = new HashMap<>();75expStrMap.put(cmdStr, List.of("Symbol"));76String inspectOutput = test.run(theApp.getPid(), cmds, expStrMap, null);7778// The inspect command output will have one line of output that looks like the following.79// Symbol* Klass::_name: Symbol @ 0x000000080047112080// Extract the Symbol address from it.81String symbolAddress = inspectOutput.lines()82.filter(part -> part.startsWith("Symbol"))83.map(part -> part.split("@ "))84.findFirst().map(symbolParts -> symbolParts[1])85.orElseThrow(() -> new RuntimeException("Cannot find address with Symbol instance"));8687// Run "symbol" command on the Symbol instance address extracted in the previous step.88// It should produce the symbol for java/lang/Thread.89cmdStr = "symbol " + symbolAddress;90cmds = List.of(cmdStr);91expStrMap = new HashMap<>();92expStrMap.put(cmdStr, List.of("#java/lang/Thread"));93test.run(theApp.getPid(), cmds, expStrMap, null);94} catch (SkippedException se) {95throw se;96} catch (Exception ex) {97throw new RuntimeException("Test ERROR " + ex, ex);98} finally {99LingeredApp.stopApp(theApp);100}101System.out.println("Test PASSED");102}103}104105106