I need to locate, recompile and deploy on my JDK running on Linux the following native methods below, from SocketDispatcher.java
:
(Native methods are on the bottom of the code below, so scroll it down please)
package sun.nio.ch;
import java.io.*;
/**
* Allows different platforms to call different native methods
* for read and write operations.
*/
class SocketDispatcher extends NativeDispatcher
{
static {
IOUtil.load();
}
int read(FileDescriptor fd, long address, int len) throws IOException {
return read0(fd, address, len);
}
long readv(FileDescriptor fd, long address, int len) throws IOException {
return readv0(fd, address, len);
}
int write(FileDescriptor fd, long address, int len) throws IOException {
return write0(fd, address, len);
}
long writev(FileDescriptor fd, long address, int len) throws IOException {
return writev0(fd, address, len);
}
void preClose(FileDescriptor fd) throws IOException {
preClose0(fd);
}
void close(FileDescriptor fd) throws IOException {
close0(fd);
}
//-- Native methods
static native int read0(FileDescriptor fd, long address, int len)
throws IOException;
static native long readv0(FileDescriptor fd, long address, int len)
throws IOException;
static native int write0(FileDescriptor fd, long address, int len)
throws IOException;
static native long writev0(FileDescriptor fd, long address, int len)
throws IOException;
static native void preClose0(FileDescriptor fd) throws IOException;
static native void close0(FileDescriptor fd) throws IOException;
}
So basically I want to make the native method write0
print "Hello from native write0!".
Questions:
Where is the C/C++ code for
write0
for Linux?How do I recompile (gcc command-line?) the C/C++ code for
write0
on Linux?How do I start my JVM and make it use my new compiled native code for
write0
on Linux?