Path: blob/master/test/hotspot/jtreg/compiler/intrinsics/mathexact/sanity/IntrinsicBase.java
41159 views
/*1* Copyright (c) 2013, 2015, Oracle and/or its affiliates. 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*/2223package compiler.intrinsics.mathexact.sanity;2425import compiler.testlibrary.intrinsics.Verifier;26import compiler.whitebox.CompilerWhiteBoxTest;27import jdk.test.lib.Platform;2829import java.io.FileOutputStream;30import java.lang.reflect.Executable;31import java.util.Properties;3233public abstract class IntrinsicBase extends CompilerWhiteBoxTest {34protected String useMathExactIntrinsics;3536protected IntrinsicBase(TestCase testCase) {37super(testCase);38useMathExactIntrinsics = getVMOption("UseMathExactIntrinsics");39}4041@Override42protected void test() throws Exception {43//java.lang.Math should be loaded to allow a compilation of the methods that use Math's method44System.out.println("class java.lang.Math should be loaded. Proof: " + Math.class);45printEnvironmentInfo();46if (Platform.isInt()) {47throw new Error("TESTBUG: test can not be run in interpreter");48}4950int expectedIntrinsicCount = 0;5152if (Platform.isServer() && !Platform.isEmulatedClient()) {53if (TIERED_COMPILATION) {54int max_level = TIERED_STOP_AT_LEVEL;55expectedIntrinsicCount = (max_level == COMP_LEVEL_MAX) ? 1 : 0;56for (int i = COMP_LEVEL_SIMPLE; i <= max_level; ++i) {57deoptimize();58compileAtLevel(i);59}60} else {61expectedIntrinsicCount = 1;62deoptimize();63compileAtLevel(COMP_LEVEL_MAX);64}65} else {66deoptimize();67compileAtLevel(COMP_LEVEL_SIMPLE);68}6970if (!isIntrinsicAvailable()) {71expectedIntrinsicCount = 0;72}7374System.out.println("Expected intrinsic count is " + expectedIntrinsicCount + " name " + getIntrinsicId());7576final FileOutputStream out = new FileOutputStream(getVMOption("LogFile") + Verifier.PROPERTY_FILE_SUFFIX);77Properties expectedProps = new Properties();78expectedProps.setProperty(Verifier.INTRINSIC_NAME_PROPERTY, getIntrinsicId());79expectedProps.setProperty(Verifier.INTRINSIC_EXPECTED_COUNT_PROPERTY, String.valueOf(expectedIntrinsicCount));80expectedProps.store(out, null);8182out.close();83}8485protected void printEnvironmentInfo() {86System.out.println("os.arch=" + Platform.getOsArch());87System.out.println("java.vm.info=" + Platform.vmInfo);88System.out.println("useMathExactIntrinsics=" + useMathExactIntrinsics);89}9091protected void compileAtLevel(int level) {92WHITE_BOX.enqueueMethodForCompilation(method, level);93waitBackgroundCompilation();94checkCompilation(method, level);95}9697protected void checkCompilation(Executable executable, int level) {98if (!WHITE_BOX.isMethodCompiled(executable)) {99throw new RuntimeException("Test bug, expected compilation (level): " + level + ", but not compiled");100}101final int compilationLevel = WHITE_BOX.getMethodCompilationLevel(executable);102if (compilationLevel != level) {103if (!(TIERED_COMPILATION && level == COMP_LEVEL_FULL_PROFILE && compilationLevel == COMP_LEVEL_LIMITED_PROFILE)) { //possible case104throw new RuntimeException("Test bug, expected compilation (level): " + level + ", but level: " + compilationLevel);105}106}107}108109// An intrinsic is available if:110// - the intrinsic is enabled (by using the appropriate command-line flag) and111// - the intrinsic is supported by the VM (i.e., the platform on which the VM is112// running provides the instructions necessary for the VM to generate the intrinsic).113protected abstract boolean isIntrinsicAvailable();114115protected abstract String getIntrinsicId();116117static class IntTest extends IntrinsicBase {118119protected boolean isIntrinsicAvailable; // The tested intrinsic is available on the current platform.120121protected IntTest(MathIntrinsic.IntIntrinsic testCase) {122super(testCase);123// Only the C2 compiler intrinsifies exact math methods124// so check if the intrinsics are available with C2.125isIntrinsicAvailable = WHITE_BOX.isIntrinsicAvailable(testCase.getTestMethod(),126COMP_LEVEL_FULL_OPTIMIZATION);127}128129@Override130protected boolean isIntrinsicAvailable() {131return isIntrinsicAvailable;132}133134@Override135protected String getIntrinsicId() {136return "_" + testCase.name().toLowerCase() + "ExactI";137}138}139140static class LongTest extends IntrinsicBase {141142protected boolean isIntrinsicAvailable; // The tested intrinsic is available on the current platform.143144protected LongTest(MathIntrinsic.LongIntrinsic testCase) {145super(testCase);146// Only the C2 compiler intrinsifies exact math methods147// so check if the intrinsics are available with C2.148isIntrinsicAvailable = WHITE_BOX.isIntrinsicAvailable(testCase.getTestMethod(),149COMP_LEVEL_FULL_OPTIMIZATION);150}151152@Override153protected boolean isIntrinsicAvailable() {154return isIntrinsicAvailable;155}156157@Override158protected String getIntrinsicId() {159return "_" + testCase.name().toLowerCase() + "ExactL";160}161}162}163164165