27
27
import java .io .ByteArrayOutputStream ;
28
28
import java .io .DataOutputStream ;
29
29
import java .io .IOException ;
30
- import java .security .MessageDigest ;
31
- import java .security .NoSuchAlgorithmException ;
32
30
import java .util .List ;
33
31
34
32
import jdk .graal .compiler .debug .DebugContext ;
42
40
import jdk .graal .compiler .nodes .StructuredGraph ;
43
41
import jdk .graal .compiler .nodes .cfg .HIRBlock ;
44
42
import jdk .graal .compiler .phases .schedule .SchedulePhase ;
43
+ import jdk .graal .compiler .util .Digest ;
45
44
46
45
/**
47
46
* A utility class that computes graph signatures and canonical node identity which can be useful
@@ -51,7 +50,7 @@ public class GraphSignature {
51
50
52
51
private int nextId ;
53
52
private final NodeMap <Integer > canonicalId ;
54
- private byte [] signature ;
53
+ private final byte [] signature ;
55
54
56
55
@ SuppressWarnings ("this-escape" )
57
56
public GraphSignature (StructuredGraph graph ) {
@@ -81,21 +80,15 @@ protected byte[] computeSignature(StructuredGraph graph) {
81
80
ByteArrayOutputStream byteArray = new ByteArrayOutputStream ();
82
81
DataOutputStream dos = new DataOutputStream (byteArray );
83
82
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 );
89
84
}
90
85
91
- private static byte [] getSignature (ByteArrayOutputStream byteArray , String algorithm ) throws NoSuchAlgorithmException {
86
+ private static byte [] getSignature (ByteArrayOutputStream byteArray ) {
92
87
byte [] data = byteArray .toByteArray ();
93
88
if (data .length == 0 ) {
94
89
return null ;
95
90
}
96
- MessageDigest digest = MessageDigest .getInstance (algorithm );
97
- digest .update (data );
98
- return digest .digest ();
91
+ return Digest .digestAsByteArray (data , 0 , data .length );
99
92
}
100
93
101
94
private static String getSignatureString (byte [] data ) {
0 commit comments