Minor performance enhancement on FileInputStream read()
Jing LV
lvjing at linux.vnet.ibm.com
Tue Mar 29 03:38:40 UTC 2011
Hello,
I am reading the code in FileInputStream.read(), I find the current API was:
Java_java_io_RandomAccessFile_read(JNIEnv *env, jobject this)
readSingle(JNIEnv *env, jobject this, jfieldID fid)
It brings a object down into native and as we know reflection costs a
lot. I am wondering if we can improve this.
I see the real pointer is stored in class FileDescriptor, a quick
solution may be:
1. add a method read() in FileDescriptor, and it delgate to a native
method read(fd), fd is the real pointer stored
2. modify readSingle(JNIEnv *env, jobject this, jfieldID fid) to
readSingle(JNIEnv *env, jobject this, jlong fd)
3. add Java_java_io_FileDescriptor_read(JNIEnv *env, jobject this, jlong
fd) in FileDescriptor_md.c, which calls readSingle
As FileDescriptor is used in Socket as well, we may add similar
approach, i.e, readSocket() etc. And this approach may be available for
write and other operations.
Any comments?
--
Best Regards,
Jimmy, Jing LV
More information about the core-libs-dev
mailing list