jdk/test/java/lang/ProcessBuilder/SiblingIOEHandle.java
author robm
Fri, 18 Oct 2013 16:28:35 +0100
changeset 21294 545dfa5b947e
parent 19372 e404c834f1cd
permissions -rw-r--r--
8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds Reviewed-by: alanb Contributed-by: pavel.punegov@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19372
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
     1
/*
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
     4
 *
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
     8
 *
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    13
 * accompanied this code).
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    14
 *
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    18
 *
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    21
 * questions.
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    22
 */
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    23
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    24
/**
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    25
 * @test
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    26
 * @bug 6921885
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    27
 * @run main/othervm SiblingIOEHandle
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    28
 * @summary inherit IOE handles and MS CreateProcess limitations (kb315939)
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    29
 */
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    30
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    31
import java.io.BufferedReader;
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    32
import java.io.File;
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    33
import java.io.IOException;
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    34
import java.io.InputStreamReader;
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    35
import java.util.concurrent.BrokenBarrierException;
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    36
import java.util.concurrent.CyclicBarrier;
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    37
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    38
public class SiblingIOEHandle {
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    39
    private static enum APP {
21294
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
    40
        A, B, C;
19372
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    41
    }
21294
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
    42
19372
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    43
    private static File stopC = new File(".\\StopCs.txt");
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    44
    private static String SIGNAL = "B child reported.";
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    45
    private static String JAVA_EXE = System.getProperty("java.home")
21294
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
    46
            + File.separator + "bin"
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
    47
            + File.separator + "java";
19372
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    48
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    49
    private static String[] getCommandArray(String processName) {
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    50
        String[] cmdArray = {
21294
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
    51
                JAVA_EXE,
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
    52
                "-cp",
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
    53
                System.getProperty("java.class.path"),
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
    54
                SiblingIOEHandle.class.getName(),
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
    55
                processName
19372
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    56
        };
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    57
        return cmdArray;
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    58
    }
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    59
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    60
    public static void main(String[] args) {
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    61
        if (!System.getProperty("os.name").startsWith("Windows")) {
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    62
            return;
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    63
        }
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    64
21294
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
    65
        APP app = (args.length > 0) ? APP.valueOf(args[0]) : APP.A;
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
    66
        switch (app) {
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
    67
            case A:
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
    68
                performA(true);
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
    69
                performA(false);
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
    70
                break;
19372
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    71
            case B:
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    72
                performB();
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    73
                break;
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    74
            case C:
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    75
                performC();
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    76
                break;
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    77
        }
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    78
    }
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    79
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    80
    static boolean procClaunched = false;
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    81
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    82
    private static void waitAbit() {
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    83
        try {
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    84
            Thread.sleep(0);
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    85
        } catch (InterruptedException ex) {
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    86
            // that was long enough
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    87
        }
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    88
    }
21294
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
    89
19372
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    90
    private static boolean waitBarrier(CyclicBarrier barrier) {
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    91
        while (true) try {
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    92
            barrier.await();
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    93
            return true;
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    94
        } catch (InterruptedException ex) {
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    95
            continue;
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    96
        } catch (BrokenBarrierException ex) {
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    97
            ex.printStackTrace();
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    98
            return false;
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
    99
        }
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   100
    }
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   101
21294
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   102
    private static class ProcessC implements Runnable {
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   103
        private CyclicBarrier barrier;
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   104
        private Process processC;
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   105
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   106
        public ProcessC(CyclicBarrier barrier) {
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   107
            this.barrier = barrier;
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   108
        }
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   109
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   110
        @Override
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   111
        public void run() {
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   112
            try {
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   113
                if (waitBarrier(barrier)) {
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   114
                    waitAbit();
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   115
                    // Run process C next to B ASAP to make an attempt
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   116
                    // to capture the B-process IOE handles in C process.
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   117
                    ProcessBuilder builderC = new ProcessBuilder(
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   118
                            getCommandArray(APP.C.name()));
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   119
                    processC = builderC.start();
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   120
                    procClaunched = true;
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   121
                }
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   122
            } catch (IOException ex) {
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   123
                ex.printStackTrace();
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   124
            }
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   125
        }
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   126
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   127
        public void waitFor() throws InterruptedException {
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   128
            processC.waitFor();
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   129
        }
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   130
    }
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   131
19372
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   132
    private static void performA(boolean fileOut) {
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   133
        try {
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   134
            stopC.delete();
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   135
            ProcessBuilder builderB = new ProcessBuilder(
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   136
                    getCommandArray(APP.B.name()));
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   137
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   138
            File outB = null;
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   139
            if (fileOut) {
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   140
                outB = new File("outB.txt");
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   141
                builderB.redirectOutput(outB);
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   142
            }
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   143
            builderB.redirectErrorStream(true);
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   144
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   145
            final CyclicBarrier barrier = new CyclicBarrier(2);
21294
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   146
            //Create process C in a new thread
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   147
            ProcessC processC = new ProcessC(barrier);
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   148
            Thread procCRunner = new Thread(processC);
19372
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   149
            procCRunner.start();
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   150
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   151
            if (!waitBarrier(barrier)) {
21294
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   152
                throw new RuntimeException("Catastrophe in process A! Synchronization failed.");
19372
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   153
            }
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   154
            // Run process B first.
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   155
            Process processB = builderB.start();
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   156
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   157
            while (true) try {
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   158
                procCRunner.join();
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   159
                break;
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   160
            } catch (InterruptedException ex) {
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   161
                continue;
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   162
            }
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   163
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   164
            if (!procClaunched) {
21294
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   165
                throw new RuntimeException("Catastrophe in process A! C was not launched.");
19372
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   166
            }
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   167
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   168
            processB.getOutputStream().close();
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   169
            processB.getErrorStream().close();
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   170
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   171
            if (fileOut) {
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   172
                try {
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   173
                    processB.waitFor();
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   174
                } catch (InterruptedException ex) {
21294
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   175
                    throw new RuntimeException("Catastrophe in process B! B hung up.");
19372
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   176
                }
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   177
                System.err.println("Trying to delete [outB.txt].");
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   178
                if (!outB.delete()) {
21294
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   179
                    throw new RuntimeException("Greedy brother C deadlock! File share.");
19372
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   180
                }
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   181
                System.err.println("Succeeded in delete [outB.txt].");
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   182
            } else {
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   183
                System.err.println("Read stream start.");
21294
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   184
                boolean isSignalReceived = false;
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   185
                try (BufferedReader in = new BufferedReader(new InputStreamReader(
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   186
                        processB.getInputStream(), "utf-8"))) {
19372
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   187
                    String result;
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   188
                    while ((result = in.readLine()) != null) {
21294
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   189
                        if (SIGNAL.equals(result)) {
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   190
                            isSignalReceived = true;
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   191
                        } else {
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   192
                            throw new RuntimeException("Catastrophe in process B! Bad output.");
19372
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   193
                        }
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   194
                    }
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   195
                }
21294
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   196
                if (!isSignalReceived) {
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   197
                    throw new RuntimeException("Signal from B was not received");
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   198
                }
19372
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   199
                System.err.println("Read stream finished.");
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   200
            }
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   201
            // If JDK-6921885 is not fixed that point is unreachable.
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   202
            // Test timeout exception.
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   203
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   204
            // write signal file to stop C process.
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   205
            stopC.createNewFile();
21294
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   206
            processC.waitFor();
19372
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   207
        } catch (IOException ex) {
21294
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   208
            throw new RuntimeException("Catastrophe in process A!", ex);
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   209
        } catch (InterruptedException ex) {
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   210
            throw new RuntimeException("Process A was interrupted while waiting for C", ex);
19372
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   211
        }
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   212
    }
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   213
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   214
    private static void performB() {
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   215
        System.out.println(SIGNAL);
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   216
    }
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   217
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   218
    private static void performC() {
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   219
        // If JDK-7147084 is not fixed the loop is 5min long.
21294
545dfa5b947e 8024660: TEST_BUG: java/lang/ProcessBuilder/*IOHandle.java leaving hotspot.log open in fastdebug builds
robm
parents: 19372
diff changeset
   220
        for (int i = 0; i < 5 * 60; ++i) {
19372
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   221
            try {
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   222
                Thread.sleep(1000);
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   223
                // check for sucess
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   224
                if (stopC.exists())
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   225
                    break;
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   226
            } catch (InterruptedException ex) {
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   227
                // that is ok. Longer sleep - better effect.
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   228
            }
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   229
        }
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   230
    }
e404c834f1cd 7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever
uta
parents:
diff changeset
   231
}