Update to JDK 20 foreign-abi preview API.
authorNot Zed <notzed@gmail.com>
Tue, 9 May 2023 02:57:32 +0000 (12:27 +0930)
committerNot Zed <notzed@gmail.com>
Tue, 9 May 2023 02:57:32 +0000 (12:27 +0930)
32 files changed:
Makefile
nbproject/project.properties
src/notzed.zcl.demo/classes/au/notzed/zcl/test/TestAllocate.java
src/notzed.zcl.demo/classes/au/notzed/zcl/test/TestCopies.java
src/notzed.zcl.demo/classes/au/notzed/zcl/test/TestExtensions.java
src/notzed.zcl.demo/classes/au/notzed/zcl/test/TestMemory.java
src/notzed.zcl.demo/classes/au/notzed/zcl/test/TestMemoryLong.java
src/notzed.zcl/classes/api/Callback.java
src/notzed.zcl/classes/api/Frame.java
src/notzed.zcl/classes/api/Memory.java
src/notzed.zcl/classes/api/Native.java
src/notzed.zcl/classes/au/notzed/zcl/CLBuffer.java
src/notzed.zcl/classes/au/notzed/zcl/CLCommandQueue.java
src/notzed.zcl/classes/au/notzed/zcl/CLContext.java
src/notzed.zcl/classes/au/notzed/zcl/CLContextNotify.java
src/notzed.zcl/classes/au/notzed/zcl/CLDevice.java
src/notzed.zcl/classes/au/notzed/zcl/CLEvent.java
src/notzed.zcl/classes/au/notzed/zcl/CLEventList.java
src/notzed.zcl/classes/au/notzed/zcl/CLImage.java
src/notzed.zcl/classes/au/notzed/zcl/CLKernel.java
src/notzed.zcl/classes/au/notzed/zcl/CLMemory.java
src/notzed.zcl/classes/au/notzed/zcl/CLNotify.java
src/notzed.zcl/classes/au/notzed/zcl/CLObject.java
src/notzed.zcl/classes/au/notzed/zcl/CLPipe.java
src/notzed.zcl/classes/au/notzed/zcl/CLPlatform.java
src/notzed.zcl/classes/au/notzed/zcl/CLProgram.java
src/notzed.zcl/classes/au/notzed/zcl/CLSampler.java
src/notzed.zcl/classes/au/notzed/zcl/EventInfo.java
src/notzed.zcl/gen/generate-api
src/notzed.zcl/tests/au/notzed/zcl/CLBufferTest.java
src/notzed.zcl/tests/au/notzed/zcl/CLEventTest.java
src/notzed.zcl/tests/au/notzed/zcl/MemoryTest.java

index 6255afa..85aaa03 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -70,7 +70,7 @@ $(foreach host,$(maven_HOSTS),\
 # 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
index 03c200e..0f7e106 100644 (file)
@@ -48,8 +48,8 @@ javac.modulepath=\
 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}
index 232bb81..447ec9e 100644 (file)
@@ -21,11 +21,11 @@ public class TestAllocate {
                        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;
@@ -35,9 +35,9 @@ public class TestAllocate {
                        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;
@@ -47,11 +47,11 @@ public class TestAllocate {
                        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;
@@ -62,9 +62,9 @@ public class TestAllocate {
 
                                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;
index 5beaeaa..cdc5449 100644 (file)
@@ -7,7 +7,6 @@ import java.lang.foreign.*;
 
 import api.*;
 
-import java.nio.ByteOrder;
 import java.lang.invoke.VarHandle;
 import java.util.HashMap;
 import static java.lang.Math.*;
@@ -61,8 +60,8 @@ public class TestCopies {
                                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);
                                                }
                                        }
@@ -74,8 +73,8 @@ public class TestCopies {
                                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);
                                                }
                                        }
index b31b7ab..9a3acc8 100644 (file)
 
 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);
index 3b9f7d3..b46e5b3 100644 (file)
@@ -8,7 +8,7 @@ import java.nio.ByteBuffer;
 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.
@@ -64,7 +64,7 @@ public class TestMemory {
 
                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());
                }
 
index bcee335..7fcfa5d 100644 (file)
@@ -8,7 +8,7 @@ import java.nio.ByteBuffer;
 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.
@@ -64,7 +64,7 @@ public class TestMemoryLong {
 
                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());
                }
 
