Skip to content

Commit

Permalink
compiler: adopt "JDK-8332826: Make hashCode methods in ArraysSupport …
Browse files Browse the repository at this point in the history
…friendlier"
  • Loading branch information
zapster committed May 30, 2024
1 parent f1a2d95 commit 59a170e
Showing 1 changed file with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
package jdk.graal.compiler.replacements.test;

import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.Set;
Expand All @@ -40,13 +41,24 @@
@AddExports({"java.base/jdk.internal.util"})
public class VectorizedHashCodeTest extends GraalCompilerTest {

private static int getField(String name) {
try {
var arraysSupport = Class.forName("jdk.internal.util.ArraysSupport");
Field f = arraysSupport.getDeclaredField(name);
f.setAccessible(true);
return f.getInt(null);
} catch (Throwable e) {
throw new RuntimeException(e);
}
}

@Test
public void testJDKConstantValue() {
Assert.assertEquals(ArraysSupport.T_BOOLEAN, VectorizedHashCodeInvocationPlugin.T_BOOLEAN);
Assert.assertEquals(ArraysSupport.T_CHAR, VectorizedHashCodeInvocationPlugin.T_CHAR);
Assert.assertEquals(ArraysSupport.T_BYTE, VectorizedHashCodeInvocationPlugin.T_BYTE);
Assert.assertEquals(ArraysSupport.T_SHORT, VectorizedHashCodeInvocationPlugin.T_SHORT);
Assert.assertEquals(ArraysSupport.T_INT, VectorizedHashCodeInvocationPlugin.T_INT);
Assert.assertEquals(getField("T_BOOLEAN"), VectorizedHashCodeInvocationPlugin.T_BOOLEAN);
Assert.assertEquals(getField("T_CHAR"), VectorizedHashCodeInvocationPlugin.T_CHAR);
Assert.assertEquals(getField("T_BYTE"), VectorizedHashCodeInvocationPlugin.T_BYTE);
Assert.assertEquals(getField("T_SHORT"), VectorizedHashCodeInvocationPlugin.T_SHORT);
Assert.assertEquals(getField("T_INT"), VectorizedHashCodeInvocationPlugin.T_INT);
}

// @formatter:off
Expand Down Expand Up @@ -89,7 +101,7 @@ private void testHash(String method, Function<byte[], Object> f, Function<byte[]
}

public static int hashByteArray(byte[] array, int fromIndex, int length, int initialValue) {
return ArraysSupport.vectorizedHashCode(array, fromIndex, length, initialValue, ArraysSupport.T_BYTE);
return ArraysSupport.hashCode(array, fromIndex, length, initialValue);
}

@Test
Expand All @@ -98,16 +110,16 @@ public void testHashByteArray() {
}

public static int hashByteArrayCharElement(byte[] array, int fromIndex, int length, int initialValue) {
return ArraysSupport.vectorizedHashCode(array, fromIndex, length, initialValue, ArraysSupport.T_CHAR);
return ArraysSupport.hashCode(array, fromIndex, length, initialValue);
}

@Test
public void testHashByteArrayCharElement() {
testHash("hashByteArrayCharElement", a -> a, a -> a.length / 2);
}

public static int hashBooleanArray(Object array, int fromIndex, int length, int initialValue) {
return ArraysSupport.vectorizedHashCode(array, fromIndex, length, initialValue, ArraysSupport.T_BOOLEAN);
public static int hashBooleanArray(byte[] array, int fromIndex, int length, int initialValue) {
return ArraysSupport.hashCode(array, fromIndex, length, initialValue);
}

@Test
Expand All @@ -124,7 +136,7 @@ public void testHashBooleanArray() {
}

public static int hashCharArray(char[] array, int fromIndex, int length, int initialValue) {
return ArraysSupport.vectorizedHashCode(array, fromIndex, length, initialValue, ArraysSupport.T_CHAR);
return ArraysSupport.hashCode(array, fromIndex, length, initialValue);
}

@Test
Expand All @@ -139,7 +151,7 @@ public void testHashCharArray() {
}

public static int hashShortArray(short[] array, int fromIndex, int length, int initialValue) {
return ArraysSupport.vectorizedHashCode(array, fromIndex, length, initialValue, ArraysSupport.T_SHORT);
return ArraysSupport.hashCode(array, fromIndex, length, initialValue);
}

@Test
Expand All @@ -154,7 +166,7 @@ public void testHashShortArray() {
}

public static int hashIntArray(int[] array, int fromIndex, int length, int initialValue) {
return ArraysSupport.vectorizedHashCode(array, fromIndex, length, initialValue, ArraysSupport.T_INT);
return ArraysSupport.hashCode(array, fromIndex, length, initialValue);
}

@Test
Expand Down

0 comments on commit 59a170e

Please sign in to comment.