-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
8324066: "clhsdb jstack" should not by default scan for j.u.c locks b…
…ecause it can be very slow Reviewed-by: kevinw, amenkov
- Loading branch information
Showing
10 changed files
with
227 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
test/hotspot/jtreg/serviceability/sa/ClhsdbJstackWithConcurrentLock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Copyright (c) 2024, 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 | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
/** | ||
* @test | ||
* @bug 8324066 | ||
* @summary Test the clhsdb 'jstack -l' command for printing concurrent lock information | ||
* @requires vm.hasSA | ||
* @library /test/lib | ||
* @run main/othervm ClhsdbJstackWithConcurrentLock | ||
*/ | ||
|
||
import java.util.List; | ||
import jdk.test.lib.apps.LingeredApp; | ||
import jtreg.SkippedException; | ||
|
||
public class ClhsdbJstackWithConcurrentLock { | ||
|
||
public static void main(String[] args) throws Exception { | ||
System.out.println("Starting the ClhsdbJstackWithConcurrentLock test"); | ||
|
||
LingeredApp theApp = null; | ||
try { | ||
ClhsdbLauncher test = new ClhsdbLauncher(); | ||
|
||
theApp = new LingeredAppWithConcurrentLock(); | ||
// Use a small heap so the scan is quick. | ||
LingeredApp.startApp(theApp, "-Xmx4m"); | ||
System.out.println("Started LingeredApp with pid " + theApp.getPid()); | ||
|
||
// Run the 'jstack -l' command to get the stack and have java.util.concurrent | ||
// lock information included. | ||
List<String> cmds = List.of("jstack -l"); | ||
String jstackOutput = test.run(theApp.getPid(), cmds, null, null); | ||
|
||
// We are looking for: | ||
// Locked ownable synchronizers: | ||
// - <0x00000000ffc2ed70>, (a java/util/concurrent/locks/ReentrantLock$NonfairSync) | ||
// We want to fetch the address from this line. | ||
String key = ", (a java/util/concurrent/locks/ReentrantLock$NonfairSync)"; | ||
String[] lines = jstackOutput.split("\\R"); | ||
String addressString = null; | ||
for (String line : lines) { | ||
if (line.contains(key)) { | ||
String[] words = line.split("[, ]"); | ||
for (String word : words) { | ||
word = word.replace("<", "").replace(">", ""); | ||
if (word.startsWith("0x")) { | ||
addressString = word; | ||
break; | ||
} | ||
} | ||
if (addressString != null) | ||
break; | ||
} | ||
} | ||
if (addressString == null) { | ||
throw new RuntimeException("Token '" + key + "' not found in jstack output"); | ||
} | ||
|
||
// We are looking for the following java frame: | ||
// - jdk.internal.misc.Unsafe.park(boolean, long)... | ||
// - parking to wait for <0x00000000ffc2ed70> (a java/util/concurrent/locks/ReentrantLock$NonfairSync) | ||
// Note the address matches the one we found above. | ||
key = "- parking to wait for <" + addressString + | ||
"> (a java/util/concurrent/locks/ReentrantLock$NonfairSync)"; | ||
boolean found = false; | ||
for (String line : lines) { | ||
if (line.contains(key)) { | ||
found = true; | ||
break; | ||
} | ||
} | ||
if (!found) { | ||
throw new RuntimeException("Token '" + key + "' not found in jstack output"); | ||
} | ||
} catch (SkippedException e) { | ||
throw e; | ||
} catch (Exception ex) { | ||
throw new RuntimeException("Test ERROR " + ex, ex); | ||
} finally { | ||
LingeredApp.stopApp(theApp); | ||
System.out.println("OUTPUT: " + theApp.getOutput()); | ||
} | ||
System.out.println("Test PASSED"); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
test/hotspot/jtreg/serviceability/sa/LingeredAppWithConcurrentLock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (c) 2024, 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 | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
import jdk.test.lib.apps.LingeredApp; | ||
|
||
import java.util.concurrent.locks.Lock; | ||
import java.util.concurrent.locks.ReentrantLock; | ||
|
||
|
||
public class LingeredAppWithConcurrentLock extends LingeredApp { | ||
|
||
private static final Lock lock = new ReentrantLock(); | ||
|
||
public static void lockMethod(Lock lock) { | ||
lock.lock(); | ||
synchronized (lock) { | ||
try { | ||
Thread.sleep(300000); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} | ||
|
||
public static void main(String args[]) { | ||
Thread classLock1 = new Thread(() -> lockMethod(lock)); | ||
Thread classLock2 = new Thread(() -> lockMethod(lock)); | ||
Thread classLock3 = new Thread(() -> lockMethod(lock)); | ||
|
||
classLock1.start(); | ||
classLock2.start(); | ||
classLock3.start(); | ||
|
||
// Wait until all threads have reached their blocked or timed wait state | ||
while ((classLock1.getState() != Thread.State.WAITING && | ||
classLock1.getState() != Thread.State.TIMED_WAITING) || | ||
(classLock2.getState() != Thread.State.WAITING && | ||
classLock2.getState() != Thread.State.TIMED_WAITING) || | ||
(classLock3.getState() != Thread.State.WAITING && | ||
classLock3.getState() != Thread.State.TIMED_WAITING)) { | ||
try { | ||
Thread.sleep(100); | ||
} catch (InterruptedException ex) { | ||
} | ||
} | ||
System.out.println("classLock1 state: " + classLock1.getState()); | ||
System.out.println("classLock2 state: " + classLock2.getState()); | ||
System.out.println("classLock3 state: " + classLock3.getState()); | ||
|
||
LingeredApp.main(args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
192349e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review
Issues