Skip to content

Commit

Permalink
Automatic merge of foreign-memaccess into foreign-abi
Browse files Browse the repository at this point in the history
  • Loading branch information
duke committed May 15, 2020
2 parents 90a47d1 + 0bc9c6b commit f0c2d3a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
Expand Up @@ -310,16 +310,16 @@ static <S extends MemorySegment> Spliterator<S> spliterator(S segment, SequenceL
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.
Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -69,13 +69,13 @@ public class BulkOps {
@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
Expand Down

0 comments on commit f0c2d3a

Please sign in to comment.