Path: blob/master/test/hotspot/jtreg/compiler/blackhole/BlackholeExistingIntrinsicWarningTest.java
41149 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.BlackholeExistingIntrinsicWarningTest28*/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 BlackholeExistingIntrinsicWarningTest {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 =53"Blackhole compile option only works for methods that do not have intrinsic set: java.lang.Thread.onSpinWait()V, _onSpinWait";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.BlackholeExistingIntrinsicWarningTest");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,java/lang/Thread.onSpinWait"85);86shouldFail(87"-XX:+UnlockExperimentalVMOptions",88"-XX:CompileCommand=quiet",89"-XX:CompileCommand=option,java/lang/Thread.onSpinWait,Blackhole"90);9192// Should be able to shun the warning93shouldPass(94"-XX:-PrintWarnings",95"-XX:+UnlockExperimentalVMOptions",96"-XX:CompileCommand=quiet",97"-XX:CompileCommand=blackhole,java/lang/Thread.onSpinWait"98);99shouldPass(100"-XX:-PrintWarnings",101"-XX:+UnlockExperimentalVMOptions",102"-XX:CompileCommand=quiet",103"-XX:CompileCommand=option,java/lang/Thread.onSpinWait,Blackhole"104);105}106107public static void runner() {108for (int t = 0; t < TRIES; t++) {109run();110}111}112113public static void run() {114for (int c = 0; c < CYCLES; c++) {115Thread.onSpinWait();116}117}118119}120121122