Path: blob/master/test/hotspot/jtreg/serviceability/sa/ClhsdbPrintAs.java
41152 views
/*1* Copyright (c) 2017, 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 819298526* @summary Test the clhsdb 'printas' command27* @requires vm.hasSA28* @library /test/lib29* @run main/othervm ClhsdbPrintAs30*/3132import java.util.HashMap;33import java.util.List;34import java.util.Map;35import java.util.ArrayList;36import jdk.test.lib.apps.LingeredApp;37import jtreg.SkippedException;3839public class ClhsdbPrintAs {4041public static void main(String[] args) throws Exception {42System.out.println("Starting the ClhsdbPrintAs test");4344LingeredApp theApp = null;45try {46ClhsdbLauncher test = new ClhsdbLauncher();47theApp = LingeredApp.startApp();48System.out.println("Started LingeredApp with pid " + theApp.getPid());4950// Run the 'jstack -v' command to get the address of a the Method*51// representing LingeredApp.steadyState52List<String> cmds = List.of("jstack -v");53Map<String, List<String>> expStrMap;5455String jstackOutput = test.run(theApp.getPid(), cmds, null, null);5657String[] snippets = jstackOutput.split("LingeredApp.steadyState");58String addressString = null;5960String[] tokens = snippets[1].split("Method\\*=");61String[] words = tokens[1].split(" ");62addressString = words[0];6364cmds = new ArrayList<String>();65expStrMap = new HashMap<>();6667String cmd = "printas Method " + addressString;68cmds.add(cmd);69expStrMap.put(cmd, List.of70("ConstMethod", "MethodCounters", "Method::_access_flags"));7172// Run the printas Method <addr> command to obtain the address73// of ConstMethod*74String methodDetailsOutput = test.run(theApp.getPid(), cmds, expStrMap, null);75snippets = methodDetailsOutput.split("ConstMethod*");7677tokens = snippets[1].split(" ");78for (String token : tokens) {79if (token.contains("0x")) {80addressString = token.replace("\n", "");81break;82}83}8485cmds = new ArrayList<String>();86expStrMap = new HashMap<>();8788cmd = "printas ConstMethod " + addressString;89cmds.add(cmd);90expStrMap.put(cmd, List.of91("ConstantPool", "_max_locals", "_flags"));9293// Run the printas constMethod <addr> command to obtain the address94// of ConstantPool*95String constMethodDetailsOutput = test.run(theApp.getPid(), cmds, expStrMap, null);96snippets = constMethodDetailsOutput.split("ConstantPool*");9798tokens = snippets[1].split(" ");99for (String token : tokens) {100if (token.contains("0x")) {101addressString = token.replace("\n", "");102break;103}104}105106cmds = new ArrayList<String>();107expStrMap = new HashMap<>();108109cmd = "printas ConstantPool " + addressString;110cmds.add(cmd);111expStrMap.put(cmd, List.of112("ConstantPoolCache", "_pool_holder", "InstanceKlass*"));113test.run(theApp.getPid(), cmds, expStrMap, null);114} catch (SkippedException e) {115throw e;116} catch (Exception ex) {117throw new RuntimeException("Test ERROR " + ex, ex);118} finally {119LingeredApp.stopApp(theApp);120}121System.out.println("Test PASSED");122}123}124125126