On Wed, 19 Nov 2025 05:46:37 GMT, Chris Plummer <[email protected]> wrote:

>> Yasumasa Suenaga has updated the pull request incrementally with one 
>> additional commit since the last revision:
>> 
>>   Update for Linux PPC64 and RISC-V
>
> With your diffs ClhsdbPStack.java is passing but now I'm seeing issues with 
> the following 3 core file tests on both aarch64 and x64:
> 
> 
> serviceability/sa/ClhsdbFindPC.java#xcomp-core
> serviceability/sa/ClhsdbFindPC.java#no-xcomp-core
> serviceability/sa/ClhsdbCDSCore.java
> 
> 
> In the log it is having trouble with the stack trace:
> 
> 
> hsdb> + jstack -v
> Deadlock Detection:
> 
> No deadlocks found.
> 
> "main" #3 prio=5 tid=0x00007fa48a809010 nid=10499 runnable 
> [0x000070000b780000]
>    java.lang.Thread.State: RUNNABLE
>    JavaThread state: _thread_in_native
> 
> Error occurred during stack walking:
> sun.jvm.hotspot.debugger.DebuggerException: get_thread_regs failed for a lwp
>       at 
> jdk.hotspot.agent/sun.jvm.hotspot.debugger.bsd.BsdDebuggerLocal.getThreadIntegerRegisterSet0(Native
>  Method)
>       at 
> jdk.hotspot.agent/sun.jvm.hotspot.debugger.bsd.BsdDebuggerLocal.getThreadIntegerRegisterSet(BsdDebuggerLocal.java:462)
>       at 
> jdk.hotspot.agent/sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:68)
>       at 
> jdk.hotspot.agent/sun.jvm.hotspot.runtime.bsd_amd64.BsdAMD64JavaThreadPDAccess.getCurrentFrameGuess(BsdAMD64JavaThreadPDAccess.java:98)
>       at 
> jdk.hotspot.agent/sun.jvm.hotspot.runtime.JavaThread.getCurrentFrameGuess(JavaThread.java:266)
>       at 
> jdk.hotspot.agent/sun.jvm.hotspot.runtime.JavaThread.getLastJavaVFrameDbg(JavaThread.java:228)
>       at 
> jdk.hotspot.agent/sun.jvm.hotspot.tools.StackTrace.run(StackTrace.java:81)
>       at 
> jdk.hotspot.agent/sun.jvm.hotspot.CommandProcessor$23.doit(CommandProcessor.java:1020)
>       at 
> jdk.hotspot.agent/sun.jvm.hotspot.CommandProcessor.executeCommand(CommandProcessor.java:2088)
>       at 
> jdk.hotspot.agent/sun.jvm.hotspot.CommandProcessor.executeCommand(CommandProcessor.java:2058)
>       at 
> jdk.hotspot.agent/sun.jvm.hotspot.CommandProcessor.run(CommandProcessor.java:1929)
>       at jdk.hotspot.agent/sun.jvm.hotspot.CLHSDB.run(CLHSDB.java:113)
>       at jdk.hotspot.agent/sun.jvm.hotspot.CLHSDB.main(CLHSDB.java:45)
>       at 
> jdk.hotspot.agent/sun.jvm.hotspot.SALauncher.runCLHSDB(SALauncher.java:285)
>       at 
> jdk.hotspot.agent/sun.jvm.hotspot.SALauncher.main(SALauncher.java:507)
> 
> 
> This repeats for every thread.

@plummercj Thanks a lot for your report! The error what you saw is caused that 
thread list wasn't made in `attach()`.
I think following patch goes well... Can you try it?


diff --git 
a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/bsd/BsdDebuggerLocal.java
 
b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/bsd/BsdDebuggerLocal.java
index 10f6881d010..7c71dcd0ca5 100644
--- 
a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/bsd/BsdDebuggerLocal.java
+++ 
b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/bsd/BsdDebuggerLocal.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,9 @@
 package sun.jvm.hotspot.debugger.bsd;

 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
+import java.util.stream.IntStream;

 import sun.jvm.hotspot.debugger.Address;
 import sun.jvm.hotspot.debugger.DebuggerBase;
