RFR: 8266310: deadlock while loading the JNI code [v5]
Aleksei Voitylov
avoitylov at openjdk.java.net
Thu May 27 14:32:04 UTC 2021
On Wed, 26 May 2021 07:30:10 GMT, Peter Levart <plevart at openjdk.org> wrote:
>> Aleksei Voitylov has updated the pull request incrementally with one additional commit since the last revision:
>>
>> fix whitespace
>
> src/java.base/share/classes/jdk/internal/loader/NativeLibraries.java line 481:
>
>> 479: throw new Error("Maximum lock count exceeded");
>> 480: }
>> 481:
>
> Hi Aleksei,
> I know in practice this counter will never overflow, but just to be pedantic, it would be better that you either decrement back the counter before throwing Error or you check for overflow without incrementing it. Otherwise the lock is left in a corrupted state since you use it like this:
>
>
> acquireNativeLibraryLock(name);
> try {
> ...
> } finally {
> releaseNativeLibraryLock(name);
> }
>
> ...you see, if acquire fails, it is not paired with release, which is correct since the ReentrantLock has not been acquired, but the counter *HAS* been incremented...
Peter, the updated version checks if counter hits MAX_VALUE before incrementing. It also means the counter can't underflow, so that check is removed.
-------------
PR: https://git.openjdk.java.net/jdk/pull/3976
More information about the core-libs-dev
mailing list