[foreign] RFR 8210998: Missing pointer scope checks
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Fri Sep 21 11:47:19 UTC 2018
Hi,
while playing around with the Panama API in jshell, I realized that we
don't always enforce scope liveness in all contexts. One of the most
important cases was:
Pointer::addr
But there were other cases left out too (see Reference subclasses).
This patch adds the missing checks in the right places and also add a
comprehensive test which check:
* Pointer dereference (get/set) after Scope::close() with various
pointer shapes
* Struct/array/callback access after Scope::close
* Passing pointer/struct/callback after Scope::close
In writing this tests I uncovered few issues:
1) The signature of LayoutType.ofFunction was wrong - it had a
Callback<Z> bound on the type variable which was bogus. In fact there's
no bound here (this is a leftover from previous code). This also
required tweaks to LayoutTypeImpl
2) Scope::allocateCallback was NOT associating the callback entry point
pointer with the current scope. As a result the callback pointer was
accessible even AFTER the owning scope was closed. I fixed it by moving
the pointer creation logic inside Scope - now UpcallHandler just has a
'long' entry point, which I think makes the code even clearer.
3) CallbackImplGenerator - this code was going out of his way in order
to enforce checks on pointer scope; however, on a closer inspection,
since this code relied on 'addr()' and Pointer::addr is now checked
properly, there's no need to add special cruft.
4) The logic for 'setting' arrays into array references was overly
convoluted: with Array we can now just do the operation with a bulk
pointer copy.
Webrev:
http://cr.openjdk.java.net/~mcimadamore/panama/8210998/
Cheers
Maurizio
More information about the panama-dev
mailing list