You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by zr...@apache.org on 2026/04/23 06:13:35 UTC

(dubbo) branch 3.3 updated: fix: disable lockedSynchronizers in dumpAllThreads to avoid ZGC safepoint heap scan (#16195)

This is an automated email from the ASF dual-hosted git repository.

zrlw pushed a commit to branch 3.3
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.3 by this push:
     new 27fc75b643 fix: disable lockedSynchronizers in dumpAllThreads to avoid ZGC safepoint heap scan (#16195)
27fc75b643 is described below

commit 27fc75b643f929a14392ac8eed70357bc63ad6b5
Author: Ran <84...@users.noreply.github.com>
AuthorDate: Thu Apr 23 14:13:29 2026 +0800

    fix: disable lockedSynchronizers in dumpAllThreads to avoid ZGC safepoint heap scan (#16195)
    
    * fix: disable lockedSynchronizers in dumpAllThreads to avoid safepoint heap scan (#16194)
    
    `ThreadMXBean.dumpAllThreads(true, true)` with lockedSynchronizers=true
    forces the JVM to scan the entire heap at a safepoint to find all
    AbstractOwnableSynchronizer instances. On ZGC with large heaps (65GB+),
    this causes ~37-second safepoint pauses that freeze all application
    threads, leading to cascading thread pool exhaustion.
    
    Change lockedSynchronizers from true to false. This retains locked
    monitor information (derived from thread stacks, cheap) but skips the
    expensive heap scan. Only java.util.concurrent.locks ownership info
    is lost from the thread dump output.
    
    Fixes #16194
    
    * chore: remove inline comments from JVMUtil.jstack()
    
    Context is documented in the issue and PR description.
    
    Fixes #16194
    
    * Make locked synchronizer scan opt-in via system property
    
    Per @RainYuY: allow users to restore the legacy dumpAllThreads(true, true)
    behaviour by setting dubbo.jstack-dump.locked-synchronizers=true. Default
    remains false, since on ZGC + large heaps the full-heap safepoint scan
    triggered by this flag can freeze the JVM for tens of seconds (#16194).
---
 .../java/org/apache/dubbo/common/constants/CommonConstants.java   | 4 ++++
 .../src/main/java/org/apache/dubbo/common/utils/JVMUtil.java      | 8 +++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
index d2cd352132..81c0ebc964 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
@@ -607,6 +607,8 @@ public interface CommonConstants {
      */
     String DUBBO_JSTACK_MAXLINE = "dubbo.jstack-dump.max-line";
 
+    String DUBBO_JSTACK_LOCKED_SYNCHRONIZERS = "dubbo.jstack-dump.locked-synchronizers";
+
     String ENCODE_IN_IO_THREAD_KEY = "encode.in.io";
 
     boolean DEFAULT_ENCODE_IN_IO_THREAD = false;
@@ -724,6 +726,8 @@ public interface CommonConstants {
          */
         String DUBBO_JSTACK_MAXLINE = "dubbo.jstack-dump.max-line";
 
+        String DUBBO_JSTACK_LOCKED_SYNCHRONIZERS = "dubbo.jstack-dump.locked-synchronizers";
+
         /**
          * The property name for {@link NetworkInterface#getDisplayName() the name of network interface} that the Dubbo
          * application will be ignored
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/JVMUtil.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/JVMUtil.java
index 146e351e08..694752493b 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/JVMUtil.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/JVMUtil.java
@@ -33,7 +33,13 @@ import static java.lang.Thread.State.WAITING;
 public class JVMUtil {
     public static void jstack(OutputStream stream) throws Exception {
         ThreadMXBean threadMxBean = ManagementFactory.getThreadMXBean();
-        for (ThreadInfo threadInfo : threadMxBean.dumpAllThreads(true, true)) {
+        boolean lockedSynchronizers = false;
+        String lockedSynchronizersStr = SystemPropertyConfigUtils.getSystemProperty(
+                CommonConstants.DubboProperty.DUBBO_JSTACK_LOCKED_SYNCHRONIZERS);
+        if (StringUtils.isNotEmpty(lockedSynchronizersStr)) {
+            lockedSynchronizers = Boolean.parseBoolean(lockedSynchronizersStr);
+        }
+        for (ThreadInfo threadInfo : threadMxBean.dumpAllThreads(true, lockedSynchronizers)) {
             stream.write(getThreadDumpString(threadInfo).getBytes(StandardCharsets.UTF_8));
         }
     }