test/compiler/8005419/Test8005419.java

changeset 4413
038dd2875b94
child 6198
55fb97c4c58d
equal deleted inserted replaced
4412:ffa87474d7a4 4413:038dd2875b94
1 /*
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 8005419
27 * @summary Improve intrinsics code performance on x86 by using AVX2
28 * @run main/othervm -Xbatch -Xmx64m Test8005419
29 *
30 */
31
32 public class Test8005419 {
33 public static int SIZE = 64;
34
35 public static void main(String[] args) {
36 char[] a = new char[SIZE];
37 char[] b = new char[SIZE];
38
39 for (int i = 16; i < SIZE; i++) {
40 a[i] = (char)i;
41 b[i] = (char)i;
42 }
43 String s1 = new String(a);
44 String s2 = new String(b);
45
46 // Warm up
47 boolean failed = false;
48 int result = 0;
49 for (int i = 0; i < 10000; i++) {
50 result += test(s1, s2);
51 }
52 for (int i = 0; i < 10000; i++) {
53 result += test(s1, s2);
54 }
55 for (int i = 0; i < 10000; i++) {
56 result += test(s1, s2);
57 }
58 if (result != 0) failed = true;
59
60 System.out.println("Start testing");
61 // Compare same string
62 result = test(s1, s1);
63 if (result != 0) {
64 failed = true;
65 System.out.println("Failed same: result = " + result + ", expected 0");
66 }
67 // Compare equal strings
68 for (int i = 1; i <= SIZE; i++) {
69 s1 = new String(a, 0, i);
70 s2 = new String(b, 0, i);
71 result = test(s1, s2);
72 if (result != 0) {
73 failed = true;
74 System.out.println("Failed equals s1[" + i + "], s2[" + i + "]: result = " + result + ", expected 0");
75 }
76 }
77 // Compare equal strings but different sizes
78 for (int i = 1; i <= SIZE; i++) {
79 s1 = new String(a, 0, i);
80 for (int j = 1; j <= SIZE; j++) {
81 s2 = new String(b, 0, j);
82 result = test(s1, s2);
83 if (result != (i-j)) {
84 failed = true;
85 System.out.println("Failed diff size s1[" + i + "], s2[" + j + "]: result = " + result + ", expected " + (i-j));
86 }
87 }
88 }
89 // Compare strings with one char different and different sizes
90 for (int i = 1; i <= SIZE; i++) {
91 s1 = new String(a, 0, i);
92 for (int j = 0; j < i; j++) {
93 b[j] -= 3; // change char
94 s2 = new String(b, 0, i);
95 result = test(s1, s2);
96 int chdiff = a[j] - b[j];
97 if (result != chdiff) {
98 failed = true;
99 System.out.println("Failed diff char s1[" + i + "], s2[" + i + "]: result = " + result + ", expected " + chdiff);
100 }
101 result = test(s2, s1);
102 chdiff = b[j] - a[j];
103 if (result != chdiff) {
104 failed = true;
105 System.out.println("Failed diff char s2[" + i + "], s1[" + i + "]: result = " + result + ", expected " + chdiff);
106 }
107 b[j] += 3; // restore
108 }
109 }
110 if (failed) {
111 System.out.println("FAILED");
112 System.exit(97);
113 }
114 System.out.println("PASSED");
115 }
116
117 private static int test(String str1, String str2) {
118 return str1.compareTo(str2);
119 }
120 }

mercurial