[foreign-memaccess] [Rev 03] RFR: Move "owner" field and thread-confinement checks to MemoryScope
Jorn Vernee
jvernee at openjdk.java.net
Fri May 15 13:35:40 UTC 2020
On Fri, 15 May 2020 13:28:29 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/MemoryScope.java line 192:
>>
>>> 191: checkAliveConfined(this);
>>> 192: }
>>> 193: }
>>
>> This changes the behavior we had before in AbstractMemorySegmentImpl::checkValidState. We should still do the liveness
>> check even if there is no owner. Suggestion:
>>
>> if (owner != null && owner != Thread.currentThread()) {
>> throw new IllegalStateException("Attempted access outside owning thread");
>> }
>> checkAliveConfined(this);
>
>> This changes the behavior we had before in AbstractMemorySegmentImpl::checkValidState. We should still do the liveness
>> check even if there is no owner.
>
> True - I suspect Peter would argue that such check doesn't make much sense in a racy context - but still, there's a
> change in behavior here.
IMO It's not necessarily racy, it's just that the API doesn't guarantee that there is no race, that's up to the user to
do. e.g. by making sure that the thread doing the access can see an up to date liveness flag (by using other
synchronization).
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/167
More information about the panama-dev
mailing list