annotate test/compiler/intrinsics/squaretolen/TestSquareToLen.java @ 23888:dd8507f51d78 jdk8u77-b31

8152098: Fix 8151522 caused test compiler/intrinsics/squaretolen/TestSquareToLen.java to fail Reviewed-by: kvn
author vkempik
date Fri, 18 Mar 2016 17:23:07 +0300
parents 4abc54f62213
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23885
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
1 /*
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
4 *
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
7 * published by the Free Software Foundation.
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
8 *
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
13 * accompanied this code).
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
14 *
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
18 *
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
21 * questions.
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
22 *
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
23 */
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
24
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
25 /**
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
26 * @test
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
27 * @bug 8081778
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
28 * @summary Add C2 x86 intrinsic for BigInteger::squareToLen() method
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
29 *
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
30 * @run main/othervm/timeout=600 -XX:-TieredCompilation -Xbatch
23888
dd8507f51d78 8152098: Fix 8151522 caused test compiler/intrinsics/squaretolen/TestSquareToLen.java to fail
vkempik
parents: 23887
diff changeset
31 * -XX:+IgnoreUnrecognizedVMOptions
23887
4abc54f62213 8151522: Disable 8130150 and 8081778 intrinsics by default
vkempik
parents: 23885
diff changeset
32 * -XX:+UseSquareToLenIntrinsic
23885
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
33 * -XX:CompileCommand=exclude,TestSquareToLen::main
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
34 * -XX:CompileCommand=option,TestSquareToLen::base_multiply,ccstr,DisableIntrinsic,_squareToLen
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
35 * -XX:CompileCommand=option,java.math.BigInteger::multiply,ccstr,DisableIntrinsic,_squareToLen
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
36 * -XX:CompileCommand=option,java.math.BigInteger::square,ccstr,DisableIntrinsic,_squareToLen
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
37 * -XX:CompileCommand=option,java.math.BigInteger::squareToLen,ccstr,DisableIntrinsic,_squareToLen
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
38 * -XX:CompileCommand=inline,java.math.BigInteger::multiply
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
39 * -XX:CompileCommand=inline,java.math.BigInteger::square
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
40 * -XX:CompileCommand=inline,java.math.BigInteger::squareToLen TestSquareToLen
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
41 */
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
42
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
43 import java.util.Random;
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
44 import java.math.*;
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
45
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
46 public class TestSquareToLen {
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
47
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
48 // Avoid intrinsic by preventing inlining multiply() and squareToLen().
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
49 public static BigInteger base_multiply(BigInteger op1) {
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
50 return op1.multiply(op1);
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
51 }
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
52
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
53 // Generate squareToLen() intrinsic by inlining multiply().
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
54 public static BigInteger new_multiply(BigInteger op1) {
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
55 return op1.multiply(op1);
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
56 }
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
57
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
58 public static boolean bytecompare(BigInteger b1, BigInteger b2) {
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
59 byte[] data1 = b1.toByteArray();
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
60 byte[] data2 = b2.toByteArray();
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
61 if (data1.length != data2.length)
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
62 return false;
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
63 for (int i = 0; i < data1.length; i++) {
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
64 if (data1[i] != data2[i])
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
65 return false;
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
66 }
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
67 return true;
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
68 }
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
69
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
70 public static String stringify(BigInteger b) {
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
71 String strout= "";
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
72 byte [] data = b.toByteArray();
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
73 for (int i = 0; i < data.length; i++) {
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
74 strout += (String.format("%02x",data[i]) + " ");
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
75 }
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
76 return strout;
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
77 }
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
78
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
79 public static void main(String args[]) throws Exception {
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
80
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
81 BigInteger oldsum = new BigInteger("0");
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
82 BigInteger newsum = new BigInteger("0");
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
83
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
84 BigInteger b1, b2, oldres, newres;
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
85
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
86 Random rand = new Random();
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
87 long seed = System.nanoTime();
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
88 Random rand1 = new Random();
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
89 long seed1 = System.nanoTime();
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
90 rand.setSeed(seed);
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
91 rand1.setSeed(seed1);
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
92
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
93 for (int j = 0; j < 100000; j++) {
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
94 int rand_int = rand1.nextInt(3136)+32;
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
95 b1 = new BigInteger(rand_int, rand);
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
96
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
97 oldres = base_multiply(b1);
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
98 newres = new_multiply(b1);
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
99
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
100 oldsum = oldsum.add(oldres);
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
101 newsum = newsum.add(newres);
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
102
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
103 if (!bytecompare(oldres,newres)) {
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
104 System.out.print("mismatch for:b1:" + stringify(b1) + " :oldres:" + stringify(oldres) + " :newres:" + stringify(newres));
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
105 System.out.println(b1);
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
106 throw new Exception("Failed");
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
107 }
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
108 }
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
109 if (!bytecompare(oldsum,newsum)) {
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
110 System.out.println("Failure: oldsum:" + stringify(oldsum) + " newsum:" + stringify(newsum));
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
111 throw new Exception("Failed");
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
112 } else {
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
113 System.out.println("Success");
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
114 }
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
115 }
51c505229e71 8081778: Use Intel x64 CPU instructions for RSA acceleration
igerasim
parents:
diff changeset
116 }