Skip to content
Permalink
Browse files

Move MemoryAddress::copy (more review feedback)

Reviewed-by: psandoz
  • Loading branch information
mcimadamore committed May 15, 2020
1 parent 3487383 commit 0bc9c6bc13acc7c8044219b883bf1e9848a37776
@@ -310,16 +310,16 @@
MemorySegment fill(byte value);

/**
* Perform bulk copy from given source segment to this segment. More specifically, the bytes at
* Performs a bulk copy from given source segment to this segment. More specifically, the bytes at
* offset {@code 0} through {@code src.byteSize() - 1} in the source segment are copied into this segment
* at offset {@code 0} through {@code src.byteSize() - 1}.
* If the source segment overlaps with this segment, then the copying is performed as if the bytes at
* offset {@code 0} through {@code src.byteSize() - 1} in the source segment were first copied into a
* temporary segment with size {@code bytes}, and then the contents of the temporary segment were copied into
* this segment at offset {@code 0} through {@code src.byteSize() - 1}.
* <p>
* The result of a bulk copy is unspecified if, in the uncommon case, the source segment does not overlap with
* this segment, but it instead refers to an overlapping regions of the same backing storage using different addresses.
* 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.
* For example, this may occur if the same file is {@link MemorySegment#mapFromPath mapped} to two segments.
*
* @param src the source segment.
@@ -122,14 +122,13 @@ public final MemorySegment fill(byte value){
}

public void copyFrom(MemorySegment src) {
long size = src.byteSize();
((AbstractMemorySegmentImpl)src).checkRange(0, size, true);
checkRange(0, size, false);
long offsetSrc = ((AbstractMemorySegmentImpl) src).min();
long offsetDst = min();
Object baseSrc = ((AbstractMemorySegmentImpl) src).base();
Object baseDst = base();
UNSAFE.copyMemory(baseSrc, offsetSrc, baseDst, offsetDst, size);
AbstractMemorySegmentImpl that = (AbstractMemorySegmentImpl)src;
long size = that.byteSize();
checkRange(0, size, true);
that.checkRange(0, size, false);
UNSAFE.copyMemory(
that.base(), that.min(),
base(), min(), size);
}

@Override
@@ -69,13 +69,13 @@
@Benchmark
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void unsafe_fill() {
unsafe.setMemory(unsafe_addr, ALLOC_SIZE, (byte)0);
unsafe.setMemory(unsafe_addr, ALLOC_SIZE, (byte)42);
}

@Benchmark
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void segment_fill() {
segment.fill((byte)0);
segment.fill((byte)42);
}

@Benchmark

0 comments on commit 0bc9c6b

Please sign in to comment.
You can’t perform that action at this time.