JDK-4676548 : (bf) Buffer-put operations too slow when direct and non-direct buffers are mixed
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 1.4.1
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2002-04-29
  • Updated: 2002-06-14
  • Resolved: 2002-05-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.1 betaFixed
Related Reports
Relates :  
Description
import java.io.*;
import java.nio.*;


public class BufferPutSpeed {

    static PrintStream log = System.out;

    static final int N = 100;

    static String type(ByteBuffer b) {
	return b.isDirect() ? "dir" : "heap";
    }

    static void go(ByteBuffer src, ByteBuffer dst) {
	log.print(type(src) + " --> " + type(dst) + "\t");
	long start = System.currentTimeMillis();
	for (int i = 0; i < N; i++) {
	    src.clear();
	    dst.clear();
	    dst.put(src);
	}
	log.println(System.currentTimeMillis() - start);
    }

    public static void main(String[] args) {
	ByteBuffer bbh1 = ByteBuffer.allocate(1 << 20);
	ByteBuffer bbh2 = ByteBuffer.allocate(1 << 20);
	ByteBuffer bbd1 = ByteBuffer.allocateDirect(1 << 20);
	ByteBuffer bbd2 = ByteBuffer.allocateDirect(1 << 20);
	go(bbd1, bbd2);
	go(bbd1, bbh1);
	go(bbh1, bbd1);
	go(bbh1, bbh2);
    }

}


% jr BufferPutSpeed
dir --> dir     412
dir --> heap    3802
heap --> dir    4360
heap --> heap   411
% 

In addition to slowing down pure buffer operations, this discrepancy is also
visible when doing channel reads and writes with non-direct buffers.

-- ###@###.### 2002/4/29

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: hopper-beta FIXED IN: hopper-beta INTEGRATED IN: hopper-beta VERIFIED IN: hopper
14-06-2004

SUGGESTED FIX ---- ./src/share/classes/java/nio/Direct-X-Buffer.java *** /tmp/19842aaa Mon Apr 29 12:43:38 2002 --- Direct-X-Buffer.java Mon Apr 29 12:29:57 2002 *************** *** 267,272 **** --- 267,282 ---- unsafe.copyMemory(sb.ix(spos), ix(pos), srem << $LG_BYTES_PER_VALUE$); sb.position(spos + srem); position(pos + srem); + } else if (!src.isDirect()) { + + int spos = src.position(); + int slim = src.limit(); + assert (spos <= slim); + int srem = (spos <= slim ? slim - spos : 0); + + put(src.array(), src.arrayOffset() + spos, srem); + src.position(spos + srem); + } else { super.put(src); } ---- ./src/share/classes/java/nio/Heap-X-Buffer.java *** /tmp/19955aaa Mon Apr 29 12:43:38 2002 --- Heap-X-Buffer.java Mon Apr 29 12:32:32 2002 *************** *** 184,189 **** --- 184,194 ---- hb, ix(position()), n); sb.position(sb.position() + n); position(position() + n); + } else if (src.isDirect()) { + int n = src.remaining(); + if (n > remaining()) + throw new BufferOverflowException(); + src.get(hb, ix(position()), n); } else { super.put(src); }
11-06-2004

EVALUATION % /w/nio/build/bin/java BufferPutSpeed dir --> dir 383 dir --> heap 374 heap --> dir 382 heap --> heap 379 % -- ###@###.### 2002/4/29
04-10-0195