Make StopRecur test hardened against move-exception

In some circumstances a StopThread call can occur just before a
move-exception instruction. In this case the stopThread exception can
be cleared unintentionally.

Test: stress --cpu 60
Test: ./test/run-test --host --gcstress 1934
Bug: 67576489
Change-Id: Ia06baedf64ff41cc7be78750d4dd4543b8ff50d2
diff --git a/test/1934-jvmti-signal-thread/info.txt b/test/1934-jvmti-signal-thread/info.txt
index c8c9189..1c58674 100644
--- a/test/1934-jvmti-signal-thread/info.txt
+++ b/test/1934-jvmti-signal-thread/info.txt
@@ -1,3 +1,3 @@
 Tests basic functions in the jvmti plugin.
 
-Tests that the GetBytecodes function works as expected.
+Tests that the StopThread and InterruptThread functions work as expected.
diff --git a/test/1934-jvmti-signal-thread/src/art/Test1934.java b/test/1934-jvmti-signal-thread/src/art/Test1934.java
index 552570a..3e97b20 100644
--- a/test/1934-jvmti-signal-thread/src/art/Test1934.java
+++ b/test/1934-jvmti-signal-thread/src/art/Test1934.java
@@ -195,8 +195,18 @@
     target.start();
     sem.acquire();
     System.out.println("stopping other thread recurring");
-    Threads.stopThread(target, new Error("AWESOME!"));
-    target.join();
+    do {
+      // Due to the fact that dex has a specific instruction to get the current exception it is
+      // possible for the 'stop-thread' to be unintentionally caught. We just retry in this case.
+      try {
+        Threads.stopThread(target, new Error("AWESOME!"));
+      } catch (Exception e) {
+        // If we just missed the thread dying we would get a JVMTI_ERROR_THREAD_NOT_ALIVE so we
+        // catch that here.
+      }
+      // Wait for 1 second.
+      target.join(1000);
+    } while (target.isAlive());
     System.out.println("Other thread Stopped by: " + out_err[0]);
     if (PRINT_STACK_TRACE && out_err[0] != null) {
       out_err[0].printStackTrace();