RFR: 8266310: deadlock while loading the JNI code [v5]
Peter Levart
plevart at openjdk.java.net
Mon May 31 09:57:22 UTC 2021
On Thu, 27 May 2021 14:28:09 GMT, Aleksei Voitylov <avoitylov at openjdk.org> wrote:
>> 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.
This is good now.
-------------
PR: https://git.openjdk.java.net/jdk/pull/3976
More information about the core-libs-dev
mailing list