8198987: [Graal] compiler/intrinsics/sha/sanity tests fail on macos with Graal as JIT
authorthartmann
Tue, 06 Mar 2018 10:30:24 +0100
changeset 49345 2a12ff1fff68
parent 49344 e55d7a31cfa7
child 49346 14e84a4edb9c
8198987: [Graal] compiler/intrinsics/sha/sanity tests fail on macos with Graal as JIT Summary: Use the isIntrinsicAvailable WhiteBox API method to check if an intrinsic is available. Reviewed-by: kvn
test/hotspot/jtreg/compiler/testlibrary/sha/predicate/IntrinsicPredicates.java
--- a/test/hotspot/jtreg/compiler/testlibrary/sha/predicate/IntrinsicPredicates.java	Sat Mar 03 10:15:23 2018 +0000
+++ b/test/hotspot/jtreg/compiler/testlibrary/sha/predicate/IntrinsicPredicates.java	Tue Mar 06 10:30:24 2018 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -29,6 +29,7 @@
 import jdk.test.lib.cli.predicate.OrPredicate;
 import sun.hotspot.WhiteBox;
 
+import java.lang.reflect.Method;
 import java.util.function.BooleanSupplier;
 
 /**
@@ -100,27 +101,23 @@
                             IntrinsicPredicates.SHA512_INSTRUCTION_AVAILABLE));
 
     public static final BooleanSupplier SHA1_INTRINSICS_AVAILABLE
-            = new AndPredicate(new AndPredicate(
-                    IntrinsicPredicates.SHA1_INSTRUCTION_AVAILABLE,
-                    IntrinsicPredicates.COMPILABLE_BY_C2),
-                IntrinsicPredicates.booleanOptionValue("UseSHA1Intrinsics"));
+            = new AndPredicate(IntrinsicPredicates.COMPILABLE_BY_C2,
+                               IntrinsicPredicates.isIntrinsicAvailable("sun.security.provider.SHA", "implCompress0"));
 
     public static final BooleanSupplier SHA256_INTRINSICS_AVAILABLE
-            = new AndPredicate(new AndPredicate(
-                    IntrinsicPredicates.SHA256_INSTRUCTION_AVAILABLE,
-                    IntrinsicPredicates.COMPILABLE_BY_C2),
-                IntrinsicPredicates.booleanOptionValue("UseSHA256Intrinsics"));
+            = new AndPredicate(IntrinsicPredicates.COMPILABLE_BY_C2,
+                               IntrinsicPredicates.isIntrinsicAvailable("sun.security.provider.SHA2", "implCompress0"));
 
     public static final BooleanSupplier SHA512_INTRINSICS_AVAILABLE
-            = new AndPredicate(new AndPredicate(
-                    IntrinsicPredicates.SHA512_INSTRUCTION_AVAILABLE,
-                    IntrinsicPredicates.COMPILABLE_BY_C2),
-                IntrinsicPredicates.booleanOptionValue("UseSHA512Intrinsics"));
+            = new AndPredicate(IntrinsicPredicates.COMPILABLE_BY_C2,
+                               IntrinsicPredicates.isIntrinsicAvailable("sun.security.provider.SHA5", "implCompress0"));
 
-    private static BooleanSupplier booleanOptionValue(String option) {
-        return () -> IntrinsicPredicates.WHITE_BOX.getBooleanVMFlag(option);
-    }
-
-    private IntrinsicPredicates() {
-    }
+    private static BooleanSupplier isIntrinsicAvailable(String klass, String method) {
+        try {
+            Method m = Class.forName(klass).getDeclaredMethod(method, byte[].class, int.class);
+            return () -> WHITE_BOX.isIntrinsicAvailable(m, (int)IntrinsicPredicates.TIERED_MAX_LEVEL);
+        } catch (Exception e) {
+            throw new RuntimeException("Intrinsified method " +  klass + "::" + method + " not found!");
+        }
+    };
 }