Skip to content

Commit e3ef253

Browse files
committed
[GR-65488] Use a non-cryptographic hash algorithm implementation for GraphSignature.
PullRequest: graal/20979
2 parents 333677c + 131695a commit e3ef253

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/phases/util/GraphSignature.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import java.io.ByteArrayOutputStream;
2828
import java.io.DataOutputStream;
2929
import java.io.IOException;
30-
import java.security.MessageDigest;
31-
import java.security.NoSuchAlgorithmException;
3230
import java.util.List;
3331

3432
import jdk.graal.compiler.debug.DebugContext;
@@ -42,6 +40,7 @@
4240
import jdk.graal.compiler.nodes.StructuredGraph;
4341
import jdk.graal.compiler.nodes.cfg.HIRBlock;
4442
import jdk.graal.compiler.phases.schedule.SchedulePhase;
43+
import jdk.graal.compiler.util.Digest;
4544

4645
/**
4746
* A utility class that computes graph signatures and canonical node identity which can be useful
@@ -51,7 +50,7 @@ public class GraphSignature {
5150

5251
private int nextId;
5352
private final NodeMap<Integer> canonicalId;
54-
private byte[] signature;
53+
private final byte[] signature;
5554

5655
@SuppressWarnings("this-escape")
5756
public GraphSignature(StructuredGraph graph) {
@@ -81,21 +80,15 @@ protected byte[] computeSignature(StructuredGraph graph) {
8180
ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
8281
DataOutputStream dos = new DataOutputStream(byteArray);
8382
computeFromSchedule(graph, dos);
84-
try {
85-
return getSignature(byteArray, "SHA-512");
86-
} catch (NoSuchAlgorithmException e) {
87-
throw new GraalError(e);
88-
}
83+
return getSignature(byteArray);
8984
}
9085

91-
private static byte[] getSignature(ByteArrayOutputStream byteArray, String algorithm) throws NoSuchAlgorithmException {
86+
private static byte[] getSignature(ByteArrayOutputStream byteArray) {
9287
byte[] data = byteArray.toByteArray();
9388
if (data.length == 0) {
9489
return null;
9590
}
96-
MessageDigest digest = MessageDigest.getInstance(algorithm);
97-
digest.update(data);
98-
return digest.digest();
91+
return Digest.digestAsByteArray(data, 0, data.length);
9992
}
10093

10194
private static String getSignatureString(byte[] data) {

0 commit comments

Comments
 (0)