Path: blob/master/test/hotspot/jtreg/compiler/blackhole/BlackholeExperimentalUnlockTest.java
64474 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* @requires vm.compMode != "Xint"28* @run driver compiler.blackhole.BlackholeExperimentalUnlockTest29*/3031package compiler.blackhole;3233import java.io.IOException;34import java.util.List;35import java.util.Arrays;36import java.util.ArrayList;37import jdk.test.lib.Platform;38import jdk.test.lib.process.ProcessTools;39import jdk.test.lib.process.OutputAnalyzer;4041public class BlackholeExperimentalUnlockTest {4243private static final int CYCLES = 100_000;44private static final int TRIES = 10;4546public static void main(String[] args) throws IOException {47if (args.length == 0) {48driver();49} else {50runner();51}52}5354private static final String MSG = "Blackhole compile option is experimental and must be enabled via -XX:+UnlockExperimentalVMOptions";5556private static List<String> cmdline(String[] args) {57List<String> r = new ArrayList();58r.add("-Xmx128m");59r.add("-Xbatch");60r.addAll(Arrays.asList(args));61r.add("compiler.blackhole.BlackholeExperimentalUnlockTest");62r.add("run");63return r;64}6566public static void shouldFail(String... args) throws IOException {67ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(cmdline(args));68OutputAnalyzer output = new OutputAnalyzer(pb.start());69output.shouldHaveExitValue(0);70output.shouldContain(MSG);71}7273public static void shouldPass(String... args) throws IOException {74ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(cmdline(args));75OutputAnalyzer output = new OutputAnalyzer(pb.start());76output.shouldHaveExitValue(0);77output.shouldNotContain(MSG);78}7980public static void driver() throws IOException {81// Option is disabled by default, should fail:82shouldFail(83"-XX:CompileCommand=quiet",84"-XX:CompileCommand=option,compiler/blackhole/BlackholeTarget.bh_*,Blackhole"85);86shouldFail(87"-XX:CompileCommand=quiet",88"-XX:CompileCommand=blackhole,compiler/blackhole/BlackholeTarget.bh_*"89);9091// Option should be enabled by UnlockExperimentalVMOptions92shouldPass(93"-XX:+UnlockExperimentalVMOptions",94"-XX:CompileCommand=quiet",95"-XX:CompileCommand=option,compiler/blackhole/BlackholeTarget.bh_*,Blackhole"96);97shouldPass(98"-XX:+UnlockExperimentalVMOptions",99"-XX:CompileCommand=quiet",100"-XX:CompileCommand=blackhole,compiler/blackhole/BlackholeTarget.bh_*"101);102103// Should be able to shun the warning104shouldPass(105"-XX:-PrintWarnings",106"-XX:CompileCommand=quiet",107"-XX:CompileCommand=option,compiler/blackhole/BlackholeTarget.bh_*,Blackhole"108);109shouldPass(110"-XX:-PrintWarnings",111"-XX:CompileCommand=quiet",112"-XX:CompileCommand=blackhole,compiler/blackhole/BlackholeTarget.bh_*"113);114}115116public static void runner() {117for (int t = 0; t < TRIES; t++) {118run();119}120}121122public static void run() {123for (int c = 0; c < CYCLES; c++) {124BlackholeTarget.bh_s_int_1(c);125}126}127128}129130131