8263635: Add --servername option to jhsdb debugd
Reviewed-by: cjplummer, sspitsyn
This commit is contained in:
parent
6ffa3e66db
commit
37bc4e2e3c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 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
|
||||
@ -103,11 +103,11 @@ public class DebugServer {
|
||||
try {
|
||||
if (usePid) {
|
||||
System.err.println("Attaching to process ID " + pid + " and starting RMI services, please wait...");
|
||||
agent.startServer(pid, serverID);
|
||||
agent.startServer(pid, serverID, null);
|
||||
} else {
|
||||
System.err.println("Attaching to core " + coreFileName +
|
||||
" from executable " + javaExecutableName + " and starting RMI services, please wait...");
|
||||
agent.startServer(javaExecutableName, coreFileName, serverID);
|
||||
agent.startServer(javaExecutableName, coreFileName, serverID, null);
|
||||
}
|
||||
}
|
||||
catch (DebuggerException e) {
|
||||
|
@ -90,6 +90,7 @@ public class HotSpotAgent {
|
||||
|
||||
// All needed information for server side
|
||||
private String serverID;
|
||||
private String serverName;
|
||||
|
||||
private String[] jvmLibNames;
|
||||
|
||||
@ -203,7 +204,8 @@ public class HotSpotAgent {
|
||||
to which the RMI connector is bound. If not specified a random
|
||||
available port is used. */
|
||||
public synchronized void startServer(int processID,
|
||||
String uniqueID,
|
||||
String serverID,
|
||||
String serverName,
|
||||
int rmiPort) {
|
||||
if (debugger != null) {
|
||||
throw new DebuggerException("Already attached");
|
||||
@ -211,7 +213,8 @@ public class HotSpotAgent {
|
||||
pid = processID;
|
||||
startupMode = PROCESS_MODE;
|
||||
isServer = true;
|
||||
serverID = uniqueID;
|
||||
this.serverID = serverID;
|
||||
this.serverName = serverName;
|
||||
this.rmiPort = rmiPort;
|
||||
go();
|
||||
}
|
||||
@ -220,8 +223,8 @@ public class HotSpotAgent {
|
||||
starts a debug server, allowing remote machines to connect and
|
||||
examine this process. Uses specified name to uniquely identify a
|
||||
specific debuggee on the server */
|
||||
public synchronized void startServer(int processID, String uniqueID) {
|
||||
startServer(processID, uniqueID, 0);
|
||||
public synchronized void startServer(int processID, String serverID, String serverName) {
|
||||
startServer(processID, serverID, serverName, 0);
|
||||
}
|
||||
|
||||
/** This attaches to a process running on the local machine and
|
||||
@ -229,7 +232,7 @@ public class HotSpotAgent {
|
||||
examine this process. */
|
||||
public synchronized void startServer(int processID)
|
||||
throws DebuggerException {
|
||||
startServer(processID, null);
|
||||
startServer(processID, null, null);
|
||||
}
|
||||
|
||||
/** This opens a core file on the local machine and starts a debug
|
||||
@ -239,7 +242,8 @@ public class HotSpotAgent {
|
||||
is bound. If not specified a random available port is used. */
|
||||
public synchronized void startServer(String javaExecutableName,
|
||||
String coreFileName,
|
||||
String uniqueID,
|
||||
String serverID,
|
||||
String serverName,
|
||||
int rmiPort) {
|
||||
if (debugger != null) {
|
||||
throw new DebuggerException("Already attached");
|
||||
@ -251,7 +255,8 @@ public class HotSpotAgent {
|
||||
this.coreFileName = coreFileName;
|
||||
startupMode = CORE_FILE_MODE;
|
||||
isServer = true;
|
||||
serverID = uniqueID;
|
||||
this.serverID = serverID;
|
||||
this.serverName = serverName;
|
||||
this.rmiPort = rmiPort;
|
||||
go();
|
||||
}
|
||||
@ -262,8 +267,9 @@ public class HotSpotAgent {
|
||||
debugee */
|
||||
public synchronized void startServer(String javaExecutableName,
|
||||
String coreFileName,
|
||||
String uniqueID) {
|
||||
startServer(javaExecutableName, coreFileName, uniqueID, 0);
|
||||
String serverID,
|
||||
String serverName) {
|
||||
startServer(javaExecutableName, coreFileName, serverID, serverName, 0);
|
||||
}
|
||||
|
||||
/** This opens a core file on the local machine and starts a debug
|
||||
@ -271,7 +277,7 @@ public class HotSpotAgent {
|
||||
core file. */
|
||||
public synchronized void startServer(String javaExecutableName, String coreFileName)
|
||||
throws DebuggerException {
|
||||
startServer(javaExecutableName, coreFileName, null);
|
||||
startServer(javaExecutableName, coreFileName, null, null);
|
||||
}
|
||||
|
||||
/** This may only be called on the server side after startServer()
|
||||
@ -302,7 +308,7 @@ public class HotSpotAgent {
|
||||
DebuggerException ex = null;
|
||||
if (isServer) {
|
||||
try {
|
||||
RMIHelper.unbind(serverID);
|
||||
RMIHelper.unbind(serverID, serverName);
|
||||
}
|
||||
catch (DebuggerException de) {
|
||||
ex = de;
|
||||
@ -377,7 +383,7 @@ public class HotSpotAgent {
|
||||
catch (RemoteException rem) {
|
||||
throw new DebuggerException(rem);
|
||||
}
|
||||
RMIHelper.rebind(serverID, remote);
|
||||
RMIHelper.rebind(serverID, serverName, remote);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
|
@ -28,12 +28,14 @@ import java.io.*;
|
||||
import java.net.*;
|
||||
import java.rmi.*;
|
||||
import java.rmi.registry.*;
|
||||
import java.util.regex.*;
|
||||
import sun.jvm.hotspot.debugger.DebuggerException;
|
||||
|
||||
public class RMIHelper {
|
||||
private static final boolean startRegistry;
|
||||
private static final Pattern CONNECT_PATTERN = Pattern.compile("^((?<serverid>.+?)@)?(?<host>.+?)(/(?<servername>.+))?$");
|
||||
private static final String DEFAULT_RMI_OBJECT_NAME = "SARemoteDebugger";
|
||||
private static int port;
|
||||
private static String serverNamePrefix;
|
||||
|
||||
static {
|
||||
String tmp = System.getProperty("sun.jvm.hotspot.rmi.startRegistry");
|
||||
@ -53,12 +55,10 @@ public class RMIHelper {
|
||||
System.err.println("invalid port supplied, assuming default");
|
||||
}
|
||||
}
|
||||
|
||||
serverNamePrefix = System.getProperty("sun.jvm.hotspot.rmi.serverNamePrefix", "SARemoteDebugger");
|
||||
}
|
||||
|
||||
public static void rebind(String uniqueID, Remote object) throws DebuggerException {
|
||||
String name = getName(uniqueID);
|
||||
public static void rebind(String serverID, String serverName, Remote object) throws DebuggerException {
|
||||
String name = getName(serverID, serverName);
|
||||
try {
|
||||
Naming.rebind(name, object);
|
||||
} catch (RemoteException re) {
|
||||
@ -78,8 +78,8 @@ public class RMIHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public static void unbind(String uniqueID) throws DebuggerException {
|
||||
String name = getName(uniqueID);
|
||||
public static void unbind(String serverID, String serverName) throws DebuggerException {
|
||||
String name = getName(serverID, serverName);
|
||||
try {
|
||||
Naming.unbind(name);
|
||||
} catch (Exception exp) {
|
||||
@ -87,25 +87,32 @@ public class RMIHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public static Remote lookup(String debugServerID) throws DebuggerException {
|
||||
// debugServerID follows the pattern [unique_id@]host[:port]
|
||||
// we have to transform this as //host[:port]/<serverNamePrefix>['_'<unique_id>]
|
||||
public static Remote lookup(String connectionString) throws DebuggerException {
|
||||
// connectionString follows the pattern [serverid@]host[:port][/servername]
|
||||
// we have to transform this as //host[:port]/<servername>['_'<serverid>]
|
||||
Matcher matcher = CONNECT_PATTERN.matcher(connectionString);
|
||||
matcher.find();
|
||||
|
||||
int index = debugServerID.indexOf('@');
|
||||
StringBuilder nameBuf = new StringBuilder("//");
|
||||
String uniqueID = null;
|
||||
if (index != -1) {
|
||||
nameBuf.append(debugServerID.substring(index + 1));
|
||||
uniqueID = debugServerID.substring(0, index);
|
||||
} else {
|
||||
nameBuf.append(debugServerID);
|
||||
String serverNamePrefix = System.getProperty("sun.jvm.hotspot.rmi.serverNamePrefix");
|
||||
String rmiObjectName = matcher.group("servername");
|
||||
if (serverNamePrefix != null) {
|
||||
if (rmiObjectName == null) {
|
||||
System.err.println("WARNING: sun.jvm.hotspot.rmi.serverNamePrefix is deprecated. Please specify it in --connect.");
|
||||
rmiObjectName = serverNamePrefix;
|
||||
} else {
|
||||
throw new DebuggerException("Cannot set both sun.jvm.hotspot.rmi.serverNamePrefix and servername in --connect together");
|
||||
}
|
||||
}
|
||||
|
||||
if (rmiObjectName == null) {
|
||||
rmiObjectName = DEFAULT_RMI_OBJECT_NAME;
|
||||
}
|
||||
StringBuilder nameBuf = new StringBuilder("//");
|
||||
nameBuf.append(matcher.group("host"));
|
||||
nameBuf.append('/');
|
||||
nameBuf.append(serverNamePrefix);
|
||||
if (uniqueID != null) {
|
||||
nameBuf.append(rmiObjectName);
|
||||
if (matcher.group("serverid") != null) {
|
||||
nameBuf.append('_');
|
||||
nameBuf.append(uniqueID);
|
||||
nameBuf.append(matcher.group("serverid"));
|
||||
}
|
||||
|
||||
try {
|
||||
@ -115,12 +122,22 @@ public class RMIHelper {
|
||||
}
|
||||
}
|
||||
|
||||
private static String getName(String uniqueID) {
|
||||
String name = null;
|
||||
if (uniqueID != null) {
|
||||
name = serverNamePrefix + "_" + uniqueID;
|
||||
} else {
|
||||
name = serverNamePrefix;
|
||||
private static String getName(String serverID, String serverName) {
|
||||
String name = serverName;
|
||||
String serverNamePrefix = System.getProperty("sun.jvm.hotspot.rmi.serverNamePrefix");
|
||||
if (serverNamePrefix != null) {
|
||||
if (serverName == null) {
|
||||
System.err.println("WARNING: sun.jvm.hotspot.rmi.serverNamePrefix is deprecated. Please specify it with --servername.");
|
||||
name = serverNamePrefix;
|
||||
} else {
|
||||
throw new DebuggerException("Cannot set both sun.jvm.hotspot.rmi.serverNamePrefix and --servername together");
|
||||
}
|
||||
}
|
||||
if (name == null) {
|
||||
name = DEFAULT_RMI_OBJECT_NAME;
|
||||
}
|
||||
if (serverID != null) {
|
||||
name += "_" + serverID;
|
||||
}
|
||||
if (port != Registry.REGISTRY_PORT) {
|
||||
name = "//localhost:" + port + "/" + name;
|
||||
|
@ -68,7 +68,7 @@ public class SALauncher {
|
||||
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>[:registryport] To connect to a remote debug server (debugd).");
|
||||
System.out.println(" --connect [<serverid>@]<host>[:registryport][/servername] 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,15 +85,14 @@ 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 id@debugserver:1234");
|
||||
System.out.println(" or jhsdb " + mode + " --connect serverid@debugserver:1234/servername");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean debugdHelp() {
|
||||
// [options] <pid> [server-id]
|
||||
// [options] <executable> <core> [server-id]
|
||||
System.out.println(" --serverid <id> A unique identifier for this debug server.");
|
||||
System.out.println(" --serverid <id> A unique identifier for this debugd server.");
|
||||
System.out.println(" --servername <name> Instance name of debugd server.");
|
||||
System.out.println(" --rmiport <port> Sets the port number to which the RMI connector is bound." +
|
||||
" If not specified a random available port is used.");
|
||||
System.out.println(" --registryport <port> Sets the RMI registry port." +
|
||||
@ -376,7 +375,8 @@ public class SALauncher {
|
||||
"rmiport=", "rmiport",
|
||||
"registryport=", "registryport",
|
||||
"disable-registry", "disable-registry",
|
||||
"hostname=", "hostname");
|
||||
"hostname=", "hostname",
|
||||
"servername=", "servername");
|
||||
|
||||
Map<String, String> argMap = parseOptions(args, longOptsMap);
|
||||
|
||||
@ -391,6 +391,7 @@ public class SALauncher {
|
||||
String javaExecutableName = argMap.get("exe");
|
||||
String coreFileName = argMap.get("core");
|
||||
String pidString = argMap.get("pid");
|
||||
String serverName = argMap.get("servername");
|
||||
|
||||
// Set RMI registry port, if specified
|
||||
if (registryPort != null) {
|
||||
@ -434,7 +435,7 @@ public class SALauncher {
|
||||
System.err.println("Attaching to process ID " + pid + " and starting RMI services," +
|
||||
" please wait...");
|
||||
try {
|
||||
agent.startServer(pid, serverID, rmiPort);
|
||||
agent.startServer(pid, serverID, serverName, rmiPort);
|
||||
} catch (DebuggerException e) {
|
||||
System.err.print("Error attaching to process or starting server: ");
|
||||
e.printStackTrace();
|
||||
@ -446,7 +447,7 @@ public class SALauncher {
|
||||
System.err.println("Attaching to core " + coreFileName +
|
||||
" from executable " + javaExecutableName + " and starting RMI services, please wait...");
|
||||
try {
|
||||
agent.startServer(javaExecutableName, coreFileName, serverID, rmiPort);
|
||||
agent.startServer(javaExecutableName, coreFileName, serverID, serverName, rmiPort);
|
||||
} catch (DebuggerException e) {
|
||||
System.err.print("Error attaching to core file or starting server: ");
|
||||
e.printStackTrace();
|
||||
|
@ -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[:registryport]\f[R]\]
|
||||
\f[CB]\-\-connect\f[R] \f[I][serverid\@]debugd\-host[:registryport][/servername]\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[:registryport]\f[R]\]
|
||||
\f[CB]\-\-connect\f[R] \f[I][serverid\@]debugd\-host[:registryport][/servername]\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[:registryport]\f[R])
|
||||
| \f[CB]\-\-connect\f[R] \f[I][serverid\@]debugd\-host[:registryport][/servername]\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[:registryport]\f[R])
|
||||
| \f[CB]\-\-connect\f[R] \f[I][serverid\@]debugd\-host[:registryport][/servername]\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[:registryport]\f[R])
|
||||
| \f[CB]\-\-connect\f[R] \f[I][serverid\@]debugd\-host[:registryport][/servername]\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[:registryport]\f[R])
|
||||
| \f[CB]\-\-connect\f[R] \f[I][serverid\@]debugd\-host[:registryport][/servername]\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[:registryport]\f[R]
|
||||
.B \f[I][serverid\@]debugd\-host[:registryport][/servername]\f[R]
|
||||
An optional server ID and the address of the remote debug server
|
||||
(debugd).
|
||||
.RS
|
||||
@ -158,9 +158,10 @@ Displays the options available for the \f[I]command\f[R].
|
||||
.RE
|
||||
.SH OPTIONS FOR THE DEBUGD MODE
|
||||
.TP
|
||||
.B \f[CB]\-\-serverid\f[R] \f[I]server\-id\f[R]
|
||||
.B \f[CB]\-\-serverid\f[R] \f[I]serverid\f[R]
|
||||
An optional unique ID for this debug server.
|
||||
This is required if multiple debug servers are run on the same machine.
|
||||
This is required if multiple debug servers are run on the same server instance.
|
||||
It would be added to RMI object name for server instance.
|
||||
.RS
|
||||
.RE
|
||||
.TP
|
||||
@ -198,6 +199,13 @@ If not specified, the system property is used.
|
||||
If the system property is not set, a system hostname is used.
|
||||
.RS
|
||||
.RE
|
||||
.TP
|
||||
.B \f[CB]\-\-servername\f[R] \f[I]servername\f[R]
|
||||
Sets the instance name of debugd server to distinguish SA debugee.
|
||||
It is used for RMI object name for server instance.
|
||||
If not specified, "SARemoteDebugger" will be used.
|
||||
.RS
|
||||
.RE
|
||||
.SH OPTIONS FOR THE JINFO MODE
|
||||
.TP
|
||||
.B \f[CB]\-\-flags\f[R]
|
||||
|
@ -54,7 +54,7 @@ public class ClhsdbAttachToDebugServer {
|
||||
try {
|
||||
theApp = LingeredApp.startApp();
|
||||
System.out.println("Started LingeredApp with pid " + theApp.getPid());
|
||||
debugd = new DebugdUtils(null);
|
||||
debugd = new DebugdUtils();
|
||||
debugd.attach(theApp.getPid());
|
||||
|
||||
JDKToolLauncher jhsdbLauncher = JDKToolLauncher.createUsingTestJDK("jhsdb");
|
||||
|
@ -53,7 +53,7 @@ public class ClhsdbTestConnectArgument {
|
||||
try {
|
||||
theApp = LingeredApp.startApp();
|
||||
System.out.println("Started LingeredApp with pid " + theApp.getPid());
|
||||
debugd = new DebugdUtils(null);
|
||||
debugd = new DebugdUtils();
|
||||
debugd.attach(theApp.getPid());
|
||||
|
||||
JDKToolLauncher jhsdbLauncher = JDKToolLauncher.createUsingTestJDK("jhsdb");
|
||||
|
@ -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
|
||||
@ -44,13 +44,13 @@ import jdk.test.lib.process.OutputAnalyzer;
|
||||
|
||||
public class DebugdConnectTest {
|
||||
|
||||
private static OutputAnalyzer runJHSDB(String command, String id) throws IOException, InterruptedException {
|
||||
private static OutputAnalyzer runJHSDB(String command, String serverID) throws IOException, InterruptedException {
|
||||
JDKToolLauncher jhsdbLauncher = JDKToolLauncher.createUsingTestJDK("jhsdb");
|
||||
jhsdbLauncher.addVMArgs(Utils.getFilteredTestJavaOpts("-showversion", "-Xcomp"));
|
||||
jhsdbLauncher.addToolArg(command);
|
||||
jhsdbLauncher.addToolArg("--connect");
|
||||
if (id != null) {
|
||||
jhsdbLauncher.addToolArg(id + "@localhost");
|
||||
if (serverID != null) {
|
||||
jhsdbLauncher.addToolArg(serverID + "@localhost");
|
||||
} else {
|
||||
jhsdbLauncher.addToolArg("localhost");
|
||||
}
|
||||
@ -66,47 +66,50 @@ public class DebugdConnectTest {
|
||||
return out;
|
||||
}
|
||||
|
||||
private static void runJSTACK(String id) throws IOException, InterruptedException {
|
||||
OutputAnalyzer out = runJHSDB("jstack", id);
|
||||
private static void runJSTACK(String serverID) throws IOException, InterruptedException {
|
||||
OutputAnalyzer out = runJHSDB("jstack", serverID);
|
||||
|
||||
out.shouldContain("LingeredApp");
|
||||
out.stderrShouldBeEmptyIgnoreDeprecatedWarnings();
|
||||
out.shouldHaveExitValue(0);
|
||||
}
|
||||
|
||||
private static void runJMAP(String id) throws IOException, InterruptedException {
|
||||
OutputAnalyzer out = runJHSDB("jmap", id);
|
||||
private static void runJMAP(String serverID) throws IOException, InterruptedException {
|
||||
OutputAnalyzer out = runJHSDB("jmap", serverID);
|
||||
|
||||
out.shouldContain("JVM version is");
|
||||
out.stderrShouldBeEmptyIgnoreDeprecatedWarnings();
|
||||
out.shouldHaveExitValue(0);
|
||||
}
|
||||
|
||||
private static void runJINFO(String id) throws IOException, InterruptedException {
|
||||
OutputAnalyzer out = runJHSDB("jinfo", id);
|
||||
private static void runJINFO(String serverID) throws IOException, InterruptedException {
|
||||
OutputAnalyzer out = runJHSDB("jinfo", serverID);
|
||||
|
||||
out.shouldContain("Java System Properties:");
|
||||
out.stderrShouldBeEmptyIgnoreDeprecatedWarnings();
|
||||
out.shouldHaveExitValue(0);
|
||||
}
|
||||
|
||||
private static void runJSNAP(String id) throws IOException, InterruptedException {
|
||||
OutputAnalyzer out = runJHSDB("jsnap", id);
|
||||
private static void runJSNAP(String serverID) throws IOException, InterruptedException {
|
||||
OutputAnalyzer out = runJHSDB("jsnap", serverID);
|
||||
|
||||
out.shouldContain("java.vm.name=");
|
||||
out.stderrShouldBeEmptyIgnoreDeprecatedWarnings();
|
||||
out.shouldHaveExitValue(0);
|
||||
}
|
||||
|
||||
private static void runTests(String id, long debuggeePid) throws IOException, InterruptedException {
|
||||
DebugdUtils debugd = new DebugdUtils(id);
|
||||
private static void runTests(String serverID, long debuggeePid) throws IOException, InterruptedException {
|
||||
DebugdUtils debugd = new DebugdUtils();
|
||||
if (serverID != null) {
|
||||
debugd.setServerID(serverID);
|
||||
}
|
||||
debugd.attach(debuggeePid);
|
||||
|
||||
try {
|
||||
runJSTACK(id);
|
||||
runJMAP(id);
|
||||
runJINFO(id);
|
||||
runJSNAP(id);
|
||||
runJSTACK(serverID);
|
||||
runJMAP(serverID);
|
||||
runJINFO(serverID);
|
||||
runJSNAP(serverID);
|
||||
} finally {
|
||||
debugd.detach();
|
||||
}
|
||||
|
@ -31,17 +31,17 @@ import jdk.test.lib.Utils;
|
||||
|
||||
public class DebugdUtils {
|
||||
private static final String GOLDEN = "Debugger attached";
|
||||
private final String id;
|
||||
private String serverID;
|
||||
private int registryPort;
|
||||
private boolean disableRegistry;
|
||||
private String prefix;
|
||||
private String serverName;
|
||||
private Process debugdProcess;
|
||||
|
||||
public DebugdUtils(String id) {
|
||||
this.id = id;
|
||||
public DebugdUtils() {
|
||||
this.serverID = null;
|
||||
this.registryPort = 0;
|
||||
this.disableRegistry = false;
|
||||
this.prefix = null;
|
||||
this.serverName = null;
|
||||
debugdProcess = null;
|
||||
}
|
||||
|
||||
@ -53,22 +53,23 @@ public class DebugdUtils {
|
||||
this.disableRegistry = disableRegistry;
|
||||
}
|
||||
|
||||
public void setPrefix(String prefix) {
|
||||
this.prefix = prefix;
|
||||
public void setServerID(String serverID) {
|
||||
this.serverID = serverID;
|
||||
}
|
||||
|
||||
public void setServerName(String serverName) {
|
||||
this.serverName = serverName;
|
||||
}
|
||||
|
||||
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));
|
||||
if (id != null) {
|
||||
if (serverID != null) {
|
||||
jhsdbLauncher.addToolArg("--serverid");
|
||||
jhsdbLauncher.addToolArg(id);
|
||||
jhsdbLauncher.addToolArg(serverID);
|
||||
}
|
||||
if (registryPort != 0) {
|
||||
jhsdbLauncher.addToolArg("--registryport");
|
||||
@ -77,6 +78,10 @@ public class DebugdUtils {
|
||||
if (disableRegistry) {
|
||||
jhsdbLauncher.addToolArg("--disable-registry");
|
||||
}
|
||||
if (serverName != null) {
|
||||
jhsdbLauncher.addToolArg("--servername");
|
||||
jhsdbLauncher.addToolArg(serverName);
|
||||
}
|
||||
debugdProcess = (new ProcessBuilder(jhsdbLauncher.getCommand())).start();
|
||||
|
||||
// Wait until debug server attached
|
||||
|
@ -33,7 +33,7 @@ import jtreg.SkippedException;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8263636
|
||||
* @bug 8263636 8263635
|
||||
* @summary Test to use already started RMI registry
|
||||
* @requires vm.hasSA
|
||||
* @requires os.family != "windows"
|
||||
@ -46,23 +46,22 @@ public class DisableRegistryTest {
|
||||
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);
|
||||
private static DebugdUtils attachWithDebugd(int pid, boolean disableRegistry, String serverName) throws IOException {
|
||||
var debugd = new DebugdUtils();
|
||||
debugd.setRegistryPort(REGISTRY_PORT);
|
||||
debugd.setDisableRegistry(disableRegistry);
|
||||
debugd.setPrefix(prefix);
|
||||
debugd.setServerName(serverName);
|
||||
debugd.attach(pid);
|
||||
return debugd;
|
||||
}
|
||||
|
||||
private static void test(String prefix) throws IOException, InterruptedException {
|
||||
private static void test(String serverName) throws IOException, InterruptedException {
|
||||
assert serverName != null;
|
||||
|
||||
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);
|
||||
jhsdbLauncher.addToolArg("localhost:" + REGISTRY_PORT + "/" + serverName);
|
||||
|
||||
Process jhsdb = (SATestUtils.createProcessBuilder(jhsdbLauncher)).start();
|
||||
OutputAnalyzer out = new OutputAnalyzer(jhsdb);
|
||||
@ -71,7 +70,7 @@ public class DisableRegistryTest {
|
||||
System.err.println(out.getStderr());
|
||||
|
||||
out.stderrShouldBeEmptyIgnoreDeprecatedWarnings();
|
||||
out.shouldContain("Attaching to remote server localhost:10000, please wait...");
|
||||
out.shouldContain("Attaching to remote server localhost:10000");
|
||||
out.shouldContain("java.vm.version");
|
||||
out.shouldHaveExitValue(0);
|
||||
|
||||
|
@ -49,7 +49,7 @@ public class PmapOnDebugdTest {
|
||||
try {
|
||||
theApp = LingeredApp.startApp();
|
||||
System.out.println("Started LingeredApp with pid " + theApp.getPid());
|
||||
debugd = new DebugdUtils(null);
|
||||
debugd = new DebugdUtils();
|
||||
debugd.attach(theApp.getPid());
|
||||
|
||||
JDKToolLauncher jhsdbLauncher = JDKToolLauncher.createUsingTestJDK("jhsdb");
|
||||
|
@ -52,7 +52,7 @@ public class RunCommandOnServerTest {
|
||||
try {
|
||||
theApp = LingeredApp.startApp();
|
||||
System.out.println("Started LingeredApp with pid " + theApp.getPid());
|
||||
debugd = new DebugdUtils(null);
|
||||
debugd = new DebugdUtils();
|
||||
debugd.attach(theApp.getPid());
|
||||
|
||||
JDKToolLauncher jhsdbLauncher = JDKToolLauncher.createUsingTestJDK("jhsdb");
|
||||
|
Loading…
Reference in New Issue
Block a user