Path: blob/master/test/hotspot/jtreg/compiler/intrinsics/Test8005419.java
41149 views
/*1* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 800541926* @summary Improve intrinsics code performance on x86 by using AVX227*28* @run main/othervm -Xbatch -Xmx128m compiler.intrinsics.Test800541929*/3031package compiler.intrinsics;3233public class Test8005419 {34public static int SIZE = 64;3536public static void main(String[] args) {37char[] a = new char[SIZE];38char[] b = new char[SIZE];3940for (int i = 16; i < SIZE; i++) {41a[i] = (char)i;42b[i] = (char)i;43}44String s1 = new String(a);45String s2 = new String(b);4647// Warm up48boolean failed = false;49int result = 0;50for (int i = 0; i < 10000; i++) {51result += test(s1, s2);52}53for (int i = 0; i < 10000; i++) {54result += test(s1, s2);55}56for (int i = 0; i < 10000; i++) {57result += test(s1, s2);58}59if (result != 0) failed = true;6061System.out.println("Start testing");62// Compare same string63result = test(s1, s1);64if (result != 0) {65failed = true;66System.out.println("Failed same: result = " + result + ", expected 0");67}68// Compare equal strings69for (int i = 1; i <= SIZE; i++) {70s1 = new String(a, 0, i);71s2 = new String(b, 0, i);72result = test(s1, s2);73if (result != 0) {74failed = true;75System.out.println("Failed equals s1[" + i + "], s2[" + i + "]: result = " + result + ", expected 0");76}77}78// Compare equal strings but different sizes79for (int i = 1; i <= SIZE; i++) {80s1 = new String(a, 0, i);81for (int j = 1; j <= SIZE; j++) {82s2 = new String(b, 0, j);83result = test(s1, s2);84if (result != (i-j)) {85failed = true;86System.out.println("Failed diff size s1[" + i + "], s2[" + j + "]: result = " + result + ", expected " + (i-j));87}88}89}90// Compare strings with one char different and different sizes91for (int i = 1; i <= SIZE; i++) {92s1 = new String(a, 0, i);93for (int j = 0; j < i; j++) {94b[j] -= 3; // change char95s2 = new String(b, 0, i);96result = test(s1, s2);97int chdiff = a[j] - b[j];98if (result != chdiff) {99failed = true;100System.out.println("Failed diff char s1[" + i + "], s2[" + i + "]: result = " + result + ", expected " + chdiff);101}102result = test(s2, s1);103chdiff = b[j] - a[j];104if (result != chdiff) {105failed = true;106System.out.println("Failed diff char s2[" + i + "], s1[" + i + "]: result = " + result + ", expected " + chdiff);107}108b[j] += 3; // restore109}110}111if (failed) {112System.out.println("FAILED");113System.exit(97);114}115System.out.println("PASSED");116}117118private static int test(String str1, String str2) {119return str1.compareTo(str2);120}121}122123124