Merge "Make 597-deopt-invoke-stub more solid."
diff --git a/test/597-deopt-invoke-stub/src/Main.java b/test/597-deopt-invoke-stub/src/Main.java
index 0751783..8c6f069 100644
--- a/test/597-deopt-invoke-stub/src/Main.java
+++ b/test/597-deopt-invoke-stub/src/Main.java
@@ -16,8 +16,8 @@
 
 public class Main implements Runnable {
     static final int numberOfThreads = 2;
-    volatile static boolean sExitFlag = false;
-    volatile static boolean sEntered = false;
+    static boolean sExitFlag = false;
+    static boolean sEntered = false;
     int threadIndex;
 
     private static native void deoptimizeAll();
@@ -46,8 +46,17 @@
     private static int $noinline$bar() {
         // Should be entered via interpreter bridge.
         assertIsInterpreted();
-        sEntered = true;
-        while (!sExitFlag) {}
+        synchronized (Main.class) {
+            sEntered = true;
+            Main.class.notify();
+            while (!sExitFlag) {
+                try {
+                    Main.class.wait();
+                } catch (InterruptedException e) {
+                    throw new Error("Unexpected exception.");
+                }
+            }
+        }
         assertIsInterpreted();
         return 0x1234;
     }
@@ -62,11 +71,20 @@
 
     public void run() {
         if (threadIndex == 0) {
-            while (!sEntered) {
-              Thread.yield();
+            synchronized (Main.class) {
+                while (!sEntered) {
+                    try {
+                        Main.class.wait();
+                    } catch (InterruptedException e) {
+                        throw new Error("Unexpected exception.");
+                    }
+                }
             }
             deoptimizeAll();
-            sExitFlag = true;
+            synchronized (Main.class) {
+                sExitFlag = true;
+                Main.class.notify();
+            }
         } else {
             ensureJitCompiled(Main.class, "$noinline$foo");
             $noinline$foo();