Manually merge my AOSP update to the VM tests.

Original change: https://android-review.googlesource.com/32051

Bug: http://code.google.com/p/android/issues/detail?id=21599
Bug: http://code.google.com/p/android/issues/detail?id=21597
Change-Id: I31e440b66b720647afab54ca39fd6eb1bbb0cb60
diff --git a/test/050-sync-test/src/Main.java b/test/050-sync-test/src/Main.java
index 0de3159..ec6d732 100644
--- a/test/050-sync-test/src/Main.java
+++ b/test/050-sync-test/src/Main.java
@@ -37,8 +37,7 @@
         System.out.println("GOING");
         try {
             Thread.sleep(1000);
-        }
-        catch (InterruptedException ie) {
+        } catch (InterruptedException ie) {
             System.out.println("INTERRUPT!");
             ie.printStackTrace();
         }
@@ -52,23 +51,22 @@
         two = new CpuThread(2);
 
         one.start();
-        two.start();
 
         try {
             Thread.sleep(100);
-        }
-        catch (InterruptedException ie) {
+        } catch (InterruptedException ie) {
             System.out.println("INTERRUPT!");
             ie.printStackTrace();
         }
 
+        two.start();
+
         //System.out.println("main: off and running");
 
         try {
             one.join();
             two.join();
-        }
-        catch (InterruptedException ie) {
+        } catch (InterruptedException ie) {
             System.out.println("INTERRUPT!");
             ie.printStackTrace();
         }
@@ -102,34 +100,29 @@
         //System.out.print("thread running -- ");
         //System.out.println(Thread.currentThread().getName());
 
-        for (int i = 0; i < 10; i++) {
-            output(mNumber);
-        }
+        synchronized (mSyncable) {
+            for (int i = 0; i < 10; i++) {
+                output(mNumber);
+            }
 
-        System.out.print("Final result: ");
-        System.out.println(mCount);
+            System.out.print("Final result: ");
+            System.out.println(mCount);
+        }
     }
 
     void output(int num) {
-        /*
-         * Delete the next line; last "final result" should != 20.
-         */
-        synchronized (mSyncable)
-        {
-            int i, count;
+        int count = mCount;
 
-            count = mCount;
+        System.out.print("going: ");
+        System.out.println(num);
 
-            System.out.print("going: ");
-            System.out.println(num);
-
-            /* burn CPU; adjust end value so we exceed scheduler quantum */
-            for (int j = 0; j < 5000; j++)
-                ;
-
-            count++;
-            mCount = count;
+        /* burn CPU; adjust end value so we exceed scheduler quantum */
+        for (int j = 0; j < 5000; j++) {
+            ;
         }
+
+        count++;
+        mCount = count;
     }
 }
 
@@ -164,14 +157,12 @@
                 synchronized (mWaitOnMe) {
                     mWaitOnMe.wait(9000);
                 }
-            }
-            catch (InterruptedException ie) {
+            } catch (InterruptedException ie) {
                 // Expecting this; interrupted should be false.
                 System.out.println(Thread.currentThread().getName() +
                         " interrupted, flag=" + Thread.interrupted());
                 intr = true;
-            }
-            catch (Exception ex) {
+            } catch (Exception ex) {
                 ex.printStackTrace();
             }
 
@@ -180,8 +171,7 @@
         } else {
             try {
                 Thread.sleep(2000);
-            }
-            catch (InterruptedException ie) {
+            } catch (InterruptedException ie) {
                 System.out.println("PESKY INTERRUPTED?");
             }