Path: blob/master/test/hotspot/jtreg/serviceability/sa/ClhsdbJstackXcompStress.java
41149 views
/*1* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.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 it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 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 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324import java.util.Arrays;25import java.util.List;26import java.util.stream.Collectors;2728import jdk.test.lib.JDKToolLauncher;29import jdk.test.lib.SA.SATestUtils;30import jdk.test.lib.Utils;31import jdk.test.lib.apps.LingeredApp;32import jdk.test.lib.process.OutputAnalyzer;3334/**35* @test36* @bug 819696937* @requires vm.hasSA38* @requires vm.opt.DeoptimizeALot != true39* @library /test/lib40* @run main/othervm ClhsdbJstackXcompStress41*/42public class ClhsdbJstackXcompStress {4344private static final int MAX_ITERATIONS = 20;45private static final boolean DEBUG = false;4647private static boolean isMatchCompiledFrame(List<String> output) {48List<String> filtered = output.stream().filter( s -> s.contains("Compiled frame"))49.collect(Collectors.toList());50System.out.println("DEBUG: " + filtered);51return !filtered.isEmpty() &&52filtered.stream().anyMatch( s -> s.contains("LingeredAppWithRecComputation") );53}5455private static void runJstackInLoop(LingeredApp app) throws Exception {56boolean anyMatchedCompiledFrame = false;57for (int i = 0; i < MAX_ITERATIONS; i++) {58JDKToolLauncher launcher = JDKToolLauncher59.createUsingTestJDK("jhsdb");60launcher.addVMArgs(Utils.getFilteredTestJavaOpts("-showversion", "-Xcomp"));61launcher.addToolArg("jstack");62launcher.addToolArg("--pid");63launcher.addToolArg(Long.toString(app.getPid()));6465ProcessBuilder pb = SATestUtils.createProcessBuilder(launcher);66Process jhsdb = pb.start();67OutputAnalyzer out = new OutputAnalyzer(jhsdb);6869jhsdb.waitFor();7071if (DEBUG) {72System.out.println(out.getStdout());73System.err.println(out.getStderr());74}7576out.stderrShouldBeEmptyIgnoreDeprecatedWarnings();77out.stdoutShouldNotContain("Error occurred during stack walking:");78out.stdoutShouldContain(LingeredAppWithRecComputation.THREAD_NAME);79List<String> stdoutList = Arrays.asList(out.getStdout().split("\\R"));80anyMatchedCompiledFrame = anyMatchedCompiledFrame || isMatchCompiledFrame(stdoutList);81}82if (!anyMatchedCompiledFrame) {83throw new RuntimeException("Expected jstack output to contain 'Compiled frame'");84}85System.out.println("DEBUG: jhsdb jstack did not throw NPE, as expected.");86}8788public static void main(String... args) throws Exception {89SATestUtils.skipIfCannotAttach(); // throws SkippedException if attach not expected to work.90LingeredApp app = null;91try {92app = new LingeredAppWithRecComputation();93LingeredApp.startApp(app,94"-Xcomp",95"-XX:CompileCommand=dontinline,LingeredAppWithRecComputation.factorial",96"-XX:CompileCommand=compileonly,LingeredAppWithRecComputation.testLoop",97"-XX:CompileCommand=compileonly,LingeredAppWithRecComputation.factorial");98System.out.println("Started LingeredAppWithRecComputation with pid " + app.getPid());99runJstackInLoop(app);100System.out.println("Test Completed");101} catch (Throwable e) {102e.printStackTrace();103throw e;104} finally {105LingeredApp.stopApp(app);106}107}108}109110111