Finalization and dead references: another proposal
Peter Levart
peter.levart at gmail.com
Thu Dec 7 18:46:47 UTC 2017
Hi Remi,
On 12/07/2017 07:12 PM, Remi Forax wrote:
>>> So no magic here. Just API.
>> This is an API version of Hans’s #3 approach. As he said, there’s
>> performance overhead and nothing guarantees that the referent is kept alive
>> - that’s an implementation artifact.
> it's not even true, the implementation do not even guarantee that the referent field will be kept on stack,
> a value type can disappear completely if its field are not used,
> so without a reachabilityFence somewhere, it will not work.
>
What do you mean by saying "the implementation do not even guarantee
that the referent field will be kept on stack".
If a referent is passed through a reference typed parameter to the JNI
method (there's no other way actually), then such referent must be kept
alive for the entire time the native method executes, because native
method may call methods or access fields on such referent. Because
there's no cross-native-baundary optimization going on currently, JNI
must guarantee that. If/when there will be cross-native-baundary
optimization, I suppose native side would have to have an equivalent to
reachabilityFence too ...
Regards, Peter
More information about the core-libs-dev
mailing list