Mercurial > hg > truffle
changeset 14644:07ce8ff3603d
Reduce unncessary list allocations in register allocator
author | Christian Wimmer <christian.wimmer@oracle.com> |
---|---|
date | Thu, 20 Mar 2014 13:41:59 -0700 |
parents | ab8a5b82fe73 |
children | 4f5a97ba0883 |
files | graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScanWalker.java |
diffstat | 1 files changed, 15 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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<Interval> 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<Interval> list = spillIntervals[i]; + if (list == EMPTY_LIST) { + list = new ArrayList<>(2); + spillIntervals[i] = list; + } + list.add(interval); } } }