src/jdk.jdi/share/classes/com/sun/tools/jdi/AbstractLauncher.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 45714 jdk/src/jdk.jdi/share/classes/com/sun/tools/jdi/AbstractLauncher.java@1820d351198d
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
     2
 * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.jdi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    28
import java.io.IOException;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    29
import java.io.InterruptedIOException;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    30
import java.util.ArrayList;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    31
import java.util.List;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    35
import com.sun.jdi.Bootstrap;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    36
import com.sun.jdi.InternalException;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    37
import com.sun.jdi.VirtualMachine;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    38
import com.sun.jdi.VirtualMachineManager;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    39
import com.sun.jdi.connect.Connector;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    40
import com.sun.jdi.connect.IllegalConnectorArgumentsException;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    41
import com.sun.jdi.connect.LaunchingConnector;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    42
import com.sun.jdi.connect.VMStartException;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    43
import com.sun.jdi.connect.spi.Connection;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    44
import com.sun.jdi.connect.spi.TransportService;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    45
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    46
abstract class AbstractLauncher extends ConnectorImpl
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    47
                                implements LaunchingConnector
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    48
{
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    abstract public VirtualMachine
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    50
        launch(Map<String, ? extends Connector.Argument> arguments)
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    51
        throws IOException, IllegalConnectorArgumentsException,
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    52
               VMStartException;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    53
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    abstract public String name();
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    55
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    abstract public String description();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    ThreadGroup grp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    AbstractLauncher() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        grp = Thread.currentThread().getThreadGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        ThreadGroup parent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        while ((parent = grp.getParent()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            grp = parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    String[] tokenizeCommand(String command, char quote) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        String quoteStr = String.valueOf(quote); // easier to deal with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
         * Tokenize the command, respecting the given quote character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        StringTokenizer tokenizer = new StringTokenizer(command,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                                                        quote + " \t\r\n\f",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                                                        true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        String quoted = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        String pending = null;
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    81
        List<String> tokenList = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        while (tokenizer.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            String token = tokenizer.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            if (quoted != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                if (token.equals(quoteStr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                    tokenList.add(quoted);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                    quoted = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                    quoted += token;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            } else if (pending != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                if (token.equals(quoteStr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                    quoted = pending;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                } else if ((token.length() == 1) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                           Character.isWhitespace(token.charAt(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                    tokenList.add(pending);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                    throw new InternalException("Unexpected token: " + token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                pending = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                if (token.equals(quoteStr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                    quoted = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                } else if ((token.length() == 1) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                           Character.isWhitespace(token.charAt(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                    // continue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                    pending = token;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
         * Add final token.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        if (pending != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            tokenList.add(pending);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
         * An unclosed quote at the end of the command. Do an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
         * implicit end quote.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        if (quoted != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            tokenList.add(quoted);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        String[] tokenArray = new String[tokenList.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        for (int i = 0; i < tokenList.size(); i++) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   130
            tokenArray[i] = tokenList.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        return tokenArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    protected VirtualMachine launch(String[] commandArray, String address,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                                    TransportService.ListenKey listenKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                                    TransportService ts)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                                    throws IOException, VMStartException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        Helper helper = new Helper(commandArray, address, listenKey, ts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        helper.launchAndAccept();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        VirtualMachineManager manager =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            Bootstrap.virtualMachineManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        return manager.createVirtualMachine(helper.connection(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                                            helper.process());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * This class simply provides a context for a single launch and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * accept. It provides instance fields that can be used by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * all threads involved. This stuff can't be in the Connector proper
17484
4ad440adc4b1 8014676: Java debugger may fail to run
dmeetry
parents: 5506
diff changeset
   153
     * because the connector is a singleton and is not specific to any
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * one launch.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    private class Helper {
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   157
        @SuppressWarnings("unused")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        private final String address;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        private TransportService.ListenKey listenKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        private TransportService ts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        private final String[] commandArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        private Process process = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        private Connection connection = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        private IOException acceptException = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        private boolean exited = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        Helper(String[] commandArray, String address, TransportService.ListenKey listenKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            TransportService ts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            this.commandArray = commandArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            this.address = address;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            this.listenKey = listenKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            this.ts = ts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        String commandString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            String str = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            for (int i = 0; i < commandArray.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                if (i > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                    str += " ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                str += commandArray[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            return str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        synchronized void launchAndAccept() throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                                IOException, VMStartException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            process = Runtime.getRuntime().exec(commandArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            Thread acceptingThread = acceptConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            Thread monitoringThread = monitorTarget();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                while ((connection == null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                       (acceptException == null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                       !exited) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                    wait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                if (exited) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                    throw new VMStartException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                        "VM initialization failed for: " + commandString(), process);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                if (acceptException != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                    // Rethrow the exception in this thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                    throw acceptException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                throw new InterruptedIOException("Interrupted during accept");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                acceptingThread.interrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                monitoringThread.interrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        Process process() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            return process;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        Connection connection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            return connection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        synchronized void notifyOfExit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            exited = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            notify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        synchronized void notifyOfConnection(Connection connection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            this.connection = connection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            notify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        synchronized void notifyOfAcceptException(IOException acceptException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            this.acceptException = acceptException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            notify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        Thread monitorTarget() {
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   240
            Thread thread = new Thread(grp, "launched target monitor") {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                        process.waitFor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                         * Notify waiting thread of VM error termination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                        notifyOfExit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                    } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                        // Connection has been established, stop monitoring
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            thread.setDaemon(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            thread.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            return thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        Thread acceptConnection() {
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   259
            Thread thread = new Thread(grp, "connection acceptor") {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                        Connection connection = ts.accept(listenKey, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                         * Notify waiting thread of connection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                        notifyOfConnection(connection);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                    } catch (InterruptedIOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                        // VM terminated, stop accepting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                    } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                        // Report any other exception to waiting thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                        notifyOfAcceptException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            thread.setDaemon(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            thread.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            return thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
}