1212 * @library /compiler/patches /test/lib
1313 * @run main/othervm -Xbatch -XX:Tier4InvocationThreshold=200 -XX:CompileThreshold=100 compiler.intrinsics.string.TestStringLatin1IndexOfChar
1414 * @run main/othervm -Xbatch -XX:Tier4InvocationThreshold=200 -XX:CompileThreshold=100 -XX:+UnlockDiagnosticVMOptions -XX:DisableIntrinsic=_indexOfL_char compiler.intrinsics.string.TestStringLatin1IndexOfChar
15- * @run main/othervm -Xbatch -XX:Tier4InvocationThreshold=200 -XX:CompileThreshold=100 -XX:UseSSE=0 compiler.intrinsics.string.TestStringLatin1IndexOfChar
16- * @run main/othervm -Xbatch -XX:Tier4InvocationThreshold=200 -XX:CompileThreshold=100 -XX:UseAVX=1 compiler.intrinsics.string.TestStringLatin1IndexOfChar
17- * @run main/othervm -Xbatch -XX:Tier4InvocationThreshold=200 -XX:CompileThreshold=100 -XX:UseAVX=2 compiler.intrinsics.string.TestStringLatin1IndexOfChar
18- * @run main/othervm -Xbatch -XX:Tier4InvocationThreshold=200 -XX:CompileThreshold=100 -XX:UseAVX=3 compiler.intrinsics.string.TestStringLatin1IndexOfChar
15+ * @run main/othervm -Xbatch -XX:Tier4InvocationThreshold=200 -XX:CompileThreshold=100 -XX:+IgnoreUnrecognizedVMOptions -XX: UseSSE=0 compiler.intrinsics.string.TestStringLatin1IndexOfChar
16+ * @run main/othervm -Xbatch -XX:Tier4InvocationThreshold=200 -XX:CompileThreshold=100 -XX:+IgnoreUnrecognizedVMOptions -XX: UseAVX=1 compiler.intrinsics.string.TestStringLatin1IndexOfChar
17+ * @run main/othervm -Xbatch -XX:Tier4InvocationThreshold=200 -XX:CompileThreshold=100 -XX:+IgnoreUnrecognizedVMOptions -XX: UseAVX=2 compiler.intrinsics.string.TestStringLatin1IndexOfChar
18+ * @run main/othervm -Xbatch -XX:Tier4InvocationThreshold=200 -XX:CompileThreshold=100 -XX:+IgnoreUnrecognizedVMOptions -XX: UseAVX=3 compiler.intrinsics.string.TestStringLatin1IndexOfChar
1919 */
2020
2121package compiler .intrinsics .string ;
@@ -27,7 +27,8 @@ public class TestStringLatin1IndexOfChar{
2727
2828 public static void main (String [] args ) throws Exception {
2929 for (int i = 0 ; i < 1_000 ; ++i ) {//repeat such that we enter into C2 code...
30- maintest ();
30+ findOneItem ();
31+ withOffsetTest ();
3132 testEmpty ();
3233 }
3334 }
@@ -40,14 +41,39 @@ private static void testEmpty(){
4041 private final static char INVERLEAVING_CHAR = 'a' ;
4142 private final static char MISSING_CHAR = 'd' ;
4243
43- private static void maintest (){
44+ private static void findOneItem (){
45+ //test strings of varying length ensuring that for all lengths one instance of the
46+ //search char can be found. We check what happens when the search character is in
47+ //each position of the search string (including first and last positions)
48+ for (int strLength : new int []{1 , 15 , 31 , 32 , 79 }){
49+ for (int searchPos = 0 ; searchPos < strLength ; searchPos ++){
50+ String totest = makeOneItemStringLatin1 (strLength , searchPos );
51+
52+ int intri = totest .indexOf (SEARCH_CHAR );
53+ int nonintri = indexOfCharNonIntrinsic (totest , SEARCH_CHAR , 0 );
54+ Asserts .assertEQ (intri , nonintri );
55+ }
56+ }
57+ }
58+
59+ private static String makeOneItemStringLatin1 (int length , int searchPos ){
60+ StringBuilder sb = new StringBuilder (length );
61+
62+ for (int n =0 ; n < length ; n ++){
63+ sb .append (searchPos ==n ?SEARCH_CHAR :INVERLEAVING_CHAR );
64+ }
65+
66+ return sb .toString ();
67+ }
68+
69+ private static void withOffsetTest (){
4470 //progressivly move through string checking indexes and starting offset correctly processed
4571 //string is of form azaza, aazaazaa, aaazaaazaaa, etc
4672 //we find n s.t. maxlength = (n*3) + 2
4773 int maxaInstances = (MAX_LENGTH -2 )/3 ;
4874
4975 for (int aInstances = 5 ; aInstances < MAX_LENGTH ; aInstances ++){
50- String totest = makeCandidateStringLatin1 (aInstances );
76+ String totest = makeWithOffsetStringLatin1 (aInstances );
5177
5278 int startoffset ;
5379 {
@@ -71,7 +97,7 @@ private static void maintest(){
7197 }
7298 }
7399
74- private static String makeCandidateStringLatin1 (int aInstances ){
100+ private static String makeWithOffsetStringLatin1 (int aInstances ){
75101 StringBuilder sb = new StringBuilder ((aInstances *3 ) + 2 );
76102 for (int n =0 ; n < aInstances ; n ++){
77103 sb .append (INVERLEAVING_CHAR );
0 commit comments