src/jdk.jdi/share/classes/com/sun/tools/jdi/VirtualMachineManagerImpl.java
author dholmes
Sat, 23 Jun 2018 01:32:41 -0400
changeset 50735 2f2af62dfac7
parent 47216 71c04702a3d5
child 54836 e2ed0691ae79
permissions -rw-r--r--
8010319: Implementation of JEP 181: Nest-Based Access Control Reviewed-by: alanb, psandoz, mchung, coleenp, acorn, mcimadamore, forax, jlahoda, sspitsyn, abuckley Contributed-by: alex.buckley@oracle.com, maurizio.mimadamore@oracle.com, mandy.chung@oracle.com, tobias.hartmann@oracle.com, david.holmes@oracle.com, vladimir.x.ivanov@oracle.com, karen.kinnear@oracle.com, vladimir.kozlov@oracle.com, john.r.rose@oracle.com, daniel.smith@oracle.com, serguei.spitsyn@oracle.com, kumardotsrinivasan@gmail.com, boris.ulasevich@bell-sw.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 47216
diff changeset
     2
 * Copyright (c) 1998, 2018, 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: 36511
diff changeset
    28
import java.io.IOException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Iterator;
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    32
import java.util.List;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.ResourceBundle;
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    34
import java.util.ServiceLoader;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    36
import com.sun.jdi.JDIPermission;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    37
import com.sun.jdi.VMDisconnectedException;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    38
import com.sun.jdi.VirtualMachine;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    39
import com.sun.jdi.VirtualMachineManager;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    40
import com.sun.jdi.connect.AttachingConnector;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    41
import com.sun.jdi.connect.Connector;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    42
import com.sun.jdi.connect.LaunchingConnector;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    43
import com.sun.jdi.connect.ListeningConnector;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    44
import com.sun.jdi.connect.spi.Connection;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    45
import com.sun.jdi.connect.spi.TransportService;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
/* Public for use by com.sun.jdi.Bootstrap */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
public class VirtualMachineManagerImpl implements VirtualMachineManagerService {
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    49
    private List<Connector> connectors = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private LaunchingConnector defaultConnector = null;
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
    51
    private List<VirtualMachine> targets = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private final ThreadGroup mainGroupForJDI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private ResourceBundle messages = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private int vmSequenceNumber = 0;
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 47216
diff changeset
    55
    private static final int majorVersion = 11;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    56
    private static final int minorVersion = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private static final Object lock = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private static VirtualMachineManagerImpl vmm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    public static VirtualMachineManager virtualMachineManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            JDIPermission vmmPermission =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                new JDIPermission("virtualMachineManager");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            sm.checkPermission(vmmPermission);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            if (vmm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                vmm = new VirtualMachineManagerImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        return vmm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    protected VirtualMachineManagerImpl() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
         * Create a top-level thread group
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        ThreadGroup top = Thread.currentThread().getThreadGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        ThreadGroup parent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        while ((parent = top.getParent()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            top = parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        mainGroupForJDI = new ThreadGroup(top, "JDI main");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
         * Load the connectors
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        ServiceLoader<Connector> connectorLoader =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            ServiceLoader.load(Connector.class, Connector.class.getClassLoader());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        Iterator<Connector> connectors = connectorLoader.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        while (connectors.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            Connector connector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            try {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   100
                connector = connectors.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            } catch (ThreadDeath x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                throw x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                System.err.println(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            } catch (Error x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                System.err.println(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            addConnector(connector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
         * Load any transport services and encapsulate them with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
         * an attaching and listening connector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        ServiceLoader<TransportService> transportLoader =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            ServiceLoader.load(TransportService.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                               TransportService.class.getClassLoader());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        Iterator<TransportService> transportServices =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            transportLoader.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        while (transportServices.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            TransportService transportService;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            try {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   129
                transportService = transportServices.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            } catch (ThreadDeath x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                throw x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                System.err.println(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            } catch (Error x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                System.err.println(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            addConnector(GenericAttachingConnector.create(transportService));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            addConnector(GenericListeningConnector.create(transportService));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        // no connectors found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        if (allConnectors().size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            throw new Error("no Connectors loaded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        // Set the default launcher. In order to be compatible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        // 1.2/1.3/1.4 we try to make the default launcher
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        // "com.sun.jdi.CommandLineLaunch". If this connector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        // isn't found then we arbitarly pick the first connector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        boolean found = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        List<LaunchingConnector> launchers = launchingConnectors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        for (LaunchingConnector lc: launchers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            if (lc.name().equals("com.sun.jdi.CommandLineLaunch")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                setDefaultConnector(lc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                found = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        if (!found && launchers.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            setDefaultConnector(launchers.get(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public LaunchingConnector defaultConnector() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        if (defaultConnector == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            throw new Error("no default LaunchingConnector");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        return defaultConnector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public void setDefaultConnector(LaunchingConnector connector) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        defaultConnector = connector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public List<LaunchingConnector> launchingConnectors() {
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
   180
        List<LaunchingConnector> launchingConnectors = new ArrayList<>(connectors.size());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        for (Connector connector: connectors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            if (connector instanceof LaunchingConnector) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                launchingConnectors.add((LaunchingConnector)connector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        return Collections.unmodifiableList(launchingConnectors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    public List<AttachingConnector> attachingConnectors() {
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
   190
        List<AttachingConnector> attachingConnectors = new ArrayList<>(connectors.size());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        for (Connector connector: connectors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            if (connector instanceof AttachingConnector) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                attachingConnectors.add((AttachingConnector)connector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        return Collections.unmodifiableList(attachingConnectors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    public List<ListeningConnector> listeningConnectors() {
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 36511
diff changeset
   200
        List<ListeningConnector> listeningConnectors = new ArrayList<>(connectors.size());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        for (Connector connector: connectors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            if (connector instanceof ListeningConnector) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                listeningConnectors.add((ListeningConnector)connector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        return Collections.unmodifiableList(listeningConnectors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public List<Connector> allConnectors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        return Collections.unmodifiableList(connectors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    public List<VirtualMachine> connectedVirtualMachines() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        return Collections.unmodifiableList(targets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public void addConnector(Connector connector) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        connectors.add(connector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    public void removeConnector(Connector connector) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        connectors.remove(connector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    public synchronized VirtualMachine createVirtualMachine(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                                        Connection connection,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                                        Process process) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        if (!connection.isOpen()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            throw new IllegalStateException("connection is not open");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        VirtualMachine vm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            vm = new VirtualMachineImpl(this, connection, process,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                                                   ++vmSequenceNumber);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        } catch (VMDisconnectedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            throw new IOException(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        targets.add(vm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        return vm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public VirtualMachine createVirtualMachine(Connection connection) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        return createVirtualMachine(connection, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    public void addVirtualMachine(VirtualMachine vm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        targets.add(vm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    void disposeVirtualMachine(VirtualMachine vm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        targets.remove(vm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public int majorInterfaceVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        return majorVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public int minorInterfaceVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        return minorVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    ThreadGroup mainGroupForJDI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        return mainGroupForJDI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    String getString(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        if (messages == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            messages = ResourceBundle.getBundle("com.sun.tools.jdi.resources.jdi");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        return messages.getString(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
}