From: Not Zed Date: Thu, 30 Apr 2020 05:17:33 +0000 (+0930) Subject: Track panama-foreign changes as of 30.4.20. X-Git-Url: https://code.zedzone.au/cvs?a=commitdiff_plain;h=66439ae913f67ce15ec8abf61ca35aafd35c9ca7;p=zcl Track panama-foreign changes as of 30.4.20. --- diff --git a/Makefile b/Makefile index f21e8aa..eeca8da 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,8 @@ notzed.zcl.demo_DEMOS=au.notzed.zcl.tools.clinfo \ notzed.zcl.fxdemo_DEMOS=fxdemo.fract.Mandelbrot fxdemo.fract.Test -DEMOFLAGS=--add-exports jdk.incubator.foreign/jdk.incubator.foreign.unsafe=notzed.zcl +DEMOFLAGS=--add-exports jdk.incubator.foreign/jdk.incubator.foreign.unsafe=notzed.zcl \ + -Dforeign.restricted=permit # module class basename(class) define java_demo= 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 new file mode 100644 index 0000000..a91758d --- /dev/null +++ b/src/notzed.zcl.demo/classes/au/notzed/zcl/test/TestExtensions.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2020 Michael Zucchi + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +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 jdk.incubator.foreign.MemoryAddress; +import jdk.incubator.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); + //GLEvent gle = plat.getExtension(CLPlatform.cl_khr_gl_event, (p) -> new GLEvent(p)); + //gle.clCreateEventFromGLsync(cl, MemoryAddress.NULL); + } +} diff --git a/src/notzed.zcl/classes/api/Memory.java b/src/notzed.zcl/classes/api/Memory.java index a1d008e..63cd351 100644 --- a/src/notzed.zcl/classes/api/Memory.java +++ b/src/notzed.zcl/classes/api/Memory.java @@ -18,7 +18,6 @@ package api; import jdk.incubator.foreign.*; -import jdk.incubator.foreign.unsafe.ForeignUnsafe; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodType; @@ -92,7 +91,8 @@ public class Memory { Stack(MemoryAddress p, long size) { super(p); - stack = ForeignUnsafe.ofNativeUnchecked(addr(), size); + // TODO: use cleanup stuff, perhaps owner thread + stack = MemorySegment.ofNativeRestricted(addr(), size, null, null, null); base = stack.baseAddress(); sp = size; @@ -168,7 +168,7 @@ public class Memory { static { // So for whatever reason it's been decided that MemorySegment can't be freed normally on another thread - SystemABI abi = SystemABI.getInstance(); + SystemABI abi = SystemABI.getSystemABI(); MethodHandles.Lookup lookup = MethodHandles.lookup(); LibraryLookup libc = LibraryLookup.ofDefault(); @@ -177,13 +177,11 @@ public class Memory { MethodType.methodType(MemoryAddress.class, long.class), FunctionDescriptor.of(MemoryLayouts.SysV.C_POINTER, - false, MemoryLayouts.SysV.C_ULONG)); free = abi.downcallHandle(libc.lookup("free"), MethodType.methodType(void.class, MemoryAddress.class), - FunctionDescriptor.ofVoid(false, - MemoryLayouts.SysV.C_POINTER)); + FunctionDescriptor.ofVoid(MemoryLayouts.SysV.C_POINTER)); } catch (NoSuchMethodException x) { throw new RuntimeException(x); } @@ -194,14 +192,14 @@ public class Memory { * Closing this segment has no effect on the original, and the original must be used for that. */ public static MemorySegment ofNative(MemoryAddress addr, long size) { - return ForeignUnsafe.ofNativeUnchecked(addr, size); + return MemorySegment.ofNativeRestricted(addr, size, null, null, null); } /** * Get the physical address. I mean how is this an "offset"? */ public static long toLong(MemoryAddress addr) { - return ForeignUnsafe.getUnsafeOffset(addr); + return addr.toRawLongValue(); } /** diff --git a/src/notzed.zcl/classes/api/Native.java b/src/notzed.zcl/classes/api/Native.java index a2d2b0e..f2f3d39 100644 --- a/src/notzed.zcl/classes/api/Native.java +++ b/src/notzed.zcl/classes/api/Native.java @@ -27,7 +27,6 @@ import java.util.List; import java.util.function.Function; import java.util.function.IntFunction; import jdk.incubator.foreign.*; -import jdk.incubator.foreign.unsafe.ForeignUnsafe; import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; import java.lang.reflect.Constructor; @@ -59,7 +58,7 @@ public class Native { final static VarHandle longHandle = MemoryHandles.varHandle(long.class, ByteOrder.nativeOrder()); final static VarHandle floatHandle = MemoryHandles.varHandle(float.class, ByteOrder.nativeOrder()); final static VarHandle doubleHandle = MemoryHandles.varHandle(double.class, ByteOrder.nativeOrder()); - final static VarHandle addrHandle = MemoryHandles.varHandle(MemoryAddress.class, ByteOrder.nativeOrder()); + final static VarHandle addrHandle = MemoryHandles.asAddressVarHandle(MemoryHandles.varHandle(long.class, ByteOrder.nativeOrder())); final static VarHandle byteVHandle = MemoryHandles.withStride(byteHandle, 1); final static VarHandle shortVHandle = MemoryHandles.withStride(shortHandle, 2); @@ -273,7 +272,7 @@ public class Native { } public static String toString(MemoryAddress cstr) { - MemorySegment seg = ForeignUnsafe.ofNativeUnchecked(cstr, Integer.MAX_VALUE); + MemorySegment seg = MemorySegment.ofNativeRestricted(cstr, Integer.MAX_VALUE, null, null, null); MemoryAddress add = seg.baseAddress(); byte[] data; int len = 0; @@ -304,7 +303,7 @@ public class Native { public static MethodHandle downcallHandle(LibraryLookup[] libs, String name, String signature) { Signature sig = Signature.parse(signature); int n = sig.classes.length; - SystemABI abi = SystemABI.getInstance(); + SystemABI abi = SystemABI.getSystemABI(); if (sig.classes.length != sig.layouts.length) throw new RuntimeException("layout class mismatch"); @@ -315,7 +314,7 @@ public class Native { try { return abi.downcallHandle(lib.lookup(name), MethodType.methodType(resClass, Arrays.copyOf(sig.classes, n-1)), - FunctionDescriptor.of(resLayout, false, Arrays.copyOf(sig.layouts, n-1))); + FunctionDescriptor.of(resLayout, Arrays.copyOf(sig.layouts, n-1))); } catch (NoSuchMethodException x) { } } @@ -332,7 +331,7 @@ public class Native { public static MethodHandle downcallHandle(MemoryAddress addr, String signature) { Signature sig = Signature.parse(signature); int n = sig.classes.length; - SystemABI abi = SystemABI.getInstance(); + SystemABI abi = SystemABI.getSystemABI(); if (sig.classes.length != sig.layouts.length) throw new RuntimeException("layout class mismatch"); @@ -341,14 +340,14 @@ public class Native { return abi.downcallHandle(addr, MethodType.methodType(resClass, Arrays.copyOf(sig.classes, n-1)), - FunctionDescriptor.of(resLayout, false, Arrays.copyOf(sig.layouts, 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) { Signature sig = Signature.parse(signature); int n = sig.classes.length; - SystemABI abi = SystemABI.getInstance(); + SystemABI abi = SystemABI.getSystemABI(); if (sig.classes.length != sig.layouts.length) throw new RuntimeException("layout class mismatch"); @@ -368,14 +367,14 @@ public class Native { m.getName(), mt) .bindTo(instance), - FunctionDescriptor.of(resLayout, false, Arrays.copyOf(sig.layouts, n-1))); + FunctionDescriptor.of(resLayout, Arrays.copyOf(sig.layouts, n-1))); } catch (NoSuchMethodException | IllegalAccessException x) { throw new RuntimeException(x); } } public static void freeUpcallStub(MemoryAddress addr) { - SystemABI.getInstance().freeUpcallStub(addr); + SystemABI.getSystemABI().freeUpcallStub(addr); } public static LibraryLookup[] loadLibraries(String... libraries) { diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLContext.java b/src/notzed.zcl/classes/au/notzed/zcl/CLContext.java index 2913512..116f46b 100644 --- a/src/notzed.zcl/classes/au/notzed/zcl/CLContext.java +++ b/src/notzed.zcl/classes/au/notzed/zcl/CLContext.java @@ -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.addr().offset()); + return new CLContextProperty.TagValue(CL.CL_CONTEXT_PLATFORM, Memory.toLong(platform.addr())); } /** diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLImage.java b/src/notzed.zcl/classes/au/notzed/zcl/CLImage.java index d9ff52d..6fcf662 100644 --- a/src/notzed.zcl/classes/au/notzed/zcl/CLImage.java +++ b/src/notzed.zcl/classes/au/notzed/zcl/CLImage.java @@ -21,6 +21,7 @@ import static au.notzed.zcl.CLLib.*; import jdk.incubator.foreign.*; import java.nio.ByteBuffer; import java.lang.invoke.MethodHandle; +import api.Memory; /** * Interface for cl_image. @@ -92,7 +93,7 @@ public class CLImage extends CLMemory { @Override public String toString() { - return String.format("[%s: %dx%dx%d 0x%x]", getClass().getSimpleName(), getWidth(), getHeight(), getDepth(), addr().offset()); + return String.format("[%s: %dx%dx%d 0x%x]", getClass().getSimpleName(), getWidth(), getHeight(), getDepth(), Memory.toLong(addr())); } /** diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLMemory.java b/src/notzed.zcl/classes/au/notzed/zcl/CLMemory.java index a4ddbdc..cff5f69 100644 --- a/src/notzed.zcl/classes/au/notzed/zcl/CLMemory.java +++ b/src/notzed.zcl/classes/au/notzed/zcl/CLMemory.java @@ -94,7 +94,7 @@ public abstract class CLMemory extends CLObject { */ @Deprecated private static CLMemory create(MemoryAddress p, CLPlatform plat) { - if (p.offset() == 0) + if (Memory.toLong(p) == 0) return null;