From: Not Zed Date: Mon, 26 Sep 2022 02:16:08 +0000 (+0930) Subject: Updated to OpenJDK 19 java.lang.foriegn preview API. X-Git-Url: https://code.zedzone.au/cvs?a=commitdiff_plain;h=138e910e6d4dc91ed667a5cc09b7fa46628e8b41;p=zcl Updated to OpenJDK 19 java.lang.foriegn preview API. --- diff --git a/Makefile b/Makefile index 796d6d6..6255afa 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ notzed.zcl.demo_DEMOS=au.notzed.zcl.tools.clinfo \ notzed.zcl.fxdemo_DEMOS=fxdemo.fract.Mandelbrot fxdemo.fract.Test -DEMOFLAGS=--enable-native-access=notzed.zcl +DEMOFLAGS=--enable-native-access=notzed.zcl --enable-preview # module class basename(class) define java_demo= diff --git a/README b/README index 4c00a31..260caea 100644 --- a/README +++ b/README @@ -1,4 +1,12 @@ +foreign-abi branch note 20220926 +-------------------------------- + +I've updated it to OpenJDK 19 and it builds and clinfo runs, but since +I don't have a working OpenCL on my Renior laptop even after a couple +of years I'm not inclined to bother and i'm focusing on learning +vulkan compute instead, albeit slowly. + foreign-abi branch note ----------------------- diff --git a/config.make.in b/config.make.in index 628f6d8..5904cea 100644 --- a/config.make.in +++ b/config.make.in @@ -4,7 +4,7 @@ TARGET ?= linux-amd64 JAVA_HOME ?= /usr/local/jdk JAVAFX_HOME ?= /usr/local/javafx-sdk -JAVACFLAGS += --add-exports jdk.incubator.foreign/jdk.incubator.foreign.unsafe=notzed.zcl +JAVACFLAGS += --enable-preview --source 19 JAVA ?= $(JAVA_HOME)/bin/java JAVAC ?= $(JAVA_HOME)/bin/javac diff --git a/nbproject/project.properties b/nbproject/project.properties index ad1c93c..03c200e 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -40,16 +40,16 @@ includes=** jar.compress=false javac.classpath= # Space-separated list of extra javac options -javac.compilerargs=-Xlint:unchecked --add-exports jdk.incubator.foreign/jdk.incubator.foreign.unsafe=notzed.zcl +javac.compilerargs=-Xlint:unchecked --enable-preview javac.deprecation=false javac.external.vm=false javac.modulepath=\ - ${libs.JavaFX_13.classpath} + ${libs.JavaFX.classpath} javac.processormodulepath= javac.processorpath=\ ${javac.classpath} -javac.source=17 -javac.target=17 +javac.source=19 +javac.target=19 javac.test.classpath=\ ${libs.junit_4.classpath}:\ ${javac.classpath} @@ -82,7 +82,7 @@ run.classpath= # Space-separated list of JVM arguments used when running the project. # You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. # To set system properties for unit tests define test-sys-prop.name=value: -run.jvmargs=--enable-native-access=notzed.zcl -Djava.library.path=/usr/lib64 +run.jvmargs=--enable-native-access=notzed.zcl -Djava.library.path=/usr/lib64 --enable-preview run.modulepath=\ ${javac.modulepath}:\ ${build.modules.dir} diff --git a/src/notzed.zcl.demo/classes/au/notzed/zcl/test/TestAllocate.java b/src/notzed.zcl.demo/classes/au/notzed/zcl/test/TestAllocate.java index 89b1d7f..232bb81 100644 --- a/src/notzed.zcl.demo/classes/au/notzed/zcl/test/TestAllocate.java +++ b/src/notzed.zcl.demo/classes/au/notzed/zcl/test/TestAllocate.java @@ -3,7 +3,7 @@ */ package au.notzed.zcl.test; -import jdk.incubator.foreign.*; +import java.lang.foreign.*; import api.*; @@ -21,7 +21,7 @@ public class TestAllocate { if (true) { now = System.nanoTime(); for (int l = 0; l < X; l++) { - try (ResourceScope scope = ResourceScope.newConfinedScope()) { + 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); @@ -35,7 +35,7 @@ public class TestAllocate { if (false) { now = System.nanoTime(); for (int l = 0; l < X; l++) { - try (ResourceScope scope = ResourceScope.newConfinedScope()) { + try (MemorySession scope = MemorySession.openConfined()) { MemorySegment arg0 = MemorySegment.allocateNative(8, 8, scope); MemorySegment arg1 = MemorySegment.allocateNative(8, 8, scope); } @@ -47,11 +47,11 @@ public class TestAllocate { if (false) { now = System.nanoTime(); for (int l = 0; l < X; l++) { - try (ResourceScope scope = ResourceScope.newConfinedScope()) { - MemorySegment arg0 = MemorySegment.allocateNative(CLinker.C_POINTER, scope); - MemorySegment arg1 = MemorySegment.allocateNative(CLinker.C_POINTER, scope); - MemorySegment arg2 = MemorySegment.allocateNative(CLinker.C_POINTER, scope); - MemorySegment arg3 = MemorySegment.allocateNative(CLinker.C_POINTER, scope); + 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); } } long u = System.nanoTime() - now; @@ -62,9 +62,9 @@ public class TestAllocate { now = System.nanoTime(); for (int l = 0; l < X; l++) { - try (ResourceScope scope = ResourceScope.newConfinedScope()) { - MemorySegment arg0 = MemorySegment.allocateNative(CLinker.C_POINTER, scope); - MemorySegment arg1 = MemorySegment.allocateNative(CLinker.C_POINTER, scope); + try (MemorySession scope = MemorySession.openConfined()) { + MemorySegment arg0 = MemorySegment.allocateNative(Memory.POINTER, scope); + MemorySegment arg1 = MemorySegment.allocateNative(Memory.POINTER, scope); } } long m = System.nanoTime() - now; diff --git a/src/notzed.zcl.demo/classes/au/notzed/zcl/test/TestCopies.java b/src/notzed.zcl.demo/classes/au/notzed/zcl/test/TestCopies.java index 1d7481a..5beaeaa 100644 --- a/src/notzed.zcl.demo/classes/au/notzed/zcl/test/TestCopies.java +++ b/src/notzed.zcl.demo/classes/au/notzed/zcl/test/TestCopies.java @@ -3,7 +3,7 @@ */ package au.notzed.zcl.test; -import jdk.incubator.foreign.*; +import java.lang.foreign.*; import api.*; @@ -14,9 +14,9 @@ import static java.lang.Math.*; public class TestCopies { - final static VarHandle longHandle = MemoryHandles.varHandle(long.class, ByteOrder.nativeOrder()); - final static SequenceLayout longVLayout = MemoryLayout.sequenceLayout(CLinker.C_LONG); - final static VarHandle longVHandle = longVLayout.varHandle(long.class, MemoryLayout.PathElement.sequenceElement()); + final static VarHandle longHandle = Memory.LONG.varHandle(); + final static SequenceLayout longVLayout = MemoryLayout.sequenceLayout(-1, Memory.LONG); + final static VarHandle longVHandle = Memory.LONG.arrayElementVarHandle(); public static long getLong(MemorySegment p) { return (long)longHandle.get(p); @@ -61,7 +61,7 @@ public class TestCopies { if (true) { now = System.nanoTime(); for (int l = 0; l < X; l++) { - try (ResourceScope scope = ResourceScope.newConfinedScope()) { + try (MemorySession scope = MemorySession.openConfined()) { MemorySegment seg = MemorySegment.allocateNative(data.length * 8, scope); copyLoop(data, seg); } @@ -74,7 +74,7 @@ public class TestCopies { if (true) { now = System.nanoTime(); for (int l = 0; l < X; l++) { - try (ResourceScope scope = ResourceScope.newConfinedScope()) { + try (MemorySession scope = MemorySession.openConfined()) { MemorySegment seg = MemorySegment.allocateNative(data.length * 8, scope); copyBulk(data, seg); } @@ -94,7 +94,7 @@ public class TestCopies { now = System.nanoTime(); for (int l = 0; l < X; l++) { try (Frame frame = api.Memory.createFrame()) { - MemorySegment seg = frame.allocate(CLinker.C_POINTER, data.length); + MemorySegment seg = frame.allocate(Memory.POINTER, data.length); copyLoop(data, seg); } } @@ -107,7 +107,7 @@ public class TestCopies { now = System.nanoTime(); for (int l = 0; l < X; l++) { try (Frame frame = api.Memory.createFrame()) { - MemorySegment seg = frame.allocate(CLinker.C_POINTER, data.length); + MemorySegment seg = frame.allocate(Memory.POINTER, data.length); copyBulk(data, seg); } } diff --git a/src/notzed.zcl.demo/classes/au/notzed/zcl/test/TestExtensions.java b/src/notzed.zcl.demo/classes/au/notzed/zcl/test/TestExtensions.java index a91758d..b31b7ab 100644 --- a/src/notzed.zcl.demo/classes/au/notzed/zcl/test/TestExtensions.java +++ b/src/notzed.zcl.demo/classes/au/notzed/zcl/test/TestExtensions.java @@ -22,8 +22,8 @@ import au.notzed.zcl.CL; import au.notzed.zcl.CLContext; import au.notzed.zcl.CLPlatform; import java.util.stream.Stream; -import jdk.incubator.foreign.MemoryAddress; -import jdk.incubator.foreign.MemorySegment; +import java.lang.foreign.MemoryAddress; +import java.lang.foreign.MemorySegment; public class TestExtensions { diff --git a/src/notzed.zcl.demo/classes/au/notzed/zcl/test/TestMemory.java b/src/notzed.zcl.demo/classes/au/notzed/zcl/test/TestMemory.java index 276c1fe..3b9f7d3 100644 --- a/src/notzed.zcl.demo/classes/au/notzed/zcl/test/TestMemory.java +++ b/src/notzed.zcl.demo/classes/au/notzed/zcl/test/TestMemory.java @@ -3,14 +3,12 @@ */ package au.notzed.zcl.test; -import api.Native; +import api.Memory; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; -import jdk.incubator.foreign.MemoryAccess; -import jdk.incubator.foreign.MemoryAddress; -import jdk.incubator.foreign.MemorySegment; -import jdk.incubator.foreign.ResourceScope; +import java.lang.foreign.MemorySegment; +import java.lang.foreign.MemorySession; /** * Some memory tests. @@ -22,8 +20,8 @@ public class TestMemory { float sum = 0; for (int i = 0; i < len; i++) - sum += MemoryAccess.getFloatAtIndex(seg, i); - MemoryAccess.setFloat(seg, sum); + sum += seg.getAtIndex(Memory.FLOAT, i); + seg.set(Memory.FLOAT, 0, sum); } static void check(float[] seg) { @@ -66,11 +64,11 @@ 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, ResourceScope.globalScope()); + segments[i] = MemorySegment.allocateNative(sizes[i] * 4, 16, MemorySession.global()); buffers[i] = ByteBuffer.allocateDirect(sizes[i] * 4).order(ByteOrder.nativeOrder()); } - for (int c = 0; c < 10; c++) { + for (int c = 0; c < 3; c++) { long now; now = System.nanoTime(); diff --git a/src/notzed.zcl.demo/classes/au/notzed/zcl/test/TestMemoryLong.java b/src/notzed.zcl.demo/classes/au/notzed/zcl/test/TestMemoryLong.java index bc8581e..bcee335 100644 --- a/src/notzed.zcl.demo/classes/au/notzed/zcl/test/TestMemoryLong.java +++ b/src/notzed.zcl.demo/classes/au/notzed/zcl/test/TestMemoryLong.java @@ -3,12 +3,12 @@ */ package au.notzed.zcl.test; +import api.Memory; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.LongBuffer; -import jdk.incubator.foreign.MemoryAccess; -import jdk.incubator.foreign.MemorySegment; -import jdk.incubator.foreign.ResourceScope; +import java.lang.foreign.MemorySegment; +import java.lang.foreign.MemorySession; /** * Some memory tests. @@ -20,8 +20,8 @@ public class TestMemoryLong { long sum = 0; for (int i = 0; i < len; i++) - sum += MemoryAccess.getLongAtIndex(seg, i); - MemoryAccess.setLong(seg, sum); + sum += seg.getAtIndex(Memory.LONG, i); + seg.set(Memory.LONG, 0, sum); } static void check(long[] seg) { @@ -64,11 +64,11 @@ 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, ResourceScope.globalScope()); + segments[i] = MemorySegment.allocateNative(sizes[i] * 8, 16, MemorySession.global()); buffers[i] = ByteBuffer.allocateDirect(sizes[i] * 8).order(ByteOrder.nativeOrder()); } - for (int c = 0; c < 10; c++) { + for (int c = 0; c < 3; c++) { long now; now = System.nanoTime(); diff --git a/src/notzed.zcl.demo/classes/au/notzed/zcl/test/TestObjects.java b/src/notzed.zcl.demo/classes/au/notzed/zcl/test/TestObjects.java index 4b0db81..cb6a17d 100644 --- a/src/notzed.zcl.demo/classes/au/notzed/zcl/test/TestObjects.java +++ b/src/notzed.zcl.demo/classes/au/notzed/zcl/test/TestObjects.java @@ -25,7 +25,7 @@ public class TestObjects { CLDevice dev = CLPlatform.getBestDevice(CL.CL_DEVICE_TYPE_ALL); cl = CLContext.createContext(null, new CLDevice[]{dev}); - for (int c = 0; c < 10; c++) { + for (int c = 0; c < 3; c++) { long now; now = System.nanoTime(); diff --git a/src/notzed.zcl.demo/classes/module-info.java b/src/notzed.zcl.demo/classes/module-info.java index e9b21e9..2fda2d1 100644 --- a/src/notzed.zcl.demo/classes/module-info.java +++ b/src/notzed.zcl.demo/classes/module-info.java @@ -22,7 +22,6 @@ */ module notzed.zcl.demo { requires notzed.zcl; - requires jdk.incubator.foreign; - + exports au.notzed.zcl.tools; } diff --git a/src/notzed.zcl/classes/api/Callback.java b/src/notzed.zcl/classes/api/Callback.java index c6c2208..ccbc391 100644 --- a/src/notzed.zcl/classes/api/Callback.java +++ b/src/notzed.zcl/classes/api/Callback.java @@ -24,7 +24,7 @@ package api; -import jdk.incubator.foreign.*; +import java.lang.foreign.MemoryAddress; public class Callback extends Native implements AutoCloseable { T func; diff --git a/src/notzed.zcl/classes/api/Frame.java b/src/notzed.zcl/classes/api/Frame.java index bb89a5c..2cd854f 100644 --- a/src/notzed.zcl/classes/api/Frame.java +++ b/src/notzed.zcl/classes/api/Frame.java @@ -16,11 +16,9 @@ */ package api; -import jdk.incubator.foreign.CLinker; -import jdk.incubator.foreign.MemoryAccess; -import jdk.incubator.foreign.MemoryAddress; -import jdk.incubator.foreign.MemoryLayout; -import jdk.incubator.foreign.MemorySegment; +import java.lang.foreign.MemoryAddress; +import java.lang.foreign.MemoryLayout; +import java.lang.foreign.MemorySegment; // TODO: after writing this i discovered SegmentAllocator, perhaps should be one of those. public interface Frame extends AutoCloseable { @@ -51,62 +49,62 @@ public interface Frame extends AutoCloseable { } default MemorySegment allocateInt() { - return allocate(CLinker.C_INT); + return allocate(Memory.INT); } default MemorySegment allocateInt(int count) { - return allocate(CLinker.C_INT, count); + return allocate(Memory.INT, count); } default MemorySegment allocateLong() { - return allocate(CLinker.C_LONG); + return allocate(Memory.LONG); } default MemorySegment allocateLong(int count) { - return allocate(CLinker.C_LONG, count); + return allocate(Memory.LONG, count); } default MemorySegment allocateAddress() { - return allocate(CLinker.C_POINTER); + return allocate(Memory.POINTER); } default MemorySegment allocateAddress(int count) { - return allocate(CLinker.C_POINTER, count); + return allocate(Memory.POINTER, count); } default MemorySegment copy(byte value) { - MemorySegment mem = allocate(1); - MemoryAccess.setByte(mem, value); + MemorySegment mem = allocate(Memory.BYTE); + mem.set(Memory.BYTE, 0, value); return mem; } default MemorySegment copy(short value) { - MemorySegment mem = allocate(2, 2); - MemoryAccess.setShort(mem, value); + MemorySegment mem = allocate(Memory.SHORT); + mem.set(Memory.SHORT, 0, value); return mem; } default MemorySegment copy(int value) { - MemorySegment mem = allocate(4, 4); - MemoryAccess.setInt(mem, value); + MemorySegment mem = allocate(Memory.INT); + mem.set(Memory.INT, 0, value); return mem; } default MemorySegment copy(long value) { - MemorySegment mem = allocate(8, 8); - MemoryAccess.setLong(mem, value); + MemorySegment mem = allocate(Memory.LONG); + mem.set(Memory.LONG, 0, value); return mem; } default MemorySegment copy(float value) { - MemorySegment mem = allocate(4, 4); - MemoryAccess.setFloat(mem, value); + MemorySegment mem = allocate(Memory.FLOAT); + mem.set(Memory.FLOAT, 0, value); return mem; } default MemorySegment copy(double value) { - MemorySegment mem = allocate(8, 8); - MemoryAccess.setDouble(mem, value); + MemorySegment mem = allocate(Memory.DOUBLE); + mem.set(Memory.DOUBLE, 0, value); return mem; } @@ -137,7 +135,8 @@ public interface Frame extends AutoCloseable { default MemorySegment copy(T[] array) { MemorySegment mem = allocateAddress(array.length); for (int i = 0; i < array.length; i++) - MemoryAccess.setAddressAtIndex(mem, i, array[i].address()); + mem.setAtIndex(Memory.POINTER, i, array[i].address()); + return mem; } @@ -147,7 +146,7 @@ public interface Frame extends AutoCloseable { default MemorySegment copy(MemoryAddress value) { MemorySegment mem = allocateAddress(); - MemoryAccess.setAddress(mem, value); + mem.set(Memory.POINTER, 0, value); return mem; } @@ -155,7 +154,7 @@ public interface Frame extends AutoCloseable { default MemorySegment copy(String[] array) { MemorySegment list = allocateAddress(array.length); for (int i = 0; i < array.length; i++) { - MemoryAccess.setAddressAtIndex(list, i, copy(array[i])); + list.setAtIndex(Memory.POINTER, i, copy(array[i])); } return list; } diff --git a/src/notzed.zcl/classes/api/Memory.java b/src/notzed.zcl/classes/api/Memory.java index 4b2765d..86bf7e5 100644 --- a/src/notzed.zcl/classes/api/Memory.java +++ b/src/notzed.zcl/classes/api/Memory.java @@ -16,7 +16,18 @@ */ package api; -import jdk.incubator.foreign.*; +import java.lang.foreign.Linker; +import java.lang.foreign.MemoryAddress; +import java.lang.foreign.MemorySegment; +import java.lang.foreign.MemorySession; +import java.lang.foreign.ValueLayout; +import static java.lang.foreign.ValueLayout.ADDRESS; +import static java.lang.foreign.ValueLayout.JAVA_BYTE; +import static java.lang.foreign.ValueLayout.JAVA_DOUBLE; +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; /** @@ -34,7 +45,16 @@ import java.lang.ref.Cleaner; */ public class Memory { - static final ResourceScope scope = ResourceScope.newSharedScope(Cleaner.create()); + // probably should be INT8 INT16, etc + public static final ValueLayout.OfByte BYTE = JAVA_BYTE; + public static final ValueLayout.OfShort SHORT = JAVA_SHORT.withBitAlignment(16); + public static final ValueLayout.OfInt INT = JAVA_INT.withBitAlignment(32); + public static final ValueLayout.OfLong LONG = JAVA_LONG.withBitAlignment(64); + public static final ValueLayout.OfFloat FLOAT = JAVA_FLOAT.withBitAlignment(32); + 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()); private static final ThreadLocal stacks = ThreadLocal.withInitial(() -> new Stack(scope)); public static Frame createFrame() { @@ -47,7 +67,7 @@ public class Memory { private long sp; private Thread thread = Thread.currentThread(); - Stack(ResourceScope scope) { + Stack(MemorySession scope) { stack = MemorySegment.allocateNative(4096, 4096, scope); sp = 4096; } @@ -57,7 +77,7 @@ public class Memory { return new Frame() { private final long tos = sp; private Thread self = thread; - private ResourceScope scope; + private MemorySession scope; @Override public MemorySegment allocate(long size, long alignment) { @@ -70,19 +90,19 @@ public class Memory { return stack.asSlice(sp, size); } else { if (scope == null) - scope = ResourceScope.newConfinedScope(); + scope = MemorySession.openConfined(); return MemorySegment.allocateNative(size, alignment, scope); } } @Override public MemorySegment copy(String value) { + if (scope == null) + scope = MemorySession.openConfined(); if (value != null) { - if (scope == null) - scope = ResourceScope.newConfinedScope(); - return CLinker.toCString(value, scope); + return scope.allocateUtf8String(value); } else { - return MemorySegment.globalNativeSegment().asSlice(0, 0); + return MemorySegment.ofAddress(MemoryAddress.NULL, 0, scope); } } diff --git a/src/notzed.zcl/classes/api/Native.java b/src/notzed.zcl/classes/api/Native.java index 550aeb5..805c5e3 100644 --- a/src/notzed.zcl/classes/api/Native.java +++ b/src/notzed.zcl/classes/api/Native.java @@ -24,12 +24,19 @@ import java.util.Arrays; import java.util.List; import java.util.function.Function; import java.util.function.IntFunction; -import jdk.incubator.foreign.*; import java.lang.ref.ReferenceQueue; 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.SymbolLookup; /** * Base class for all native objects. @@ -45,7 +52,7 @@ import java.lang.System.Logger.Level; *

