src/jdk.jshell/share/classes/jdk/jshell/execution/JDIInitiator.java
Print this page
@@ -54,13 +54,15 @@
* @param port the socket port for (non-JDI) commands
* @param remoteVMOptions any user requested VM options
* @param remoteAgent full class name of remote agent to launch
* @param isLaunch does JDI do the launch? That is, LaunchingConnector,
* otherwise we start explicitly and use ListeningConnector
+ * @param useLocalhost explicitly use "localhost" rather than discovered
+ * hostname, applies to listening only (!isLaunch)
*/
- public JDIInitiator(int port, List<String> remoteVMOptions,
- String remoteAgent, boolean isLaunch) {
+ public JDIInitiator(int port, List<String> remoteVMOptions, String remoteAgent,
+ boolean isLaunch, boolean useLocalhost) {
this.remoteAgent = remoteAgent;
String connectorName
= isLaunch
? "com.sun.jdi.CommandLineLaunch"
: "com.sun.jdi.SocketListen";
@@ -70,10 +72,13 @@
}
Map<String, String> argumentName2Value
= isLaunch
? launchArgs(port, String.join(" ", remoteVMOptions))
: new HashMap<>();
+ if (useLocalhost && !isLaunch) {
+ argumentName2Value.put("localAddress", "localhost");
+ }
this.connectorArgs = mergeConnectorArgs(connector, argumentName2Value);
this.vm = isLaunch
? launchTarget()
: listenTarget(port, remoteVMOptions);