# TODO: module deps?
# TODO: JAVAFLAGS / DEMOFLAGS / TESTFLAGS?
-TESTFLAGS=--enable-native-access=notzed.zcl -Djava.library.path=/usr/lib64
+TESTFLAGS=--enable-native-access=notzed.zcl --enable-preview -Djava.library.path=/usr/lib64
#central_JARS+=junit:junit:4.12 \
# org.hamcrest:hamcrest-core:1.3
javac.processormodulepath=
javac.processorpath=\
${javac.classpath}
-javac.source=19
-javac.target=19
+javac.source=20
+javac.target=20
javac.test.classpath=\
${libs.junit_4.classpath}:\
${javac.classpath}
if (true) {
now = System.nanoTime();
for (int l = 0; l < X; l++) {
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment arg0 = MemorySegment.allocateNative(8, 8, scope);
- MemorySegment arg1 = MemorySegment.allocateNative(8, 8, scope);
- MemorySegment arg2 = MemorySegment.allocateNative(8, 8, scope);
- MemorySegment arg3 = MemorySegment.allocateNative(8, 8, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment arg0 = scope.allocate(8, 8);
+ MemorySegment arg1 = scope.allocate(8, 8);
+ MemorySegment arg2 = scope.allocate(8, 8);
+ MemorySegment arg3 = scope.allocate(8, 8);
}
}
long t = System.nanoTime() - now;
if (false) {
now = System.nanoTime();
for (int l = 0; l < X; l++) {
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment arg0 = MemorySegment.allocateNative(8, 8, scope);
- MemorySegment arg1 = MemorySegment.allocateNative(8, 8, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment arg0 = scope.allocate(8, 8);
+ MemorySegment arg1 = scope.allocate(8, 8);
}
}
long n = System.nanoTime() - now;
if (false) {
now = System.nanoTime();
for (int l = 0; l < X; l++) {
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment arg0 = MemorySegment.allocateNative(Memory.POINTER, scope);
- MemorySegment arg1 = MemorySegment.allocateNative(Memory.POINTER, scope);
- MemorySegment arg2 = MemorySegment.allocateNative(Memory.POINTER, scope);
- MemorySegment arg3 = MemorySegment.allocateNative(Memory.POINTER, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment arg0 = scope.allocate(Memory.POINTER);
+ MemorySegment arg1 = scope.allocate(Memory.POINTER);
+ MemorySegment arg2 = scope.allocate(Memory.POINTER);
+ MemorySegment arg3 = scope.allocate(Memory.POINTER);
}
}
long u = System.nanoTime() - now;
now = System.nanoTime();
for (int l = 0; l < X; l++) {
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment arg0 = MemorySegment.allocateNative(Memory.POINTER, scope);
- MemorySegment arg1 = MemorySegment.allocateNative(Memory.POINTER, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment arg0 = scope.allocate(Memory.POINTER);
+ MemorySegment arg1 = scope.allocate(Memory.POINTER);
}
}
long m = System.nanoTime() - now;
import api.*;
-import java.nio.ByteOrder;
import java.lang.invoke.VarHandle;
import java.util.HashMap;
import static java.lang.Math.*;
if (true) {
now = System.nanoTime();
for (int l = 0; l < X; l++) {
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment seg = MemorySegment.allocateNative(data.length * 8, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment seg = scope.allocate(data.length * 8);
copyLoop(data, seg);
}
}
if (true) {
now = System.nanoTime();
for (int l = 0; l < X; l++) {
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment seg = MemorySegment.allocateNative(data.length * 8, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment seg = scope.allocate(data.length * 8);
copyBulk(data, seg);
}
}
package au.notzed.zcl.test;
-import api.Memory;
-import au.notzed.zcl.CL;
-import au.notzed.zcl.CLContext;
-import au.notzed.zcl.CLPlatform;
-import java.util.stream.Stream;
-import java.lang.foreign.MemoryAddress;
-import java.lang.foreign.MemorySegment;
-
public class TestExtensions {
public static void main(String[] args) {
-
+
//CLPlatform plat = CLPlatform.getPlatforms()[0];
//CLContext cl = CLContext.createContext(null, plat.getDevices(CL.CL_DEVICE_TYPE_ALL));
//Stream.of(plat.getExtensions()).forEach(System.out::println);
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.lang.foreign.MemorySegment;
-import java.lang.foreign.MemorySession;
+import java.lang.foreign.SegmentScope;
/**
* Some memory tests.
for (int i = 0; i < sizes.length; i++) {
arrays[i] = new float[sizes[i]];
- segments[i] = MemorySegment.allocateNative(sizes[i] * 4, 16, MemorySession.global());
+ segments[i] = MemorySegment.allocateNative(sizes[i] * 4, 16, SegmentScope.global());
buffers[i] = ByteBuffer.allocateDirect(sizes[i] * 4).order(ByteOrder.nativeOrder());
}
import java.nio.ByteOrder;
import java.nio.LongBuffer;
import java.lang.foreign.MemorySegment;
-import java.lang.foreign.MemorySession;
+import java.lang.foreign.SegmentScope;
/**
* Some memory tests.
for (int i = 0; i < sizes.length; i++) {
arrays[i] = new long[sizes[i]];
- segments[i] = MemorySegment.allocateNative(sizes[i] * 8, 16, MemorySession.global());
+ segments[i] = MemorySegment.allocateNative(sizes[i] * 8, 16, SegmentScope.global());
buffers[i] = ByteBuffer.allocateDirect(sizes[i] * 8).order(ByteOrder.nativeOrder());
}
package api;
-import java.lang.foreign.MemoryAddress;
+import java.lang.foreign.MemorySegment;
public class Callback<T> extends Native implements AutoCloseable {
T func;
- public Callback(MemoryAddress addr, T func) {
+ public Callback(MemorySegment addr, T func) {
super(addr);
this.func = func;
}
/*
- * A callback that resolve to MemoryAddress.NULL.
+ * A callback that resolve to MemorySegment.NULL.
* This can be released safely any number of times.
* This must never be registerd with ref queue.
*/
- public static final Callback NULL = new Callback<>(MemoryAddress.NULL, null) {
+ public static final Callback NULL = new Callback<>(MemorySegment.NULL, null) {
@Override
public void release() {
}
}
};
- private static void release(MemoryAddress p) {
+ private static void release(MemorySegment p) {
}
@Override
*/
package api;
-import java.lang.foreign.MemoryAddress;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
return copy(value.address());
}
- default <T extends Native> MemorySegment copy(MemoryAddress value) {
+ default <T extends Native> MemorySegment copy(MemorySegment value) {
MemorySegment mem = allocateAddress();
mem.set(Memory.POINTER, 0, value);
return mem;
*/
package api;
-import java.lang.foreign.Linker;
-import java.lang.foreign.MemoryAddress;
+import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
-import java.lang.foreign.MemorySession;
+import java.lang.foreign.SegmentScope;
import java.lang.foreign.ValueLayout;
import static java.lang.foreign.ValueLayout.ADDRESS;
import static java.lang.foreign.ValueLayout.JAVA_BYTE;
import static java.lang.foreign.ValueLayout.JAVA_INT;
import static java.lang.foreign.ValueLayout.JAVA_LONG;
import static java.lang.foreign.ValueLayout.JAVA_SHORT;
-import java.lang.ref.Cleaner;
/**
* A utility for memory operations including a stack allocator.
public static final ValueLayout.OfDouble DOUBLE = JAVA_DOUBLE.withBitAlignment(64);
public static final ValueLayout.OfAddress POINTER = ADDRESS.withBitAlignment(64);
- static final MemorySession scope = MemorySession.openShared(Cleaner.create());
+ static final SegmentScope scope = SegmentScope.auto();
private static final ThreadLocal<Stack> stacks = ThreadLocal.withInitial(() -> new Stack(scope));
public static Frame createFrame() {
private long sp;
private Thread thread = Thread.currentThread();
- Stack(MemorySession scope) {
+ Stack(SegmentScope scope) {
stack = MemorySegment.allocateNative(4096, 4096, scope);
sp = 4096;
}
return new Frame() {
private final long tos = sp;
private Thread self = thread;
- private MemorySession scope;
+ private Arena arena;
@Override
public MemorySegment allocate(long size, long alignment) {
sp = (sp - size) & ~(alignment - 1);
return stack.asSlice(sp, size);
} else {
- if (scope == null)
- scope = MemorySession.openConfined();
- return MemorySegment.allocateNative(size, alignment, scope);
+ if (arena == null)
+ arena = Arena.openConfined();
+ return arena.allocate(size, alignment);
}
}
@Override
public MemorySegment copy(String value) {
- if (scope == null)
- scope = MemorySession.openConfined();
+ if (arena == null)
+ arena = Arena.openConfined();
if (value != null) {
- return scope.allocateUtf8String(value);
+ return arena.allocateUtf8String(value);
} else {
- return MemorySegment.ofAddress(MemoryAddress.NULL, 0, scope);
+ return MemorySegment.NULL;
}
}
public void close() {
sp = tos;
self = null;
- if (scope != null) {
- scope.close();
- scope = null;
+ if (arena != null) {
+ arena.close();
+ arena = null;
}
}
};
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.System.Logger.Level;
-import java.lang.foreign.Addressable;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.Linker;
-import java.lang.foreign.MemoryAddress;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
-import java.lang.foreign.MemorySession;
+import java.lang.foreign.SegmentScope;
import java.lang.foreign.SymbolLookup;
/**
*/
public class Native {
- private final MemoryAddress p;
+ private final MemorySegment p;
private final static boolean dolog = true;
- protected Native(MemoryAddress p) {
+ protected Native(MemorySegment p) {
this.p = p;
}
return System.getLogger("notzed.native");
}
- public MemoryAddress address() {
+ public MemorySegment address() {
return p;
}
- public static MemoryAddress addr(Native o) {
- return o != null ? o.address() : MemoryAddress.NULL;
+ public static MemorySegment addr(Native o) {
+ return o != null ? o.address() : MemorySegment.NULL;
}
- public static MemoryAddress addr(MemorySegment o) {
- return o != null ? o.address() : MemoryAddress.NULL;
+ public static MemorySegment addr(MemorySegment o) {
+ return o != null ? o : MemorySegment.NULL;
}
/* helpers - native to java */
- public static <T extends Native> T[] toObjectV(MemorySegment list, T[] array, Function<MemoryAddress, T> create) {
+ public static <T extends Native> T[] toObjectV(MemorySegment list, T[] array, Function<MemorySegment, T> create) {
for (int i = 0; i < array.length; i++)
array[i] = Native.resolve(list.getAtIndex(Memory.POINTER, i), create);
return array;
}
- public static <T extends Native> T[] toObjectV(MemorySegment list, Function<MemoryAddress, T> create, IntFunction<T[]> createArray) {
+ public static <T extends Native> T[] toObjectV(MemorySegment list, Function<MemorySegment, T> create, IntFunction<T[]> createArray) {
return toObjectV(list, createArray.apply((int)(list.byteSize() >>> 3)), create);
}
MemoryLayout resLayout = sig.layouts[n - 1];
if (resLayout != null) {
- return lib.lookup(name).map(addr
+ return lib.find(name).map(addr
-> abi.downcallHandle(addr, FunctionDescriptor.of(resLayout, Arrays.copyOf(sig.layouts, n - 1))))
.get();
} else {
- return lib.lookup(name).map(addr
+ return lib.find(name).map(addr
-> abi.downcallHandle(addr, FunctionDescriptor.ofVoid(Arrays.copyOf(sig.layouts, n - 1))))
.get();
}
}
- public static MethodHandle downcallHandle(Function<String, MemoryAddress> find, String name, String signature) {
+ public static MethodHandle downcallHandle(Function<String, MemorySegment> find, String name, String signature) {
return downcallHandle(find.apply(name), signature);
}
- public static MethodHandle downcallHandle(MemoryAddress addr, String signature) {
+ public static MethodHandle downcallHandle(MemorySegment addr, String signature) {
Signature sig = Signature.parse(signature);
int n = sig.classes.length;
Linker abi = Linker.nativeLinker();
Method m = instance.getClass().getMethods()[0];
MethodType mt = MethodType.methodType(m.getReturnType(), m.getParameterTypes());
- // FIXME: MemorySession usage is broken here
+ // FIXME: SegmentScope usage is broken here
//System.out.printf("instance %s\n", instance);
//System.out.printf("declaring class %s\n", m.getDeclaringClass());
try {
m.getName(),
mt).bindTo(instance),
FunctionDescriptor.of(resLayout, Arrays.copyOf(sig.layouts, n - 1)),
- MemorySession.openShared());
+ SegmentScope.auto());
} else {
return abi.upcallStub(
lookup.findVirtual(
m.getName(),
mt).bindTo(instance),
FunctionDescriptor.ofVoid(Arrays.copyOf(sig.layouts, n - 1)),
- MemorySession.openShared());
+ SegmentScope.auto());
}
} catch (NoSuchMethodException | IllegalAccessException x) {
throw new RuntimeException(x);
}
if (pointerDepth > 0) {
- argClass.add(MemoryAddress.class);
+ argClass.add(MemorySegment.class);
argLayout.add(Memory.POINTER);
} else {
switch (c) {
case 'v':
//System.out.printf("void *=%d\n", pointerDepth);
if (pointerDepth > 0) {
- argClass.add(MemoryAddress.class);
+ argClass.add(MemorySegment.class);
argLayout.add(Memory.POINTER);
} else {
// can only be return value
}
//System.out.printf(" type: *=%d %s\n", pointerDepth, sb);
if (pointerDepth > 0) {
- argClass.add(MemoryAddress.class);
+ argClass.add(MemorySegment.class);
argLayout.add(Memory.POINTER);
} else {
argClass.add(MemorySegment.class);
*/
static private final ReferenceQueue<Native> references = new ReferenceQueue<>();
- private static <T extends Native> T createInstance(Class<T> jtype, MemoryAddress p) {
+ private static <T extends Native> T createInstance(Class<T> jtype, MemorySegment p) {
cleanerStep();
try {
- Class[] params = {MemoryAddress.class};
+ Class[] params = {MemorySegment.class};
Constructor<T> cc = jtype.getDeclaredConstructor(params);
cc.setAccessible(true);
}
/*
- public static <T extends Native> T resolve(Class<T> jtype, MemoryAddress p) {
+ public static <T extends Native> T resolve(Class<T> jtype, MemorySegment p) {
T o;
//if (dolog)
}
return o;
}*/
- public static <T extends Native> T resolve(Addressable p, Function<MemoryAddress, T> create) {
- return resolve(p.address(), create);
- }
-
- public static <T extends Native> T resolve(MemoryAddress p, Function<MemoryAddress, T> create) {
+ public static <T extends Native> T resolve(MemorySegment p, Function<MemorySegment, T> create) {
T o;
boolean step = false;
//if (dolog)
// log().log(Level.DEBUG, () -> String.format(" resolv $%016x %s", Memory.toLong(p), create));
- if (p.toRawLongValue() == 0)
+ if (p.address() == 0)
return null;
// Instantiation needs to be synchronized for obvious reasons.
}
{
T x = o;
- log().log(Level.DEBUG, () -> String.format(fmt, p.toRawLongValue(), x.getClass().getName()));
+ log().log(Level.DEBUG, () -> String.format(fmt, p.address(), x.getClass().getName()));
}
}
if (ref != null) {
if (dolog)
- log().log(Level.DEBUG, () -> String.format(" force $%016x %s", p.toRawLongValue(), getClass().getName()));
+ log().log(Level.DEBUG, () -> String.format(" force $%016x %s", p.address(), getClass().getName()));
ref.enqueue();
}
private static class CHandle extends WeakReference<Native> {
- protected MemoryAddress p;
+ protected MemorySegment p;
final Class<? extends Native> jtype;
CHandle next;
- CHandle(Native referent, ReferenceQueue<Native> references, MemoryAddress p) {
+ CHandle(Native referent, ReferenceQueue<Native> references, MemorySegment p) {
super(referent, references);
this.p = p;
this.jtype = referent.getClass();
try {
if (p != null) {
if (dolog)
- log().log(Level.DEBUG, () -> String.format(" releas $%016x %s", p.toRawLongValue(), jtype.getName()));
+ log().log(Level.DEBUG, () -> String.format(" releas $%016x %s", p.address(), jtype.getName()));
- Method mm = jtype.getDeclaredMethod("release", MemoryAddress.class);
+ Method mm = jtype.getDeclaredMethod("release", MemorySegment.class);
mm.setAccessible(true);
mm.invoke(null, p);
}
/**
* Sigh, memoryaddress has a miserable hashCode(), it's even worse than Long.hashCode()
*/
- public static final int hashCode(MemoryAddress p) {
+ public static final int hashCode(MemorySegment p) {
return p.hashCode() >>> 5;
}
}
while (h != null) {
Native o = h.get();
System.out.printf(" $%016x: %s %-40s %s\n",
- h.p.toRawLongValue(),
+ h.p.address(),
o == null ? "dead" : "live",
h.jtype.getName(),
o);
size += 1;
}
- public CHandle get(MemoryAddress p) {
+ public CHandle get(MemorySegment p) {
int i = CHandle.hashCode(p) & mask;
CHandle h = table[i];
return h;
}
- public CHandle remove(MemoryAddress p) {
+ public CHandle remove(MemorySegment p) {
int i = CHandle.hashCode(p) & mask;
CHandle h = table[i];
CHandle a = null;
*/
public class CLBuffer extends CLMemory {
- public CLBuffer(MemoryAddress p, CLPlatform platform) {
+ public CLBuffer(MemorySegment p, CLPlatform platform) {
super(p, platform, null);
}
- CLBuffer(MemoryAddress p, CLPlatform platform, MemorySegment seg) {
+ CLBuffer(MemorySegment p, CLPlatform platform, MemorySegment seg) {
super(p, platform, seg);
}
- static void release(MemoryAddress p) {
+ static void release(MemorySegment p) {
CLMemory.release(p);
}
try (Frame frame = Memory.createFrame()) {
MemorySegment pres = frame.allocateInt();
MemorySegment pinfo = info.toNative(frame);
- MemoryAddress b;
+ MemorySegment b;
int res;
- b = clCreateSubBuffer(address(), flags, CL_BUFFER_CREATE_TYPE_REGION, pinfo.address(), pres.address());
+ b = clCreateSubBuffer(address(), flags, CL_BUFFER_CREATE_TYPE_REGION, pinfo, pres);
if ((res = pres.get(Memory.INT, 0)) != 0)
throw new CLRuntimeException(res);
*/
public class CLCommandQueue extends CLObject {
- public CLCommandQueue(MemoryAddress p, CLPlatform platform) {
+ public CLCommandQueue(MemorySegment p, CLPlatform platform) {
super(p, platform);
}
- private static void release(MemoryAddress p) {
+ private static void release(MemorySegment p) {
try {
clReleaseCommandQueue(p);
} catch (Throwable t) {
res = clEnqueueReadBuffer(address(), mem.address(), blocking ? 1 : 0,
mem_offset, size,
- buffer.address(),
+ buffer,
info.nwait, info.wait, info.event);
if (res != 0)
throw new CLException(res);
byte[] buffer, int buf_offset,
CLEventList wait,
CLEventList event) throws CLException {
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment seg = MemorySegment.allocateNative(size, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment seg = scope.allocate(size);
enqueueReadBuffer(mem, true, mem_offset, size, seg, wait, event);
seg.asByteBuffer().order(ByteOrder.nativeOrder()).get(buffer, buf_offset, size);
}
short[] buffer, int buf_offset,
CLEventList wait,
CLEventList event) throws CLException {
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment seg = MemorySegment.allocateNative(size * 2, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment seg = scope.allocate(size * 2);
enqueueReadBuffer(mem, true, mem_offset * 2, size * 2, seg, wait, event);
seg.asByteBuffer().order(ByteOrder.nativeOrder()).asShortBuffer().get(buffer, buf_offset, size);
}
int[] buffer, int buf_offset,
CLEventList wait,
CLEventList event) throws CLException {
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment seg = MemorySegment.allocateNative(size * 4, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment seg = scope.allocate(size * 4);
enqueueReadBuffer(mem, true, mem_offset * 4, size * 4, seg, wait, event);
seg.asByteBuffer().order(ByteOrder.nativeOrder()).asIntBuffer().get(buffer, buf_offset, size);
}
long[] buffer, int buf_offset,
CLEventList wait,
CLEventList event) throws CLException {
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment seg = MemorySegment.allocateNative(size * 8, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment seg = scope.allocate(size * 8);
enqueueReadBuffer(mem, true, mem_offset * 8, size * 8, seg, wait, event);
seg.asByteBuffer().order(ByteOrder.nativeOrder()).asLongBuffer().get(buffer, buf_offset, size);
}
float[] buffer, int buf_offset,
CLEventList wait,
CLEventList event) throws CLException {
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment seg = MemorySegment.allocateNative(size * 4, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment seg = scope.allocate(size * 4);
enqueueReadBuffer(mem, true, mem_offset * 4, size * 4, seg, wait, event);
seg.asByteBuffer().order(ByteOrder.nativeOrder()).asFloatBuffer().get(buffer, buf_offset, size);
}
double[] buffer, int buf_offset,
CLEventList wait,
CLEventList event) throws CLException {
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment seg = MemorySegment.allocateNative(size * 8, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment seg = scope.allocate(size * 8);
enqueueReadBuffer(mem, true, mem_offset * 8, size * 8, seg, wait, event);
seg.asByteBuffer().order(ByteOrder.nativeOrder()).asDoubleBuffer().get(buffer, buf_offset, size);
}
res = clEnqueueReadBufferRect(
address(), mem.address(), blocking ? 1 : 0,
- cbuffer_origin.address(), chost_origin.address(), cregion.address(),
+ cbuffer_origin, chost_origin, cregion,
buffer_row_pitch,
buffer_slice_pitch,
host_row_pitch,
host_slice_pitch,
- buffer.address(),
+ buffer,
info.nwait, info.wait, info.event);
if (res != 0)
long slice = region[1] * stride;
long size = slice * region[2];
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment seg = MemorySegment.allocateNative(size, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment seg = scope.allocate(size);
enqueueReadBufferRect(mem, blocking,
buffer_origin, OFFSET_0x0x0, region,
buffer_row_pitch, buffer_slice_pitch, stride, slice,
res = clEnqueueWriteBuffer(address(), mem.address(), blocking ? 1 : 0,
mem_offset, size,
- buffer.address(),
+ buffer,
info.nwait, info.wait, info.event);
if (res != 0)
throw new CLException(res);
byte[] buffer, int buf_offset,
CLEventList wait,
CLEventList event) throws CLException {
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment seg = MemorySegment.allocateNative(size, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment seg = scope.allocate(size);
seg.asByteBuffer().order(ByteOrder.nativeOrder()).put(buffer, buf_offset, size);
enqueueWriteBuffer(mem, true, mem_offset, size, seg, wait, event);
}
short[] buffer, int buf_offset,
CLEventList wait,
CLEventList event) throws CLException {
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment seg = MemorySegment.allocateNative(size * 2L, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment seg = scope.allocate(size * 2L);
seg.asByteBuffer().order(ByteOrder.nativeOrder()).asShortBuffer().put(buffer, buf_offset, size);
enqueueWriteBuffer(mem, true, mem_offset * 2, size * 2L, seg, wait, event);
}
int[] buffer, int buf_offset,
CLEventList wait,
CLEventList event) throws CLException {
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment seg = MemorySegment.allocateNative(size * 4L, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment seg = scope.allocate(size * 4L);
seg.asByteBuffer().order(ByteOrder.nativeOrder()).asIntBuffer().put(buffer, buf_offset, size);
enqueueWriteBuffer(mem, true, mem_offset * 4, size * 4L, seg, wait, event);
}
long[] buffer, int buf_offset,
CLEventList wait,
CLEventList event) throws CLException {
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment seg = MemorySegment.allocateNative(size * 8L, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment seg = scope.allocate(size * 8L);
seg.asByteBuffer().order(ByteOrder.nativeOrder()).asLongBuffer().put(buffer, buf_offset, size);
enqueueWriteBuffer(mem, true, mem_offset * 8, size * 8L, seg, wait, event);
}
float[] buffer, int buf_offset,
CLEventList wait,
CLEventList event) throws CLException {
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment seg = MemorySegment.allocateNative(size * 4L, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment seg = scope.allocate(size * 4L);
seg.asByteBuffer().order(ByteOrder.nativeOrder()).asFloatBuffer().put(buffer, buf_offset, size);
enqueueWriteBuffer(mem, true, mem_offset * 4, size * 4L, seg, wait, event);
}
double[] buffer, int buf_offset,
CLEventList wait,
CLEventList event) throws CLException {
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment seg = MemorySegment.allocateNative(size * 8L, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment seg = scope.allocate(size * 8L);
seg.asByteBuffer().order(ByteOrder.nativeOrder()).asDoubleBuffer().put(buffer, buf_offset, size);
enqueueWriteBuffer(mem, true, mem_offset * 8, size * 8L, seg, wait, event);
}
res = clEnqueueWriteBufferRect(
address(), mem.address(), blocking ? 1 : 0,
- cbuffer_origin.address(), chost_origin.address(), cregion.address(),
+ cbuffer_origin, chost_origin, cregion,
buffer_row_pitch,
buffer_slice_pitch,
host_row_pitch,
host_slice_pitch,
- buffer.address(),
+ buffer,
info.nwait, info.wait, info.event);
if (res != 0)
res = clEnqueueFillBuffer(
address(), buffer.address(),
- pattern.address(), pattern.byteSize(),
+ pattern, pattern.byteSize(),
offset * pattern.byteSize(),
size * pattern.byteSize(),
info.nwait, info.wait, info.event);
long size,
CLEventList wait,
CLEventList event) throws CLException {
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment seg = MemorySegment.allocateNative(pattern.length, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment seg = scope.allocate(pattern.length);
seg.copyFrom(MemorySegment.ofArray(pattern));
enqueueFillBuffer(buffer, seg, offset, size, wait, event);
long size,
CLEventList wait,
CLEventList event) throws CLException {
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment seg = MemorySegment.allocateNative(pattern.length * 2, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment seg = scope.allocate(pattern.length * 2);
seg.copyFrom(MemorySegment.ofArray(pattern));
enqueueFillBuffer(buffer, seg, offset * 2, size * 2, wait, event);
long size,
CLEventList wait,
CLEventList event) throws CLException {
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment seg = MemorySegment.allocateNative(pattern.length * 4, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment seg = scope.allocate(pattern.length * 4);
seg.copyFrom(MemorySegment.ofArray(pattern));
enqueueFillBuffer(buffer, seg, offset * 4, size * 4, wait, event);
long size,
CLEventList wait,
CLEventList event) throws CLException {
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment seg = MemorySegment.allocateNative(pattern.length * 4, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment seg = scope.allocate(pattern.length * 4);
seg.copyFrom(MemorySegment.ofArray(pattern));
enqueueFillBuffer(buffer, seg, offset * 4, size * 4, wait, event);
long size,
CLEventList wait,
CLEventList event) throws CLException {
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment seg = MemorySegment.allocateNative(pattern.length * 4, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment seg = scope.allocate(pattern.length * 4);
seg.copyFrom(MemorySegment.ofArray(pattern));
enqueueFillBuffer(buffer, seg, offset * 4, size * 4, wait, event);
long xstride = region[0] << dshift;
long xslice = xstride * region[1];
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment seg = MemorySegment.allocateNative(alloc, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment seg = scope.allocate(alloc);
if (!readMode)
writer.apply(seg).copy((int)region[0], (int)region[1], (int)region[2], (int)stride, (int)slice);
doImageBuffer(image, blocking, origin, region, xstride, 0, seg, wait, event, op);
static class MapData {
- MemoryAddress raw;
+ MemorySegment raw;
ByteBuffer buffer;
- public MapData(MemoryAddress p, ByteBuffer buffer) {
+ public MapData(MemorySegment p, ByteBuffer buffer) {
this.raw = p;
this.buffer = buffer;
}
private final ArrayList<MapData> maps = new ArrayList<>();
- private void addMap(MemoryAddress raw, ByteBuffer bb) {
+ private void addMap(MemorySegment raw, ByteBuffer bb) {
synchronized (maps) {
maps.add(new MapData(raw, bb));
}
try (Frame frame = Memory.createFrame()) {
EventInfo info = new EventInfo(frame, wait, event);
MemorySegment pres = frame.allocateInt();
- MemoryAddress cmap;
+ MemorySegment cmap;
int res;
cmap = clEnqueueMapBuffer(address(), buffer.address(), blocking ? 1 : 0,
flags, offset, size,
info.nwait, info.wait, info.event,
- pres.address());
+ pres);
if ((res = pres.get(Memory.INT, 0)) != 0)
throw new CLException(res);
- return MemorySegment.ofAddress(cmap, size, MemorySession.global()).asByteBuffer();
+ return MemorySegment.ofAddress(cmap.address(), size).asByteBuffer();
} catch (CLException | RuntimeException | Error t) {
throw t;
} catch (Throwable t) {
MemorySegment cstride = frame.allocateLong();
MemorySegment cslice = frame.allocateLong();
MemorySegment pres = frame.allocateLong();
- MemoryAddress cmap;
+ MemorySegment cmap;
long stride, slice;
int res;
cmap = clEnqueueMapImage(
address(), image.address(), blocking ? 1 : 0,
flags,
- corigin.address(), cregion.address(),
- cstride.address(), cslice.address(),
+ corigin, cregion,
+ cstride, cslice,
info.nwait, info.wait, info.event,
- pres.address());
+ pres);
if ((res = pres.get(Memory.INT, 0)) != 0)
throw new CLException(res);
? stride * region[1] + region[0] // 2D
: slice * region[2] + stride * region[1] + region[0]; // 3D
- return MemorySegment.ofAddress(cmap, size, MemorySession.global()).asByteBuffer();
+ return MemorySegment.ofAddress(cmap.address(), size).asByteBuffer();
} catch (CLException | RuntimeException | Error t) {
throw t;
} catch (Throwable t) {
public void enqueueUnmapMemObject(CLMemory mem, ByteBuffer mapped,
CLEventList wait,
CLEventList event) throws CLException {
- MemoryAddress cmap = MemorySegment.ofBuffer(mapped).address();
+ MemorySegment cmap = MemorySegment.ofBuffer(mapped);
try (Frame frame = Memory.createFrame()) {
EventInfo info = new EventInfo(frame, wait, event);
return frame.copy(ws);
} else {
// or null??
- return MemorySegment.ofAddress(MemoryAddress.NULL, 0, MemorySession.global());
+ return MemorySegment.NULL;
}
}
int res;
res = clEnqueueNDRangeKernel(address(), kernel.address(),
- work_dim, gwo.address(), gws.address(), lws.address(),
+ work_dim, gwo, gws, lws,
info.nwait, info.wait, info.event);
if (res != 0)
throw new CLException(res);
}
Callback<CLNativeKernel> call = Native.resolve(
- Call_pv_v.stub((MemoryAddress memargs) -> {
+ Call_pv_v.stub((MemorySegment memargs) -> {
int tmem = 0;
int xmem = 0;
tmem++;
}
- MemorySegment seg = MemorySegment.ofAddress(memargs, tmem * Memory.POINTER.byteSize(), MemorySession.global());
+ MemorySegment seg = MemorySegment.ofAddress(memargs.address(), tmem * Memory.POINTER.byteSize());
for (int i = 0; i < args.length; i++) {
if (args[i] instanceof CLMemory) {
- MemoryAddress mem = seg.get(Memory.POINTER, xmem);
+ MemorySegment mem = seg.get(Memory.POINTER, xmem);
long size = ((CLMemory)args[i]).getSize();
- save[i] = MemorySegment.ofAddress(mem, size, MemorySession.global()).asByteBuffer().order(ByteOrder.nativeOrder());
+ save[i] = MemorySegment.ofAddress(mem.address(), size).asByteBuffer().order(ByteOrder.nativeOrder());
xmem++;
}
}
}),
(p) -> new Callback<>(p, kernel));
- res = clEnqueueNativeKernel(address(), call.address(), memstage.address(), nmem * Memory.POINTER.byteSize(), nmem, memstage.address(), memptrs.address(), info.nwait, info.wait, info.event);
+ res = clEnqueueNativeKernel(address(), call.address(), memstage, nmem * Memory.POINTER.byteSize(), nmem, memstage, memptrs, info.nwait, info.wait, info.event);
if (res != 0)
throw new CLException(res);
MemorySegment cmem_objects = frame.copy(mem_objects);
int res;
- res = gl.clEnqueueAcquireGLObjects(address(), mem_objects.length, cmem_objects.address(),
+ res = gl.clEnqueueAcquireGLObjects(address(), mem_objects.length, cmem_objects,
info.nwait, info.wait, info.event);
if (res != 0)
throw new CLRuntimeException(res);
MemorySegment cmem_objects = frame.copy(mem_objects);
int res;
- res = gl.clEnqueueReleaseGLObjects(address(), mem_objects.length, cmem_objects.address(),
+ res = gl.clEnqueueReleaseGLObjects(address(), mem_objects.length, cmem_objects,
info.nwait, info.wait, info.event);
if (res != 0)
throw new CLRuntimeException(res);
/**
* platform must not be null.
*/
- public CLContext(MemoryAddress p, CLPlatform platform) {
+ public CLContext(MemorySegment p, CLPlatform platform) {
super(p, platform);
this.notify = null;
}
/**
* platform must not be null.
*/
- CLContext(MemoryAddress p, CLPlatform platform, Callback<CLContextNotify> notify) {
+ CLContext(MemorySegment p, CLPlatform platform, Callback<CLContextNotify> notify) {
super(p, platform);
this.notify = notify;
}
- private static void release(MemoryAddress p) {
+ private static void release(MemorySegment p) {
try {
clReleaseContext(p);
} catch (Throwable t) {
* @return new property
*/
public static CLContextProperty PLATFORM(CLPlatform platform) {
- return new CLContextProperty.TagValue(CL.CL_CONTEXT_PLATFORM, platform.address().toRawLongValue());
+ return new CLContextProperty.TagValue(CL.CL_CONTEXT_PLATFORM, platform.address().address());
}
/**
MemorySegment pdevs = frame.allocateAddress(devices.length);
MemorySegment pres = frame.allocateInt();
Callback<CLContextNotify> call = CLContextNotify.call(notify);
- MemoryAddress cl;
+ MemorySegment cl;
int res;
for (int i = 0; i < devices.length; i++)
pdevs.setAtIndex(Memory.POINTER, i, devices[i].address());
- cl = clCreateContext(pprops.address(), devices.length, pdevs.address(), call.address(), MemoryAddress.NULL, pres.address());
+ cl = clCreateContext(pprops, devices.length, pdevs, call.address(), MemorySegment.NULL, pres);
res = pres.get(Memory.INT, 0);
if (res != 0)
/**
* Directly lookup platform for a context where we have no other context to find it
*/
- static CLPlatform findPlatform(MemoryAddress ccl) {
+ static CLPlatform findPlatform(MemorySegment ccl) {
try (Frame frame = Memory.createFrame()) {
MemorySegment devices = getInfoAny(ccl, CL_CONTEXT_DEVICES, clGetContextInfo, frame);
- MemoryAddress dev0 = devices.get(Memory.POINTER, 0);
- MemoryAddress plat = getInfo(dev0, CL_DEVICE_PLATFORM, clGetDeviceInfo, frame, 8).get(Memory.POINTER, 0);
+ MemorySegment dev0 = devices.get(Memory.POINTER, 0);
+ MemorySegment plat = getInfo(dev0, CL_DEVICE_PLATFORM, clGetDeviceInfo, frame, 8).get(Memory.POINTER, 0);
return Native.resolve(plat, CLPlatform::new);
} catch (RuntimeException | Error t) {
try (Frame frame = Memory.createFrame()) {
MemorySegment pprops = CLProperty.toNative(frame, properties);
MemorySegment pres = frame.allocateInt();
- MemoryAddress cl;
+ MemorySegment cl;
Callback<CLContextNotify> call = CLContextNotify.call(notify);
int res;
- cl = clCreateContextFromType(pprops.address(), device_type, call.address(), MemoryAddress.NULL, pres.address());
+ cl = clCreateContextFromType(pprops, device_type, call.address(), MemorySegment.NULL, pres);
res = pres.get(Memory.INT, 0);
if (res != 0)
public CLCommandQueue createCommandQueue(CLDevice dev, long properties) throws CLRuntimeException {
try (Frame frame = Memory.createFrame()) {
MemorySegment pres = frame.allocateInt();
- MemoryAddress q;
+ MemorySegment q;
int res;
- q = clCreateCommandQueue(address(), dev.address(), properties, pres.address());
+ q = clCreateCommandQueue(address(), dev.address(), properties, pres);
res = pres.get(Memory.INT, 0);
if (res != 0)
try (Frame frame = Memory.createFrame()) {
MemorySegment pprops = CLProperty.toNative(frame, properties);
MemorySegment pres = frame.allocateInt();
- MemoryAddress q;
+ MemorySegment q;
int res;
- q = clCreateCommandQueueWithProperties(address(), dev.address(), pprops.address(), pres.address());
+ q = clCreateCommandQueueWithProperties(address(), dev.address(), pprops, pres);
res = pres.get(Memory.INT, 0);
if (res != 0)
try (Frame frame = Memory.createFrame()) {
MemorySegment pres = frame.allocateInt();
- MemoryAddress pbuffer;
+ MemorySegment pbuffer;
int res;
- pbuffer = clCreateBuffer(address(), flags, size, addr(hostseg), pres.address());
+ pbuffer = clCreateBuffer(address(), flags, size, addr(hostseg), pres);
if ((res = pres.get(Memory.INT, 0)) != 0)
throw new CLRuntimeException(res);
try (Frame frame = Memory.createFrame()) {
MemorySegment cfmt = CLImageFormat.toNative(frame, fmt);
MemorySegment cres = frame.allocateInt();
- MemoryAddress ci;
+ MemorySegment ci;
int res;
// FIXME: perform range checks
if (haveAPIVersion(CLPlatform.VERSION_1_2)) {
MemorySegment cdesc = CLImageDesc.toNative(frame, desc);
- ci = clCreateImage(address(), flags, cfmt.address(), cdesc.address(), addr(hostseg), cres.address());
+ ci = clCreateImage(address(), flags, cfmt, cdesc, addr(hostseg), cres);
} else {
switch (desc.imageType) {
case CL_MEM_OBJECT_IMAGE2D:
- ci = clCreateImage2D(address(), flags, cfmt.address(), desc.imageWidth, desc.imageHeight, desc.imageRowPitch, addr(hostseg), cres.address());
+ ci = clCreateImage2D(address(), flags, cfmt, desc.imageWidth, desc.imageHeight, desc.imageRowPitch, addr(hostseg), cres);
break;
case CL_MEM_OBJECT_IMAGE3D:
- ci = clCreateImage3D(address(), flags, cfmt.address(), desc.imageWidth, desc.imageHeight, desc.imageDepth,
- desc.imageRowPitch, desc.imageSlicePitch, addr(hostseg), cres.address());
+ ci = clCreateImage3D(address(), flags, cfmt, desc.imageWidth, desc.imageHeight, desc.imageDepth,
+ desc.imageRowPitch, desc.imageSlicePitch, addr(hostseg), cres);
break;
default:
throw new UnsupportedOperationException("Requires OpenCL 1.2");
MemorySegment pprops = CLProperty.toNative(frame, properties);
MemorySegment pres = frame.allocateInt();
int res;
- MemoryAddress cp;
+ MemorySegment cp;
- cp = clCreatePipe(address(), flags, packetSize, maxPackets, pprops.address(), pres.address());
+ cp = clCreatePipe(address(), flags, packetSize, maxPackets, pprops, pres);
if ((res = pres.get(Memory.INT, 0)) != 0)
throw new CLRuntimeException(res);
int num;
int res;
- res = clGetSupportedImageFormats(address(), flags, type, 0, MemoryAddress.NULL, cnum.address());
+ res = clGetSupportedImageFormats(address(), flags, type, 0, MemorySegment.NULL, cnum);
if (res != 0)
throw new CLRuntimeException(res);
num = cnum.get(Memory.INT, 0);
list = frame.allocateAddress(8);
- res = clGetSupportedImageFormats(address(), flags, type, num, list.address(), cnum.address());
+ res = clGetSupportedImageFormats(address(), flags, type, num, list, cnum);
CLImageFormat[] out = new CLImageFormat[num];
for (int i = 0; i < out.length; i++)
- out[i] = CLImageFormat.fromNative(MemorySegment.ofAddress(list.getAtIndex(Memory.POINTER, i), CLImageFormat.layout().byteSize(), MemorySession.global()));
+ out[i] = CLImageFormat.fromNative(MemorySegment.ofAddress(list.getAtIndex(Memory.POINTER, i).address(), CLImageFormat.layout().byteSize()));
return out;
} catch (RuntimeException | Error t) {
try (Frame frame = Memory.createFrame()) {
MemorySegment cres = frame.allocateInt();
int res;
- MemoryAddress cs;
+ MemorySegment cs;
- cs = clCreateSampler(address(), norm ? 1 : 0, addr_mode, filter_mode, cres.address());
+ cs = clCreateSampler(address(), norm ? 1 : 0, addr_mode, filter_mode, cres);
if ((res = cres.get(Memory.INT, 0)) != 0)
throw new CLRuntimeException(res);
MemorySegment pprops = CLProperty.toNative(frame, properties);
MemorySegment pres = frame.allocateInt();
int res;
- MemoryAddress cs;
+ MemorySegment cs;
- cs = clCreateSamplerWithProperties(address(), pprops.address(), pres.address());
+ cs = clCreateSamplerWithProperties(address(), pprops, pres);
if ((res = pres.get(Memory.INT, 0)) != 0)
throw new CLRuntimeException(res);
MemorySegment cstring = frame.copy(buffer.address());
MemorySegment clength = frame.copy(size);
MemorySegment pres = frame.allocateInt();
- MemoryAddress cp;
+ MemorySegment cp;
int res;
- cp = clCreateProgramWithSource(address(), 1, cstring.address(), clength.address(), pres.address());
+ cp = clCreateProgramWithSource(address(), 1, cstring, clength, pres);
if ((res = pres.get(Memory.INT, 0)) != 0)
throw new CLException(res);
try (Frame frame = Memory.createFrame()) {
MemorySegment buffer = frame.copy(il);
MemorySegment pres = frame.allocateInt();
- MemoryAddress cp;
+ MemorySegment cp;
int res;
- cp = clCreateProgramWithIL(address(), buffer.address(), il.length, pres.address());
+ cp = clCreateProgramWithIL(address(), buffer, il.length, pres);
if ((res = pres.get(Memory.INT, 0)) != 0)
throw new CLException(res);
MemorySegment cdevs = frame.copy(devices);
MemorySegment barray = frame.allocateAddress(binaries.length);
MemorySegment larray = frame.allocateLong(binaries.length);
- MemorySegment cstatus = status != null ? frame.allocateInt(status.length) : MemorySegment.ofAddress(MemoryAddress.NULL, 0, MemorySession.global());
+ MemorySegment cstatus = status != null ? frame.allocateInt(status.length) : MemorySegment.NULL;
MemorySegment pres = frame.allocateInt();
- MemoryAddress cp;
+ MemorySegment cp;
int res;
for (int i = 0, o = 0; i < binaries.length; i++) {
o += binaries[i].length;
}
- cp = clCreateProgramWithBinary(address(), devices.length, cdevs.address(), larray.address(), barray.address(), cstatus.address(), pres.address());
+ cp = clCreateProgramWithBinary(address(), devices.length, cdevs, larray, barray, cstatus, pres);
if ((res = pres.get(Memory.INT, 0)) != 0)
throw new CLException(res);
MemorySegment cdevs = frame.copy(devices);
MemorySegment cnames = frame.copy(names);
MemorySegment pres = frame.allocateInt();
- MemoryAddress cp;
+ MemorySegment cp;
int res;
- cp = clCreateProgramWithBuiltInKernels(address(), devices.length, cdevs.address(), cnames.address(), pres.address());
+ cp = clCreateProgramWithBuiltInKernels(address(), devices.length, cdevs, cnames, pres);
if ((res = pres.get(Memory.INT, 0)) != 0)
throw new CLException(res);
MemorySegment coptions = frame.copy(options);
MemorySegment cprogs = frame.copy(programs);
MemorySegment pres = frame.allocateInt();
- MemoryAddress cp;
+ MemorySegment cp;
int res;
- cp = clLinkProgram(address(), devices.length, cdevs.address(), coptions.address(), programs.length, cprogs.address(), cnotify.address(), MemoryAddress.NULL, pres.address());
+ cp = clLinkProgram(address(), devices.length, cdevs, coptions, programs.length, cprogs, cnotify.address(), MemorySegment.NULL, pres);
if ((res = pres.get(Memory.INT, 0)) != 0)
throw new CLException(res);
try (Frame frame = Memory.createFrame()) {
MemorySegment pres = frame.allocateInt();
- MemoryAddress ce;
+ MemorySegment ce;
int res;
- ce = clCreateUserEvent(address(), pres.address());
+ ce = clCreateUserEvent(address(), pres);
if ((res = pres.get(Memory.INT, 0)) != 0)
throw new CLException(res);
GLext gl = getGLext();
try (Frame frame = Memory.createFrame()) {
MemorySegment cres = frame.allocateInt();
- MemoryAddress ce;
+ MemorySegment ce;
int res;
- ce = gl.clCreateFromGLBuffer(address(), flags, bufobj, cres.address());
+ ce = gl.clCreateFromGLBuffer(address(), flags, bufobj, cres);
if ((res = cres.get(Memory.INT, 0)) != 0)
throw new CLRuntimeException(res);
return Native.resolve(ce, (b) -> new CLBuffer(b, getObjectPlatform()));
GLext gl = getGLext();
try (Frame frame = Memory.createFrame()) {
MemorySegment pres = frame.allocateInt();
- MemoryAddress ce;
+ MemorySegment ce;
int res;
- ce = gl.clCreateFromGLTexture(address(), flags, target, miplevel, texture, pres.address());
+ ce = gl.clCreateFromGLTexture(address(), flags, target, miplevel, texture, pres);
if ((res = pres.get(Memory.INT, 0)) != 0)
throw new CLRuntimeException(res);
return Native.resolve(ce, (x) -> new CLImage(x, getObjectPlatform()));
GLext gl = getGLext();
try (Frame frame = Memory.createFrame()) {
MemorySegment pres = frame.allocateInt();
- MemoryAddress ce;
+ MemorySegment ce;
int res;
- ce = gl.clCreateFromGLRenderbuffer(address(), flags, renderbuffer, pres.address());
+ ce = gl.clCreateFromGLRenderbuffer(address(), flags, renderbuffer, pres);
if ((res = pres.get(Memory.INT, 0)) != 0)
throw new CLRuntimeException(res);
return Native.resolve(ce, (x) -> new CLImage(x, getObjectPlatform()));
/**
* @since cl_khr_gl_event extension
*/
- public CLEvent clCreateEventFromGLsyncKHR(MemoryAddress glsync) {
+ public CLEvent clCreateEventFromGLsyncKHR(MemorySegment glsync) {
GLext gl = getGLext();
try (Frame frame = Memory.createFrame()) {
MemorySegment pres = frame.allocateInt();
- MemoryAddress ce;
+ MemorySegment ce;
int res;
- ce = gl.clCreateEventFromGLsyncKHR(address(), glsync, pres.address());
+ ce = gl.clCreateEventFromGLsyncKHR(address(), glsync, pres);
if ((res = pres.get(Memory.INT, 0)) != 0)
throw new CLRuntimeException(res);
import java.lang.foreign.MemorySegment;
import api.Native;
import api.Callback;
-import java.lang.foreign.MemorySession;
/**
* Callback for CLContext.createContext*()
if (notify != null) {
return Native.resolve(
Call_pBpvJpv_v.stub((cwhat, cinfo, cinfolen, dummy) -> {
- MemorySegment seg = MemorySegment.ofAddress(cinfo, cinfolen, MemorySession.global());
+ MemorySegment seg = MemorySegment.ofAddress(cinfo.address(), cinfolen);
notify.notify(cwhat.getUtf8String(0), seg.asByteBuffer());
}),
(p) -> new Callback<>(p, notify));
*/
public class CLDevice extends CLObject {
- public CLDevice(MemoryAddress p, CLPlatform platform) {
+ public CLDevice(MemorySegment p, CLPlatform platform) {
super(p, platform);
}
- private static void release(MemoryAddress p) {
+ private static void release(MemorySegment p) {
try {
clReleaseDevice(p);
} catch (Throwable t) {
*/
ArrayList<Callback<CLEventNotify>> callbacks;
- public CLEvent(MemoryAddress p, CLPlatform platform) {
+ public CLEvent(MemorySegment p, CLPlatform platform) {
super(p, platform);
}
- public CLEvent(MemoryAddress p) {
+ public CLEvent(MemorySegment p) {
super(p);
}
- private static void release(MemoryAddress p) {
+ private static void release(MemorySegment p) {
try {
clReleaseEvent(p);
} catch (Throwable t) {
* Internal get platform.
* This goes via the context - every one must have a context?
*/
- static CLPlatform findPlatform(MemoryAddress cevent) {
+ static CLPlatform findPlatform(MemorySegment cevent) {
try (Frame frame = Memory.createFrame()) {
- MemoryAddress ccl = getInfo(cevent, CL_EVENT_CONTEXT, clGetEventInfo, frame, 8).get(Memory.POINTER, 0);
+ MemorySegment ccl = getInfo(cevent, CL_EVENT_CONTEXT, clGetEventInfo, frame, 8).get(Memory.POINTER, 0);
return CLContext.findPlatform(ccl);
} catch (RuntimeException | Error t) {
Callback<CLEventNotify> callback = CLEventNotify.call(notify);
try {
- int res = clSetEventCallback(address(), type, callback.address(), MemoryAddress.NULL);
+ int res = clSetEventCallback(address(), type, callback.address(), MemorySegment.NULL);
if (res != 0)
throw new CLRuntimeException(res);
package au.notzed.zcl;
import api.Memory;
-import java.lang.foreign.MemoryAddress;
import java.lang.foreign.MemorySegment;
import api.Native;
import static au.notzed.zcl.CLLib.*;
-import java.lang.foreign.MemorySession;
+import java.lang.foreign.Arena;
/**
* Manages a list of cl_events.
/**
* Scope is required for native allocation
*/
- final MemorySession scope = MemorySession.openConfined();
+ final Arena arena = Arena.openConfined();
/**
* Raw event values.
*/
*/
public CLEventList(int capacity) {
this.jevents = new CLEvent[capacity];
- this.cevents = scope.allocateArray(Memory.POINTER, capacity);
+ this.cevents = arena.allocateArray(Memory.POINTER, capacity);
}
/**
ev.release();
jevents[i] = null;
}
- cevents.setAtIndex(Memory.POINTER, i, MemoryAddress.NULL);
+ cevents.setAtIndex(Memory.POINTER, i, MemorySegment.NULL);
}
index = 0;
}
*/
public void release() {
reset();
- scope.close();
+ arena.close();
}
@Override
*
* This is used internally by CLCommandQueue.EventInfo to write directly to the event list.
*/
- public MemoryAddress slots() {
- return cevents.address();
+ public MemorySegment slots() {
+ return cevents;
}
/**
* @throws IllegalStateException if the CLEventList has been released.
* @throws ArrayIndexOutOfBoundsException if the CLEventList is full.
*/
- public MemoryAddress currentSlot() {
+ public MemorySegment currentSlot() {
if (index < jevents.length) {
MemorySegment addr = cevents.asSlice(index * 8);
// This should already be null, but this performs a range check
- addr.set(Memory.POINTER, 0, MemoryAddress.NULL);
- return addr.address();
+ addr.set(Memory.POINTER, 0, MemorySegment.NULL);
+ return addr;
} else
throw new ArrayIndexOutOfBoundsException();
}
public void waitForEvents() throws CLException {
if (size() > 0) {
try {
- int res = clWaitForEvents(size(), cevents.address());
+ int res = clWaitForEvents(size(), cevents);
if (res != 0)
throw new CLException(res);
} catch (CLException | RuntimeException | Error t) {
*/
public class CLImage<T> extends CLMemory {
- public CLImage(MemoryAddress p, CLPlatform platform) {
+ public CLImage(MemorySegment p, CLPlatform platform) {
super(p, platform, null);
}
- public CLImage(MemoryAddress p, CLPlatform platform, MemorySegment seg) {
+ public CLImage(MemorySegment p, CLPlatform platform, MemorySegment seg) {
super(p, platform, seg);
}
- static void release(MemoryAddress p) {
+ static void release(MemorySegment p) {
CLMemory.release(p);
}
@Override
public String toString() {
- return String.format("[%s: %dx%dx%d 0x%x]", getClass().getSimpleName(), getWidth(), getHeight(), getDepth(), address().toRawLongValue());
+ return String.format("[%s: %dx%dx%d 0x%x]", getClass().getSimpleName(), getWidth(), getHeight(), getDepth(), address().address());
}
/**
*/
public class CLKernel extends CLObject {
- CLKernel(MemoryAddress p, CLPlatform platform) {
+ CLKernel(MemorySegment p, CLPlatform platform) {
super(p, platform);
}
- private static void release(MemoryAddress p) {
+ private static void release(MemorySegment p) {
try {
clReleaseKernel(p);
} catch (Throwable t) {
try (Frame frame = Memory.createFrame()) {
MemorySegment pres = frame.allocateInt();
- MemoryAddress ck = clCloneKernel(address(), pres.address());
+ MemorySegment ck = clCloneKernel(address(), pres);
int res;
if ((res = pres.get(Memory.INT, 0)) != 0)
* Calls clGetKernelArg.
* pval is a pointer to the value.
*/
- private void setKernelArg(int index, long size, MemoryAddress pval) {
+ private void setKernelArg(int index, long size, MemorySegment pval) {
try {
int res;
* @param size The size to reserve in bytes.
*/
public void setArgLDS(int index, long size) {
- setKernelArg(index, size, MemoryAddress.NULL);
+ setKernelArg(index, size, MemorySegment.NULL);
}
/**
try (Frame frame = Memory.createFrame()) {
MemorySegment pval = frame.copy(o);
- setKernelArg(index, Memory.POINTER.byteSize(), pval.address());
+ setKernelArg(index, Memory.POINTER.byteSize(), pval);
}
}
try (Frame frame = Memory.createFrame()) {
MemorySegment pval = frame.copy(val);
- setKernelArg(index, 1, pval.address());
+ setKernelArg(index, 1, pval);
}
}
try (Frame frame = Memory.createFrame()) {
MemorySegment pval = frame.copy(val);
- setKernelArg(index, Memory.SHORT.byteSize(), pval.address());
+ setKernelArg(index, Memory.SHORT.byteSize(), pval);
}
}
try (Frame frame = Memory.createFrame()) {
MemorySegment pval = frame.copy(val);
- setKernelArg(index, Memory.INT.byteSize(), pval.address());
+ setKernelArg(index, Memory.INT.byteSize(), pval);
}
}
try (Frame frame = Memory.createFrame()) {
MemorySegment pval = frame.copy(val);
- setKernelArg(index, Memory.LONG.byteSize(), pval.address());
+ setKernelArg(index, Memory.LONG.byteSize(), pval);
}
}
try (Frame frame = Memory.createFrame()) {
MemorySegment pval = frame.copy(val);
- setKernelArg(index, Memory.FLOAT.byteSize(), pval.address());
+ setKernelArg(index, Memory.FLOAT.byteSize(), pval);
}
}
try (Frame frame = Memory.createFrame()) {
MemorySegment pval = frame.copy(val);
- setKernelArg(index, Memory.DOUBLE.byteSize(), pval.address());
+ setKernelArg(index, Memory.DOUBLE.byteSize(), pval);
}
}
MemorySegment pval = frame.allocate(val.byteSize(), 16);
pval.copyFrom(val);
- setKernelArg(index, pval.byteSize(), pval.address());
+ setKernelArg(index, pval.byteSize(), pval);
}
}
*/
Callback<CLNotify<CLMemory>> destroyCallback;
- CLMemory(MemoryAddress p, CLPlatform plat, MemorySegment seg) {
+ CLMemory(MemorySegment p, CLPlatform plat, MemorySegment seg) {
super(p, plat);
this.seg = seg;
* that are only given a 'mem object'.
*/
@Deprecated
- private static CLMemory create(MemoryAddress p, CLPlatform plat) {
- if (p.toRawLongValue() == 0)
+ private static CLMemory create(MemorySegment p, CLPlatform plat) {
+ if (p.address() == 0)
return null;
}
}
- static void release(MemoryAddress p) {
+ static void release(MemorySegment p) {
// note: no way to free the hostSegment, even if we could
try {
clReleaseMemObject(p);
destroyCallback = CLNotify.call(notify, (x) -> this);
try {
- int res = clSetMemObjectDestructorCallback(address(), destroyCallback.address(), MemoryAddress.NULL);
+ int res = clSetMemObjectDestructorCallback(address(), destroyCallback.address(), MemorySegment.NULL);
if (res != 0)
throw new CLException(res);
} catch (RuntimeException | Error t) {
MemorySegment cname = frame.allocateInt();
int res;
- res = getGLext().clGetGLObjectInfo(address(), ctype.address(), cname.address());
+ res = getGLext().clGetGLObjectInfo(address(), ctype, cname);
if (res != 0)
throw new CLRuntimeException(res);
return new GLObjectInfo(ctype.get(Memory.INT, 0), cname.get(Memory.INT, 0));
package au.notzed.zcl;
import java.util.function.Function;
-import java.lang.foreign.MemoryAddress;
import api.Native;
import api.Callback;
+import java.lang.foreign.MemorySegment;
/**
* Generic notify routine.
public void notify(T source);
@SuppressWarnings("unchecked")
- static <T extends Native> Callback<CLNotify<T>> call(CLNotify<T> notify, Function<MemoryAddress,T> create) {
+ static <T extends Native> Callback<CLNotify<T>> call(CLNotify<T> notify, Function<MemorySegment,T> create) {
if (notify != null) {
return Native.resolve(
Call_pLpv_v.stub((co, dummy) -> notify.notify(Native.resolve(co, create))),
/**
* Instantiate a new CLObject.
*
- * @param p address of object. May be MemoryAddress.NULL if required.
+ * @param p address of object. May be MemorySegment.NULL if required.
* @param platform This must not be null.
*/
- protected CLObject(MemoryAddress p, CLPlatform platform) {
+ protected CLObject(MemorySegment p, CLPlatform platform) {
super(p);
if (platform == null)
* If this constructor is called then getObjectPlatform() must
* be overridden.
*/
- protected CLObject(MemoryAddress p) {
+ protected CLObject(MemorySegment p) {
super(p);
}
// some are static for access before object instantiation
// new 5-param version
- static MemorySegment getInfo(MemoryAddress self, int id, MethodHandle getInfo, Frame frame, long size) throws CLRuntimeException {
+ static MemorySegment getInfo(MemorySegment self, int id, MethodHandle getInfo, Frame frame, long size) throws CLRuntimeException {
try {
MemorySegment addr = frame.allocate(size, 8);
int res;
- res = (int)getInfo.invokeExact((Addressable)self, id, size, (Addressable)addr.address(), (Addressable)MemoryAddress.NULL);
+ res = (int)getInfo.invokeExact(self, id, size, addr, MemorySegment.NULL);
if (res != 0)
throw new CLRuntimeException(res);
return getInfoLong(id, getInfo);
}
- protected <T extends CLObject> T getInfoAny(int id, MethodHandle getInfo, Function<MemoryAddress, T> create) {
+ protected <T extends CLObject> T getInfoAny(int id, MethodHandle getInfo, Function<MemorySegment, T> create) {
try (Frame frame = Memory.createFrame()) {
return Native.resolve(getInfo(address(), id, getInfo, frame, 8).get(Memory.POINTER, 0), create);
}
}
// new 5-param version for get any
- static MemorySegment getInfoAny(MemoryAddress addr, int id, MethodHandle getInfo, Frame frame) throws CLRuntimeException {
+ static MemorySegment getInfoAny(MemorySegment addr, int id, MethodHandle getInfo, Frame frame) throws CLRuntimeException {
try {
MemorySegment sizep = frame.allocateLong();
MemorySegment valp;
long size;
int res;
- res = (int)getInfo.invokeExact((Addressable)addr, id, 0L, (Addressable)MemoryAddress.NULL, (Addressable)sizep.address());
+ res = (int)getInfo.invokeExact(addr, id, 0L, MemorySegment.NULL, sizep);
size = sizep.get(Memory.LONG, 0);
valp = frame.allocate(size);
- res = (int)getInfo.invokeExact((Addressable)addr, id, size, (Addressable)valp.address(), (Addressable)sizep.address());
+ res = (int)getInfo.invokeExact(addr, id, size, valp, sizep);
if (res != 0)
throw new CLRuntimeException(res);
}
}
- protected <T extends CLObject> T[] getInfoAnyV(int id, MethodHandle getInfo, Function<MemoryAddress, T> create, IntFunction<T[]> createArray) {
+ protected <T extends CLObject> T[] getInfoAnyV(int id, MethodHandle getInfo, Function<MemorySegment, T> create, IntFunction<T[]> createArray) {
try (Frame frame = Memory.createFrame()) {
return Native.toObjectV(getInfoAny(address(), id, getInfo, frame), create, createArray);
} catch (RuntimeException | Error t) {
MemorySegment addr = frame.allocate(size, 16);
int res;
- res = (int)getInfo.invokeExact((Addressable)address(), (Addressable)ctx.address(), id, size, (Addressable)addr.address(), (Addressable)MemoryAddress.NULL);
+ res = (int)getInfo.invokeExact(address(), ctx.address(), id, size, addr, MemorySegment.NULL);
if (res != 0)
throw new CLRuntimeException(res);
long size;
int res;
- res = (int)getInfo.invokeExact((Addressable)address(), (Addressable)ctx.address(), id, 0L, (Addressable)MemoryAddress.NULL, (Addressable)sizep.address());
+ res = (int)getInfo.invokeExact(address(), ctx.address(), id, 0L, MemorySegment.NULL, sizep);
size = sizep.get(Memory.LONG, 0);
valp = frame.allocate(size, 16);
- res = (int)getInfo.invokeExact((Addressable)address(), (Addressable)ctx.address(), id, size, (Addressable)valp.address(), (Addressable)sizep.address());
+ res = (int)getInfo.invokeExact(address(), ctx.address(), id, size, valp, sizep);
if (res != 0)
throw new CLRuntimeException(res);
try {
// TODO: type for alignment
MemorySegment addr = frame.allocate(size, 16);
- int res = (int)getInfo.invokeExact((Addressable)address(), index, id, size, (Addressable)addr, (Addressable)MemoryAddress.NULL);
+ int res = (int)getInfo.invokeExact(address(), index, id, size, addr, MemorySegment.NULL);
if (res != 0)
throw new IllegalArgumentException();
long size;
int res;
- res = (int)getInfo.invokeExact((Addressable)address(), index, id, 0L, (Addressable)MemoryAddress.NULL, (Addressable)sizep.address());
+ res = (int)getInfo.invokeExact(address(), index, id, 0L, MemorySegment.NULL, sizep);
size = sizep.get(Memory.LONG, 0);
valp = frame.allocate(size, 16);
- res = (int)getInfo.invokeExact((Addressable)address(), index, id, size, (Addressable)valp.address(), (Addressable)sizep.address());
+ res = (int)getInfo.invokeExact(address(), index, id, size, valp, sizep);
if (res != 0)
throw new CLRuntimeException(res);
*/
public class CLPipe<T> extends CLMemory {
- public CLPipe(MemoryAddress p, CLPlatform platform) {
+ public CLPipe(MemorySegment p, CLPlatform platform) {
super(p, platform, null);
}
- public CLPipe(MemoryAddress p, CLPlatform platform, MemorySegment seg) {
+ public CLPipe(MemorySegment p, CLPlatform platform, MemorySegment seg) {
super(p, platform, seg);
}
return clGetPipeInfo;
}
- static void release(MemoryAddress p) {
+ static void release(MemorySegment p) {
CLMemory.release(p);
}
final int apiVersion;
- public CLPlatform(MemoryAddress p) {
+ public CLPlatform(MemorySegment p) {
super(p);
String v = getVersion();
}
}
- private static void release(MemoryAddress p) {
+ private static void release(MemorySegment p) {
// noop
System.out.println("** release clplatform");
}
int len;
int res;
- res = (int)clGetPlatformIDs.invokeExact(0, (Addressable)MemoryAddress.NULL, (Addressable)lenp.address());
+ res = (int)clGetPlatformIDs.invokeExact(0, MemorySegment.NULL, lenp);
if (res != 0)
throw new CLRuntimeException(res);
len = lenp.get(Memory.INT, 0);
list = frame.allocate(MemoryLayout.sequenceLayout(len, Memory.POINTER));
- res = (int)clGetPlatformIDs.invokeExact(len, (Addressable)list.address(), (Addressable)lenp.address());
+ res = (int)clGetPlatformIDs.invokeExact(len, list, lenp);
if (res != 0)
throw new CLRuntimeException(res);
MemorySegment list;
int res, len;
- res = (int)clGetDeviceIDs.invokeExact((Addressable)address(), type, 0, (Addressable)MemoryAddress.NULL, (Addressable)lenp.address());
+ res = (int)clGetDeviceIDs.invokeExact(address(), type, 0, MemorySegment.NULL, lenp);
if (res == CL_DEVICE_NOT_FOUND)
return new CLDevice[0];
len = lenp.get(Memory.INT, 0);
list = frame.allocate(MemoryLayout.sequenceLayout(len, Memory.POINTER));
- res = (int)clGetDeviceIDs.invokeExact((Addressable)address(), type, len, (Addressable)list.address(), (Addressable)lenp.address());
+ res = (int)clGetDeviceIDs.invokeExact(address(), type, len, list, lenp);
if (res != 0)
throw new CLRuntimeException(res);
* it falls back to clGetExtensionFunctionAddress.
*
* @param name extension function name
- * @return MemoryAddress of function entry point, or MemoryAddress.NULL.
+ * @return MemorySegment of function entry point, or MemorySegment.NULL.
*/
- public MemoryAddress clGetExtensionFunctionAddressForPlatform(String name) {
+ public MemorySegment clGetExtensionFunctionAddressForPlatform(String name) {
try (Frame frame = Memory.createFrame()) {
MemorySegment cname = frame.copy(name);
if (apiVersion >= VERSION_1_2) {
- return CLLib.clGetExtensionFunctionAddressForPlatform(address(), cname.address());
+ return CLLib.clGetExtensionFunctionAddressForPlatform(address(), cname);
} else {
- return clGetExtensionFunctionAddress(cname.address());
+ return clGetExtensionFunctionAddress(cname);
}
} catch (RuntimeException | Error t) {
throw t;
*/
public class CLProgram extends CLObject {
- CLProgram(MemoryAddress p, CLPlatform platform) {
+ CLProgram(MemorySegment p, CLPlatform platform) {
super(p, platform);
}
- private static void release(MemoryAddress p) {
+ private static void release(MemorySegment p) {
try {
clReleaseProgram(p);
} catch (Throwable t) {
MemorySegment poptions = frame.copy(options);
int res;
- res = clBuildProgram(address(), devices.length, pdevs.address(), poptions.address(), call.address(), MemoryAddress.NULL);
+ res = clBuildProgram(address(), devices.length, pdevs, poptions, call.address(), MemorySegment.NULL);
if (res != 0)
throw new CLException(res);
} catch (CLException | RuntimeException | Error t) {
MemorySegment cnames = frame.copy(header_names);
int res;
- res = clCompileProgram(address(), devices.length, cdevs.address(), poptions.address(), nheaders, cheaders.address(), cnames.address(), call.address(), MemoryAddress.NULL);
+ res = clCompileProgram(address(), devices.length, cdevs, poptions, nheaders, cheaders, cnames, call.address(), MemorySegment.NULL);
if (res != 0)
throw new CLException(res);
} catch (CLException | RuntimeException | Error t) {
MemorySegment pres = frame.allocateInt();
MemorySegment pname = frame.copy(name);
int res;
- MemoryAddress ck;
+ MemorySegment ck;
- ck = clCreateKernel(address(), pname.address(), pres.address());
+ ck = clCreateKernel(address(), pname, pres);
if ((res = pres.get(Memory.INT, 0)) != 0)
throw new CLException(res);
return resolve(ck, (x) -> new CLKernel(x, getObjectPlatform()));
MemorySegment ckern = frame.allocateAddress(count);
int res;
- res = clCreateKernelsInProgram(address(), count, ckern.address(), csize.address());
+ res = clCreateKernelsInProgram(address(), count, ckern, csize);
if (res != 0)
throw new CLRuntimeException();
try (Frame frame = Memory.createFrame()) {
MemorySegment seg = frame.allocate(size);
- MemoryAddress data = seg.address();
+ MemorySegment data = seg;
MemorySegment cptrs = frame.allocateAddress(sizes.length);
long off = 0;
int res;
for (int i = 0; i < sizes.length; i++) {
- cptrs.setAtIndex(Memory.POINTER, i, data.addOffset(off));
+ cptrs.setAtIndex(Memory.POINTER, i, data.asSlice(off));
off += sizes[i];
}
- res = clGetProgramInfo(address(), CL_PROGRAM_BINARIES, sizes.length * Memory.POINTER.byteSize(), cptrs.address(), MemoryAddress.NULL);
+ res = clGetProgramInfo(address(), CL_PROGRAM_BINARIES, sizes.length * Memory.POINTER.byteSize(), cptrs, MemorySegment.NULL);
if (res != 0)
throw new CLRuntimeException(res);
*/
public class CLSampler extends CLObject {
- public CLSampler(MemoryAddress p, CLPlatform platform) {
+ public CLSampler(MemorySegment p, CLPlatform platform) {
super(p, platform);
}
return clGetSamplerInfo;
}
- private static void release(MemoryAddress p) {
+ private static void release(MemorySegment p) {
try {
clReleaseSampler(p);
} catch (Throwable t) {
*/
class EventInfo {
public final int nwait;
- public final MemoryAddress wait;
- public final MemoryAddress event;
+ public final MemorySegment wait;
+ public final MemorySegment event;
// TODO: frame isn't used, maybe it should be removed? if so check callers where scope isn't doing anyting
public EventInfo(Frame frame, CLEventList waiters, CLEventList events) {
nwait = waiters != null ? waiters.size() : 0;
- wait = nwait > 0 ? waiters.slots() : MemoryAddress.NULL;
- event = events != null ? events.currentSlot() : MemoryAddress.NULL;
+ wait = nwait > 0 ? waiters.slots() : MemorySegment.NULL;
+ event = events != null ? events.currentSlot() : MemorySegment.NULL;
}
public void post(CLEventList events) {
my $type = typeToJava(\%param);
if ($ref =~ m/^u64:/) {
- return "MemoryAddress";
+ return "MemorySegment";
} elsif ($type =~ m/^(struct|union):/) {
return "MemorySegment";
} else {
print $dst "\t\tSymbolLookup ctx = SymbolLookup.loaderLookup();\n";
} else {
# address factory handle init
- print $dst "\tpublic $class{name}(Function<String,MemoryAddress> ctx) {\n";
+ print $dst "\tpublic $class{name}(Function<String,MemorySegment> ctx) {\n";
}
for $k (sort(findDefinition(\%data, 'func', @match))) {
my %func = %{$data{$k}};
my %param = %{$pi};
if ($param{deref} || ($param{type} =~ m/^struct|union/)) {
- print $dst "(Addressable)";
+ print $dst "(MemorySegment)";
}
print $dst "$param{name}";
print $dst ") throws Throwable;\n";
# downcall
- print $dst "\tstatic public $name of(MemoryAddress addr) {\n";
+ print $dst "\tstatic public $name of(MemorySegment addr) {\n";
print $dst "\t\tMethodHandle func = Native.downcallHandle(addr, \"$signature\");\n";
print $dst "\t\treturn (";
for $pi (@params) {
my %param = %{$pi};
if ($param{deref} || ($param{type} =~ m/^struct|union/)) {
- print $dst "(Addressable)";
+ print $dst "(MemorySegment)";
}
print $dst "$param{name}";
if ($param{deref}) {
public void testCreate4() throws Exception {
System.out.println("createBuffer COPY_HOST_PTR");
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment sega = MemorySegment.allocateNative(1024, 8, scope);
- MemorySegment segb = MemorySegment.allocateNative(1024, 8, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment sega = scope.allocate(1024, 8);
+ MemorySegment segb = scope.allocate(1024, 8);
fillSegment(sega, filla);
CLBuffer b = cl.createBuffer(CL_MEM_COPY_HOST_PTR, 1024, sega);
assertEquals(CLRuntimeException.class, x.getClass());
assertEquals(CL_INVALID_HOST_PTR, ((CLRuntimeException)x).err);
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment seg = MemorySegment.allocateNative(8, 8, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment seg = scope.allocate(8, 8);
x = null;
cl.createBuffer(0, 8, seg);
} catch (Throwable t) {
assertEquals(CLRuntimeException.class, x.getClass());
assertEquals(CL_INVALID_HOST_PTR, ((CLRuntimeException)x).err);
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment seg = MemorySegment.allocateNative(8, 8, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment seg = scope.allocate(8, 8);
x = null;
cl.createBuffer(0, seg);
} catch (Throwable t) {
Throwable x;
System.out.println("createBuffer sized segment");
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment seg = MemorySegment.allocateNative(720, 8, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment seg = scope.allocate(720, 8);
CLBuffer b = cl.createBuffer(CL_MEM_COPY_HOST_PTR, seg);
assertEquals(seg.byteSize(), b.getSize());
@Test
public void testMap1() throws Exception {
System.out.println("mapBuffer");
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment sega = MemorySegment.allocateNative(1024, 8, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment sega = scope.allocate(1024, 8);
fillSegment(sega, filla);
CLBuffer b = cl.createBuffer(CL_MEM_COPY_HOST_PTR, 1024, sega);
@Test
public void testMap2() throws Exception {
System.out.println("mapBuffer double unmap");
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment sega = MemorySegment.allocateNative(1024, 8, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment sega = scope.allocate(1024, 8);
fillSegment(sega, filla);
CLBuffer b = cl.createBuffer(CL_MEM_COPY_HOST_PTR, 1024, sega);
byte[] data = new byte[]{1, 2, 3, 4};
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment seg = MemorySegment.allocateNative(1024, 8, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment seg = scope.allocate(1024, 8);
CLBuffer b = cl.createBuffer(0, 1024);
q.enqueueFillBuffer(b, data, 0, 256, null, null);
CLEvent ev = cl.createUserEvent();
CLBuffer mem = cl.createBuffer(0, 64);
- try (MemorySession scope = MemorySession.openConfined();
+ try (Arena scope = Arena.openConfined();
CLEventList list = new CLEventList(1);
CLEventList wait = new CLEventList(1)) {
- MemorySegment seg = MemorySegment.allocateNative(64, 8, scope);
+ MemorySegment seg = scope.allocate(64, 8);
wait.add(ev);
assertEquals(ev, wait.get(0));
System.out.println("event callback, state");
CLBuffer mem = cl.createBuffer(0, 64);
- try (MemorySession scope = MemorySession.openConfined();
+ try (Arena scope = Arena.openConfined();
CLEventList list = new CLEventList(1)) {
- MemorySegment seg = MemorySegment.allocateNative(64, 8, scope);
+ MemorySegment seg = scope.allocate(64, 8);
CLEvent ev;
q.enqueueReadBuffer(mem, true, 0, 64, seg, null, list);
}
}
- void retainEvent(MemoryAddress x) {
+ void retainEvent(MemorySegment x) {
try {
clRetainEvent(x);
} catch (Throwable T) {
}
}
- int countEvent(MemoryAddress x) {
+ int countEvent(MemorySegment x) {
int res = -1;
try (Frame frame = Memory.createFrame()) {
MemorySegment pres = frame.allocateInt();
- clGetEventInfo(x, CL_EVENT_REFERENCE_COUNT, 4, pres.address(), MemoryAddress.NULL);
+ clGetEventInfo(x, CL_EVENT_REFERENCE_COUNT, 4, pres, MemorySegment.NULL);
res = pres.get(Memory.INT, 0);
} catch (Throwable T) {
}
return res;
}
- void releaseEvent(MemoryAddress x) {
+ void releaseEvent(MemorySegment x) {
try {
clReleaseEvent(x);
} catch (Throwable T) {
assertEquals(IllegalStateException.class, x.getClass());
CLBuffer mem = cl.createBuffer(0, 64);
- try (MemorySession scope = MemorySession.openConfined()) {
- MemorySegment seg = MemorySegment.allocateNative(64, 8, scope);
+ try (Arena scope = Arena.openConfined()) {
+ MemorySegment seg = scope.allocate(64, 8);
x = null;
q.enqueueReadBuffer(mem, false, 0, 64, seg, null, list);
} catch (Throwable t) {
public void testMulti() throws Exception {
System.out.println("multi");
CLBuffer mem = cl.createBuffer(0, 64);
- try (MemorySession scope = MemorySession.openConfined();
+ try (Arena scope = Arena.openConfined();
CLEventList list = new CLEventList(2);
CLEventList last = new CLEventList(1)) {
- MemorySegment seg = MemorySegment.allocateNative(64, 8, scope);
+ MemorySegment seg = scope.allocate(64, 8);
q.enqueueReadBuffer(mem, false, 0, 64, seg, null, list);
assertEquals(1, list.size());
public void testMultiWait() throws Exception {
System.out.println("multi wait");
CLBuffer mem = cl.createBuffer(0, 64);
- try (MemorySession scope = MemorySession.openConfined();
+ try (Arena scope = Arena.openConfined();
CLEventList list = new CLEventList(3)) {
- MemorySegment seg = MemorySegment.allocateNative(64, 8, scope);
+ MemorySegment seg = scope.allocate(64, 8);
q.enqueueReadBuffer(mem, false, 0, 64, seg, null, list);
assertEquals(1, list.size());
MemorySegment c = frame.allocate(2, 2);
MemorySegment d = frame.allocate(8, 8);
- assertEquals(b.address().toRawLongValue() & 15, 0);
- assertEquals(d.address().toRawLongValue() & 7, 0);
+ assertEquals(b.address() & 15, 0);
+ assertEquals(d.address() & 7, 0);
}
}
}
static void assertSeparate(MemorySegment a, MemorySegment b) {
- long ap = a.address().toRawLongValue();
+ long ap = a.address();
long as = a.byteSize();
- long bp = b.address().toRawLongValue();
+ long bp = b.address();
long bs = b.byteSize();
assertNotEquals(ap, bp);