Path: blob/master/test/hotspot/jtreg/serviceability/sa/ClhsdbThread.java
41149 views
/*1* Copyright (c) 2018, 2019, 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;26import jdk.test.lib.apps.LingeredApp;27import jtreg.SkippedException;2829/**30* @test31* @bug 819335232* @summary Test clhsdb 'thread' and 'threads' commands33* @requires vm.hasSA34* @library /test/lib35* @run main/othervm ClhsdbThread36*/3738public class ClhsdbThread {3940public static void main(String[] args) throws Exception {41System.out.println("Starting ClhsdbThread test");4243LingeredApp theApp = null;44try {45ClhsdbLauncher test = new ClhsdbLauncher();46theApp = LingeredApp.startApp();47System.out.println("Started LingeredApp with pid " + theApp.getPid());4849List<String> cmds = List.of("thread", "thread -a", "threads");5051Map<String, List<String>> expStrMap = new HashMap<>();52// Check for the presence of the usage string53expStrMap.put("thread", List.of( "Usage: thread \\{ \\-a \\| id \\}"));54expStrMap.put("thread -a", List.of(55"State: BLOCKED",56"Stack in use by Java",57"Base of Stack",58"Last_Java_SP:",59"Address"));60expStrMap.put("threads", List.of(61"Finalizer",62"Signal Dispatcher",63"Common-Cleaner",64"Stack in use by Java:",65"State:",66"Base of Stack:",67"main"));68Map<String, List<String>> unExpStrMap = new HashMap<>();69unExpStrMap.put(70"thread -a",71List.of("Couldn't find thread \\-a"));7273String consolidatedOutput = test.run(74theApp.getPid(),75cmds,76expStrMap,77unExpStrMap);7879// Test the thread <id> command now. Obtain <id> from the80// output of the previous 'threads' command. The word before81// the token 'Finalizer' should denote the thread id of the82// 'Finalizer' thread.8384String[] snippets = consolidatedOutput.split("Finalizer");85String[] wordTokens = snippets[0].split(" ");86String threadIdObtained = wordTokens[wordTokens.length - 1];8788// Weed out newlines and blurb before that.89if (threadIdObtained.contains("\n")) {90String[] threadIdTokens = threadIdObtained.split("\n");91threadIdObtained = threadIdTokens[threadIdTokens.length - 1];92}9394expStrMap = new HashMap<>();95System.out.println("Thread Id obtained is: " + threadIdObtained);9697String cmd = "thread " + threadIdObtained;98expStrMap.put(cmd, List.of(99"Base of Stack:",100"State:",101"Last_Java_SP"));102cmds = List.of(cmd);103test.run(theApp.getPid(), cmds, expStrMap, null);104} catch (SkippedException se) {105throw se;106} catch (Exception ex) {107throw new RuntimeException("Test ERROR " + ex, ex);108} finally {109LingeredApp.stopApp(theApp);110}111System.out.println("Test PASSED");112}113}114115116