/*
* 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.
*/
// the enqueue code stub (copied into each target VM)
private static byte[] stub;
{
int pid;
try {
} catch (NumberFormatException x) {
throw new AttachNotSupportedException("Invalid process identifier");
}
// The target VM might be a pre-6.0 VM so we enqueue a "null" command
// which minimally tests that the enqueue function exists in the target
// VM.
try {
} catch (IOException x) {
throw new AttachNotSupportedException(x.getMessage());
}
}
synchronized (this) {
if (hProcess != -1) {
hProcess = -1;
}
}
}
throws AgentLoadException, IOException
{
// create a pipe using a random name
// check if we are detached - in theory it's possible that detach is invoked
// after this check but before we enqueue the command.
if (hProcess == -1) {
throw new IOException("Detached from target VM");
}
try {
// enqueue the command to the process
// wait for command to complete - process will connect with the
// completion status
// create an input stream for the pipe
// read completion status
if (status != 0) {
// special case the load command so that the right exception is thrown
throw new AgentLoadException("Failed to load agent library");
} else {
throw new IOException("Command failed in target VM");
}
}
// return the input stream
return is;
} catch (IOException ioe) {
throw ioe;
}
}
// An InputStream based on a pipe to the target VM
private long hPipe;
}
byte b[] = new byte[1];
if (n == 1) {
return b[0] & 0xff;
} else {
return -1;
}
}
throw new IndexOutOfBoundsException();
} else if (len == 0)
return 0;
}
if (hPipe != -1) {
hPipe = -1;
}
}
}
//-- native methods
static native void init();
static native byte[] generateStub();
static {
init(); // native initialization
}
}