1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/serviceability/sa/ClhsdbJstackXcompStress.java Mon Sep 23 20:26:18 2019 +0200 1.3 @@ -0,0 +1,107 @@ 1.4 +/* 1.5 + * Copyright (c) 2019, Red Hat Inc. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +import java.util.ArrayList; 1.28 +import java.util.Arrays; 1.29 +import java.util.List; 1.30 +import java.util.regex.Matcher; 1.31 +import java.util.regex.Pattern; 1.32 +import java.util.stream.Collectors; 1.33 + 1.34 +import jdk.test.lib.JDKToolLauncher; 1.35 +import jdk.test.lib.Utils; 1.36 +import jdk.test.lib.apps.LingeredApp; 1.37 +import jdk.test.lib.process.OutputAnalyzer; 1.38 + 1.39 +/** 1.40 + * @bug 8196969 1.41 + * @requires vm.hasSAandCanAttach 1.42 + * @library /test/lib 1.43 + * @run main/othervm ClhsdbJstackXcompStress 1.44 + */ 1.45 +public class ClhsdbJstackXcompStress { 1.46 + 1.47 + private static final int MAX_ITERATIONS = 20; 1.48 + private static final boolean DEBUG = false; 1.49 + 1.50 + private static boolean isMatchCompiledFrame(List<String> output) { 1.51 + List<String> filtered = output.stream().filter( s -> s.contains("Compiled frame")) 1.52 + .collect(Collectors.toList()); 1.53 + System.out.println("DEBUG: " + filtered); 1.54 + return !filtered.isEmpty() && 1.55 + filtered.stream().anyMatch( s -> s.contains("LingeredAppWithRecComputation") ); 1.56 + } 1.57 + 1.58 + private static void runJstackInLoop(LingeredApp app) throws Exception { 1.59 + boolean anyMatchedCompiledFrame = false; 1.60 + for (int i = 0; i < MAX_ITERATIONS; i++) { 1.61 + JDKToolLauncher launcher = JDKToolLauncher 1.62 + .createUsingTestJDK("jhsdb"); 1.63 + launcher.addToolArg("jstack"); 1.64 + launcher.addToolArg("--pid"); 1.65 + launcher.addToolArg(Long.toString(app.getPid())); 1.66 + 1.67 + ProcessBuilder pb = new ProcessBuilder(); 1.68 + pb.command(launcher.getCommand()); 1.69 + Process jhsdb = pb.start(); 1.70 + OutputAnalyzer out = new OutputAnalyzer(jhsdb); 1.71 + 1.72 + jhsdb.waitFor(); 1.73 + 1.74 + if (DEBUG) { 1.75 + System.out.println(out.getStdout()); 1.76 + System.err.println(out.getStderr()); 1.77 + } 1.78 + 1.79 + out.stderrShouldBeEmpty(); // NPE's are reported on the err stream 1.80 + out.stdoutShouldNotContain("Error occurred during stack walking:"); 1.81 + out.stdoutShouldContain(LingeredAppWithRecComputation.THREAD_NAME); 1.82 + List<String> stdoutList = Arrays.asList(out.getStdout().split("\\R")); 1.83 + anyMatchedCompiledFrame = anyMatchedCompiledFrame || isMatchCompiledFrame(stdoutList); 1.84 + } 1.85 + if (!anyMatchedCompiledFrame) { 1.86 + throw new RuntimeException("Expected jstack output to contain 'Compiled frame'"); 1.87 + } 1.88 + System.out.println("DEBUG: jhsdb jstack did not throw NPE, as expected."); 1.89 + } 1.90 + 1.91 + public static void main(String... args) throws Exception { 1.92 + LingeredApp app = null; 1.93 + try { 1.94 + List<String> vmArgs = List.of("-Xcomp", 1.95 + "-XX:CompileCommand=dontinline,LingeredAppWithRecComputation.factorial", 1.96 + "-XX:CompileCommand=compileonly,LingeredAppWithRecComputation.testLoop", 1.97 + "-XX:CompileCommand=compileonly,LingeredAppWithRecComputation.factorial"); 1.98 + app = new LingeredAppWithRecComputation(); 1.99 + LingeredApp.startApp(vmArgs, app); 1.100 + System.out.println("Started LingeredAppWithRecComputation with pid " + app.getPid()); 1.101 + runJstackInLoop(app); 1.102 + System.out.println("Test Completed"); 1.103 + } catch (Throwable e) { 1.104 + e.printStackTrace(); 1.105 + throw e; 1.106 + } finally { 1.107 + LingeredApp.stopApp(app); 1.108 + } 1.109 + } 1.110 +}