commit-classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

nio-caching.patch (last call for comments)


From: Steven Augart
Subject: nio-caching.patch (last call for comments)
Date: Sun, 20 Jun 2004 12:33:59 -0400
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7b) Gecko/20040421


--
Steven Augart

Jikes RVM, a free, open source, Virtual Machine:
http://oss.software.ibm.com/jikesrvm
This patch was posted to the "classpath" list by David Grove on May 7,
2004.  There's been no comment on it since then.  I approve of it,
with formatting changes to meet the GNU Coding Standards (made in this
version of the patch).  Does anyone else have feedback on it before I
commit it?

The patch's context was that Dave had noticed a performance
degradation of 10% on Jikes RVM's performance on _288_jack on
Classpath 0.09 versus Classpath 0.08.

Part of Dave's original message was:

   Here's a patch.  Works with Jikes RVM and reduces our classpath 0.09
   performance degradation on _228_jack to a slightly more tolerable 5%.

ChangeLog entry:

2004-06-20  David Grove <address@hidden> and Steven Augart <address@hidden>

        * native/jni/java-nio/gnu_java_nio_channels_FileChannelImpl.c:
        Trivial formatting (trim trailing spaces).
        (native_fd_fieldID): New variable.
        (Java_gnu_java_nio_channels_FileChannelImpl_init): 
        Cache native_fd_fieldID. 
        Fix "return with value in function returning void" warning.
        (get_native_fd): Use cached native_fd_fieldID.

Index: native/jni/java-nio/gnu_java_nio_channels_FileChannelImpl.c
===================================================================
RCS file: 
/cvsroot/classpath/classpath/native/jni/java-nio/gnu_java_nio_channels_FileChannelImpl.c,v
retrieving revision 1.10
diff -I*.class -u -r1.10 gnu_java_nio_channels_FileChannelImpl.c
--- native/jni/java-nio/gnu_java_nio_channels_FileChannelImpl.c 1 May 2004 
10:40:56 -0000       1.10
+++ native/jni/java-nio/gnu_java_nio_channels_FileChannelImpl.c 20 Jun 2004 
16:35:22 -0000
@@ -7,7 +7,7 @@
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2, or (at your option)
 any later version.
- 
+
 GNU Classpath 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
@@ -87,26 +87,13 @@
 #define CONVERT_SSIZE_T_TO_JINT(x) ((jint)(x & 0xFFFFFFFF))
 #define CONVERT_JINT_TO_SSIZE_T(x) (x)
 
