[foreign] RFR: native libraries should have a global scope

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Mon Jul 9 17:47:53 UTC 2018



On 09/07/18 18:33, Henry Jen wrote:
> I was hoping the get it right at first time, but this works. :)
I didn't put much effort in creating a new API point because all this 
stuff is static: note that we don't have to recompute the pointer on 
every access - the pointer to the global var is determined once and for 
all, and injected into the bytecode (through CP patching). So, the cost 
we pay for creating that initial pointer is a one-off - access will be 
as before.

Maurizio
>
> Not an expert, hope JVM is smart enough to optimize it.
>
> Cheers,
> Henry
>
>
>> On Jul 9, 2018, at 3:39 AM, Maurizio Cimadamore <maurizio.cimadamore at oracle.com> wrote:
>>
>> Here's a revised version of the patch that adds the boundary check we discussed. A single call to the 'limit' method was enough to achieve the desired effect:
>>
>> http://cr.openjdk.java.net/~mcimadamore/panama/global_scope_v2/
>>
>> Maurizio
>>
>>
>>
>> On 06/07/18 18:08, Henry Jen wrote:
>>> Looks good.
>>>
>>> One nitpick, the createNativeVoidPointer, I see it’s following existing convention, however, I think we should tighten the region whenever possible if the range of access is known at the time.
>>>
>>> For global variable, we should know the size and truly bound the region to the allowed size, make sense?
>>>
>>> Cheers,
>>> Henry
>>>
>>>> On Jul 6, 2018, at 6:15 AM, Maurizio Cimadamore <maurizio.cimadamore at oracle.com> wrote:
>>>>
>>>> Hi,
>>>> In general, all user-facing pointers have a scope; there is however an important exceptions: pointer to globals. Since such pointers are computed inside the binder, they do not have any associate scope. This leads to issues with code uniformity (where e.g. we have to defensively check for null when retrieving a pointer's scope), and it is also an impediment to develop certain features: for instance, we'd like constant values to be generated in the binder - and not in jextract (as now) - but doing so might require native memory allocation by the native library (think about a string constant) - and that requires a scope.
>>>>
>>>> This patch adds a global scope that is shared by all instance of a certain library. The scope is created when an impl for a library interface is requested. A reference cleaner is also used to make sure that the Scope::close method is called when the library class is unloaded.
>>>>
>>>> As part of this change I also added javadoc to the Library interface, and turned the Library.Symbol class into an interface (allocating a symbol is a privileged operation and should not be exposed by the public API).
>>>>
>>>> Webrev:
>>>>
>>>> http://cr.openjdk.java.net/~mcimadamore/panama/global_scope/
>>>>
>>>>
>>>> Maurizio
>>>>



More information about the panama-dev mailing list