test/serviceability/sa/ClhsdbJstackXcompStress.java

Mon, 23 Sep 2019 20:26:18 +0200

author
sgehwolf
date
Mon, 23 Sep 2019 20:26:18 +0200
changeset 9919
e8a0af9fc1cb
permissions
-rw-r--r--

8196969: JTreg Failure: serviceability/sa/ClhsdbJstack.java causes NPE
Summary: Account for serialized null scopes in NMethod
Reviewed-by: aph, never, andrew

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

mercurial