index ccbc391..bfc9faf 100644 (file)
 
 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;
@@ -41,11 +41,11 @@ public class Callback<T> extends Native implements AutoCloseable {
        }
 
        /*
-        * 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() {
                        }
@@ -54,7 +54,7 @@ public class Callback<T> extends Native implements AutoCloseable {
                        }
                };
 
-       private static void release(MemoryAddress p) {
+       private static void release(MemorySegment p) {
        }
 
        @Override
index 2cd854f..e66e760 100644 (file)
@@ -16,7 +16,6 @@
  */
 package api;
 
-import java.lang.foreign.MemoryAddress;
 import java.lang.foreign.MemoryLayout;
 import java.lang.foreign.MemorySegment;
 
@@ -144,7 +143,7 @@ public interface Frame extends AutoCloseable {
                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;
index 86bf7e5..4393822 100644 (file)
  */
 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;
@@ -28,7 +27,6 @@ import static java.lang.foreign.ValueLayout.JAVA_FLOAT;
 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.
@@ -54,7 +52,7 @@ public class Memory {
        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() {
@@ -67,7 +65,7 @@ public class Memory {
                private long sp;
                private Thread thread = Thread.currentThread();
 
-               Stack(MemorySession scope) {
+               Stack(SegmentScope scope) {
                        stack = MemorySegment.allocateNative(4096, 4096, scope);
                        sp = 4096;
                }
@@ -77,7 +75,7 @@ public class Memory {
                        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) {
@@ -89,20 +87,20 @@ public class Memory {
                                                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;
                                        }
                                }
 
@@ -110,9 +108,9 @@ public class Memory {
                                public void close() {
                                        sp = tos;
                                        self = null;
-                                       if (scope != null) {
-                                               scope.close();
-                                               scope = null;
+                                       if (arena != null) {
+                                               arena.close();
+                                               arena = null;
                                        }
                                }
                        };
index 805c5e3..8c8895e 100644 (file)
@@ -29,13 +29,11 @@ import java.lang.ref.WeakReference;
 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;
 
 /**
@@ -54,11 +52,11 @@ 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;
        }
 
@@ -66,26 +64,26 @@ public class Native {
                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);
        }
 
@@ -107,21 +105,21 @@ public class Native {
                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();
@@ -149,7 +147,7 @@ public class Native {
                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 {
@@ -160,7 +158,7 @@ public class Native {
                                                m.getName(),
                                                mt).bindTo(instance),
                                        FunctionDescriptor.of(resLayout, Arrays.copyOf(sig.layouts, n - 1)),
-                                       MemorySession.openShared());
+                                       SegmentScope.auto());
                        } else {
                                return abi.upcallStub(
                                        lookup.findVirtual(
@@ -168,7 +166,7 @@ public class Native {
                                                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);
@@ -269,7 +267,7 @@ public class Native {
                                                        }
 
                                                        if (pointerDepth > 0) {
-                                                               argClass.add(MemoryAddress.class);
+                                                               argClass.add(MemorySegment.class);
                                                                argLayout.add(Memory.POINTER);
                                                        } else {
                                                                switch (c) {
@@ -353,7 +351,7 @@ public class Native {
                                        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
@@ -381,7 +379,7 @@ public class Native {
                                                }
                                                //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);
@@ -436,10 +434,10 @@ public class Native {
         */
        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);
@@ -452,7 +450,7 @@ public class Native {
        }
 
        /*
-       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)
@@ -470,17 +468,13 @@ public class Native {
                }
                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.
@@ -502,7 +496,7 @@ public class Native {
                        }
                        {
                                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()));
                        }
                }
 
@@ -541,7 +535,7 @@ public class Native {
 
                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();
                }
@@ -606,11 +600,11 @@ public class Native {
 
        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();
@@ -620,9 +614,9 @@ public class Native {
                        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);
                                }
@@ -661,7 +655,7 @@ public class Native {
                /**
                 * 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;
                }
        }
@@ -694,7 +688,7 @@ public class Native {
                                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);
@@ -764,7 +758,7 @@ public class Native {
                        size += 1;
                }
 
-               public CHandle get(MemoryAddress p) {
+               public CHandle get(MemorySegment p) {
                        int i = CHandle.hashCode(p) & mask;
                        CHandle h = table[i];
 
@@ -773,7 +767,7 @@ public class Native {
                        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;
index d1caa41..6926afe 100644 (file)
@@ -28,15 +28,15 @@ import java.nio.ByteBuffer;
  */
 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);
        }
 
@@ -68,10 +68,10 @@ public class CLBuffer extends CLMemory {
                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);
 
index c4bd9d3..2d93104 100644 (file)
@@ -53,11 +53,11 @@ import java.util.function.Function;
  */
 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) {
@@ -151,7 +151,7 @@ public class CLCommandQueue extends CLObject {
 
                        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);
@@ -196,8 +196,8 @@ public class CLCommandQueue extends CLObject {
                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);
                }
@@ -223,8 +223,8 @@ public class CLCommandQueue extends CLObject {
                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);
                }
@@ -235,8 +235,8 @@ public class CLCommandQueue extends CLObject {
                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);
                }
