src/jdk.attach/linux/classes/sun/tools/attach/VirtualMachineImpl.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 57844 3bc26ffdf001
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
53858
e7cf035682e3 8215622: Add dump to file support for jmap –histo
phh
parents: 52817
diff changeset
     2
 * Copyright (c) 2005, 2019, 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
package sun.tools.attach;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
24363
33b869a8806b 8039173: Propagate errors from Diagnostic Commands as exceptions in the attach framework
sla
parents: 14342
diff changeset
    27
import com.sun.tools.attach.AttachOperationFailedException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import com.sun.tools.attach.AgentLoadException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import com.sun.tools.attach.AttachNotSupportedException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import com.sun.tools.attach.spi.AttachProvider;
24363
33b869a8806b 8039173: Propagate errors from Diagnostic Commands as exceptions in the attach framework
sla
parents: 14342
diff changeset
    31
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.File;
47540
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
    35
import java.nio.charset.StandardCharsets;
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
    36
import java.nio.file.Path;
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
    37
import java.nio.file.Paths;
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
    38
import java.nio.file.Files;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * Linux implementation of HotSpotVirtualMachine
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
26216
5e46c782b43c 8055230: Rename attach provider implementation class be platform neutral
mchung
parents: 25859
diff changeset
    43
public class VirtualMachineImpl extends HotSpotVirtualMachine {
11692
dd4289e8b9e3 7132199: sun/management/jmxremote/bootstrap/JvmstatCountersTest.java failing on all platforms
sla
parents: 10419
diff changeset
    44
    // "/tmp" is used as a global well-known location for the files
dd4289e8b9e3 7132199: sun/management/jmxremote/bootstrap/JvmstatCountersTest.java failing on all platforms
sla
parents: 10419
diff changeset
    45
    // .java_pid<pid>. and .attach_pid<pid>. It is important that this
dd4289e8b9e3 7132199: sun/management/jmxremote/bootstrap/JvmstatCountersTest.java failing on all platforms
sla
parents: 10419
diff changeset
    46
    // location is the same for all processes, otherwise the tools
dd4289e8b9e3 7132199: sun/management/jmxremote/bootstrap/JvmstatCountersTest.java failing on all platforms
sla
parents: 10419
diff changeset
    47
    // will not be able to find all Hotspot processes.
dd4289e8b9e3 7132199: sun/management/jmxremote/bootstrap/JvmstatCountersTest.java failing on all platforms
sla
parents: 10419
diff changeset
    48
    // Any changes to this needs to be synchronized with HotSpot.
dd4289e8b9e3 7132199: sun/management/jmxremote/bootstrap/JvmstatCountersTest.java failing on all platforms
sla
parents: 10419
diff changeset
    49
    private static final String tmpdir = "/tmp";
48485
258a4dab74a7 8188856: Incorrect file path in an exception message when .java_pid is not accessible on Unix
gadams
parents: 47540
diff changeset
    50
    String socket_path;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * Attaches to the target VM
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     */
26216
5e46c782b43c 8055230: Rename attach provider implementation class be platform neutral
mchung
parents: 25859
diff changeset
    54
    VirtualMachineImpl(AttachProvider provider, String vmid)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        throws AttachNotSupportedException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        super(provider, vmid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        // This provider only understands pids
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        int pid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            pid = Integer.parseInt(vmid);
57844
3bc26ffdf001 8229957: Harden pid verification in attach mechanism
lmesnik
parents: 55685
diff changeset
    63
            if (pid < 1) {
3bc26ffdf001 8229957: Harden pid verification in attach mechanism
lmesnik
parents: 55685
diff changeset
    64
                throw new NumberFormatException();
3bc26ffdf001 8229957: Harden pid verification in attach mechanism
lmesnik
parents: 55685
diff changeset
    65
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        } catch (NumberFormatException x) {
57844
3bc26ffdf001 8229957: Harden pid verification in attach mechanism
lmesnik
parents: 55685
diff changeset
    67
            throw new AttachNotSupportedException("Invalid process identifier: " + vmid);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
47540
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
    70
        // Try to resolve to the "inner most" pid namespace
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
    71
        int ns_pid = getNamespacePid(pid);
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
    72
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        // Find the socket file. If not found then we attempt to start the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        // attach mechanism in the target VM by sending it a QUIT signal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        // Then we attempt to find the socket file again.
48485
258a4dab74a7 8188856: Incorrect file path in an exception message when .java_pid is not accessible on Unix
gadams
parents: 47540
diff changeset
    76
        File socket_file = findSocketFile(pid, ns_pid);
258a4dab74a7 8188856: Incorrect file path in an exception message when .java_pid is not accessible on Unix
gadams
parents: 47540
diff changeset
    77
        socket_path = socket_file.getPath();
258a4dab74a7 8188856: Incorrect file path in an exception message when .java_pid is not accessible on Unix
gadams
parents: 47540
diff changeset
    78
        if (!socket_file.exists()) {
47540
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
    79
            File f = createAttachFile(pid, ns_pid);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            try {
40685
e6f3a9fff607 8157236: attach on ARMv7 fails with com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file
dsamersoff
parents: 26216
diff changeset
    81
                sendQuitTo(pid);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                // give the target VM time to start the attach mechanism
40685
e6f3a9fff607 8157236: attach on ARMv7 fails with com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file
dsamersoff
parents: 26216
diff changeset
    84
                final int delay_step = 100;
e6f3a9fff607 8157236: attach on ARMv7 fails with com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file
dsamersoff
parents: 26216
diff changeset
    85
                final long timeout = attachTimeout();
e6f3a9fff607 8157236: attach on ARMv7 fails with com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file
dsamersoff
parents: 26216
diff changeset
    86
                long time_spend = 0;
e6f3a9fff607 8157236: attach on ARMv7 fails with com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file
dsamersoff
parents: 26216
diff changeset
    87
                long delay = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                do {
40685
e6f3a9fff607 8157236: attach on ARMv7 fails with com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file
dsamersoff
parents: 26216
diff changeset
    89
                    // Increase timeout on each attempt to reduce polling
e6f3a9fff607 8157236: attach on ARMv7 fails with com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file
dsamersoff
parents: 26216
diff changeset
    90
                    delay += delay_step;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                        Thread.sleep(delay);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                    } catch (InterruptedException x) { }
40685
e6f3a9fff607 8157236: attach on ARMv7 fails with com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file
dsamersoff
parents: 26216
diff changeset
    94
e6f3a9fff607 8157236: attach on ARMv7 fails with com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file
dsamersoff
parents: 26216
diff changeset
    95
                    time_spend += delay;
48485
258a4dab74a7 8188856: Incorrect file path in an exception message when .java_pid is not accessible on Unix
gadams
parents: 47540
diff changeset
    96
                    if (time_spend > timeout/2 && !socket_file.exists()) {
40685
e6f3a9fff607 8157236: attach on ARMv7 fails with com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file
dsamersoff
parents: 26216
diff changeset
    97
                        // Send QUIT again to give target VM the last chance to react
e6f3a9fff607 8157236: attach on ARMv7 fails with com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file
dsamersoff
parents: 26216
diff changeset
    98
                        sendQuitTo(pid);
e6f3a9fff607 8157236: attach on ARMv7 fails with com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file
dsamersoff
parents: 26216
diff changeset
    99
                    }
48485
258a4dab74a7 8188856: Incorrect file path in an exception message when .java_pid is not accessible on Unix
gadams
parents: 47540
diff changeset
   100
                } while (time_spend <= timeout && !socket_file.exists());
258a4dab74a7 8188856: Incorrect file path in an exception message when .java_pid is not accessible on Unix
gadams
parents: 47540
diff changeset
   101
                if (!socket_file.exists()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                    throw new AttachNotSupportedException(
40685
e6f3a9fff607 8157236: attach on ARMv7 fails with com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file
dsamersoff
parents: 26216
diff changeset
   103
                        String.format("Unable to open socket file %s: " +
e6f3a9fff607 8157236: attach on ARMv7 fails with com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file
dsamersoff
parents: 26216
diff changeset
   104
                          "target process %d doesn't respond within %dms " +
48485
258a4dab74a7 8188856: Incorrect file path in an exception message when .java_pid is not accessible on Unix
gadams
parents: 47540
diff changeset
   105
                          "or HotSpot VM not loaded", socket_path, pid,
258a4dab74a7 8188856: Incorrect file path in an exception message when .java_pid is not accessible on Unix
gadams
parents: 47540
diff changeset
   106
                                      time_spend));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                f.delete();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            }
49742
1196aa0be8be 8201247: Various cleanups in the attach framework
clanger
parents: 48485
diff changeset
   111
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        // Check that the file owner/permission to avoid attaching to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        // bogus process
48485
258a4dab74a7 8188856: Incorrect file path in an exception message when .java_pid is not accessible on Unix
gadams
parents: 47540
diff changeset
   115
        checkPermissions(socket_path);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        // Check that we can connect to the process
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        // - this ensures we throw the permission denied error now rather than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        // later when we attempt to enqueue a command.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        int s = socket();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        try {
48485
258a4dab74a7 8188856: Incorrect file path in an exception message when .java_pid is not accessible on Unix
gadams
parents: 47540
diff changeset
   122
            connect(s, socket_path);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            close(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Detach from the target VM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public void detach() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        synchronized (this) {
48485
258a4dab74a7 8188856: Incorrect file path in an exception message when .java_pid is not accessible on Unix
gadams
parents: 47540
diff changeset
   133
            if (socket_path != null) {
258a4dab74a7 8188856: Incorrect file path in an exception message when .java_pid is not accessible on Unix
gadams
parents: 47540
diff changeset
   134
                socket_path = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    // protocol version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    private final static String PROTOCOL_VERSION = "1";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    // known errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    private final static int ATTACH_ERROR_BADVERSION = 101;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * Execute the given command in the target VM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    InputStream execute(String cmd, Object ... args) throws AgentLoadException, IOException {
54065
f984aca565c1 8219721: jcmd from earlier release will hang attaching to VM with JDK-8215622 applied
dholmes
parents: 53858
diff changeset
   149
        assert args.length <= 3;                // includes null
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        // did we detach?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        synchronized (this) {
48485
258a4dab74a7 8188856: Incorrect file path in an exception message when .java_pid is not accessible on Unix
gadams
parents: 47540
diff changeset
   153
            if (socket_path == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                throw new IOException("Detached from target VM");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        // create UNIX socket
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        int s = socket();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        // connect to target VM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        try {
48485
258a4dab74a7 8188856: Incorrect file path in an exception message when .java_pid is not accessible on Unix
gadams
parents: 47540
diff changeset
   163
            connect(s, socket_path);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        } catch (IOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            close(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            throw x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        IOException ioe = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        // connected - write request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        // <ver> <cmd> <args...>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            writeString(s, PROTOCOL_VERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            writeString(s, cmd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
54065
f984aca565c1 8219721: jcmd from earlier release will hang attaching to VM with JDK-8215622 applied
dholmes
parents: 53858
diff changeset
   177
            for (int i = 0; i < 3; i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                if (i < args.length && args[i] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                    writeString(s, (String)args[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                    writeString(s, "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        } catch (IOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            ioe = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        // Create an input stream to read reply
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        SocketInputStream sis = new SocketInputStream(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        // Read the command completion status
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        int completionStatus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            completionStatus = readInt(sis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        } catch (IOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            sis.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            if (ioe != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                throw ioe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                throw x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if (completionStatus != 0) {
24363
33b869a8806b 8039173: Propagate errors from Diagnostic Commands as exceptions in the attach framework
sla
parents: 14342
diff changeset
   206
            // read from the stream and use that as the error message
33b869a8806b 8039173: Propagate errors from Diagnostic Commands as exceptions in the attach framework
sla
parents: 14342
diff changeset
   207
            String message = readErrorMessage(sis);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            sis.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            // In the event of a protocol mismatch then the target VM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            // returns a known error so that we can throw a reasonable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            // error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            if (completionStatus == ATTACH_ERROR_BADVERSION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                throw new IOException("Protocol mismatch with target VM");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            // Special-case the "load" command so that the right exception is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            // thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            if (cmd.equals("load")) {
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 40943
diff changeset
   220
                String msg = "Failed to load agent library";
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 40943
diff changeset
   221
                if (!message.isEmpty())
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 40943
diff changeset
   222
                    msg += ": " + message;
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 40943
diff changeset
   223
                throw new AgentLoadException(msg);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            } else {
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 40943
diff changeset
   225
                if (message.isEmpty())
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 40943
diff changeset
   226
                    message = "Command failed in target VM";
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 40943
diff changeset
   227
                throw new AttachOperationFailedException(message);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        // Return the input stream so that the command output can be read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        return sis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * InputStream for the socket connection to get target VM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    private class SocketInputStream extends InputStream {
55443
99b604ec1af6 8224642: Test sun/tools/jcmd/TestJcmdSanity.java fails: Bad file descriptor
gadams
parents: 54065
diff changeset
   239
        int s = -1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        public SocketInputStream(int s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            this.s = s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        public synchronized int read() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            byte b[] = new byte[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            int n = this.read(b, 0, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            if (n == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                return b[0] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        public synchronized int read(byte[] bs, int off, int len) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            if ((off < 0) || (off > bs.length) || (len < 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                ((off + len) > bs.length) || ((off + len) < 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                throw new IndexOutOfBoundsException();
48485
258a4dab74a7 8188856: Incorrect file path in an exception message when .java_pid is not accessible on Unix
gadams
parents: 47540
diff changeset
   259
            } else if (len == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                return 0;
48485
258a4dab74a7 8188856: Incorrect file path in an exception message when .java_pid is not accessible on Unix
gadams
parents: 47540
diff changeset
   261
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
26216
5e46c782b43c 8055230: Rename attach provider implementation class be platform neutral
mchung
parents: 25859
diff changeset
   263
            return VirtualMachineImpl.read(s, bs, off, len);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
55685
56b96d234f26 8227440: Implement fix to JDK-8224642 on all platforms
rschmelter
parents: 55443
diff changeset
   266
        public synchronized void close() throws IOException {
56b96d234f26 8227440: Implement fix to JDK-8224642 on all platforms
rschmelter
parents: 55443
diff changeset
   267
            if (s != -1) {
56b96d234f26 8227440: Implement fix to JDK-8224642 on all platforms
rschmelter
parents: 55443
diff changeset
   268
                int toClose = s;
56b96d234f26 8227440: Implement fix to JDK-8224642 on all platforms
rschmelter
parents: 55443
diff changeset
   269
                s = -1;
56b96d234f26 8227440: Implement fix to JDK-8224642 on all platforms
rschmelter
parents: 55443
diff changeset
   270
                VirtualMachineImpl.close(toClose);
55443
99b604ec1af6 8224642: Test sun/tools/jcmd/TestJcmdSanity.java fails: Bad file descriptor
gadams
parents: 54065
diff changeset
   271
            }
2
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
    // Return the socket file for the given process.
48485
258a4dab74a7 8188856: Incorrect file path in an exception message when .java_pid is not accessible on Unix
gadams
parents: 47540
diff changeset
   276
    private File findSocketFile(int pid, int ns_pid) {
47540
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   277
        // A process may not exist in the same mount namespace as the caller.
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   278
        // Instead, attach relative to the target root filesystem as exposed by
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   279
        // procfs regardless of namespaces.
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   280
        String root = "/proc/" + pid + "/root/" + tmpdir;
48485
258a4dab74a7 8188856: Incorrect file path in an exception message when .java_pid is not accessible on Unix
gadams
parents: 47540
diff changeset
   281
        return new File(root, ".java_pid" + ns_pid);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
49742
1196aa0be8be 8201247: Various cleanups in the attach framework
clanger
parents: 48485
diff changeset
   284
    // On Linux a simple handshake is used to start the attach mechanism
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    // if not already started. The client creates a .attach_pid<pid> file in the
5771
1f415c7e277d 6950927: Testcase failure sun/management/jmxremote/bootstrap/JvmstatCountersTest.java
alanb
parents: 5506
diff changeset
   286
    // target VM's working directory (or temp directory), and the SIGQUIT handler
1f415c7e277d 6950927: Testcase failure sun/management/jmxremote/bootstrap/JvmstatCountersTest.java
alanb
parents: 5506
diff changeset
   287
    // checks for the file.
47540
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   288
    private File createAttachFile(int pid, int ns_pid) throws IOException {
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   289
        String fn = ".attach_pid" + ns_pid;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        String path = "/proc/" + pid + "/cwd/" + fn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        File f = new File(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        try {
52817
981eb3c1b90d 8214300: .attach_pid files may remain in the process cwd
gadams
parents: 49742
diff changeset
   293
            f = f.getCanonicalFile();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            f.createNewFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        } catch (IOException x) {
47540
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   296
            String root;
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   297
            if (pid != ns_pid) {
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   298
                // A process may not exist in the same mount namespace as the caller.
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   299
                // Instead, attach relative to the target root filesystem as exposed by
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   300
                // procfs regardless of namespaces.
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   301
                root = "/proc/" + pid + "/root/" + tmpdir;
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   302
            } else {
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   303
                root = tmpdir;
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   304
            }
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   305
            f = new File(root, fn);
52817
981eb3c1b90d 8214300: .attach_pid files may remain in the process cwd
gadams
parents: 49742
diff changeset
   306
            f = f.getCanonicalFile();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            f.createNewFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        return f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * Write/sends the given to the target VM. String is transmitted in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * UTF-8 encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    private void writeString(int fd, String s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        if (s.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            byte b[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                b = s.getBytes("UTF-8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            } catch (java.io.UnsupportedEncodingException x) {
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 7668
diff changeset
   322
                throw new InternalError(x);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            }
26216
5e46c782b43c 8055230: Rename attach provider implementation class be platform neutral
mchung
parents: 25859
diff changeset
   324
            VirtualMachineImpl.write(fd, b, 0, b.length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        byte b[] = new byte[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        b[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        write(fd, b, 0, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
47540
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   332
    // Return the inner most namespaced PID if there is one,
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   333
    // otherwise return the original PID.
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   334
    private int getNamespacePid(int pid) throws AttachNotSupportedException, IOException {
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   335
        // Assuming a real procfs sits beneath, reading this doesn't block
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   336
        // nor will it consume a lot of memory.
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   337
        String statusFile = "/proc/" + pid + "/status";
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   338
        File f = new File(statusFile);
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   339
        if (!f.exists()) {
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   340
            return pid; // Likely a bad pid, but this is properly handled later.
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   341
        }
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   342
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   343
        Path statusPath = Paths.get(statusFile);
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   344
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   345
        try {
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   346
            for (String line : Files.readAllLines(statusPath, StandardCharsets.UTF_8)) {
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   347
                String[] parts = line.split(":");
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   348
                if (parts.length == 2 && parts[0].trim().equals("NSpid")) {
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   349
                    parts = parts[1].trim().split("\\s+");
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   350
                    // The last entry represents the PID the JVM "thinks" it is.
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   351
                    // Even in non-namespaced pids these entries should be
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   352
                    // valid. You could refer to it as the inner most pid.
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   353
                    int ns_pid = Integer.parseInt(parts[parts.length - 1]);
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   354
                    return ns_pid;
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   355
                }
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   356
            }
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   357
            // Old kernels may not have NSpid field (i.e. 3.10).
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   358
            // Fallback to original pid in the event we cannot deduce.
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   359
            return pid;
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   360
        } catch (NumberFormatException | IOException x) {
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   361
            throw new AttachNotSupportedException("Unable to parse namespace");
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   362
        }
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   363
    }
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   364
7242ab15b6a5 8179498: attach in linux should be relative to /proc/pid/root and namespace aware
cjplummer
parents: 47216
diff changeset
   365
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    //-- native methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    static native void sendQuitTo(int pid) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    static native void checkPermissions(String path) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    static native int socket() throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    static native void connect(int fd, String path) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    static native void close(int fd) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    static native int read(int fd, byte buf[], int off, int bufLen) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    static native void write(int fd, byte buf[], int off, int bufLen) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        System.loadLibrary("attach");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
}