@@ -75,10 +77,11 @@ public class BsdDebuggerLocal extends DebuggerBase 
implements BsdDebugger {
     // CDebugger support
     private BsdCDebugger cdbg;

-    // threadList and loadObjectList are filled by attach0 method
-    private List<ThreadProxy> threadList;
+    // loadObjectList are filled by attach0 method
     private List<LoadObject> loadObjectList;

+    private List<JavaThread> javaThreadList;
+
     // called by native method lookupByAddress0
     private ClosestSymbol createClosestSymbol(String name, long offset) {
        return new ClosestSymbol(name, offset);
@@ -241,10 +244,16 @@ private void findABIVersion() throws DebuggerException {
         }
     }

+    private List<JavaThread> generateJavaThreadList() {
+      Threads threads = VM.getVM().getThreads();
+      return IntStream.range(0, threads.getNumberOfThreads())
+                      .mapToObj(threads::getJavaThreadAt)
+                      .toList();
+    }
+
     /** From the Debugger interface via JVMDebugger */
     public synchronized void attach(int processID) throws DebuggerException {
         checkAttached();
-        threadList = new ArrayList<>();
         loadObjectList = new ArrayList<>();
         class AttachTask implements WorkerThreadTask {
            int pid;
@@ -253,6 +262,10 @@ public void doit(BsdDebuggerLocal debugger) {
               debugger.attached = true;
               debugger.isCore = false;
               findABIVersion();
+
+              // TODO: thread list on macOS is now supported for corefile only.
+              debugger.javaThreadList = debugger.isDarwin ? 
Collections.emptyList()
+                                                          : 
generateJavaThreadList();
            }
         }

@@ -264,12 +277,12 @@ public void doit(BsdDebuggerLocal debugger) {
     /** From the Debugger interface via JVMDebugger */
     public synchronized void attach(String execName, String coreName) {
         checkAttached();
-        threadList = new ArrayList<>();
         loadObjectList = new ArrayList<>();
         attach0(execName, coreName);
         attached = true;
         isCore = true;
         findABIVersion();
+        javaThreadList = generateJavaThreadList();
     }

     /** From the Debugger interface via JVMDebugger */
@@ -278,7 +291,7 @@ public synchronized boolean detach() {
             return false;
         }

-        threadList = null;
+        javaThreadList = null;
         loadObjectList = null;

         if (isCore) {
@@ -492,7 +505,9 @@ public Address newAddress(long value) {
     /** From the BsdCDebugger interface */
     public List<ThreadProxy> getThreadList() {
       requireAttach();
-      return threadList;
+      return javaThreadList.stream()
+                           .map(JavaThread::getThreadProxy)
+                           .toList();
     }

     /** From the BsdCDebugger interface */
@@ -561,21 +576,16 @@ public void doit(BsdDebuggerLocal debugger) {
     /** this functions used for core file reading and called from native 
attach0,
         it returns an array of long integers as
         [thread_id, stack_start, stack_end, thread_id, stack_start, stack_end, 
....] for
-        all java threads recorded in Threads. Also adds the ThreadProxy to 
threadList */
+        all java threads recorded in Threads. */
     public long[] getJavaThreadsInfo() {
         requireAttach();
-        Threads threads = VM.getVM().getThreads();
-        int len = threads.getNumberOfThreads();
-        long[] result = new long[len * 3];    // triple
+        long[] result = new long[javaThreadList.size() * 3];    // triple
         long beg, end;
         int i = 0;
-        for (int k = 0; k < threads.getNumberOfThreads(); k++) {
-            JavaThread t = threads.getJavaThreadAt(k);
+        for (var t : javaThreadList) {
             end = t.getStackBaseValue();
             beg = end - t.getStackSize();
-            BsdThread bsdt = (BsdThread)t.getThreadProxy();
-            long uid = bsdt.getUniqueThreadId();
-            if (threadList != null) threadList.add(bsdt);
+            long uid = ((BsdThread)t.getThreadProxy()).getUniqueThreadId();
             result[i] = uid;
             result[i + 1] = beg;
             result[i + 2] = end;

-------------

PR Comment: https://git.openjdk.org/jdk/pull/28284#issuecomment-3551112603

Reply via email to