|
1 /* |
|
2 * Copyright (c) 2019, Red Hat Inc. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 |
|
24 import java.util.ArrayList; |
|
25 import java.util.Arrays; |
|
26 import java.util.List; |
|
27 import java.util.regex.Matcher; |
|
28 import java.util.regex.Pattern; |
|
29 import java.util.stream.Collectors; |
|
30 |
|
31 import jdk.test.lib.JDKToolLauncher; |
|
32 import jdk.test.lib.Utils; |
|
33 import jdk.test.lib.apps.LingeredApp; |
|
34 import jdk.test.lib.process.OutputAnalyzer; |
|
35 |
|
36 /** |
|
37 * @bug 8196969 |
|
38 * @requires vm.hasSAandCanAttach |
|
39 * @library /test/lib |
|
40 * @run main/othervm ClhsdbJstackXcompStress |
|
41 */ |
|
42 public class ClhsdbJstackXcompStress { |
|
43 |
|
44 private static final int MAX_ITERATIONS = 20; |
|
45 private static final boolean DEBUG = false; |
|
46 |
|
47 private static boolean isMatchCompiledFrame(List<String> output) { |
|
48 List<String> filtered = output.stream().filter( s -> s.contains("Compiled frame")) |
|
49 .collect(Collectors.toList()); |
|
50 System.out.println("DEBUG: " + filtered); |
|
51 return !filtered.isEmpty() && |
|
52 filtered.stream().anyMatch( s -> s.contains("LingeredAppWithRecComputation") ); |
|
53 } |
|
54 |
|
55 private static void runJstackInLoop(LingeredApp app) throws Exception { |
|
56 boolean anyMatchedCompiledFrame = false; |
|
57 for (int i = 0; i < MAX_ITERATIONS; i++) { |
|
58 JDKToolLauncher launcher = JDKToolLauncher |
|
59 .createUsingTestJDK("jhsdb"); |
|
60 launcher.addToolArg("jstack"); |
|
61 launcher.addToolArg("--pid"); |
|
62 launcher.addToolArg(Long.toString(app.getPid())); |
|
63 |
|
64 ProcessBuilder pb = new ProcessBuilder(); |
|
65 pb.command(launcher.getCommand()); |
|
66 Process jhsdb = pb.start(); |
|
67 OutputAnalyzer out = new OutputAnalyzer(jhsdb); |
|
68 |
|
69 jhsdb.waitFor(); |
|
70 |
|
71 if (DEBUG) { |
|
72 System.out.println(out.getStdout()); |
|
73 System.err.println(out.getStderr()); |
|
74 } |
|
75 |
|
76 out.stderrShouldBeEmpty(); // NPE's are reported on the err stream |
|
77 out.stdoutShouldNotContain("Error occurred during stack walking:"); |
|
78 out.stdoutShouldContain(LingeredAppWithRecComputation.THREAD_NAME); |
|
79 List<String> stdoutList = Arrays.asList(out.getStdout().split("\\R")); |
|
80 anyMatchedCompiledFrame = anyMatchedCompiledFrame || isMatchCompiledFrame(stdoutList); |
|
81 } |
|
82 if (!anyMatchedCompiledFrame) { |
|
83 throw new RuntimeException("Expected jstack output to contain 'Compiled frame'"); |
|
84 } |
|
85 System.out.println("DEBUG: jhsdb jstack did not throw NPE, as expected."); |
|
86 } |
|
87 |
|
88 public static void main(String... args) throws Exception { |
|
89 LingeredApp app = null; |
|
90 try { |
|
91 List<String> vmArgs = List.of("-Xcomp", |
|
92 "-XX:CompileCommand=dontinline,LingeredAppWithRecComputation.factorial", |
|
93 "-XX:CompileCommand=compileonly,LingeredAppWithRecComputation.testLoop", |
|
94 "-XX:CompileCommand=compileonly,LingeredAppWithRecComputation.factorial"); |
|
95 app = new LingeredAppWithRecComputation(); |
|
96 LingeredApp.startApp(vmArgs, app); |
|
97 System.out.println("Started LingeredAppWithRecComputation with pid " + app.getPid()); |
|
98 runJstackInLoop(app); |
|
99 System.out.println("Test Completed"); |
|
100 } catch (Throwable e) { |
|
101 e.printStackTrace(); |
|
102 throw e; |
|
103 } finally { |
|
104 LingeredApp.stopApp(app); |
|
105 } |
|
106 } |
|
107 } |