Path: blob/master/test/hotspot/jtreg/compiler/blackhole/BlackholeIntrinsicTest.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.BlackholeIntrinsicTest29*/3031package compiler.blackhole;3233import java.io.IOException;34import java.util.List;35import java.util.Arrays;36import java.util.ArrayList;37import java.util.LinkedHashMap;38import java.util.Map;3940import jdk.test.lib.Platform;41import jdk.test.lib.process.ProcessTools;42import jdk.test.lib.process.OutputAnalyzer;4344public class BlackholeIntrinsicTest {4546private static final Map<String, Runnable> TESTS;4748static {49TESTS = new LinkedHashMap<>();50TESTS.put("bh_s_boolean_0", BlackholeIntrinsicTest::test_boolean_0);51TESTS.put("bh_s_byte_0", BlackholeIntrinsicTest::test_byte_0);52TESTS.put("bh_s_char_0", BlackholeIntrinsicTest::test_char_0);53TESTS.put("bh_s_short_0", BlackholeIntrinsicTest::test_short_0);54TESTS.put("bh_s_int_0", BlackholeIntrinsicTest::test_int_0);55TESTS.put("bh_s_float_0", BlackholeIntrinsicTest::test_float_0);56TESTS.put("bh_s_long_0", BlackholeIntrinsicTest::test_long_0);57TESTS.put("bh_s_double_0", BlackholeIntrinsicTest::test_double_0);58TESTS.put("bh_s_Object_0", BlackholeIntrinsicTest::test_Object_0);5960TESTS.put("bh_s_boolean_1", BlackholeIntrinsicTest::test_boolean_1);61TESTS.put("bh_s_byte_1", BlackholeIntrinsicTest::test_byte_1);62TESTS.put("bh_s_char_1", BlackholeIntrinsicTest::test_char_1);63TESTS.put("bh_s_short_1", BlackholeIntrinsicTest::test_short_1);64TESTS.put("bh_s_int_1", BlackholeIntrinsicTest::test_int_1);65TESTS.put("bh_s_float_1", BlackholeIntrinsicTest::test_float_1);66TESTS.put("bh_s_long_1", BlackholeIntrinsicTest::test_long_1);67TESTS.put("bh_s_double_1", BlackholeIntrinsicTest::test_double_1);68TESTS.put("bh_s_Object_1", BlackholeIntrinsicTest::test_Object_1);6970TESTS.put("bh_s_boolean_2", BlackholeIntrinsicTest::test_boolean_2);71TESTS.put("bh_s_byte_2", BlackholeIntrinsicTest::test_byte_2);72TESTS.put("bh_s_char_2", BlackholeIntrinsicTest::test_char_2);73TESTS.put("bh_s_short_2", BlackholeIntrinsicTest::test_short_2);74TESTS.put("bh_s_int_2", BlackholeIntrinsicTest::test_int_2);75TESTS.put("bh_s_float_2", BlackholeIntrinsicTest::test_float_2);76TESTS.put("bh_s_long_2", BlackholeIntrinsicTest::test_long_2);77TESTS.put("bh_s_double_2", BlackholeIntrinsicTest::test_double_2);78TESTS.put("bh_s_Object_2", BlackholeIntrinsicTest::test_Object_2);7980// Test calling static methods through instance method to exercise81// unusual intrinsic shapes.82TESTS.put("bh_is_int_0", BlackholeIntrinsicTest::test_is_int_0);83TESTS.put("bh_is_Object_0", BlackholeIntrinsicTest::test_is_Object_0);84TESTS.put("bh_is_int_1", BlackholeIntrinsicTest::test_is_int_1);85TESTS.put("bh_is_Object_1", BlackholeIntrinsicTest::test_is_Object_1);86TESTS.put("bh_is_int_2", BlackholeIntrinsicTest::test_is_int_2);87TESTS.put("bh_is_Object_2", BlackholeIntrinsicTest::test_is_Object_2);88}8990private static final int CYCLES = 100_000;91private static final int TRIES = 10;9293public static void main(String[] args) throws IOException {94if (args.length == 0) {95driver();96} else {97test(args[0]);98}99}100101public static void driver() throws IOException {102for (String test : TESTS.keySet()) {103check(test, "-XX:TieredStopAtLevel=1");104check(test, "-XX:-TieredCompilation");105if (Platform.is64bit()) {106check(test, "-XX:-UseCompressedOops", "-XX:TieredStopAtLevel=1");107check(test, "-XX:-UseCompressedOops", "-XX:-TieredCompilation");108}109}110}111112private static void test(String test) {113Runnable r = TESTS.get(test);114if (r == null) {115throw new IllegalArgumentException("Cannot find test " + test);116}117for (int t = 0; t < TRIES; t++) {118r.run();119}120}121122public static void check(String test, String... args) throws IOException {123List<String> cmdline = new ArrayList();124cmdline.add("-Xmx128m");125cmdline.add("-Xbatch");126cmdline.add("-XX:+UnlockDiagnosticVMOptions");127cmdline.add("-XX:+AbortVMOnCompilationFailure");128cmdline.add("-XX:+PrintCompilation");129cmdline.add("-XX:+PrintInlining");130cmdline.add("-XX:+UnlockExperimentalVMOptions");131cmdline.add("-XX:CompileCommand=blackhole,compiler/blackhole/BlackholeTarget.bh_*");132cmdline.addAll(Arrays.asList(args));133cmdline.add("compiler.blackhole.BlackholeIntrinsicTest");134cmdline.add(test);135136ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(cmdline);137OutputAnalyzer output = new OutputAnalyzer(pb.start());138output.shouldHaveExitValue(0);139output.stderrShouldBeEmpty();140output.stdoutShouldMatch("compiler.blackhole.BlackholeTarget::" + test + ".*intrinsic.*");141}142143private static void test_boolean_0() {144for (int c = 0; c < CYCLES; c++) {145BlackholeTarget.bh_s_boolean_0();146}147}148149private static void test_byte_0() {150for (int c = 0; c < CYCLES; c++) {151BlackholeTarget.bh_s_byte_0();152}153}154155private static void test_char_0() {156for (int c = 0; c < CYCLES; c++) {157BlackholeTarget.bh_s_char_0();158}159}160161private static void test_short_0() {162for (int c = 0; c < CYCLES; c++) {163BlackholeTarget.bh_s_short_0();164}165}166167private static void test_int_0() {168for (int c = 0; c < CYCLES; c++) {169BlackholeTarget.bh_s_int_0();170}171}172173private static void test_is_int_0() {174BlackholeTarget t = new BlackholeTarget();175for (int c = 0; c < CYCLES; c++) {176t.bh_is_int_0();177}178}179180private static void test_float_0() {181for (int c = 0; c < CYCLES; c++) {182BlackholeTarget.bh_s_float_0();183}184}185186private static void test_long_0() {187for (int c = 0; c < CYCLES; c++) {188BlackholeTarget.bh_s_long_0();189}190}191192private static void test_double_0() {193for (int c = 0; c < CYCLES; c++) {194BlackholeTarget.bh_s_double_0();195}196}197198private static void test_Object_0() {199for (int c = 0; c < CYCLES; c++) {200BlackholeTarget.bh_s_Object_0();201}202}203204private static void test_is_Object_0() {205BlackholeTarget t = new BlackholeTarget();206for (int c = 0; c < CYCLES; c++) {207t.bh_is_Object_0();208}209}210211private static void test_boolean_1() {212for (int c = 0; c < CYCLES; c++) {213BlackholeTarget.bh_s_boolean_1((c & 0x1) == 0);214}215}216217private static void test_byte_1() {218for (int c = 0; c < CYCLES; c++) {219BlackholeTarget.bh_s_byte_1((byte)c);220}221}222223private static void test_char_1() {224for (int c = 0; c < CYCLES; c++) {225BlackholeTarget.bh_s_char_1((char)c);226}227}228229private static void test_short_1() {230for (int c = 0; c < CYCLES; c++) {231BlackholeTarget.bh_s_short_1((short)c);232}233}234235private static void test_int_1() {236for (int c = 0; c < CYCLES; c++) {237BlackholeTarget.bh_s_int_1(c);238}239}240241private static void test_is_int_1() {242BlackholeTarget t = new BlackholeTarget();243for (int c = 0; c < CYCLES; c++) {244t.bh_is_int_1(c);245}246}247248private static void test_float_1() {249for (int c = 0; c < CYCLES; c++) {250BlackholeTarget.bh_s_float_1(c);251}252}253254private static void test_long_1() {255for (int c = 0; c < CYCLES; c++) {256BlackholeTarget.bh_s_long_1(c);257}258}259260private static void test_double_1() {261for (int c = 0; c < CYCLES; c++) {262BlackholeTarget.bh_s_double_1(c);263}264}265266private static void test_Object_1() {267for (int c = 0; c < CYCLES; c++) {268Object o = new Object();269BlackholeTarget.bh_s_Object_1(o);270}271}272273private static void test_is_Object_1() {274BlackholeTarget t = new BlackholeTarget();275for (int c = 0; c < CYCLES; c++) {276Object o = new Object();277t.bh_is_Object_1(o);278}279}280281private static void test_boolean_2() {282for (int c = 0; c < CYCLES; c++) {283BlackholeTarget.bh_s_boolean_2((c & 0x1) == 0, (c & 0x2) == 0);284}285}286287private static void test_byte_2() {288for (int c = 0; c < CYCLES; c++) {289BlackholeTarget.bh_s_byte_2((byte)c, (byte)(c + 1));290}291}292293private static void test_char_2() {294for (int c = 0; c < CYCLES; c++) {295BlackholeTarget.bh_s_char_2((char)c, (char)(c + 1));296}297}298299private static void test_short_2() {300for (int c = 0; c < CYCLES; c++) {301BlackholeTarget.bh_s_short_2((short)c, (short)(c + 1));302}303}304305private static void test_int_2() {306for (int c = 0; c < CYCLES; c++) {307BlackholeTarget.bh_s_int_2(c, c + 1);308}309}310311private static void test_is_int_2() {312BlackholeTarget t = new BlackholeTarget();313for (int c = 0; c < CYCLES; c++) {314t.bh_is_int_2(c, c + 1);315}316}317318private static void test_float_2() {319for (int c = 0; c < CYCLES; c++) {320BlackholeTarget.bh_s_float_2(c, c + 1);321}322}323324private static void test_long_2() {325for (int c = 0; c < CYCLES; c++) {326BlackholeTarget.bh_s_long_2(c, c + 1);327}328}329330private static void test_double_2() {331for (int c = 0; c < CYCLES; c++) {332BlackholeTarget.bh_s_double_2(c, c + 1);333}334}335336private static void test_Object_2() {337for (int c = 0; c < CYCLES; c++) {338Object o1 = new Object();339Object o2 = new Object();340BlackholeTarget.bh_s_Object_2(o1, o2);341}342}343344private static void test_is_Object_2() {345BlackholeTarget t = new BlackholeTarget();346for (int c = 0; c < CYCLES; c++) {347Object o1 = new Object();348Object o2 = new Object();349t.bh_is_Object_2(o1, o2);350}351}352}353354355