On Thu, 27 May 2021 14:28:09 GMT, Aleksei Voitylov <avoity...@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