diff options
author | Alex Light <allight@google.com> | 2019-10-08 10:46:04 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-10-08 10:46:04 -0700 |
commit | 5cdead74fc14a0809de59574038acdfcb3ea5dd7 (patch) | |
tree | 366e4385ffeec2d7ec0db97c94ecb622c10c308c | |
parent | 3bc2ceaa0bf68163df07399cd7dfbbb8329ecfa9 (diff) | |
parent | 19eba4c437925e3106d5da73ffeaf425647e8ccb (diff) | |
download | apache-harmony-5cdead74fc14a0809de59574038acdfcb3ea5dd7.tar.gz |
Merge "Fix MonitorContendedEntered test." am: 91a2252422 am: 51b8314166 am: 2691c71170
am: 19eba4c437
Change-Id: I01a5725f26fc517ad0b0574ed0f2806f277a5a83
3 files changed, 47 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 9c237e8..de5b397 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 @@ -51,6 +51,10 @@ public class MonitorContendedEnterAndEnteredDebuggee extends SyncDebuggee { 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"); } } @@ -66,7 +70,6 @@ public class MonitorContendedEnterAndEnteredDebuggee extends SyncDebuggee { @Override public void run() { logWriter.println("--> BlockedThread: start to run"); - synchronized (lock) { this.getName().trim(); logWriter.println("--> BlockedThread: get lock"); diff --git a/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnterTest.java b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnterTest.java index 7f80e5b..5aa6491 100644 --- a/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnterTest.java +++ b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnterTest.java @@ -83,6 +83,12 @@ public class MonitorContendedEnterTest extends JDWPSyncTestCase { assertEquals("Invalid monitor class signature: ", monitorSignature , actualSignature); logWriter.println("==> CHECK: monitor class signature: " + actualSignature); + + // We don't actually need these in this test. They're used for the Entered test. + // Debuggee thinks the monitor is contended. + synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + // Wake up the blocking thread. Its job is done. + synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); } } diff --git a/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnteredTest.java b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnteredTest.java index fc0bf0f..b5d76fa 100644 --- a/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnteredTest.java +++ b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnteredTest.java @@ -20,9 +20,12 @@ package org.apache.harmony.jpda.tests.jdwp.Events; import org.apache.harmony.jpda.tests.framework.TestErrorException; import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket; +import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands; import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants; import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent; import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent.Event_MONITOR_CONTENDED_ENTERED; +import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket; +import org.apache.harmony.jpda.tests.framework.jdwp.Value; import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase; import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; @@ -49,6 +52,40 @@ public class MonitorContendedEnteredTest extends JDWPSyncTestCase { // Inform debuggee that the request has been set logWriter.println("==> Request has been set."); synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); + // Debuggee thinks the monitor is contended. + synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + + // Wait for the other thread to look asleep. + boolean hasWaiters; + long classID = getClassIDBySignature(getDebuggeeClassSignature()); + long cnt = 0; + String fieldName = "lock"; + long fld_id = checkField(classID, fieldName); + do { + CommandPacket getValuesCommand = new CommandPacket( + JDWPCommands.ReferenceTypeCommandSet.CommandSetID, + JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand); + getValuesCommand.setNextValueAsReferenceTypeID(classID); + getValuesCommand.setNextValueAsInt(1); + getValuesCommand.setNextValueAsFieldID(fld_id); + ReplyPacket getValuesReply = debuggeeWrapper.vmMirror.performCommand(getValuesCommand); + checkReplyPacket(getValuesReply, "ReferenceType::GetValues command"); + getValuesReply.getNextValueAsInt(); // num-replies + Value lkvalue = getValuesReply.getNextValueAsValue(); + long lk = lkvalue.getLongValue(); + CommandPacket monitorInfoCmd = new CommandPacket( + JDWPCommands.ObjectReferenceCommandSet.CommandSetID, + JDWPCommands.ObjectReferenceCommandSet.MonitorInfoCommand); + monitorInfoCmd.setNextValueAsObjectID(lk); + ReplyPacket monInfoReply = debuggeeWrapper.vmMirror.performCommand(monitorInfoCmd); + checkReplyPacket(monInfoReply, "ObjectReference::MonitorInfo command"); + monInfoReply.getNextValueAsThreadID(); // owner + monInfoReply.getNextValueAsInt(); // entryCount + hasWaiters = monInfoReply.getNextValueAsInt() != 0; + } while (!hasWaiters); + logWriter.println("==> Monitor has waiter."); + // Wake up the blocking thread. Its job is done. + synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); // Receive event of MONITOR_CONTENDED_ENTERED logWriter.println("==> Receive Event."); |