# HG changeset patch # User Tom Rodriguez # Date 1430525031 25200 # Node ID 4518107de3dbc50cd815ee9e3ce95218d233479b # Parent d5c1f00373c7e56c65d5e15f87f11374bd783db4 Reduce overhead of hash computation for graph identity checks diff -r d5c1f00373c7 -r 4518107de3db src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/BinaryParser.java --- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/BinaryParser.java Fri May 01 17:02:38 2015 -0700 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/BinaryParser.java Fri May 01 17:03:51 2015 -0700 @@ -275,28 +275,33 @@ hashStack = new LinkedList<>(); this.monitor = monitor; try { - this.digest = MessageDigest.getInstance("SHA-256"); + this.digest = MessageDigest.getInstance("SHA-1"); } catch (NoSuchAlgorithmException e) { } } private void fill() throws IOException { + // All the data between lastPosition and position has been + // used so add it to the digest. + int position = buffer.position(); + buffer.position(lastPosition); + byte[] remaining = new byte[position - buffer.position()]; + buffer.get(remaining); + digest.update(remaining); + assert position == buffer.position(); + buffer.compact(); if (channel.read(buffer) < 0) { throw new EOFException(); } buffer.flip(); + lastPosition = buffer.position(); } private void ensureAvailable(int i) throws IOException { while (buffer.remaining() < i) { fill(); } - buffer.mark(); - byte[] result = new byte[i]; - buffer.get(result); - digest.update(result); - buffer.reset(); } private int readByte() throws IOException { @@ -650,6 +655,8 @@ } return group; } + + int lastPosition = 0; private InputGraph parseGraph() throws IOException { if (monitor != null) { @@ -657,7 +664,17 @@ } String title = readPoolObject(String.class); digest.reset(); + lastPosition = buffer.position(); InputGraph graph = parseGraph(title); + + int position = buffer.position(); + buffer.position(lastPosition); + byte[] remaining = new byte[position - buffer.position()]; + buffer.get(remaining); + digest.update(remaining); + assert position == buffer.position(); + lastPosition = buffer.position(); + byte[] d = digest.digest(); byte[] hash = hashStack.peek(); if (hash != null && Arrays.equals(hash, d)) { @@ -822,9 +839,10 @@ } } + static final Pattern templatePattern = Pattern.compile("\\{(p|i)#([a-zA-Z0-9$_]+)(/(l|m|s))?\\}"); + private String createName(List edges, Map properties, String template) { - Pattern p = Pattern.compile("\\{(p|i)#([a-zA-Z0-9$_]+)(/(l|m|s))?\\}"); - Matcher m = p.matcher(template); + Matcher m = templatePattern.matcher(template); StringBuffer sb = new StringBuffer(); while (m.find()) { String name = m.group(2);