author | jlahoda |
Tue, 09 May 2017 12:22:15 +0200 | |
changeset 45044 | 7c50549b7744 |
parent 44683 | 610dc2b48954 |
child 45045 | 834233132ab1 |
permissions | -rw-r--r-- |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
1 |
/* |
43758 | 2 |
* Copyright (c) 2016,2017 Oracle and/or its affiliates. All rights reserved. |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
4 |
* |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
10 |
* |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
15 |
* accompanied this code). |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
16 |
* |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
20 |
* |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
23 |
* questions. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
24 |
*/ |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
25 |
package jdk.jshell.execution; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
26 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
27 |
import java.io.File; |
42272
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
28 |
import java.io.IOException; |
44683
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
29 |
import java.nio.charset.StandardCharsets; |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
30 |
import java.nio.file.Files; |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
31 |
import java.util.ArrayList; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
32 |
import java.util.HashMap; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
33 |
import java.util.List; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
34 |
import java.util.Map; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
35 |
import java.util.Map.Entry; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
36 |
import com.sun.jdi.Bootstrap; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
37 |
import com.sun.jdi.VirtualMachine; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
38 |
import com.sun.jdi.connect.Connector; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
39 |
import com.sun.jdi.connect.LaunchingConnector; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
40 |
import com.sun.jdi.connect.ListeningConnector; |
42272
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
41 |
import java.util.concurrent.Callable; |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
42 |
import java.util.concurrent.ExecutorService; |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
43 |
import java.util.concurrent.Executors; |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
44 |
import java.util.concurrent.Future; |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
45 |
import java.util.concurrent.TimeUnit; |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
46 |
import java.util.concurrent.TimeoutException; |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
47 |
import com.sun.jdi.connect.IllegalConnectorArgumentsException; |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
48 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
49 |
/** |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
50 |
* Sets up a JDI connection, providing the resulting JDI {@link VirtualMachine} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
51 |
* and the {@link Process} the remote agent is running in. |
43770 | 52 |
* |
53 |
* @since 9 |
|
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
54 |
*/ |
41941
a935ac3f5274
8161983: JShell API: Clean-up following 8160127 et. al.
rfield
parents:
40764
diff
changeset
|
55 |
public class JdiInitiator { |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
56 |
|
42272
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
57 |
// factor for the timeout on all of connect |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
58 |
private static final double CONNECT_TIMEOUT_FACTOR = 1.5; |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
59 |
|
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
60 |
// Over-all connect time-out |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
61 |
private final int connectTimeout; |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
62 |
|
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
63 |
private VirtualMachine vm; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
64 |
private Process process = null; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
65 |
private final Connector connector; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
66 |
private final String remoteAgent; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
67 |
private final Map<String, com.sun.jdi.connect.Connector.Argument> connectorArgs; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
68 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
69 |
/** |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
70 |
* Start the remote agent and establish a JDI connection to it. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
71 |
* |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
72 |
* @param port the socket port for (non-JDI) commands |
43758 | 73 |
* @param remoteVMOptions any user requested VM command-line options |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
74 |
* @param remoteAgent full class name of remote agent to launch |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
75 |
* @param isLaunch does JDI do the launch? That is, LaunchingConnector, |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
76 |
* otherwise we start explicitly and use ListeningConnector |
40764
29ded021f809
8164518: JShell: Add failover case of explicitly listening to "localhost"
rfield
parents:
39807
diff
changeset
|
77 |
* @param host explicit hostname to use, if null use discovered |
29ded021f809
8164518: JShell: Add failover case of explicitly listening to "localhost"
rfield
parents:
39807
diff
changeset
|
78 |
* hostname, applies to listening only (!isLaunch) |
43758 | 79 |
* @param timeout the start-up time-out in milliseconds. If zero or negative, |
80 |
* will not wait thus will timeout immediately if not already started. |
|
81 |
* @param customConnectorArgs custom arguments passed to the connector. |
|
82 |
* These are JDI com.sun.jdi.connect.Connector arguments. |
|
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
83 |
*/ |
41941
a935ac3f5274
8161983: JShell API: Clean-up following 8160127 et. al.
rfield
parents:
40764
diff
changeset
|
84 |
public JdiInitiator(int port, List<String> remoteVMOptions, String remoteAgent, |
43758 | 85 |
boolean isLaunch, String host, int timeout, |
86 |
Map<String, String> customConnectorArgs) { |
|
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
87 |
this.remoteAgent = remoteAgent; |
42272
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
88 |
this.connectTimeout = (int) (timeout * CONNECT_TIMEOUT_FACTOR); |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
89 |
String connectorName |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
90 |
= isLaunch |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
91 |
? "com.sun.jdi.CommandLineLaunch" |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
92 |
: "com.sun.jdi.SocketListen"; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
93 |
this.connector = findConnector(connectorName); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
94 |
if (connector == null) { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
95 |
throw new IllegalArgumentException("No connector named: " + connectorName); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
96 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
97 |
Map<String, String> argumentName2Value |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
98 |
= isLaunch |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
99 |
? launchArgs(port, String.join(" ", remoteVMOptions)) |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
100 |
: new HashMap<>(); |
42272
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
101 |
if (!isLaunch) { |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
102 |
argumentName2Value.put("timeout", ""+timeout); |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
103 |
if (host != null && !isLaunch) { |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
104 |
argumentName2Value.put("localAddress", host); |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
105 |
} |
40764
29ded021f809
8164518: JShell: Add failover case of explicitly listening to "localhost"
rfield
parents:
39807
diff
changeset
|
106 |
} |
43758 | 107 |
argumentName2Value.putAll(customConnectorArgs); |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
108 |
this.connectorArgs = mergeConnectorArgs(connector, argumentName2Value); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
109 |
this.vm = isLaunch |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
110 |
? launchTarget() |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
111 |
: listenTarget(port, remoteVMOptions); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
112 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
113 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
114 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
115 |
/** |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
116 |
* Returns the resulting {@code VirtualMachine} instance. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
117 |
* |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
118 |
* @return the virtual machine |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
119 |
*/ |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
120 |
public VirtualMachine vm() { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
121 |
return vm; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
122 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
123 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
124 |
/** |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
125 |
* Returns the launched process. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
126 |
* |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
127 |
* @return the remote agent process |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
128 |
*/ |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
129 |
public Process process() { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
130 |
return process; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
131 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
132 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
133 |
/* launch child target vm */ |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
134 |
private VirtualMachine launchTarget() { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
135 |
LaunchingConnector launcher = (LaunchingConnector) connector; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
136 |
try { |
42272
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
137 |
VirtualMachine new_vm = timedVirtualMachineCreation(() -> launcher.launch(connectorArgs), null); |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
138 |
process = new_vm.process(); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
139 |
return new_vm; |
42272
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
140 |
} catch (Throwable ex) { |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
141 |
throw reportLaunchFail(ex, "launch"); |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
142 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
143 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
144 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
145 |
/** |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
146 |
* Directly launch the remote agent and connect JDI to it with a |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
147 |
* ListeningConnector. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
148 |
*/ |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
149 |
private VirtualMachine listenTarget(int port, List<String> remoteVMOptions) { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
150 |
ListeningConnector listener = (ListeningConnector) connector; |
44683
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
151 |
// Files to collection to output of a start-up failure |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
152 |
File crashErrorFile = createTempFile("error"); |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
153 |
File crashOutputFile = createTempFile("output"); |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
154 |
try { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
155 |
// Start listening, get the JDI connection address |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
156 |
String addr = listener.startListening(connectorArgs); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
157 |
debug("Listening at address: " + addr); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
158 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
159 |
// Launch the RemoteAgent requesting a connection on that address |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
160 |
String javaHome = System.getProperty("java.home"); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
161 |
List<String> args = new ArrayList<>(); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
162 |
args.add(javaHome == null |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
163 |
? "java" |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
164 |
: javaHome + File.separator + "bin" + File.separator + "java"); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
165 |
args.add("-agentlib:jdwp=transport=" + connector.transport().name() + |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
166 |
",address=" + addr); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
167 |
args.addAll(remoteVMOptions); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
168 |
args.add(remoteAgent); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
169 |
args.add("" + port); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
170 |
ProcessBuilder pb = new ProcessBuilder(args); |
44683
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
171 |
pb.redirectError(crashErrorFile); |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
172 |
pb.redirectOutput(crashOutputFile); |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
173 |
process = pb.start(); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
174 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
175 |
// Accept the connection from the remote agent |
42272
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
176 |
vm = timedVirtualMachineCreation(() -> listener.accept(connectorArgs), |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
177 |
() -> process.waitFor()); |
44683
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
178 |
try { |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
179 |
listener.stopListening(connectorArgs); |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
180 |
} catch (IOException | IllegalConnectorArgumentsException ex) { |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
181 |
// ignore |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
182 |
} |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
183 |
crashErrorFile.delete(); |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
184 |
crashOutputFile.delete(); |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
185 |
return vm; |
42272
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
186 |
} catch (Throwable ex) { |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
187 |
if (process != null) { |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
188 |
process.destroyForcibly(); |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
189 |
} |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
190 |
try { |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
191 |
listener.stopListening(connectorArgs); |
44683
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
192 |
} catch (IOException | IllegalConnectorArgumentsException iex) { |
42272
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
193 |
// ignore |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
194 |
} |
44683
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
195 |
String text = readFile(crashErrorFile) + readFile(crashOutputFile); |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
196 |
crashErrorFile.delete(); |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
197 |
crashOutputFile.delete(); |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
198 |
if (text.isEmpty()) { |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
199 |
throw reportLaunchFail(ex, "listen"); |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
200 |
} else { |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
201 |
throw new IllegalArgumentException(text); |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
202 |
} |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
203 |
} |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
204 |
} |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
205 |
|
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
206 |
private File createTempFile(String label) { |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
207 |
try { |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
208 |
File f = File.createTempFile("remote", label); |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
209 |
f.deleteOnExit(); |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
210 |
return f; |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
211 |
} catch (IOException ex) { |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
212 |
throw new InternalError("Failed create temp ", ex); |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
213 |
} |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
214 |
} |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
215 |
|
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
216 |
private String readFile(File f) { |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
217 |
try { |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
218 |
return new String(Files.readAllBytes(f.toPath()), |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
219 |
StandardCharsets.UTF_8); |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
220 |
} catch (IOException ex) { |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43770
diff
changeset
|
221 |
return "error reading " + f + " : " + ex.toString(); |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
222 |
} |
42272
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
223 |
} |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
224 |
|
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
225 |
VirtualMachine timedVirtualMachineCreation(Callable<VirtualMachine> creator, |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
226 |
Callable<Integer> processComplete) throws Exception { |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
227 |
VirtualMachine result; |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
228 |
ExecutorService executor = Executors.newCachedThreadPool(runnable -> { |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
229 |
Thread thread = Executors.defaultThreadFactory().newThread(runnable); |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
230 |
thread.setDaemon(true); |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
231 |
return thread; |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
232 |
}); |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
233 |
try { |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
234 |
Future<VirtualMachine> future = executor.submit(creator); |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
235 |
if (processComplete != null) { |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
236 |
executor.submit(() -> { |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
237 |
Integer i = processComplete.call(); |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
238 |
future.cancel(true); |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
239 |
return i; |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
240 |
}); |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
241 |
} |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
242 |
|
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
243 |
try { |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
244 |
result = future.get(connectTimeout, TimeUnit.MILLISECONDS); |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
245 |
} catch (TimeoutException ex) { |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
246 |
future.cancel(true); |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
247 |
throw ex; |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
248 |
} |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
249 |
} finally { |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
250 |
executor.shutdownNow(); |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
251 |
} |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
252 |
return result; |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
253 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
254 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
255 |
private Connector findConnector(String name) { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
256 |
for (Connector cntor |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
257 |
: Bootstrap.virtualMachineManager().allConnectors()) { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
258 |
if (cntor.name().equals(name)) { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
259 |
return cntor; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
260 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
261 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
262 |
return null; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
263 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
264 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
265 |
private Map<String, Connector.Argument> mergeConnectorArgs(Connector connector, Map<String, String> argumentName2Value) { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
266 |
Map<String, Connector.Argument> arguments = connector.defaultArguments(); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
267 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
268 |
for (Entry<String, String> argumentEntry : argumentName2Value.entrySet()) { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
269 |
String name = argumentEntry.getKey(); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
270 |
String value = argumentEntry.getValue(); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
271 |
Connector.Argument argument = arguments.get(name); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
272 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
273 |
if (argument == null) { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
274 |
throw new IllegalArgumentException("Argument is not defined for connector:" + |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
275 |
name + " -- " + connector.name()); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
276 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
277 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
278 |
argument.setValue(value); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
279 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
280 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
281 |
return arguments; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
282 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
283 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
284 |
/** |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
285 |
* The JShell specific Connector args for the LaunchingConnector. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
286 |
* |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
287 |
* @param portthe socket port for (non-JDI) commands |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
288 |
* @param remoteVMOptions any user requested VM options |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
289 |
* @return the argument map |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
290 |
*/ |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
291 |
private Map<String, String> launchArgs(int port, String remoteVMOptions) { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
292 |
Map<String, String> argumentName2Value = new HashMap<>(); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
293 |
argumentName2Value.put("main", remoteAgent + " " + port); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
294 |
argumentName2Value.put("options", remoteVMOptions); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
295 |
return argumentName2Value; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
296 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
297 |
|
42272
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
298 |
private InternalError reportLaunchFail(Throwable ex, String context) { |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
299 |
return new InternalError("Failed remote " + context + ": " |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
300 |
+ ex.toString() |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41941
diff
changeset
|
301 |
+ " @ " + connector + |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
302 |
" -- " + connectorArgs, ex); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
303 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
304 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
305 |
/** |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
306 |
* Log debugging information. Arguments as for {@code printf}. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
307 |
* |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
308 |
* @param format a format string as described in Format string syntax |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
309 |
* @param args arguments referenced by the format specifiers in the format |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
310 |
* string. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
311 |
*/ |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
312 |
private void debug(String format, Object... args) { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
313 |
// Reserved for future logging |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
314 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
315 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
316 |
/** |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
317 |
* Log a serious unexpected internal exception. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
318 |
* |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
319 |
* @param ex the exception |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
320 |
* @param where a description of the context of the exception |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
321 |
*/ |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
322 |
private void debug(Throwable ex, String where) { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
323 |
// Reserved for future logging |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
324 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
325 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
326 |
} |