On Tue, 18 Nov 2025 04:45:46 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
>
> On macosx I'm seeing the following when running ClhsdbPStack.java:
> ``` Opening core file, please wait...
> hsdb> hsdb> + verbose true
> hsdb> + pstack -v
> Deadlock Detection:
> 
> No deadlocks found.
> 
> Not available for Mac OS X processes
> hsdb> + quit
> 
> The "Not available for Mac OS X processes" message is expected when running 
> on a macosx process, but in this case the test is running the core version of 
> the test, so SA is acting on a core file. The test goes on to fail because 
> there are no threads in the output.
> 
> The message is generated by PStack.java whenever the thread list is null and 
> it is running on OSX. In that case it assumes the reason the thread list is 
> null is because it is running on a macosx process. It's not clear to me why 
> the thread list is null. I don't see any changes that look like they could 
> cause that.
> 
> This happens with both x64 and aarch64, although you need to remove the test 
> from the problem list for macosx-aarch64 to get it to reproduce. macosx-x64 
> is not problem listed.

@plummercj Can you try this patch on your Mac? You can apply it to this PR 
branch.


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..f091b22f9d7 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);
@@ -244,7 +247,7 @@ private void findABIVersion() throws DebuggerException {
     /** From the Debugger interface via JVMDebugger */
     public synchronized void attach(int processID) throws DebuggerException {
         checkAttached();
-        threadList = new ArrayList<>();
+        javaThreadList = new ArrayList<>();
         loadObjectList = new ArrayList<>();
         class AttachTask implements WorkerThreadTask {
            int pid;
@@ -264,7 +267,7 @@ public void doit(BsdDebuggerLocal debugger) {
     /** From the Debugger interface via JVMDebugger */
     public synchronized void attach(String execName, String coreName) {
         checkAttached();
-        threadList = new ArrayList<>();
+        javaThreadList = new ArrayList<>();
         loadObjectList = new ArrayList<>();
         attach0(execName, coreName);
         attached = true;
@@ -278,7 +281,7 @@ public synchronized boolean detach() {
             return false;
         }

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

         if (isCore) {
@@ -492,7 +495,25 @@ public Address newAddress(long value) {
     /** From the BsdCDebugger interface */
     public List<ThreadProxy> getThreadList() {
       requireAttach();
-      return threadList;
+
+      if (javaThreadList == null) {
+        return null;
+      }
+      if (!isCore) {
+        // TODO: thread list is now supported for corefile only.
+        return Collections.emptyList();
+      }
+
+      if (javaThreadList.isEmpty()) {
+        Threads threads = VM.getVM().getThreads();
+        IntStream.range(0, threads.getNumberOfThreads())
+                 .mapToObj(threads::getJavaThreadAt)
+                 .forEach(javaThreadList::add);
+      }
+
+      return javaThreadList.stream()
+                           .map(t -> t.getThreadProxy())
+                           .toList();
     }

     /** From the BsdCDebugger interface */
@@ -561,21 +582,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-3550467374

Reply via email to