jdk/src/windows/classes/com/sun/tools/jdi/SharedMemoryTransportService.java
author ohair
Tue, 10 Apr 2012 08:22:03 -0700
changeset 12317 9670c1610c53
parent 5506 202f599c92aa
permissions -rw-r--r--
7074397: Build infrastructure changes (makefile re-write) Summary: New makefiles transition, old and new living side by side for now. Reviewed-by: ohair, jjg, dholmes, ohrstrom, erikj, ihse, tgranat, ykantser Contributed-by: ohrstrom <fredrik.ohrstrom@oracle.com>, erikj <erik.joelsson@oracle.com>, ihse <magnus.ihse.bursie@oracle.com>, tgranat <torbjorn.granat@oracle.com>, ykantser <yekaterina.kantserova@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
12317
9670c1610c53 7074397: Build infrastructure changes (makefile re-write)
ohair
parents: 5506
diff changeset
     2
 * Copyright (c) 1999, 2012, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import com.sun.jdi.connect.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import com.sun.jdi.connect.spi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.ResourceBundle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
class SharedMemoryTransportService extends TransportService {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    private ResourceBundle messages = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
     * The listener returned by startListening
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    static class SharedMemoryListenKey extends ListenKey {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        long id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        SharedMemoryListenKey(long id, String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
            this.id = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
            this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        long id() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            return id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        void setId(long id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            this.id = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        public String address() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            return address();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    SharedMemoryTransportService() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        System.loadLibrary("dt_shmem");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        initialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public String name() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        return "SharedMemory";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public String defaultAddress() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        return "javadebug";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * Return localized description of this transport service
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public String description() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            if (messages == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                messages = ResourceBundle.getBundle("com.sun.tools.jdi.resources.jdi");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        return messages.getString("memory_transportservice.description");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public Capabilities capabilities() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        return new SharedMemoryTransportServiceCapabilities();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private native void initialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private native long startListening0(String address) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private native long attach0(String address, long attachTimeout) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private native void stopListening0(long id) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private native long accept0(long id, long acceptTimeout) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private native String name(long id) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public Connection attach(String address, long attachTimeout, long handshakeTimeout) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        if (address == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            throw new NullPointerException("address is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        long id = attach0(address, attachTimeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        SharedMemoryConnection conn = new SharedMemoryConnection(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        conn.handshake(handshakeTimeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        return conn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public TransportService.ListenKey startListening(String address) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        if (address == null || address.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            address = defaultAddress();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        long id = startListening0(address);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        return new SharedMemoryListenKey(id, name(id));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public ListenKey startListening() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        return startListening(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public void stopListening(ListenKey listener) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        if (!(listener instanceof SharedMemoryListenKey)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            throw new IllegalArgumentException("Invalid listener");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        long id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        SharedMemoryListenKey key = (SharedMemoryListenKey)listener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        synchronized (key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            id = key.id();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            if (id == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                throw new IllegalArgumentException("Invalid listener");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            // invalidate the id
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            key.setId(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        stopListening0(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public Connection accept(ListenKey listener, long acceptTimeout, long handshakeTimeout) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        if (!(listener instanceof SharedMemoryListenKey)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            throw new IllegalArgumentException("Invalid listener");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        long transportId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        SharedMemoryListenKey key = (SharedMemoryListenKey)listener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        synchronized (key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            transportId = key.id();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            if (transportId == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                throw new IllegalArgumentException("Invalid listener");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        // in theory another thread could call stopListening before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        // accept0 is called. In that case accept0 will try to accept
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        // with an invalid "transport id" - this should result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        // IOException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        long connectId = accept0(transportId, acceptTimeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        SharedMemoryConnection conn = new SharedMemoryConnection(connectId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        conn.handshake(handshakeTimeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        return conn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
class SharedMemoryTransportServiceCapabilities extends TransportService.Capabilities {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public boolean supportsMultipleConnections() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    public boolean supportsAttachTimeout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    public boolean supportsAcceptTimeout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    public boolean supportsHandshakeTimeout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
}