Basic questions about Panama
Henry Jen
henry.jen at oracle.com
Thu Mar 15 01:39:01 UTC 2018
On Mar 14, 2018, at 3:13 PM, Virendra J. Marathe <virendra.marathe at oracle.com> wrote:
>
>
> Hi Henry,
>
> Thanks for pointing to the right directory. I looked at the simple.h and recursive.h
> examples, and their respective .java files. I have questions.
>
> * First I don't understand how the pieces fit together. i.e. jextract uses a .h file to
> create a jar/class file; so what is the .java in those examples for? Is it something
> the programmer has to write up to mimic the interfaces present in the class files?
Those demo in jdk/nicl is not using jextract, but they put annotation on .java file directory to test the runtime binding process. We are trying to standardize the annotations and API, you can see recent discussion led by Maurizio.
> * The annotations seem quite heavy and superfluous. Can a Java programmer omit
> some of them?
Yup, some of those are information only, and ideally we only want to have native type descriptor. If you work with jextract, you don’t need to worry about those.
> * I also don't understand the role of each argument in these annotations -- e.g. USR,
> do we need to write down the line and column numbers? what is layout? what is @Offset,
> and why are all of them a multiple of 8?
> * What would the Java code that uses these interfaces look like? If the programmer wants
> to allocate an off-heap object and cast it into an interface, what would the native as well as
> Java side of that interaction look like?
The jdk.internal.clang code on this webrev[1] is typically user code to directly use generated native API.
The APIs to deal with native calls is mainly in jdk.nicl package, there is a concept of Scope which manages lifecycle and provide facility to allocate native memory.
Again, there is an effort going on to consolidate APIs in current prototype.
> * Lastly, can I talk to someone for clarifications to these basic doubts? A higher
> bandwidth call may be much more useful than email swaps.
>
If you have a header file and simply want to use those native APIs, I recommend using jextract. The webrev I pointed you to for jextract/libclang would show how you run jextract and what code using those extract interface looks like.
I’ll have an update webrev for the jextract test later today or tomorrow.
Cheers,
Henry
[1] http://cr.openjdk.java.net/~henryjen/panama/clang-ffi/0/webrev/
More information about the panama-dev
mailing list