@@ -247,8 +247,8 @@ public class CLCommandQueue extends CLObject {
                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);
                }
@@ -259,8 +259,8 @@ public class CLCommandQueue extends CLObject {
                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);
                }
@@ -271,8 +271,8 @@ public class CLCommandQueue extends CLObject {
                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);
                }
@@ -333,12 +333,12 @@ public class CLCommandQueue extends CLObject {
 
                        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)
@@ -377,8 +377,8 @@ public class CLCommandQueue extends CLObject {
                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,
@@ -442,7 +442,7 @@ public class CLCommandQueue extends CLObject {
 
                        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);
@@ -472,8 +472,8 @@ public class CLCommandQueue extends CLObject {
                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);
                }
@@ -484,8 +484,8 @@ public class CLCommandQueue extends CLObject {
                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);
                }
@@ -496,8 +496,8 @@ public class CLCommandQueue extends CLObject {
                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);
                }
@@ -508,8 +508,8 @@ public class CLCommandQueue extends CLObject {
                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);
                }
@@ -520,8 +520,8 @@ public class CLCommandQueue extends CLObject {
                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);
                }
@@ -532,8 +532,8 @@ public class CLCommandQueue extends CLObject {
                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);
                }
@@ -579,12 +579,12 @@ public class CLCommandQueue extends CLObject {
 
                        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)
@@ -675,7 +675,7 @@ public class CLCommandQueue extends CLObject {
 
                        res = clEnqueueFillBuffer(
                                address(), buffer.address(),
-                               pattern.address(), pattern.byteSize(),
+                               pattern, pattern.byteSize(),
                                offset * pattern.byteSize(),
                                size * pattern.byteSize(),
                                info.nwait, info.wait, info.event);
@@ -722,8 +722,8 @@ public class CLCommandQueue extends CLObject {
                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);
@@ -748,8 +748,8 @@ public class CLCommandQueue extends CLObject {
                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);
@@ -774,8 +774,8 @@ public class CLCommandQueue extends CLObject {
                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);
@@ -819,8 +819,8 @@ public class CLCommandQueue extends CLObject {
                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);
@@ -845,8 +845,8 @@ public class CLCommandQueue extends CLObject {
                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);
@@ -1000,8 +1000,8 @@ public class CLCommandQueue extends CLObject {
                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);
@@ -1330,10 +1330,10 @@ public class CLCommandQueue extends CLObject {
 
        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;
                }
@@ -1341,7 +1341,7 @@ public class CLCommandQueue extends CLObject {
 
        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));
                }
