|
1 /* |
|
2 * Copyright (c) 2019, Google Inc. All rights reserved. |
|
3 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
|
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
5 * |
|
6 * This code is free software; you can redistribute it and/or modify it |
|
7 * under the terms of the GNU General Public License version 2 only, as |
|
8 * published by the Free Software Foundation. |
|
9 * |
|
10 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 * version 2 for more details (a copy is included in the LICENSE file that |
|
14 * accompanied this code). |
|
15 * |
|
16 * You should have received a copy of the GNU General Public License version |
|
17 * 2 along with this work; if not, write to the Free Software Foundation, |
|
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 * |
|
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
21 * or visit www.oracle.com if you need additional information or have any |
|
22 * questions. |
|
23 */ |
|
24 import java.lang.ProcessBuilder; |
|
25 import java.io.BufferedReader; |
|
26 import java.io.IOException; |
|
27 import java.io.InputStream; |
|
28 import java.io.InputStreamReader; |
|
29 |
|
30 public class T { |
|
31 public static boolean run() { |
|
32 boolean res = false; |
|
33 String echoInput = "foo"; |
|
34 ProcessBuilder pb = new ProcessBuilder("echo", echoInput); |
|
35 |
|
36 try { |
|
37 // Starting a ProcessBuilder causes the process reaper thread to be |
|
38 // created. The process reaper thread has small stack size. In JDK |
|
39 // 13, the REAPER_DEFAULT_STACKSIZE is 128K. With JDK 8, it is 32K. |
|
40 // Using the process reaper thread can demonstrate the TLS problem. |
|
41 // The reaper thread can fail with StackOverflow in one of the |
|
42 // failure mode with certain TLS sizes. In another observed |
|
43 // failure mode the VM fails to create a thread with error message |
|
44 // 'Failed to start thread - pthread_create failed'. |
|
45 System.out.println("Starting a new process ..."); |
|
46 Process process = pb.start(); |
|
47 process.waitFor(); |
|
48 String echoOutput = output(process.getInputStream()); |
|
49 System.out.println("Echo Output: " + echoOutput); |
|
50 if (echoOutput.equals(echoInput)) { |
|
51 res = true; |
|
52 } else { |
|
53 // 'res' is false, fail |
|
54 System.out.println("Unexpected Echo output: " + echoOutput + |
|
55 ", expects: " + echoInput); |
|
56 } |
|
57 } catch (Exception e) { |
|
58 System.out.println(e.toString()); |
|
59 e.printStackTrace(); |
|
60 } |
|
61 return res; |
|
62 } |
|
63 |
|
64 private static String output(InputStream inputStream) throws IOException { |
|
65 String s = ""; |
|
66 try (BufferedReader br = |
|
67 new BufferedReader(new InputStreamReader(inputStream))) { |
|
68 s = br.readLine(); |
|
69 } |
|
70 return s; |
|
71 } |
|
72 } |
|
73 |