Path: blob/master/test/hotspot/jtreg/compiler/blackhole/BlackholeExistingIntrinsicWarningTest.java
64475 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.BlackholeExistingIntrinsicWarningTest29*/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 BlackholeExistingIntrinsicWarningTest {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 =54"Blackhole compile option only works for methods that do not have intrinsic set: java.lang.Thread.onSpinWait()V, _onSpinWait";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.BlackholeExistingIntrinsicWarningTest");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// Should print the warning82shouldFail(83"-XX:+UnlockExperimentalVMOptions",84"-XX:CompileCommand=quiet",85"-XX:CompileCommand=blackhole,java/lang/Thread.onSpinWait"86);87shouldFail(88"-XX:+UnlockExperimentalVMOptions",89"-XX:CompileCommand=quiet",90"-XX:CompileCommand=option,java/lang/Thread.onSpinWait,Blackhole"91);9293// Should be able to shun the warning94shouldPass(95"-XX:-PrintWarnings",96"-XX:+UnlockExperimentalVMOptions",97"-XX:CompileCommand=quiet",98"-XX:CompileCommand=blackhole,java/lang/Thread.onSpinWait"99);100shouldPass(101"-XX:-PrintWarnings",102"-XX:+UnlockExperimentalVMOptions",103"-XX:CompileCommand=quiet",104"-XX:CompileCommand=option,java/lang/Thread.onSpinWait,Blackhole"105);106}107108public static void runner() {109for (int t = 0; t < TRIES; t++) {110run();111}112}113114public static void run() {115for (int c = 0; c < CYCLES; c++) {116Thread.onSpinWait();117}118}119120}121122123