Advertisement
Guest User

Untitled

a guest
Mar 9th, 2020
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. package org.goliath.bindings.nvml.functions;
  2.  
  3. import java.lang.invoke.MethodHandle;
  4. import java.lang.invoke.MethodType;
  5. import jdk.incubator.foreign.FunctionDescriptor;
  6. import jdk.incubator.foreign.MemoryAddress;
  7. import jdk.incubator.foreign.MemoryLayouts;
  8. import jdk.incubator.foreign.SystemABI;
  9. import org.goliath.bindings.nvml.main.nvml_h;
  10. import org.goliath.crosspoint.interfaces.NativeFunction;
  11.  
  12. public record nvmlInit(MemoryAddress address, FunctionDescriptor descriptor, MethodType type, MethodHandle handle) implements NativeFunction
  13. {
  14. public static nvmlInit create() throws NoSuchMethodException
  15. {
  16. MemoryAddress address = nvml_h.LIBRARY_LOOKUP.lookup("nvmlInit");
  17.  
  18. FunctionDescriptor descriptor = FunctionDescriptor.of(MemoryLayouts.C_INT);
  19.  
  20. MethodType type = MethodType.methodType(int.class);
  21.  
  22. MethodHandle handle = SystemABI.getInstance().downcallHandle(address, type, descriptor);
  23.  
  24. return new nvmlInit(address, descriptor, type, handle);
  25. }
  26.  
  27. public nvmlInit(MemoryAddress address, FunctionDescriptor descriptor, MethodType type, MethodHandle handle)
  28. {
  29. this.address = address;
  30.  
  31. this.descriptor = descriptor;
  32.  
  33. this.type = type;
  34.  
  35. this.handle = handle;
  36. }
  37.  
  38. @Override
  39. public Object call(Object... args) throws Throwable
  40. {
  41. return this.handle.invoke();
  42. }
  43.  
  44. @Override
  45. public MemoryAddress getAddress()
  46. {
  47. return this.address;
  48. }
  49.  
  50. @Override
  51. public FunctionDescriptor getDescriptor()
  52. {
  53. return this.descriptor;
  54. }
  55.  
  56. @Override
  57. public MethodType getMethodType()
  58. {
  59. return this.type;
  60. }
  61.  
  62. @Override
  63. public MethodHandle getMethodHandle()
  64. {
  65. return this.handle;
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement