# HG changeset patch # User Christian Wimmer # Date 1395348119 25200 # Node ID 07ce8ff3603d66d2fd9de3a75f8dcd5f003ccf08 # Parent ab8a5b82fe7335e95905a0ed5922b020db143af7 Reduce unncessary list allocations in register allocator diff -r ab8a5b82fe73 -r 07ce8ff3603d graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScanWalker.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScanWalker.java Thu Mar 20 20:40:11 2014 +0100 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScanWalker.java Thu Mar 20 13:41:59 2014 -0700 @@ -53,6 +53,14 @@ private MoveResolver moveResolver; // for ordering spill moves + /** + * Only 10% of the lists in {@link #spillIntervals} are actually used. But when they are used, + * they can grow quite long. The maximum length observed was 45 (all numbers taken from a + * bootstrap run of Graal). Therefore, we initialize {@link #spillIntervals} with this marker + * value, and allocate a "real" list only on demand in {@link #setUsePos}. + */ + private static final List EMPTY_LIST = new ArrayList<>(0); + // accessors mapped to same functions in class LinearScan int blockCount() { return allocator.blockCount(); @@ -76,7 +84,7 @@ moveResolver = new MoveResolver(allocator); spillIntervals = Util.uncheckedCast(new List[allocator.registers.length]); for (int i = 0; i < allocator.registers.length; i++) { - spillIntervals[i] = new ArrayList<>(2); + spillIntervals[i] = EMPTY_LIST; } usePos = new int[allocator.registers.length]; blockPos = new int[allocator.registers.length]; @@ -111,7 +119,12 @@ this.usePos[i] = usePos; } if (!onlyProcessUsePos) { - spillIntervals[i].add(interval); + List list = spillIntervals[i]; + if (list == EMPTY_LIST) { + list = new ArrayList<>(2); + spillIntervals[i] = list; + } + list.add(interval); } } }