Path: blob/master/test/hotspot/jtreg/compiler/blackhole/BlackholeIntrinsicTest.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.BlackholeIntrinsicTest28*/2930package compiler.blackhole;3132import java.io.IOException;33import java.util.List;34import java.util.Arrays;35import java.util.ArrayList;36import java.util.LinkedHashMap;37import java.util.Map;3839import jdk.test.lib.Platform;40import jdk.test.lib.process.ProcessTools;41import jdk.test.lib.process.OutputAnalyzer;4243public class BlackholeIntrinsicTest {4445private static final Map<String, Runnable> TESTS;4647static {48TESTS = new LinkedHashMap<>();49TESTS.put("bh_s_boolean_0", BlackholeIntrinsicTest::test_boolean_0);50TESTS.put("bh_s_byte_0", BlackholeIntrinsicTest::test_byte_0);51TESTS.put("bh_s_char_0", BlackholeIntrinsicTest::test_char_0);52TESTS.put("bh_s_short_0", BlackholeIntrinsicTest::test_short_0);53TESTS.put("bh_s_int_0", BlackholeIntrinsicTest::test_int_0);54TESTS.put("bh_s_float_0", BlackholeIntrinsicTest::test_float_0);55TESTS.put("bh_s_long_0", BlackholeIntrinsicTest::test_long_0);56TESTS.put("bh_s_double_0", BlackholeIntrinsicTest::test_double_0);57TESTS.put("bh_s_Object_0", BlackholeIntrinsicTest::test_Object_0);5859TESTS.put("bh_s_boolean_1", BlackholeIntrinsicTest::test_boolean_1);60TESTS.put("bh_s_byte_1", BlackholeIntrinsicTest::test_byte_1);61TESTS.put("bh_s_char_1", BlackholeIntrinsicTest::test_char_1);62TESTS.put("bh_s_short_1", BlackholeIntrinsicTest::test_short_1);63TESTS.put("bh_s_int_1", BlackholeIntrinsicTest::test_int_1);64TESTS.put("bh_s_float_1", BlackholeIntrinsicTest::test_float_1);65TESTS.put("bh_s_long_1", BlackholeIntrinsicTest::test_long_1);66TESTS.put("bh_s_double_1", BlackholeIntrinsicTest::test_double_1);67TESTS.put("bh_s_Object_1", BlackholeIntrinsicTest::test_Object_1);6869TESTS.put("bh_s_boolean_2", BlackholeIntrinsicTest::test_boolean_2);70TESTS.put("bh_s_byte_2", BlackholeIntrinsicTest::test_byte_2);71TESTS.put("bh_s_char_2", BlackholeIntrinsicTest::test_char_2);72TESTS.put("bh_s_short_2", BlackholeIntrinsicTest::test_short_2);73TESTS.put("bh_s_int_2", BlackholeIntrinsicTest::test_int_2);74TESTS.put("bh_s_float_2", BlackholeIntrinsicTest::test_float_2);75TESTS.put("bh_s_long_2", BlackholeIntrinsicTest::test_long_2);76TESTS.put("bh_s_double_2", BlackholeIntrinsicTest::test_double_2);77TESTS.put("bh_s_Object_2", BlackholeIntrinsicTest::test_Object_2);78}7980private static final int CYCLES = 100_000;81private static final int TRIES = 10;8283public static void main(String[] args) throws IOException {84if (args.length == 0) {85driver();86} else {87test(args[0]);88}89}9091public static void driver() throws IOException {92for (String test : TESTS.keySet()) {93check(test, "-XX:TieredStopAtLevel=1");94check(test, "-XX:-TieredCompilation");95if (Platform.is64bit()) {96check(test, "-XX:-UseCompressedOops", "-XX:TieredStopAtLevel=1");97check(test, "-XX:-UseCompressedOops", "-XX:-TieredCompilation");98}99}100}101102private static void test(String test) {103Runnable r = TESTS.get(test);104if (r == null) {105throw new IllegalArgumentException("Cannot find test " + test);106}107for (int t = 0; t < TRIES; t++) {108r.run();109}110}111112public static void check(String test, String... args) throws IOException {113List<String> cmdline = new ArrayList();114cmdline.add("-Xmx128m");115cmdline.add("-Xbatch");116cmdline.add("-XX:+UnlockDiagnosticVMOptions");117cmdline.add("-XX:+AbortVMOnCompilationFailure");118cmdline.add("-XX:+PrintCompilation");119cmdline.add("-XX:+PrintInlining");120cmdline.add("-XX:+UnlockExperimentalVMOptions");121cmdline.add("-XX:CompileCommand=blackhole,compiler/blackhole/BlackholeTarget.bh_*");122cmdline.addAll(Arrays.asList(args));123cmdline.add("compiler.blackhole.BlackholeIntrinsicTest");124cmdline.add(test);125126ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(cmdline);127OutputAnalyzer output = new OutputAnalyzer(pb.start());128output.shouldHaveExitValue(0);129output.stderrShouldBeEmpty();130output.stdoutShouldMatch("compiler.blackhole.BlackholeTarget::" + test + ".*intrinsic.*");131}132133private static void test_boolean_0() {134for (int c = 0; c < CYCLES; c++) {135BlackholeTarget.bh_s_boolean_0();136}137}138139private static void test_byte_0() {140for (int c = 0; c < CYCLES; c++) {141BlackholeTarget.bh_s_byte_0();142}143}144145private static void test_char_0() {146for (int c = 0; c < CYCLES; c++) {147BlackholeTarget.bh_s_char_0();148}149}150151private static void test_short_0() {152for (int c = 0; c < CYCLES; c++) {153BlackholeTarget.bh_s_short_0();154}155}156157private static void test_int_0() {158for (int c = 0; c < CYCLES; c++) {159BlackholeTarget.bh_s_int_0();160}161}162163private static void test_float_0() {164for (int c = 0; c < CYCLES; c++) {165BlackholeTarget.bh_s_float_0();166}167}168169private static void test_long_0() {170for (int c = 0; c < CYCLES; c++) {171BlackholeTarget.bh_s_long_0();172}173}174175private static void test_double_0() {176for (int c = 0; c < CYCLES; c++) {177BlackholeTarget.bh_s_double_0();178}179}180181private static void test_Object_0() {182for (int c = 0; c < CYCLES; c++) {183BlackholeTarget.bh_s_Object_0();184}185}186187private static void test_boolean_1() {188for (int c = 0; c < CYCLES; c++) {189BlackholeTarget.bh_s_boolean_1((c & 0x1) == 0);190}191}192193private static void test_byte_1() {194for (int c = 0; c < CYCLES; c++) {195BlackholeTarget.bh_s_byte_1((byte)c);196}197}198199private static void test_char_1() {200for (int c = 0; c < CYCLES; c++) {201BlackholeTarget.bh_s_char_1((char)c);202}203}204205private static void test_short_1() {206for (int c = 0; c < CYCLES; c++) {207BlackholeTarget.bh_s_short_1((short)c);208}209}210211private static void test_int_1() {212for (int c = 0; c < CYCLES; c++) {213BlackholeTarget.bh_s_int_1(c);214}215}216217private static void test_float_1() {218for (int c = 0; c < CYCLES; c++) {219BlackholeTarget.bh_s_float_1(c);220}221}222223private static void test_long_1() {224for (int c = 0; c < CYCLES; c++) {225BlackholeTarget.bh_s_long_1(c);226}227}228229private static void test_double_1() {230for (int c = 0; c < CYCLES; c++) {231BlackholeTarget.bh_s_double_1(c);232}233}234235private static void test_Object_1() {236for (int c = 0; c < CYCLES; c++) {237Object o = new Object();238BlackholeTarget.bh_s_Object_1(o);239}240}241242private static void test_boolean_2() {243for (int c = 0; c < CYCLES; c++) {244BlackholeTarget.bh_s_boolean_2((c & 0x1) == 0, (c & 0x2) == 0);245}246}247248private static void test_byte_2() {249for (int c = 0; c < CYCLES; c++) {250BlackholeTarget.bh_s_byte_2((byte)c, (byte)(c + 1));251}252}253254private static void test_char_2() {255for (int c = 0; c < CYCLES; c++) {256BlackholeTarget.bh_s_char_2((char)c, (char)(c + 1));257}258}259260private static void test_short_2() {261for (int c = 0; c < CYCLES; c++) {262BlackholeTarget.bh_s_short_2((short)c, (short)(c + 1));263}264}265266private static void test_int_2() {267for (int c = 0; c < CYCLES; c++) {268BlackholeTarget.bh_s_int_2(c, c + 1);269}270}271272private static void test_float_2() {273for (int c = 0; c < CYCLES; c++) {274BlackholeTarget.bh_s_float_2(c, c + 1);275}276}277278private static void test_long_2() {279for (int c = 0; c < CYCLES; c++) {280BlackholeTarget.bh_s_long_2(c, c + 1);281}282}283284private static void test_double_2() {285for (int c = 0; c < CYCLES; c++) {286BlackholeTarget.bh_s_double_2(c, c + 1);287}288}289290private static void test_Object_2() {291for (int c = 0; c < CYCLES; c++) {292Object o1 = new Object();293Object o2 = new Object();294BlackholeTarget.bh_s_Object_2(o1, o2);295}296}297}298299300