Path: blob/master/test/hotspot/jtreg/compiler/intrinsics/string/TestStringIntrinsics2.java
41153 views
/*1* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2016 SAP SE. 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 it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 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 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324/*25* @test26* @bug 814533627* @summary PPC64: fix string intrinsics after CompactStrings change28* @modules java.base/jdk.internal.misc29* @library /test/lib30*31* @build sun.hotspot.WhiteBox32* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox33*34* @run main/othervm35* -Xbootclasspath/a:.36* -Xmixed37* -XX:+UnlockDiagnosticVMOptions38* -XX:+WhiteBoxAPI39* -XX:+IgnoreUnrecognizedVMOptions40* -XX:MaxInlineSize=7041* -XX:MinInliningThreshold=042* compiler.intrinsics.string.TestStringIntrinsics243*/4445package compiler.intrinsics.string;4647import sun.hotspot.WhiteBox;4849import java.lang.annotation.ElementType;50import java.lang.annotation.Retention;51import java.lang.annotation.RetentionPolicy;52import java.lang.annotation.Target;53import java.util.Arrays;54import java.util.function.Consumer;5556import static jdk.test.lib.Asserts.assertEquals;57import static jdk.test.lib.Asserts.assertFalse;58import static jdk.test.lib.Asserts.assertTrue;5960public class TestStringIntrinsics2 {61// ------------------------------------------------------------------------62//63// We test the following cases:64// - no match in string. Do we miss the end condition? Will crash if we read65// past the string.66// - no match in string, but after the string there is a match.67// Do we incorrectly report this match? We had a case where we stepped68// a few chars past the string, this test would report that error. The69// one above would not.70// - The needle is exactly at the end of the string.71// - The needle spans the end of the string72//73// A special case are needles of length 1. For these we test:74// - needle is first char75// - needle is last char76// - no match77// - match behind string.78//79// We test all these for an unknown needle, and needles known to the compiler80// of lengths 5, 2 and 1.818283private static final WhiteBox WB = WhiteBox.getWhiteBox();8485public enum Role {86TEST_ENTRY,87TEST_HELPER88}8990@Retention(RetentionPolicy.RUNTIME)91@Target(ElementType.METHOD)92@interface Test {93Role role();94int compileAt() default 0;95int warmup() default 0;96String[] warmupArgs() default {};97}9899// All this mess is needed to avoid try/catch inside the lambdas below.100// See: http://stackoverflow.com/questions/27644361/how-can-i-throw-checked-exceptions-from-inside-java-8-streams101@SuppressWarnings ("unchecked")102private static <E extends Throwable> void throwAsUnchecked(Exception exception) throws E {103throw (E)exception;104}105@FunctionalInterface106public interface Consumer_WithExceptions<T, E extends Exception> {107void accept(T t) throws E;108}109public static <T, E extends Exception> Consumer<T> rethrowConsumer(Consumer_WithExceptions<T, E> consumer) {110return t -> {111try { consumer.accept(t); }112catch (Exception exception) { throwAsUnchecked(exception); }113};114}115116public static void main(String[] args) throws Exception {117118// Warmup helper methods119Arrays.stream(TestStringIntrinsics2.class.getDeclaredMethods())120.filter(m -> m.isAnnotationPresent(Test.class))121.filter(m -> m.getAnnotation(Test.class).warmup() > 0)122.forEach(rethrowConsumer(m -> {123Test a = m.getAnnotation(Test.class);124System.out.println("Warming up " + m + " " + a.warmup() + " time(s) ");125for (int i=0; i < a.warmup(); i++) {126m.invoke(null, (Object[])a.warmupArgs());127}128}));129130// Compile helper methods131Arrays.stream(TestStringIntrinsics2.class.getDeclaredMethods())132.filter(m -> m.isAnnotationPresent(Test.class))133.filter(m -> m.getAnnotation(Test.class).compileAt() > 0)134.forEach(rethrowConsumer(m -> {135Test a = m.getAnnotation(Test.class);136if (WB.isMethodCompilable(m, a.compileAt())) {137WB.enqueueMethodForCompilation(m, a.compileAt());138while (WB.isMethodQueuedForCompilation(m)) Thread.sleep(10);139System.out.println(m + " compiled at " + WB.getMethodCompilationLevel(m));140} else {141System.out.println("Can't compile " + m + " at level " + a.compileAt());142}143}));144145// Run test methods146Arrays.stream(TestStringIntrinsics2.class.getDeclaredMethods())147.filter(m -> m.isAnnotationPresent(Test.class))148.filter(m -> m.getAnnotation(Test.class).role() == Role.TEST_ENTRY)149.forEach(rethrowConsumer(m -> {150System.out.print("Executing " + m);151m.invoke(null, (Object[])null);152System.out.println(" - OK");153}));154}155156static String text = "<t><t><t><t><t><t>\n" + "<hit>";157static String text2 = "<t><t><t><t><t><t><t>\n" + "<hit>";158static String[] ss = text.split("\n");159static String[] ss2 = null;160static String needle = "<miss>";161162@Test(role = Role.TEST_ENTRY)163public static void test_indexOf_no_match() {164int res = indexOf_no_match_unknown_needle(ss[0], "<miss>");165assertEquals(res, -1, "test_indexOf_no_match_unknown_needle matched at: " + res);166res = indexOf_no_match_imm_needle(ss[0]);167assertEquals(res, -1, "test_indexOf_no_match_imm_needle matched at: " + res);168res = indexOf_no_match_imm2_needle(ss[0]);169assertEquals(res, -1, "test_indexOf_no_match_imm2_needle matched at: " + res);170171if (ss2 == null) ss2 = text.split("\n");172res = indexOf_no_match_unknown_needle(ss2[0], "<miss>");173assertEquals(res, -1, "test_indexOf_no_match_unknown_needle matched at: " + res);174res = indexOf_no_match_imm_needle(ss2[0]);175assertEquals(res, -1, "test_indexOf_no_match_imm_needle matched at: " + res);176res = indexOf_no_match_imm2_needle(ss2[0]);177assertEquals(res, -1, "test_indexOf_no_match_imm2_needle matched at: " + res);178res = indexOf_no_match_imm1_needle(ss2[0]);179assertEquals(res, -1, "test_indexOf_no_match_imm1_needle matched at: " + res);180}181182@Test(role = Role.TEST_HELPER, compileAt = 4, warmup = 1, warmupArgs = { "<t><t><t>", "<miss>" })183static int indexOf_no_match_unknown_needle(String s, String needle) {184int index = s.indexOf(needle);185return index;186}187188@Test(role = Role.TEST_HELPER, compileAt = 4, warmup = 1, warmupArgs = { "<t><t><t>" })189static int indexOf_no_match_imm_needle(String s) {190int index = s.indexOf("<hitt>");191return index;192}193194@Test(role = Role.TEST_HELPER, compileAt = 4, warmup = 1, warmupArgs = { "<t><t><t>" })195static int indexOf_no_match_imm2_needle(String s) {196int index = s.indexOf("<m");197return index;198}199200@Test(role = Role.TEST_HELPER, compileAt = 4, warmup = 1, warmupArgs = { "<t><t><t>" })201static int indexOf_no_match_imm1_needle(String s) {202int index = s.indexOf("m");203return index;204}205206@Test(role = Role.TEST_ENTRY)207public static void test_indexOf_reads_past_string() {208if (ss == null) ss = text.split("\n");209String res = indexOf_reads_past_string_unknown_needle(ss[0], "<hit>");210assertEquals(res, null, "test_indexOf_reads_past_string_unknown_needle " + res);211res = indexOf_reads_past_string_imm_needle(ss[0]);212assertEquals(res, null, "test_indexOf_reads_past_string_imm_needle " + res);213res = indexOf_reads_past_string_imm2_needle(ss[0]);214assertEquals(res, null, "test_indexOf_reads_past_string_imm2_needle " + res);215res = indexOf_reads_past_string_imm1_needle(ss[0]);216assertEquals(res, null, "test_indexOf_reads_past_string_imm1_needle " + res);217}218219@Test(role = Role.TEST_HELPER, compileAt = 4, warmup = 1, warmupArgs = { "<t><t><t>", "<hit>" })220static String indexOf_reads_past_string_unknown_needle(String s, String needle) {221int index = s.indexOf(needle);222if (index > s.length()) {223return "Found needle \"" + needle + "\" behind string of length " + s.length()224+ " at position " + index + ".";225}226return null;227}228229@Test(role = Role.TEST_HELPER, compileAt = 4, warmup = 1, warmupArgs = { "<t><t><t>" })230static String indexOf_reads_past_string_imm_needle(String s) {231int index = s.indexOf("<hit>");232if (index > s.length()) {233return "Found needle \"<hit>\" behind string of length " + s.length() + " at position " + index + ".";234}235return null;236}237238@Test(role = Role.TEST_HELPER, compileAt = 4, warmup = 1, warmupArgs = { "<t><t><t>" })239static String indexOf_reads_past_string_imm2_needle(String s) {240int index = s.indexOf("<h");241if (index > s.length()) {242return "Found needle \"<h\" behind string of length " + s.length() + " at position " + index + ".";243}244return null;245}246247@Test(role = Role.TEST_HELPER, compileAt = 4, warmup = 1, warmupArgs = { "<t><t><t>" })248static String indexOf_reads_past_string_imm1_needle(String s) {249int index = s.indexOf("h");250if (index > s.length()) {251return "Found needle \"<h\" behind string of length " + s.length() + " at position " + index + ".";252}253return null;254}255256static String text3 = "<t><hi><t><h><hit<t><hit>";257static String text4 = "a<t><hi><t><h><hit<t><hit>";258static String text5 = "gg<t><hi><t><h><hit<t><hit>";259static String text6 = "ccc<t><hi><t><h><hit<t><hit>";260static int len3 = text3.length();261static int len4 = text4.length();262static int len5 = text5.length();263static int len6 = text6.length();264265static String text7 = "<t><t><t><t><t<t><h";266static String text8 = "a<t><t><t><t><t<t><h";267static String text9 = "gg<t><t><t><t><t<t><h";268static String text10 = "ccc<t><t><t><t><t<t><h";269270@Test(role = Role.TEST_ENTRY)271public static void test_indexOf_match_at_end_of_string() {272String testname = "test_indexOf_match_at_end_of_string";273int res = 0;274res = indexOf_match_at_end_of_string_unknown_needle(text3, "<hit>");275assertEquals(len3, res + 5, testname);276res = indexOf_match_at_end_of_string_unknown_needle(text4, "<hit>");277assertEquals(len4, res + 5, testname);278res = indexOf_match_at_end_of_string_unknown_needle(text5, "<hit>");279assertEquals(len5, res + 5, testname);280res = indexOf_match_at_end_of_string_unknown_needle(text6, "<hit>");281assertEquals(len6, res + 5, testname);282283res = indexOf_match_at_end_of_string_imm_needle(text3);284assertEquals(len3, res + 5, testname);285res = indexOf_match_at_end_of_string_imm_needle(text4);286assertEquals(len4, res + 5, testname);287res = indexOf_match_at_end_of_string_imm_needle(text5);288assertEquals(len5, res + 5, testname);289res = indexOf_match_at_end_of_string_imm_needle(text6);290assertEquals(len6, res + 5, testname);291292res = indexOf_match_at_end_of_string_imm2_needle(text7);293assertEquals(text7.length(), res + 2, testname);294res = indexOf_match_at_end_of_string_imm2_needle(text8);295assertEquals(text8.length(), res + 2, testname);296res = indexOf_match_at_end_of_string_imm2_needle(text9);297assertEquals(text9.length(), res + 2, testname);298res = indexOf_match_at_end_of_string_imm2_needle(text10);299assertEquals(text10.length(), res + 2, testname);300301res = indexOf_match_at_end_of_string_imm1_needle(text7);302assertEquals(text7.length(), res + 1, testname);303res = indexOf_match_at_end_of_string_imm1_needle(text8);304assertEquals(text8.length(), res + 1, testname);305res = indexOf_match_at_end_of_string_imm1_needle(text9);306assertEquals(text9.length(), res + 1, testname);307res = indexOf_match_at_end_of_string_imm1_needle(text10);308assertEquals(text10.length(), res + 1, testname);309}310311@Test(role = Role.TEST_HELPER, compileAt = 4, warmup = 1, warmupArgs = { "<t><hi><t><h><hit<t><hit>", "<hit>" })312static int indexOf_match_at_end_of_string_unknown_needle(String s, String needle) {313int index = s.indexOf(needle);314return index;315}316317@Test(role = Role.TEST_HELPER, compileAt = 4, warmup = 1, warmupArgs = { "<t><hi><t><h><hit<t><hit>" })318static int indexOf_match_at_end_of_string_imm_needle(String s) {319int index = s.indexOf("<hit>");320return index;321}322323@Test(role = Role.TEST_HELPER, compileAt = 4, warmup = 1, warmupArgs = { "<t><hi><t><h><hit<t><hit>" })324static int indexOf_match_at_end_of_string_imm2_needle(String s) {325int index = s.indexOf("<h");326return index;327}328329@Test(role = Role.TEST_HELPER, compileAt = 4, warmup = 1, warmupArgs = { "<t><hi><t><h><hit<t><hit>" })330static int indexOf_match_at_end_of_string_imm1_needle(String s) {331int index = s.indexOf("h");332return index;333}334335static String s0_1 = text3.substring(0, len3-1);336static String s0_2 = text3.substring(0, len3-2);337static String s0_3 = text3.substring(0, len3-3);338static String s0_4 = text3.substring(0, len3-4);339static String s1_1 = text4.substring(0, len4-1);340static String s1_2 = text4.substring(0, len4-2);341static String s1_3 = text4.substring(0, len4-3);342static String s1_4 = text4.substring(0, len4-4);343static String s2_1 = text5.substring(0, len5-1);344static String s2_2 = text5.substring(0, len5-2);345static String s2_3 = text5.substring(0, len5-3);346static String s2_4 = text5.substring(0, len5-4);347static String s3_1 = text6.substring(0, len6-1);348static String s3_2 = text6.substring(0, len6-2);349static String s3_3 = text6.substring(0, len6-3);350static String s3_4 = text6.substring(0, len6-4);351352static String s0_1x = text7 .substring(0, text7 .length()-1);353static String s1_1x = text8 .substring(0, text8 .length()-1);354static String s2_1x = text9 .substring(0, text9 .length()-1);355static String s3_1x = text10.substring(0, text10.length()-1);356357@Test(role = Role.TEST_ENTRY)358public static void test_indexOf_match_spans_end_of_string() {359String res = null;360res = indexOf_match_spans_end_of_string_unknown_needle(s0_1, "<hit>");361assertEquals(res, null, "test_indexOf_match_spans_end_of_string_unknown_needle s0_1 " + res);362res = indexOf_match_spans_end_of_string_unknown_needle(s0_2, "<hit>");363assertEquals(res, null, "test_indexOf_match_spans_end_of_string_unknown_needle s0_2 " + res);364res = indexOf_match_spans_end_of_string_unknown_needle(s0_3, "<hit>");365assertEquals(res, null, "test_indexOf_match_spans_end_of_string_unknown_needle s0_3 " + res);366res = indexOf_match_spans_end_of_string_unknown_needle(s0_4, "<hit>");367assertEquals(res, null, "test_indexOf_match_spans_end_of_string_unknown_needle s0_4 " + res);368res = indexOf_match_spans_end_of_string_unknown_needle(s1_1, "<hit>");369assertEquals(res, null, "test_indexOf_match_spans_end_of_string_unknown_needle s1_1 " + res);370res = indexOf_match_spans_end_of_string_unknown_needle(s1_2, "<hit>");371assertEquals(res, null, "test_indexOf_match_spans_end_of_string_unknown_needle s1_2 " + res);372res = indexOf_match_spans_end_of_string_unknown_needle(s1_3, "<hit>");373assertEquals(res, null, "test_indexOf_match_spans_end_of_string_unknown_needle s1_3 " + res);374res = indexOf_match_spans_end_of_string_unknown_needle(s1_4, "<hit>");375assertEquals(res, null, "test_indexOf_match_spans_end_of_string_unknown_needle s1_4 " + res);376res = indexOf_match_spans_end_of_string_unknown_needle(s2_1, "<hit>");377assertEquals(res, null, "test_indexOf_match_spans_end_of_string_unknown_needle s2_1 " + res);378res = indexOf_match_spans_end_of_string_unknown_needle(s2_2, "<hit>");379assertEquals(res, null, "test_indexOf_match_spans_end_of_string_unknown_needle s2_2 " + res);380res = indexOf_match_spans_end_of_string_unknown_needle(s2_3, "<hit>");381assertEquals(res, null, "test_indexOf_match_spans_end_of_string_unknown_needle s2_3 " + res);382res = indexOf_match_spans_end_of_string_unknown_needle(s2_4, "<hit>");383assertEquals(res, null, "test_indexOf_match_spans_end_of_string_unknown_needle s2_4 " + res);384res = indexOf_match_spans_end_of_string_unknown_needle(s3_1, "<hit>");385assertEquals(res, null, "test_indexOf_match_spans_end_of_string_unknown_needle s3_1 " + res);386res = indexOf_match_spans_end_of_string_unknown_needle(s3_2, "<hit>");387assertEquals(res, null, "test_indexOf_match_spans_end_of_string_unknown_needle s3_2 " + res);388res = indexOf_match_spans_end_of_string_unknown_needle(s3_3, "<hit>");389assertEquals(res, null, "test_indexOf_match_spans_end_of_string_unknown_needle s3_3 " + res);390res = indexOf_match_spans_end_of_string_unknown_needle(s3_4, "<hit>");391assertEquals(res, null, "test_indexOf_match_spans_end_of_string_unknown_needle s3_4 " + res);392393res = indexOf_match_spans_end_of_string_imm_needle(s0_1);394assertEquals(res, null, "test_indexOf_match_spans_end_of_string_imm_needle s0_1 " + res);395res = indexOf_match_spans_end_of_string_imm_needle(s0_2);396assertEquals(res, null, "test_indexOf_match_spans_end_of_string_imm_needle s0_2 " + res);397res = indexOf_match_spans_end_of_string_imm_needle(s0_3);398assertEquals(res, null, "test_indexOf_match_spans_end_of_string_imm_needle s0_3 " + res);399res = indexOf_match_spans_end_of_string_imm_needle(s0_4);400assertEquals(res, null, "test_indexOf_match_spans_end_of_string_imm_needle s0_4 " + res);401res = indexOf_match_spans_end_of_string_imm_needle(s1_1);402assertEquals(res, null, "test_indexOf_match_spans_end_of_string_imm_needle s1_1 " + res);403res = indexOf_match_spans_end_of_string_imm_needle(s1_2);404assertEquals(res, null, "test_indexOf_match_spans_end_of_string_imm_needle s1_2 " + res);405res = indexOf_match_spans_end_of_string_imm_needle(s1_3);406assertEquals(res, null, "test_indexOf_match_spans_end_of_string_imm_needle s1_3 " + res);407res = indexOf_match_spans_end_of_string_imm_needle(s1_4);408assertEquals(res, null, "test_indexOf_match_spans_end_of_string_imm_needle s1_4 " + res);409res = indexOf_match_spans_end_of_string_imm_needle(s2_1);410assertEquals(res, null, "test_indexOf_match_spans_end_of_string_imm_needle s2_1 " + res);411res = indexOf_match_spans_end_of_string_imm_needle(s2_2);412assertEquals(res, null, "test_indexOf_match_spans_end_of_string_imm_needle s2_2 " + res);413res = indexOf_match_spans_end_of_string_imm_needle(s2_3);414assertEquals(res, null, "test_indexOf_match_spans_end_of_string_imm_needle s2_3 " + res);415res = indexOf_match_spans_end_of_string_imm_needle(s2_4);416assertEquals(res, null, "test_indexOf_match_spans_end_of_string_imm_needle s2_4 " + res);417res = indexOf_match_spans_end_of_string_imm_needle(s3_1);418assertEquals(res, null, "test_indexOf_match_spans_end_of_string_imm_needle s3_1 " + res);419res = indexOf_match_spans_end_of_string_imm_needle(s3_2);420assertEquals(res, null, "test_indexOf_match_spans_end_of_string_imm_needle s3_2 " + res);421res = indexOf_match_spans_end_of_string_imm_needle(s3_3);422assertEquals(res, null, "test_indexOf_match_spans_end_of_string_imm_needle s3_3 " + res);423res = indexOf_match_spans_end_of_string_imm_needle(s3_4);424assertEquals(res, null, "test_indexOf_match_spans_end_of_string_imm_needle s3_4 " + res);425426res = indexOf_match_spans_end_of_string_imm2_needle(s0_1x);427assertEquals(res, null, "test_indexOf_match_spans_end_of_string_imm2_needle s0_1x " + res);428res = indexOf_match_spans_end_of_string_imm2_needle(s1_1x);429assertEquals(res, null, "test_indexOf_match_spans_end_of_string_imm2_needle s1_1x " + res);430res = indexOf_match_spans_end_of_string_imm2_needle(s2_1x);431assertEquals(res, null, "test_indexOf_match_spans_end_of_string_imm2_needle s2_1x " + res);432res = indexOf_match_spans_end_of_string_imm2_needle(s3_1x);433assertEquals(res, null, "test_indexOf_match_spans_end_of_string_imm2_needle s3_1x " + res);434}435436@Test(role = Role.TEST_HELPER, compileAt = 4, warmup = 1, warmupArgs = { "<t><hi><t><h><hit<t><hit", "<hit>" })437static String indexOf_match_spans_end_of_string_unknown_needle(String s, String needle) {438int index = s.indexOf(needle);439if (index > -1) {440return "Found needle \"" + needle + "\" that is spanning the end of the string: " + s + ".";441}442return null;443}444445@Test(role = Role.TEST_HELPER, compileAt = 4, warmup = 1, warmupArgs = { "<t><hi><t><h><hit<t><hit" })446static String indexOf_match_spans_end_of_string_imm_needle(String s) {447int index = s.indexOf("<hit>");448if (index > -1) {449return "Found needle \"<hit>\" that is spanning the end of the string: " + s + ".";450}451return null;452}453454@Test(role = Role.TEST_HELPER, compileAt = 4, warmup = 1, warmupArgs = { "<t><t><t><t><t<t><" })455static String indexOf_match_spans_end_of_string_imm2_needle(String s) {456int index = s.indexOf("<h");457if (index > -1) {458return "Found needle \"<h\" that is spanning the end of the string: " + s + ".";459}460return null;461}462463static String text16 = "ooooooo";464static String text11 = "1ooooooo";465static String text12 = "ooooooo1";466static String text13 = "oooooooo1";467static String text14 = "ooooooooo1";468static String text15 = "oooooooooo1";469static int len12 = text12.length();470static int len13 = text13.length();471static int len14 = text14.length();472static int len15 = text15.length();473474static String text12_1 = text12.substring(0, len12-1);475static String text13_1 = text13.substring(0, len13-1);476static String text14_1 = text14.substring(0, len14-1);477static String text15_1 = text15.substring(0, len15-1);478479@Test(role = Role.TEST_ENTRY)480public static void test_indexOf_imm1_needle() {481assertEquals( -1, indexOf_imm1_needle(text16), "test_indexOf_imm1_needle no_match");482483assertEquals( 0, indexOf_imm1_needle(text11), "test_indexOf_imm1_needle first_matches");484485assertEquals(len12-1, indexOf_imm1_needle(text12), "test_indexOf_imm1_needle last_matches");486assertEquals(len13-1, indexOf_imm1_needle(text13), "test_indexOf_imm1_needle last_matches");487assertEquals(len14-1, indexOf_imm1_needle(text14), "test_indexOf_imm1_needle last_matches");488assertEquals(len15-1, indexOf_imm1_needle(text15), "test_indexOf_imm1_needle last_matches");489490assertEquals( -1, indexOf_imm1_needle(text12_1), "test_indexOf_imm1_needle walked_past");491assertEquals( -1, indexOf_imm1_needle(text13_1), "test_indexOf_imm1_needle walked_past");492assertEquals( -1, indexOf_imm1_needle(text14_1), "test_indexOf_imm1_needle walked_past");493assertEquals( -1, indexOf_imm1_needle(text15_1), "test_indexOf_imm1_needle walked_past");494}495496@Test(role = Role.TEST_HELPER, compileAt = 4, warmup = 1, warmupArgs = { "ooooooo1" })497static int indexOf_imm1_needle(String s) {498return s.indexOf("1");499}500501static String text1UTF16 = "A" + "\u05d0" + "\u05d1" + "B";502503@Test(role = Role.TEST_ENTRY)504public static void test_indexOf_immUTF16() {505assertEquals( 3, indexOf_imm1Latin1_needle(text1UTF16), "test_indexOf_immUTF16");506assertEquals( 1, indexOf_imm1UTF16_needle(text1UTF16), "test_indexOf_immUTF16");507assertEquals( 1, indexOf_immUTF16_needle(text1UTF16), "test_indexOf_immUTF16");508}509510@Test(role = Role.TEST_HELPER, compileAt = 4, warmup = 1, warmupArgs = { "A" + "\u05d0" + "\u05d1" + "B" })511static int indexOf_imm1Latin1_needle(String s) {512return s.indexOf("B");513}514515@Test(role = Role.TEST_HELPER, compileAt = 4, warmup = 1, warmupArgs = { "A" + "\u05d0" + "\u05d1" + "B" })516static int indexOf_imm1UTF16_needle(String s) {517return s.indexOf("\u05d0");518}519520@Test(role = Role.TEST_HELPER, compileAt = 4, warmup = 1, warmupArgs = { "A" + "\u05d0" + "\u05d1" + "B" })521static int indexOf_immUTF16_needle(String s) {522return s.indexOf("\u05d0" + "\u05d1");523}524525@Test(role = Role.TEST_HELPER, compileAt = 4, warmup = 1, warmupArgs = { "abc", "abcd" })526public static int asmStringCompareTo(String a, String b) {527return a.compareTo(b);528}529530@Test(role = Role.TEST_ENTRY)531public static void test_asmStringCompareTo() {532// null533try {534asmStringCompareTo("not null", null);535assertTrue(false,536"TestOther.asmStringCompareTo(\"not null\", null) doesn't throw exception");537} catch (NullPointerException e) {538assertEquals("java.lang.String.compareTo",539e.getStackTrace()[0].getClassName() + "." +540e.getStackTrace()[0].getMethodName(),541"TestOther.asmStringCompareTo(\"not null\", null) throws exception");542}543544// ==0545{546// check length 0 optimization547assertEquals(0, asmStringCompareTo("", ""),548"TestOther.asmStringCompareTo(\"\", \"\")");549550// check first character optimization551assertEquals(0, asmStringCompareTo("A", "A"),552"TestOther.asmStringCompareTo(\"A\", \"A\")");553554// check real comparisons555assertEquals(0, asmStringCompareTo(new String("eq") + new String("ual"), "equal"),556"TestOther.asmStringCompareTo(\"equal\", \"equal\")");557assertEquals(0, asmStringCompareTo("textABC", "textABC"),558"TestOther.asmStringCompareTo(\"textABC\", \"textABC\")");559assertEquals(0,560asmStringCompareTo(new String("abcdefgh01234") +561new String("56abcdefgh0123456abcdefgh0123456"),562"abcdefgh0123456abcdefgh0123456abcdefgh0123456"),563"TestOther.asmStringCompareTo(\"abcdefgh0123456abcdefgh0123456abcdefgh0123456\", " +564"\"abcdefgh0123456abcdefgh0123456abcdefgh0123456\")");565}566567// <0568{569// check first character optimization570assertEquals(-1, asmStringCompareTo("4", "5"),571"TestOther.asmStringCompareTo(\"4\", \"5\")");572573// check real comparisons574assertEquals(-1, asmStringCompareTo("diff4", "diff5"),575"TestOther.asmStringCompareTo(\"diff4\", \"diff5\")");576assertEquals(-10, asmStringCompareTo("", "123456789A"),577"TestOther.asmStringCompareTo(\"\", \"123456789A\")");578assertEquals(-10, asmStringCompareTo("ZYX", "ZYX123456789A"),579"TestOther.asmStringCompareTo(\"ZYX\", \"ZYX123456789A\")");580}581582// >0583{584// check first character optimization585assertEquals(1, asmStringCompareTo("5", "4"),586"TestOther.asmStringCompareTo(\"5\", \"4\")");587588// check real comparisons589assertEquals(1, asmStringCompareTo("diff5", "diff4"),590"TestOther.asmStringCompareTo(\"diff5\", \"diff4\")");591assertEquals(10, asmStringCompareTo("123456789A", ""),592"TestOther.asmStringCompareTo(\"123456789A\", \"\")");593assertEquals(10, asmStringCompareTo("ZYX123456789A", "ZYX"),594"TestOther.asmStringCompareTo(\"ZYX123456789A\", \"ZYX\")");595}596597// very long strings (100k)598{599char[] ac = new char[(100 * 1024)];600for (int i = 0; i < (100 * 1024); i += 315)601ac[i] = (char) ((i % 12) + 'a');602char[] bc = new char[(100 * 1024)];603for (int i = 0; i < (100 * 1024); i += 315)604bc[i] = (char) ((i % 12) + 'a');605606ac[(100 * 1024) - 1] = '2';607bc[(100 * 1024) - 1] = '2';608String a1 = new String(ac);609String b1 = new String(bc);610assertEquals(0, asmStringCompareTo(a1, b1),611"TestOther.asmStringCompareTo(very_long_strings_1)");612613ac[(100 * 1024) - 1] = 'X';614bc[(100 * 1024) - 1] = 'Z';615String a2 = new String(ac);616String b2 = new String(bc);617assertEquals(-2, asmStringCompareTo(a2, b2),618"TestOther.asmStringCompareTo(very_long_strings_2)");619}620621// very very long strings (2M)622{623char[] ac = new char[(2 * 1024 * 1024)];624for (int i = 0; i < (2 * 1024 * 1024); i += 315)625ac[i] = (char) ((i % 12) + 'a');626char[] bc = new char[(2 * 1024 * 1024)];627for (int i = 0; i < (2 * 1024 * 1024); i += 315)628bc[i] = (char) ((i % 12) + 'a');629630ac[(2 * 1024 * 1024) - 1] = '3';631bc[(2 * 1024 * 1024) - 1] = '3';632String a1 = new String(ac);633String b1 = new String(bc);634assertEquals(0, asmStringCompareTo(a1, b1),635"TestOther.asmStringCompareTo(very_very_long_strings_1)");636637ac[(2 * 1024 * 1024) - 1] = 'W';638bc[(2 * 1024 * 1024) - 1] = 'Z';639String a2 = new String(ac);640String b2 = new String(bc);641assertEquals(-3, asmStringCompareTo(a2, b2),642"TestOther.asmStringCompareTo(very_very_long_strings_2)");643}644645// See bug 8215100646{647assertEquals(-20, asmStringCompareTo("e.\u0259.", "y.e."));648assertEquals(20, asmStringCompareTo("y.e.", "e.\u0259."));649}650}651652653@Test(role = Role.TEST_HELPER, compileAt = 4, warmup = 1, warmupArgs = { "abc", "abcd" })654public static boolean asmStringEquals(String a, String b) {655return a.equals(b);656}657658static String a1 = "abcd";659static String b1 = "abcd";660static final String a2 = "1234";661static final String b2 = "1234";662663@Test(role = Role.TEST_HELPER, compileAt = 4, warmup = 1)664public static boolean asmStringEqualsConst() {665boolean ret = a1.equals(b1);666ret &= a2.equals(b2);667ret &= !a2.equals(b1);668ret &= "ABCD".equals("ABCD");669return ret;670}671672673@Test(role = Role.TEST_ENTRY)674public static void test_asmStringEquals() {675// null676{677assertFalse(asmStringEquals("not null", null),678"TestOther.asmStringEquals(\"not null\", null)");679}680681// true682{683// check constant optimization684assertTrue(asmStringEqualsConst(),685"TestOther.asmStringEqualsConst(\"\", \"\")");686687// check length 0 optimization688assertTrue(asmStringEquals("", ""),689"TestOther.asmStringEquals(\"\", \"\")");690691// check first character optimization692assertTrue(asmStringEquals("A", "A"),693"TestOther.asmStringEquals(\"A\", \"A\")");694695// check real comparisons696assertTrue(asmStringEquals(new String("eq") + new String("ual"), "equal"),697"TestOther.asmStringEquals(\"equal\", \"equal\")");698assertTrue(asmStringEquals("textABC", "textABC"),699"TestOther.asmStringEquals(\"textABC\", \"textABC\")");700assertTrue(asmStringEquals(new String("abcdefgh01234") +701new String("56abcdefgh0123456abcdefgh0123456"),702"abcdefgh0123456abcdefgh0123456abcdefgh0123456"),703"TestOther.asmStringEquals(\"abcdefgh0123456abcdefgh0123456abcdefgh0123456\", " +704"\"abcdefgh0123456abcdefgh0123456abcdefgh0123456\")");705}706}707708}709710711