Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/intrinsics/string/TestStringLatin1IndexOfChar.java
41153 views
1
/*
2
* Copyright Amazon.com Inc. or its affiliates. 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 it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 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 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 8173585
27
* @summary Test intrinsification of StringLatin1.indexOf(char). Note that
28
* differing code paths are taken contingent upon the length of the input String.
29
* Hence we must test against differing string lengths in order to validate
30
* correct functionality. We also ensure the strings are long enough to trigger
31
* the looping conditions of the individual code paths.
32
*
33
* Run with varing levels of AVX and SSE support, also without the intrinsic at all
34
*
35
* @library /compiler/patches /test/lib
36
* @run main/othervm -Xbatch -XX:Tier4InvocationThreshold=200 -XX:CompileThreshold=100 compiler.intrinsics.string.TestStringLatin1IndexOfChar
37
* @run main/othervm -Xbatch -XX:Tier4InvocationThreshold=200 -XX:CompileThreshold=100 -XX:+UnlockDiagnosticVMOptions -XX:DisableIntrinsic=_indexOfL_char compiler.intrinsics.string.TestStringLatin1IndexOfChar
38
* @run main/othervm -Xbatch -XX:Tier4InvocationThreshold=200 -XX:CompileThreshold=100 -XX:+IgnoreUnrecognizedVMOptions -XX:UseSSE=0 compiler.intrinsics.string.TestStringLatin1IndexOfChar
39
* @run main/othervm -Xbatch -XX:Tier4InvocationThreshold=200 -XX:CompileThreshold=100 -XX:+IgnoreUnrecognizedVMOptions -XX:UseAVX=1 compiler.intrinsics.string.TestStringLatin1IndexOfChar
40
* @run main/othervm -Xbatch -XX:Tier4InvocationThreshold=200 -XX:CompileThreshold=100 -XX:+IgnoreUnrecognizedVMOptions -XX:UseAVX=2 compiler.intrinsics.string.TestStringLatin1IndexOfChar
41
* @run main/othervm -Xbatch -XX:Tier4InvocationThreshold=200 -XX:CompileThreshold=100 -XX:+IgnoreUnrecognizedVMOptions -XX:UseAVX=3 compiler.intrinsics.string.TestStringLatin1IndexOfChar
42
*/
43
44
package compiler.intrinsics.string;
45
46
import jdk.test.lib.Asserts;
47
48
public class TestStringLatin1IndexOfChar{
49
private final static int MAX_LENGTH = 2048;//future proof for AVX-512 instructions
50
51
public static void main(String[] args) throws Exception {
52
for (int i = 0; i < 1_000; ++i) {//repeat such that we enter into C2 code...
53
findOneItem();
54
withOffsetTest();
55
testEmpty();
56
}
57
}
58
59
private static void testEmpty(){
60
Asserts.assertEQ("".indexOf('a'), -1);
61
}
62
63
private final static char SEARCH_CHAR = 'z';
64
private final static char INVERLEAVING_CHAR = 'a';
65
private final static char MISSING_CHAR = 'd';
66
67
private static void findOneItem(){
68
//test strings of varying length ensuring that for all lengths one instance of the
69
//search char can be found. We check what happens when the search character is in
70
//each position of the search string (including first and last positions)
71
for(int strLength : new int[]{1, 15, 31, 32, 79}){
72
for(int searchPos = 0; searchPos < strLength; searchPos++){
73
String totest = makeOneItemStringLatin1(strLength, searchPos);
74
75
int intri = totest.indexOf(SEARCH_CHAR);
76
int nonintri = indexOfCharNonIntrinsic(totest, SEARCH_CHAR, 0);
77
Asserts.assertEQ(intri, nonintri);
78
}
79
}
80
}
81
82
private static String makeOneItemStringLatin1(int length, int searchPos){
83
StringBuilder sb = new StringBuilder(length);
84
85
for(int n =0; n < length; n++){
86
sb.append(searchPos==n?SEARCH_CHAR:INVERLEAVING_CHAR);
87
}
88
89
return sb.toString();
90
}
91
92
private static void withOffsetTest(){
93
//progressivly move through string checking indexes and starting offset correctly processed
94
//string is of form azaza, aazaazaa, aaazaaazaaa, etc
95
//we find n s.t. maxlength = (n*3) + 2
96
int maxaInstances = (MAX_LENGTH-2)/3;
97
98
for(int aInstances = 5; aInstances < MAX_LENGTH; aInstances++){
99
String totest = makeWithOffsetStringLatin1(aInstances);
100
101
int startoffset;
102
{
103
int intri = totest.indexOf(SEARCH_CHAR);
104
int nonintri = indexOfCharNonIntrinsic(totest, SEARCH_CHAR, 0);
105
106
Asserts.assertEQ(intri, nonintri);
107
startoffset = intri+1;
108
}
109
110
{
111
int intri = totest.indexOf(SEARCH_CHAR, startoffset);
112
int nonintri = indexOfCharNonIntrinsic(totest, SEARCH_CHAR, startoffset);
113
114
Asserts.assertEQ(intri, nonintri);
115
startoffset = intri+1;
116
}
117
118
Asserts.assertEQ(totest.indexOf(SEARCH_CHAR, startoffset), -1);//only two SEARCH_CHAR per string
119
Asserts.assertEQ(totest.indexOf(MISSING_CHAR), -1);
120
}
121
}
122
123
private static String makeWithOffsetStringLatin1(int aInstances){
124
StringBuilder sb = new StringBuilder((aInstances*3) + 2);
125
for(int n =0; n < aInstances; n++){
126
sb.append(INVERLEAVING_CHAR);
127
}
128
129
sb.append(SEARCH_CHAR);
130
131
for(int n =0; n < aInstances; n++){
132
sb.append(INVERLEAVING_CHAR);
133
}
134
135
sb.append(SEARCH_CHAR);
136
137
for(int n =0; n < aInstances; n++){
138
sb.append(INVERLEAVING_CHAR);
139
}
140
return sb.toString();
141
}
142
143
private static int indexOfCharNonIntrinsic(String value, int ch, int fromIndex) {
144
//non intrinsic version of indexOfChar
145
byte c = (byte)ch;
146
for (int i = fromIndex; i < value.length(); i++) {
147
if (value.charAt(i) == c) {
148
return i;
149
}
150
}
151
return -1;
152
}
153
}
154
155