test/compiler/8005419/Test8005419.java

changeset 4413
038dd2875b94
child 6198
55fb97c4c58d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/compiler/8005419/Test8005419.java	Tue Jan 08 11:30:51 2013 -0800
     1.3 @@ -0,0 +1,120 @@
     1.4 +/*
     1.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + */
    1.26 +
    1.27 +/*
    1.28 + * @test
    1.29 + * @bug 8005419
    1.30 + * @summary Improve intrinsics code performance on x86 by using AVX2
    1.31 + * @run main/othervm -Xbatch -Xmx64m Test8005419
    1.32 + *
    1.33 + */
    1.34 +
    1.35 +public class Test8005419 {
    1.36 +    public static int SIZE = 64;
    1.37 +
    1.38 +    public static void main(String[] args) {
    1.39 +        char[] a = new char[SIZE];
    1.40 +        char[] b = new char[SIZE];
    1.41 +
    1.42 +        for (int i = 16; i < SIZE; i++) {
    1.43 +          a[i] = (char)i;
    1.44 +          b[i] = (char)i;
    1.45 +        }
    1.46 +        String s1 = new String(a);
    1.47 +        String s2 = new String(b);
    1.48 +
    1.49 +        // Warm up
    1.50 +        boolean failed = false;
    1.51 +        int result = 0;
    1.52 +        for (int i = 0; i < 10000; i++) {
    1.53 +          result += test(s1, s2);
    1.54 +        }
    1.55 +        for (int i = 0; i < 10000; i++) {
    1.56 +          result += test(s1, s2);
    1.57 +        }
    1.58 +        for (int i = 0; i < 10000; i++) {
    1.59 +          result += test(s1, s2);
    1.60 +        }
    1.61 +        if (result != 0) failed = true;
    1.62 +
    1.63 +        System.out.println("Start testing");
    1.64 +        // Compare same string
    1.65 +        result = test(s1, s1);
    1.66 +        if (result != 0) {
    1.67 +          failed = true;
    1.68 +          System.out.println("Failed same: result = " + result + ", expected 0");
    1.69 +        }
    1.70 +        // Compare equal strings
    1.71 +        for (int i = 1; i <= SIZE; i++) {
    1.72 +          s1 = new String(a, 0, i);
    1.73 +          s2 = new String(b, 0, i);
    1.74 +          result = test(s1, s2);
    1.75 +          if (result != 0) {
    1.76 +            failed = true;
    1.77 +            System.out.println("Failed equals s1[" + i + "], s2[" + i + "]: result = " + result + ", expected 0");
    1.78 +          }
    1.79 +        }
    1.80 +        // Compare equal strings but different sizes
    1.81 +        for (int i = 1; i <= SIZE; i++) {
    1.82 +          s1 = new String(a, 0, i);
    1.83 +          for (int j = 1; j <= SIZE; j++) {
    1.84 +            s2 = new String(b, 0, j);
    1.85 +            result = test(s1, s2);
    1.86 +            if (result != (i-j)) {
    1.87 +              failed = true;
    1.88 +              System.out.println("Failed diff size s1[" + i + "], s2[" + j + "]: result = " + result + ", expected " + (i-j));
    1.89 +            }
    1.90 +          }
    1.91 +        }
    1.92 +        // Compare strings with one char different and different sizes
    1.93 +        for (int i = 1; i <= SIZE; i++) {
    1.94 +          s1 = new String(a, 0, i);
    1.95 +          for (int j = 0; j < i; j++) {
    1.96 +            b[j] -= 3; // change char
    1.97 +            s2 = new String(b, 0, i);
    1.98 +            result = test(s1, s2);
    1.99 +            int chdiff = a[j] - b[j];
   1.100 +            if (result != chdiff) {
   1.101 +              failed = true;
   1.102 +              System.out.println("Failed diff char s1[" + i + "], s2[" + i + "]: result = " + result + ", expected " + chdiff);
   1.103 +            }
   1.104 +            result = test(s2, s1);
   1.105 +            chdiff = b[j] - a[j];
   1.106 +            if (result != chdiff) {
   1.107 +              failed = true;
   1.108 +              System.out.println("Failed diff char s2[" + i + "], s1[" + i + "]: result = " + result + ", expected " + chdiff);
   1.109 +            }
   1.110 +            b[j] += 3; // restore
   1.111 +          }
   1.112 +        }
   1.113 +        if (failed) {
   1.114 +          System.out.println("FAILED");
   1.115 +          System.exit(97);
   1.116 +        }
   1.117 +        System.out.println("PASSED");
   1.118 +    }
   1.119 +
   1.120 +    private static int test(String str1, String str2) {
   1.121 +        return str1.compareTo(str2);
   1.122 +    }
   1.123 +}

mercurial