resource scopes and close actions

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Mon Feb 7 10:49:13 UTC 2022


If you want a "scoped" memory address, please look at NativeSymbol. This 
is used by the lookup functions provided by the JDK, but is also useful 
to capture an address and associate a scope with it. This allows you to 
model everything with one field (NativeSymbol) and then no liveness 
check is needed, just pass the symbol to the method handle, and standard 
safety checks will apply.

Maurizio

On 05/02/2022 09:16, Michael Zucchi wrote:
> OpenCL (& Vulkan) does everything via handles (typed anonymous 
> pointers), so presumably represented by MemoryAddress.  What approach 
> to use here to make them scope-safe?  Have explicit scope tests before 
> using them in calls?
>
> If one wanted a scope-protected MemoryAddress this seems to be the 
> only solution in the present api:
>
> CLCommandQueue {
>   ResourceScope scope;
>   MemoryAddress handle;
>
>   void enqueueNDRangeKernel(...) {
>     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
>        scope.keepAlive(this.scope);
>          enqueueNDRangeKernel$MH.invokeExact((Addressable)handle, ...);
>     } catch (IllegalStateException ex) {
>     }
>   }
> }
>
> Actually it's a bit worse because there will be handles (possibly in 
> different scopes) in the argument list and they would all need to be 
> checked in the same way.
>
> So for practicality they would have to be MemorySegment (ideally 
> length=0) since they are always checked? 


More information about the panama-dev mailing list