RFR: 8266310: deadlock while loading the JNI code [v2]

Aleksei Voitylov aleksei.voitylov at bell-sw.com
Fri May 21 20:19:29 UTC 2021


Peter, David,

I updated the PR to focus on solving the problem I originally intended
to solve that is observed in the wild - a deadlock when two different
libraries are being loaded. The case when the same library JNI_OnLoad
has FindClass with a circular dependency on loading the same library is
artificial. I thought of two ways to resolve it with the following
conclusions:

- not holding a lock when JNI_OnLoad is executed can only be done in a
such a way that would lead to a possibility to get JNI_OnLoad executed
multiple times, and the JNI code can rely on the fact that it's called
only once (though the JNI spec does not say so). Decoupling
dlopen/LoadLibrary from JNI_OnLoad does not solve this problem as well.
- throwing something like LibraryBeingLoadedError similar to
ClassCircularityError for JNI calls trying to use a class which
initializes the same library is also not a good option, as it is
behavior change. I as a user would not know what to do with that
(remember it can appear for a different thread that just happened to be
initializing the same library as well). Such a thread should just sit
and wait on the lock.

Both such solutions would make innocent code suffer, so are a no-go. I'm
open to ideas how to resolve it, if at all, but IMO it has a different
priority compared to the original bug report. I thus focused on solving
the original problem.

Thanks,

-Aleksei

On 21/05/2021 21:10, Peter Levart wrote:
>
> On 21/05/2021 10:29, Peter Levart wrote:
>> I still haven't found a scenario of a possible deadlock when Sergei's
>> initial patch is combined with...
>
>
> Sorry Aleksei, I renamed you to Sergei without intention. Please
> excuse me.
>
>
> Peter
>
>



More information about the core-libs-dev mailing list