Path: blob/master/test/hotspot/jtreg/compiler/blackhole/BlackholeExperimentalUnlockTest.java
41152 views
/*1* Copyright (c) 2021, 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*/2223/**24* @test25* @library /test/lib /26* @requires vm.flagless27* @run driver compiler.blackhole.BlackholeExperimentalUnlockTest28*/2930package compiler.blackhole;3132import java.io.IOException;33import java.util.List;34import java.util.Arrays;35import java.util.ArrayList;36import jdk.test.lib.Platform;37import jdk.test.lib.process.ProcessTools;38import jdk.test.lib.process.OutputAnalyzer;3940public class BlackholeExperimentalUnlockTest {4142private static final int CYCLES = 100_000;43private static final int TRIES = 10;4445public static void main(String[] args) throws IOException {46if (args.length == 0) {47driver();48} else {49runner();50}51}5253private static final String MSG = "Blackhole compile option is experimental and must be enabled via -XX:+UnlockExperimentalVMOptions";5455private static List<String> cmdline(String[] args) {56List<String> r = new ArrayList();57r.add("-Xmx128m");58r.add("-Xbatch");59r.addAll(Arrays.asList(args));60r.add("compiler.blackhole.BlackholeExperimentalUnlockTest");61r.add("run");62return r;63}6465public static void shouldFail(String... args) throws IOException {66ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(cmdline(args));67OutputAnalyzer output = new OutputAnalyzer(pb.start());68output.shouldHaveExitValue(0);69output.shouldContain(MSG);70}7172public static void shouldPass(String... args) throws IOException {73ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(cmdline(args));74OutputAnalyzer output = new OutputAnalyzer(pb.start());75output.shouldHaveExitValue(0);76output.shouldNotContain(MSG);77}7879public static void driver() throws IOException {80// Option is disabled by default, should fail:81shouldFail(82"-XX:CompileCommand=quiet",83"-XX:CompileCommand=option,compiler/blackhole/BlackholeTarget.bh_*,Blackhole"84);85shouldFail(86"-XX:CompileCommand=quiet",87"-XX:CompileCommand=blackhole,compiler/blackhole/BlackholeTarget.bh_*"88);8990// Option should be enabled by UnlockExperimentalVMOptions91shouldPass(92"-XX:+UnlockExperimentalVMOptions",93"-XX:CompileCommand=quiet",94"-XX:CompileCommand=option,compiler/blackhole/BlackholeTarget.bh_*,Blackhole"95);96shouldPass(97"-XX:+UnlockExperimentalVMOptions",98"-XX:CompileCommand=quiet",99"-XX:CompileCommand=blackhole,compiler/blackhole/BlackholeTarget.bh_*"100);101102// Should be able to shun the warning103shouldPass(104"-XX:-PrintWarnings",105"-XX:CompileCommand=quiet",106"-XX:CompileCommand=option,compiler/blackhole/BlackholeTarget.bh_*,Blackhole"107);108shouldPass(109"-XX:-PrintWarnings",110"-XX:CompileCommand=quiet",111"-XX:CompileCommand=blackhole,compiler/blackhole/BlackholeTarget.bh_*"112);113}114115public static void runner() {116for (int t = 0; t < TRIES; t++) {117run();118}119}120121public static void run() {122for (int c = 0; c < CYCLES; c++) {123BlackholeTarget.bh_s_int_1(c);124}125}126127}128129130