* FIXME: there are MemorySegment based accessors for primitive types now, use those */ -public class Native implements Addressable { +public class Native { private final MemoryAddress p; @@ -74,7 +81,7 @@ public class Native implements Addressable { /* helpers - native to java */ public static T[] toObjectV(MemorySegment list, T[] array, Function create) { for (int i = 0; i < array.length; i++) - array[i] = Native.resolve(MemoryAccess.getAddressAtIndex(list, i), create); + array[i] = Native.resolve(list.getAtIndex(Memory.POINTER, i), create); return array; } @@ -92,7 +99,7 @@ public class Native implements Addressable { public static MethodHandle downcallHandle(SymbolLookup lib, String name, String signature) { Signature sig = Signature.parse(signature); int n = sig.classes.length; - CLinker abi = CLinker.getInstance(); + Linker abi = Linker.nativeLinker(); if (sig.classes.length != sig.layouts.length) throw new RuntimeException("layout class mismatch"); @@ -100,14 +107,12 @@ public class Native implements Addressable { MemoryLayout resLayout = sig.layouts[n - 1]; if (resLayout != null) { - return lib.lookup(name).map(addr -> abi.downcallHandle(addr, - MethodType.methodType(resClass, Arrays.copyOf(sig.classes, n - 1)), - FunctionDescriptor.of(resLayout, Arrays.copyOf(sig.layouts, n - 1)))) + return lib.lookup(name).map(addr + -> abi.downcallHandle(addr, FunctionDescriptor.of(resLayout, Arrays.copyOf(sig.layouts, n - 1)))) .get(); } else { - return lib.lookup(name).map(addr -> abi.downcallHandle(addr, - MethodType.methodType(resClass, Arrays.copyOf(sig.classes, n - 1)), - FunctionDescriptor.ofVoid(Arrays.copyOf(sig.layouts, n - 1)))) + return lib.lookup(name).map(addr + -> abi.downcallHandle(addr, FunctionDescriptor.ofVoid(Arrays.copyOf(sig.layouts, n - 1)))) .get(); } } @@ -119,7 +124,7 @@ public class Native implements Addressable { public static MethodHandle downcallHandle(MemoryAddress addr, String signature) { Signature sig = Signature.parse(signature); int n = sig.classes.length; - CLinker abi = CLinker.getInstance(); + Linker abi = Linker.nativeLinker(); if (sig.classes.length != sig.layouts.length) throw new RuntimeException("layout class mismatch"); @@ -127,15 +132,14 @@ public class Native implements Addressable { MemoryLayout resLayout = sig.layouts[n - 1]; return abi.downcallHandle(addr, - MethodType.methodType(resClass, Arrays.copyOf(sig.classes, n - 1)), FunctionDescriptor.of(resLayout, Arrays.copyOf(sig.layouts, n - 1))); } // instance must be of a functional interface - public static MemoryAddress upcallStub(MethodHandles.Lookup lookup, Object instance, String signature) { + public static MemorySegment upcallStub(MethodHandles.Lookup lookup, Object instance, String signature) { Signature sig = Signature.parse(signature); int n = sig.classes.length; - CLinker abi = CLinker.getInstance(); + Linker abi = Linker.nativeLinker(); if (sig.classes.length != sig.layouts.length) throw new RuntimeException("layout class mismatch"); @@ -145,26 +149,26 @@ public class Native implements Addressable { Method m = instance.getClass().getMethods()[0]; MethodType mt = MethodType.methodType(m.getReturnType(), m.getParameterTypes()); - // FIXME: ResourceScope usage is broken here + // FIXME: MemorySession usage is broken here //System.out.printf("instance %s\n", instance); //System.out.printf("declaring class %s\n", m.getDeclaringClass()); try { if (resLayout != null) { - return abi.upcallStub(lookup.findVirtual( - m.getDeclaringClass(), - m.getName(), - mt) - .bindTo(instance), + return abi.upcallStub( + lookup.findVirtual( + m.getDeclaringClass(), + m.getName(), + mt).bindTo(instance), FunctionDescriptor.of(resLayout, Arrays.copyOf(sig.layouts, n - 1)), - ResourceScope.newSharedScope()); + MemorySession.openShared()); } else { - return abi.upcallStub(lookup.findVirtual( - m.getDeclaringClass(), - m.getName(), - mt) - .bindTo(instance), + return abi.upcallStub( + lookup.findVirtual( + m.getDeclaringClass(), + m.getName(), + mt).bindTo(instance), FunctionDescriptor.ofVoid(Arrays.copyOf(sig.layouts, n - 1)), - ResourceScope.newSharedScope()); + MemorySession.openShared()); } } catch (NoSuchMethodException | IllegalAccessException x) { throw new RuntimeException(x); @@ -266,27 +270,27 @@ public class Native implements Addressable { if (pointerDepth > 0) { argClass.add(MemoryAddress.class); - argLayout.add(CLinker.C_POINTER); + argLayout.add(Memory.POINTER); } else { switch (c) { case 'u': switch (size) { case 8: argClass.add(byte.class); - argLayout.add(CLinker.C_CHAR); + argLayout.add(Memory.BYTE); break; case 16: // char.class? argClass.add(short.class); - argLayout.add(CLinker.C_SHORT); + argLayout.add(Memory.SHORT); break; case 32: argClass.add(int.class); - argLayout.add(CLinker.C_INT); + argLayout.add(Memory.INT); break; case 64: argClass.add(long.class); - argLayout.add(CLinker.C_LONG); + argLayout.add(Memory.LONG); break; } break; @@ -294,19 +298,19 @@ public class Native implements Addressable { switch (size) { case 8: argClass.add(byte.class); - argLayout.add(CLinker.C_CHAR); + argLayout.add(Memory.BYTE); break; case 16: argClass.add(short.class); - argLayout.add(CLinker.C_SHORT); + argLayout.add(Memory.SHORT); break; case 32: argClass.add(int.class); - argLayout.add(CLinker.C_INT); + argLayout.add(Memory.INT); break; case 64: argClass.add(long.class); - argLayout.add(CLinker.C_LONG); + argLayout.add(Memory.LONG); break; } break; @@ -314,27 +318,27 @@ public class Native implements Addressable { switch (size) { case 32: argClass.add(float.class); - argLayout.add(CLinker.C_FLOAT); + argLayout.add(Memory.FLOAT); break; case 64: argClass.add(double.class); - argLayout.add(CLinker.C_DOUBLE); + argLayout.add(Memory.DOUBLE); break; } break; case 'x': switch (size) { case 8: - argLayout.add(MemoryLayouts.PAD_8); + argLayout.add(MemoryLayout.paddingLayout(8)); break; case 16: - argLayout.add(MemoryLayouts.PAD_16); + argLayout.add(MemoryLayout.paddingLayout(16)); break; case 32: - argLayout.add(MemoryLayouts.PAD_32); + argLayout.add(MemoryLayout.paddingLayout(32)); break; case 64: - argLayout.add(MemoryLayouts.PAD_64); + argLayout.add(MemoryLayout.paddingLayout(64)); break; } break; @@ -350,7 +354,7 @@ public class Native implements Addressable { //System.out.printf("void *=%d\n", pointerDepth); if (pointerDepth > 0) { argClass.add(MemoryAddress.class); - argLayout.add(CLinker.C_POINTER); + argLayout.add(Memory.POINTER); } else { // can only be return value argClass.add(void.class); @@ -378,7 +382,7 @@ public class Native implements Addressable { //System.out.printf(" type: *=%d %s\n", pointerDepth, sb); if (pointerDepth > 0) { argClass.add(MemoryAddress.class); - argLayout.add(CLinker.C_POINTER); + argLayout.add(Memory.POINTER); } else { argClass.add(MemorySegment.class); try { @@ -466,6 +470,10 @@ public class Native implements Addressable { } return o; }*/ + public static T resolve(Addressable p, Function create) { + return resolve(p.address(), create); + } + public static T resolve(MemoryAddress p, Function create) { T o; boolean step = false; @@ -549,7 +557,7 @@ public class Native implements Addressable { release(o); } - static { + static{ Thread cleanup = new Thread(Native::cleaner, "Native cleaner"); cleanup.setPriority(Thread.MAX_PRIORITY); cleanup.setDaemon(true); diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLBuffer.java b/src/notzed.zcl/classes/au/notzed/zcl/CLBuffer.java index d27aeeb..d1caa41 100644 --- a/src/notzed.zcl/classes/au/notzed/zcl/CLBuffer.java +++ b/src/notzed.zcl/classes/au/notzed/zcl/CLBuffer.java @@ -18,7 +18,7 @@ package au.notzed.zcl; import static au.notzed.zcl.CL.*; import static au.notzed.zcl.CLLib.*; -import jdk.incubator.foreign.*; +import java.lang.foreign.*; import api.*; import java.nio.ByteBuffer; @@ -72,7 +72,7 @@ public class CLBuffer extends CLMemory { int res; b = clCreateSubBuffer(address(), flags, CL_BUFFER_CREATE_TYPE_REGION, pinfo.address(), pres.address()); - if ((res = MemoryAccess.getInt(pres)) != 0) + if ((res = pres.get(Memory.INT, 0)) != 0) throw new CLRuntimeException(res); return Native.resolve(b, (c) -> new CLBuffer(c, getObjectPlatform())); diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLBufferInfo.java b/src/notzed.zcl/classes/au/notzed/zcl/CLBufferInfo.java index 4a2241b..8794abb 100644 --- a/src/notzed.zcl/classes/au/notzed/zcl/CLBufferInfo.java +++ b/src/notzed.zcl/classes/au/notzed/zcl/CLBufferInfo.java @@ -17,9 +17,8 @@ package au.notzed.zcl; import api.Frame; -import jdk.incubator.foreign.CLinker; -import jdk.incubator.foreign.MemoryAccess; -import jdk.incubator.foreign.MemorySegment; +import api.Memory; +import java.lang.foreign.MemorySegment; /** * Parameters for Buffer.createSubBuffer() @@ -40,10 +39,10 @@ public abstract class CLBufferInfo { } MemorySegment toNative(Frame frame) { - MemorySegment addr = frame.allocate(CLinker.C_LONG, 2); // FIXME: size_t + MemorySegment addr = frame.allocate(Memory.LONG, 2); // FIXME: size_t - MemoryAccess.setLong(addr, origin); - MemoryAccess.setLongAtIndex(addr, 1, size); + addr.setAtIndex(Memory.LONG, 0, origin); + addr.setAtIndex(Memory.LONG, 1, size); return addr; } diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLCommandQueue.java b/src/notzed.zcl/classes/au/notzed/zcl/CLCommandQueue.java index 592a145..c4bd9d3 100644 --- a/src/notzed.zcl/classes/au/notzed/zcl/CLCommandQueue.java +++ b/src/notzed.zcl/classes/au/notzed/zcl/CLCommandQueue.java @@ -18,7 +18,7 @@ package au.notzed.zcl; import static au.notzed.zcl.CL.*; import static au.notzed.zcl.CLLib.*; -import jdk.incubator.foreign.*; +import java.lang.foreign.*; import api.Native; import api.Memory; import api.Callback; @@ -169,7 +169,7 @@ public class CLCommandQueue extends CLObject { ByteBuffer buffer, CLEventList wait, CLEventList event) throws CLException { - MemorySegment seg = MemorySegment.ofByteBuffer(buffer); + MemorySegment seg = MemorySegment.ofBuffer(buffer); enqueueReadBuffer(mem, blocking, mem_offset, size, seg, @@ -196,7 +196,7 @@ public class CLCommandQueue extends CLObject { byte[] buffer, int buf_offset, CLEventList wait, CLEventList event) throws CLException { - try (ResourceScope scope = ResourceScope.newConfinedScope()) { + try (MemorySession scope = MemorySession.openConfined()) { MemorySegment seg = MemorySegment.allocateNative(size, scope); enqueueReadBuffer(mem, true, mem_offset, size, seg, wait, event); seg.asByteBuffer().order(ByteOrder.nativeOrder()).get(buffer, buf_offset, size); @@ -223,7 +223,7 @@ public class CLCommandQueue extends CLObject { short[] buffer, int buf_offset, CLEventList wait, CLEventList event) throws CLException { - try (ResourceScope scope = ResourceScope.newConfinedScope()) { + try (MemorySession scope = MemorySession.openConfined()) { MemorySegment seg = MemorySegment.allocateNative(size * 2, scope); enqueueReadBuffer(mem, true, mem_offset * 2, size * 2, seg, wait, event); seg.asByteBuffer().order(ByteOrder.nativeOrder()).asShortBuffer().get(buffer, buf_offset, size); @@ -235,7 +235,7 @@ public class CLCommandQueue extends CLObject { int[] buffer, int buf_offset, CLEventList wait, CLEventList event) throws CLException { - try (ResourceScope scope = ResourceScope.newConfinedScope()) { + try (MemorySession scope = MemorySession.openConfined()) { MemorySegment seg = MemorySegment.allocateNative(size * 4, scope); enqueueReadBuffer(mem, true, mem_offset * 4, size * 4, seg, wait, event); seg.asByteBuffer().order(ByteOrder.nativeOrder()).asIntBuffer().get(buffer, buf_offset, size); @@ -247,7 +247,7 @@ public class CLCommandQueue extends CLObject { long[] buffer, int buf_offset, CLEventList wait, CLEventList event) throws CLException { - try (ResourceScope scope = ResourceScope.newConfinedScope()) { + try (MemorySession scope = MemorySession.openConfined()) { MemorySegment seg = MemorySegment.allocateNative(size * 8, scope); enqueueReadBuffer(mem, true, mem_offset * 8, size * 8, seg, wait, event); seg.asByteBuffer().order(ByteOrder.nativeOrder()).asLongBuffer().get(buffer, buf_offset, size); @@ -259,7 +259,7 @@ public class CLCommandQueue extends CLObject { float[] buffer, int buf_offset, CLEventList wait, CLEventList event) throws CLException { - try (ResourceScope scope = ResourceScope.newConfinedScope()) { + try (MemorySession scope = MemorySession.openConfined()) { MemorySegment seg = MemorySegment.allocateNative(size * 4, scope); enqueueReadBuffer(mem, true, mem_offset * 4, size * 4, seg, wait, event); seg.asByteBuffer().order(ByteOrder.nativeOrder()).asFloatBuffer().get(buffer, buf_offset, size); @@ -271,7 +271,7 @@ public class CLCommandQueue extends CLObject { double[] buffer, int buf_offset, CLEventList wait, CLEventList event) throws CLException { - try (ResourceScope scope = ResourceScope.newConfinedScope()) { + try (MemorySession scope = MemorySession.openConfined()) { MemorySegment seg = MemorySegment.allocateNative(size * 8, scope); enqueueReadBuffer(mem, true, mem_offset * 8, size * 8, seg, wait, event); seg.asByteBuffer().order(ByteOrder.nativeOrder()).asDoubleBuffer().get(buffer, buf_offset, size); @@ -358,7 +358,7 @@ public class CLCommandQueue extends CLObject { ByteBuffer buffer, CLEventList waiters, CLEventList events) throws CLException, UnsupportedOperationException { - MemorySegment seg = MemorySegment.ofByteBuffer(buffer); + MemorySegment seg = MemorySegment.ofBuffer(buffer); enqueueReadBufferRect(mem, blocking, buffer_origin, host_origin, region, buffer_row_pitch, buffer_slice_pitch, host_row_pitch, host_slice_pitch, @@ -377,7 +377,7 @@ public class CLCommandQueue extends CLObject { long slice = region[1] * stride; long size = slice * region[2]; - try (ResourceScope scope = ResourceScope.newConfinedScope()) { + try (MemorySession scope = MemorySession.openConfined()) { MemorySegment seg = MemorySegment.allocateNative(size, scope); enqueueReadBufferRect(mem, blocking, buffer_origin, OFFSET_0x0x0, region, @@ -460,7 +460,7 @@ public class CLCommandQueue extends CLObject { ByteBuffer buffer, CLEventList wait, CLEventList event) throws CLException { - MemorySegment seg = MemorySegment.ofByteBuffer(buffer); + MemorySegment seg = MemorySegment.ofBuffer(buffer); enqueueWriteBuffer(mem, blocking, mem_offset, size, seg, @@ -472,7 +472,7 @@ public class CLCommandQueue extends CLObject { byte[] buffer, int buf_offset, CLEventList wait, CLEventList event) throws CLException { - try (ResourceScope scope = ResourceScope.newConfinedScope()) { + try (MemorySession scope = MemorySession.openConfined()) { MemorySegment seg = MemorySegment.allocateNative(size, scope); seg.asByteBuffer().order(ByteOrder.nativeOrder()).put(buffer, buf_offset, size); enqueueWriteBuffer(mem, true, mem_offset, size, seg, wait, event); @@ -484,7 +484,7 @@ public class CLCommandQueue extends CLObject { short[] buffer, int buf_offset, CLEventList wait, CLEventList event) throws CLException { - try (ResourceScope scope = ResourceScope.newConfinedScope()) { + try (MemorySession scope = MemorySession.openConfined()) { MemorySegment seg = MemorySegment.allocateNative(size * 2L, scope); seg.asByteBuffer().order(ByteOrder.nativeOrder()).asShortBuffer().put(buffer, buf_offset, size); enqueueWriteBuffer(mem, true, mem_offset * 2, size * 2L, seg, wait, event); @@ -496,7 +496,7 @@ public class CLCommandQueue extends CLObject { int[] buffer, int buf_offset, CLEventList wait, CLEventList event) throws CLException { - try (ResourceScope scope = ResourceScope.newConfinedScope()) { + try (MemorySession scope = MemorySession.openConfined()) { MemorySegment seg = MemorySegment.allocateNative(size * 4L, scope); seg.asByteBuffer().order(ByteOrder.nativeOrder()).asIntBuffer().put(buffer, buf_offset, size); enqueueWriteBuffer(mem, true, mem_offset * 4, size * 4L, seg, wait, event); @@ -508,7 +508,7 @@ public class CLCommandQueue extends CLObject { long[] buffer, int buf_offset, CLEventList wait, CLEventList event) throws CLException { - try (ResourceScope scope = ResourceScope.newConfinedScope()) { + try (MemorySession scope = MemorySession.openConfined()) { MemorySegment seg = MemorySegment.allocateNative(size * 8L, scope); seg.asByteBuffer().order(ByteOrder.nativeOrder()).asLongBuffer().put(buffer, buf_offset, size); enqueueWriteBuffer(mem, true, mem_offset * 8, size * 8L, seg, wait, event); @@ -520,7 +520,7 @@ public class CLCommandQueue extends CLObject { float[] buffer, int buf_offset, CLEventList wait, CLEventList event) throws CLException { - try (ResourceScope scope = ResourceScope.newConfinedScope()) { + try (MemorySession scope = MemorySession.openConfined()) { MemorySegment seg = MemorySegment.allocateNative(size * 4L, scope); seg.asByteBuffer().order(ByteOrder.nativeOrder()).asFloatBuffer().put(buffer, buf_offset, size); enqueueWriteBuffer(mem, true, mem_offset * 4, size * 4L, seg, wait, event); @@ -532,7 +532,7 @@ public class CLCommandQueue extends CLObject { double[] buffer, int buf_offset, CLEventList wait, CLEventList event) throws CLException { - try (ResourceScope scope = ResourceScope.newConfinedScope()) { + try (MemorySession scope = MemorySession.openConfined()) { MemorySegment seg = MemorySegment.allocateNative(size * 8L, scope); seg.asByteBuffer().order(ByteOrder.nativeOrder()).asDoubleBuffer().put(buffer, buf_offset, size); enqueueWriteBuffer(mem, true, mem_offset * 8, size * 8L, seg, wait, event); @@ -603,7 +603,7 @@ public class CLCommandQueue extends CLObject { long buffer_row_pitch, long buffer_slice_pitch, long host_row_pitch, long host_slice_pitch, ByteBuffer buffer, CLEventList waiters, CLEventList events) throws CLException, UnsupportedOperationException { - MemorySegment seg = MemorySegment.ofByteBuffer(buffer); + MemorySegment seg = MemorySegment.ofBuffer(buffer); enqueueWriteBufferRect(mem, blocking, buffer_origin, host_origin, region, buffer_row_pitch, buffer_slice_pitch, host_row_pitch, host_slice_pitch, @@ -697,7 +697,7 @@ public class CLCommandQueue extends CLObject { long size, CLEventList wait, CLEventList event) throws CLException { - MemorySegment seg = MemorySegment.ofByteBuffer(pattern); + MemorySegment seg = MemorySegment.ofBuffer(pattern); enqueueFillBuffer(buffer, pattern, offset, size, @@ -722,7 +722,7 @@ public class CLCommandQueue extends CLObject { long size, CLEventList wait, CLEventList event) throws CLException { - try (ResourceScope scope = ResourceScope.newConfinedScope()) { + try (MemorySession scope = MemorySession.openConfined()) { MemorySegment seg = MemorySegment.allocateNative(pattern.length, scope); seg.copyFrom(MemorySegment.ofArray(pattern)); @@ -748,7 +748,7 @@ public class CLCommandQueue extends CLObject { long size, CLEventList wait, CLEventList event) throws CLException { - try (ResourceScope scope = ResourceScope.newConfinedScope()) { + try (MemorySession scope = MemorySession.openConfined()) { MemorySegment seg = MemorySegment.allocateNative(pattern.length * 2, scope); seg.copyFrom(MemorySegment.ofArray(pattern)); @@ -774,7 +774,7 @@ public class CLCommandQueue extends CLObject { long size, CLEventList wait, CLEventList event) throws CLException { - try (ResourceScope scope = ResourceScope.newConfinedScope()) { + try (MemorySession scope = MemorySession.openConfined()) { MemorySegment seg = MemorySegment.allocateNative(pattern.length * 4, scope); seg.copyFrom(MemorySegment.ofArray(pattern)); @@ -819,7 +819,7 @@ public class CLCommandQueue extends CLObject { long size, CLEventList wait, CLEventList event) throws CLException { - try (ResourceScope scope = ResourceScope.newConfinedScope()) { + try (MemorySession scope = MemorySession.openConfined()) { MemorySegment seg = MemorySegment.allocateNative(pattern.length * 4, scope); seg.copyFrom(MemorySegment.ofArray(pattern)); @@ -845,7 +845,7 @@ public class CLCommandQueue extends CLObject { long size, CLEventList wait, CLEventList event) throws CLException { - try (ResourceScope scope = ResourceScope.newConfinedScope()) { + try (MemorySession scope = MemorySession.openConfined()) { MemorySegment seg = MemorySegment.allocateNative(pattern.length * 4, scope); seg.copyFrom(MemorySegment.ofArray(pattern)); @@ -1000,7 +1000,7 @@ public class CLCommandQueue extends CLObject { long xstride = region[0] << dshift; long xslice = xstride * region[1]; - try (ResourceScope scope = ResourceScope.newConfinedScope()) { + try (MemorySession scope = MemorySession.openConfined()) { MemorySegment seg = MemorySegment.allocateNative(alloc, scope); if (!readMode) writer.apply(seg).copy((int)region[0], (int)region[1], (int)region[2], (int)stride, (int)slice); @@ -1049,7 +1049,7 @@ public class CLCommandQueue extends CLObject { ByteBuffer buffer, CLEventList wait, CLEventList event) throws CLException { - MemorySegment seg = MemorySegment.ofByteBuffer(buffer); + MemorySegment seg = MemorySegment.ofBuffer(buffer); enqueueReadImage(image, blocking, origin, region, row_pitch, slice_pitch, @@ -1182,7 +1182,7 @@ public class CLCommandQueue extends CLObject { ByteBuffer buffer, CLEventList wait, CLEventList event) throws CLException { - MemorySegment seg = MemorySegment.ofByteBuffer(buffer); + MemorySegment seg = MemorySegment.ofBuffer(buffer); enqueueWriteImage(image, blocking, origin, region, row_pitch, slice_pitch, @@ -1363,10 +1363,10 @@ public class CLCommandQueue extends CLObject { flags, offset, size, info.nwait, info.wait, info.event, pres.address()); - if ((res = MemoryAccess.getInt(pres)) != 0) + if ((res = pres.get(Memory.INT, 0)) != 0) throw new CLException(res); - return cmap.asSegment(size, ResourceScope.globalScope()).asByteBuffer(); + return MemorySegment.ofAddress(cmap, size, MemorySession.global()).asByteBuffer(); } catch (CLException | RuntimeException | Error t) { throw t; } catch (Throwable t) { @@ -1407,11 +1407,11 @@ public class CLCommandQueue extends CLObject { cstride.address(), cslice.address(), info.nwait, info.wait, info.event, pres.address()); - if ((res = MemoryAccess.getInt(pres)) != 0) + if ((res = pres.get(Memory.INT, 0)) != 0) throw new CLException(res); - stride = MemoryAccess.getLong(cstride); - slice = MemoryAccess.getLong(cslice); + stride = cstride.get(Memory.LONG, 0); + slice = cslice.get(Memory.LONG, 0); image_row_pitch[0] = stride; if (image_slice_pitch != null) @@ -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 cmap.asSegment(size, ResourceScope.globalScope()).asByteBuffer(); + return MemorySegment.ofAddress(cmap, size, MemorySession.global()).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.ofByteBuffer(mapped).address(); + MemoryAddress cmap = MemorySegment.ofBuffer(mapped).address(); 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.globalNativeSegment(); + return MemorySegment.ofAddress(MemoryAddress.NULL, 0, MemorySession.global()); } } @@ -1568,8 +1568,8 @@ public class CLCommandQueue extends CLObject { // This means args and mem_list are the same value try (Frame frame = Memory.createFrame()) { EventInfo info = new EventInfo(frame, waiters, events); - MemorySegment memstage = frame.allocate(CLinker.C_POINTER, args.length); - MemorySegment memptrs = frame.allocate(CLinker.C_POINTER, args.length); + MemorySegment memstage = frame.allocate(Memory.POINTER, args.length); + MemorySegment memptrs = frame.allocate(Memory.POINTER, args.length); int nmem = 0; int res; @@ -1577,8 +1577,8 @@ public class CLCommandQueue extends CLObject { for (Object a: args) { if (a instanceof CLMemory) { - MemoryAccess.setAddressAtIndex(memstage, nmem, ((CLMemory)a).address()); - MemoryAccess.setAddressAtIndex(memptrs, nmem, memstage.asSlice(nmem * CLinker.C_POINTER.byteSize())); + memstage.setAtIndex(Memory.POINTER, nmem, ((CLMemory)a).address()); + memptrs.setAtIndex(Memory.POINTER, nmem, memstage.asSlice(nmem * Memory.POINTER.byteSize())); nmem++; } } @@ -1594,14 +1594,14 @@ public class CLCommandQueue extends CLObject { tmem++; } - MemorySegment seg = memargs.asSegment(tmem * CLinker.C_POINTER.byteSize(), ResourceScope.globalScope()); + MemorySegment seg = MemorySegment.ofAddress(memargs, tmem * Memory.POINTER.byteSize(), MemorySession.global()); for (int i = 0; i < args.length; i++) { if (args[i] instanceof CLMemory) { - MemoryAddress mem = MemoryAccess.getAddressAtIndex(seg, xmem); + MemoryAddress mem = seg.get(Memory.POINTER, xmem); long size = ((CLMemory)args[i]).getSize(); - save[i] = mem.asSegment(size, ResourceScope.globalScope()).asByteBuffer().order(ByteOrder.nativeOrder()); + save[i] = MemorySegment.ofAddress(mem, size, MemorySession.global()).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 * CLinker.C_POINTER.byteSize(), nmem, memstage.address(), memptrs.address(), info.nwait, info.wait, info.event); + res = clEnqueueNativeKernel(address(), call.address(), memstage.address(), nmem * Memory.POINTER.byteSize(), nmem, memstage.address(), memptrs.address(), info.nwait, info.wait, info.event); if (res != 0) throw new CLException(res); diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLContext.java b/src/notzed.zcl/classes/au/notzed/zcl/CLContext.java index a23d145..20446bd 100644 --- a/src/notzed.zcl/classes/au/notzed/zcl/CLContext.java +++ b/src/notzed.zcl/classes/au/notzed/zcl/CLContext.java @@ -18,7 +18,7 @@ package au.notzed.zcl; import static au.notzed.zcl.CL.*; import static au.notzed.zcl.CLLib.*; -import jdk.incubator.foreign.*; +import java.lang.foreign.*; import api.Memory; import api.Native; import api.Callback; @@ -122,10 +122,10 @@ public class CLContext extends CLObject { int res; for (int i = 0; i < devices.length; i++) - MemoryAccess.setAddressAtIndex(pdevs, i, devices[i].address()); + pdevs.setAtIndex(Memory.POINTER, i, devices[i].address()); cl = clCreateContext(pprops.address(), devices.length, pdevs.address(), call.address(), MemoryAddress.NULL, pres.address()); - res = MemoryAccess.getInt(pres); + res = pres.get(Memory.INT, 0); if (res != 0) throw new CLRuntimeException(res); @@ -150,8 +150,8 @@ public class CLContext extends CLObject { static CLPlatform findPlatform(MemoryAddress ccl) { try (Frame frame = Memory.createFrame()) { MemorySegment devices = getInfoAny(ccl, CL_CONTEXT_DEVICES, clGetContextInfo, frame); - MemoryAddress dev0 = MemoryAccess.getAddress(devices); - MemoryAddress plat = MemoryAccess.getAddress(getInfo(dev0, CL_DEVICE_PLATFORM, clGetDeviceInfo, frame, 8)); + MemoryAddress dev0 = devices.get(Memory.POINTER, 0); + MemoryAddress plat = getInfo(dev0, CL_DEVICE_PLATFORM, clGetDeviceInfo, frame, 8).get(Memory.POINTER, 0); return Native.resolve(plat, CLPlatform::new); } catch (RuntimeException | Error t) { @@ -180,7 +180,7 @@ public class CLContext extends CLObject { int res; cl = clCreateContextFromType(pprops.address(), device_type, call.address(), MemoryAddress.NULL, pres.address()); - res = MemoryAccess.getInt(pres); + res = pres.get(Memory.INT, 0); if (res != 0) throw new CLRuntimeException(res); @@ -210,7 +210,7 @@ public class CLContext extends CLObject { int res; q = clCreateCommandQueue(address(), dev.address(), properties, pres.address()); - res = MemoryAccess.getInt(pres); + res = pres.get(Memory.INT, 0); if (res != 0) throw new CLRuntimeException(res); @@ -243,7 +243,7 @@ public class CLContext extends CLObject { int res; q = clCreateCommandQueueWithProperties(address(), dev.address(), pprops.address(), pres.address()); - res = MemoryAccess.getInt(pres); + res = pres.get(Memory.INT, 0); if (res != 0) throw new CLRuntimeException(res); @@ -314,7 +314,7 @@ public class CLContext extends CLObject { int res; pbuffer = clCreateBuffer(address(), flags, size, addr(hostseg), pres.address()); - if ((res = MemoryAccess.getInt(pres)) != 0) + if ((res = pres.get(Memory.INT, 0)) != 0) throw new CLRuntimeException(res); if (hostseg != null && (flags & CL_MEM_USE_HOST_PTR) != 0) @@ -343,7 +343,7 @@ public class CLContext extends CLObject { */ public CLBuffer createBuffer(long flags, long size, ByteBuffer hostp) throws CLRuntimeException { if (hostp != null) { - MemorySegment hostseg = MemorySegment.ofByteBuffer(hostp); + MemorySegment hostseg = MemorySegment.ofBuffer(hostp); try { CLBuffer buffer = createBuffer(flags, size, hostseg); @@ -471,7 +471,7 @@ public class CLContext extends CLObject { } } - if ((res = MemoryAccess.getInt(cres)) != 0) + if ((res = cres.get(Memory.INT, 0)) != 0) throw new CLRuntimeException(res); if (hostseg != null && (flags & CL_MEM_USE_HOST_PTR) != 0) @@ -487,7 +487,7 @@ public class CLContext extends CLObject { public CLImage createImage(long flags, CLImageFormat fmt, CLImageDesc desc, ByteBuffer hostp) throws CLRuntimeException, UnsupportedOperationException { if (hostp != null) { - MemorySegment hostseg = MemorySegment.ofByteBuffer(hostp); + MemorySegment hostseg = MemorySegment.ofBuffer(hostp); try { CLImage image = createImage(flags, fmt, desc, hostseg); @@ -555,7 +555,7 @@ public class CLContext extends CLObject { MemoryAddress cp; cp = clCreatePipe(address(), flags, packetSize, maxPackets, pprops.address(), pres.address()); - if ((res = MemoryAccess.getInt(pres)) != 0) + if ((res = pres.get(Memory.INT, 0)) != 0) throw new CLRuntimeException(res); return resolve(cp, (x) -> new CLPipe(x, getObjectPlatform())); @@ -585,14 +585,14 @@ public class CLContext extends CLObject { if (res != 0) throw new CLRuntimeException(res); - num = MemoryAccess.getInt(cnum); + num = cnum.get(Memory.INT, 0); list = frame.allocateAddress(8); res = clGetSupportedImageFormats(address(), flags, type, num, list.address(), cnum.address()); CLImageFormat[] out = new CLImageFormat[num]; for (int i = 0; i < out.length; i++) - out[i] = CLImageFormat.fromNative(MemoryAccess.getAddressAtIndex(list, i).asSegment(CLImageFormat.layout().byteSize(), ResourceScope.globalScope())); + out[i] = CLImageFormat.fromNative(MemorySegment.ofAddress(list.getAtIndex(Memory.POINTER, i), CLImageFormat.layout().byteSize(), MemorySession.global())); return out; } catch (RuntimeException | Error t) { @@ -650,7 +650,7 @@ public class CLContext extends CLObject { MemoryAddress cs; cs = clCreateSampler(address(), norm ? 1 : 0, addr_mode, filter_mode, cres.address()); - if ((res = MemoryAccess.getInt(cres)) != 0) + if ((res = cres.get(Memory.INT, 0)) != 0) throw new CLRuntimeException(res); return resolve(cs, (x) -> new CLSampler(x, getObjectPlatform())); @@ -680,7 +680,7 @@ public class CLContext extends CLObject { MemoryAddress cs; cs = clCreateSamplerWithProperties(address(), pprops.address(), pres.address()); - if ((res = MemoryAccess.getInt(pres)) != 0) + if ((res = pres.get(Memory.INT, 0)) != 0) throw new CLRuntimeException(res); return resolve(cs, (x) -> new CLSampler(x, getObjectPlatform())); @@ -735,7 +735,7 @@ public class CLContext extends CLObject { int res; cp = clCreateProgramWithSource(address(), 1, cstring.address(), clength.address(), pres.address()); - if ((res = MemoryAccess.getInt(pres)) != 0) + if ((res = pres.get(Memory.INT, 0)) != 0) throw new CLException(res); return resolve(cp, (x) -> new CLProgram(x, getObjectPlatform())); @@ -785,7 +785,7 @@ public class CLContext extends CLObject { int res; cp = clCreateProgramWithIL(address(), buffer.address(), il.length, pres.address()); - if ((res = MemoryAccess.getInt(pres)) != 0) + if ((res = pres.get(Memory.INT, 0)) != 0) throw new CLException(res); return resolve(cp, (x) -> new CLProgram(x, getObjectPlatform())); @@ -813,7 +813,7 @@ 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.globalNativeSegment(); + MemorySegment cstatus = status != null ? frame.allocateInt(status.length) : MemorySegment.ofAddress(MemoryAddress.NULL, 0, MemorySession.global()); MemorySegment pres = frame.allocateInt(); MemoryAddress cp; int res; @@ -822,19 +822,19 @@ public class CLContext extends CLObject { MemorySegment addr = buffer.asSlice(o); addr.copyFrom(MemorySegment.ofArray(binaries[i])); - MemoryAccess.setAddressAtIndex(barray, i, addr); - MemoryAccess.setLongAtIndex(larray, i, binaries[i].length); + barray.setAtIndex(Memory.POINTER, i, addr); + larray.setAtIndex(Memory.LONG, i, binaries[i].length); o += binaries[i].length; } cp = clCreateProgramWithBinary(address(), devices.length, cdevs.address(), larray.address(), barray.address(), cstatus.address(), pres.address()); - if ((res = MemoryAccess.getInt(pres)) != 0) + if ((res = pres.get(Memory.INT, 0)) != 0) throw new CLException(res); if (status != null) { for (int i = 0; i < status.length; i++) - status[i] = MemoryAccess.getIntAtIndex(cstatus, i); + status[i] = cstatus.getAtIndex(Memory.INT, i); } return resolve(cp, (x) -> new CLProgram(x, getObjectPlatform())); @@ -866,7 +866,7 @@ public class CLContext extends CLObject { int res; cp = clCreateProgramWithBuiltInKernels(address(), devices.length, cdevs.address(), cnames.address(), pres.address()); - if ((res = MemoryAccess.getInt(pres)) != 0) + if ((res = pres.get(Memory.INT, 0)) != 0) throw new CLException(res); return resolve(cp, (x) -> new CLProgram(x, getObjectPlatform())); @@ -903,7 +903,7 @@ public class CLContext extends CLObject { int res; cp = clLinkProgram(address(), devices.length, cdevs.address(), coptions.address(), programs.length, cprogs.address(), cnotify.address(), MemoryAddress.NULL, pres.address()); - if ((res = MemoryAccess.getInt(pres)) != 0) + if ((res = pres.get(Memory.INT, 0)) != 0) throw new CLException(res); return resolve(cp, (x) -> new CLProgram(x, getObjectPlatform())); @@ -931,7 +931,7 @@ public class CLContext extends CLObject { int res; ce = clCreateUserEvent(address(), pres.address()); - if ((res = MemoryAccess.getInt(pres)) != 0) + if ((res = pres.get(Memory.INT, 0)) != 0) throw new CLException(res); return resolve(ce, (x) -> new CLEvent(x, getObjectPlatform())); @@ -1012,7 +1012,7 @@ public class CLContext extends CLObject { int res; ce = gl.clCreateFromGLBuffer(address(), flags, bufobj, cres.address()); - if ((res = MemoryAccess.getInt(cres)) != 0) + if ((res = cres.get(Memory.INT, 0)) != 0) throw new CLRuntimeException(res); return Native.resolve(ce, (b) -> new CLBuffer(b, getObjectPlatform())); } catch (RuntimeException | Error t) { @@ -1037,7 +1037,7 @@ public class CLContext extends CLObject { int res; ce = gl.clCreateFromGLTexture(address(), flags, target, miplevel, texture, pres.address()); - if ((res = MemoryAccess.getInt(pres)) != 0) + if ((res = pres.get(Memory.INT, 0)) != 0) throw new CLRuntimeException(res); return Native.resolve(ce, (x) -> new CLImage(x, getObjectPlatform())); } catch (RuntimeException | Error t) { @@ -1060,7 +1060,7 @@ public class CLContext extends CLObject { int res; ce = gl.clCreateFromGLRenderbuffer(address(), flags, renderbuffer, pres.address()); - if ((res = MemoryAccess.getInt(pres)) != 0) + if ((res = pres.get(Memory.INT, 0)) != 0) throw new CLRuntimeException(res); return Native.resolve(ce, (x) -> new CLImage(x, getObjectPlatform())); } catch (RuntimeException | Error t) { @@ -1103,7 +1103,7 @@ public class CLContext extends CLObject { int res; ce = gl.clCreateEventFromGLsyncKHR(address(), glsync, pres.address()); - if ((res = MemoryAccess.getInt(pres)) != 0) + if ((res = pres.get(Memory.INT, 0)) != 0) throw new CLRuntimeException(res); return Native.resolve(ce, CLEvent::new); diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLContextNotify.java b/src/notzed.zcl/classes/au/notzed/zcl/CLContextNotify.java index a18255d..314b34c 100644 --- a/src/notzed.zcl/classes/au/notzed/zcl/CLContextNotify.java +++ b/src/notzed.zcl/classes/au/notzed/zcl/CLContextNotify.java @@ -17,11 +17,10 @@ package au.notzed.zcl; import java.nio.ByteBuffer; -import jdk.incubator.foreign.MemorySegment; +import java.lang.foreign.MemorySegment; import api.Native; import api.Callback; -import jdk.incubator.foreign.CLinker; -import jdk.incubator.foreign.ResourceScope; +import java.lang.foreign.MemorySession; /** * Callback for CLContext.createContext*() @@ -35,8 +34,8 @@ public interface CLContextNotify { if (notify != null) { return Native.resolve( Call_pBpvJpv_v.stub((cwhat, cinfo, cinfolen, dummy) -> { - MemorySegment seg = cinfo.asSegment(cinfolen, ResourceScope.globalScope()); - notify.notify(CLinker.toJavaString(cwhat), seg.asByteBuffer()); + MemorySegment seg = MemorySegment.ofAddress(cinfo, cinfolen, MemorySession.global()); + notify.notify(cwhat.getUtf8String(0), seg.asByteBuffer()); }), (p) -> new Callback<>(p, notify)); } else { diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLDevice.java b/src/notzed.zcl/classes/au/notzed/zcl/CLDevice.java index 420c0ea..5145602 100644 --- a/src/notzed.zcl/classes/au/notzed/zcl/CLDevice.java +++ b/src/notzed.zcl/classes/au/notzed/zcl/CLDevice.java @@ -17,7 +17,7 @@ package au.notzed.zcl; import java.lang.invoke.MethodHandle; -import jdk.incubator.foreign.*; +import java.lang.foreign.*; import static au.notzed.zcl.CL.*; import static au.notzed.zcl.CLLib.*; import java.util.stream.Stream; diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLDeviceProperty.java b/src/notzed.zcl/classes/au/notzed/zcl/CLDeviceProperty.java index e3c8f32..ebfc64e 100644 --- a/src/notzed.zcl/classes/au/notzed/zcl/CLDeviceProperty.java +++ b/src/notzed.zcl/classes/au/notzed/zcl/CLDeviceProperty.java @@ -16,9 +16,8 @@ */ package au.notzed.zcl; -import api.Native; -import jdk.incubator.foreign.MemoryAccess; -import jdk.incubator.foreign.MemorySegment; +import api.Memory; +import java.lang.foreign.MemorySegment; /** * Properties for CLDevice sub-device creation. @@ -49,19 +48,19 @@ public interface CLDeviceProperty extends CLProperty { @Override public int toInt(MemorySegment dst, int o) { - MemoryAccess.setIntAtIndex(dst, o++, CL.CL_DEVICE_PARTITION_BY_COUNTS); + dst.setAtIndex(Memory.INT, o++, CL.CL_DEVICE_PARTITION_BY_COUNTS); for (int c : counts) - MemoryAccess.setIntAtIndex(dst, o++, c); - MemoryAccess.setIntAtIndex(dst, o++, CL.CL_DEVICE_PARTITION_BY_COUNTS_LIST_END); + dst.setAtIndex(Memory.INT, o++, c); + dst.setAtIndex(Memory.INT, o++, CL.CL_DEVICE_PARTITION_BY_COUNTS_LIST_END); return o; } - + @Override public int toLong(MemorySegment dst, int o) { - MemoryAccess.setLongAtIndex(dst, o++, CL.CL_DEVICE_PARTITION_BY_COUNTS); + dst.setAtIndex(Memory.LONG, o++, CL.CL_DEVICE_PARTITION_BY_COUNTS); for (int c : counts) - MemoryAccess.setLongAtIndex(dst, o++, c); - MemoryAccess.setLongAtIndex(dst, o++, CL.CL_DEVICE_PARTITION_BY_COUNTS_LIST_END); + dst.setAtIndex(Memory.LONG, o++, c); + dst.setAtIndex(Memory.LONG, o++, CL.CL_DEVICE_PARTITION_BY_COUNTS_LIST_END); return o; } } diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLEvent.java b/src/notzed.zcl/classes/au/notzed/zcl/CLEvent.java index 1351968..f6b6e0b 100644 --- a/src/notzed.zcl/classes/au/notzed/zcl/CLEvent.java +++ b/src/notzed.zcl/classes/au/notzed/zcl/CLEvent.java @@ -16,7 +16,7 @@ */ package au.notzed.zcl; -import jdk.incubator.foreign.*; +import java.lang.foreign.*; import static au.notzed.zcl.CL.*; import static au.notzed.zcl.CLLib.*; import api.*; @@ -76,7 +76,7 @@ public class CLEvent extends CLObject { */ static CLPlatform findPlatform(MemoryAddress cevent) { try (Frame frame = Memory.createFrame()) { - MemoryAddress ccl = MemoryAccess.getAddress(getInfo(cevent, CL_EVENT_CONTEXT, clGetEventInfo, frame, 8)); + MemoryAddress ccl = getInfo(cevent, CL_EVENT_CONTEXT, clGetEventInfo, frame, 8).get(Memory.POINTER, 0); return CLContext.findPlatform(ccl); } catch (RuntimeException | Error t) { diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLEventList.java b/src/notzed.zcl/classes/au/notzed/zcl/CLEventList.java index cf4eace..96f79de 100644 --- a/src/notzed.zcl/classes/au/notzed/zcl/CLEventList.java +++ b/src/notzed.zcl/classes/au/notzed/zcl/CLEventList.java @@ -16,13 +16,12 @@ */ package au.notzed.zcl; -import jdk.incubator.foreign.MemoryAddress; -import jdk.incubator.foreign.MemorySegment; +import api.Memory; +import java.lang.foreign.MemoryAddress; +import java.lang.foreign.MemorySegment; import api.Native; import static au.notzed.zcl.CLLib.*; -import jdk.incubator.foreign.CLinker; -import jdk.incubator.foreign.MemoryAccess; -import jdk.incubator.foreign.ResourceScope; +import java.lang.foreign.MemorySession; /** * Manages a list of cl_events. @@ -48,7 +47,7 @@ public final class CLEventList implements AutoCloseable { /** * Scope is required for native allocation */ - final ResourceScope scope = ResourceScope.newConfinedScope(); + final MemorySession scope = MemorySession.openConfined(); /** * Raw event values. */ @@ -70,7 +69,7 @@ public final class CLEventList implements AutoCloseable { */ public CLEventList(int capacity) { this.jevents = new CLEvent[capacity]; - this.cevents = MemorySegment.allocateNative(CLinker.C_POINTER.byteSize() * capacity, CLinker.C_POINTER.byteAlignment(), scope); + this.cevents = scope.allocateArray(Memory.POINTER, capacity); } /** @@ -84,14 +83,14 @@ public final class CLEventList implements AutoCloseable { if (ev == null) { try { - clReleaseEvent(MemoryAccess.getAddressAtIndex(cevents, i)); + clReleaseEvent(cevents.getAtIndex(Memory.POINTER, i)); } catch (Throwable t) { } } else { ev.release(); jevents[i] = null; } - MemoryAccess.setAddressAtIndex(cevents, i, MemoryAddress.NULL); + cevents.setAtIndex(Memory.POINTER, i, MemoryAddress.NULL); } index = 0; } @@ -134,7 +133,7 @@ public final class CLEventList implements AutoCloseable { MemorySegment addr = cevents.asSlice(index * 8); // This should already be null, but this performs a range check - MemoryAccess.setAddress(addr, MemoryAddress.NULL); + addr.set(Memory.POINTER, 0, MemoryAddress.NULL); return addr.address(); } else throw new ArrayIndexOutOfBoundsException(); @@ -159,7 +158,7 @@ public final class CLEventList implements AutoCloseable { if (i < index) { CLEvent ev = jevents[i]; if (ev == null) - jevents[i] = ev = Native.resolve(MemoryAccess.getAddressAtIndex(cevents, i), CLEvent::new); + jevents[i] = ev = Native.resolve(cevents.getAtIndex(Memory.POINTER, i), CLEvent::new); return ev; } else throw new ArrayIndexOutOfBoundsException(); @@ -171,7 +170,7 @@ public final class CLEventList implements AutoCloseable { * @param event */ public void add(CLEvent event) { - MemoryAccess.setAddressAtIndex(cevents, index, event.address()); + cevents.setAtIndex(Memory.POINTER, index, event.address()); jevents[index++] = event; } diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLImage.java b/src/notzed.zcl/classes/au/notzed/zcl/CLImage.java index bd12b63..c78b822 100644 --- a/src/notzed.zcl/classes/au/notzed/zcl/CLImage.java +++ b/src/notzed.zcl/classes/au/notzed/zcl/CLImage.java @@ -18,7 +18,7 @@ package au.notzed.zcl; import static au.notzed.zcl.CL.*; import static au.notzed.zcl.CLLib.*; -import jdk.incubator.foreign.*; +import java.lang.foreign.*; import java.nio.ByteBuffer; import java.lang.invoke.MethodHandle; import api.Memory; diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLImageDesc.java b/src/notzed.zcl/classes/au/notzed/zcl/CLImageDesc.java index 8024c3d..35ff275 100644 --- a/src/notzed.zcl/classes/au/notzed/zcl/CLImageDesc.java +++ b/src/notzed.zcl/classes/au/notzed/zcl/CLImageDesc.java @@ -16,9 +16,10 @@ */ package au.notzed.zcl; -import jdk.incubator.foreign.*; +import java.lang.foreign.*; import api.Native; import api.Frame; +import api.Memory; /** * Holder for cl_image_desc equivalent. @@ -89,22 +90,33 @@ public class CLImageDesc { public static MemorySegment toNative(Frame frame, CLImageDesc d) { MemorySegment addr = frame.allocate(LAYOUT); - MemoryAccess.setInt(addr, d.imageType); - MemoryAccess.setLongAtIndex(addr, 1, d.imageWidth); - MemoryAccess.setLongAtIndex(addr, 2, d.imageHeight); - MemoryAccess.setLongAtIndex(addr, 3, d.imageDepth); - MemoryAccess.setLongAtIndex(addr, 4, d.imageArraySize); - MemoryAccess.setLongAtIndex(addr, 5, d.imageRowPitch); - MemoryAccess.setLongAtIndex(addr, 6, d.imageSlicePitch); - MemoryAccess.setLongAtIndex(addr, 7, d.numMipLevels); - MemoryAccess.setLongAtIndex(addr, 8, d.numSamples); - MemoryAccess.setAddressAtIndex(addr, 9, d.memObject.address()); + addr.set(Memory.INT, 0, d.imageType); + addr.setAtIndex(Memory.LONG, 1, d.imageWidth); + addr.setAtIndex(Memory.LONG, 2, d.imageHeight); + addr.setAtIndex(Memory.LONG, 3, d.imageDepth); + addr.setAtIndex(Memory.LONG, 4, d.imageArraySize); + addr.setAtIndex(Memory.LONG, 5, d.imageRowPitch); + addr.setAtIndex(Memory.LONG, 6, d.imageSlicePitch); + addr.setAtIndex(Memory.LONG, 7, d.numMipLevels); + addr.setAtIndex(Memory.LONG, 8, d.numSamples); + addr.setAtIndex(Memory.POINTER, 9, d.memObject.address()); return addr; } - public static CLImageFormat fromNative(MemorySegment addr) { - return new CLImageFormat(MemoryAccess.getInt(addr), MemoryAccess.getIntAtIndex(addr, 1)); + public static CLImageDesc fromNative(MemorySegment addr) { + return new CLImageDesc( + addr.get(Memory.INT, 0), + addr.get(Memory.LONG, 8), + addr.get(Memory.LONG, 16), + addr.get(Memory.LONG, 24), + addr.get(Memory.LONG, 32), + addr.get(Memory.LONG, 40), + addr.get(Memory.LONG, 48), + addr.get(Memory.LONG, 56), + addr.get(Memory.LONG, 64), + null // no way to know? + ); } static final MemoryLayout LAYOUT = Native.parseStruct("[u32(image_type)x32u64(image_width)u64(image_height)u64(image_depth)u64(image_array_size)u64(image_row_pitch)u64(image_slice_pitch)u32(num_mip_levels)u32(num_samples)u64(buffer):${_cl_mem}u64(mem_object):${_cl_mem}]"); diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLImageFormat.java b/src/notzed.zcl/classes/au/notzed/zcl/CLImageFormat.java index 9911097..b6cda1c 100644 --- a/src/notzed.zcl/classes/au/notzed/zcl/CLImageFormat.java +++ b/src/notzed.zcl/classes/au/notzed/zcl/CLImageFormat.java @@ -16,9 +16,10 @@ */ package au.notzed.zcl; -import jdk.incubator.foreign.*; +import java.lang.foreign.*; import api.Native; import api.Frame; +import api.Memory; /** * Holder for cl_image_format equivalent. @@ -97,16 +98,16 @@ public class CLImageFormat { * since these are just going to be used temporarily */ static MemorySegment toNative(Frame frame, CLImageFormat fmt) { - MemorySegment addr = frame.allocate(CLinker.C_INT, 2); + MemorySegment addr = frame.allocate(Memory.INT, 2); - MemoryAccess.setInt(addr, fmt.channelOrder); - MemoryAccess.setIntAtIndex(addr, 1, fmt.channelDataType); + addr.set(Memory.INT, 0, fmt.channelOrder); + addr.set(Memory.INT, 4, fmt.channelDataType); return addr; } static CLImageFormat fromNative(MemorySegment addr) { - return new CLImageFormat(MemoryAccess.getInt(addr), MemoryAccess.getIntAtIndex(addr, 1)); + return new CLImageFormat(addr.get(Memory.INT, 0), addr.get(Memory.INT, 4)); } static final MemoryLayout LAYOUT = Native.parseStruct("[u32(image_channel_order)u32(image_channel_data_type)]"); diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLKernel.java b/src/notzed.zcl/classes/au/notzed/zcl/CLKernel.java index 2c12aaf..1a16b57 100644 --- a/src/notzed.zcl/classes/au/notzed/zcl/CLKernel.java +++ b/src/notzed.zcl/classes/au/notzed/zcl/CLKernel.java @@ -18,7 +18,7 @@ package au.notzed.zcl; import static au.notzed.zcl.CL.*; import static au.notzed.zcl.CLLib.*; -import jdk.incubator.foreign.*; +import java.lang.foreign.*; import api.Native; import api.Frame; import api.Memory; @@ -60,8 +60,8 @@ public class CLKernel extends CLObject { MemorySegment pres = frame.allocateInt(); MemoryAddress ck = clCloneKernel(address(), pres.address()); int res; - - if ((res = MemoryAccess.getInt(pres)) != 0) + + if ((res = pres.get(Memory.INT, 0)) != 0) throw new CLRuntimeException(res); return Native.resolve(ck, (x) -> new CLKernel(x, getObjectPlatform())); @@ -121,7 +121,7 @@ public class CLKernel extends CLObject { try (Frame frame = Memory.createFrame()) { MemorySegment pval = frame.copy(o); - setKernelArg(index, CLinker.C_POINTER.byteSize(), pval.address()); + setKernelArg(index, Memory.POINTER.byteSize(), pval.address()); } } @@ -151,7 +151,7 @@ public class CLKernel extends CLObject { try (Frame frame = Memory.createFrame()) { MemorySegment pval = frame.copy(val); - setKernelArg(index, CLinker.C_SHORT.byteSize(), pval.address()); + setKernelArg(index, Memory.SHORT.byteSize(), pval.address()); } } @@ -166,7 +166,7 @@ public class CLKernel extends CLObject { try (Frame frame = Memory.createFrame()) { MemorySegment pval = frame.copy(val); - setKernelArg(index, CLinker.C_INT.byteSize(), pval.address()); + setKernelArg(index, Memory.INT.byteSize(), pval.address()); } } @@ -181,7 +181,7 @@ public class CLKernel extends CLObject { try (Frame frame = Memory.createFrame()) { MemorySegment pval = frame.copy(val); - setKernelArg(index, CLinker.C_LONG.byteSize(), pval.address()); + setKernelArg(index, Memory.LONG.byteSize(), pval.address()); } } @@ -195,7 +195,7 @@ public class CLKernel extends CLObject { try (Frame frame = Memory.createFrame()) { MemorySegment pval = frame.copy(val); - setKernelArg(index, CLinker.C_FLOAT.byteSize(), pval.address()); + setKernelArg(index, Memory.FLOAT.byteSize(), pval.address()); } } @@ -209,7 +209,7 @@ public class CLKernel extends CLObject { try (Frame frame = Memory.createFrame()) { MemorySegment pval = frame.copy(val); - setKernelArg(index, CLinker.C_DOUBLE.byteSize(), pval.address()); + setKernelArg(index, Memory.DOUBLE.byteSize(), pval.address()); } } @@ -226,7 +226,7 @@ public class CLKernel extends CLObject { /** * Set a non-native memory segment argument * @param index - * @param val + * @param val */ private void setArg(int index, MemorySegment val) { try (Frame frame = Memory.createFrame()) { diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLMemory.java b/src/notzed.zcl/classes/au/notzed/zcl/CLMemory.java index 2c5d8ea..1c0c8a3 100644 --- a/src/notzed.zcl/classes/au/notzed/zcl/CLMemory.java +++ b/src/notzed.zcl/classes/au/notzed/zcl/CLMemory.java @@ -18,7 +18,7 @@ package au.notzed.zcl; import static au.notzed.zcl.CL.*; import static au.notzed.zcl.CLLib.*; -import jdk.incubator.foreign.*; +import java.lang.foreign.*; import api.Native; import api.Callback; import api.Memory; @@ -100,7 +100,7 @@ public abstract class CLMemory extends CLObject { try (Frame frame = Memory.createFrame()) { MemorySegment addr = getInfo(p, CL_MEM_TYPE, clGetMemObjectInfo, frame, 4); - int type = MemoryAccess.getInt(addr); + int type = addr.get(Memory.INT, 0); switch (type) { case CL_MEM_OBJECT_BUFFER: @@ -272,7 +272,7 @@ public abstract class CLMemory extends CLObject { res = getGLext().clGetGLObjectInfo(address(), ctype.address(), cname.address()); if (res != 0) throw new CLRuntimeException(res); - return new GLObjectInfo(MemoryAccess.getInt(ctype), MemoryAccess.getInt(cname)); + return new GLObjectInfo(ctype.get(Memory.INT, 0), cname.get(Memory.INT, 0)); } catch (RuntimeException | Error t) { throw t; } catch (Throwable t) { @@ -285,7 +285,7 @@ public abstract class CLMemory extends CLObject { */ public int getGLTextureInfoInt(int param) { try (Frame frame = Memory.createFrame()) { - return MemoryAccess.getInt(getInfo(address(), CL_GL_TEXTURE_TARGET, getGLext().clGetGLTextureInfo, frame, 4)); + return getInfo(address(), CL_GL_TEXTURE_TARGET, getGLext().clGetGLTextureInfo, frame, 4).get(Memory.INT, 0); } } diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLNotify.java b/src/notzed.zcl/classes/au/notzed/zcl/CLNotify.java index ceb6f8d..8bb3e8e 100644 --- a/src/notzed.zcl/classes/au/notzed/zcl/CLNotify.java +++ b/src/notzed.zcl/classes/au/notzed/zcl/CLNotify.java @@ -17,7 +17,7 @@ package au.notzed.zcl; import java.util.function.Function; -import jdk.incubator.foreign.MemoryAddress; +import java.lang.foreign.MemoryAddress; import api.Native; import api.Callback; diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLObject.java b/src/notzed.zcl/classes/au/notzed/zcl/CLObject.java index 0cecffe..142d91e 100644 --- a/src/notzed.zcl/classes/au/notzed/zcl/CLObject.java +++ b/src/notzed.zcl/classes/au/notzed/zcl/CLObject.java @@ -22,7 +22,7 @@ import java.lang.invoke.MethodHandle; import java.util.function.Function; import java.util.function.IntFunction; import java.util.function.BiFunction; -import jdk.incubator.foreign.*; +import java.lang.foreign.*; import api.Native; /** @@ -106,7 +106,7 @@ public abstract class CLObject extends Native { MemorySegment addr = frame.allocate(size, 8); int res; - res = (int)getInfo.invokeExact(self, id, size, addr.address(), MemoryAddress.NULL); + res = (int)getInfo.invokeExact((Addressable)self, id, size, (Addressable)addr.address(), (Addressable)MemoryAddress.NULL); if (res != 0) throw new CLRuntimeException(res); @@ -120,13 +120,13 @@ public abstract class CLObject extends Native { protected int getInfoInt(int id, MethodHandle getInfo) { try (Frame frame = Memory.createFrame()) { - return MemoryAccess.getInt(getInfo(address(), id, getInfo, frame, 4)); + return getInfo(address(), id, getInfo, frame, 4).get(Memory.INT, 0); } } protected long getInfoLong(int id, MethodHandle getInfo) { try (Frame frame = Memory.createFrame()) { - return MemoryAccess.getLong(getInfo(address(), id, getInfo, frame, 8)); + return getInfo(address(), id, getInfo, frame, 8).get(Memory.LONG, 0); } } @@ -136,7 +136,7 @@ public abstract class CLObject extends Native { protected T getInfoAny(int id, MethodHandle getInfo, Function create) { try (Frame frame = Memory.createFrame()) { - return Native.resolve(MemoryAccess.getAddress(getInfo(address(), id, getInfo, frame, 8)), create); + return Native.resolve(getInfo(address(), id, getInfo, frame, 8).get(Memory.POINTER, 0), create); } } @@ -154,12 +154,12 @@ public abstract class CLObject extends Native { long size; int res; - res = (int)getInfo.invokeExact(addr, id, 0L, MemoryAddress.NULL, sizep.address()); + res = (int)getInfo.invokeExact((Addressable)addr, id, 0L, (Addressable)MemoryAddress.NULL, (Addressable)sizep.address()); - size = MemoryAccess.getLong(sizep); + size = sizep.get(Memory.LONG, 0); valp = frame.allocate(size); - res = (int)getInfo.invokeExact(addr, id, size, valp.address(), sizep.address()); + res = (int)getInfo.invokeExact((Addressable)addr, id, size, (Addressable)valp.address(), (Addressable)sizep.address()); if (res != 0) throw new CLRuntimeException(res); @@ -174,7 +174,7 @@ public abstract class CLObject extends Native { protected byte[] getInfoByteV(int id, MethodHandle getInfo) { try (Frame frame = Memory.createFrame()) { - return getInfoAny(address(), id, getInfo, frame).toByteArray(); + return getInfoAny(address(), id, getInfo, frame).toArray(Memory.BYTE); } } @@ -213,7 +213,7 @@ public abstract class CLObject extends Native { MemorySegment addr = frame.allocate(size, 16); int res; - res = (int)getInfo.invokeExact(address(), ctx.address(), id, size, addr.address(), MemoryAddress.NULL); + res = (int)getInfo.invokeExact((Addressable)address(), (Addressable)ctx.address(), id, size, (Addressable)addr.address(), (Addressable)MemoryAddress.NULL); if (res != 0) throw new CLRuntimeException(res); @@ -227,13 +227,13 @@ public abstract class CLObject extends Native { protected int getInfoInt(T ctx, int id, MethodHandle getInfo) { try (Frame frame = Memory.createFrame()) { - return MemoryAccess.getInt(getInfo(ctx, id, getInfo, frame, 4)); + return getInfo(ctx, id, getInfo, frame, 4).get(Memory.INT, 0); } } protected long getInfoLong(T ctx, int id, MethodHandle getInfo) { try (Frame frame = Memory.createFrame()) { - return MemoryAccess.getLong(getInfo(ctx, id, getInfo, frame, 8)); + return getInfo(ctx, id, getInfo, frame, 8).get(Memory.LONG, 0); } } @@ -250,12 +250,12 @@ public abstract class CLObject extends Native { long size; int res; - res = (int)getInfo.invokeExact(address(), ctx.address(), id, 0L, MemoryAddress.NULL, sizep.address()); + res = (int)getInfo.invokeExact((Addressable)address(), (Addressable)ctx.address(), id, 0L, (Addressable)MemoryAddress.NULL, (Addressable)sizep.address()); - size = MemoryAccess.getLong(sizep); + size = sizep.get(Memory.LONG, 0); valp = frame.allocate(size, 16); - res = (int)getInfo.invokeExact(address(), ctx.address(), id, size, valp.address(), sizep.address()); + res = (int)getInfo.invokeExact((Addressable)address(), (Addressable)ctx.address(), id, size, (Addressable)valp.address(), (Addressable)sizep.address()); if (res != 0) throw new CLRuntimeException(res); @@ -271,13 +271,13 @@ public abstract class CLObject extends Native { protected byte[] getInfoByteV(T ctx, int id, MethodHandle getInfo) { try (Frame frame = Memory.createFrame()) { MemorySegment seg = getInfoAny(ctx, id, getInfo, frame); - return seg.toByteArray(); + return seg.toArray(Memory.BYTE); } } // clGet*Info includes terminating 0 static String infoToString(MemorySegment seg) { - return CLinker.toJavaString(seg); + return seg.getUtf8String(0); } protected String getInfoString(T ctx, int id, MethodHandle getInfo) { @@ -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(address(), index, id, size, addr, MemoryAddress.NULL); + int res = (int)getInfo.invokeExact((Addressable)address(), index, id, size, (Addressable)addr, (Addressable)MemoryAddress.NULL); if (res != 0) throw new IllegalArgumentException(); @@ -323,13 +323,13 @@ public abstract class CLObject extends Native { protected int getInfoInt(int index, int id, MethodHandle getInfo) { try (Frame frame = Memory.createFrame()) { - return MemoryAccess.getInt(getInfo(index, id, getInfo, frame, 4)); + return getInfo(index, id, getInfo, frame, 4).get(Memory.INT, 0); } } protected long getInfoLong(int index, int id, MethodHandle getInfo) { try (Frame frame = Memory.createFrame()) { - return MemoryAccess.getLong(getInfo(index, id, getInfo, frame, 8)); + return getInfo(index, id, getInfo, frame, 8).get(Memory.LONG, 0); } } @@ -340,12 +340,12 @@ public abstract class CLObject extends Native { long size; int res; - res = (int)getInfo.invokeExact(address(), index, id, 0L, MemoryAddress.NULL, sizep.address()); + res = (int)getInfo.invokeExact((Addressable)address(), index, id, 0L, (Addressable)MemoryAddress.NULL, (Addressable)sizep.address()); - size = MemoryAccess.getLong(sizep); + size = sizep.get(Memory.LONG, 0); valp = frame.allocate(size, 16); - res = (int)getInfo.invokeExact(address(), index, id, size, valp.address(), sizep.address()); + res = (int)getInfo.invokeExact((Addressable)address(), index, id, size, (Addressable)valp.address(), (Addressable)sizep.address()); if (res != 0) throw new CLRuntimeException(res); diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLPipe.java b/src/notzed.zcl/classes/au/notzed/zcl/CLPipe.java index 58f6f93..15f20a0 100644 --- a/src/notzed.zcl/classes/au/notzed/zcl/CLPipe.java +++ b/src/notzed.zcl/classes/au/notzed/zcl/CLPipe.java @@ -18,7 +18,7 @@ package au.notzed.zcl; import static au.notzed.zcl.CL.*; import static au.notzed.zcl.CLLib.*; -import jdk.incubator.foreign.*; +import java.lang.foreign.*; import java.lang.invoke.MethodHandle; /** diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLPlatform.java b/src/notzed.zcl/classes/au/notzed/zcl/CLPlatform.java index 078ee08..601f531 100644 --- a/src/notzed.zcl/classes/au/notzed/zcl/CLPlatform.java +++ b/src/notzed.zcl/classes/au/notzed/zcl/CLPlatform.java @@ -22,7 +22,7 @@ import static au.notzed.zcl.CL.*; import static au.notzed.zcl.CLLib.*; import java.util.function.ToDoubleFunction; import java.util.function.Function; -import jdk.incubator.foreign.*; +import java.lang.foreign.*; import java.lang.invoke.*; /** @@ -95,14 +95,14 @@ public class CLPlatform extends CLObject { int len; int res; - res = (int)clGetPlatformIDs.invokeExact(0, MemoryAddress.NULL, lenp.address()); + res = (int)clGetPlatformIDs.invokeExact(0, (Addressable)MemoryAddress.NULL, (Addressable)lenp.address()); if (res != 0) throw new CLRuntimeException(res); - len = MemoryAccess.getInt(lenp); - list = frame.allocate(MemoryLayout.sequenceLayout(len, CLinker.C_POINTER)); + len = lenp.get(Memory.INT, 0); + list = frame.allocate(MemoryLayout.sequenceLayout(len, Memory.POINTER)); - res = (int)clGetPlatformIDs.invokeExact(len, list.address(), lenp.address()); + res = (int)clGetPlatformIDs.invokeExact(len, (Addressable)list.address(), (Addressable)lenp.address()); if (res != 0) throw new CLRuntimeException(res); @@ -129,17 +129,17 @@ public class CLPlatform extends CLObject { MemorySegment list; int res, len; - res = (int)clGetDeviceIDs.invokeExact(address(), type, 0, MemoryAddress.NULL, lenp.address()); + res = (int)clGetDeviceIDs.invokeExact((Addressable)address(), type, 0, (Addressable)MemoryAddress.NULL, (Addressable)lenp.address()); if (res == CL_DEVICE_NOT_FOUND) return new CLDevice[0]; else if (res != 0) throw new CLRuntimeException(res); - len = MemoryAccess.getInt(lenp); - list = frame.allocate(MemoryLayout.sequenceLayout(len, CLinker.C_POINTER)); + len = lenp.get(Memory.INT, 0); + list = frame.allocate(MemoryLayout.sequenceLayout(len, Memory.POINTER)); - res = (int)clGetDeviceIDs.invokeExact(address(), type, len, list.address(), lenp.address()); + res = (int)clGetDeviceIDs.invokeExact((Addressable)address(), type, len, (Addressable)list.address(), (Addressable)lenp.address()); if (res != 0) throw new CLRuntimeException(res); diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLProgram.java b/src/notzed.zcl/classes/au/notzed/zcl/CLProgram.java index bafe559..5f06a34 100644 --- a/src/notzed.zcl/classes/au/notzed/zcl/CLProgram.java +++ b/src/notzed.zcl/classes/au/notzed/zcl/CLProgram.java @@ -18,7 +18,7 @@ package au.notzed.zcl; import static au.notzed.zcl.CL.*; import static au.notzed.zcl.CLLib.*; -import jdk.incubator.foreign.*; +import java.lang.foreign.*; import api.Native; import api.Memory; import api.Callback; @@ -152,7 +152,7 @@ public class CLProgram extends CLObject { MemoryAddress ck; ck = clCreateKernel(address(), pname.address(), pres.address()); - if ((res = MemoryAccess.getInt(pres)) != 0) + if ((res = pres.get(Memory.INT, 0)) != 0) throw new CLException(res); return resolve(ck, (x) -> new CLKernel(x, getObjectPlatform())); } catch (CLException | RuntimeException | Error t) { @@ -180,7 +180,7 @@ public class CLProgram extends CLObject { if (res != 0) throw new CLRuntimeException(); - count = MemoryAccess.getInt(csize); + count = csize.get(Memory.INT, 0); return Native.toObjectV(ckern, new CLKernel[count], (x) -> new CLKernel(x, getObjectPlatform())); } catch (RuntimeException | Error t) { throw t; @@ -220,10 +220,10 @@ public class CLProgram extends CLObject { int res; for (int i = 0; i < sizes.length; i++) { - MemoryAccess.setAddressAtIndex(cptrs, i, data.addOffset(off)); + cptrs.setAtIndex(Memory.POINTER, i, data.addOffset(off)); off += sizes[i]; } - res = clGetProgramInfo(address(), CL_PROGRAM_BINARIES, sizes.length * CLinker.C_POINTER.byteSize(), cptrs.address(), MemoryAddress.NULL); + res = clGetProgramInfo(address(), CL_PROGRAM_BINARIES, sizes.length * Memory.POINTER.byteSize(), cptrs.address(), MemoryAddress.NULL); if (res != 0) throw new CLRuntimeException(res); @@ -231,7 +231,7 @@ public class CLProgram extends CLObject { byte[][] out = new byte[sizes.length][]; off = 0; for (int i = 0; i < sizes.length; i++) { - out[i] = seg.asSlice(off, sizes[i]).toByteArray(); + out[i] = seg.asSlice(off, sizes[i]).toArray(Memory.BYTE); off += sizes[i]; } diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLProperty.java b/src/notzed.zcl/classes/au/notzed/zcl/CLProperty.java index 71ffbd1..675ce65 100644 --- a/src/notzed.zcl/classes/au/notzed/zcl/CLProperty.java +++ b/src/notzed.zcl/classes/au/notzed/zcl/CLProperty.java @@ -18,13 +18,13 @@ package au.notzed.zcl; import api.Frame; +import api.Memory; import static au.notzed.zcl.CL.*; -import jdk.incubator.foreign.MemorySegment; +import java.lang.foreign.MemorySegment; import java.util.function.BiFunction; import java.util.function.IntFunction; import java.util.ArrayList; -import jdk.incubator.foreign.MemoryAccess; /** * All property arrays implement this interface. @@ -71,15 +71,15 @@ public interface CLProperty { @Override public int toInt(MemorySegment dst, int o) { - MemoryAccess.setIntAtIndex(dst, o++, (int)tag); - MemoryAccess.setIntAtIndex(dst, o++, (int)value); + dst.setAtIndex(Memory.INT, o++, (int)tag); + dst.setAtIndex(Memory.INT, o++, (int)value); return o; } @Override public int toLong(MemorySegment dst, int o) { - MemoryAccess.setLongAtIndex(dst, o++, tag); - MemoryAccess.setLongAtIndex(dst, o++, value); + dst.setAtIndex(Memory.LONG, o++, tag); + dst.setAtIndex(Memory.LONG, o++, value); return o; } @@ -111,11 +111,11 @@ public interface CLProperty { for (CLProperty p: properties) i = p.toLong(addr, i); - MemoryAccess.setLongAtIndex(addr, i, 0L); + addr.setAtIndex(Memory.LONG, i, 0L); return addr; } else { MemorySegment addr = frame.allocateLong(); - MemoryAccess.setLong(addr, 0L); + addr.set(Memory.LONG, 0, 0L); return addr; } } @@ -124,12 +124,12 @@ public interface CLProperty { ArrayList list = new ArrayList<>(); long tag; - for (int i = 0;(tag = MemoryAccess.getLongAtIndex(seg, i++)) != 0;) { + for (int i = 0;(tag = seg.getAtIndex(Memory.LONG, i++)) != 0;) { // HACK: this needs some other mechanism, just hardcode each for now if (tag == CL_DEVICE_PARTITION_BY_COUNTS) { throw new UnsupportedOperationException(); } else { - long value = MemoryAccess.getLongAtIndex(seg, i++); + long value = seg.getAtIndex(Memory.LONG, i++); list.add(create.apply(tag, value)); } diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLSampler.java b/src/notzed.zcl/classes/au/notzed/zcl/CLSampler.java index 7bb6a2c..d400fe0 100644 --- a/src/notzed.zcl/classes/au/notzed/zcl/CLSampler.java +++ b/src/notzed.zcl/classes/au/notzed/zcl/CLSampler.java @@ -18,7 +18,7 @@ package au.notzed.zcl; import static au.notzed.zcl.CL.*; import static au.notzed.zcl.CLLib.*; -import jdk.incubator.foreign.*; +import java.lang.foreign.*; import java.lang.invoke.MethodHandle; /** diff --git a/src/notzed.zcl/classes/au/notzed/zcl/EventInfo.java b/src/notzed.zcl/classes/au/notzed/zcl/EventInfo.java index e117294..6a958ad 100644 --- a/src/notzed.zcl/classes/au/notzed/zcl/EventInfo.java +++ b/src/notzed.zcl/classes/au/notzed/zcl/EventInfo.java @@ -18,7 +18,7 @@ package au.notzed.zcl; import api.Frame; -import jdk.incubator.foreign.*; +import java.lang.foreign.*; /** * Simplify wait/event handling. diff --git a/src/notzed.zcl/classes/module-info.java b/src/notzed.zcl/classes/module-info.java index 6483e0b..8ef9c4c 100644 --- a/src/notzed.zcl/classes/module-info.java +++ b/src/notzed.zcl/classes/module-info.java @@ -21,8 +21,6 @@ * Implements a java-friendly binding to OpenCL. */ module notzed.zcl { - requires jdk.incubator.foreign; - exports au.notzed.zcl; exports api to notzed.zcl.demo; diff --git a/src/notzed.zcl/gen/generate-api b/src/notzed.zcl/gen/generate-api index aaf6954..812a832 100755 --- a/src/notzed.zcl/gen/generate-api +++ b/src/notzed.zcl/gen/generate-api @@ -669,7 +669,7 @@ if ($enclosingType) { print $dst <