Skip to content

Commit b8693d3

Browse files
committed
[GR-50017] TruffleStrings: internal refactoring for better performance in statically compiled code.
PullRequest: graal/19999
2 parents 67d54bb + 2f28115 commit b8693d3

File tree

105 files changed

+6396
-4648
lines changed

Some content is hidden

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

105 files changed

+6396
-4648
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ public TStringOpsCalcStringAttributesBMPConstantTest(byte[] array, int offset, i
4848
@Test
4949
public void testBMP() {
5050
setConstantArgs(DUMMY_LOCATION, arrayA, offsetA, lengthA);
51-
test(getTStringOpsMethod("calcStringAttributesBMP", Object.class, int.class, int.class), null, DUMMY_LOCATION, arrayA, offsetA, lengthA);
51+
test(getTStringOpsMethod("calcStringAttributesBMP", byte[].class, long.class, int.class), null, DUMMY_LOCATION, arrayA, offsetA, lengthA);
5252
}
5353
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,18 @@ public static List<Object[]> data() {
8787
}
8888

8989
final byte[] array;
90-
final int offset;
90+
final long offset;
9191
final int length;
9292

9393
public TStringOpsCalcStringAttributesBMPTest(byte[] array, int offset, int length) {
9494
super(CalcStringAttributesNode.class);
9595
this.array = array;
96-
this.offset = offset;
96+
this.offset = offset + byteArrayBaseOffset();
9797
this.length = length;
9898
}
9999

100100
@Test
101101
public void testBMP() {
102-
testWithNative(getTStringOpsMethod("calcStringAttributesBMP", Object.class, int.class, int.class), null, DUMMY_LOCATION, array, offset, length);
102+
testWithNative(getTStringOpsMethod("calcStringAttributesBMP", byte[].class, long.class, int.class), null, DUMMY_LOCATION, array, offset, length);
103103
}
104104
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class TStringOpsCalcStringAttributesLatin1ConstantRegionOOBTest extends T
4444

4545
static {
4646
try {
47-
Method methodLatin1 = T_STRING_OPS_CLASS.getDeclaredMethod("calcStringAttributesLatin1", com.oracle.truffle.api.nodes.Node.class, Object.class, int.class, int.class);
47+
Method methodLatin1 = T_STRING_OPS_CLASS.getDeclaredMethod("calcStringAttributesLatin1", com.oracle.truffle.api.nodes.Node.class, byte[].class, long.class, int.class);
4848
methodLatin1.setAccessible(true);
4949
calcLatin1 = MethodHandles.lookup().unreflect(methodLatin1);
5050
} catch (NoSuchMethodException | IllegalAccessException e) {
@@ -71,13 +71,13 @@ public TStringOpsCalcStringAttributesLatin1ConstantRegionOOBTest(int offset, int
7171
public void testConstantRegionOutOfBounds() throws Throwable {
7272
setConstantArgs(arrayA, offsetA, lengthA);
7373
// Make calcStringAttributesLatin1 branch reachable (must be in bounds)
74-
runTestMethod(arrayA, 2, 2, true);
74+
runTestMethod(arrayA, 2 + byteArrayBaseOffset(), 2, true);
7575
// Run and compile with constant offset + length out of bounds in the not taken branch.
7676
runTestMethod(arrayA, offsetA, lengthA, false);
7777
test("runTestMethod", arrayA, offsetA, lengthA, false);
7878
}
7979

80-
public static long runTestMethod(Object array, int offset, int length, boolean condition) throws Throwable {
80+
public static long runTestMethod(byte[] array, long offset, int length, boolean condition) throws Throwable {
8181
if (condition) {
8282
return (int) calcLatin1.invokeExact(DUMMY_LOCATION, array, offset, length);
8383
} else {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ public TStringOpsCalcStringAttributesLatin1ConstantTest(byte[] array, int offset
4848
@Test
4949
public void testLatin1() {
5050
setConstantArgs(DUMMY_LOCATION, arrayA, offsetA, lengthA);
51-
test(getTStringOpsMethod("calcStringAttributesLatin1", Object.class, int.class, int.class), null, DUMMY_LOCATION, arrayA, offsetA, lengthA);
51+
test(getTStringOpsMethod("calcStringAttributesLatin1", byte[].class, long.class, int.class), null, DUMMY_LOCATION, arrayA, offsetA, lengthA);
5252
}
5353
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,18 @@ public static List<Object[]> data() {
6666
}
6767

6868
final byte[] array;
69-
final int offset;
69+
final long offset;
7070
final int length;
7171

7272
public TStringOpsCalcStringAttributesLatin1Test(byte[] array, int offset, int length) {
7373
super(CalcStringAttributesNode.class);
7474
this.array = array;
75-
this.offset = offset;
75+
this.offset = offset + byteArrayBaseOffset();
7676
this.length = length;
7777
}
7878

7979
@Test
8080
public void testLatin1() {
81-
testWithNative(getTStringOpsMethod("calcStringAttributesLatin1", Object.class, int.class, int.class), null, DUMMY_LOCATION, array, offset, length);
81+
testWithNative(getTStringOpsMethod("calcStringAttributesLatin1", byte[].class, long.class, int.class), null, DUMMY_LOCATION, array, offset, length);
8282
}
8383
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ public class TStringOpsCalcStringAttributesMixedConstantTest extends TStringOpsC
4040

4141
static {
4242
try {
43-
Method methodLatin1 = T_STRING_OPS_CLASS.getDeclaredMethod("calcStringAttributesLatin1", com.oracle.truffle.api.nodes.Node.class, Object.class, int.class, int.class);
43+
Method methodLatin1 = T_STRING_OPS_CLASS.getDeclaredMethod("calcStringAttributesLatin1", com.oracle.truffle.api.nodes.Node.class, byte[].class, long.class, int.class);
4444
methodLatin1.setAccessible(true);
4545
calcLatin1 = MethodHandles.lookup().unreflect(methodLatin1);
46-
Method methodUTF16 = T_STRING_OPS_CLASS.getDeclaredMethod("calcStringAttributesUTF16", com.oracle.truffle.api.nodes.Node.class, Object.class, int.class, int.class, boolean.class);
46+
Method methodUTF16 = T_STRING_OPS_CLASS.getDeclaredMethod("calcStringAttributesUTF16", com.oracle.truffle.api.nodes.Node.class, byte[].class, long.class, int.class, boolean.class);
4747
methodUTF16.setAccessible(true);
4848
calcUTF16 = MethodHandles.lookup().unreflect(methodUTF16);
4949
} catch (NoSuchMethodException | IllegalAccessException e) {
@@ -63,7 +63,7 @@ public void testMixed() throws Throwable {
6363
test("runTestMethod", arrayA, offsetA, lengthA, false);
6464
}
6565

66-
public static long runTestMethod(Object array, int offset, int length, boolean condition) throws Throwable {
66+
public static long runTestMethod(byte[] array, long offset, int length, boolean condition) throws Throwable {
6767
if (condition) {
6868
return (long) calcUTF16.invokeExact(DUMMY_LOCATION, array, offset, length, false);
6969
} else {

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,20 @@ public TStringOpsCalcStringAttributesUTF16ConstantTest(byte[] array, int offset,
4848
@Test
4949
public void testValid() {
5050
setConstantArgs(DUMMY_LOCATION, arrayA, offsetA, lengthA, true);
51-
test(getTStringOpsMethod("calcStringAttributesUTF16", Object.class, int.class, int.class, boolean.class), null, DUMMY_LOCATION, arrayA, offsetA, lengthA, true);
51+
test(getTStringOpsMethod("calcStringAttributesUTF16", byte[].class, long.class, int.class, boolean.class), null, DUMMY_LOCATION, arrayA, offsetA, lengthA, true);
5252
}
5353

5454
@Test
5555
public void testUnknown() {
5656
setConstantArgs(DUMMY_LOCATION, arrayA, offsetA, lengthA, false);
57-
test(getTStringOpsMethod("calcStringAttributesUTF16", Object.class, int.class, int.class, boolean.class), null, DUMMY_LOCATION, arrayA, offsetA, lengthA, false);
57+
test(getTStringOpsMethod("calcStringAttributesUTF16", byte[].class, long.class, int.class, boolean.class), null, DUMMY_LOCATION, arrayA, offsetA, lengthA, false);
5858
}
5959

6060
@Test
6161
public void testUnknownC() {
6262
char[] charArray = toCharArray(arrayA);
63-
setConstantArgs(DUMMY_LOCATION, charArray, offsetA, lengthA);
64-
test(getTStringOpsMethod("calcStringAttributesUTF16C", char[].class, int.class, int.class), null, DUMMY_LOCATION, charArray, offsetA, lengthA);
63+
long offsetCharArray = offsetA - byteArrayBaseOffset() + charArrayBaseOffset();
64+
setConstantArgs(DUMMY_LOCATION, charArray, offsetCharArray, lengthA);
65+
test(getTStringOpsMethod("calcStringAttributesUTF16C", char[].class, long.class, int.class), null, DUMMY_LOCATION, charArray, offsetCharArray, lengthA);
6566
}
6667
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,28 +190,29 @@ private static int writeCodePoint(byte[] array, int index, int cp, boolean forwa
190190
}
191191

192192
final byte[] array;
193-
final int offset;
193+
final long offset;
194194
final int length;
195195

196196
public TStringOpsCalcStringAttributesUTF16Test(byte[] array, int offset, int length) {
197197
super(CalcStringAttributesNode.class);
198198
this.array = array;
199-
this.offset = offset;
199+
this.offset = offset + byteArrayBaseOffset();
200200
this.length = length;
201201
}
202202

203203
@Test
204204
public void testValid() {
205-
testWithNative(getTStringOpsMethod("calcStringAttributesUTF16", Object.class, int.class, int.class, boolean.class), null, DUMMY_LOCATION, array, offset, length, true);
205+
testWithNative(getTStringOpsMethod("calcStringAttributesUTF16", byte[].class, long.class, int.class, boolean.class), null, DUMMY_LOCATION, array, offset, length, true);
206206
}
207207

208208
@Test
209209
public void testUnknown() {
210-
testWithNative(getTStringOpsMethod("calcStringAttributesUTF16", Object.class, int.class, int.class, boolean.class), null, DUMMY_LOCATION, array, offset, length, false);
210+
testWithNative(getTStringOpsMethod("calcStringAttributesUTF16", byte[].class, long.class, int.class, boolean.class), null, DUMMY_LOCATION, array, offset, length, false);
211211
}
212212

213213
@Test
214214
public void testUnknownC() {
215-
test(getTStringOpsMethod("calcStringAttributesUTF16C", char[].class, int.class, int.class), null, DUMMY_LOCATION, toCharArray(array), offset, length);
215+
test(getTStringOpsMethod("calcStringAttributesUTF16C", char[].class, long.class, int.class), null, DUMMY_LOCATION, toCharArray(array), offset - byteArrayBaseOffset() + charArrayBaseOffset(),
216+
length);
216217
}
217218
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,15 @@ public TStringOpsCalcStringAttributesUTF32ConstantTest(byte[] array, int offset,
4848
@Test
4949
public void testUTF32() {
5050
setConstantArgs(DUMMY_LOCATION, arrayA, offsetA, lengthA);
51-
test(getTStringOpsMethod("calcStringAttributesUTF32", Object.class, int.class, int.class), null, DUMMY_LOCATION, arrayA, offsetA, lengthA);
51+
test(getTStringOpsMethod("calcStringAttributesUTF32", byte[].class, long.class, int.class), null, DUMMY_LOCATION, arrayA, offsetA, lengthA);
5252
}
5353

5454
@Test
5555
public void testUTF32I() {
5656
int[] intArray = toIntArray(arrayA);
57-
setConstantArgs(DUMMY_LOCATION, intArray, offsetA, lengthA);
58-
test(getTStringOpsMethod("calcStringAttributesUTF32I", int[].class, int.class, int.class), null, DUMMY_LOCATION, intArray, offsetA, lengthA);
57+
long offsetIntArray = offsetA - byteArrayBaseOffset() + intArrayBaseOffset();
58+
setConstantArgs(DUMMY_LOCATION, intArray, offsetIntArray, lengthA);
59+
test(getTStringOpsMethod("calcStringAttributesUTF32I", int[].class, long.class, int.class), null, DUMMY_LOCATION, intArray, offsetIntArray, lengthA);
5960
}
6061

6162
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,24 @@ public static List<Object[]> data() {
9494
}
9595

9696
final byte[] array;
97-
final int offset;
97+
final long offset;
9898
final int length;
9999

100100
public TStringOpsCalcStringAttributesUTF32Test(byte[] array, int offset, int length) {
101101
super(CalcStringAttributesNode.class);
102102
this.array = array;
103-
this.offset = offset;
103+
this.offset = offset + byteArrayBaseOffset();
104104
this.length = length;
105105
}
106106

107107
@Test
108108
public void testUTF32() {
109-
testWithNative(getTStringOpsMethod("calcStringAttributesUTF32", Object.class, int.class, int.class), null, DUMMY_LOCATION, array, offset, length);
109+
testWithNative(getTStringOpsMethod("calcStringAttributesUTF32", byte[].class, long.class, int.class), null, DUMMY_LOCATION, array, offset, length);
110110
}
111111

112112
@Test
113113
public void testUTF32I() {
114-
test(getTStringOpsMethod("calcStringAttributesUTF32I", int[].class, int.class, int.class), null, DUMMY_LOCATION, toIntArray(array), offset, length);
114+
test(getTStringOpsMethod("calcStringAttributesUTF32I", int[].class, long.class, int.class), null, DUMMY_LOCATION, toIntArray(array), offset - byteArrayBaseOffset() + intArrayBaseOffset(),
115+
length);
115116
}
116117
}

0 commit comments

Comments
 (0)