jdk

Форк
0
122 строки · 4.1 Кб
1
/*
2
 * Copyright (c) 2012, 2013, 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
 *
29
 * @run main/othervm -Xbatch -Xmx128m compiler.intrinsics.Test8005419
30
 */
31

32
package compiler.intrinsics;
33

34
public class Test8005419 {
35
    public static int SIZE = 64;
36

37
    public static void main(String[] args) {
38
        char[] a = new char[SIZE];
39
        char[] b = new char[SIZE];
40

41
        for (int i = 16; i < SIZE; i++) {
42
          a[i] = (char)i;
43
          b[i] = (char)i;
44
        }
45
        String s1 = new String(a);
46
        String s2 = new String(b);
47

48
        // Warm up
49
        boolean failed = false;
50
        int result = 0;
51
        for (int i = 0; i < 10000; i++) {
52
          result += test(s1, s2);
53
        }
54
        for (int i = 0; i < 10000; i++) {
55
          result += test(s1, s2);
56
        }
57
        for (int i = 0; i < 10000; i++) {
58
          result += test(s1, s2);
59
        }
60
        if (result != 0) failed = true;
61

62
        System.out.println("Start testing");
63
        // Compare same string
64
        result = test(s1, s1);
65
        if (result != 0) {
66
          failed = true;
67
          System.out.println("Failed same: result = " + result + ", expected 0");
68
        }
69
        // Compare equal strings
70
        for (int i = 1; i <= SIZE; i++) {
71
          s1 = new String(a, 0, i);
72
          s2 = new String(b, 0, i);
73
          result = test(s1, s2);
74
          if (result != 0) {
75
            failed = true;
76
            System.out.println("Failed equals s1[" + i + "], s2[" + i + "]: result = " + result + ", expected 0");
77
          }
78
        }
79
        // Compare equal strings but different sizes
80
        for (int i = 1; i <= SIZE; i++) {
81
          s1 = new String(a, 0, i);
82
          for (int j = 1; j <= SIZE; j++) {
83
            s2 = new String(b, 0, j);
84
            result = test(s1, s2);
85
            if (result != (i-j)) {
86
              failed = true;
87
              System.out.println("Failed diff size s1[" + i + "], s2[" + j + "]: result = " + result + ", expected " + (i-j));
88
            }
89
          }
90
        }
91
        // Compare strings with one char different and different sizes
92
        for (int i = 1; i <= SIZE; i++) {
93
          s1 = new String(a, 0, i);
94
          for (int j = 0; j < i; j++) {
95
            b[j] -= 3; // change char
96
            s2 = new String(b, 0, i);
97
            result = test(s1, s2);
98
            int chdiff = a[j] - b[j];
99
            if (result != chdiff) {
100
              failed = true;
101
              System.out.println("Failed diff char s1[" + i + "], s2[" + i + "]: result = " + result + ", expected " + chdiff);
102
            }
103
            result = test(s2, s1);
104
            chdiff = b[j] - a[j];
105
            if (result != chdiff) {
106
              failed = true;
107
              System.out.println("Failed diff char s2[" + i + "], s1[" + i + "]: result = " + result + ", expected " + chdiff);
108
            }
109
            b[j] += 3; // restore
110
          }
111
        }
112
        if (failed) {
113
          System.out.println("FAILED");
114
          System.exit(97);
115
        }
116
        System.out.println("PASSED");
117
    }
118

119
    private static int test(String str1, String str2) {
120
        return str1.compareTo(str2);
121
    }
122
}
123

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.