Skip to content

Commit 199fbe4

Browse files
committed
[GR-69853] TRegex: add support for big-endian UTF-16 and UTF-32.
PullRequest: graal/22372
2 parents d10978a + 6d6cf83 commit 199fbe4

File tree

151 files changed

+3606
-3747
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

151 files changed

+3606
-3747
lines changed

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/strings/TStringOpsCalcStringAttributesUTF16ConstantTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ public void testUnknown() {
5757
test(getTStringOpsMethod("calcStringAttributesUTF16", byte[].class, long.class, int.class, boolean.class), null, DUMMY_LOCATION, arrayA, offsetA, lengthA, false);
5858
}
5959

60+
@Test
61+
public void testForeignEndianValid() {
62+
byte[] swappedArray = byteSwapArray(arrayA, 1);
63+
setConstantArgs(DUMMY_LOCATION, swappedArray, offsetA, lengthA);
64+
test(getTStringOpsMethod("calcStringAttributesUTF16FEAssumeValid", byte[].class, long.class, int.class), null, DUMMY_LOCATION, swappedArray, offsetA, lengthA);
65+
}
66+
67+
@Test
68+
public void testForeignEndianUnknown() {
69+
byte[] swappedArray = byteSwapArray(arrayA, 1);
70+
setConstantArgs(DUMMY_LOCATION, swappedArray, offsetA, lengthA);
71+
test(getTStringOpsMethod("calcStringAttributesUTF16FE", byte[].class, long.class, int.class), null, DUMMY_LOCATION, swappedArray, offsetA, lengthA);
72+
}
73+
6074
@Test
6175
public void testUnknownC() {
6276
char[] charArray = toCharArray(arrayA);

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/strings/TStringOpsCalcStringAttributesUTF16Test.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,16 @@ public void testUnknown() {
210210
testWithNative(getTStringOpsMethod("calcStringAttributesUTF16", byte[].class, long.class, int.class, boolean.class), null, DUMMY_LOCATION, array, offset, length, false);
211211
}
212212

213+
@Test
214+
public void testForeignEndianValid() {
215+
testWithNative(getTStringOpsMethod("calcStringAttributesUTF16FEAssumeValid", byte[].class, long.class, int.class), null, DUMMY_LOCATION, byteSwapArray(array, 1), offset, length);
216+
}
217+
218+
@Test
219+
public void testForeignEndianUnknown() {
220+
testWithNative(getTStringOpsMethod("calcStringAttributesUTF16FE", byte[].class, long.class, int.class), null, DUMMY_LOCATION, byteSwapArray(array, 1), offset, length);
221+
}
222+
213223
@Test
214224
public void testUnknownC() {
215225
test(getTStringOpsMethod("calcStringAttributesUTF16C", char[].class, long.class, int.class), null, DUMMY_LOCATION, toCharArray(array), offset - byteArrayBaseOffset() + charArrayBaseOffset(),

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/strings/TStringOpsCalcStringAttributesUTF32ConstantTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ public void testUTF32() {
5151
test(getTStringOpsMethod("calcStringAttributesUTF32", byte[].class, long.class, int.class), null, DUMMY_LOCATION, arrayA, offsetA, lengthA);
5252
}
5353

54+
@Test
55+
public void testUTF32ForeignEndian() {
56+
byte[] swappedArray = byteSwapArray(arrayA, 2);
57+
setConstantArgs(DUMMY_LOCATION, swappedArray, offsetA, lengthA);
58+
test(getTStringOpsMethod("calcStringAttributesUTF32FE", byte[].class, long.class, int.class), null, DUMMY_LOCATION, swappedArray, offsetA, lengthA);
59+
}
60+
5461
@Test
5562
public void testUTF32I() {
5663
int[] intArray = toIntArray(arrayA);

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/strings/TStringOpsCalcStringAttributesUTF32Test.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ public void testUTF32() {
109109
testWithNative(getTStringOpsMethod("calcStringAttributesUTF32", byte[].class, long.class, int.class), null, DUMMY_LOCATION, array, offset, length);
110110
}
111111

112+
@Test
113+
public void testUTF32FE() {
114+
testWithNative(getTStringOpsMethod("calcStringAttributesUTF32FE", byte[].class, long.class, int.class), null, DUMMY_LOCATION, byteSwapArray(array, 2), offset, length);
115+
}
116+
112117
@Test
113118
public void testUTF32I() {
114119
test(getTStringOpsMethod("calcStringAttributesUTF32I", int[].class, long.class, int.class), null, DUMMY_LOCATION, toIntArray(array), offset - byteArrayBaseOffset() + intArrayBaseOffset(),

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/strings/TStringOpsCodepointIndexToByteIndexUTF16Test.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ public static Iterable<Object[]> data() {
106106
return ret;
107107
}
108108

109-
private final Object array;
109+
private final byte[] array;
110110
private final long offset;
111111
private final int length;
112112
private final int index;
113113

114-
public TStringOpsCodepointIndexToByteIndexUTF16Test(Object array, int offset, int length, int index) {
114+
public TStringOpsCodepointIndexToByteIndexUTF16Test(byte[] array, int offset, int length, int index) {
115115
super(StringCodepointIndexToByteIndexNode.class);
116116
this.array = array;
117117
this.offset = offset + byteArrayBaseOffset();
@@ -125,4 +125,11 @@ public void testUtf16() {
125125
ResolvedJavaMethod method = getTStringOpsMethod("codePointIndexToByteIndexUTF16Valid", byte[].class, long.class, int.class, int.class);
126126
testWithNative(method, null, DUMMY_LOCATION, array, offset, length, index);
127127
}
128+
129+
@Test
130+
public void testUtf16FE() {
131+
Assume.assumeTrue(getArchitecture() instanceof AMD64);
132+
ResolvedJavaMethod method = getTStringOpsMethod("codePointIndexToByteIndexUTF16FEValid", byte[].class, long.class, int.class, int.class);
133+
testWithNative(method, null, DUMMY_LOCATION, byteSwapArray(array, 1), offset, length, index);
134+
}
128135
}

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/strings/TStringOpsCompareConstantStrideTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ protected GraphBuilderConfiguration editGraphBuilderConfiguration(GraphBuilderCo
6666

6767
@Override
6868
protected InstalledCode getCode(final ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, boolean ignoreForceCompile, boolean ignoreInstallAsDefault, OptionValues options) {
69-
return cacheInstalledCodeConstantStride(installedCodeOwner, graph, options, getMemcmpWithStrideIntl(), cache.get(), strideA, strideB);
69+
return cacheInstalledCodeConstantStride(installedCodeOwner, graph, options, getMemcmpWithStride(), cache.get(), strideA, strideB);
7070
}
7171

7272
@Override
7373
@Test
7474
public void testMemCmp() {
7575
constantArgs[3] = strideA;
7676
constantArgs[6] = strideB;
77-
testWithNative(getMemcmpWithStrideIntl(), null, DUMMY_LOCATION,
77+
testWithNative(getMemcmpWithStride(), null, DUMMY_LOCATION,
7878
arrayA, offsetA, strideA,
7979
arrayB, offsetB, strideB, lengthCMP);
8080
}

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/strings/TStringOpsCompareConstantTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ protected InstalledCode getCode(final ResolvedJavaMethod installedCodeOwner, Str
7777
@Override
7878
@Test
7979
public void testMemCmp() {
80-
test(getMemcmpWithStrideIntl(), null, DUMMY_LOCATION,
80+
test(getMemcmpWithStride(), null, DUMMY_LOCATION,
8181
arrayA, offsetA, strideA,
8282
arrayB, offsetB, strideB, lengthCMP);
8383
}

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/strings/TStringOpsCompareTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public TStringOpsCompareTest(
111111

112112
@Test
113113
public void testMemCmp() {
114-
testWithNative(getMemcmpWithStrideIntl(), null, DUMMY_LOCATION,
114+
testWithNative(getMemcmpWithStride(), null, DUMMY_LOCATION,
115115
arrayA, offsetA, strideA,
116116
arrayB, offsetB, strideB, lengthCMP);
117117
}

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/strings/TStringOpsIndexOfAnyRangeTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,19 @@ public TStringOpsIndexOfAnyRangeTest(byte[] arrayA, int offsetA, int lengthA, in
114114

115115
@Test
116116
public void testIndexOfAnyRange() {
117+
test(getIndexOfAnyIntRangeIntl(), null, DUMMY_LOCATION, arrayA, offsetA, lengthA, strideA, fromIndexA, clampedValues());
118+
}
119+
120+
@Test
121+
public void testIndexOfAnyRangeForeignEndian() {
122+
test(getIndexOfAnyIntRangeForeignEndianIntl(), null, DUMMY_LOCATION, byteSwapArray(arrayA, strideA), offsetA, lengthA, strideA, fromIndexA, clampedValues());
123+
}
124+
125+
private int[] clampedValues() {
117126
int[] valuesI = new int[values.length];
118127
for (int i = 0; i < values.length; i++) {
119128
valuesI[i] = strideA == 0 ? values[i] & 0xff : strideA == 1 ? values[i] & 0xffff : values[i];
120129
}
121-
test(getIndexOfAnyIntRangeIntl(), null, DUMMY_LOCATION, arrayA, offsetA, lengthA, strideA, fromIndexA, valuesI);
130+
return valuesI;
122131
}
123132
}

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/strings/TStringOpsIndexOfTableTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,12 @@ public TStringOpsIndexOfTableTest(byte[] arrayA, int offsetA, int lengthA, int s
112112
}
113113

114114
@Test
115-
public void testIndexOfAny() {
115+
public void testIndexOfTable() {
116116
test(getIndexOfTableIntl(), null, DUMMY_LOCATION, arrayA, offsetA, lengthA, strideA, fromIndexA, table);
117117
}
118+
119+
@Test
120+
public void testIndexOfTableForeignEndian() {
121+
test(getIndexOfTableForeignEndianIntl(), null, DUMMY_LOCATION, byteSwapArray(arrayA, strideA), offsetA, lengthA, strideA, fromIndexA, table);
122+
}
118123
}

0 commit comments

Comments
 (0)