changeset 19162:c06f39fa2228

Move HIR independent utilities to c.o.g.compiler.common.
author Josef Eisl <josef.eisl@jku.at>
date Wed, 04 Feb 2015 18:24:05 +0100
parents ce68659c641f
children 0751ebc54c13
files graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/util/ArrayMap.java graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/util/ArraySet.java graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/util/BitMap2D.java graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/util/IntList.java graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/util/Util.java graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/Interval.java graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScan.java graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScanWalker.java graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/RegisterVerifier.java graal/com.oracle.graal.phases/src/com/oracle/graal/phases/util/ArrayMap.java graal/com.oracle.graal.phases/src/com/oracle/graal/phases/util/ArraySet.java graal/com.oracle.graal.phases/src/com/oracle/graal/phases/util/BitMap2D.java graal/com.oracle.graal.phases/src/com/oracle/graal/phases/util/IntList.java graal/com.oracle.graal.phases/src/com/oracle/graal/phases/util/Util.java graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapeClosure.java
diffstat 16 files changed, 777 insertions(+), 776 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java	Wed Feb 04 18:21:29 2015 +0100
+++ b/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java	Wed Feb 04 18:24:05 2015 +0100
@@ -38,6 +38,7 @@
 import com.oracle.graal.compiler.common.*;
 import com.oracle.graal.compiler.common.calc.*;
 import com.oracle.graal.compiler.common.spi.*;
