Skip to content
Permalink
Browse files

Move MemoryAddress::copy (ABI version)

Reviewed-by: jvernee
  • Loading branch information
mcimadamore committed May 15, 2020
1 parent d4ce7aa commit 90a47d1d0bd2f33579341d88c3ebcd8e9610fb37
@@ -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);
}
@@ -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 -> {
@@ -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;
}

@@ -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);
}

0 comments on commit 90a47d1

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