Merge
authorjwilhelm
Thu, 22 Jan 2015 12:26:25 +0100
changeset 28674 9c49f00a2b58
parent 28673 4dbf48487f1f (current diff)
parent 28672 9a2e5d103695 (diff)
child 28676 3235e4827e1a
Merge
--- a/jdk/src/java.base/share/classes/sun/misc/Unsafe.java	Tue Jan 20 13:29:26 2015 -0800
+++ b/jdk/src/java.base/share/classes/sun/misc/Unsafe.java	Thu Jan 22 12:26:25 2015 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -845,22 +845,6 @@
     public native Object allocateInstance(Class<?> cls)
         throws InstantiationException;
 
-    /** Lock the object.  It must get unlocked via {@link #monitorExit}. */
-    public native void monitorEnter(Object o);
-
-    /**
-     * Unlock the object.  It must have been locked via {@link
-     * #monitorEnter}.
-     */
-    public native void monitorExit(Object o);
-
-    /**
-     * Tries to lock the object.  Returns true or false to indicate
-     * whether the lock succeeded.  If it did, the object must be
-     * unlocked via {@link #monitorExit}.
-     */
-    public native boolean tryMonitorEnter(Object o);
-
     /** Throw the exception without telling the verifier. */
     public native void throwException(Throwable ee);
 
--- a/jdk/test/java/lang/ProcessBuilder/Basic.java	Tue Jan 20 13:29:26 2015 -0800
+++ b/jdk/test/java/lang/ProcessBuilder/Basic.java	Thu Jan 22 12:26:25 2015 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,7 +26,7 @@
  * @bug 4199068 4738465 4937983 4930681 4926230 4931433 4932663 4986689
  *      5026830 5023243 5070673 4052517 4811767 6192449 6397034 6413313
  *      6464154 6523983 6206031 4960438 6631352 6631966 6850957 6850958
- *      4947220 7018606 7034570 4244896 5049299 8003488
+ *      4947220 7018606 7034570 4244896 5049299 8003488 8054494
  * @summary Basic tests for Process and Environment Variable code
  * @run main/othervm/timeout=300 Basic
  * @run main/othervm/timeout=300 -Djdk.lang.Process.launchMechanism=fork Basic
@@ -2059,13 +2059,11 @@
                         Thread.yield();
                     }
                 } else if (s instanceof BufferedInputStream) {
-                    Field f = Unsafe.class.getDeclaredField("theUnsafe");
-                    f.setAccessible(true);
-                    Unsafe unsafe = (Unsafe)f.get(null);
-
-                    while (unsafe.tryMonitorEnter(s)) {
-                        unsafe.monitorExit(s);
-                        Thread.sleep(1);
+                    // Wait until after the s.read occurs in "thread" by
+                    // checking when the input stream monitor is acquired
+                    // (BufferedInputStream.read is synchronized)
+                    while (!isLocked(s, 10)) {
+                        Thread.sleep(100);
                     }
                 }
                 p.destroy();
@@ -2565,4 +2563,21 @@
             catch (Throwable t) {
                 if (k.isAssignableFrom(t.getClass())) pass();
                 else unexpected(t);}}
+
+    static boolean isLocked(final Object monitor, final long millis) throws InterruptedException {
+        return new Thread() {
+            volatile boolean unlocked;
+
+            @Override
+            public void run() {
+                synchronized (monitor) { unlocked = true; }
+            }
+
+            boolean isLocked() throws InterruptedException {
+                start();
+                join(millis);
+                return !unlocked;
+            }
+        }.isLocked();
+    }
 }