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