Skip to content

Commit d6c6847

Browse files
tkiriyamaDavid Holmes
authored andcommitted
8335743: jhsdb jstack cannot print some information on the waiting thread
Reviewed-by: dholmes, cjplummer, kevinw
1 parent cad68e0 commit d6c6847

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/JavaVFrame.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -100,7 +100,7 @@ public void printLockInfo(PrintStream tty, int frameCount) {
100100
// then print out the receiver. Locals are not always available,
101101
// e.g., compiled native frames have no scope so there are no locals.
102102
if (frameCount == 0) {
103-
if (getMethod().getName().asString().equals("wait") &&
103+
if (getMethod().getName().asString().equals("wait0") &&
104104
getMethod().getMethodHolder().getName().asString().equals("java/lang/Object")) {
105105
String waitState = "waiting on"; // assume we are waiting
106106
// If earlier in the output we reported java.lang.Thread.State ==

test/hotspot/jtreg/serviceability/sa/LingeredAppWithLock.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,7 @@
2525

2626

2727
public class LingeredAppWithLock extends LingeredApp {
28+
private static Object lockObj = new Object();
2829

2930
public static void lockMethod(Object lock) {
3031
synchronized (lock) {
@@ -36,24 +37,37 @@ public static void lockMethod(Object lock) {
3637
}
3738
}
3839

40+
public static void waitMethod() {
41+
synchronized (lockObj) {
42+
try {
43+
lockObj.wait(300000);
44+
} catch (InterruptedException e) {
45+
throw new RuntimeException(e);
46+
}
47+
}
48+
}
49+
3950
public static void main(String args[]) {
4051
Thread classLock1 = new Thread(() -> lockMethod(LingeredAppWithLock.class));
4152
Thread classLock2 = new Thread(() -> lockMethod(LingeredAppWithLock.class));
4253
Thread objectLock = new Thread(() -> lockMethod(classLock1));
4354
Thread primitiveLock = new Thread(() -> lockMethod(int.class));
55+
Thread objectWait = new Thread(() -> waitMethod());
4456

4557
classLock1.start();
4658
classLock2.start();
4759
objectLock.start();
4860
primitiveLock.start();
61+
objectWait.start();
4962

5063
// Wait until all threads have reached their blocked or timed wait state
5164
while ((classLock1.getState() != Thread.State.BLOCKED &&
5265
classLock1.getState() != Thread.State.TIMED_WAITING) ||
5366
(classLock2.getState() != Thread.State.BLOCKED &&
5467
classLock2.getState() != Thread.State.TIMED_WAITING) ||
5568
(objectLock.getState() != Thread.State.TIMED_WAITING) ||
56-
(primitiveLock.getState() != Thread.State.TIMED_WAITING)) {
69+
(primitiveLock.getState() != Thread.State.TIMED_WAITING) ||
70+
(objectWait.getState() != Thread.State.TIMED_WAITING)) {
5771
try {
5872
Thread.sleep(100);
5973
} catch (InterruptedException ex) {

test/hotspot/jtreg/serviceability/sa/TestClhsdbJstackLock.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -31,6 +31,7 @@
3131

3232
/**
3333
* @test
34+
* @bug 8185796 8335743
3435
* @requires vm.hasSA
3536
* @library /test/lib
3637
* @run main/othervm TestClhsdbJstackLock
@@ -57,7 +58,8 @@ public static void main (String... args) throws Exception {
5758
"^\\s+- locked <0x[0-9a-f]+> \\(a java\\.lang\\.Class for LingeredAppWithLock\\)$",
5859
"^\\s+- waiting to lock <0x[0-9a-f]+> \\(a java\\.lang\\.Class for LingeredAppWithLock\\)$",
5960
"^\\s+- locked <0x[0-9a-f]+> \\(a java\\.lang\\.Thread\\)$",
60-
"^\\s+- locked <0x[0-9a-f]+> \\(a java\\.lang\\.Class for int\\)$"));
61+
"^\\s+- locked <0x[0-9a-f]+> \\(a java\\.lang\\.Class for int\\)$",
62+
"^\\s+- waiting on <0x[0-9a-f]+> \\(a java\\.lang\\.Object\\)$"));
6163
unExpStrMap.put("jstack", List.of(
6264
"missing reason for "));
6365
test.run(app.getPid(), cmds, expStrMap, unExpStrMap);

test/hotspot/jtreg/serviceability/sa/TestJhsdbJstackLock.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -29,6 +29,7 @@
2929

3030
/**
3131
* @test
32+
* @bug 8185796 8335743
3233
* @requires vm.hasSA
3334
* @library /test/lib
3435
* @run driver TestJhsdbJstackLock
@@ -64,6 +65,7 @@ public static void main (String... args) throws Exception {
6465
out.shouldMatch("^\\s+- waiting to lock <0x[0-9a-f]+> \\(a java\\.lang\\.Class for LingeredAppWithLock\\)$");
6566
out.shouldMatch("^\\s+- locked <0x[0-9a-f]+> \\(a java\\.lang\\.Thread\\)$");
6667
out.shouldMatch("^\\s+- locked <0x[0-9a-f]+> \\(a java\\.lang\\.Class for int\\)$");
68+
out.shouldMatch("^\\s+- waiting on <0x[0-9a-f]+> \\(a java\\.lang\\.Object\\)$");
6769

6870
out.stderrShouldBeEmptyIgnoreDeprecatedWarnings();
6971

0 commit comments

Comments
 (0)