summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMythri Alle <mythria@google.com>2024-02-20 13:48:59 +0000
committerMythri Alle <mythria@google.com>2024-02-22 15:08:01 +0000
commitff05d9d01cb458e145c4788ae8b979deb77c3421 (patch)
tree6cf80bb4f9fed6caba29225765970e5adf74f157
parentabb611dcc070b5aab2ace7a30c63b78de05df7ed (diff)
downloadapache-harmony-ff05d9d01cb458e145c4788ae8b979deb77c3421.tar.gz
Wait for helper thread to finish in MonitorContendedEntered test
In testMonitorContendedEnteredForClassMatch, we have main thread and a helper thread contending on the same monitor. We make sure that there is contention by waiting on the main thread till the helper thread is in blocked state before releasing the lock. Though it is possible that we exit since main thread finishes before the helper thread gets a lock. This CL makes the main thread wait for the helper thread to finish. Bug: 142039794 Test: org.apache.harmony.jpda.tests.jdwp.Events_MonitorContendedEnteredTest#testMonitorContendedEnteredForClassMatch Change-Id: I430afe5372c3fea53bfd7c53e4047c57565edfa8
-rw-r--r--jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnterAndEnteredDebuggee.java16
1 files changed, 15 insertions, 1 deletions
diff --git a/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnterAndEnteredDebuggee.java b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnterAndEnteredDebuggee.java
index de5b397..53708d4 100644
--- a/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnterAndEnteredDebuggee.java
+++ b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnterAndEnteredDebuggee.java
@@ -50,13 +50,27 @@ public class MonitorContendedEnterAndEnteredDebuggee extends SyncDebuggee {
Thread.yield();
logWriter.println("main thread: Waiting for second thread to attempt to lock a monitor");
}
-
+
// We think the monitor is contended.
synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
// Make sure we're good to finish.
synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
logWriter.println("--> main thread: finish test");
}
+
+ // Wait for the blocked thread to join. This makes sure we entered the synchronized section
+ // in the blocked thread and hence the MonitorContentedEntered message should be sent. If we
+ // don't wait here, there is a possibility we exit the process before the blocked thread
+ // gets a chance to enter the monitor lock.
+ boolean done = false;
+ while (!done) {
+ try {
+ thread.join();
+ done = true;
+ } catch(InterruptedException e) {
+ System.out.println("Thread interrupted when joining, giving another chance");
+ }
+ }
}
static class BlockedThread extends Thread {