+import com.oracle.graal.compiler.common.util.*;
 import com.oracle.graal.lir.*;
 import com.oracle.graal.lir.StandardOp.JumpOp;
 import com.oracle.graal.lir.amd64.*;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/util/ArrayMap.java	Wed Feb 04 18:24:05 2015 +0100
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.compiler.common.util;
+
+/**
+ * The {@code ArrayMap} class implements an efficient one-level map which is implemented as an
+ * array. Note that because of the one-level array inside, this data structure performs best when
+ * the range of integer keys is small and densely used. Note that the implementation can handle
+ * arbitrary intervals, including negative numbers, up to intervals of size 2^31 - 1.
+ */
+public class ArrayMap<T> {
+
+    private static final int INITIAL_SIZE = 5; // how big the initial array should be
+    private static final int EXTRA = 2; // how far on the left or right of a new element to grow
+
+    Object[] map;
+    int low;
+
+    /**
+     * Constructs a new {@code ArrayMap} with no initial assumptions.
+     */
+    public ArrayMap() {
+    }
+
+    /**
+     * Constructs a new {@code ArrayMap} that initially covers the specified interval. Note that
+     * this map will automatically expand if necessary later.
+     * 
+     * @param low the low index, inclusive
+     * @param high the high index, exclusive
+     */
+    public ArrayMap(int low, int high) {
+        this.low = low;
+        this.map = new Object[high - low + 1];
+    }
+
+    /**
+     * Puts a new value in the map at the specified index.
+     * 
+     * @param i the index at which to store the value
+     * @param value the value to store at the specified index
+     */
+    public void put(int i, T value) {
+        int index = i - low;
+        if (map == null) {
+            // no map yet
+            map = new Object[INITIAL_SIZE];
+            low = index - 2;
+            map[INITIAL_SIZE / 2] = value;
+        } else if (index < 0) {
+            // grow backwards
+            growBackward(i, value);
+        } else if (index >= map.length) {
+            // grow forwards
+            growForward(i, value);
+        } else {
+            // no growth necessary
+            map[index] = value;
+        }
+    }
+
+    /**
+     * Gets the value at the specified index in the map.
+     * 
+     * @param i the index
+     * @return the value at the specified index; {@code null} if there is no value at the specified
+     *         index, or if the index is out of the currently stored range
+     */
+    public T get(int i) {
+        int index = i - low;
+        if (map == null || index < 0 || index >= map.length) {
+            return null;
+        }
+        Class<T> type = null;
+        return Util.uncheckedCast(type, map[index]);
+    }
+
+    public int length() {
+        return map.length;
+    }
+
+    private void growBackward(int i, T value) {
+        int nlow = i - EXTRA;
+        Object[] nmap = new Object[low - nlow + map.length];
+        System.arraycopy(map, 0, nmap, low - nlow, map.length);
+        map = nmap;
+        low = nlow;
+        map[i - low] = value;
+    }
+
+    private void growForward(int i, T value) {
+        int nlen = i - low + 1 + EXTRA;
+        Object[] nmap = new Object[nlen];
+        System.arraycopy(map, 0, nmap, 0, map.length);
+        map = nmap;
+        map[i - low] = value;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/util/ArraySet.java	Wed Feb 04 18:24:05 2015 +0100
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.compiler.common.util;
+
+import java.util.*;
+
+/**
+ * Mimic a set implementation with an ArrayList. Beneficial for small sets (compared to
+ * {@link HashSet}).
+ */
+public class ArraySet<E> extends ArrayList<E> implements Set<E> {
+    private static final long serialVersionUID = 4476957522387436654L;
+
+    public ArraySet() {
+        super();
+    }
+
+    public ArraySet(int i) {
+        super(i);
+    }
+
+    public ArraySet(Collection<? extends E> c) {
+        super(c);
+    }
+
+    @Override
+    public boolean add(E e) {
+        // avoid duplicated entries
+        if (contains(e)) {
+            return false;
+        }
+        return super.add(e);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/util/BitMap2D.java	Wed Feb 04 18:24:05 2015 +0100
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.compiler.common.util;
+
+import java.util.*;
+
+/**
+ * This class implements a two-dimensional bitmap.
+ */
+public final class BitMap2D {
+
+    private BitSet map;
+    private final int bitsPerSlot;
+
+    private int bitIndex(int slotIndex, int bitWithinSlotIndex) {
+        return slotIndex * bitsPerSlot + bitWithinSlotIndex;
+    }
+
+    private boolean verifyBitWithinSlotIndex(int index) {
+        assert index < bitsPerSlot : "index " + index + " is out of bounds " + bitsPerSlot;
+        return true;
+    }
+
+    public BitMap2D(int sizeInSlots, int bitsPerSlot) {
+        map = new BitSet(sizeInSlots * bitsPerSlot);
+        this.bitsPerSlot = bitsPerSlot;
+    }
+
+    public int sizeInBits() {
+        return map.size();
+    }
+
+    // Returns number of full slots that have been allocated
+    public int sizeInSlots() {
+        return map.size() / bitsPerSlot;
+    }
+
+    public boolean isValidIndex(int slotIndex, int bitWithinSlotIndex) {
+        assert verifyBitWithinSlotIndex(bitWithinSlotIndex);
+        return (bitIndex(slotIndex, bitWithinSlotIndex) < sizeInBits());
+    }
+
+    public boolean at(int slotIndex, int bitWithinSlotIndex) {
+        assert verifyBitWithinSlotIndex(bitWithinSlotIndex);
+        return map.get(bitIndex(slotIndex, bitWithinSlotIndex));
+    }
+
+    public void setBit(int slotIndex, int bitWithinSlotIndex) {
+        assert verifyBitWithinSlotIndex(bitWithinSlotIndex);
+        map.set(bitIndex(slotIndex, bitWithinSlotIndex));
+    }
+
+    public void clearBit(int slotIndex, int bitWithinSlotIndex) {
+        assert verifyBitWithinSlotIndex(bitWithinSlotIndex);
+        map.clear(bitIndex(slotIndex, bitWithinSlotIndex));
+    }
+
+    public void atPutGrow(int slotIndex, int bitWithinSlotIndex, boolean value) {
+        int size = sizeInSlots();
+        if (size <= slotIndex) {
+            while (size <= slotIndex) {
+                size *= 2;
+            }
+            BitSet newBitMap = new BitSet(size * bitsPerSlot);
+            newBitMap.or(map);
+            map = newBitMap;
+        }
+
+        if (value) {
+            setBit(slotIndex, bitWithinSlotIndex);
+        } else {
+            clearBit(slotIndex, bitWithinSlotIndex);
+        }
+    }
+
+    public void clear() {
+        map.clear();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/util/IntList.java	Wed Feb 04 18:24:05 2015 +0100
@@ -0,0 +1,163 @@
+/*
+ * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.compiler.common.util;
+
+import java.util.*;
+
+/**
+ * An expandable and indexable list of {@code int}s.
+ * 
+ * This class avoids the boxing/unboxing incurred by {@code ArrayList<Integer>}.
+ */
+public final class IntList {
+
+    private int[] array;
+    private int size;
+
+    /**
+     * Creates an int list with a specified initial capacity.
+     * 
+     * @param initialCapacity
+     */
+    public IntList(int initialCapacity) {
+        array = new int[initialCapacity];
+    }
+
+    /**
+     * Creates an int list with a specified initial array.
+     * 
+     * @param array the initial array used for the list (no copy is made)
+     * @param initialSize the initial {@linkplain #size() size} of the list (must be less than or
+     *            equal to {@code array.length}
+     */
+    public IntList(int[] array, int initialSize) {
+        assert initialSize <= array.length;
+        this.array = array;
+        this.size = initialSize;
+    }
+
+    /**
+     * Makes a new int list by copying a range from a given int list.
+     * 
+     * @param other the list from which a range of values is to be copied into the new list
+     * @param startIndex the index in {@code other} at which to start copying
+     * @param length the number of values to copy from {@code other}
+     * @return a new int list whose {@linkplain #size() size} and capacity is {@code length}
+     */
+    public static IntList copy(IntList other, int startIndex, int length) {
+        return copy(other, startIndex, length, length);
+    }
+
+    /**
+     * Makes a new int list by copying a range from a given int list.
+     * 
+     * @param other the list from which a range of values is to be copied into the new list
+     * @param startIndex the index in {@code other} at which to start copying
+     * @param length the number of values to copy from {@code other}
+     * @param initialCapacity the initial capacity of the new int list (must be greater or equal to
+     *            {@code length})
+     * @return a new int list whose {@linkplain #size() size} is {@code length}
+     */
+    public static IntList copy(IntList other, int startIndex, int length, int initialCapacity) {
+        assert initialCapacity >= length : "initialCapacity < length";
+        int[] array = new int[initialCapacity];
+        System.arraycopy(other.array, startIndex, array, 0, length);
+        return new IntList(array, length);
+    }
+
+    public int size() {
+        return size;
+    }
+
+    /**
+     * Appends a value to the end of this list, increasing its {@linkplain #size() size} by 1.
+     * 
+     * @param value the value to append
+     */
+    public void add(int value) {
+        if (size == array.length) {
+            int newSize = (size * 3) / 2 + 1;
+            array = Arrays.copyOf(array, newSize);
+        }
+        array[size++] = value;
+    }
+
+    /**
+     * Gets the value in this list at a given index.
+     * 
+     * @param index the index of the element to return
+     * @throws IndexOutOfBoundsException if {@code index < 0 || index >= size()}
+     */
+    public int get(int index) {
+        if (index >= size) {
+            throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
+        }
+        return array[index];
+    }
+
+    /**
+     * Sets the size of this list to 0.
+     */
+    public void clear() {
+        size = 0;
+    }
+
+    /**
+     * Sets a value at a given index in this list.
+     * 
+     * @param index the index of the element to update
+     * @param value the new value of the element
+     * @throws IndexOutOfBoundsException if {@code index < 0 || index >= size()}
+     */
+    public void set(int index, int value) {
+        if (index >= size) {
+            throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
+        }
+        array[index] = value;
+    }
+
+    /**
+     * Adjusts the {@linkplain #size() size} of this int list.
+     * 
+     * If {@code newSize < size()}, the size is changed to {@code newSize}. If
+     * {@code newSize > size()}, sufficient 0 elements are {@linkplain #add(int) added} until
+     * {@code size() == newSize}.
+     * 
+     * @param newSize the new size of this int list
+     */
+    public void setSize(int newSize) {
+        if (newSize < size) {
+            size = newSize;
+        } else if (newSize > size) {
+            array = Arrays.copyOf(array, newSize);
+        }
+    }
+
+    @Override
+    public String toString() {
+        if (array.length == size) {
+            return Arrays.toString(array);
+        }
+        return Arrays.toString(Arrays.copyOf(array, size));
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/util/Util.java	Wed Feb 04 18:24:05 2015 +0100
@@ -0,0 +1,337 @@
+/*
+ * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.compiler.common.util;
+
+import java.util.*;
+
+import com.oracle.graal.api.code.*;
+import com.oracle.graal.debug.*;
+
+/**
+ * The {@code Util} class contains a motley collection of utility methods used throughout the
+ * compiler.
+ */
+public class Util {
+
+    public static final int PRINTING_LINE_WIDTH = 40;
+    public static final char SECTION_CHARACTER = '*';
+    public static final char SUB_SECTION_CHARACTER = '=';
+    public static final char SEPERATOR_CHARACTER = '-';
+
+    public static <T> boolean replaceInList(T a, T b, List<T> list) {
+        final int max = list.size();
+        for (int i = 0; i < max; i++) {
+            if (list.get(i) == a) {
+                list.set(i, b);
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Statically cast an object to an arbitrary Object type. Dynamically checked.
+     */
+    @SuppressWarnings("unchecked")
+    public static <T> T uncheckedCast(@SuppressWarnings("unused") Class<T> type, Object object) {
+        return (T) object;
+    }
+
+    /**
+     * Statically cast an object to an arbitrary Object type. Dynamically checked.
+     */
+    @SuppressWarnings("unchecked")
+    public static <T> T uncheckedCast(Object object) {
+        return (T) object;
+    }
+
+    /**
+     * Utility method to combine a base hash with the identity hash of one or more objects.
+     *
+     * @param hash the base hash
+     * @param x the object to add to the hash
+     * @return the combined hash
+     */
+    public static int hash1(int hash, Object x) {
+        // always set at least one bit in case the hash wraps to zero
+        return 0x10000000 | (hash + 7 * System.identityHashCode(x));
+    }
+
+    /**
+     * Utility method to combine a base hash with the identity hash of one or more objects.
+     *
+     * @param hash the base hash
+     * @param x the first object to add to the hash
+     * @param y the second object to add to the hash
+     * @return the combined hash
+     */
+    public static int hash2(int hash, Object x, Object y) {
+        // always set at least one bit in case the hash wraps to zero
+        return 0x20000000 | (hash + 7 * System.identityHashCode(x) + 11 * System.identityHashCode(y));
+    }
+
+    /**
+     * Utility method to combine a base hash with the identity hash of one or more objects.
+     *
+     * @param hash the base hash
+     * @param x the first object to add to the hash
+     * @param y the second object to add to the hash
+     * @param z the third object to add to the hash
+     * @return the combined hash
+     */
+    public static int hash3(int hash, Object x, Object y, Object z) {
+        // always set at least one bit in case the hash wraps to zero
+        return 0x30000000 | (hash + 7 * System.identityHashCode(x) + 11 * System.identityHashCode(y) + 13 * System.identityHashCode(z));
+    }
+
+    /**
+     * Utility method to combine a base hash with the identity hash of one or more objects.
+     *
+     * @param hash the base hash
+     * @param x the first object to add to the hash
+     * @param y the second object to add to the hash
+     * @param z the third object to add to the hash
+     * @param w the fourth object to add to the hash
+     * @return the combined hash
+     */
+    public static int hash4(int hash, Object x, Object y, Object z, Object w) {
+        // always set at least one bit in case the hash wraps to zero
+        return 0x40000000 | (hash + 7 * System.identityHashCode(x) + 11 * System.identityHashCode(y) + 13 * System.identityHashCode(z) + 17 * System.identityHashCode(w));
+    }
+
+    static {
+        assert CodeUtil.log2(2) == 1;
+        assert CodeUtil.log2(4) == 2;
+        assert CodeUtil.log2(8) == 3;
+        assert CodeUtil.log2(16) == 4;
+        assert CodeUtil.log2(32) == 5;
+        assert CodeUtil.log2(0x40000000) == 30;
+
+        assert CodeUtil.log2(2L) == 1;
+        assert CodeUtil.log2(4L) == 2;
+        assert CodeUtil.log2(8L) == 3;
+        assert CodeUtil.log2(16L) == 4;
+        assert CodeUtil.log2(32L) == 5;
+        assert CodeUtil.log2(0x4000000000000000L) == 62;
+
+        assert !CodeUtil.isPowerOf2(3);
+        assert !CodeUtil.isPowerOf2(5);
+        assert !CodeUtil.isPowerOf2(7);
+        assert !CodeUtil.isPowerOf2(-1);
+
+        assert CodeUtil.isPowerOf2(2);
+        assert CodeUtil.isPowerOf2(4);
+        assert CodeUtil.isPowerOf2(8);
+        assert CodeUtil.isPowerOf2(16);
+        assert CodeUtil.isPowerOf2(32);
+        assert CodeUtil.isPowerOf2(64);
+    }
+
+    /**
+     * Sets the element at a given position of a list and ensures that this position exists. If the
+     * list is current shorter than the position, intermediate positions are filled with a given
+     * value.
+     *
+     * @param list the list to put the element into
+     * @param pos the position at which to insert the element
+     * @param x the element that should be inserted
+     * @param filler the filler element that is used for the intermediate positions in case the list
+     *            is shorter than pos
+     */
+    public static <T> void atPutGrow(List<T> list, int pos, T x, T filler) {
+        if (list.size() < pos + 1) {
+            while (list.size() < pos + 1) {
+                list.add(filler);
+            }
+            assert list.size() == pos + 1;
+        }
+
+        assert list.size() >= pos + 1;
+        list.set(pos, x);
+    }
+
+    public static void breakpoint() {
+        // do nothing.
+    }
+
+    public static void guarantee(boolean b, String string) {
+        if (!b) {
+            throw new BailoutException(string);
+        }
+    }
+
+    public static void warning(String string) {
+        TTY.println("WARNING: " + string);
+    }
+
+    public static int safeToInt(long l) {
+        assert (int) l == l;
+        return (int) l;
+    }
+
+    public static int roundUp(int number, int mod) {
+        return ((number + mod - 1) / mod) * mod;
+    }
+
+    public static void printSection(String name, char sectionCharacter) {
+
+        String header = " " + name + " ";
+        int remainingCharacters = PRINTING_LINE_WIDTH - header.length();
+        int leftPart = remainingCharacters / 2;
+        int rightPart = remainingCharacters - leftPart;
+        for (int i = 0; i < leftPart; i++) {
+            TTY.print(sectionCharacter);
+        }
+
+        TTY.print(header);
+
+        for (int i = 0; i < rightPart; i++) {
+            TTY.print(sectionCharacter);
+        }
+
+        TTY.println();
+    }
+
+    /**
+     * Prints entries in a byte array as space separated hex values to {@link TTY}.
+     *
+     * @param address an address at which the bytes are located. This is used to print an address
+     *            prefix per line of output.
+     * @param array the array containing all the bytes to print
+     * @param bytesPerLine the number of values to print per line of output
+     */
+    public static void printBytes(long address, byte[] array, int bytesPerLine) {
+        printBytes(address, array, 0, array.length, bytesPerLine);
+    }
+
+    /**
+     * Prints entries in a byte array as space separated hex values to {@link TTY}.
+     *
+     * @param address an address at which the bytes are located. This is used to print an address
+     *            prefix per line of output.
+     * @param array the array containing the bytes to print
+     * @param offset the offset in {@code array} of the values to print
+     * @param length the number of values from {@code array} print
+     * @param bytesPerLine the number of values to print per line of output
+     */
+    public static void printBytes(long address, byte[] array, int offset, int length, int bytesPerLine) {
+        assert bytesPerLine > 0;
+        boolean newLine = true;
+        for (int i = 0; i < length; i++) {
+            if (newLine) {
+                TTY.print("%08x: ", address + i);
+                newLine = false;
+            }
+            TTY.print("%02x ", array[i]);
+            if (i % bytesPerLine == bytesPerLine - 1) {
+                TTY.println();
+                newLine = true;
+            }
+        }
+
+        if (length % bytesPerLine != bytesPerLine) {
+            TTY.println();
+        }
+    }
+
+    public static boolean isShiftCount(int x) {
+        return 0 <= x && x < 32;
+    }
+
+    /**
+     * Determines if a given {@code int} value is the range of unsigned byte values.
+     */
+    public static boolean isUByte(int x) {
+        return (x & 0xff) == x;
+    }
+
+    /**
+     * Determines if a given {@code int} value is the range of signed byte values.
+     */
+    public static boolean isByte(int x) {
+        return (byte) x == x;
+    }
+
+    /**
+     * Determines if a given {@code long} value is the range of unsigned byte values.
+     */
+    public static boolean isUByte(long x) {
+        return (x & 0xffL) == x;
+    }
+
+    /**
+     * Determines if a given {@code long} value is the range of signed byte values.
+     */
+    public static boolean isByte(long l) {
+        return (byte) l == l;
+    }
+
+    /**
+     * Determines if a given {@code long} value is the range of unsigned int values.
+     */
+    public static boolean isUInt(long x) {
+        return (x & 0xffffffffL) == x;
+    }
+
+    /**
+     * Determines if a given {@code long} value is the range of signed int values.
+     */
+    public static boolean isInt(long l) {
+        return (int) l == l;
+    }
+
+    /**
+     * Determines if a given {@code int} value is the range of signed short values.
+     */
+    public static boolean isShort(int x) {
+        return (short) x == x;
+    }
+
+    public static boolean is32bit(long x) {
+        return -0x80000000L <= x && x < 0x80000000L;
+    }
+
+    public static short safeToShort(int v) {
+        assert isShort(v);
+        return (short) v;
+    }
+
+    /**
+     * Creates an array of integers of length "size", in which each number from 0 to (size - 1)
+     * occurs exactly once. The integers are sorted using the given comparator. This can be used to
+     * create a sorting for arrays that cannot be modified directly.
+     *
+     * @param size The size of the range to be sorted.
+     * @param comparator A comparator that is used to compare indexes.
+     * @return An array of integers that contains each number from 0 to (size - 1) exactly once,
+     *         sorted using the comparator.
+     */
+    public static Integer[] createSortedPermutation(int size, Comparator<Integer> comparator) {
+        Integer[] indexes = new Integer[size];
+        for (int i = 0; i < size; i++) {
+            indexes[i] = i;
+        }
+        Arrays.sort(indexes, comparator);
+        return indexes;
+    }
+}
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/Interval.java	Wed Feb 04 18:21:29 2015 +0100
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/Interval.java	Wed Feb 04 18:24:05 2015 +0100
@@ -31,9 +31,9 @@
 import com.oracle.graal.api.code.*;
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.compiler.common.*;
+import com.oracle.graal.compiler.common.util.*;
 import com.oracle.graal.debug.*;
 import com.oracle.graal.lir.*;
-import com.oracle.graal.phases.util.*;
 
 /**
  * Represents an interval in the {@linkplain LinearScan linear scan register allocator}.
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScan.java	Wed Feb 04 18:21:29 2015 +0100
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScan.java	Wed Feb 04 18:24:05 2015 +0100
@@ -38,6 +38,7 @@
 import com.oracle.graal.compiler.alloc.Interval.SpillState;
 import com.oracle.graal.compiler.common.*;
 import com.oracle.graal.compiler.common.cfg.*;
+import com.oracle.graal.compiler.common.util.*;
 import com.oracle.graal.compiler.gen.*;
 import com.oracle.graal.debug.*;
 import com.oracle.graal.debug.Debug.Scope;
@@ -49,7 +50,6 @@
 import com.oracle.graal.lir.gen.*;
 import com.oracle.graal.nodes.*;
 import com.oracle.graal.options.*;
-import com.oracle.graal.phases.util.*;
 
 /**
  * An implementation of the linear scan register allocator algorithm described in <a
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScanWalker.java	Wed Feb 04 18:21:29 2015 +0100
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScanWalker.java	Wed Feb 04 18:24:05 2015 +0100
@@ -35,10 +35,10 @@
 import com.oracle.graal.compiler.alloc.Interval.SpillState;
 import com.oracle.graal.compiler.alloc.Interval.State;
 import com.oracle.graal.compiler.common.cfg.*;
+import com.oracle.graal.compiler.common.util.*;
 import com.oracle.graal.debug.*;
 import com.oracle.graal.lir.*;
 import com.oracle.graal.lir.StandardOp.MoveOp;
-import com.oracle.graal.phases.util.*;
 
 /**
  */
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/RegisterVerifier.java	Wed Feb 04 18:21:29 2015 +0100
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/RegisterVerifier.java	Wed Feb 04 18:24:05 2015 +0100
@@ -30,11 +30,11 @@
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.compiler.common.*;
 import com.oracle.graal.compiler.common.cfg.*;
+import com.oracle.graal.compiler.common.util.*;
 import com.oracle.graal.debug.*;
 import com.oracle.graal.lir.*;
 import com.oracle.graal.lir.LIRInstruction.OperandFlag;
 import com.oracle.graal.lir.LIRInstruction.OperandMode;
-import com.oracle.graal.phases.util.*;
 
 /**
  */
--- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/util/ArrayMap.java	Wed Feb 04 18:21:29 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,118 +0,0 @@
-/*
- * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.graal.phases.util;
-
-/**
- * The {@code ArrayMap} class implements an efficient one-level map which is implemented as an
- * array. Note that because of the one-level array inside, this data structure performs best when
- * the range of integer keys is small and densely used. Note that the implementation can handle
- * arbitrary intervals, including negative numbers, up to intervals of size 2^31 - 1.
- */
-public class ArrayMap<T> {
-
-    private static final int INITIAL_SIZE = 5; // how big the initial array should be
-    private static final int EXTRA = 2; // how far on the left or right of a new element to grow
-
-    Object[] map;
-    int low;
-
-    /**
-     * Constructs a new {@code ArrayMap} with no initial assumptions.
-     */
-    public ArrayMap() {
-    }
-
-    /**
-     * Constructs a new {@code ArrayMap} that initially covers the specified interval. Note that
-     * this map will automatically expand if necessary later.
-     * 
-     * @param low the low index, inclusive
-     * @param high the high index, exclusive
-     */
-    public ArrayMap(int low, int high) {
-        this.low = low;
-        this.map = new Object[high - low + 1];
-    }
-
-    /**
-     * Puts a new value in the map at the specified index.
-     * 
-     * @param i the index at which to store the value
-     * @param value the value to store at the specified index
-     */
-    public void put(int i, T value) {
-        int index = i - low;
-        if (map == null) {
-            // no map yet
-            map = new Object[INITIAL_SIZE];
-            low = index - 2;
-            map[INITIAL_SIZE / 2] = value;
-        } else if (index < 0) {
-            // grow backwards
-            growBackward(i, value);
-        } else if (index >= map.length) {
-            // grow forwards
-            growForward(i, value);
-        } else {
-            // no growth necessary
-            map[index] = value;
-        }
-    }
-
-    /**
-     * Gets the value at the specified index in the map.
-     * 
-     * @param i the index
-     * @return the value at the specified index; {@code null} if there is no value at the specified
-     *         index, or if the index is out of the currently stored range
-     */
-    public T get(int i) {
-        int index = i - low;
-        if (map == null || index < 0 || index >= map.length) {
-            return null;
-        }
-        Class<T> type = null;
-        return Util.uncheckedCast(type, map[index]);
-    }
-
-    public int length() {
-        return map.length;
-    }
-
-    private void growBackward(int i, T value) {
-        int nlow = i - EXTRA;
-        Object[] nmap = new Object[low - nlow + map.length];
-        System.arraycopy(map, 0, nmap, low - nlow, map.length);
-        map = nmap;
-        low = nlow;
-        map[i - low] = value;
-    }
-
-    private void growForward(int i, T value) {
-        int nlen = i - low + 1 + EXTRA;
-        Object[] nmap = new Object[nlen];
-        System.arraycopy(map, 0, nmap, 0, map.length);
-        map = nmap;
-        map[i - low] = value;
-    }
-}
--- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/util/ArraySet.java	Wed Feb 04 18:21:29 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.graal.phases.util;
-
-import java.util.*;
-
-/**
- * Mimic a set implementation with an ArrayList. Beneficial for small sets (compared to
- * {@link HashSet}).
- */
-public class ArraySet<E> extends ArrayList<E> implements Set<E> {
-    private static final long serialVersionUID = 4476957522387436654L;
-
-    public ArraySet() {
-        super();
-    }
-
-    public ArraySet(int i) {
-        super(i);
-    }
-
-    public ArraySet(Collection<? extends E> c) {
-        super(c);
-    }
-
-    @Override
-    public boolean add(E e) {
-        // avoid duplicated entries
-        if (contains(e)) {
-            return false;
-        }
-        return super.add(e);
-    }
-}
--- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/util/BitMap2D.java	Wed Feb 04 18:21:29 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,99 +0,0 @@
-/*
- * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.graal.phases.util;
-
-import java.util.*;
-
-/**
- * This class implements a two-dimensional bitmap.
- */
-public final class BitMap2D {
-
-    private BitSet map;
-    private final int bitsPerSlot;
-
-    private int bitIndex(int slotIndex, int bitWithinSlotIndex) {
-        return slotIndex * bitsPerSlot + bitWithinSlotIndex;
-    }
-
-    private boolean verifyBitWithinSlotIndex(int index) {
-        assert index < bitsPerSlot : "index " + index + " is out of bounds " + bitsPerSlot;
-        return true;
-    }
-
-    public BitMap2D(int sizeInSlots, int bitsPerSlot) {
-        map = new BitSet(sizeInSlots * bitsPerSlot);
-        this.bitsPerSlot = bitsPerSlot;
-    }
-
-    public int sizeInBits() {
-        return map.size();
-    }
-
-    // Returns number of full slots that have been allocated
-    public int sizeInSlots() {
-        return map.size() / bitsPerSlot;
-    }
-
-    public boolean isValidIndex(int slotIndex, int bitWithinSlotIndex) {
-        assert verifyBitWithinSlotIndex(bitWithinSlotIndex);
-        return (bitIndex(slotIndex, bitWithinSlotIndex) < sizeInBits());
-    }
-
-    public boolean at(int slotIndex, int bitWithinSlotIndex) {
-        assert verifyBitWithinSlotIndex(bitWithinSlotIndex);
-        return map.get(bitIndex(slotIndex, bitWithinSlotIndex));
-    }
-
-    public void setBit(int slotIndex, int bitWithinSlotIndex) {
-        assert verifyBitWithinSlotIndex(bitWithinSlotIndex);
-        map.set(bitIndex(slotIndex, bitWithinSlotIndex));
-    }
-
-    public void clearBit(int slotIndex, int bitWithinSlotIndex) {
-        assert verifyBitWithinSlotIndex(bitWithinSlotIndex);
-        map.clear(bitIndex(slotIndex, bitWithinSlotIndex));
-    }
-
-    public void atPutGrow(int slotIndex, int bitWithinSlotIndex, boolean value) {
-        int size = sizeInSlots();
-        if (size <= slotIndex) {
-            while (size <= slotIndex) {
-                size *= 2;
-            }
-            BitSet newBitMap = new BitSet(size * bitsPerSlot);
-            newBitMap.or(map);
-            map = newBitMap;
-        }
-
-        if (value) {
-            setBit(slotIndex, bitWithinSlotIndex);
-        } else {
-            clearBit(slotIndex, bitWithinSlotIndex);
-        }
-    }
-
-    public void clear() {
-        map.clear();
-    }
-}
--- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/util/IntList.java	Wed Feb 04 18:21:29 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,163 +0,0 @@
-/*
- * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.graal.phases.util;
-
-import java.util.*;
-
-/**
- * An expandable and indexable list of {@code int}s.
- * 
- * This class avoids the boxing/unboxing incurred by {@code ArrayList<Integer>}.
- */
-public final class IntList {
-
-    private int[] array;
-    private int size;
-
-    /**
-     * Creates an int list with a specified initial capacity.
-     * 
-     * @param initialCapacity
-     */
-    public IntList(int initialCapacity) {
-        array = new int[initialCapacity];
-    }
-
-    /**
-     * Creates an int list with a specified initial array.
-     * 
-     * @param array the initial array used for the list (no copy is made)
-     * @param initialSize the initial {@linkplain #size() size} of the list (must be less than or
-     *            equal to {@code array.length}
-     */
-    public IntList(int[] array, int initialSize) {
-        assert initialSize <= array.length;
-        this.array = array;
-        this.size = initialSize;
-    }
-
-    /**
-     * Makes a new int list by copying a range from a given int list.
-     * 
-     * @param other the list from which a range of values is to be copied into the new list
-     * @param startIndex the index in {@code other} at which to start copying
-     * @param length the number of values to copy from {@code other}
-     * @return a new int list whose {@linkplain #size() size} and capacity is {@code length}
-     */
-    public static IntList copy(IntList other, int startIndex, int length) {
-        return copy(other, startIndex, length, length);
-    }
-
-    /**
-     * Makes a new int list by copying a range from a given int list.
-     * 
-     * @param other the list from which a range of values is to be copied into the new list
-     * @param startIndex the index in {@code other} at which to start copying
-     * @param length the number of values to copy from {@code other}
-     * @param initialCapacity the initial capacity of the new int list (must be greater or equal to
-     *            {@code length})
-     * @return a new int list whose {@linkplain #size() size} is {@code length}
-     */
-    public static IntList copy(IntList other, int startIndex, int length, int initialCapacity) {
-        assert initialCapacity >= length : "initialCapacity < length";
-        int[] array = new int[initialCapacity];
-        System.arraycopy(other.array, startIndex, array, 0, length);
-        return new IntList(array, length);
-    }
-
-    public int size() {
-        return size;
-    }
-
-    /**
-     * Appends a value to the end of this list, increasing its {@linkplain #size() size} by 1.
-     * 
-     * @param value the value to append
-     */
-    public void add(int value) {
-        if (size == array.length) {
-            int newSize = (size * 3) / 2 + 1;
-            array = Arrays.copyOf(array, newSize);
-        }
-        array[size++] = value;
-    }
-
-    /**
-     * Gets the value in this list at a given index.
-     * 
-     * @param index the index of the element to return
-     * @throws IndexOutOfBoundsException if {@code index < 0 || index >= size()}
-     */
-    public int get(int index) {
-        if (index >= size) {
-            throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
-        }
-        return array[index];
-    }
-
-    /**
-     * Sets the size of this list to 0.
-     */
-    public void clear() {
-        size = 0;
-    }
-
-    /**
-     * Sets a value at a given index in this list.
-     * 
-     * @param index the index of the element to update
-     * @param value the new value of the element
-     * @throws IndexOutOfBoundsException if {@code index < 0 || index >= size()}
-     */
-    public void set(int index, int value) {
-        if (index >= size) {
-            throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
-        }
-        array[index] = value;
-    }
-
-    /**
-     * Adjusts the {@linkplain #size() size} of this int list.
-     * 
-     * If {@code newSize < size()}, the size is changed to {@code newSize}. If
-     * {@code newSize > size()}, sufficient 0 elements are {@linkplain #add(int) added} until
-     * {@code size() == newSize}.
-     * 
-     * @param newSize the new size of this int list
-     */
-    public void setSize(int newSize) {
-        if (newSize < size) {
-            size = newSize;
-        } else if (newSize > size) {
-            array = Arrays.copyOf(array, newSize);
-        }
-    }
-
-    @Override
-    public String toString() {
-        if (array.length == size) {
-            return Arrays.toString(array);
-        }
-        return Arrays.toString(Arrays.copyOf(array, size));
-    }
-}
--- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/util/Util.java	Wed Feb 04 18:21:29 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,337 +0,0 @@
-/*
- * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.graal.phases.util;
-
-import java.util.*;
-
-import com.oracle.graal.api.code.*;
-import com.oracle.graal.debug.*;
-
-/**
- * The {@code Util} class contains a motley collection of utility methods used throughout the
- * compiler.
- */
-public class Util {
-
-    public static final int PRINTING_LINE_WIDTH = 40;
-    public static final char SECTION_CHARACTER = '*';
-    public static final char SUB_SECTION_CHARACTER = '=';
-    public static final char SEPERATOR_CHARACTER = '-';
-
-    public static <T> boolean replaceInList(T a, T b, List<T> list) {
-        final int max = list.size();
-        for (int i = 0; i < max; i++) {
-            if (list.get(i) == a) {
-                list.set(i, b);
-                return true;
-            }
-        }
-        return false;
-    }
-
-    /**
-     * Statically cast an object to an arbitrary Object type. Dynamically checked.
-     */
-    @SuppressWarnings("unchecked")
-    public static <T> T uncheckedCast(@SuppressWarnings("unused") Class<T> type, Object object) {
-        return (T) object;
-    }
-
-    /**
-     * Statically cast an object to an arbitrary Object type. Dynamically checked.
-     */
-    @SuppressWarnings("unchecked")
-    public static <T> T uncheckedCast(Object object) {
-        return (T) object;
-    }
-
-    /**
-     * Utility method to combine a base hash with the identity hash of one or more objects.
-     * 
-     * @param hash the base hash
-     * @param x the object to add to the hash
-     * @return the combined hash
-     */
-    public static int hash1(int hash, Object x) {
-        // always set at least one bit in case the hash wraps to zero
-        return 0x10000000 | (hash + 7 * System.identityHashCode(x));
-    }
-
-    /**
-     * Utility method to combine a base hash with the identity hash of one or more objects.
-     * 
-     * @param hash the base hash
-     * @param x the first object to add to the hash
-     * @param y the second object to add to the hash
-     * @return the combined hash
-     */
-    public static int hash2(int hash, Object x, Object y) {
-        // always set at least one bit in case the hash wraps to zero
-        return 0x20000000 | (hash + 7 * System.identityHashCode(x) + 11 * System.identityHashCode(y));
-    }
-
-    /**
-     * Utility method to combine a base hash with the identity hash of one or more objects.
-     * 
-     * @param hash the base hash
-     * @param x the first object to add to the hash
-     * @param y the second object to add to the hash
-     * @param z the third object to add to the hash
-     * @return the combined hash
-     */
-    public static int hash3(int hash, Object x, Object y, Object z) {
-        // always set at least one bit in case the hash wraps to zero
-        return 0x30000000 | (hash + 7 * System.identityHashCode(x) + 11 * System.identityHashCode(y) + 13 * System.identityHashCode(z));
-    }
-
-    /**
-     * Utility method to combine a base hash with the identity hash of one or more objects.
-     * 
-     * @param hash the base hash
-     * @param x the first object to add to the hash
-     * @param y the second object to add to the hash
-     * @param z the third object to add to the hash
-     * @param w the fourth object to add to the hash
-     * @return the combined hash
-     */
-    public static int hash4(int hash, Object x, Object y, Object z, Object w) {
-        // always set at least one bit in case the hash wraps to zero
-        return 0x40000000 | (hash + 7 * System.identityHashCode(x) + 11 * System.identityHashCode(y) + 13 * System.identityHashCode(z) + 17 * System.identityHashCode(w));
-    }
-
-    static {
-        assert CodeUtil.log2(2) == 1;
-        assert CodeUtil.log2(4) == 2;
-        assert CodeUtil.log2(8) == 3;
-        assert CodeUtil.log2(16) == 4;
-        assert CodeUtil.log2(32) == 5;
-        assert CodeUtil.log2(0x40000000) == 30;
-
-        assert CodeUtil.log2(2L) == 1;
-        assert CodeUtil.log2(4L) == 2;
-        assert CodeUtil.log2(8L) == 3;
-        assert CodeUtil.log2(16L) == 4;
-        assert CodeUtil.log2(32L) == 5;
-        assert CodeUtil.log2(0x4000000000000000L) == 62;
-
-        assert !CodeUtil.isPowerOf2(3);
-        assert !CodeUtil.isPowerOf2(5);
-        assert !CodeUtil.isPowerOf2(7);
-        assert !CodeUtil.isPowerOf2(-1);
-
-        assert CodeUtil.isPowerOf2(2);
-        assert CodeUtil.isPowerOf2(4);
-        assert CodeUtil.isPowerOf2(8);
-        assert CodeUtil.isPowerOf2(16);
-        assert CodeUtil.isPowerOf2(32);
-        assert CodeUtil.isPowerOf2(64);
-    }
-
-    /**
-     * Sets the element at a given position of a list and ensures that this position exists. If the
-     * list is current shorter than the position, intermediate positions are filled with a given
-     * value.
-     * 
-     * @param list the list to put the element into
-     * @param pos the position at which to insert the element
-     * @param x the element that should be inserted
-     * @param filler the filler element that is used for the intermediate positions in case the list
-     *            is shorter than pos
-     */
-    public static <T> void atPutGrow(List<T> list, int pos, T x, T filler) {
-        if (list.size() < pos + 1) {
-            while (list.size() < pos + 1) {
-                list.add(filler);
-            }
-            assert list.size() == pos + 1;
-        }
-
-        assert list.size() >= pos + 1;
-        list.set(pos, x);
-    }
-
-    public static void breakpoint() {
-        // do nothing.
-    }
-
-    public static void guarantee(boolean b, String string) {
-        if (!b) {
-            throw new BailoutException(string);
-        }
-    }
-
-    public static void warning(String string) {
-        TTY.println("WARNING: " + string);
-    }
-
-    public static int safeToInt(long l) {
-        assert (int) l == l;
-        return (int) l;
-    }
-
-    public static int roundUp(int number, int mod) {
-        return ((number + mod - 1) / mod) * mod;
-    }
-
-    public static void printSection(String name, char sectionCharacter) {
-
-        String header = " " + name + " ";
-        int remainingCharacters = PRINTING_LINE_WIDTH - header.length();
-        int leftPart = remainingCharacters / 2;
-        int rightPart = remainingCharacters - leftPart;
-        for (int i = 0; i < leftPart; i++) {
-            TTY.print(sectionCharacter);
-        }
-
-        TTY.print(header);
-
-        for (int i = 0; i < rightPart; i++) {
-            TTY.print(sectionCharacter);
-        }
-
-        TTY.println();
-    }
-
-    /**
-     * Prints entries in a byte array as space separated hex values to {@link TTY}.
-     * 
-     * @param address an address at which the bytes are located. This is used to print an address
-     *            prefix per line of output.
-     * @param array the array containing all the bytes to print
-     * @param bytesPerLine the number of values to print per line of output
-     */
-    public static void printBytes(long address, byte[] array, int bytesPerLine) {
-        printBytes(address, array, 0, array.length, bytesPerLine);
-    }
-
-    /**
-     * Prints entries in a byte array as space separated hex values to {@link TTY}.
-     * 
-     * @param address an address at which the bytes are located. This is used to print an address
-     *            prefix per line of output.
-     * @param array the array containing the bytes to print
-     * @param offset the offset in {@code array} of the values to print
-     * @param length the number of values from {@code array} print
-     * @param bytesPerLine the number of values to print per line of output
-     */
-    public static void printBytes(long address, byte[] array, int offset, int length, int bytesPerLine) {
-        assert bytesPerLine > 0;
-        boolean newLine = true;
-        for (int i = 0; i < length; i++) {
-            if (newLine) {
-                TTY.print("%08x: ", address + i);
-                newLine = false;
-            }
-            TTY.print("%02x ", array[i]);
-            if (i % bytesPerLine == bytesPerLine - 1) {
-                TTY.println();
-                newLine = true;
-            }
-        }
-
-        if (length % bytesPerLine != bytesPerLine) {
-            TTY.println();
-        }
-    }
-
-    public static boolean isShiftCount(int x) {
-        return 0 <= x && x < 32;
-    }
-
-    /**
-     * Determines if a given {@code int} value is the range of unsigned byte values.
-     */
-    public static boolean isUByte(int x) {
-        return (x & 0xff) == x;
-    }
-
-    /**
-     * Determines if a given {@code int} value is the range of signed byte values.
-     */
-    public static boolean isByte(int x) {
-        return (byte) x == x;
-    }
-
-    /**
-     * Determines if a given {@code long} value is the range of unsigned byte values.
-     */
-    public static boolean isUByte(long x) {
-        return (x & 0xffL) == x;
-    }
-
-    /**
-     * Determines if a given {@code long} value is the range of signed byte values.
-     */
-    public static boolean isByte(long l) {
-        return (byte) l == l;
-    }
-
-    /**
-     * Determines if a given {@code long} value is the range of unsigned int values.
-     */
-    public static boolean isUInt(long x) {
-        return (x & 0xffffffffL) == x;
-    }
-
-    /**
-     * Determines if a given {@code long} value is the range of signed int values.
-     */
-    public static boolean isInt(long l) {
-        return (int) l == l;
-    }
-
-    /**
-     * Determines if a given {@code int} value is the range of signed short values.
-     */
-    public static boolean isShort(int x) {
-        return (short) x == x;
-    }
-
-    public static boolean is32bit(long x) {
-        return -0x80000000L <= x && x < 0x80000000L;
-    }
-
-    public static short safeToShort(int v) {
-        assert isShort(v);
-        return (short) v;
-    }
-
-    /**
-     * Creates an array of integers of length "size", in which each number from 0 to (size - 1)
-     * occurs exactly once. The integers are sorted using the given comparator. This can be used to
-     * create a sorting for arrays that cannot be modified directly.
-     * 
-     * @param size The size of the range to be sorted.
-     * @param comparator A comparator that is used to compare indexes.
-     * @return An array of integers that contains each number from 0 to (size - 1) exactly once,
-     *         sorted using the comparator.
-     */
-    public static Integer[] createSortedPermutation(int size, Comparator<Integer> comparator) {
-        Integer[] indexes = new Integer[size];
-        for (int i = 0; i < size; i++) {
-            indexes[i] = i;
-        }
-        Arrays.sort(indexes, comparator);
-        return indexes;
-    }
-}
--- a/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapeClosure.java	Wed Feb 04 18:21:29 2015 +0100
+++ b/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapeClosure.java	Wed Feb 04 18:24:05 2015 +0100
@@ -28,6 +28,7 @@
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.compiler.common.*;
 import com.oracle.graal.compiler.common.type.*;
+import com.oracle.graal.compiler.common.util.*;
 import com.oracle.graal.debug.*;
 import com.oracle.graal.graph.*;
 import com.oracle.graal.nodes.*;
@@ -38,7 +39,6 @@
 import com.oracle.graal.nodes.spi.Virtualizable.EscapeState;
 import com.oracle.graal.nodes.virtual.*;
 import com.oracle.graal.phases.schedule.*;
-import com.oracle.graal.phases.util.*;
 import com.oracle.graal.virtual.nodes.*;
 
 public abstract class PartialEscapeClosure<BlockT extends PartialEscapeBlockState<BlockT>> extends EffectsClosure<BlockT> {