test/hotspot/jtreg/compiler/testlibrary/sha/predicate/IntrinsicPredicates.java
changeset 49345 2a12ff1fff68
parent 47565 f4962ab855b6
child 51410 cb8cab787ba2
equal deleted inserted replaced
49344:e55d7a31cfa7 49345:2a12ff1fff68
     1 /*
     1 /*
     2  * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    27 import jdk.test.lib.cli.predicate.AndPredicate;
    27 import jdk.test.lib.cli.predicate.AndPredicate;
    28 import jdk.test.lib.cli.predicate.CPUSpecificPredicate;
    28 import jdk.test.lib.cli.predicate.CPUSpecificPredicate;
    29 import jdk.test.lib.cli.predicate.OrPredicate;
    29 import jdk.test.lib.cli.predicate.OrPredicate;
    30 import sun.hotspot.WhiteBox;
    30 import sun.hotspot.WhiteBox;
    31 
    31 
       
    32 import java.lang.reflect.Method;
    32 import java.util.function.BooleanSupplier;
    33 import java.util.function.BooleanSupplier;
    33 
    34 
    34 /**
    35 /**
    35  * Helper class aimed to provide predicates on availability of SHA-related
    36  * Helper class aimed to provide predicates on availability of SHA-related
    36  * CPU instructions and intrinsics.
    37  * CPU instructions and intrinsics.
    98                     new OrPredicate(
    99                     new OrPredicate(
    99                             IntrinsicPredicates.SHA256_INSTRUCTION_AVAILABLE,
   100                             IntrinsicPredicates.SHA256_INSTRUCTION_AVAILABLE,
   100                             IntrinsicPredicates.SHA512_INSTRUCTION_AVAILABLE));
   101                             IntrinsicPredicates.SHA512_INSTRUCTION_AVAILABLE));
   101 
   102 
   102     public static final BooleanSupplier SHA1_INTRINSICS_AVAILABLE
   103     public static final BooleanSupplier SHA1_INTRINSICS_AVAILABLE
   103             = new AndPredicate(new AndPredicate(
   104             = new AndPredicate(IntrinsicPredicates.COMPILABLE_BY_C2,
   104                     IntrinsicPredicates.SHA1_INSTRUCTION_AVAILABLE,
   105                                IntrinsicPredicates.isIntrinsicAvailable("sun.security.provider.SHA", "implCompress0"));
   105                     IntrinsicPredicates.COMPILABLE_BY_C2),
       
   106                 IntrinsicPredicates.booleanOptionValue("UseSHA1Intrinsics"));
       
   107 
   106 
   108     public static final BooleanSupplier SHA256_INTRINSICS_AVAILABLE
   107     public static final BooleanSupplier SHA256_INTRINSICS_AVAILABLE
   109             = new AndPredicate(new AndPredicate(
   108             = new AndPredicate(IntrinsicPredicates.COMPILABLE_BY_C2,
   110                     IntrinsicPredicates.SHA256_INSTRUCTION_AVAILABLE,
   109                                IntrinsicPredicates.isIntrinsicAvailable("sun.security.provider.SHA2", "implCompress0"));
   111                     IntrinsicPredicates.COMPILABLE_BY_C2),
       
   112                 IntrinsicPredicates.booleanOptionValue("UseSHA256Intrinsics"));
       
   113 
   110 
   114     public static final BooleanSupplier SHA512_INTRINSICS_AVAILABLE
   111     public static final BooleanSupplier SHA512_INTRINSICS_AVAILABLE
   115             = new AndPredicate(new AndPredicate(
   112             = new AndPredicate(IntrinsicPredicates.COMPILABLE_BY_C2,
   116                     IntrinsicPredicates.SHA512_INSTRUCTION_AVAILABLE,
   113                                IntrinsicPredicates.isIntrinsicAvailable("sun.security.provider.SHA5", "implCompress0"));
   117                     IntrinsicPredicates.COMPILABLE_BY_C2),
       
   118                 IntrinsicPredicates.booleanOptionValue("UseSHA512Intrinsics"));
       
   119 
   114 
   120     private static BooleanSupplier booleanOptionValue(String option) {
   115     private static BooleanSupplier isIntrinsicAvailable(String klass, String method) {
   121         return () -> IntrinsicPredicates.WHITE_BOX.getBooleanVMFlag(option);
   116         try {
   122     }
   117             Method m = Class.forName(klass).getDeclaredMethod(method, byte[].class, int.class);
   123 
   118             return () -> WHITE_BOX.isIntrinsicAvailable(m, (int)IntrinsicPredicates.TIERED_MAX_LEVEL);
   124     private IntrinsicPredicates() {
   119         } catch (Exception e) {
   125     }
   120             throw new RuntimeException("Intrinsified method " +  klass + "::" + method + " not found!");
       
   121         }
       
   122     };
   126 }
   123 }