[foreign-abi] RFR: JDK-8243669: Improve library loading for Panama libraries

Samuel Audet samuel.audet at gmail.com
Tue May 5 22:56:25 UTC 2020

Hi, Maurizio,

On 5/5/20 7:32 PM, Maurizio Cimadamore wrote:
> To which you might say "why don't you just do all that?" - and the 
> answer (which you won't like) is that it feels to me that we are in a 
> land of diminishing return, where you have to do a lot of effort in 
> order to do something that is only marginally better to what you could 
> achieve _today_ with a slightly different API: if your pointer access 
> API is separated from the pointer API itself, then doing what you 
> describe can be achieved like this:
> Pointer p ....
> p.withHandle(PointerHandle ph -> {
>       ph.get(...)
>       ph.set(...)
> });
> p.deallocate() // will fail if there are any pending handles
> This is a relatively pleasing API - which has the added benefit that it 
> makes it extra obvious as to which operations are allowed on with 
> entities (e.g. you cannot just call `get` on a pointer, it just isn't 
> there!). This is much simpler for the user to understand (IMHO) than an 
> API which say "there is a `get` method here, but to call it safely you 
> must wrap access inside some kind of try-pointer block provided by the 
> language".

That actually looks good, I agree, but I still don't see why that kind 
of pattern could not be made (more) standard. You're using different 
APIs for memory layouts and library loading, why? In technical terms, 
what prevents us from using something similar for memory layouts, 
library loading, or anything else users would like to support, such as 
GPU resources?

It sounds like you're saying that this pattern is so easy to implement 
that everyone should reimplement their own custom versions, but I don't 
consider this to be obvious given that everyone else on other platforms 
standardizes resource management, either at the language level or by 
using some sort of standard API. However, even as part of the JDK, 
you're not even using the same API for memory layouts and library 
loading! In other words, why not make it (even) easier to implement for 
*any* type of resources? What are the roadblocks that we should start to 
look at?

That's basically my stance. I'm not trying to push solutions, I'm just 
trying to drive the point home that we need some sort of solution. GPUs, 
FPGAs, DSPs, and other accelerators in general are not going to become 
magically irrelevant simply because OpenJDK does not consider them 
important! They are important, they are here to stay, and their 
importance is only going to continue to grow.

Again, I'm not saying that all of this is going to be easy to figure 
out. What I would really like to do is to get a discussion started about 


More information about the panama-dev mailing list