4135N/A/*
4135N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
4135N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4135N/A *
4135N/A * This code is free software; you can redistribute it and/or modify it
4135N/A * under the terms of the GNU General Public License version 2 only, as
4135N/A * published by the Free Software Foundation.
4135N/A *
4135N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4135N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4135N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4135N/A * version 2 for more details (a copy is included in the LICENSE file that
4135N/A * accompanied this code).
4135N/A *
4135N/A * You should have received a copy of the GNU General Public License version
4135N/A * 2 along with this work; if not, write to the Free Software Foundation,
4135N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4135N/A *
4135N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4135N/A * or visit www.oracle.com if you need additional information or have any
4135N/A * questions.
4135N/A */
4135N/A
4135N/A/*
4135N/A * @test
4135N/A * @bug 8005419
4135N/A * @summary Improve intrinsics code performance on x86 by using AVX2
4135N/A * @run main/othervm -Xbatch -Xmx64m Test8005419
4135N/A *
4135N/A */
4135N/A
4135N/Apublic class Test8005419 {
4135N/A public static int SIZE = 64;
4135N/A
4135N/A public static void main(String[] args) {
4135N/A char[] a = new char[SIZE];
4135N/A char[] b = new char[SIZE];
4135N/A
4135N/A for (int i = 16; i < SIZE; i++) {
4135N/A a[i] = (char)i;
4135N/A b[i] = (char)i;
4135N/A }
4135N/A String s1 = new String(a);
4135N/A String s2 = new String(b);
4135N/A
4135N/A // Warm up
4135N/A boolean failed = false;
4135N/A int result = 0;
4135N/A for (int i = 0; i < 10000; i++) {
4135N/A result += test(s1, s2);
4135N/A }
4135N/A for (int i = 0; i < 10000; i++) {
4135N/A result += test(s1, s2);
4135N/A }
4135N/A for (int i = 0; i < 10000; i++) {
4135N/A result += test(s1, s2);
4135N/A }
4135N/A if (result != 0) failed = true;
4135N/A
4135N/A System.out.println("Start testing");
4135N/A // Compare same string
4135N/A result = test(s1, s1);
4135N/A if (result != 0) {
4135N/A failed = true;
4135N/A System.out.println("Failed same: result = " + result + ", expected 0");
4135N/A }
4135N/A // Compare equal strings
4135N/A for (int i = 1; i <= SIZE; i++) {
4135N/A s1 = new String(a, 0, i);
4135N/A s2 = new String(b, 0, i);
4135N/A result = test(s1, s2);
4135N/A if (result != 0) {
4135N/A failed = true;
4135N/A System.out.println("Failed equals s1[" + i + "], s2[" + i + "]: result = " + result + ", expected 0");
4135N/A }
4135N/A }
4135N/A // Compare equal strings but different sizes
4135N/A for (int i = 1; i <= SIZE; i++) {
4135N/A s1 = new String(a, 0, i);
4135N/A for (int j = 1; j <= SIZE; j++) {
4135N/A s2 = new String(b, 0, j);
4135N/A result = test(s1, s2);
4135N/A if (result != (i-j)) {
4135N/A failed = true;
4135N/A System.out.println("Failed diff size s1[" + i + "], s2[" + j + "]: result = " + result + ", expected " + (i-j));
4135N/A }
4135N/A }
4135N/A }
4135N/A // Compare strings with one char different and different sizes
4135N/A for (int i = 1; i <= SIZE; i++) {
4135N/A s1 = new String(a, 0, i);
4135N/A for (int j = 0; j < i; j++) {
4135N/A b[j] -= 3; // change char
4135N/A s2 = new String(b, 0, i);
4135N/A result = test(s1, s2);
4135N/A int chdiff = a[j] - b[j];
4135N/A if (result != chdiff) {
4135N/A failed = true;
4135N/A System.out.println("Failed diff char s1[" + i + "], s2[" + i + "]: result = " + result + ", expected " + chdiff);
4135N/A }
4135N/A result = test(s2, s1);
4135N/A chdiff = b[j] - a[j];
4135N/A if (result != chdiff) {
4135N/A failed = true;
4135N/A System.out.println("Failed diff char s2[" + i + "], s1[" + i + "]: result = " + result + ", expected " + chdiff);
4135N/A }
4135N/A b[j] += 3; // restore
4135N/A }
4135N/A }
4135N/A if (failed) {
4135N/A System.out.println("FAILED");
4135N/A System.exit(97);
4135N/A }
4135N/A System.out.println("PASSED");
4135N/A }
4135N/A
4135N/A private static int test(String str1, String str2) {
4135N/A return str1.compareTo(str2);
4135N/A }
4135N/A}