< prev index next >

test/jdk/java/lang/ProcessBuilder/Basic.java

Print this page
*** 29,29 ***
--- 29,34 ---
   *      4947220 7018606 7034570 4244896 5049299 8003488 8054494 8058464
   *      8067796 8224905 8263729 8265173 8272600 8231297
   * @key intermittent
   * @summary Basic tests for Process and Environment Variable code
   * @modules java.base/java.lang:open
+  *          java.base/java.io:open
+  *          java.base/jdk.internal.misc
   * @library /test/lib
   * @run main/othervm/native/timeout=300 -Djava.security.manager=allow Basic
   * @run main/othervm/native/timeout=300 -Djava.security.manager=allow -Djdk.lang.Process.launchMechanism=fork Basic
   * @author Martin Buchholz
   */
  
  /*
   * @test
   * @modules java.base/java.lang:open
+  *          java.base/java.io:open
+  *          java.base/jdk.internal.misc
   * @requires (os.family == "linux")
   * @library /test/lib
   * @run main/othervm/timeout=300 -Djava.security.manager=allow -Djdk.lang.Process.launchMechanism=posix_spawn Basic
   */
  
  import java.lang.ProcessBuilder.Redirect;
  import java.lang.ProcessHandle;
  import static java.lang.ProcessBuilder.Redirect.*;
  
  import java.io.*;
+ import java.lang.reflect.Field;
  import java.nio.file.Files;
  import java.nio.file.Path;
  import java.nio.file.Paths;
  import java.nio.file.StandardCopyOption;
  import java.util.*;

*** 2187,11 ***
  
                  if (s instanceof BufferedInputStream) {
                      // 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();
                  thread.join();
--- 2192,11 ---
  
                  if (s instanceof BufferedInputStream) {
                      // Wait until after the s.read occurs in "thread" by
                      // checking when the input stream monitor is acquired
                      // (BufferedInputStream.read is synchronized)
!                     while (!isLocked((BufferedInputStream) s, 10)) {
                          Thread.sleep(100);
                      }
                  }
                  p.destroy();
                  thread.join();

*** 2841,17 ***
              try { f.f(); fail("Expected " + k.getName() + " not thrown"); }
              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);
--- 2846,28 ---
              try { f.f(); fail("Expected " + k.getName() + " not thrown"); }
              catch (Throwable t) {
                  if (k.isAssignableFrom(t.getClass())) pass();
                  else unexpected(t);}}
  
!     static boolean isLocked(BufferedInputStream bis, long millis) throws Exception {
+         Field lockField = BufferedInputStream.class.getDeclaredField("lock");
+         lockField.setAccessible(true);
+         var lock = (jdk.internal.misc.InternalLock) lockField.get(bis);
+         if (lock != null) {
+             if (lock.tryLock()) {
+                 lock.unlock();
+                 return false;
+             } else {
+                 return true;
+             }
+         }
          return new Thread() {
              volatile boolean unlocked;
  
              @Override
              public void run() {
!                 synchronized (bis) { unlocked = true; }
              }
  
              boolean isLocked() throws InterruptedException {
                  start();
                  join(millis);
< prev index next >