2017-12-14 12:49:47 +05:30
|
|
|
/*
|
2020-01-24 10:31:45 +01:00
|
|
|
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
|
2017-12-14 12:49:47 +05:30
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*/
|
|
|
|
|
2018-06-25 23:04:21 +02:00
|
|
|
/**
|
2017-12-14 12:49:47 +05:30
|
|
|
* @test
|
|
|
|
* @bug 8192985
|
|
|
|
* @summary Test the clhsdb 'inspect' command
|
2018-06-25 23:04:21 +02:00
|
|
|
* @requires vm.hasSA
|
2017-12-14 12:49:47 +05:30
|
|
|
* @library /test/lib
|
2019-01-04 13:41:45 +05:30
|
|
|
* @run main/othervm/timeout=480 ClhsdbInspect
|
2017-12-14 12:49:47 +05:30
|
|
|
*/
|
|
|
|
|
2018-08-02 14:40:55 -07:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import jdk.test.lib.apps.LingeredApp;
|
|
|
|
import jtreg.SkippedException;
|
|
|
|
|
2017-12-14 12:49:47 +05:30
|
|
|
public class ClhsdbInspect {
|
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
System.out.println("Starting the ClhsdbInspect test");
|
|
|
|
|
|
|
|
LingeredAppWithLock theApp = null;
|
|
|
|
try {
|
|
|
|
ClhsdbLauncher test = new ClhsdbLauncher();
|
|
|
|
|
|
|
|
theApp = new LingeredAppWithLock();
|
2020-01-24 10:31:45 +01:00
|
|
|
LingeredApp.startApp(theApp);
|
2017-12-14 12:49:47 +05:30
|
|
|
System.out.println("Started LingeredApp with pid " + theApp.getPid());
|
|
|
|
|
2018-02-06 11:43:13 +05:30
|
|
|
// Run the 'jstack -v' command to get the address of a Method*,
|
|
|
|
// the oop address of a java.lang.ref.ReferenceQueue$Lock
|
|
|
|
// and the oop address of a java.lang.Class object
|
2017-12-14 12:49:47 +05:30
|
|
|
List<String> cmds = List.of("jstack -v");
|
|
|
|
|
|
|
|
String jstackOutput = test.run(theApp.getPid(), cmds, null, null);
|
|
|
|
|
|
|
|
Map<String, String> tokensMap = new HashMap<>();
|
2018-02-06 11:43:13 +05:30
|
|
|
tokensMap.put("(a java.lang.Class for LingeredAppWithLock)",
|
2017-12-14 12:49:47 +05:30
|
|
|
"instance of Oop for java/lang/Class");
|
2018-02-06 11:43:13 +05:30
|
|
|
tokensMap.put("Method*=", "Type is Method");
|
|
|
|
tokensMap.put("(a java.lang.ref.ReferenceQueue$Lock)",
|
2019-02-05 00:43:38 +05:30
|
|
|
"instance of Oop for java/lang/ref/ReferenceQueue\\$Lock");
|
2017-12-14 12:49:47 +05:30
|
|
|
|
2018-02-06 11:43:13 +05:30
|
|
|
String[] lines = jstackOutput.split("\\R");
|
|
|
|
|
2017-12-14 12:49:47 +05:30
|
|
|
for (String key: tokensMap.keySet()) {
|
|
|
|
cmds = new ArrayList<String>();
|
|
|
|
Map<String, List<String>> expStrMap = new HashMap<>();
|
|
|
|
|
2018-02-06 11:43:13 +05:30
|
|
|
String addressString = null;
|
|
|
|
for (String line : lines) {
|
|
|
|
if (line.contains(key)) {
|
|
|
|
// Escape the token "Method*=" because the split method uses
|
|
|
|
// a regex, not just a straight String.
|
|
|
|
String escapedKey = key.replace("*","\\*");
|
|
|
|
String[] words = line.split(escapedKey+"|[ ]");
|
|
|
|
for (String word : words) {
|
|
|
|
word = word.replace("<","").replace(">","");
|
|
|
|
if (word.startsWith("0x")) {
|
|
|
|
addressString = word;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (addressString != null)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-12-14 12:49:47 +05:30
|
|
|
|
|
|
|
String cmd = "inspect " + addressString;
|
|
|
|
cmds.add(cmd);
|
|
|
|
expStrMap.put(cmd, List.of(tokensMap.get(key)));
|
|
|
|
test.run(theApp.getPid(), cmds, expStrMap, null);
|
|
|
|
}
|
2018-08-02 14:40:55 -07:00
|
|
|
} catch (SkippedException e) {
|
|
|
|
throw e;
|
2017-12-14 12:49:47 +05:30
|
|
|
} catch (Exception ex) {
|
|
|
|
throw new RuntimeException("Test ERROR " + ex, ex);
|
|
|
|
} finally {
|
|
|
|
LingeredApp.stopApp(theApp);
|
|
|
|
}
|
|
|
|
System.out.println("Test PASSED");
|
|
|
|
}
|
|
|
|
}
|