8242165: SA sysprops support fails to dump all system properties
Reviewed-by: sspitsyn, ysuenaga
This commit is contained in:
parent
9fb91b4e9c
commit
ccd2a16c58
src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities
test/hotspot/jtreg
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -205,6 +205,7 @@ public class ObjectReader {
|
||||
InstanceKlass ik = (InstanceKlass)oop.getKlass();
|
||||
OopField keyField = (OopField)ik.findField("key", "Ljava/lang/Object;");
|
||||
OopField valueField = (OopField)ik.findField("val", "Ljava/lang/Object;");
|
||||
OopField nextField = (OopField)ik.findField("next", "Ljava/util/concurrent/ConcurrentHashMap$Node;");
|
||||
|
||||
try {
|
||||
p.setProperty((String)readObject(keyField.getValue(oop)),
|
||||
@ -214,6 +215,11 @@ public class ObjectReader {
|
||||
debugPrintStackTrace(ce);
|
||||
}
|
||||
}
|
||||
// If this hashmap table Node is chained, then follow the chain to the next Node.
|
||||
Oop chainedOop = nextField.getValue(oop);
|
||||
if (chainedOop != null) {
|
||||
setPropertiesEntry(p, chainedOop);
|
||||
}
|
||||
}
|
||||
|
||||
protected Object getHashtable(Instance oop) {
|
||||
|
@ -56,4 +56,5 @@ serviceability/sa/TestJhsdbJstackLock.java 8220624 generic-
|
||||
serviceability/sa/TestJhsdbJstackMixed.java 8220624 generic-all
|
||||
serviceability/sa/TestJmapCore.java 8220624 generic-all
|
||||
serviceability/sa/TestJmapCoreMetaspace.java 8220624 generic-all
|
||||
serviceability/sa/TestSysProps.java 8220624 generic-all
|
||||
serviceability/sa/sadebugd/DebugdConnectTest.java 8220624 generic-all
|
||||
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import jdk.test.lib.apps.LingeredApp;
|
||||
|
||||
public class LingeredAppSysProps extends LingeredApp {
|
||||
public static void main(String args[]) {
|
||||
// Print all the system properties first.
|
||||
System.getProperties().list(System.out);
|
||||
|
||||
LingeredApp.main(args);
|
||||
}
|
||||
}
|
185
test/hotspot/jtreg/serviceability/sa/TestSysProps.java
Normal file
185
test/hotspot/jtreg/serviceability/sa/TestSysProps.java
Normal file
@ -0,0 +1,185 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import jdk.test.lib.apps.LingeredApp;
|
||||
import jdk.test.lib.JDKToolLauncher;
|
||||
import jdk.test.lib.Platform;
|
||||
import jdk.test.lib.process.OutputAnalyzer;
|
||||
import jdk.test.lib.process.ProcessTools;
|
||||
import jdk.test.lib.SA.SATestUtils;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8242165
|
||||
* @summary Test "jhsdb jinfo --sysprops" and "jinfo -sysprops" commands
|
||||
* @requires vm.hasSA
|
||||
* @library /test/lib
|
||||
* @run main/othervm TestSysProps
|
||||
*/
|
||||
|
||||
public class TestSysProps {
|
||||
|
||||
public static void main (String... args) throws Exception {
|
||||
SATestUtils.skipIfCannotAttach(); // throws SkippedException if attach not expected to work.
|
||||
LingeredAppSysProps app = null;
|
||||
|
||||
try {
|
||||
app = new LingeredAppSysProps();
|
||||
LingeredApp.startApp(app);
|
||||
System.out.println("Started LingeredAppSysProps with pid " + app.getPid());
|
||||
|
||||
// First get properties using the SA version of jinfo
|
||||
|
||||
JDKToolLauncher jhsdbLauncher = JDKToolLauncher.createUsingTestJDK("jhsdb");
|
||||
jhsdbLauncher.addToolArg("jinfo");
|
||||
jhsdbLauncher.addToolArg("--sysprops");
|
||||
jhsdbLauncher.addToolArg("--pid");
|
||||
jhsdbLauncher.addToolArg(Long.toString(app.getPid()));
|
||||
|
||||
ProcessBuilder jhsdbPb = SATestUtils.createProcessBuilder(jhsdbLauncher);
|
||||
System.out.println("> " + ProcessTools.getCommandLine(jhsdbPb));
|
||||
Process jhsdb = jhsdbPb.start();
|
||||
OutputAnalyzer jhsdbOut = new OutputAnalyzer(jhsdb);
|
||||
|
||||
jhsdb.waitFor();
|
||||
|
||||
System.out.println(jhsdbOut.getStdout());
|
||||
System.err.println(jhsdbOut.getStderr());
|
||||
|
||||
jhsdbOut.shouldMatch("Debugger attached successfully.");
|
||||
|
||||
// Now get properties using the Attach API version of jinfo
|
||||
|
||||
JDKToolLauncher jinfoLauncher = JDKToolLauncher.createUsingTestJDK("jinfo");
|
||||
jinfoLauncher.addToolArg("-sysprops");
|
||||
jinfoLauncher.addToolArg(Long.toString(app.getPid()));
|
||||
|
||||
List<String> cmdStringList = Arrays.asList(jinfoLauncher.getCommand());
|
||||
ProcessBuilder jinfoPb = new ProcessBuilder(cmdStringList);
|
||||
System.out.println("> " + ProcessTools.getCommandLine(jinfoPb));
|
||||
Process jinfo = jinfoPb.start();
|
||||
OutputAnalyzer jinfoOut = new OutputAnalyzer(jinfo);
|
||||
|
||||
jinfo.waitFor();
|
||||
|
||||
System.out.println(jinfoOut.getStdout());
|
||||
System.err.println(jinfoOut.getStderr());
|
||||
|
||||
jinfoOut.shouldMatch("Java System Properties:");
|
||||
|
||||
// Get the output from LingeredAppSysProps, which has printed all the
|
||||
// system properties from java.
|
||||
|
||||
app.stopApp();
|
||||
System.out.println("LingeredAppSysProps output:");
|
||||
System.out.println(app.getOutput().getStdout());
|
||||
System.err.println(app.getOutput().getStderr());
|
||||
OutputAnalyzer appOut = new OutputAnalyzer(app.getOutput().getStdout());
|
||||
appOut.shouldMatch("-- listing properties --");
|
||||
|
||||
// Now make sure the above 3 outputs all contain the same list of properties.
|
||||
// We don't compare the property values since sometimes they get truncated
|
||||
// in one list but not the other, and also special characters are not always
|
||||
// handled the same.
|
||||
|
||||
String[] jhsdbLines = jhsdbOut.getStdout().split("\\R");
|
||||
String[] jinfoLines = jinfoOut.getStdout().split("\\R");
|
||||
String[] appLines = app.getOutput().getStdout().split("\\R");
|
||||
int numAppProps = 0;
|
||||
for (String appProp : appLines) {
|
||||
boolean found;
|
||||
|
||||
// Find the next property in the app output
|
||||
int idx = appProp.indexOf("=");
|
||||
if (idx == -1) continue; // This line does not contain a property
|
||||
String propname = appProp.substring(0, idx);
|
||||
System.out.println("Found prop " + propname);
|
||||
numAppProps++;
|
||||
|
||||
// Find the same property in "jhsdb jinfo" output
|
||||
found = false;
|
||||
for (String jhsdbProp : jhsdbLines) {
|
||||
if (appProp.startsWith(jhsdbProp)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
throw new RuntimeException("Could not find property in jhsdb jinfo output: " + propname);
|
||||
}
|
||||
|
||||
// Find the same property in "jinfo" output
|
||||
found = false;
|
||||
for (String jinfoProp : jinfoLines) {
|
||||
if (jinfoProp.startsWith(propname)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
throw new RuntimeException("Could not find property in jinfo output: " + propname);
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure we found a reasonable number of properties in the app output. It should
|
||||
// be close to 44, but the spec only mandates 29, so this is what we check for. The
|
||||
// main reason for this check is just to make sure something didn't go drastically
|
||||
// wrong, resulting in no properties in the app output, meaning that no comparison
|
||||
// was actually done with the other sets of output.
|
||||
System.out.println(numAppProps + " properties found.");
|
||||
if (numAppProps < 29) {
|
||||
throw new RuntimeException("Did not find at least 29 properties: " + numAppProps);
|
||||
}
|
||||
|
||||
// Make sure jhsdb list has the same number of properties.
|
||||
int numJhsdbProps = 0;
|
||||
for (String jhsdbProp : jhsdbLines) {
|
||||
if (jhsdbProp.indexOf("=") != -1) {
|
||||
numJhsdbProps++;
|
||||
}
|
||||
}
|
||||
if (numJhsdbProps != numAppProps) {
|
||||
throw new RuntimeException("Wrong number of jhsdb jinfo properties: " + numJhsdbProps);
|
||||
}
|
||||
|
||||
// Make sure jinfo list has the same number of properties.
|
||||
int numJinfoProps = 0;
|
||||
for (String jinfoProp : jhsdbLines) {
|
||||
if (jinfoProp.indexOf("=") != -1) {
|
||||
numJinfoProps++;
|
||||
}
|
||||
}
|
||||
if (numJinfoProps != numAppProps) {
|
||||
throw new RuntimeException("Wrong number of jinfo properties: " + numJhsdbProps);
|
||||
}
|
||||
|
||||
System.out.println("Test Completed");
|
||||
} finally {
|
||||
LingeredApp.stopApp(app);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user