[foreign-memaccess] [Rev 01] RFR: Move MemoryAddress::copy
Paul Sandoz
psandoz at openjdk.java.net
Fri May 15 15:51:28 UTC 2020
On Fri, 15 May 2020 14:45:13 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> As discussed, this patch moves `MemoryAddress::copy` as an *instance* method of `MemorySegment`, namely
>> `MemorySegment::copyFrom`. I chose the `copyFrom` suggestion from John, since it allows us more freedom, in the future,
>> to add overloads for different sources for the copy operation.
>> I've rewrorked the documentation a bit to speak about segment offsets rather than addresses.
>>
>> I believe all use cases touched by this change actually lead to simpler code, which is good.
>>
>> I've also added a benchmark for some of the bulk operations such as fill and copyFrom - the numbers I've got look good:
>>
>> Benchmark Mode Cnt Score Error Units
>> BulkOps.segment_copy avgt 30 441675.750 ? 12794.881 ns/op
>> BulkOps.segment_fill avgt 30 122465.908 ? 1760.711 ns/op
>> BulkOps.unsafe_copy avgt 30 430153.694 ? 9055.253 ns/op
>> BulkOps.unsafe_fill avgt 30 120413.079 ? 3799.484 ns/op
>>
>> Cheers
>
> Maurizio Cimadamore has updated the pull request incrementally with one additional commit since the last revision:
>
> Fixed copyright
I like it. I always thought the prior location of `copy` was a little odd, but it took another method for it to really
stand out to me.
src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemorySegment.java line 313:
> 312: /**
> 313: * Perform bulk copy from given source segment to this segment. More specifically, the bytes at
> 314: * offset {@code 0} through {@code src.byteSize() - 1} in the source segment are copied into this segment
"Performs a bulk copy..."
src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemorySegment.java line 322:
> 321: * The result of a bulk copy is unspecified if, in the uncommon case, the source segment does not overlap with
> 322: * this segment, but it instead refers to an overlapping regions of the same backing storage using different
> addresses. 323: * For example, this may occur if the same file is {@link MemorySegment#mapFromPath mapped} to two
> segments.
"The result of a bulk copy is unspecified if, in the uncommon case, the source segment and this segment do not overlap,
but refer to overlapping regions of the same backing storage using different addresses"
test/micro/org/openjdk/bench/jdk/incubator/foreign/BulkOps.java line 72:
> 71: public void unsafe_fill() {
> 72: unsafe.setMemory(unsafe_addr, ALLOC_SIZE, (byte)0);
> 73: }
Out of an abundance of caution you might wanna choose a non-zero value just in case the JIT knows it's zeroing already
zeroed memory (i suspect it does not).
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/169
More information about the panama-dev
mailing list