Path: blob/master/test/hotspot/jtreg/compiler/ciReplay/SABase.java
41149 views
/*1* Copyright (c) 2016, 2021, Oracle and/or its affiliates. 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*/2223package compiler.ciReplay;2425import java.nio.file.Files;26import java.nio.file.Paths;27import java.io.BufferedReader;28import java.io.FileReader;29import java.io.IOException;30import java.io.File;31import java.io.FileInputStream;32import java.io.OutputStream;33import java.util.Arrays;34import jdk.test.lib.Platform;35import jdk.test.lib.Asserts;36import jdk.test.lib.JDKToolFinder;37import jdk.test.lib.process.OutputAnalyzer;38import jdk.test.lib.process.ProcessTools;3940public class SABase extends CiReplayBase {41private static final String REPLAY_FILE_COPY = "replay_vm.txt";4243public static void main(String args[]) throws Exception {44checkSetLimits();45SABase base = new SABase(args);46boolean c2 = base.runServer.orElseThrow(() -> new Error("runServer must be set"));47String[] extra = {};48if (Platform.isTieredSupported()) {49if (c2) {50// Replay produced on first compilation. We want that51// compilation delayed so profile data is produced.52extra = new String[] {"-XX:-TieredCompilation"};53} else {54extra = new String[] {"-XX:TieredStopAtLevel=1"};55}56}57base.runTest(/* needCoreDump = */ true, extra);58}5960public SABase(String[] args) {61super(args);62}6364@Override65public void testAction() {66try {67Files.move(Paths.get(REPLAY_FILE_NAME), Paths.get(REPLAY_FILE_COPY));68} catch (IOException ioe) {69throw new Error("Can't move files: " + ioe, ioe);70}71ProcessBuilder pb;72try {73pb = ProcessTools.createTestJvm("--add-modules", "jdk.hotspot.agent",74"--add-exports=jdk.hotspot.agent/sun.jvm.hotspot=ALL-UNNAMED",75"sun.jvm.hotspot.CLHSDB", JDKToolFinder.getTestJDKTool("java"),76TEST_CORE_FILE_NAME);77} catch (Exception e) {78throw new Error("Can't create process builder: " + e, e);79}80Process p;81try {82p = pb.start();83} catch (IOException ioe) {84throw new Error("Can't start child process: " + ioe, ioe);85}86OutputStream input = p.getOutputStream();87String str = "dumpreplaydata -a > " + REPLAY_FILE_NAME + "\nquit\n";88try {89input.write(str.getBytes());90input.flush();91} catch (IOException ioe) {92throw new Error("Problem writing process input: " + str, ioe);93}94try {95p.waitFor();96} catch (InterruptedException ie) {97throw new Error("Problem waitinig child process: " + ie, ie);98}99int exitValue = p.exitValue();100if (exitValue != 0) {101String output;102try {103output = new OutputAnalyzer(p).getOutput();104} catch (IOException ioe) {105throw new Error("Can't get failed CLHSDB process output: " + ioe, ioe);106}107throw new AssertionError("CLHSDB wasn't run successfully: " + output);108}109File replay = new File(REPLAY_FILE_NAME);110Asserts.assertTrue(replay.exists() && replay.isFile() && replay.length() > 0,111"Replay data wasn't generated by SA");112// other than comment lines, content of 2 files should be identical113try {114BufferedReader rep = new BufferedReader(new FileReader(replay));115BufferedReader repCopy = new BufferedReader(new FileReader(REPLAY_FILE_COPY));116boolean failure = false;117while (true) {118String l1;119while ((l1 = rep.readLine()) != null) {120if (!l1.startsWith("#")) {121break;122}123}124String l2;125while ((l2 = repCopy.readLine()) != null) {126if (!l2.startsWith("#")) {127break;128}129}130if (l1 == null || l2 == null) {131if (l1 != null || l2 != null) {132System.out.println("Warning: replay files are not equal");133System.out.println("1: " + l1);134System.out.println("2: " + l2);135failure = true;136}137break;138}139if (!l1.equals(l2)) {140System.out.println("Warning: replay files are not equal");141System.out.println("1: " + l1);142System.out.println("2: " + l2);143failure = true;144}145}146if (failure) {147throw new RuntimeException("Warning: replay files are not equal");148}149} catch (IOException ioe) {150throw new Error("Can't read replay files: " + ioe, ioe);151}152commonTests();153runVmTests();154}155156public static void checkSetLimits() {157if (!Platform.isWindows()) {158OutputAnalyzer oa;159try {160// first check if setting limit is possible161oa = ProcessTools.executeProcess("sh", "-c", RUN_SHELL_NO_LIMIT + "ulimit -c");162} catch (Throwable t) {163throw new Error("Can't set limits: " + t, t);164}165oa.shouldHaveExitValue(0);166167String out = oa.getOutput().trim(); // cut win/*nix newlines168if (!out.equals("unlimited") && !out.equals("-1")) {169throw new Error("Unable to set limits");170}171}172}173}174175176177