Path: blob/master/test/hotspot/jtreg/compiler/debug/TestStressCM.java
41149 views
/*1* Copyright (c) 2020, 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.debug;2425import jdk.test.lib.process.OutputAnalyzer;26import jdk.test.lib.process.ProcessTools;27import jdk.test.lib.Asserts;2829/*30* @test31* @bug 825376532* @requires vm.debug == true & vm.compiler2.enabled33* @summary Tests that, when compiling with StressLCM or StressGCM, using the34* same seed yields the same code motion trace.35* @library /test/lib /36* @run driver compiler.debug.TestStressCM StressLCM37* @run driver compiler.debug.TestStressCM StressGCM38*/3940public class TestStressCM {4142static String cmTrace(String stressOpt, int stressSeed) throws Exception {43String className = TestStressCM.class.getName();44String[] procArgs = {45"-Xcomp", "-XX:-TieredCompilation", "-XX:-Inline",46"-XX:CompileOnly=" + className + "::sum",47"-XX:+TraceOptoPipelining", "-XX:+" + stressOpt,48"-XX:StressSeed=" + stressSeed, className, "10"};49ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(procArgs);50OutputAnalyzer out = new OutputAnalyzer(pb.start());51out.shouldHaveExitValue(0);52// Extract the trace of our method (the last one after those of all53// mandatory stubs such as _new_instance_Java, etc.).54String [] traces = out.getStdout().split("\\R");55int start = -1;56for (int i = traces.length - 1; i >= 0; i--) {57if (traces[i].contains("Start GlobalCodeMotion")) {58start = i;59break;60}61}62// We should have found the start of the trace.63Asserts.assertTrue(start >= 0,64"could not find the code motion trace");65String trace = "";66for (int i = start; i < traces.length; i++) {67trace += traces[i] + "\n";68}69return trace;70}7172static void sum(int n) {73int acc = 0;74for (int i = 0; i < n; i++) acc += i;75System.out.println(acc);76}7778public static void main(String[] args) throws Exception {79if (args[0].startsWith("Stress")) {80String stressOpt = args[0];81for (int s = 0; s < 10; s++) {82Asserts.assertEQ(cmTrace(stressOpt, s), cmTrace(stressOpt, s),83"got different code motion traces for the same seed " + s);84}85} else if (args.length > 0) {86sum(Integer.parseInt(args[0]));87}88}89}909192