This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Re: Patch: java.nio.DirectBufferImpl.shiftDown()
Am Mittwoch, 21. April 2004 15:50 schrieb Per Bothner:
> Michael Koch wrote:
> > Hi list,
> >
> >
> > On request of some people using java.nio with JNI I made
> > java.nio.DirectBufferImpl.shiftDown() static and removed an
> > unecessary usage of array_offset which is always 0 for direct
> > buffers and is intended only for buffers with backend arrays.
> >
> > Per: whats your opinion about this ?
>
> But what about a ShortViewBufferImpl that is created by calling
> asShortBuffer on a DirectBufferImpl? You're now using the slow
> shiftDown implementation in ByteBuffer instead of the much
> faster native method.
>
> Why do some implementations need DirectBufferImpl.shiftDown to
> be static?
It was requested because its much more easy to implement in JNI.
> A possible solution: To your patch add to DirectBufferImpl:
>
> void shiftDown (int dst_offset, int src_offset, int count)
> {
> shiftDown(address, dst_offset, srd_offset, count);
> }
>
> Same thing in MappedByteBuffer:
>
> void shiftDown (int dst_offset, int src_offset, int count)
> {
> DirectByteBufferImpl.shiftDown(address, dst_offset, srd_offset,
> count); }
Thx for the hint. I added this to the patch.
Ok for commit ?
Michael
2004-04-21 Michael Koch <konqueror@gmx.de>
* java/nio/DirectByteBufferImpl.java
(shiftDown): Made static, give address as argument and
provide a convenience method that overwrites shiftDown in
ByteBufferImpl and calls the native shiftDown.
* java/nio/MappedByteBufferImpl.java
(): Use optimized method in DirectByteBufferImpl.
* java/nio/natDirectByteBufferImpl.cc
(shiftDown): Changed method signature. Removed usage of array_offset.
Index: java/nio/DirectByteBufferImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/DirectByteBufferImpl.java,v
retrieving revision 1.9
diff -u -r1.9 DirectByteBufferImpl.java
--- java/nio/DirectByteBufferImpl.java 20 Apr 2004 14:54:37 -0000 1.9
+++ java/nio/DirectByteBufferImpl.java 21 Apr 2004 14:54:11 -0000
@@ -136,15 +136,20 @@
return this;
}
- native void shiftDown (int dst_offset, int src_offset, int count);
+ static native void shiftDown(RawData address, int dst_offset, int src_offset, int count);
+ void shiftDown(int dst_offset, int src_offset, int count)
+ {
+ shiftDown(address, dst_offset, src_offset, count);
+ }
+
public ByteBuffer compact ()
{
int pos = position();
if (pos > 0)
{
int count = remaining();
- shiftDown(0, pos, count);
+ shiftDown(address, 0, pos, count);
position(count);
limit(capacity());
}
Index: java/nio/MappedByteBufferImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/MappedByteBufferImpl.java,v
retrieving revision 1.8
diff -u -r1.8 MappedByteBufferImpl.java
--- java/nio/MappedByteBufferImpl.java 20 Apr 2004 14:54:37 -0000 1.8
+++ java/nio/MappedByteBufferImpl.java 21 Apr 2004 14:54:11 -0000
@@ -121,7 +121,8 @@
if (pos > 0)
{
int count = remaining();
- shiftDown(0, pos, count);
+ // Call shiftDown method optimized for direct buffers.
+ DirectByteBufferImpl.shiftDown(address, 0, pos, count);
position(count);
limit(capacity());
}
Index: java/nio/natDirectByteBufferImpl.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/natDirectByteBufferImpl.cc,v
retrieving revision 1.4
diff -u -r1.4 natDirectByteBufferImpl.cc
--- java/nio/natDirectByteBufferImpl.cc 16 Feb 2004 20:00:33 -0000 1.4
+++ java/nio/natDirectByteBufferImpl.cc 21 Apr 2004 14:54:11 -0000
@@ -65,9 +65,9 @@
void
java::nio::DirectByteBufferImpl::shiftDown
-(jint dst_offset, jint src_offset, jint count)
+(RawData* address, jint dst_offset, jint src_offset, jint count)
{
- jbyte* dst = reinterpret_cast<jbyte*> (address) + array_offset + dst_offset;
- jbyte* src = reinterpret_cast<jbyte*> (address) + array_offset + src_offset;
+ jbyte* dst = reinterpret_cast<jbyte*> (address) + dst_offset;
+ jbyte* src = reinterpret_cast<jbyte*> (address) + src_offset;
::memmove(dst, src, count);
}