/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Solaris implementation of HotSpotVirtualMachine.
*/
// "/tmp" is used as a global well-known location for the files
// .java_pid<pid>. and .attach_pid<pid>. It is important that this
// location is the same for all processes, otherwise the tools
// will not be able to find all Hotspot processes.
// Any changes to this needs to be synchronized with HotSpot.
// door descriptor;
/**
* Attaches to the target VM
*/
{
// This provider only understands process-ids (pids).
int pid;
try {
} catch (NumberFormatException x) {
throw new AttachNotSupportedException("invalid process identifier");
}
// Opens the door file to the target VM. If the file is not
// found it might mean that the attach mechanism isn't started in the
// target VM so we attempt to start it and retry.
try {
} catch (FileNotFoundException fnf1) {
try {
// kill -QUIT will tickle target VM to check for the
// attach file.
// give the target VM time to start the attach mechanism
int i = 0;
long delay = 200;
do {
try {
} catch (InterruptedException x) { }
try {
} catch (FileNotFoundException fnf2) { }
i++;
if (fd == -1) {
throw new AttachNotSupportedException(
"Unable to open door: target process not responding or " +
"HotSpot VM not loaded");
}
} finally {
f.delete();
}
}
assert fd >= 0;
}
/**
* Detach from the target VM
*/
synchronized (this) {
if (fd != -1) {
fd = -1;
}
}
}
/**
* Execute the given command in the target VM.
*/
// first check that we are still attached
int door;
synchronized (this) {
if (fd == -1) {
throw new IOException("Detached from target VM");
}
}
// enqueue the command via a door call
assert s >= 0; // valid file descriptor
// The door call returns a file descriptor (one end of a socket pair).
// Create an input stream around it.
// Read the command completion status
int completionStatus;
try {
} catch (IOException ioe) {
throw ioe;
}
// If non-0 it means an error but we need to special-case the
// "load" command to ensure that the right exception is thrown.
if (completionStatus != 0) {
throw new AgentLoadException("Failed to load agent library");
} else {
throw new IOException("Command failed in target VM");
}
}
// Return the input stream so that the command output can be read
return sis;
}
// InputStream over a socket
int s;
public SocketInputStream(int s) {
this.s = s;
}
byte b[] = new byte[1];
if (n == 1) {
return b[0] & 0xff;
} else {
return -1;
}
}
throw new IndexOutOfBoundsException();
} else if (len == 0)
return 0;
}
}
}
// The door is attached to .java_pid<pid> in the temporary directory.
// Check that the file owner/permission to avoid attaching to
// bogus process
try {
} catch (IOException ioe) {
throw ioe;
}
return fd;
}
// if not already started. The client creates a .attach_pid<pid> file in the
// target VM's working directory (or temporary directory), and the SIGQUIT
// handler checks for the file.
try {
f.createNewFile();
} catch (IOException x) {
f.createNewFile();
}
return f;
}
//-- native methods
// enqueue a command (and arguments) to the given door
throws IOException;
static {
}
}