Skip to content

Commit

Permalink
8244679: JVM/TI GetCurrentContendedMonitor/contmon001 failed due to "…
Browse files Browse the repository at this point in the history
…(IsSameObject#3) unexpected monitor object: 0x000000562336DBA8"

Backport-of: c5fe2c1
  • Loading branch information
GoeLin committed Jan 25, 2024
1 parent 6e850f3 commit 3f42f4c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
Expand Up @@ -23,7 +23,6 @@

package nsk.jvmti.GetCurrentContendedMonitor;

import nsk.share.Wicket;
import java.io.PrintStream;

public class contmon001 {
Expand All @@ -42,8 +41,8 @@ public class contmon001 {
}
}

public static Wicket startingBarrier;
public static Wicket waitingBarrier;
public static volatile boolean startingBarrier = true;
public static volatile boolean waitingBarrier = true;
static Object lockFld = new Object();

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

public static void doSleep() {
try {
Thread.sleep(10);
} catch (Exception e) {
throw new Error("Unexpected " + e);
}
}

public static int run(String argv[], PrintStream ref) {
out = ref;
for (int i = 0; i < argv.length; i++) {
Expand All @@ -75,13 +82,13 @@ public static int run(String argv[], PrintStream ref) {
out.println("Check #1 done");

contmon001a thr = new contmon001a();
startingBarrier = new Wicket();
waitingBarrier = new Wicket();

thr.start();
if (DEBUG_MODE)
out.println("\nWaiting for auxiliary thread ...");
startingBarrier.waitFor();
while (startingBarrier) {
doSleep();
}
if (DEBUG_MODE)
out.println("Auxiliary thread is ready");

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

thr.letItGo();

waitingBarrier.waitFor();
while (waitingBarrier) {
doSleep();
}
synchronized (lockFld) {
if (DEBUG_MODE)
out.println("\nMain thread entered lockFld's monitor"
Expand Down Expand Up @@ -138,7 +147,7 @@ public void run() {

if (contmon001.DEBUG_MODE)
contmon001.out.println("notifying main thread");
contmon001.startingBarrier.unlock();
contmon001.startingBarrier = false;

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

synchronized (contmon001.lockFld) {
contmon001.waitingBarrier.unlock();
contmon001.waitingBarrier = false;
if (contmon001.DEBUG_MODE)
contmon001.out.println("\nthread entered lockFld's monitor"
+ "\n\tand releasing it through the lockFld.wait() call");
Expand Down
Expand Up @@ -23,7 +23,6 @@

package nsk.jvmti.GetCurrentContendedMonitor;

import nsk.share.Wicket;
import java.io.PrintStream;

public class contmon002 {
Expand All @@ -42,21 +41,30 @@ public class contmon002 {
}
}

public static Wicket startingBarrier;
public static boolean startingBarrier = true;

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

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

public static void doSleep() {
try {
Thread.sleep(10);
} catch (Exception e) {
throw new Error("Unexpected " + e);
}
}

public static int run(String argv[], PrintStream ref) {
checkMon(1, Thread.currentThread());

contmon002a thr = new contmon002a();
startingBarrier = new Wicket();
thr.start();
startingBarrier.waitFor();
while (startingBarrier) {
doSleep();
}
checkMon(2, thr);
thr.letItGo();
try {
Expand All @@ -73,7 +81,7 @@ class contmon002a extends Thread {
private volatile boolean flag = true;

private synchronized void meth() {
contmon002.startingBarrier.unlock();
contmon002.startingBarrier = false;
int i = 0;
int n = 1000;
while (flag) {
Expand Down

1 comment on commit 3f42f4c

@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.