8263636: Add --disable-registry option to jhsdb debugd
Reviewed-by: cjplummer, kevinw
This commit is contained in:
parent
6d49cc3b65
commit
159f5e1ede
src/jdk.hotspot.agent/share
test/hotspot/jtreg/serviceability/sa/sadebugd
@ -63,12 +63,12 @@ public class SALauncher {
|
||||
// --pid <pid>
|
||||
// --exe <exe>
|
||||
// --core <core>
|
||||
// --connect [<id>@]<host>
|
||||
// --connect [<id>@]<host>[:registryport]
|
||||
System.out.println(" --pid <pid> To attach to and operate on the given live process.");
|
||||
System.out.println(" --core <corefile> To operate on the given core file.");
|
||||
System.out.println(" --exe <executable for corefile>");
|
||||
if (canConnectToRemote) {
|
||||
System.out.println(" --connect [<id>@]<host> To connect to a remote debug server (debugd).");
|
||||
System.out.println(" --connect [<id>@]<host>[:registryport] To connect to a remote debug server (debugd).");
|
||||
}
|
||||
System.out.println();
|
||||
System.out.println(" The --core and --exe options must be set together to give the core");
|
||||
@ -85,8 +85,7 @@ public class SALauncher {
|
||||
System.out.println(" Examples: jhsdb " + mode + " --pid 1234");
|
||||
System.out.println(" or jhsdb " + mode + " --core ./core.1234 --exe ./myexe");
|
||||
if (canConnectToRemote) {
|
||||
System.out.println(" or jhsdb " + mode + " --connect debugserver");
|
||||
System.out.println(" or jhsdb " + mode + " --connect id@debugserver");
|
||||
System.out.println(" or jhsdb " + mode + " --connect id@debugserver:1234");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -100,6 +99,7 @@ public class SALauncher {
|
||||
System.out.println(" --registryport <port> Sets the RMI registry port." +
|
||||
" This option overrides the system property 'sun.jvm.hotspot.rmi.port'. If not specified," +
|
||||
" the system property is used. If the system property is not set, the default port 1099 is used.");
|
||||
System.out.println(" --disable-registry Do not start RMI registry (use already started RMI registry)");
|
||||
System.out.println(" --hostname <hostname> Sets the hostname the RMI connector is bound. The value could" +
|
||||
" be a hostname or an IPv4/IPv6 address. This option overrides the system property" +
|
||||
" 'java.rmi.server.hostname'. If not specified, the system property is used. If the system" +
|
||||
@ -375,6 +375,7 @@ public class SALauncher {
|
||||
"serverid=", "serverid",
|
||||
"rmiport=", "rmiport",
|
||||
"registryport=", "registryport",
|
||||
"disable-registry", "disable-registry",
|
||||
"hostname=", "hostname");
|
||||
|
||||
Map<String, String> argMap = parseOptions(args, longOptsMap);
|
||||
@ -401,6 +402,11 @@ public class SALauncher {
|
||||
System.setProperty("sun.jvm.hotspot.rmi.port", registryPort);
|
||||
}
|
||||
|
||||
// Disable RMI registry if specified
|
||||
if (argMap.containsKey("disable-registry")) {
|
||||
System.setProperty("sun.jvm.hotspot.rmi.startRegistry", "false");
|
||||
}
|
||||
|
||||
// Set RMI connector hostname, if specified
|
||||
if (host != null && !host.trim().isEmpty()) {
|
||||
System.setProperty("java.rmi.server.hostname", host);
|
||||
|
@ -32,11 +32,11 @@ analyze the content of a core dump from a crashed Java Virtual Machine
|
||||
.PP
|
||||
\f[CB]jhsdb\f[R] \f[CB]clhsdb\f[R] [\f[CB]\-\-pid\f[R] \f[I]pid\f[R] |
|
||||
\f[CB]\-\-exe\f[R] \f[I]executable\f[R] \f[CB]\-\-core\f[R] \f[I]coredump\f[R] |
|
||||
\f[CB]\-\-connect\f[R] \f[I][server\-id\@]debugd\-host\f[R]\]
|
||||
\f[CB]\-\-connect\f[R] \f[I][server\-id\@]debugd\-host[:registryport]\f[R]\]
|
||||
.PP
|
||||
\f[CB]jhsdb\f[R] \f[CB]hsdb\f[R] [\f[CB]\-\-pid\f[R] \f[I]pid\f[R] |
|
||||
\f[CB]\-\-exe\f[R] \f[I]executable\f[R] \f[CB]\-\-core\f[R] \f[I]coredump\f[R] |
|
||||
\f[CB]\-\-connect\f[R] \f[I][server\-id\@]debugd\-host\f[R]\]
|
||||
\f[CB]\-\-connect\f[R] \f[I][server\-id\@]debugd\-host[:registryport]\f[R]\]
|
||||
.PP
|
||||
\f[CB]jhsdb\f[R] \f[CB]debugd\f[R] (\f[CB]\-\-pid\f[R] \f[I]pid\f[R] |
|
||||
\f[CB]\-\-exe\f[R] \f[I]executable\f[R] \f[CB]\-\-core\f[R]
|
||||
@ -44,22 +44,22 @@ analyze the content of a core dump from a crashed Java Virtual Machine
|
||||
.PP
|
||||
\f[CB]jhsdb\f[R] \f[CB]jstack\f[R] (\f[CB]\-\-pid\f[R] \f[I]pid\f[R] |
|
||||
\f[CB]\-\-exe\f[R] \f[I]executable\f[R] \f[CB]\-\-core\f[R] \f[I]coredump\f[R]
|
||||
| \f[CB]\-\-connect\f[R] \f[I][server\-id\@]debugd\-host\f[R])
|
||||
| \f[CB]\-\-connect\f[R] \f[I][server\-id\@]debugd\-host[:registryport]\f[R])
|
||||
[\f[I]options\f[R]]
|
||||
.PP
|
||||
\f[CB]jhsdb\f[R] \f[CB]jmap\f[R] (\f[CB]\-\-pid\f[R] \f[I]pid\f[R] |
|
||||
\f[CB]\-\-exe\f[R] \f[I]executable\f[R] \f[CB]\-\-core\f[R] \f[I]coredump\f[R]
|
||||
| \f[CB]\-\-connect\f[R] \f[I][server\-id\@]debugd\-host\f[R])
|
||||
| \f[CB]\-\-connect\f[R] \f[I][server\-id\@]debugd\-host[:registryport]\f[R])
|
||||
[\f[I]options\f[R]]
|
||||
.PP
|
||||
\f[CB]jhsdb\f[R] \f[CB]jinfo\f[R] (\f[CB]\-\-pid\f[R] \f[I]pid\f[R] |
|
||||
\f[CB]\-\-exe\f[R] \f[I]executable\f[R] \f[CB]\-\-core\f[R] \f[I]coredump\f[R]
|
||||
| \f[CB]\-\-connect\f[R] \f[I][server\-id\@]debugd\-host\f[R])
|
||||
| \f[CB]\-\-connect\f[R] \f[I][server\-id\@]debugd\-host[:registryport]\f[R])
|
||||
[\f[I]options\f[R]]
|
||||
.PP
|
||||
\f[CB]jhsdb\f[R] \f[CB]jsnap\f[R] (\f[CB]\-\-pid\f[R] \f[I]pid\f[R] |
|
||||
\f[CB]\-\-exe\f[R] \f[I]executable\f[R] \f[CB]\-\-core\f[R] \f[I]coredump\f[R]
|
||||
| \f[CB]\-\-connect\f[R] \f[I][server\-id\@]debugd\-host\f[R])
|
||||
| \f[CB]\-\-connect\f[R] \f[I][server\-id\@]debugd\-host[:registryport]\f[R])
|
||||
[\f[I]options\f[R]]
|
||||
.TP
|
||||
.B \f[I]pid\f[R]
|
||||
@ -81,7 +81,7 @@ The core file to which the \f[CB]jhsdb\f[R] tool should attach.
|
||||
.RS
|
||||
.RE
|
||||
.TP
|
||||
.B \f[I][server\-id\@]debugd\-host\f[R]
|
||||
.B \f[I][server\-id\@]debugd\-host[:registryport]\f[R]
|
||||
An optional server ID and the address of the remote debug server
|
||||
(debugd).
|
||||
.RS
|
||||
@ -179,6 +179,16 @@ If the system property is not set, the default port 1099 is used.
|
||||
.RS
|
||||
.RE
|
||||
.TP
|
||||
.B \f[CB]\-\-disable-registry\f[R]
|
||||
Disable starting RMI registry on startup.
|
||||
This option overrides the system property
|
||||
\[aq]sun.jvm.hotspot.rmi.startRegistry\[aq].
|
||||
If not specified, RMI registry will be started on startup.
|
||||
Otherwise it will not be started, and the already started RMI registry
|
||||
will be used instead.
|
||||
.RS
|
||||
.RE
|
||||
.TP
|
||||
.B \f[CB]\-\-hostname\f[R] \f[I]hostname\f[R]
|
||||
Sets the hostname the RMI connector is bound.
|
||||
The value could be a hostname or an IPv4/IPv6 address.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2019, 2021, 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
|
||||
@ -30,21 +30,39 @@ import jdk.test.lib.Utils;
|
||||
|
||||
|
||||
public class DebugdUtils {
|
||||
|
||||
private static final String GOLDEN = "Debugger attached";
|
||||
|
||||
private final String id;
|
||||
|
||||
private int registryPort;
|
||||
private boolean disableRegistry;
|
||||
private String prefix;
|
||||
private Process debugdProcess;
|
||||
|
||||
public DebugdUtils(String id) {
|
||||
this.id = id;
|
||||
this.registryPort = 0;
|
||||
this.disableRegistry = false;
|
||||
this.prefix = null;
|
||||
debugdProcess = null;
|
||||
}
|
||||
|
||||
public void setRegistryPort(int registryPort) {
|
||||
this.registryPort = registryPort;
|
||||
}
|
||||
|
||||
public void setDisableRegistry(boolean disableRegistry) {
|
||||
this.disableRegistry = disableRegistry;
|
||||
}
|
||||
|
||||
public void setPrefix(String prefix) {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public void attach(long pid) throws IOException {
|
||||
JDKToolLauncher jhsdbLauncher = JDKToolLauncher.createUsingTestJDK("jhsdb");
|
||||
jhsdbLauncher.addVMArgs(Utils.getTestJavaOpts());
|
||||
if (prefix != null) {
|
||||
jhsdbLauncher.addToolArg("-J-Dsun.jvm.hotspot.rmi.serverNamePrefix=" + prefix);
|
||||
}
|
||||
jhsdbLauncher.addToolArg("debugd");
|
||||
jhsdbLauncher.addToolArg("--pid");
|
||||
jhsdbLauncher.addToolArg(Long.toString(pid));
|
||||
@ -52,6 +70,13 @@ public class DebugdUtils {
|
||||
jhsdbLauncher.addToolArg("--serverid");
|
||||
jhsdbLauncher.addToolArg(id);
|
||||
}
|
||||
if (registryPort != 0) {
|
||||
jhsdbLauncher.addToolArg("--registryport");
|
||||
jhsdbLauncher.addToolArg(Integer.toString(registryPort));
|
||||
}
|
||||
if (disableRegistry) {
|
||||
jhsdbLauncher.addToolArg("--disable-registry");
|
||||
}
|
||||
debugdProcess = (new ProcessBuilder(jhsdbLauncher.getCommand())).start();
|
||||
|
||||
// Wait until debug server attached
|
||||
|
@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2021 NTT DATA.
|
||||
* 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.IOException;
|
||||
|
||||
import jdk.test.lib.JDKToolLauncher;
|
||||
import jdk.test.lib.apps.LingeredApp;
|
||||
import jdk.test.lib.process.OutputAnalyzer;
|
||||
import jdk.test.lib.SA.SATestUtils;
|
||||
|
||||
import jtreg.SkippedException;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8263636
|
||||
* @summary Test to use already started RMI registry
|
||||
* @requires vm.hasSA
|
||||
* @requires os.family != "windows"
|
||||
* @library /test/lib
|
||||
* @run main/othervm DisableRegistryTest
|
||||
*/
|
||||
|
||||
public class DisableRegistryTest {
|
||||
private static final int REGISTRY_PORT = 10000;
|
||||
private static final String PREFIX_1 = "app1";
|
||||
private static final String PREFIX_2 = "app2";
|
||||
|
||||
private static DebugdUtils attachWithDebugd(int pid, boolean disableRegistry, String prefix) throws IOException {
|
||||
var debugd = new DebugdUtils(null);
|
||||
debugd.setRegistryPort(REGISTRY_PORT);
|
||||
debugd.setDisableRegistry(disableRegistry);
|
||||
debugd.setPrefix(prefix);
|
||||
debugd.attach(pid);
|
||||
return debugd;
|
||||
}
|
||||
|
||||
private static void test(String prefix) throws IOException, InterruptedException {
|
||||
JDKToolLauncher jhsdbLauncher = JDKToolLauncher.createUsingTestJDK("jhsdb");
|
||||
if (prefix != null) {
|
||||
jhsdbLauncher.addToolArg("-J-Dsun.jvm.hotspot.rmi.serverNamePrefix=" + prefix);
|
||||
}
|
||||
jhsdbLauncher.addToolArg("jinfo");
|
||||
jhsdbLauncher.addToolArg("--connect");
|
||||
jhsdbLauncher.addToolArg("localhost:" + REGISTRY_PORT);
|
||||
|
||||
Process jhsdb = (SATestUtils.createProcessBuilder(jhsdbLauncher)).start();
|
||||
OutputAnalyzer out = new OutputAnalyzer(jhsdb);
|
||||
jhsdb.waitFor();
|
||||
System.out.println(out.getStdout());
|
||||
System.err.println(out.getStderr());
|
||||
|
||||
out.stderrShouldBeEmptyIgnoreDeprecatedWarnings();
|
||||
out.shouldContain("Attaching to remote server localhost:10000, please wait...");
|
||||
out.shouldContain("java.vm.version");
|
||||
out.shouldHaveExitValue(0);
|
||||
|
||||
// This will detect most SA failures, including during the attach.
|
||||
out.shouldNotMatch("^sun.jvm.hotspot.debugger.DebuggerException:.*$");
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SATestUtils.skipIfCannotAttach(); // throws SkippedException if attach not expected to work.
|
||||
SATestUtils.validateSADebugDPrivileges();
|
||||
|
||||
LingeredApp app1 = null;
|
||||
LingeredApp app2 = null;
|
||||
DebugdUtils debugd1 = null;
|
||||
DebugdUtils debugd2 = null;
|
||||
try {
|
||||
app1 = LingeredApp.startApp();
|
||||
app2 = LingeredApp.startApp();
|
||||
debugd1 = attachWithDebugd((int)app1.getPid(), false, PREFIX_1);
|
||||
debugd2 = attachWithDebugd((int)app2.getPid(), true, PREFIX_2);
|
||||
|
||||
test(PREFIX_1);
|
||||
test(PREFIX_2);
|
||||
} catch (SkippedException se) {
|
||||
throw se;
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException("Test ERROR " + ex, ex);
|
||||
} finally {
|
||||
if (debugd2 != null) {
|
||||
debugd2.detach();
|
||||
}
|
||||
if (debugd1 != null) {
|
||||
debugd1.detach();
|
||||
}
|
||||
LingeredApp.stopApp(app1);
|
||||
LingeredApp.stopApp(app2);
|
||||
}
|
||||
System.out.println("Test PASSED");
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user