Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Very heavy lock contention under load

未关闭
#1,616 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

  • #1684 来自 @brettwooldridge —— 已关闭,未合并

评估

难度
4/5
预计耗时
3-5 天
新手友好度
28/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
java

调研方向

从 src/com/sun/jna/internal/Cleaner.java 中的 Cleaner.register 开始,然后跟踪 stack trace 中显示的调用方,尤其是 Memory 和 ByReference 的构造。在 Linux amd64 上以大约 1,000 个线程进行冷启动复现,并确认在相当的负载下 lock 竞争有所减少或消除。

由索引模型根据 Issue 内容生成。

描述

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)
主要语言
Java
星标
8.9k
派生
1.7k
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

java-native-access/jna 的其他 Issue

查看 java-native-access/jna 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。