Very heavy lock contention under load
@brettwooldridge is already working on this.
Since Sep 26, 2025.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 28/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- java
- Domain
- backend, performance
Research direction
Start in src/com/sun/jna/internal/Cleaner.java at Cleaner.register, then trace the callers shown in the stack trace, especially Memory and ByReference construction. Reproduce under a cold start with roughly 1,000 threads on Linux amd64 and confirm that the lock contention is reduced or eliminated under comparable load.
Written by the indexing model from the issue text.
Description
We're experiencing very heavy lock contention with version 5.14. It's in this section of the code https://github.com/java-native-access/jna/blob/5.14.0/src/com/sun/jna/internal/Cleaner.java#L58. In one of the thread dumps we see 647 threads waiting on the lock. We were initially running 5.10, upgrading to 5.14 didn't help.
We've tried with the latest Zulu JDK 22 and JDK 21, same result. Linux amd64. This problem now always triggers in our app immediately after a fresh start, possibly because the JVM is slower. If reduce the amount of threads initially then it doesn't trigger immediately, but it still happens after a while. Sometimes stopping and restarting the threads helps.
The server is not overloaded. We increased the number of cores two-fold and we're still experiencing the problem.
Below is the relevant part of the stacktrace.
Not sure how you can reproduce, in our case we always see this problem from cold start with about 1000 threads.
Any thoughts?
"pool-4-thread-447" #4038 [3373050] prio=5 os_prio=0 cpu=2546.58ms elapsed=612.63s tid=0x00007f5e28011e90 nid=3373050 runnabl
java.lang.Thread.State: RUNNABLE
at com.sun.jna.internal.Cleaner.register(Cleaner.java:58)
- locked <0x00007f6069fdc500> (a com.sun.jna.internal.Cleaner)
at com.sun.jna.Memory.<init>(Memory.java:122)
at com.sun.jna.ptr.ByReference.<init>(ByReference.java:57)
at com.sun.jna.ptr.IntByReference.<init>(IntByReference.java:35)
at com.sun.jna.ptr.IntByReference.<init>(IntByReference.java:31)
at java.lang.invoke.LambdaForm$DMH/0x00007f5fbbf19800.newInvokeSpecial([email protected]/LambdaForm$DMH)
at java.lang.invoke.Invokers$Holder.invokeExact_MT([email protected]/Invokers$Holder)
at jdk.internal.reflect.DirectConstructorHandleAccessor.invokeImpl([email protected]/DirectConstructorHandleAccessor.j
at jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance([email protected]/DirectConstructorHandleAccessor.
at java.lang.reflect.Constructor.newInstanceWithCaller([email protected]/Constructor.java:502)
at java.lang.reflect.Constructor.newInstance([email protected]/Constructor.java:486)
at com.sun.jna.Klass.newInstance(Klass.java:48)
at com.sun.jna.NativeMappedConverter.defaultValue(NativeMappedConverter.java:65)
at com.sun.jna.Structure.initializeField(Structure.java:1440)
at com.sun.jna.Structure.initializeFields(Structure.java:1416)
at com.sun.jna.Structure.<init>(Structure.java:218)
at com.sun.jna.Structure.<init>(Structure.java:204)
at com.sun.jna.Structure.<init>(Structure.java:191)
at com.sun.jna.Structure.<init>(Structure.java:183)
- Dominant language
- Java
- Stars
- 8.9k
- Forks
- 1.7k
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 1
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from java-native-access/jna
-
`Native.typeOptions` never releases library interfaces, leaking classloadersPossibly taken @curforever claimed this 3 days ago. Open
Difficulty 4/5 1-2 days Newbie friendliness 48/100
java-native-access/jna#1742 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 66/100
java-native-access/jna#1738 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
java-native-access/jna#1736 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 65/100
java-native-access/jna#1717 ·
-
Windows32Exception - The parameter is incorrectPossibly taken @marktech0813 claimed this 339 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 35/100
java-native-access/jna#1700 · 11 comments ·
All issues in java-native-access/jna
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
refinedmods/refinedstorage2#1421 ·
-
StepExamBenchmarkTest runs a loop and prints a timing but asserts nothingPossibly taken A pull request linked to this issue is open or already merged. Openjules
Difficulty 1/5 Under an hour Newbie friendliness 82/100
open-learning-exchange/myplanet#18199 · 1 comment ·
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
Scheme-less stream URLs throw NullPointerException instead of URISyntaxExceptionPossibly taken @blihio claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
pedroSG94/RootEncoder#2218 ·
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
apache/rocketmq-dashboard#6872 ·
Maintainers usually reply within 3 days