Path: blob/master/test/hotspot/jtreg/compiler/blackhole/BlackholeNonStaticWarningTest.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.BlackholeNonStaticWarningTest29*/3031package compiler.blackhole;3233import java.io.IOException;34import java.util.List;35import java.util.Arrays;36import java.util.ArrayList;37import jdk.test.lib.process.ProcessTools;38import jdk.test.lib.process.OutputAnalyzer;3940public class BlackholeNonStaticWarningTest {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 only works for static methods: compiler.blackhole.BlackholeTarget.bh_i_int_0()V";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.BlackholeNonStaticWarningTest");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// Should print the warning81shouldFail(82"-XX:+UnlockExperimentalVMOptions",83"-XX:CompileCommand=quiet",84"-XX:CompileCommand=blackhole,compiler/blackhole/BlackholeTarget.bh_*"85);86shouldFail(87"-XX:+UnlockExperimentalVMOptions",88"-XX:CompileCommand=quiet",89"-XX:CompileCommand=option,compiler/blackhole/BlackholeTarget.bh_*,Blackhole"90);9192// Should be able to shun the warning93shouldPass(94"-XX:-PrintWarnings",95"-XX:+UnlockExperimentalVMOptions",96"-XX:CompileCommand=quiet",97"-XX:CompileCommand=blackhole,compiler/blackhole/BlackholeTarget.bh_*"98);99shouldPass(100"-XX:-PrintWarnings",101"-XX:+UnlockExperimentalVMOptions",102"-XX:CompileCommand=quiet",103"-XX:CompileCommand=option,compiler/blackhole/BlackholeTarget.bh_*,Blackhole"104);105}106107public static void runner() {108for (int t = 0; t < TRIES; t++) {109run();110}111}112113public static void run() {114BlackholeTarget t = new BlackholeTarget();115for (int c = 0; c < CYCLES; c++) {116t.bh_i_int_0();117}118}119120}121122123