Commit ead6a095 authored by Michal Piotrowski's avatar Michal Piotrowski Committed by Michal Piotrowski
Browse files

java lib p92

java lib p93

java lib p94

java lib p95

java lib p96

java lib p97

java lib p98
parent 459c71bd
Showing with 250 additions and 136 deletions
+250 -136
......@@ -91,12 +91,13 @@ async fn bulk_wrapper(bulk: &str, database_key: &str, owner_key: &str) -> Result
#[async_ffi(?Send)]
#[no_mangle]
pub async unsafe extern "C" fn create_account(create_user_req_ptr: *const c_char) -> *const c_char {
println!("create_account beginning");
let create_user_req = CStr::from_ptr(create_user_req_ptr)
.to_string_lossy()
.into_owned();
let result = create_account_wrapper(&create_user_req).await;
println!("create_account end");
match result {
Err(_) => CString::default().as_ptr(),
Ok(result) => result.as_ptr(),
......
......@@ -14,8 +14,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>19</maven.compiler.source>
<maven.compiler.target>19</maven.compiler.target>
<maven.compiler.source>20</maven.compiler.source>
<maven.compiler.target>20</maven.compiler.target>
</properties>
<dependencies>
......@@ -50,8 +50,7 @@
<version>3.8.0</version>
<configuration>
<compilerArgs>
<arg>--add-modules</arg>
<arg>jdk.incubator.foreign</arg>
<arg>--enable-preview</arg>
</compilerArgs>
</configuration>
</plugin>
......
......@@ -18,8 +18,9 @@ import com.memri.pod.Search;
import com.memri.pod.SendEmail;
import com.memri.pod.UpdateItem;
import static com.memri.pod.ffi.memripod_h.*;
import jdk.incubator.foreign.MemoryAddress;
import jdk.incubator.foreign.MemorySegment;
import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
import java.nio.charset.Charset;
public class PodLib {
String databaseKey;
......@@ -48,10 +49,15 @@ public class PodLib {
System.out.println("createAccount");
System.out.println(json);
MemorySegment memorySegment = MemorySegment.ofArray(json.getBytes());
MemoryAddress result = create_account(memorySegment);
try (Arena arena = Arena.openConfined()) {
MemorySegment nativeString = arena.allocateUtf8String(json);
System.out.println(nativeString);
MemorySegment result = create_account(nativeString);
System.out.println(result);
String result2 = result.getUtf8String(0);
System.out.println(result2);
}
}
public void createEdge(CreateEdge createEdge) {
......
File added
......@@ -5,19 +5,21 @@ package com.memri.pod.ffi;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.VarHandle;
import java.nio.ByteOrder;
import jdk.incubator.foreign.*;
import static jdk.incubator.foreign.ValueLayout.*;
public class Constants$root {
import java.lang.foreign.*;
import static java.lang.foreign.ValueLayout.*;
final class Constants$root {
static final OfBoolean C_BOOL$LAYOUT = JAVA_BOOLEAN;
static final OfByte C_CHAR$LAYOUT = JAVA_BYTE;
static final OfShort C_SHORT$LAYOUT = JAVA_SHORT.withBitAlignment(16);
static final OfInt C_INT$LAYOUT = JAVA_INT.withBitAlignment(32);
static final OfLong C_LONG$LAYOUT = JAVA_LONG.withBitAlignment(64);
static final OfLong C_LONG_LONG$LAYOUT = JAVA_LONG.withBitAlignment(64);
static final OfFloat C_FLOAT$LAYOUT = JAVA_FLOAT.withBitAlignment(32);
static final OfDouble C_DOUBLE$LAYOUT = JAVA_DOUBLE.withBitAlignment(64);
static final OfAddress C_POINTER$LAYOUT = ADDRESS.withBitAlignment(64);
// Suppresses default constructor, ensuring non-instantiability.
private Constants$root() {}
static final OfBoolean C_BOOL$LAYOUT = JAVA_BOOLEAN;
static final OfByte C_CHAR$LAYOUT = JAVA_BYTE;
static final OfShort C_SHORT$LAYOUT = JAVA_SHORT;
static final OfInt C_INT$LAYOUT = JAVA_INT;
static final OfLong C_LONG$LAYOUT = JAVA_LONG;
static final OfLong C_LONG_LONG$LAYOUT = JAVA_LONG;
static final OfFloat C_FLOAT$LAYOUT = JAVA_FLOAT;
static final OfDouble C_DOUBLE$LAYOUT = JAVA_DOUBLE;
static final OfAddress C_POINTER$LAYOUT = ADDRESS.withBitAlignment(64).asUnbounded();
}
File added
File added
package com.memri.pod.ffi;
// Generated by jextract
import jdk.incubator.foreign.Addressable;
import jdk.incubator.foreign.CLinker;
import jdk.incubator.foreign.FunctionDescriptor;
import jdk.incubator.foreign.GroupLayout;
import jdk.incubator.foreign.NativeSymbol;
import jdk.incubator.foreign.SymbolLookup;
import jdk.incubator.foreign.MemoryAddress;
import jdk.incubator.foreign.MemoryLayout;
import jdk.incubator.foreign.MemorySegment;
import jdk.incubator.foreign.ResourceScope;
import jdk.incubator.foreign.SegmentAllocator;
import jdk.incubator.foreign.ValueLayout;
import java.lang.foreign.Linker;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.SymbolLookup;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.SegmentScope;
import java.lang.foreign.SegmentAllocator;
import java.lang.foreign.ValueLayout;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
......@@ -23,26 +20,29 @@ import java.util.Arrays;
import java.util.Optional;
import java.util.stream.Stream;
import static jdk.incubator.foreign.CLinker.*;
import static jdk.incubator.foreign.ValueLayout.*;
import static java.lang.foreign.Linker.*;
import static java.lang.foreign.ValueLayout.*;
final class RuntimeHelper {
private RuntimeHelper() {}
private final static CLinker LINKER = CLinker.systemCLinker();
private final static ClassLoader LOADER = RuntimeHelper.class.getClassLoader();
private final static MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup();
private final static SymbolLookup SYMBOL_LOOKUP;
private static final Linker LINKER = Linker.nativeLinker();
private static final ClassLoader LOADER = RuntimeHelper.class.getClassLoader();
private static final MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup();
private static final SymbolLookup SYMBOL_LOOKUP;
private static final SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); };
final static SegmentAllocator CONSTANT_ALLOCATOR =
(size, align) -> MemorySegment.allocateNative(size, align, ResourceScope.newImplicitScope());
(size, align) -> MemorySegment.allocateNative(size, align, SegmentScope.auto());
static {
System.loadLibrary("libpod");
SymbolLookup loaderLookup = SymbolLookup.loaderLookup();
SYMBOL_LOOKUP = name -> loaderLookup.lookup(name).or(() -> LINKER.lookup(name));
SYMBOL_LOOKUP = name -> loaderLookup.find(name).or(() -> LINKER.defaultLookup().find(name));
}
// Suppresses default constructor, ensuring non-instantiability.
private RuntimeHelper() {}
static <T> T requireNonNull(T obj, String symbolName) {
if (obj == null) {
throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName);
......@@ -50,51 +50,55 @@ final class RuntimeHelper {
return obj;
}
private final static SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); };
static MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) {
return SYMBOL_LOOKUP.find(name).map(symbol -> MemorySegment.ofAddress(symbol.address(), layout.byteSize(), symbol.scope())).orElse(null);
}
static MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) {
return SYMBOL_LOOKUP.find(name).
map(addr -> LINKER.downcallHandle(addr, fdesc)).
orElse(null);
}
static final MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) {
return SYMBOL_LOOKUP.lookup(name).map(symbol -> MemorySegment.ofAddress(symbol.address(), layout.byteSize(), ResourceScope.newSharedScope())).orElse(null);
static MethodHandle downcallHandle(FunctionDescriptor fdesc) {
return LINKER.downcallHandle(fdesc);
}
static final MethodHandle downcallHandle(String name, FunctionDescriptor fdesc, boolean variadic) {
return SYMBOL_LOOKUP.lookup(name).map(
addr -> {
return variadic ?
VarargsInvoker.make(addr, fdesc) :
LINKER.downcallHandle(addr, fdesc);
}).orElse(null);
static MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) {
return SYMBOL_LOOKUP.find(name).
map(addr -> VarargsInvoker.make(addr, fdesc)).
orElse(null);
}
static final MethodHandle downcallHandle(FunctionDescriptor fdesc, boolean variadic) {
if (variadic) {
throw new AssertionError("Cannot get here!");
static MethodHandle upcallHandle(Class<?> fi, String name, FunctionDescriptor fdesc) {
try {
return MH_LOOKUP.findVirtual(fi, name, fdesc.toMethodType());
} catch (Throwable ex) {
throw new AssertionError(ex);
}
return LINKER.downcallHandle(fdesc);
}
static final <Z> NativeSymbol upcallStub(Class<Z> fi, Z z, FunctionDescriptor fdesc, String mtypeDesc, ResourceScope scope) {
static <Z> MemorySegment upcallStub(MethodHandle fiHandle, Z z, FunctionDescriptor fdesc, SegmentScope scope) {
try {
MethodHandle handle = MH_LOOKUP.findVirtual(fi, "apply",
MethodType.fromMethodDescriptorString(mtypeDesc, LOADER));
handle = handle.bindTo(z);
return LINKER.upcallStub(handle, fdesc, scope);
fiHandle = fiHandle.bindTo(z);
return LINKER.upcallStub(fiHandle, fdesc, scope);
} catch (Throwable ex) {
throw new AssertionError(ex);
}
}
static MemorySegment asArray(MemoryAddress addr, MemoryLayout layout, int numElements, ResourceScope scope) {
return MemorySegment.ofAddress(addr, numElements * layout.byteSize(), scope);
static MemorySegment asArray(MemorySegment addr, MemoryLayout layout, int numElements, SegmentScope scope) {
return MemorySegment.ofAddress(addr.address(), numElements * layout.byteSize(), scope);
}
// Internals only below this point
private static class VarargsInvoker {
private static final class VarargsInvoker {
private static final MethodHandle INVOKE_MH;
private final NativeSymbol symbol;
private final MemorySegment symbol;
private final FunctionDescriptor function;
private VarargsInvoker(NativeSymbol symbol, FunctionDescriptor function) {
private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) {
this.symbol = symbol;
this.function = function;
}
......@@ -107,7 +111,7 @@ final class RuntimeHelper {
}
}
static MethodHandle make(NativeSymbol symbol, FunctionDescriptor function) {
static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) {
VarargsInvoker invoker = new VarargsInvoker(symbol, function);
MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1);
MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class);
......@@ -115,7 +119,9 @@ final class RuntimeHelper {
mtype = mtype.appendParameterTypes(carrier(layout, false));
}
mtype = mtype.appendParameterTypes(Object[].class);
if (mtype.returnType().equals(MemorySegment.class)) {
boolean needsAllocator = function.returnLayout().isPresent() &&
function.returnLayout().get() instanceof GroupLayout;
if (needsAllocator) {
mtype = mtype.insertParameterTypes(0, SegmentAllocator.class);
} else {
handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR);
......@@ -125,8 +131,7 @@ final class RuntimeHelper {
static Class<?> carrier(MemoryLayout layout, boolean ret) {
if (layout instanceof ValueLayout valueLayout) {
return (ret || valueLayout.carrier() != MemoryAddress.class) ?
valueLayout.carrier() : Addressable.class;
return valueLayout.carrier();
} else if (layout instanceof GroupLayout) {
return MemorySegment.class;
} else {
......@@ -161,7 +166,9 @@ final class RuntimeHelper {
FunctionDescriptor.ofVoid(argLayouts) :
FunctionDescriptor.of(function.returnLayout().get(), argLayouts);
MethodHandle mh = LINKER.downcallHandle(symbol, f);
if (mh.type().returnType() == MemorySegment.class) {
boolean needsAllocator = function.returnLayout().isPresent() &&
function.returnLayout().get() instanceof GroupLayout;
if (needsAllocator) {
mh = mh.bindTo(allocator);
}
// flatten argument list so that it can be passed to an asSpreader MH
......@@ -211,10 +218,7 @@ final class RuntimeHelper {
if (c.isPrimitive()) {
return promote(c);
}
if (MemoryAddress.class.isAssignableFrom(c)) {
return MemoryAddress.class;
}
if (MemorySegment.class.isAssignableFrom(c)) {
if (c == MemorySegment.class) {
return MemorySegment.class;
}
throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName());
......@@ -225,7 +229,7 @@ final class RuntimeHelper {
return JAVA_LONG;
} else if (c == double.class) {
return JAVA_DOUBLE;
} else if (MemoryAddress.class.isAssignableFrom(c)) {
} else if (c == MemorySegment.class) {
return ADDRESS;
} else {
throw new IllegalArgumentException("Unhandled variadic argument class: " + c);
......
File added
File added
......@@ -5,11 +5,19 @@ package com.memri.pod.ffi;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.VarHandle;
import java.nio.ByteOrder;
import jdk.incubator.foreign.*;
import static jdk.incubator.foreign.ValueLayout.*;
import java.lang.foreign.*;
import static java.lang.foreign.ValueLayout.*;
/**
* {@snippet :
* union {
* unsigned long long __value64;
* struct __value32;
* };
* }
*/
public class __atomic_wide_counter {
static final GroupLayout $union$LAYOUT = MemoryLayout.unionLayout(
static final UnionLayout $union$LAYOUT = MemoryLayout.unionLayout(
Constants$root.C_LONG_LONG$LAYOUT.withName("__value64"),
MemoryLayout.structLayout(
Constants$root.C_INT$LAYOUT.withName("__low"),
......@@ -23,10 +31,22 @@ public class __atomic_wide_counter {
public static VarHandle __value64$VH() {
return __atomic_wide_counter.__value64$VH;
}
/**
* Getter for field:
* {@snippet :
* unsigned long long __value64;
* }
*/
public static long __value64$get(MemorySegment seg) {
return (long)__atomic_wide_counter.__value64$VH.get(seg);
}
public static void __value64$set( MemorySegment seg, long x) {
/**
* Setter for field:
* {@snippet :
* unsigned long long __value64;
* }
*/
public static void __value64$set(MemorySegment seg, long x) {
__atomic_wide_counter.__value64$VH.set(seg, x);
}
public static long __value64$get(MemorySegment seg, long index) {
......@@ -35,9 +55,19 @@ public class __atomic_wide_counter {
public static void __value64$set(MemorySegment seg, long index, long x) {
__atomic_wide_counter.__value64$VH.set(seg.asSlice(index*sizeof()), x);
}
public static class __value32 {
/**
* {@snippet :
* struct {
* unsigned int __low;
* unsigned int __high;
* };
* }
*/
public static final class __value32 {
static final GroupLayout __value32$struct$LAYOUT = MemoryLayout.structLayout(
// Suppresses default constructor, ensuring non-instantiability.
private __value32() {}
static final StructLayout __value32$struct$LAYOUT = MemoryLayout.structLayout(
Constants$root.C_INT$LAYOUT.withName("__low"),
Constants$root.C_INT$LAYOUT.withName("__high")
);
......@@ -48,10 +78,22 @@ public class __atomic_wide_counter {
public static VarHandle __low$VH() {
return __value32.__low$VH;
}
/**
* Getter for field:
* {@snippet :
* unsigned int __low;
* }
*/
public static int __low$get(MemorySegment seg) {
return (int)__value32.__low$VH.get(seg);
}
public static void __low$set( MemorySegment seg, int x) {
/**
* Setter for field:
* {@snippet :
* unsigned int __low;
* }
*/
public static void __low$set(MemorySegment seg, int x) {
__value32.__low$VH.set(seg, x);
}
public static int __low$get(MemorySegment seg, long index) {
......@@ -64,10 +106,22 @@ public class __atomic_wide_counter {
public static VarHandle __high$VH() {
return __value32.__high$VH;
}
/**
* Getter for field:
* {@snippet :
* unsigned int __high;
* }
*/
public static int __high$get(MemorySegment seg) {
return (int)__value32.__high$VH.get(seg);
}
public static void __high$set( MemorySegment seg, int x) {
/**
* Setter for field:
* {@snippet :
* unsigned int __high;
* }
*/
public static void __high$set(MemorySegment seg, int x) {
__value32.__high$VH.set(seg, x);
}
public static int __high$get(MemorySegment seg, long index) {
......@@ -78,14 +132,10 @@ public class __atomic_wide_counter {
}
public static long sizeof() { return $LAYOUT().byteSize(); }
public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
public static MemorySegment allocateArray(long len, SegmentAllocator allocator) {
return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
}
public static MemorySegment allocate(ResourceScope scope) { return allocate(SegmentAllocator.nativeAllocator(scope)); }
public static MemorySegment allocateArray(int len, ResourceScope scope) {
return allocateArray(len, SegmentAllocator.nativeAllocator(scope));
}
public static MemorySegment ofAddress(MemoryAddress addr, ResourceScope scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); }
public static MemorySegment ofAddress(MemorySegment addr, SegmentScope scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); }
}
public static MemorySegment __value32$slice(MemorySegment seg) {
......@@ -93,14 +143,10 @@ public class __atomic_wide_counter {
}
public static long sizeof() { return $LAYOUT().byteSize(); }
public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
public static MemorySegment allocateArray(long len, SegmentAllocator allocator) {
return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
}
public static MemorySegment allocate(ResourceScope scope) { return allocate(SegmentAllocator.nativeAllocator(scope)); }
public static MemorySegment allocateArray(int len, ResourceScope scope) {
return allocateArray(len, SegmentAllocator.nativeAllocator(scope));
}
public static MemorySegment ofAddress(MemoryAddress addr, ResourceScope scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); }
public static MemorySegment ofAddress(MemorySegment addr, SegmentScope scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); }
}
File added
......@@ -5,19 +5,24 @@ package com.memri.pod.ffi;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.VarHandle;
import java.nio.ByteOrder;
import jdk.incubator.foreign.*;
import static jdk.incubator.foreign.ValueLayout.*;
import java.lang.foreign.*;
import static java.lang.foreign.ValueLayout.*;
/**
* {@snippet :
* int (*__compar_fn_t)(void*,void*);
* }
*/
public interface __compar_fn_t {
int apply(jdk.incubator.foreign.MemoryAddress x0, jdk.incubator.foreign.MemoryAddress x1);
static NativeSymbol allocate(__compar_fn_t fi, ResourceScope scope) {
return RuntimeHelper.upcallStub(__compar_fn_t.class, fi, constants$14.__compar_fn_t$FUNC, "(Ljdk/incubator/foreign/MemoryAddress;Ljdk/incubator/foreign/MemoryAddress;)I", scope);
int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1);
static MemorySegment allocate(__compar_fn_t fi, SegmentScope scope) {
return RuntimeHelper.upcallStub(constants$13.__compar_fn_t_UP$MH, fi, constants$13.__compar_fn_t$FUNC, scope);
}
static __compar_fn_t ofAddress(MemoryAddress addr, ResourceScope scope) {
NativeSymbol symbol = NativeSymbol.ofAddress("__compar_fn_t::" + Long.toHexString(addr.toRawLongValue()), addr, scope);
return (jdk.incubator.foreign.MemoryAddress x0, jdk.incubator.foreign.MemoryAddress x1) -> {
static __compar_fn_t ofAddress(MemorySegment addr, SegmentScope scope) {
MemorySegment symbol = MemorySegment.ofAddress(addr.address(), 0, scope);
return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> {
try {
return (int)constants$14.__compar_fn_t$MH.invokeExact(symbol, (jdk.incubator.foreign.Addressable)x0, (jdk.incubator.foreign.Addressable)x1);
return (int)constants$13.__compar_fn_t_DOWN$MH.invokeExact(symbol, __x0, __x1);
} catch (Throwable ex$) {
throw new AssertionError("should not reach here", ex$);
}
......
File added
......@@ -5,11 +5,18 @@ package com.memri.pod.ffi;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.VarHandle;
import java.nio.ByteOrder;
import jdk.incubator.foreign.*;
import static jdk.incubator.foreign.ValueLayout.*;
import java.lang.foreign.*;
import static java.lang.foreign.ValueLayout.*;
/**
* {@snippet :
* struct {
* int __val[2];
* };
* }
*/
public class __fsid_t {
static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
static final StructLayout $struct$LAYOUT = MemoryLayout.structLayout(
MemoryLayout.sequenceLayout(2, Constants$root.C_INT$LAYOUT).withName("__val")
);
public static MemoryLayout $LAYOUT() {
......@@ -20,14 +27,10 @@ public class __fsid_t {
}
public static long sizeof() { return $LAYOUT().byteSize(); }
public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
public static MemorySegment allocateArray(long len, SegmentAllocator allocator) {
return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
}
public static MemorySegment allocate(ResourceScope scope) { return allocate(SegmentAllocator.nativeAllocator(scope)); }
public static MemorySegment allocateArray(int len, ResourceScope scope) {
return allocateArray(len, SegmentAllocator.nativeAllocator(scope));
}
public static MemorySegment ofAddress(MemoryAddress addr, ResourceScope scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); }
public static MemorySegment ofAddress(MemorySegment addr, SegmentScope scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); }
}
File added
......@@ -5,11 +5,18 @@ package com.memri.pod.ffi;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.VarHandle;
import java.nio.ByteOrder;
import jdk.incubator.foreign.*;
import static jdk.incubator.foreign.ValueLayout.*;
import java.lang.foreign.*;
import static java.lang.foreign.ValueLayout.*;
/**
* {@snippet :
* struct {
* int __data;
* };
* }
*/
public class __once_flag {
static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
static final StructLayout $struct$LAYOUT = MemoryLayout.structLayout(
Constants$root.C_INT$LAYOUT.withName("__data")
);
public static MemoryLayout $LAYOUT() {
......@@ -19,10 +26,22 @@ public class __once_flag {
public static VarHandle __data$VH() {
return __once_flag.__data$VH;
}
/**
* Getter for field:
* {@snippet :
* int __data;
* }
*/
public static int __data$get(MemorySegment seg) {
return (int)__once_flag.__data$VH.get(seg);
}
public static void __data$set( MemorySegment seg, int x) {
/**
* Setter for field:
* {@snippet :
* int __data;
* }
*/
public static void __data$set(MemorySegment seg, int x) {
__once_flag.__data$VH.set(seg, x);
}
public static int __data$get(MemorySegment seg, long index) {
......@@ -33,14 +52,10 @@ public class __once_flag {
}
public static long sizeof() { return $LAYOUT().byteSize(); }
public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
public static MemorySegment allocateArray(long len, SegmentAllocator allocator) {
return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
}
public static MemorySegment allocate(ResourceScope scope) { return allocate(SegmentAllocator.nativeAllocator(scope)); }
public static MemorySegment allocateArray(int len, ResourceScope scope) {
return allocateArray(len, SegmentAllocator.nativeAllocator(scope));
}
public static MemorySegment ofAddress(MemoryAddress addr, ResourceScope scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); }
public static MemorySegment ofAddress(MemorySegment addr, SegmentScope scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); }
}
File added
......@@ -5,11 +5,24 @@ package com.memri.pod.ffi;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.VarHandle;
import java.nio.ByteOrder;
import jdk.incubator.foreign.*;
import static jdk.incubator.foreign.ValueLayout.*;
import java.lang.foreign.*;
import static java.lang.foreign.ValueLayout.*;
/**
* {@snippet :
* struct __pthread_cond_s {
* __atomic_wide_counter __wseq;
* __atomic_wide_counter __g1_start;
* unsigned int __g_refs[2];
* unsigned int __g_size[2];
* unsigned int __g1_orig_size;
* unsigned int __wrefs;
* unsigned int __g_signals[2];
* };
* }
*/
public class __pthread_cond_s {
static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
static final StructLayout $struct$LAYOUT = MemoryLayout.structLayout(
MemoryLayout.unionLayout(
Constants$root.C_LONG_LONG$LAYOUT.withName("__value64"),
MemoryLayout.structLayout(
......@@ -49,10 +62,22 @@ public class __pthread_cond_s {
public static VarHandle __g1_orig_size$VH() {
return __pthread_cond_s.__g1_orig_size$VH;
}
/**
* Getter for field:
* {@snippet :
* unsigned int __g1_orig_size;
* }
*/
public static int __g1_orig_size$get(MemorySegment seg) {
return (int)__pthread_cond_s.__g1_orig_size$VH.get(seg);
}
public static void __g1_orig_size$set( MemorySegment seg, int x) {
/**
* Setter for field:
* {@snippet :
* unsigned int __g1_orig_size;
* }
*/
public static void __g1_orig_size$set(MemorySegment seg, int x) {
__pthread_cond_s.__g1_orig_size$VH.set(seg, x);
}
public static int __g1_orig_size$get(MemorySegment seg, long index) {
......@@ -65,10 +90,22 @@ public class __pthread_cond_s {
public static VarHandle __wrefs$VH() {
return __pthread_cond_s.__wrefs$VH;
}
/**
* Getter for field:
* {@snippet :
* unsigned int __wrefs;
* }
*/
public static int __wrefs$get(MemorySegment seg) {
return (int)__pthread_cond_s.__wrefs$VH.get(seg);
}
public static void __wrefs$set( MemorySegment seg, int x) {
/**
* Setter for field:
* {@snippet :
* unsigned int __wrefs;
* }
*/
public static void __wrefs$set(MemorySegment seg, int x) {
__pthread_cond_s.__wrefs$VH.set(seg, x);
}
public static int __wrefs$get(MemorySegment seg, long index) {
......@@ -82,14 +119,10 @@ public class __pthread_cond_s {
}
public static long sizeof() { return $LAYOUT().byteSize(); }
public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
public static MemorySegment allocateArray(long len, SegmentAllocator allocator) {
return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
}
public static MemorySegment allocate(ResourceScope scope) { return allocate(SegmentAllocator.nativeAllocator(scope)); }
public static MemorySegment allocateArray(int len, ResourceScope scope) {
return allocateArray(len, SegmentAllocator.nativeAllocator(scope));
}
public static MemorySegment ofAddress(MemoryAddress addr, ResourceScope scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); }
public static MemorySegment ofAddress(MemorySegment addr, SegmentScope scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); }
}
File added
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment