harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Ellison <t.p.elli...@gmail.com>
Subject Re: [jira] Created: (HARMONY-6328) [classlib][nio] optimize SocketChannel.write(ByteBuffer[], int, int) by writev
Date Thu, 03 Sep 2009 10:24:54 GMT
On 03/Sep/2009 10:12, Regis wrote:
> Regis Xu (JIRA) wrote:
>> [classlib][nio] optimize SocketChannel.write(ByteBuffer[], int, int)
>> by writev
>> ------------------------------------------------------------------------------
>>                  Key: HARMONY-6328
>>                  URL: https://issues.apache.org/jira/browse/HARMONY-6328
>>              Project: Harmony
>>           Issue Type: Improvement
>>           Components: Classlib
>>     Affects Versions: 5.0M11
>>             Reporter: Regis Xu
>> SocketChannel.write(ByteBuffer[], int, int) can be optimized by using
>> writev, which can write an array of buffer to socket without any stage
>> buffer. If all passed in ByteBuffer is direct buffer, they can be
>> passed to system call directly without any copies.
> I tested the patch on Windows, Linux and AIX, nio tests are all passed.
> I know someone (Oliver, Kevin and Ray) are working on z/OS, I'm not sure
> whether writev  will work on it, so it would be great if someone can
> test the patch on z/OS before committing it.
> And also, any comments and suggestions about this improvement are
> welcome :)

I added a comment to JIRA a moment ago, which says...

Good to see this enhancement!

A minor comment first :-) Please check return values for :

+ vect = (struct iovec*) hymem_allocate_memory(sizeof(struct iovec) *
+ message = (*env)->GetPrimitiveArrayCritical(env, addrs, &isCopyMessage);
+ cts = (*env)->GetPrimitiveArrayCritical(env, counts, &isCopyCts);

A further enhancement is to have two versions of primitives, one that
deals with direct buffers and one that deals with java heap buffers, so
that there is (potentially) no data copying required for the java-heap
buffers version that you have got today:

+ if (!buffer.isDirect()) {
+ src[i] = ByteBuffer.allocateDirect(buffer.remaining());
+ int oldPosition = buffer.position();
+ src[i].put(buffer);

some VMs will pin the java heap memory accessed in JNI
(GetByteArrayElements), so if you can get hold of the ByteBuffer#array()
you can pass a set of pointers to the backing arrays and maybe send the
data directly.

Looking forward to seeing the readv impl too ;-)


View raw message