Skip to content

Commit c5fe2c1

Browse files
committedNov 16, 2020
8244679: JVM/TI GetCurrentContendedMonitor/contmon001 failed due to "(IsSameObject#3) unexpected monitor object: 0x000000562336DBA8"
Reviewed-by: pchilanomate, dcubed, dholmes, sspitsyn
1 parent 8eeb36f commit c5fe2c1

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed
 

‎test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon001.java

+18-9
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
package nsk.jvmti.GetCurrentContendedMonitor;
2525

26-
import nsk.share.Wicket;
2726
import java.io.PrintStream;
2827

2928
public class contmon001 {
@@ -42,8 +41,8 @@ public class contmon001 {
4241
}
4342
}
4443

45-
public static Wicket startingBarrier;
46-
public static Wicket waitingBarrier;
44+
public static volatile boolean startingBarrier = true;
45+
public static volatile boolean waitingBarrier = true;
4746
static Object lockFld = new Object();
4847

4948
static boolean DEBUG_MODE = false;
@@ -55,6 +54,14 @@ public static void main(String[] args) {
5554
System.exit(run(args, System.out) + 95/*STATUS_TEMP*/);
5655
}
5756

57+
public static void doSleep() {
58+
try {
59+
Thread.sleep(10);
60+
} catch (Exception e) {
61+
throw new Error("Unexpected " + e);
62+
}
63+
}
64+
5865
public static int run(String argv[], PrintStream ref) {
5966
out = ref;
6067
for (int i = 0; i < argv.length; i++) {
@@ -75,13 +82,13 @@ public static int run(String argv[], PrintStream ref) {
7582
out.println("Check #1 done");
7683

7784
contmon001a thr = new contmon001a();
78-
startingBarrier = new Wicket();
79-
waitingBarrier = new Wicket();
8085

8186
thr.start();
8287
if (DEBUG_MODE)
8388
out.println("\nWaiting for auxiliary thread ...");
84-
startingBarrier.waitFor();
89+
while (startingBarrier) {
90+
doSleep();
91+
}
8592
if (DEBUG_MODE)
8693
out.println("Auxiliary thread is ready");
8794

@@ -93,7 +100,9 @@ public static int run(String argv[], PrintStream ref) {
93100

94101
thr.letItGo();
95102

96-
waitingBarrier.waitFor();
103+
while (waitingBarrier) {
104+
doSleep();
105+
}
97106
synchronized (lockFld) {
98107
if (DEBUG_MODE)
99108
out.println("\nMain thread entered lockFld's monitor"
@@ -138,7 +147,7 @@ public void run() {
138147

139148
if (contmon001.DEBUG_MODE)
140149
contmon001.out.println("notifying main thread");
141-
contmon001.startingBarrier.unlock();
150+
contmon001.startingBarrier = false;
142151

143152
if (contmon001.DEBUG_MODE)
144153
contmon001.out.println("thread is going to loop while <flag> is true ...");
@@ -158,7 +167,7 @@ public void run() {
158167
contmon001.out.println("looping is done: <flag> is false");
159168

160169
synchronized (contmon001.lockFld) {
161-
contmon001.waitingBarrier.unlock();
170+
contmon001.waitingBarrier = false;
162171
if (contmon001.DEBUG_MODE)
163172
contmon001.out.println("\nthread entered lockFld's monitor"
164173
+ "\n\tand releasing it through the lockFld.wait() call");

‎test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentContendedMonitor/contmon002.java

+13-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
package nsk.jvmti.GetCurrentContendedMonitor;
2525

26-
import nsk.share.Wicket;
2726
import java.io.PrintStream;
2827

2928
public class contmon002 {
@@ -42,21 +41,30 @@ public class contmon002 {
4241
}
4342
}
4443

45-
public static Wicket startingBarrier;
44+
public static boolean startingBarrier = true;
4645

4746
public static void main(String[] args) {
4847
args = nsk.share.jvmti.JVMTITest.commonInit(args);
4948

5049
System.exit(run(args, System.out) + 95/*STATUS_TEMP*/);
5150
}
5251

52+
public static void doSleep() {
53+
try {
54+
Thread.sleep(10);
55+
} catch (Exception e) {
56+
throw new Error("Unexpected " + e);
57+
}
58+
}
59+
5360
public static int run(String argv[], PrintStream ref) {
5461
checkMon(1, Thread.currentThread());
5562

5663
contmon002a thr = new contmon002a();
57-
startingBarrier = new Wicket();
5864
thr.start();
59-
startingBarrier.waitFor();
65+
while (startingBarrier) {
66+
doSleep();
67+
}
6068
checkMon(2, thr);
6169
thr.letItGo();
6270
try {
@@ -73,7 +81,7 @@ class contmon002a extends Thread {
7381
private volatile boolean flag = true;
7482

7583
private synchronized void meth() {
76-
contmon002.startingBarrier.unlock();
84+
contmon002.startingBarrier = false;
7785
int i = 0;
7886
int n = 1000;
7987
while (flag) {

0 commit comments

Comments
 (0)
Please sign in to comment.