@@ -1356,17 +1356,17 @@ public class CLCommandQueue extends CLObject {
                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) {
@@ -1396,17 +1396,17 @@ public class CLCommandQueue extends CLObject {
                        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);
 
@@ -1422,7 +1422,7 @@ public class CLCommandQueue extends CLObject {
                                ? 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) {
@@ -1433,7 +1433,7 @@ public class CLCommandQueue extends CLObject {
        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);
@@ -1475,7 +1475,7 @@ public class CLCommandQueue extends CLObject {
                        return frame.copy(ws);
                } else {
                        // or null??
-                       return MemorySegment.ofAddress(MemoryAddress.NULL, 0, MemorySession.global());
+                       return MemorySegment.NULL;
                }
        }
 
@@ -1508,7 +1508,7 @@ public class CLCommandQueue extends CLObject {
                        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);
@@ -1584,7 +1584,7 @@ public class CLCommandQueue extends CLObject {
                        }
 
                        Callback<CLNativeKernel> call = Native.resolve(
-                               Call_pv_v.stub((MemoryAddress memargs) -> {
+                               Call_pv_v.stub((MemorySegment memargs) -> {
                                        int tmem = 0;
                                        int xmem = 0;
 
@@ -1594,14 +1594,14 @@ public class CLCommandQueue extends CLObject {
                                                        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++;
                                                }
                                        }
@@ -1610,7 +1610,7 @@ public class CLCommandQueue extends CLObject {
                                }),
                                (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);
@@ -1921,7 +1921,7 @@ public class CLCommandQueue extends CLObject {
                        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);
@@ -1944,7 +1944,7 @@ public class CLCommandQueue extends CLObject {
                        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);
index 20446bd..176a339 100644 (file)
@@ -44,7 +44,7 @@ public class CLContext extends CLObject {
        /**
         * platform must not be null.
         */
-       public CLContext(MemoryAddress p, CLPlatform platform) {
+       public CLContext(MemorySegment p, CLPlatform platform) {
                super(p, platform);
                this.notify = null;
        }
@@ -52,12 +52,12 @@ public class CLContext extends CLObject {
        /**
         * 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) {
@@ -89,7 +89,7 @@ public class CLContext extends CLObject {
         * @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());
        }
 
        /**
@@ -118,13 +118,13 @@ public class CLContext extends CLObject {
                        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)
@@ -147,11 +147,11 @@ public class CLContext extends CLObject {
        /**
         * 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) {
@@ -175,11 +175,11 @@ public class CLContext extends CLObject {
                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)
@@ -206,10 +206,10 @@ public class CLContext extends CLObject {
        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)
@@ -239,10 +239,10 @@ public class CLContext extends CLObject {
                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)
@@ -310,10 +310,10 @@ public class CLContext extends CLObject {
 
                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);
 
@@ -449,22 +449,22 @@ public class CLContext extends CLObject {
                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");
@@ -552,9 +552,9 @@ public class CLContext extends CLObject {
                        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);
 
@@ -581,18 +581,18 @@ public class CLContext extends CLObject {
                        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) {
@@ -647,9 +647,9 @@ public class CLContext extends CLObject {
                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);
 
@@ -677,9 +677,9 @@ public class CLContext extends CLObject {
                        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);
 
@@ -731,10 +731,10 @@ public class CLContext extends CLObject {
                        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);
 
@@ -781,10 +781,10 @@ public class CLContext extends CLObject {
                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);
 
@@ -813,9 +813,9 @@ public class CLContext extends CLObject {
                        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++) {
@@ -828,7 +828,7 @@ public class CLContext extends CLObject {
                                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);
 
@@ -862,10 +862,10 @@ public class CLContext extends CLObject {
                        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);
 
@@ -899,10 +899,10 @@ public class CLContext extends CLObject {
                        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);
 
@@ -927,10 +927,10 @@ public class CLContext extends CLObject {
 
                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);
 
@@ -1008,10 +1008,10 @@ public class CLContext extends CLObject {
                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()));
@@ -1033,10 +1033,10 @@ public class CLContext extends CLObject {
                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()));
@@ -1056,10 +1056,10 @@ public class CLContext extends CLObject {
                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()));
@@ -1095,14 +1095,14 @@ public class CLContext extends CLObject {
        /**
         * @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);
 
index 314b34c..21ca019 100644 (file)
@@ -20,7 +20,6 @@ import java.nio.ByteBuffer;
 import java.lang.foreign.MemorySegment;
 import api.Native;
 import api.Callback;
-import java.lang.foreign.MemorySession;
 
 /**
  * Callback for CLContext.createContext*()
@@ -34,7 +33,7 @@ public interface CLContextNotify {
                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));
index 5145602..5f8a086 100644 (file)
@@ -27,11 +27,11 @@ import java.util.stream.Stream;
  */
 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) {
index f6b6e0b..1da0e1f 100644 (file)
@@ -34,15 +34,15 @@ public class CLEvent extends CLObject {
         */
        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) {
@@ -74,9 +74,9 @@ public class CLEvent extends CLObject {
         * 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) {
@@ -125,7 +125,7 @@ public class CLEvent extends CLObject {
                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);
index 96f79de..486ecb0 100644 (file)
 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.
@@ -47,7 +46,7 @@ public final class CLEventList implements AutoCloseable {
        /**
         * Scope is required for native allocation
         */
-       final MemorySession scope = MemorySession.openConfined();
+       final Arena arena = Arena.openConfined();
        /**
         * Raw event values.
         */
@@ -69,7 +68,7 @@ public final class CLEventList implements AutoCloseable {
         */
        public CLEventList(int capacity) {
                this.jevents = new CLEvent[capacity];
-               this.cevents = scope.allocateArray(Memory.POINTER, capacity);
+               this.cevents = arena.allocateArray(Memory.POINTER, capacity);
        }
 
        /**
@@ -90,7 +89,7 @@ public final class CLEventList implements AutoCloseable {
                                ev.release();
                                jevents[i] = null;
                        }
-                       cevents.setAtIndex(Memory.POINTER, i, MemoryAddress.NULL);
+                       cevents.setAtIndex(Memory.POINTER, i, MemorySegment.NULL);
                }
                index = 0;
        }
@@ -103,7 +102,7 @@ public final class CLEventList implements AutoCloseable {
         */
        public void release() {
                reset();
-               scope.close();
+               arena.close();
        }
 
        @Override
@@ -116,8 +115,8 @@ public final class CLEventList implements AutoCloseable {
         *
         * 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;
        }
 
        /**
@@ -128,13 +127,13 @@ public final class CLEventList implements AutoCloseable {
         * @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();
        }
@@ -191,7 +190,7 @@ public final class CLEventList implements AutoCloseable {
        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) {
index c78b822..678fdeb 100644 (file)
@@ -30,15 +30,15 @@ import api.Memory;
  */
 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);
        }
 
@@ -93,7 +93,7 @@ public class CLImage<T> extends CLMemory {
 
        @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());
        }
 
        /**
index 1a16b57..34e1ae4 100644 (file)
@@ -30,11 +30,11 @@ import java.lang.invoke.MethodHandle;
  */
 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) {
@@ -58,7 +58,7 @@ public class CLKernel extends CLObject {
 
                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)
@@ -76,7 +76,7 @@ public class CLKernel extends CLObject {
         * 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;
 
@@ -108,7 +108,7 @@ public class CLKernel extends CLObject {
         * @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);
        }
 
        /**
@@ -121,7 +121,7 @@ public class CLKernel extends CLObject {
                try (Frame frame = Memory.createFrame()) {
                        MemorySegment pval = frame.copy(o);
 
-                       setKernelArg(index, Memory.POINTER.byteSize(), pval.address());
+                       setKernelArg(index, Memory.POINTER.byteSize(), pval);
                }
        }
 
@@ -136,7 +136,7 @@ public class CLKernel extends CLObject {
                try (Frame frame = Memory.createFrame()) {
                        MemorySegment pval = frame.copy(val);
 
-                       setKernelArg(index, 1, pval.address());
+                       setKernelArg(index, 1, pval);
                }
        }
 
@@ -151,7 +151,7 @@ public class CLKernel extends CLObject {
                try (Frame frame = Memory.createFrame()) {
                        MemorySegment pval = frame.copy(val);
 
-                       setKernelArg(index, Memory.SHORT.byteSize(), pval.address());
+                       setKernelArg(index, Memory.SHORT.byteSize(), pval);
                }
        }
 
@@ -166,7 +166,7 @@ public class CLKernel extends CLObject {
                try (Frame frame = Memory.createFrame()) {
                        MemorySegment pval = frame.copy(val);
 
-                       setKernelArg(index, Memory.INT.byteSize(), pval.address());
+                       setKernelArg(index, Memory.INT.byteSize(), pval);
                }
        }
 
@@ -181,7 +181,7 @@ public class CLKernel extends CLObject {
                try (Frame frame = Memory.createFrame()) {
                        MemorySegment pval = frame.copy(val);
 
-                       setKernelArg(index, Memory.LONG.byteSize(), pval.address());
+                       setKernelArg(index, Memory.LONG.byteSize(), pval);
                }
        }
 
@@ -195,7 +195,7 @@ public class CLKernel extends CLObject {
                try (Frame frame = Memory.createFrame()) {
                        MemorySegment pval = frame.copy(val);
 
-                       setKernelArg(index, Memory.FLOAT.byteSize(), pval.address());
+                       setKernelArg(index, Memory.FLOAT.byteSize(), pval);
                }
        }
 
@@ -209,7 +209,7 @@ public class CLKernel extends CLObject {
                try (Frame frame = Memory.createFrame()) {
                        MemorySegment pval = frame.copy(val);
 
-                       setKernelArg(index, Memory.DOUBLE.byteSize(), pval.address());
+                       setKernelArg(index, Memory.DOUBLE.byteSize(), pval);
                }
        }
 
@@ -233,7 +233,7 @@ public class CLKernel extends CLObject {
                        MemorySegment pval = frame.allocate(val.byteSize(), 16);
 
                        pval.copyFrom(val);
-                       setKernelArg(index, pval.byteSize(), pval.address());
+                       setKernelArg(index, pval.byteSize(), pval);
                }
        }
 
index 1c0c8a3..8673919 100644 (file)
@@ -77,7 +77,7 @@ public abstract class CLMemory extends CLObject {
         */
        Callback<CLNotify<CLMemory>> destroyCallback;
 
-       CLMemory(MemoryAddress p, CLPlatform plat, MemorySegment seg) {
+       CLMemory(MemorySegment p, CLPlatform plat, MemorySegment seg) {
                super(p, plat);
 
                this.seg = seg;
@@ -93,8 +93,8 @@ public abstract class CLMemory extends CLObject {
         * 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;
 
 
@@ -120,7 +120,7 @@ public abstract class CLMemory extends CLObject {
                }
        }
 
-       static void release(MemoryAddress p) {
+       static void release(MemorySegment p) {
                // note: no way to free the hostSegment, even if we could
                try {
                        clReleaseMemObject(p);
@@ -159,7 +159,7 @@ public abstract class CLMemory extends CLObject {
                        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) {
@@ -269,7 +269,7 @@ public abstract class CLMemory extends CLObject {
                        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));
index 8bb3e8e..17adb56 100644 (file)
@@ -17,9 +17,9 @@
 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.
@@ -31,7 +31,7 @@ public interface CLNotify<T> {
        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))),
index 142d91e..699bfb3 100644 (file)
@@ -56,10 +56,10 @@ public abstract class CLObject extends Native {
        /**
         * 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)
@@ -72,7 +72,7 @@ public abstract class CLObject extends Native {
         * If this constructor is called then getObjectPlatform() must
         * be overridden.
         */
-       protected CLObject(MemoryAddress p) {
+       protected CLObject(MemorySegment p) {
                super(p);
        }
 
@@ -101,12 +101,12 @@ public abstract class CLObject extends Native {
 
        // 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);
 
@@ -134,7 +134,7 @@ public abstract class CLObject extends Native {
                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);
                }
@@ -147,19 +147,19 @@ public abstract class CLObject extends Native {
        }
 
        // 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);
@@ -196,7 +196,7 @@ public abstract class CLObject extends Native {
                }
        }
 
-       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) {
@@ -213,7 +213,7 @@ public abstract class CLObject extends Native {
                        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);
 
@@ -250,12 +250,12 @@ public abstract class CLObject extends Native {
                        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);
@@ -308,7 +308,7 @@ public abstract class CLObject extends Native {
                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();
@@ -340,12 +340,12 @@ public abstract class CLObject extends Native {
                        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);
index 15f20a0..1c83c53 100644 (file)
@@ -28,11 +28,11 @@ import java.lang.invoke.MethodHandle;
  */
 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);
        }
 
@@ -41,7 +41,7 @@ public class CLPipe<T> extends CLMemory {
                return clGetPipeInfo;
        }
 
-       static void release(MemoryAddress p) {
+       static void release(MemorySegment p) {
                CLMemory.release(p);
        }
 
index 601f531..bb2dbe6 100644 (file)
@@ -39,7 +39,7 @@ public class CLPlatform extends CLObject {
 
        final int apiVersion;
 
-       public CLPlatform(MemoryAddress p) {
+       public CLPlatform(MemorySegment p) {
                super(p);
 
                String v = getVersion();
@@ -54,7 +54,7 @@ public class CLPlatform extends CLObject {
                }
        }
 
-       private static void release(MemoryAddress p) {
+       private static void release(MemorySegment p) {
                // noop
                System.out.println("** release clplatform");
        }
@@ -95,14 +95,14 @@ public class CLPlatform extends CLObject {
                        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);
 
@@ -129,7 +129,7 @@ public class CLPlatform extends CLObject {
                        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];
@@ -139,7 +139,7 @@ public class CLPlatform extends CLObject {
                        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);
 
@@ -212,16 +212,16 @@ public class CLPlatform extends CLObject {
         * 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;
index 5f06a34..75aefd0 100644 (file)
@@ -31,11 +31,11 @@ import java.util.stream.LongStream;
  */
 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) {
@@ -63,7 +63,7 @@ public class CLProgram extends CLObject {
                        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) {
@@ -126,7 +126,7 @@ public class CLProgram extends CLObject {
                        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) {
@@ -149,9 +149,9 @@ public class CLProgram extends CLObject {
                        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()));
@@ -176,7 +176,7 @@ public class CLProgram extends CLObject {
                        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();
 
@@ -214,16 +214,16 @@ public class CLProgram extends CLObject {
 
                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);
index d400fe0..91cba5e 100644 (file)
@@ -26,7 +26,7 @@ import java.lang.invoke.MethodHandle;
  */
 public class CLSampler extends CLObject {
 
-       public CLSampler(MemoryAddress p, CLPlatform platform) {
+       public CLSampler(MemorySegment p, CLPlatform platform) {
                super(p, platform);
        }
 
@@ -35,7 +35,7 @@ public class CLSampler extends CLObject {
                return clGetSamplerInfo;
        }
 
-       private static void release(MemoryAddress p) {
+       private static void release(MemorySegment p) {
                try {
                        clReleaseSampler(p);
                } catch (Throwable t) {
index 6a958ad..f21d34e 100644 (file)
@@ -30,14 +30,14 @@ import java.lang.foreign.*;
  */
 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) {
index 812a832..62d24c3 100755 (executable)
@@ -416,7 +416,7 @@ sub typeToRaw {
     my $type = typeToJava(\%param);
 
     if ($ref =~ m/^u64:/) {
-       return "MemoryAddress";
+       return "MemorySegment";
     } elsif ($type =~ m/^(struct|union):/) {
        return "MemorySegment";
     } else {
@@ -988,7 +988,7 @@ END
            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}};
@@ -1030,7 +1030,7 @@ END
            my %param = %{$pi};
 
                if ($param{deref} || ($param{type} =~ m/^struct|union/)) {
-                       print $dst "(Addressable)";
+                       print $dst "(MemorySegment)";
                }
 
            print $dst "$param{name}";
@@ -1114,7 +1114,7 @@ END
        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) {
@@ -1300,7 +1300,7 @@ END
            my %param = %{$pi};
 
                if ($param{deref} || ($param{type} =~ m/^struct|union/)) {
-                       print $dst "(Addressable)";
+                       print $dst "(MemorySegment)";
                }
            print $dst "$param{name}";
            if ($param{deref}) {
index c7109b6..7a00594 100644 (file)
@@ -122,9 +122,9 @@ public class CLBufferTest {
        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);
@@ -159,8 +159,8 @@ public class CLBufferTest {
                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) {
@@ -169,8 +169,8 @@ public class CLBufferTest {
                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) {
@@ -205,8 +205,8 @@ public class CLBufferTest {
                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());
@@ -231,8 +231,8 @@ public class CLBufferTest {
        @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);
@@ -252,8 +252,8 @@ public class CLBufferTest {
        @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);
@@ -285,8 +285,8 @@ public class CLBufferTest {
 
                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);
index 4e95c46..b9af4d5 100644 (file)
@@ -72,10 +72,10 @@ public class CLEventTest {
                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));
@@ -103,9 +103,9 @@ public class CLEventTest {
                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);
@@ -134,25 +134,25 @@ public class CLEventTest {
                }
        }
 
-       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) {
@@ -184,8 +184,8 @@ public class CLEventTest {
                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) {
@@ -198,10 +198,10 @@ public class CLEventTest {
        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());
@@ -229,9 +229,9 @@ public class CLEventTest {
        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());
index 1e9f3b6..ae5ede8 100644 (file)
@@ -39,8 +39,8 @@ public class MemoryTest {
                        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);
                }
        }
 
@@ -110,9 +110,9 @@ public class MemoryTest {
        }
 
        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);