Path: blob/master/test/hotspot/jtreg/compiler/blackhole/BlackholeNonStaticWarningTest.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.BlackholeNonStaticWarningTest28*/2930package compiler.blackhole;3132import java.io.IOException;33import java.util.List;34import java.util.Arrays;35import java.util.ArrayList;36import jdk.test.lib.process.ProcessTools;37import jdk.test.lib.process.OutputAnalyzer;3839public class BlackholeNonStaticWarningTest {4041private static final int CYCLES = 100_000;42private static final int TRIES = 10;4344public static void main(String[] args) throws IOException {45if (args.length == 0) {46driver();47} else {48runner();49}50}5152private static final String MSG = "Blackhole compile option only works for static methods: compiler.blackhole.BlackholeTarget.bh_i_int_0()V";5354private static List<String> cmdline(String[] args) {55List<String> r = new ArrayList();56r.add("-Xmx128m");57r.add("-Xbatch");58r.addAll(Arrays.asList(args));59r.add("compiler.blackhole.BlackholeNonStaticWarningTest");60r.add("run");61return r;62}6364public static void shouldFail(String... args) throws IOException {65ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(cmdline(args));66OutputAnalyzer output = new OutputAnalyzer(pb.start());67output.shouldHaveExitValue(0);68output.shouldContain(MSG);69}7071public static void shouldPass(String... args) throws IOException {72ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(cmdline(args));73OutputAnalyzer output = new OutputAnalyzer(pb.start());74output.shouldHaveExitValue(0);75output.shouldNotContain(MSG);76}7778public static void driver() throws IOException {79// Should print the warning80shouldFail(81"-XX:+UnlockExperimentalVMOptions",82"-XX:CompileCommand=quiet",83"-XX:CompileCommand=blackhole,compiler/blackhole/BlackholeTarget.bh_*"84);85shouldFail(86"-XX:+UnlockExperimentalVMOptions",87"-XX:CompileCommand=quiet",88"-XX:CompileCommand=option,compiler/blackhole/BlackholeTarget.bh_*,Blackhole"89);9091// Should be able to shun the warning92shouldPass(93"-XX:-PrintWarnings",94"-XX:+UnlockExperimentalVMOptions",95"-XX:CompileCommand=quiet",96"-XX:CompileCommand=blackhole,compiler/blackhole/BlackholeTarget.bh_*"97);98shouldPass(99"-XX:-PrintWarnings",100"-XX:+UnlockExperimentalVMOptions",101"-XX:CompileCommand=quiet",102"-XX:CompileCommand=option,compiler/blackhole/BlackholeTarget.bh_*,Blackhole"103);104}105106public static void runner() {107for (int t = 0; t < TRIES; t++) {108run();109}110}111112public static void run() {113BlackholeTarget t = new BlackholeTarget();114for (int c = 0; c < CYCLES; c++) {115t.bh_i_int_0();116}117}118119}120121122