Skip to content
This repository was archived by the owner on Sep 19, 2023. It is now read-only.

8132785: java/lang/management/ThreadMXBean/ThreadLists.java fails intermittently #14

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion test/jdk/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,6 @@ com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java 8030957 aix-all
java/lang/management/MemoryMXBean/Pending.java 8158837 generic-all
java/lang/management/MemoryMXBean/PendingAllGC.sh 8158837 generic-all
java/lang/management/ThreadMXBean/ThreadMXBeanStateTest.java 8247426 generic-all
java/lang/management/ThreadMXBean/ThreadLists.java 8132785 generic-all

sun/management/jdp/JdpDefaultsTest.java 8241865 linux-aarch64,macosx-all
sun/management/jdp/JdpJmxRemoteDynamicPortTest.java 8241865 macosx-all
Expand Down
24 changes: 22 additions & 2 deletions test/jdk/java/lang/management/ThreadMXBean/ThreadLists.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2021, 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
Expand All @@ -23,9 +23,11 @@

/*
* @test
* @bug 5047639
* @bug 5047639 8132785
* @summary Check that the "java-level" APIs provide a consistent view of
* the thread list
* @comment Must run in othervm mode to avoid interference from other tests.
* @run main/othervm ThreadLists
*/
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
Expand All @@ -50,6 +52,19 @@ public static void main(String args[]) {
// get the thread count
int activeCount = top.activeCount();

// Now enumerate to see if we find any extras yet.
// Ensure the array is big enough for a few extras.
Thread[] threads = new Thread[activeCount * 2];
int newCount = top.enumerate(threads);
if (newCount != activeCount) {
System.out.println("Found different threads after enumeration:");
} else {
System.out.println("Initial set of enumerated threads:");
}
for (int i = 0; i < newCount; i++) {
System.out.println(" - Thread: " + threads[i].getName());
}

Map<Thread, StackTraceElement[]> stackTraces = Thread.getAllStackTraces();

ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
Expand All @@ -68,6 +83,11 @@ public static void main(String args[]) {
if (activeCount != threadIds.length) failed = true;

if (failed) {
System.out.println("Set of stack-traced threads:");
for (Thread t : stackTraces.keySet()) {
System.out.println(" - Thread: " +
(t != null ? t.getName() : "null!"));
}
throw new RuntimeException("inconsistent results");
}
}
Expand Down