fzhinkin@7142: /* fzhinkin@7142: * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. fzhinkin@7142: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. fzhinkin@7142: * fzhinkin@7142: * This code is free software; you can redistribute it and/or modify it fzhinkin@7142: * under the terms of the GNU General Public License version 2 only, as fzhinkin@7142: * published by the Free Software Foundation. fzhinkin@7142: * fzhinkin@7142: * This code is distributed in the hope that it will be useful, but WITHOUT fzhinkin@7142: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or fzhinkin@7142: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License fzhinkin@7142: * version 2 for more details (a copy is included in the LICENSE file that fzhinkin@7142: * accompanied this code). fzhinkin@7142: * fzhinkin@7142: * You should have received a copy of the GNU General Public License version fzhinkin@7142: * 2 along with this work; if not, write to the Free Software Foundation, fzhinkin@7142: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. fzhinkin@7142: * fzhinkin@7142: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA fzhinkin@7142: * or visit www.oracle.com if you need additional information or have any fzhinkin@7142: * questions. fzhinkin@7142: */ fzhinkin@7142: fzhinkin@7142: package sha.predicate; fzhinkin@7142: fzhinkin@7142: import com.oracle.java.testlibrary.Platform; fzhinkin@7142: import com.oracle.java.testlibrary.cli.predicate.AndPredicate; fzhinkin@7142: import com.oracle.java.testlibrary.cli.predicate.CPUSpecificPredicate; fzhinkin@7142: import com.oracle.java.testlibrary.cli.predicate.OrPredicate; fzhinkin@7142: import sun.hotspot.WhiteBox; fzhinkin@7142: fzhinkin@7142: import java.util.function.BooleanSupplier; fzhinkin@7142: fzhinkin@7142: /** fzhinkin@7142: * Helper class aimed to provide predicates on availability of SHA-related fzhinkin@7142: * CPU instructions and intrinsics. fzhinkin@7142: */ fzhinkin@7142: public class IntrinsicPredicates { fzhinkin@7142: private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox(); fzhinkin@7142: private static final long TIERED_MAX_LEVEL = 4L; fzhinkin@7142: /** fzhinkin@7142: * Boolean supplier that check if any method could be compiled by C2. fzhinkin@7142: * Method potentially could be compiled by C2 if Server VM is used and fzhinkin@7142: * either tiered compilation is disabled or TIERED_MAX_LEVEL tier is fzhinkin@7142: * reachable. fzhinkin@7142: * fzhinkin@7142: * Please don't place this definition after SHA*_INTRINSICS_AVAILABLE fzhinkin@7142: * definitions. Otherwise its value will be {@code null} at the time when fzhinkin@7142: * all dependent fields will be initialized. fzhinkin@7142: */ fzhinkin@7142: private static final BooleanSupplier COMPILABLE_BY_C2 = () -> { fzhinkin@7142: boolean isTiered = IntrinsicPredicates.WHITE_BOX.getBooleanVMFlag( fzhinkin@7142: "TieredCompilation"); fzhinkin@7142: long tieredMaxLevel = IntrinsicPredicates.WHITE_BOX.getIntxVMFlag( fzhinkin@7142: "TieredStopAtLevel"); fzhinkin@7142: boolean maxLevelIsReachable = (tieredMaxLevel fzhinkin@7142: == IntrinsicPredicates.TIERED_MAX_LEVEL); fzhinkin@7142: return Platform.isServer() && (!isTiered || maxLevelIsReachable); fzhinkin@7142: }; fzhinkin@7142: fzhinkin@7142: public static final BooleanSupplier SHA1_INSTRUCTION_AVAILABLE fzhinkin@7142: = new CPUSpecificPredicate("sparc.*", new String[] { "sha1" }, fzhinkin@7142: null); fzhinkin@7142: fzhinkin@7142: public static final BooleanSupplier SHA256_INSTRUCTION_AVAILABLE ogatak@9713: = new OrPredicate(new CPUSpecificPredicate("sparc.*", new String[] { "sha256" }, ogatak@9713: null), ogatak@9713: new OrPredicate(new CPUSpecificPredicate("ppc64.*", new String[] { "sha" }, ogatak@9713: null), ogatak@9713: new CPUSpecificPredicate("ppc64le.*", new String[] { "sha" }, ogatak@9713: null))); fzhinkin@7142: fzhinkin@7142: public static final BooleanSupplier SHA512_INSTRUCTION_AVAILABLE ogatak@9713: = new OrPredicate(new CPUSpecificPredicate("sparc.*", new String[] { "sha512" }, ogatak@9713: null), ogatak@9713: new OrPredicate(new CPUSpecificPredicate("ppc64.*", new String[] { "sha" }, ogatak@9713: null), ogatak@9713: new CPUSpecificPredicate("ppc64le.*", new String[] { "sha" }, ogatak@9713: null))); fzhinkin@7142: fzhinkin@7142: public static final BooleanSupplier ANY_SHA_INSTRUCTION_AVAILABLE fzhinkin@7142: = new OrPredicate(IntrinsicPredicates.SHA1_INSTRUCTION_AVAILABLE, fzhinkin@7142: new OrPredicate( fzhinkin@7142: IntrinsicPredicates.SHA256_INSTRUCTION_AVAILABLE, fzhinkin@7142: IntrinsicPredicates.SHA512_INSTRUCTION_AVAILABLE)); fzhinkin@7142: fzhinkin@7142: public static final BooleanSupplier SHA1_INTRINSICS_AVAILABLE fzhinkin@7142: = new AndPredicate(new AndPredicate( fzhinkin@7142: IntrinsicPredicates.SHA1_INSTRUCTION_AVAILABLE, fzhinkin@7142: IntrinsicPredicates.COMPILABLE_BY_C2), fzhinkin@7142: IntrinsicPredicates.booleanOptionValue("UseSHA1Intrinsics")); fzhinkin@7142: fzhinkin@7142: public static final BooleanSupplier SHA256_INTRINSICS_AVAILABLE fzhinkin@7142: = new AndPredicate(new AndPredicate( fzhinkin@7142: IntrinsicPredicates.SHA256_INSTRUCTION_AVAILABLE, fzhinkin@7142: IntrinsicPredicates.COMPILABLE_BY_C2), fzhinkin@7142: IntrinsicPredicates.booleanOptionValue("UseSHA256Intrinsics")); fzhinkin@7142: fzhinkin@7142: public static final BooleanSupplier SHA512_INTRINSICS_AVAILABLE fzhinkin@7142: = new AndPredicate(new AndPredicate( fzhinkin@7142: IntrinsicPredicates.SHA512_INSTRUCTION_AVAILABLE, fzhinkin@7142: IntrinsicPredicates.COMPILABLE_BY_C2), fzhinkin@7142: IntrinsicPredicates.booleanOptionValue("UseSHA512Intrinsics")); fzhinkin@7142: fzhinkin@7142: private static BooleanSupplier booleanOptionValue(String option) { fzhinkin@7142: return () -> IntrinsicPredicates.WHITE_BOX.getBooleanVMFlag(option); fzhinkin@7142: } fzhinkin@7142: fzhinkin@7142: private IntrinsicPredicates() { fzhinkin@7142: } fzhinkin@7142: }