Skip to content
Permalink
Browse files

Automatic merge of foreign-abi into foreign-jextract

  • Loading branch information
duke
duke committed May 15, 2020
2 parents d426133 + 90a47d1 commit bb976cb5fb69de77c1dd10d87e518b0c43d328f7
@@ -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 bb976cb

Please sign in to comment.