Skip to content

Commit 9114b53

Browse files
committed
[GR-50983] Make sure ByteBuffer object is kept alive in TStringOpsTest.testWithNative.
PullRequest: graal/16405
2 parents b51f4e2 + 6539d8f commit 9114b53

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public TStringOpsRegionEqualsConstantStrideTest(
5151
super(arrayA, offsetA, lengthA, strideA, fromIndexA, arrayB, offsetB, lengthB, strideB, fromIndexB, lengthCMP);
5252
}
5353

54-
@Parameters(name = "{index}: offset: {1}, {6}, stride: {3}, {8}, length: {12}")
54+
@Parameters(name = "{index}: offset: {1}, {6}, stride: {3}, {8}, length: {10}")
5555
public static List<Object[]> data() {
5656
return TStringOpsRegionEqualsTest.data();
5757
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525
package jdk.graal.compiler.truffle.test.strings;
2626

27+
import java.lang.ref.Reference;
2728
import java.lang.reflect.Constructor;
2829
import java.lang.reflect.Field;
2930
import java.lang.reflect.InvocationTargetException;
@@ -92,8 +93,8 @@ protected void testWithNative(ResolvedJavaMethod method, Object receiver, Object
9293

9394
protected void testWithNativeExcept(ResolvedJavaMethod method, Object receiver, long ignore, Object... args) {
9495
test(method, receiver, args);
96+
Object[] argsWithNative = Arrays.copyOf(args, args.length);
9597
try {
96-
Object[] argsWithNative = Arrays.copyOf(args, args.length);
9798
ResolvedJavaMethod.Parameter[] parameters = method.getParameters();
9899
Assert.assertTrue(parameters.length <= 64);
99100
for (int i = 0; i < parameters.length; i++) {
@@ -103,12 +104,14 @@ protected void testWithNativeExcept(ResolvedJavaMethod method, Object receiver,
103104
ByteBuffer buffer = ByteBuffer.allocateDirect(array.length);
104105
long bufferAddress = getBufferAddress(buffer);
105106
UNSAFE.copyMemory(array, Unsafe.ARRAY_BYTE_BASE_OFFSET, null, bufferAddress, array.length);
106-
argsWithNative[i] = T_STRING_NATIVE_POINTER_CONSTRUCTOR.newInstance(null, bufferAddress);
107+
argsWithNative[i] = T_STRING_NATIVE_POINTER_CONSTRUCTOR.newInstance(buffer, bufferAddress);
107108
}
108109
}
109110
test(method, receiver, argsWithNative);
110111
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
111112
throw new RuntimeException(e);
113+
} finally {
114+
Reference.reachabilityFence(argsWithNative);
112115
}
113116
}
114117

0 commit comments

Comments
 (0)