When tuning the Escher peers, I did some optimizations on the
LocalSockets, which is passing the fd as argument to the JNI code,
instead of looking it up on each call.
2006-07-11 Roman Kennke <[EMAIL PROTECTED]>
* native/jni/java-net/gnu_java_net_local_LocalSocketImpl.c
(available): Pass fd as argument and avoid JNI class/field
lookup.
(read): Likewise.
(write): Likewise.
* include/gnu_java_net_local_LocalSocketImpl.h:
Regenerated.
* gnu/java/net/local/LocalSocketImpl.h
(available): Pass fd as argument and avoid JNI class/field
lookup.
(read): Likewise.
(write): Likewise.
/Roman
Index: include/gnu_java_net_local_LocalSocketImpl.h
===================================================================
RCS file: /cvsroot/classpath/classpath/include/gnu_java_net_local_LocalSocketImpl.h,v
retrieving revision 1.1
diff -u -1 -2 -r1.1 gnu_java_net_local_LocalSocketImpl.h
--- include/gnu_java_net_local_LocalSocketImpl.h 16 Apr 2006 21:54:09 -0000 1.1
+++ include/gnu_java_net_local_LocalSocketImpl.h 11 Jul 2006 19:49:26 -0000
@@ -4,28 +4,28 @@
#define __gnu_java_net_local_LocalSocketImpl__
#include <jni.h>
#ifdef __cplusplus
extern "C"
{
#endif
JNIEXPORT void JNICALL Java_gnu_java_net_local_LocalSocketImpl_create (JNIEnv *env, jobject, jboolean);
JNIEXPORT void JNICALL Java_gnu_java_net_local_LocalSocketImpl_listen (JNIEnv *env, jobject, jint);
JNIEXPORT void JNICALL Java_gnu_java_net_local_LocalSocketImpl_accept (JNIEnv *env, jobject, jobject);
-JNIEXPORT jint JNICALL Java_gnu_java_net_local_LocalSocketImpl_available (JNIEnv *env, jobject);
+JNIEXPORT jint JNICALL Java_gnu_java_net_local_LocalSocketImpl_available (JNIEnv *env, jobject, jint);
JNIEXPORT void JNICALL Java_gnu_java_net_local_LocalSocketImpl_close (JNIEnv *env, jobject);
JNIEXPORT void JNICALL Java_gnu_java_net_local_LocalSocketImpl_sendUrgentData (JNIEnv *env, jobject, jint);
JNIEXPORT void JNICALL Java_gnu_java_net_local_LocalSocketImpl_shutdownInput (JNIEnv *env, jobject);
JNIEXPORT void JNICALL Java_gnu_java_net_local_LocalSocketImpl_shutdownOutput (JNIEnv *env, jobject);
JNIEXPORT void JNICALL Java_gnu_java_net_local_LocalSocketImpl_unlink (JNIEnv *env, jobject);
JNIEXPORT void JNICALL Java_gnu_java_net_local_LocalSocketImpl_localBind (JNIEnv *env, jobject, jobject);
JNIEXPORT void JNICALL Java_gnu_java_net_local_LocalSocketImpl_localConnect (JNIEnv *env, jobject, jobject);
-JNIEXPORT jint JNICALL Java_gnu_java_net_local_LocalSocketImpl_read (JNIEnv *env, jobject, jbyteArray, jint, jint);
-JNIEXPORT void JNICALL Java_gnu_java_net_local_LocalSocketImpl_write (JNIEnv *env, jobject, jbyteArray, jint, jint);
+JNIEXPORT jint JNICALL Java_gnu_java_net_local_LocalSocketImpl_read (JNIEnv *env, jobject, jint, jbyteArray, jint, jint);
+JNIEXPORT void JNICALL Java_gnu_java_net_local_LocalSocketImpl_write (JNIEnv *env, jobject, jint, jbyteArray, jint, jint);
#ifdef __cplusplus
}
#endif
#endif /* __gnu_java_net_local_LocalSocketImpl__ */
Index: native/jni/java-net/gnu_java_net_local_LocalSocketImpl.c
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/java-net/gnu_java_net_local_LocalSocketImpl.c,v
retrieving revision 1.1
diff -u -1 -2 -r1.1 gnu_java_net_local_LocalSocketImpl.c
--- native/jni/java-net/gnu_java_net_local_LocalSocketImpl.c 16 Apr 2006 21:54:09 -0000 1.1
+++ native/jni/java-net/gnu_java_net_local_LocalSocketImpl.c 11 Jul 2006 19:49:26 -0000
@@ -191,51 +191,45 @@
(*env)->SetObjectField (env, socket, local_addr, local);
TRACE("end");
#else
(void) this;
(void) socket;
_throw (env, "java/lang/Error", "support for local sockets not available");
#endif /* ENABLE_LOCAL_SOCKETS */
}
jint
-Java_gnu_java_net_local_LocalSocketImpl_available (JNIEnv *env, jobject this)
+Java_gnu_java_net_local_LocalSocketImpl_available
+(JNIEnv *env, jobject this __attribute__((unused)), jint fd)
{
#ifdef ENABLE_LOCAL_SOCKETS
- jfieldID socket_fd;
- jclass clazz;
jint avail;
TRACE("begin");
- clazz = (*env)->GetObjectClass (env, this);
- socket_fd = (*env)->GetFieldID (env, clazz, "socket_fd", "I");
- if (!socket_fd)
- {
- return 0;
- }
- avail = (jint) local_available ((int) (*env)->GetIntField (env, this, socket_fd));
+ avail = (jint) local_available (fd);
if (avail < 0)
{
_throw (env, "java/io/IOException", local_error ());
return 0;
}
TRACE("end");
return avail;
#else
(void) this;
+ (void) fd;
_throw (env, "java/lang/Error", "support for local sockets not available");
return -1;
#endif /* ENABLE_LOCAL_SOCKETS */
}
void
Java_gnu_java_net_local_LocalSocketImpl_close (JNIEnv *env, jobject this)
{
#ifdef ENABLE_LOCAL_SOCKETS
jfieldID socket_fd;
jclass clazz;
@@ -443,92 +437,76 @@
(*env)->ReleaseStringUTFChars (env, (jstring) path, addr_path);
TRACE("end");
#else
(void) this;
(void) address;
_throw (env, "java/lang/Error", "support for local sockets not available");
#endif /* ENABLE_LOCAL_SOCKETS */
}
jint
-Java_gnu_java_net_local_LocalSocketImpl_read (JNIEnv *env, jobject this, jbyteArray buf, jint off, jint len)
+Java_gnu_java_net_local_LocalSocketImpl_read
+(JNIEnv *env, jobject this __attribute__((unused)), jint fd, jbyteArray buf,
+ jint off, jint len)
{
#ifdef ENABLE_LOCAL_SOCKETS
- jfieldID socket_fd;
- jclass clazz;
jbyte *buffer;
jint count;
- int fd;
TRACE("begin");
if (off < 0 || len < 0 || off + len > (*env)->GetArrayLength (env, buf))
{
_throw (env, "java/lang/ArrayIndexOutOfBoundsException", "");
}
- clazz = (*env)->GetObjectClass (env, this);
- socket_fd = (*env)->GetFieldID (env, clazz, "socket_fd", "I");
- if (!socket_fd)
- {
- return 0;
- }
- fd = (int) (*env)->GetIntField (env, this, socket_fd);
buffer = (*env)->GetByteArrayElements (env, buf, NULL);
count = (jint) local_read (fd, (void *) (buffer + off), (int) len);
if (count < 0)
{
_throw (env, "java/io/IOException", local_error ());
}
(*env)->ReleaseByteArrayElements (env, buf, buffer, 0);
TRACE("end");
return count;
#else
(void) this;
(void) buf;
(void) off;
(void) len;
_throw (env, "java/lang/Error", "support for local sockets not available");
return -1;
#endif /* ENABLE_LOCAL_SOCKETS */
}
void
-Java_gnu_java_net_local_LocalSocketImpl_write (JNIEnv *env, jobject this, jbyteArray buf, jint off, jint len)
+Java_gnu_java_net_local_LocalSocketImpl_write
+(JNIEnv *env, jobject this __attribute__((unused)), jint fd, jbyteArray buf,
+ jint off, jint len)
{
#ifdef ENABLE_LOCAL_SOCKETS
- jfieldID socket_fd;
- jclass clazz;
jbyte *buffer;
- int fd;
TRACE("begin");
if (off < 0 || len < 0 || off + len > (*env)->GetArrayLength (env, buf))
{
_throw (env, "java/lang/ArrayIndexOutOfBoundsException", "");
}
- clazz = (*env)->GetObjectClass (env, this);
- socket_fd = (*env)->GetFieldID (env, clazz, "socket_fd", "I");
- if (!socket_fd)
- {
- return;
- }
- fd = (int) (*env)->GetIntField (env, this, socket_fd);
buffer = (*env)->GetByteArrayElements (env, buf, NULL);
if (local_write (fd, (void *) (buffer + off), (int) len) < 0)
{
_throw (env, "java/io/IOException", local_error ());
}
(*env)->ReleaseByteArrayElements (env, buf, buffer, JNI_ABORT);
TRACE("end");
#else
(void) this;
(void) buf;
(void) off;
Index: gnu/java/net/local/LocalSocketImpl.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/net/local/LocalSocketImpl.java,v
retrieving revision 1.1
diff -u -1 -2 -r1.1 LocalSocketImpl.java
--- gnu/java/net/local/LocalSocketImpl.java 16 Apr 2006 21:54:09 -0000 1.1
+++ gnu/java/net/local/LocalSocketImpl.java 11 Jul 2006 19:49:26 -0000
@@ -48,25 +48,26 @@
import java.net.SocketException;
import java.net.SocketImpl;
final class LocalSocketImpl extends SocketImpl
{
// Fields.
// -------------------------------------------------------------------------
private boolean created;
private InputStream in;
private OutputStream out;
- private int socket_fd;
+ // Package private to avoid synthetic accessor method.
+ int socket_fd;
private LocalSocketAddress local;
private LocalSocketAddress remote;
static
{
try
{
System.loadLibrary ("javanet");
}
catch (Exception x)
{
x.printStackTrace ();
@@ -95,35 +96,41 @@
{
throw new SocketException ("local sockets do not support options");
}
public Object getOption (int opt) throws SocketException
{
throw new SocketException ("local sockets do not support options");
}
protected native void create (boolean stream) throws IOException;
protected native void listen (int timeout) throws IOException;
protected native void accept (LocalSocketImpl socket) throws IOException;
- protected native int available () throws IOException;
+ protected native int available (int fd) throws IOException;
protected native void close () throws IOException;
protected native void sendUrgentData (int data) throws IOException;
protected native void shutdownInput () throws IOException;
protected native void shutdownOutput () throws IOException;
native void unlink () throws IOException;
native void localBind (LocalSocketAddress addr) throws IOException;
native void localConnect (LocalSocketAddress addr) throws IOException;
- native int read (byte[] buf, int off, int len) throws IOException;
- native void write (byte[] buf, int off, int len) throws IOException;
+ native int read (int fd, byte[] buf, int off, int len) throws IOException;
+ native void write (int fd, byte[] buf, int off, int len) throws IOException;
+
+ protected int available()
+ throws IOException
+ {
+ return available(socket_fd);
+ }
void doCreate () throws IOException
{
if (!created)
{
create (true);
}
}
LocalSocketAddress getLocalAddress ()
{
return local;
@@ -254,25 +261,25 @@
{
return -1;
}
}
public int read (byte[] buf) throws IOException
{
return read (buf, 0, buf.length);
}
public int read (byte[] buf, int off, int len) throws IOException
{
- int ret = impl.read (buf, off, len);
+ int ret = impl.read (socket_fd, buf, off, len);
if (ret == 0)
{
return -1;
}
return ret;
}
}
class LocalOutputStream extends OutputStream
{
@@ -307,16 +314,16 @@
byte[] buf = new byte [1];
buf[0] = (byte) b;
write (buf);
}
public void write (byte[] buf) throws IOException
{
write (buf, 0, buf.length);
}
public void write (byte[] buf, int off, int len) throws IOException
{
- impl.write (buf, off, len);
+ impl.write (socket_fd, buf, off, len);
}
}
}