Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.
/ jdk18 Public archive

Commit

Permalink
8132785: java/lang/management/ThreadMXBean/ThreadLists.java fails int…
Browse files Browse the repository at this point in the history
…ermittently

Reviewed-by: alanb, kevinw, dcubed, sspitsyn
  • Loading branch information
David Holmes committed Dec 13, 2021
1 parent 9a1bbaf commit c93b24d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
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

1 comment on commit c93b24d

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.