Skip to content

Commit

Permalink
Move MemoryAddress::copy (ABI version)
Browse files Browse the repository at this point in the history
Reviewed-by: jvernee
  • Loading branch information
mcimadamore committed May 15, 2020
1 parent d4ce7aa commit 90a47d1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
Expand Up @@ -67,7 +67,7 @@ static void unbox(Object arg, List<Binding> bindings, Function<VMStorage,
MemorySegment operand = (MemorySegment) stack.pop();
assert operand.byteSize() == binding.size() : "operand size mismatch";
MemorySegment copy = MemorySegment.allocateNative(binding.size(), binding.alignment());
MemoryAddress.copy(operand.baseAddress(), copy.baseAddress(), binding.size());
copy.copyFrom(operand.asSlice(0, binding.size()));
buffers.add(copy);
stack.push(copy);
}
Expand Down Expand Up @@ -106,7 +106,7 @@ static Object box(List<Binding> bindings, Function<VMStorage, MemoryAddress> ptr
MemoryAddress operand = (MemoryAddress) stack.pop();
operand = MemoryAddressImpl.ofLongUnchecked(operand.toRawLongValue(), binding.size());
MemorySegment copy = MemorySegment.allocateNative(binding.size(), binding.alignment());
MemoryAddress.copy(operand, copy.baseAddress(), binding.size());
copy.copyFrom(operand.segment().asSlice(0, binding.size()));
stack.push(copy); // leaked
}
case ALLOC_BUFFER -> {
Expand Down
Expand Up @@ -180,9 +180,8 @@ public static MethodHandle adaptUpcallForIMR(MethodHandle target) {
}

private static MemoryAddress bufferCopy(MemoryAddress dest, MemorySegment buffer) {
MemoryAddress.copy(buffer.baseAddress(),
MemoryAddressImpl.ofLongUnchecked(dest.toRawLongValue(), buffer.byteSize()),
buffer.byteSize());
MemoryAddressImpl.ofLongUnchecked(dest.toRawLongValue(), buffer.byteSize())
.segment().copyFrom(buffer);
return dest;
}

Expand Down
2 changes: 1 addition & 1 deletion test/jdk/java/foreign/Cstring.java
Expand Up @@ -42,7 +42,7 @@ private static VarHandle arrayHandle(MemoryLayout elemLayout, Class<?> elemCarri

private static void copy(MemoryAddress addr, byte[] bytes) {
var heapSegment = MemorySegment.ofArray(bytes);
MemoryAddress.copy(heapSegment.baseAddress(), addr, bytes.length);
addr.segment().copyFrom(heapSegment);
byteArrHandle.set(addr, (long)bytes.length, (byte)0);
}

Expand Down

0 comments on commit 90a47d1

Please sign in to comment.