1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/compiler/testlibrary/sha/predicate/IntrinsicPredicates.java Wed Sep 03 15:26:06 2014 +0400 1.3 @@ -0,0 +1,103 @@ 1.4 +/* 1.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +package sha.predicate; 1.28 + 1.29 +import com.oracle.java.testlibrary.Platform; 1.30 +import com.oracle.java.testlibrary.cli.predicate.AndPredicate; 1.31 +import com.oracle.java.testlibrary.cli.predicate.CPUSpecificPredicate; 1.32 +import com.oracle.java.testlibrary.cli.predicate.OrPredicate; 1.33 +import sun.hotspot.WhiteBox; 1.34 + 1.35 +import java.util.function.BooleanSupplier; 1.36 + 1.37 +/** 1.38 + * Helper class aimed to provide predicates on availability of SHA-related 1.39 + * CPU instructions and intrinsics. 1.40 + */ 1.41 +public class IntrinsicPredicates { 1.42 + private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox(); 1.43 + private static final long TIERED_MAX_LEVEL = 4L; 1.44 + /** 1.45 + * Boolean supplier that check if any method could be compiled by C2. 1.46 + * Method potentially could be compiled by C2 if Server VM is used and 1.47 + * either tiered compilation is disabled or TIERED_MAX_LEVEL tier is 1.48 + * reachable. 1.49 + * 1.50 + * Please don't place this definition after SHA*_INTRINSICS_AVAILABLE 1.51 + * definitions. Otherwise its value will be {@code null} at the time when 1.52 + * all dependent fields will be initialized. 1.53 + */ 1.54 + private static final BooleanSupplier COMPILABLE_BY_C2 = () -> { 1.55 + boolean isTiered = IntrinsicPredicates.WHITE_BOX.getBooleanVMFlag( 1.56 + "TieredCompilation"); 1.57 + long tieredMaxLevel = IntrinsicPredicates.WHITE_BOX.getIntxVMFlag( 1.58 + "TieredStopAtLevel"); 1.59 + boolean maxLevelIsReachable = (tieredMaxLevel 1.60 + == IntrinsicPredicates.TIERED_MAX_LEVEL); 1.61 + return Platform.isServer() && (!isTiered || maxLevelIsReachable); 1.62 + }; 1.63 + 1.64 + public static final BooleanSupplier SHA1_INSTRUCTION_AVAILABLE 1.65 + = new CPUSpecificPredicate("sparc.*", new String[] { "sha1" }, 1.66 + null); 1.67 + 1.68 + public static final BooleanSupplier SHA256_INSTRUCTION_AVAILABLE 1.69 + = new CPUSpecificPredicate("sparc.*", new String[] { "sha256" }, 1.70 + null); 1.71 + 1.72 + public static final BooleanSupplier SHA512_INSTRUCTION_AVAILABLE 1.73 + = new CPUSpecificPredicate("sparc.*", new String[] { "sha512" }, 1.74 + null); 1.75 + 1.76 + public static final BooleanSupplier ANY_SHA_INSTRUCTION_AVAILABLE 1.77 + = new OrPredicate(IntrinsicPredicates.SHA1_INSTRUCTION_AVAILABLE, 1.78 + new OrPredicate( 1.79 + IntrinsicPredicates.SHA256_INSTRUCTION_AVAILABLE, 1.80 + IntrinsicPredicates.SHA512_INSTRUCTION_AVAILABLE)); 1.81 + 1.82 + public static final BooleanSupplier SHA1_INTRINSICS_AVAILABLE 1.83 + = new AndPredicate(new AndPredicate( 1.84 + IntrinsicPredicates.SHA1_INSTRUCTION_AVAILABLE, 1.85 + IntrinsicPredicates.COMPILABLE_BY_C2), 1.86 + IntrinsicPredicates.booleanOptionValue("UseSHA1Intrinsics")); 1.87 + 1.88 + public static final BooleanSupplier SHA256_INTRINSICS_AVAILABLE 1.89 + = new AndPredicate(new AndPredicate( 1.90 + IntrinsicPredicates.SHA256_INSTRUCTION_AVAILABLE, 1.91 + IntrinsicPredicates.COMPILABLE_BY_C2), 1.92 + IntrinsicPredicates.booleanOptionValue("UseSHA256Intrinsics")); 1.93 + 1.94 + public static final BooleanSupplier SHA512_INTRINSICS_AVAILABLE 1.95 + = new AndPredicate(new AndPredicate( 1.96 + IntrinsicPredicates.SHA512_INSTRUCTION_AVAILABLE, 1.97 + IntrinsicPredicates.COMPILABLE_BY_C2), 1.98 + IntrinsicPredicates.booleanOptionValue("UseSHA512Intrinsics")); 1.99 + 1.100 + private static BooleanSupplier booleanOptionValue(String option) { 1.101 + return () -> IntrinsicPredicates.WHITE_BOX.getBooleanVMFlag(option); 1.102 + } 1.103 + 1.104 + private IntrinsicPredicates() { 1.105 + } 1.106 +}