Mercurial > hg > truffle
changeset 15951:aef229a61f96
grow NodeMaps exponentially
author | Lukas Stadler <lukas.stadler@oracle.com> |
---|---|
date | Wed, 28 May 2014 17:14:24 +0200 |
parents | e4567f9acc42 |
children | b7748fffea09 |
files | graal/com.oracle.graal.graph.test/src/com/oracle/graal/graph/test/NodeMapTest.java graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeMap.java |
diffstat | 2 files changed, 3 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.graph.test/src/com/oracle/graal/graph/test/NodeMapTest.java Wed May 28 12:17:16 2014 +0200 +++ b/graal/com.oracle.graal.graph.test/src/com/oracle/graal/graph/test/NodeMapTest.java Wed May 28 17:14:24 2014 +0200 @@ -121,17 +121,4 @@ map.setAndGrow(newNode, 1); assertEquals((Integer) 1, map.get(newNode)); } - - @Test(expected = AssertionError.class) - public void testNewSetAndGrowMultiple() { - TestNode newNode = graph.add(new TestNode()); - map.setAndGrow(newNode, 1); - assertEquals((Integer) 1, map.get(newNode)); - /* - * Failing here is not required, but if this behavior changes, usages of getAndGrow and - * setAndGrow need to be checked for compatibility. - */ - TestNode newNode2 = graph.add(new TestNode()); - map.get(newNode2); - } }
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeMap.java Wed May 28 12:17:16 2014 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeMap.java Wed May 28 17:14:24 2014 +0200 @@ -28,6 +28,8 @@ public class NodeMap<T> extends NodeIdAccessor { + private static final int MIN_REALLOC_SIZE = 16; + protected Object[] values; public NodeMap(Graph graph) { @@ -54,7 +56,7 @@ private void checkAndGrow(Node node) { if (isNew(node)) { - this.values = Arrays.copyOf(values, graph.nodeIdCount()); + this.values = Arrays.copyOf(values, Math.max(MIN_REALLOC_SIZE, graph.nodeIdCount() * 3 / 2)); } assert check(node); }