# HG changeset patch # User Tom Rodriguez # Date 1430529907 25200 # Node ID bee2900f00209d1a91a668efa5dab00d7e9e8dad # Parent 7eb4d233e434b907667d893c65d1f9e5499e6e30 Share properties in IGV diff -r 7eb4d233e434 -r bee2900f0020 src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Properties.java --- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Properties.java Fri May 01 18:24:45 2015 -0700 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Properties.java Fri May 01 18:25:07 2015 -0700 @@ -24,7 +24,9 @@ package com.sun.hotspot.igv.data; import java.io.Serializable; +import java.lang.ref.WeakReference; import java.util.*; +import java.util.Map.Entry; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; @@ -36,7 +38,7 @@ public class Properties implements Serializable, Iterable { public static final long serialVersionUID = 1L; - private String[] map = new String[4]; + protected String[] map = new String[4]; public Properties() { } @@ -101,6 +103,59 @@ map = new String[p.map.length]; System.arraycopy(p.map, 0, map, 0, p.map.length); } + + protected Properties(String[] map) { + this.map = map; + } + + static class SharedProperties extends Properties { + int hashCode; + + SharedProperties(String[] map) { + super(map); + this.hashCode = Arrays.hashCode(map); + } + + @Override + protected void setPropertyInternal(String name, String value) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean equals(Object other) { + if (this == other) { + return true; + } + if (!(other instanceof SharedProperties)) { + return super.equals(other); + } + SharedProperties props2 = (SharedProperties) other; + return Arrays.equals(map, props2.map); + } + + @Override + public int hashCode() { + return hashCode; + } + } + + private static class PropertyCache { + static WeakHashMap> immutableCache = new WeakHashMap<>(); + + static synchronized SharedProperties intern(Properties properties) { + String[] map = properties.map; + SharedProperties key = new SharedProperties(map); + WeakReference entry = immutableCache.get(key); + if (entry != null) { + SharedProperties props = entry.get(); + if (props != null) { + return props; + } + } + immutableCache.put(key, new WeakReference<>(key)); + return key; + } + } public static class Entity implements Provider { @@ -118,6 +173,10 @@ public Properties getProperties() { return properties; } + + public void internProperties() { + properties = PropertyCache.intern(properties); + } } public interface PropertyMatcher { @@ -322,8 +381,8 @@ public void setProperty(String name, String value) { setPropertyInternal(name.intern(), value != null ? value.intern() : null); } - private void setPropertyInternal(String name, String value) { + protected void setPropertyInternal(String name, String value) { for (int i = 0; i < map.length; i += 2) { if (map[i] != null && map[i].equals(name)) { String p = map[i + 1]; diff -r 7eb4d233e434 -r bee2900f0020 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 18:24:45 2015 -0700 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/BinaryParser.java Fri May 01 18:25:07 2015 -0700 @@ -691,6 +691,9 @@ parseNodes(graph); parseBlocks(graph); graph.ensureNodesInBlocks(); + for (InputNode node : graph.getNodes()) { + node.internProperties(); + } return graph; }