8219014: (bf) Add absolute bulk put methods which accept a source Buffer

Paul Sandoz paul.sandoz at oracle.com
Thu Feb 6 19:32:07 UTC 2020


I think an absolute bulk put method is useful (see below for caveat).  

There is some inconsistency with the existing relative bulk specifications and implementations when this and the source buffers overlap. The loopy implementation overwrites but heap buffers defer to System.arraycopy and direct buffers defer to UNSAFE.copyMemory, I believe both make temporary copies on overlapping regions.  I am uncertain about when the loopy version is called.  

—

The new MemorySegment API supports creating segment views from buffers, from which a bulk copy can be performed using memory address within those segments (overlapping ranges create temporary copies).

This gives me pause on such enhancements to Buffers.  There is some tedious amount of work required to ensure all buffer implementations do the right thing. But, work required by a developer to transition from the buffer domain to segment and address domain is not so trivial either.

If we can find a way to simplify the work in buffer I could be persuaded to add this method. 

Since buffers are not thread safe the absolute bulk implementation could save the positional state use the relative method and restore the positional state?

Paul.

> On Jan 29, 2020, at 3:49 PM, Brian Burkhalter <brian.burkhalter at oracle.com> wrote:
> 
> Please consider this prototype fix [1] for [2]. The other potential method
> 
> $Type$Buffer put(int index, $Type$Buffer src) {} 
> 
> mentioned in the issue description is not included here so as to avoid mixing relative bulk (for src) and absolute bulk (for this) operations, i.e., not having either buffer change state. The proposed method therefore simply is the equivalent of replacing the array parameter $type$[] of $Type$Buffer.put(int, $type$[], int, int) with a $Type$Buffer.
> 
> More performant implementations specific to heap and direct buffers are intentionally omitted at this time but will be added later if this concept moves forward.
> 
> One potentially problematic behavior in the proposed method is allowing overlapping source and target ranges when the source and target buffers are the same buffer.
> 
> Thanks,
> 
> Brian
> 
> [1] http://cr.openjdk.java.net/~bpb/8219014/webrev.00/
> [2] https://bugs.openjdk.java.net/browse/JDK-8219014



More information about the nio-dev mailing list