[foreign] programmatic access to native libraries w/o binder

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Sat Dec 1 21:39:35 UTC 2018


On 01/12/2018 10:39, Samuel Audet wrote:
> Hi, Maurizio,
>
> Could you elaborate on the use cases where using something like the 
> SystemABI interface without the binder or annotated classes would be 
> desirable? In particular, I'm interested to know under which 
> circumstances an *end user* might be interested by those details. 
> Specifically, JShell supports annotations just fine, so that's not a 
> good reason. The following works with JavaCPP, and I'm sure we can do 
> something similar with your binder:

Sure - the use case I was envisioning is not for end users; of course 
users will want higher level frameworks. But those frameworks have to be 
built on something, and I think the proposed SystemABI interface seems 
to  have the right set of primitives upon which to build.

When I was preparing some demo for the talks I gave few weeks ago I also 
played with jextract and annotated interfaces and yes that works just 
fine. Really, the use of jshell in my example was not the important part 
- I was mostly trying to see how usable the SystemABI was. Clients for 
that API are the binder, and could be rich frameworks such as JNR and 
JavaCPP. I'm assuming that *not* having to have to spin annotated 
interfaces in order to be able to play with the Panama backend can be a 
feature in such instances.

Maurizio

>
> $ /path/to/jshell --class-path /path/to/javacpp.jar
> jshell> import org.bytedeco.javacpp.*;
> jshell> import org.bytedeco.javacpp.annotation.*;
> jshell> import org.bytedeco.javacpp.tools.*;
> jshell> @Platform(include = "unistd.h") class Dummy { public static 
> native int getpid(); }
> jshell> new 
> Builder().classesOrPackages(Dummy.class.getName()).outputDirectory("/tmp").build();
> jshell> System.load("/tmp/libjniDummy.so")
> jshell> Dummy.getpid()
> $12 ==> 5217
>
> We could easily make this cleaner too, see for example suggestions 
> from Cyprien Noel (added in Cc) in this pull request:
> https://github.com/bytedeco/javacpp/pull/138
> The point is, I don't see any usability issues, but do you?
>
> Samuel
>
> On 11/28/2018 11:00 PM, Maurizio Cimadamore wrote:
>> Hi,
>> I took the patch at [1] for a spin with jshell. I wanted to see how 
>> easy it was to call native functions using the SystemABI interface - 
>> e.g. w/o binder and annotated interface. I think I'm pleasantly 
>> impressed! I did some changes to the proposed patch as I wanted to 
>> put everything SystemABI-specific in a public package (java.foreign) 
>> and I also added a method on UpcallHandle to get a pointer. But 
>> overall these were minor modification, mostly in order to be able to 
>> use this setup on jshell. But let's dive on some code.
>>


More information about the panama-dev mailing list