-static jint get_native_fd(JNIEnv *env, jobject obj)
-{
-  jclass clazz_fc;
-  jfieldID field_fd;
+/* cached fieldID of gnu.java.nio.channels.FileChannelImpl.fd */
+static jfieldID native_fd_fieldID;
 
-  clazz_fc = (*env)->FindClass (env, "gnu/java/nio/channels/FileChannelImpl");
-  if (!clazz_fc)
-    {
-      JCL_ThrowException(env, IO_EXCEPTION, "Internal error");
-      return -1;
-    }
-
-  field_fd = (*env)->GetFieldID (env, clazz_fc, "fd", "I");
-  if (!field_fd)                                                       
-    {                                                                  
-      JCL_ThrowException(env, IO_EXCEPTION, "Internal error");         
-      return -1;                                                       
-    }                                                                  
-
-  return (*env)->GetIntField (env, obj, field_fd);
+static jint
+get_native_fd (JNIEnv *env, jobject obj)
+{
+  return (*env)->GetIntField (env, obj, native_fd_fieldID);
 }
 
 /*
@@ -116,10 +103,28 @@
 JNIEXPORT void JNICALL
 Java_gnu_java_nio_channels_FileChannelImpl_init (JNIEnv *env, jclass clazz)
 {
+  jclass clazz_fc;
   jfieldID field;
   jmethodID constructor;
   jobject obj;
 
+  /* Initialize native_fd_fieldID so we only compute it once! */
+  clazz_fc = (*env)->FindClass (env, "gnu/java/nio/channels/FileChannelImpl");
+  if (!clazz_fc)
+    {
+      JCL_ThrowException(env, IO_EXCEPTION, "Internal error");
+      return;
+    }
+
+  field = (*env)->GetFieldID (env, clazz_fc, "fd", "I");
+  if (!field)
+    {
+      JCL_ThrowException(env, IO_EXCEPTION, "Internal error");         
+      return;
+    }
+
+  native_fd_fieldID = field;
+
   constructor = (*env)->GetMethodID (env, clazz, "<init>", "(II)V");
   if (! constructor)
     return;
@@ -226,7 +231,7 @@
   int result;
 
   native_fd = get_native_fd(env, obj);
-  
+
   TARGET_NATIVE_FILE_CLOSE(native_fd,result);
   if (result != TARGET_NATIVE_OK)
     {
@@ -247,7 +252,7 @@
   int   result;
 
   native_fd = get_native_fd(env, obj);
-  
+
   TARGET_NATIVE_FILE_AVAILABLE(native_fd,bytes_available,result);
   if (result != TARGET_NATIVE_OK)
     {
@@ -330,13 +335,13 @@
 
   /* FIXME: What do we do if offset > the max value of off_t on this 32bit
    * system?  How do we detect that and what do we do? */
-  if (CONVERT_OFF_T_TO_JLONG(native_offset) != offset)  
+  if (CONVERT_OFF_T_TO_JLONG(native_offset) != offset)
     {
       JCL_ThrowException(env, IO_EXCEPTION,
                          "Cannot represent position correctly on this system");
     }
 #endif /* 0 */
-    
+
   result = TARGET_NATIVE_ERROR;
   new_offset = TARGET_NATIVE_MATH_INT_INT64_CONST_MINUS_1;
   TARGET_NATIVE_FILE_SEEK_BEGIN(native_fd, offset, new_offset, result);
@@ -377,7 +382,7 @@
 
   /* FIXME: What do we do if len > the max value of off_t on this 32bit
    * system?  How do we detect that and what do we do? */
-  if (CONVERT_OFF_T_TO_JLONG(native_len) != len)  
+  if (CONVERT_OFF_T_TO_JLONG(native_len) != len)
     {
       JCL_ThrowException(env, IO_EXCEPTION,
                          "Cannot represent position correctly on this system");
@@ -494,7 +499,7 @@
   int     native_fd;
   char    data;
   ssize_t bytes_read;
-  int     result; 
+  int     result;
 
   native_fd = get_native_fd(env, obj);
 
@@ -530,7 +535,7 @@
   jbyte   *bufptr;
   ssize_t bytes_read;
   ssize_t n;
-  int     result; 
+  int     result;
 
   native_fd = get_native_fd(env, obj);
 
@@ -554,7 +559,7 @@
           (*env)->ReleaseByteArrayElements(env, buffer, bufptr, 0);
           if (bytes_read == 0)
             return -1; /* Signal end of file to Java */
-          else 
+          else
             return CONVERT_SSIZE_T_TO_JINT(bytes_read);
         }
       if ((result != TARGET_NATIVE_OK)
@@ -583,7 +588,7 @@
   int     native_fd;
   char    native_data;
   ssize_t bytes_written;
-  int     result; 
+  int     result;
 
   native_fd = get_native_fd(env, obj);
   native_data = (char)(CONVERT_JINT_TO_INT(b) & 0xFF);
@@ -612,10 +617,10 @@
   jbyte   *bufptr;
   ssize_t bytes_written;
   ssize_t n;
-  int     result; 
+  int     result;
 
   native_fd = get_native_fd(env, obj);
-    
+
   bufptr = (*env)->GetByteArrayElements(env, buffer, 0);
   if (!bufptr)
     {

reply via email to

[Prev in Thread] Current Thread [Next in Thread]