3261N/A * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * Linux implementation of HotSpotVirtualMachine 4629N/A // "/tmp" is used as a global well-known location for the files 4629N/A // .java_pid<pid>. and .attach_pid<pid>. It is important that this 4629N/A // location is the same for all processes, otherwise the tools 4629N/A // will not be able to find all Hotspot processes. 4629N/A // Any changes to this needs to be synchronized with HotSpot. 0N/A // Indicates if this machine uses the old LinuxThreads 0N/A // The patch to the socket file created by the target VM 0N/A * Attaches to the target VM 0N/A // This provider only understands pids 0N/A // Find the socket file. If not found then we attempt to start the 0N/A // attach mechanism in the target VM by sending it a QUIT signal. 0N/A // Then we attempt to find the socket file again. 0N/A // On LinuxThreads each thread is a process and we don't have the 0N/A // pid of the VMThread which has SIGQUIT unblocked. To workaround 0N/A // this we get the pid of the "manager thread" that is created 0N/A // by the first call to pthread_create. This is parent of all 0N/A // threads (except the initial thread). 0N/A // give the target VM time to start the attach mechanism 0N/A "Unable to open socket file: target process not responding " +
0N/A "or HotSpot VM not loaded");
0N/A // Check that we can connect to the process 0N/A // - this ensures we throw the permission denied error now rather than 0N/A // later when we attempt to enqueue a command. 0N/A * Detach from the target VM 0N/A synchronized (
this) {
0N/A * Execute the given command in the target VM. 0N/A synchronized (
this) {
0N/A // create UNIX socket 0N/A // connect to target VM 0N/A // connected - write request 0N/A // <ver> <cmd> <args...> 0N/A for (
int i=
0; i<
3; i++) {
0N/A // Create an input stream to read reply 0N/A // Read the command completion status 0N/A // In the event of a protocol mismatch then the target VM 0N/A // returns a known error so that we can throw a reasonable 0N/A // Special-case the "load" command so that the right exception is 0N/A // Return the input stream so that the command output can be read 0N/A * InputStream for the socket connection to get target VM 0N/A byte b[] =
new byte[
1];
0N/A // Return the socket file for the given process. 0N/A // On Solaris/Linux a simple handshake is used to start the attach mechanism 0N/A // if not already started. The client creates a .attach_pid<pid> file in the 2458N/A // target VM's working directory (or temp directory), and the SIGQUIT handler 0N/A * Write/sends the given to the target VM. String is transmitted in 0N/A byte b[] =
new byte[
1];