8139907: compiler/intrinsics/montgomerymultiply/MontgomeryMultiplyTest.java fails with timeout
authorzmajo
Wed, 28 Oct 2015 15:15:59 +0100
changeset 33473 4511002b3632
parent 33472 4300fda0e8bb
child 33477 70ee0065d3ab
8139907: compiler/intrinsics/montgomerymultiply/MontgomeryMultiplyTest.java fails with timeout Summary: Change MontgomeryMultiplyTest.java test to execute only on platforms on which the tested intrinsics are available. Reviewed-by: kvn, neliasso
hotspot/test/compiler/intrinsics/montgomerymultiply/MontgomeryMultiplyTest.java
--- a/hotspot/test/compiler/intrinsics/montgomerymultiply/MontgomeryMultiplyTest.java	Tue Oct 27 18:05:20 2015 +0000
+++ b/hotspot/test/compiler/intrinsics/montgomerymultiply/MontgomeryMultiplyTest.java	Wed Oct 28 15:15:59 2015 +0100
@@ -27,21 +27,36 @@
 import java.lang.invoke.MethodHandles;
 import java.lang.invoke.MethodType;
 import java.lang.reflect.Constructor;
+import java.lang.reflect.Executable;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.math.BigInteger;
 import java.util.Arrays;
 import java.util.Random;
 
+import sun.hotspot.WhiteBox;
+
+import jdk.test.lib.Platform;
+
 /**
  * @test
- * @bug 8130150
+ * @bug 8130150 8131779 8139907
+ * @summary Verify that the Montgomery multiply and square intrinsic works and correctly checks their arguments.
+ * @library /testlibrary /../../test/lib
  * @library /testlibrary
- * @summary Verify that the Montgomery multiply intrinsic works and correctly checks its arguments.
+ * @build MontgomeryMultiplyTest
+ * @run main ClassFileInstaller sun.hotspot.WhiteBox
+ *                              sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI MontgomeryMultiplyTest
  */
 
 public class MontgomeryMultiplyTest {
 
+    private static final WhiteBox wb = WhiteBox.getWhiteBox();
+
+    /* Compilation level corresponding to C2. */
+    private static final int COMP_LEVEL_FULL_OPTIMIZATION = 4;
+
     static final MethodHandles.Lookup lookup = MethodHandles.lookup();
 
     static final MethodHandle montgomeryMultiplyHandle, montgomerySquareHandle;
@@ -76,6 +91,37 @@
         }
     }
 
+    /* Obtain executable for the intrinsics tested. Depending on the
+     * value of 'isMultiply', the executable corresponding to either
+     * implMontgomerMultiply or implMontgomerySqure is returned. */
+    static Executable getExecutable(boolean isMultiply) throws RuntimeException {
+        try {
+            Class aClass = Class.forName("java.math.BigInteger");
+            Method aMethod;
+            if (isMultiply) {
+                aMethod = aClass.getDeclaredMethod("implMontgomeryMultiply",
+                                                   int[].class,
+                                                   int[].class,
+                                                   int[].class,
+                                                   int.class,
+                                                   long.class,
+                                                   int[].class);
+            } else {
+                aMethod = aClass.getDeclaredMethod("implMontgomerySquare",
+                                                   int[].class,
+                                                   int[].class,
+                                                   int.class,
+                                                   long.class,
+                                                   int[].class);
+            }
+            return aMethod;
+        } catch (NoSuchMethodException e) {
+            throw new RuntimeException("Test bug, method is unavailable. " + e);
+        } catch (ClassNotFoundException e) {
+            throw new RuntimeException("Test bug, class is unavailable. " + e);
+        }
+    }
+
     // Invoke either BigInteger.montgomeryMultiply or BigInteger.montgomerySquare.
     int[] montgomeryMultiply(int[] a, int[] b, int[] n, int len, long inv,
                              int[] product) throws Throwable {
@@ -267,11 +313,15 @@
     }
 
     public static void main(String args[]) {
-        try {
-            new MontgomeryMultiplyTest().testMontgomeryMultiplyChecks();
-            new MontgomeryMultiplyTest().testResultValues();
-        } catch (Throwable ex) {
-            throw new RuntimeException(ex);
+        if (Platform.isServer() &&
+            wb.isIntrinsicAvailable(getExecutable(true), COMP_LEVEL_FULL_OPTIMIZATION) &&
+            wb.isIntrinsicAvailable(getExecutable(false), COMP_LEVEL_FULL_OPTIMIZATION)) {
+            try {
+                new MontgomeryMultiplyTest().testMontgomeryMultiplyChecks();
+                new MontgomeryMultiplyTest().testResultValues();
+            } catch (Throwable ex) {
+                throw new RuntimeException(ex);
+            }
         }
-     }
+    }
 }