Questions tagged [project-panama]

Project panama is the OpenJDK project that aims to create a new way to do native interop from Java.

Project panama is the OpenJDK project that aims to create a new way to do native interop from Java, without the need to manually write glue-code libraries (like needed with JNI), and aims at providing better performance characteristics when compared to JNI.

47 questions
2
votes
1 answer

Jextract YARA headers throws unknown type name 'intmax_t'

I want to generate Java bindings for the /usr/include/yara.h header file using the https://github.com/openjdk/jextract tool. From readme: Jextract jextract is a tool which mechanically generates Java bindings from a native library headers. This…
1Z10
  • 2,801
  • 7
  • 33
  • 82
2
votes
1 answer

Java VarHandle to a C string with java.lang.foreign API

I would like to use foreign function interface from project panama to access C library from Java19. The C interface is quite simple: typedef struct { int len; char name[100]; } ent; ent* foo(); When called, function foo returns pointer to…
kofemann
  • 4,217
  • 1
  • 34
  • 39
2
votes
2 answers

Java: Foreign Memory "VarHandleSegmentViewBase" error, Misaligned Access at Address

I'm trying to understand how to read/write binary encoded versions of a simple struct, like below: typedef struct Tuple { uint32_t length; uint8_t* data; } Tuple; I have the following code, which can correctly write a Tuple record in Java…
Gavin Ray
  • 595
  • 1
  • 3
  • 10
2
votes
1 answer

JDK-18 foreign functions: How to work with multiple functions that have the same name, but come from different native libraries?

Let's say I loaded a native library gg3 that has a function get_gg(), and would like to load another native library gg4 that also has a get_gg() function - how can I look one up in a "library aware" manner (for example, use the get_gg() from gg4 on…
unlimitednzt
  • 1,035
  • 2
  • 16
  • 25
2
votes
0 answers

Panama: Padding doesn't prevent false sharing

I am trying to benchmark the effects false sharing has on the performance of a program. In this example: https://github.com/lexburner/JMH-samples/blob/master/src/main/java/org/openjdk/jmh/samples/JMHSample_22_FalseSharing.java , cache line padding…
sqlearner
  • 97
  • 5
2
votes
1 answer

"cstdarg file not found" when running jextract on the C binding for a Rust project

I'm trying to get a simple integer addition function written in Rust working with Java's Project Panama. Having generated the bindings using cbindgen crate, I get the following error when running jextract: jextract -t org.adder -L . -l adder-java…
junglie85
  • 1,243
  • 10
  • 30
2
votes
0 answers

How can I convert IntBuffer to ByteBuffer without copying the data

My Scala/Java code has a large (several hundred megabytes) integer arrays. I would send these as fast as possible (without copying the contents) from this int[] using java.nio. Also, when I receive any data on my nio socket channels, I would use the…
Tamas Foldi
  • 487
  • 4
  • 8
1
vote
1 answer

Is there an efficent way to share java Image/Raster pixel memory between Java and native code using Panama or JNI or (?)

I have a C++ library that does image processing on rectangular arrays of pixels. I want to pass the output C++ pixels to java so they can most effciently be "drawn" into a java.awt.Graphics2 instance for a canvas as an Image/Raster/(?) object( yeah…
peterk
  • 5,136
  • 6
  • 33
  • 47
1
vote
2 answers

How do I get the HWND of a Canvas using Panama?

I'm porting a program that uses JNI to use Panama instead. This program uses OpenGL to draw onto a Canvas object. I can port the Windows and OpenGL calls to use Panama, but the problem is I need to get the HWND of the Canvas I want to draw to. The C…
James
  • 13
  • 3
1
vote
1 answer

Setting Up VkRenderPassBeginInfo.pClearValues Pointer Array with Project Panama (JEP 434)

I am trying to create a pointer to an array of of two (2) VkClearValues using Java's Project Panama (JEP 434, JDK 20). One clear value is for the color attachment, one is for the depth buffer. My attempt at that is the following: var pClearValue =…
brcolow
  • 1,042
  • 2
  • 11
  • 33
1
vote
2 answers

Equivalent of MemorySegment.getUtf8String for UTF-16

I'm porting my JNA-based library to "pure" Java using the Foreign Function and Memory API ([JEP 424][1]) in JDK 19. One frequent use case my library handles is reading (null-terminated) Strings from native memory. For most *nix applications, these…
Daniel Widdis
  • 8,424
  • 13
  • 41
  • 63
1
vote
1 answer

SIMD transposition of 8x8 matrix of 32-bit values in Java

I found the following code in C++ for fast transposition of an 8x8 matrix of 32-bit values: https://stackoverflow.com/a/51887176/1915854 inline void Transpose8x8Shuff(unsigned long *in) { __m256 *inI = reinterpret_cast<__m256 *>(in); …
Serge Rogatch
  • 13,865
  • 7
  • 86
  • 158
1
vote
2 answers

Obtain the native value of errno from Java in macOS

I'm porting my JNA-based library to "pure" Java using the Foreign Function and Memory API (JEP 424) in JDK 19. I've successfully implemented the sysctl() function and am fetching values using: public static MethodHandle sysctl =…
Daniel Widdis
  • 8,424
  • 13
  • 41
  • 63
1
vote
1 answer

call a native function pointer from java?

Is it possible to call a function pointer from Java? To call a C function from Java I can just use the down call method from the CLinker, but that works only for functions and not for function pointers, since it needs a NativeSymbol for the…
1
vote
1 answer

Not founding libraries in project panama on macOs

I am trying to run cpp code via Java using the Project Panama and I got an error because my library is not loading. cpp code: // MyRectangle.cpp #include #include class Rectangle { int width, height; public: …
Matrix12
  • 446
  • 8
  • 19