From 422176a837e419d72dee4d5d6b81ff78bfe315a1 Mon Sep 17 00:00:00 2001 From: Zhai Mo Date: Fri, 15 Sep 2023 17:23:33 +0800 Subject: [PATCH] [Wisp] WispThreadCompositeData.getCompositeData() should use legal Thread State String. Summary: sun.management.ThreadInfoCompositeData.threadState() will use valueOf() to read Thread.State String. We should specify a TERMINATED String for it. Also, a cleanup. Test Plan: com/alibaba/wisp/thread/TestThreadInfo.java Reviewed-by: yulei Issue: https://github.com/dragonwell-project/dragonwell17/issues/155 --- .../share/classes/sun/management/ThreadImpl.java | 7 ++++++- .../classes/sun/management/WispThreadCompositeData.java | 5 +++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/java.management/share/classes/sun/management/ThreadImpl.java b/src/java.management/share/classes/sun/management/ThreadImpl.java index 2928a668bf1..16e393a51ea 100644 --- a/src/java.management/share/classes/sun/management/ThreadImpl.java +++ b/src/java.management/share/classes/sun/management/ThreadImpl.java @@ -26,6 +26,7 @@ package sun.management; import com.alibaba.wisp.engine.WispEngine; +import com.alibaba.wisp.engine.WispTask; import jdk.internal.access.SharedSecrets; import jdk.internal.access.WispEngineAccess; @@ -206,7 +207,11 @@ public ThreadInfo[] getThreadInfo(long[] ids, int maxDepth) { if (WispEngine.enableThreadAsWisp()) { for (int i = 0; i < infos.length; i++) { if (infos[i] == null) { - infos[i] = ThreadInfo.from(new WispThreadCompositeData(WEA.getWispTaskById(ids[i]))); + WispTask task = WEA.getWispTaskById(ids[i]); + if (task == null) { + continue; + } + infos[i] = ThreadInfo.from(new WispThreadCompositeData(task)); } } } diff --git a/src/java.management/share/classes/sun/management/WispThreadCompositeData.java b/src/java.management/share/classes/sun/management/WispThreadCompositeData.java index 44b0459bc90..a397022ff69 100644 --- a/src/java.management/share/classes/sun/management/WispThreadCompositeData.java +++ b/src/java.management/share/classes/sun/management/WispThreadCompositeData.java @@ -16,17 +16,18 @@ public class WispThreadCompositeData extends LazyCompositeData { private final WispTask task; public WispThreadCompositeData(WispTask wispTask) { + assert wispTask != null : "handled null cases already"; task = wispTask; } @Override protected CompositeData getCompositeData() { Map items = new HashMap<>(); - Thread t = task != null ? task.getThreadWrapper() : null; + Thread t = task.getThreadWrapper(); Object parkBlocker = t != null ? LockSupport.getBlocker(t) : null; items.put(THREAD_ID, t != null ? t.getId() : 0L); items.put(THREAD_NAME, t != null ? t.getName() : ""); - items.put(THREAD_STATE, t != null ? t.getState().name() : ""); + items.put(THREAD_STATE, t != null ? t.getState().name() : Thread.State.TERMINATED.toString()); items.put(LOCK_NAME, parkBlocker == null ? "" : parkBlocker.toString()); items.put(BLOCKED_TIME, 0L); items.put(BLOCKED_COUNT, 0L);