changeset 5542:e318468952f5

Remove CiBitMap and replace usages with java.util.BitSet.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Sat, 09 Jun 2012 17:13:21 +0200
parents b4c406861c33
children 25d561cfdcfa
files graal/com.oracle.graal.alloc/src/com/oracle/graal/alloc/simple/AssignRegisters.java graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CiBitMap.java graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CiDebugInfo.java graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CiTargetMethod.java graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CiUtil.java graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScan.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/FrameMap.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRDebugInfo.java graal/com.oracle.max.criutils/src/com/oracle/max/criutils/CompilationPrinter.java src/share/vm/classfile/vmSymbols.hpp src/share/vm/graal/graalCodeInstaller.cpp src/share/vm/graal/graalJavaAccess.hpp
diffstat 12 files changed, 42 insertions(+), 731 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.alloc/src/com/oracle/graal/alloc/simple/AssignRegisters.java	Sat Jun 09 16:52:12 2012 +0200
+++ b/graal/com.oracle.graal.alloc/src/com/oracle/graal/alloc/simple/AssignRegisters.java	Sat Jun 09 17:13:21 2012 +0200
@@ -24,8 +24,9 @@
 
 import static com.oracle.graal.alloc.util.LocationUtil.*;
 
+import java.util.*;
+
 import com.oracle.graal.alloc.util.*;
-import com.oracle.graal.api.code.*;
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.debug.*;
 import com.oracle.graal.lir.*;
@@ -41,8 +42,8 @@
         this.frameMap = frameMap;
     }
 
-    private CiBitMap curRegisterRefMap;
-    private CiBitMap curFrameRefMap;
+    private BitSet curRegisterRefMap;
+    private BitSet curFrameRefMap;
 
     public void execute() {
         ValueProcedure useProc =          new ValueProcedure() { @Override public Value doValue(Value value) { return use(value); } };
@@ -71,12 +72,12 @@
 
                 if (op.info != null) {
                     Debug.log("    registerRefMap: %s  frameRefMap: %s", curRegisterRefMap, curFrameRefMap);
-                    op.info.finish(new CiBitMap(curRegisterRefMap), new CiBitMap(curFrameRefMap), frameMap);
+                    op.info.finish((BitSet) (curRegisterRefMap.clone()), (BitSet) (curFrameRefMap.clone()), frameMap);
 
                     if (op instanceof LIRXirInstruction) {
                         LIRXirInstruction xir = (LIRXirInstruction) op;
                         if (xir.infoAfter != null) {
-                            xir.infoAfter.finish(new CiBitMap(curRegisterRefMap), new CiBitMap(curFrameRefMap), frameMap);
+                            xir.infoAfter.finish((BitSet) (curRegisterRefMap.clone()), (BitSet) (curFrameRefMap.clone()), frameMap);
                         }
                     }
                 }
--- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CiBitMap.java	Sat Jun 09 16:52:12 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,686 +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.api.code;
-
-import java.io.*;
-import java.util.*;
-
-/**
- * Implements a bitmap that stores a single bit for a range of integers (0-n).
- */
-public final class CiBitMap implements Serializable {
-
-    private static final long serialVersionUID = 2471441272241401105L;
-    private static final int ADDRESS_BITS_PER_WORD = 6;
-    private static final int BITS_PER_WORD = 1 << ADDRESS_BITS_PER_WORD;
-    private static final int BIT_INDEX_MASK = BITS_PER_WORD - 1;
-
-    public static final int DEFAULT_LENGTH = BITS_PER_WORD;
-
-    public static int roundUpLength(int length) {
-        return ((length + (BITS_PER_WORD - 1)) >> ADDRESS_BITS_PER_WORD) << ADDRESS_BITS_PER_WORD;
-    }
-
-    private int size;
-    private long low;
-    private long[] extra;
-
-    /**
-     * Constructs a new bit map with the {@linkplain #DEFAULT_LENGTH default length}.
-     */
-    public CiBitMap() {
-        this(DEFAULT_LENGTH);
-    }
-
-    /**
-     * Constructs a new bit map from a byte array encoded bit map.
-     *
-     * @param bitmap the bit map to convert
-     */
-    public CiBitMap(byte[] bitmap) {
-        this(bitmap, 0, bitmap.length);
-    }
-
-    /**
-     * Constructs a copy of the given bit map.
-     *
-     * @param bitmap the bit map to copy.
-     */
-    public CiBitMap(CiBitMap bitmap) {
-        this.size = bitmap.size;
-        this.low = bitmap.low;
-        if (bitmap.extra != null) {
-            this.extra = Arrays.copyOf(bitmap.extra, bitmap.extra.length);
-        }
-    }
-
-    /**
-     * Constructs a new bit map from a byte array encoded bit map.
-     *
-     * @param arr the byte array containing the bit map to convert
-     * @param off the byte index in {@code arr} at which the bit map starts
-     * @param numberOfBytes the number of bytes worth of bits to copy from {@code arr}
-     */
-    public CiBitMap(byte[] arr, int off, int numberOfBytes) {
-        this(numberOfBytes * 8);
-        int byteIndex = off;
-        int end = off + numberOfBytes;
-        assert end <= arr.length;
-        while (byteIndex < end && (byteIndex - off) < 8) {
-            long bite = (long) arr[byteIndex] & 0xff;
-            low |= bite << ((byteIndex - off) * 8);
-            byteIndex++;
-        }
-        if (byteIndex < end) {
-            assert (byteIndex - off) == 8;
-            int remBytes = end - byteIndex;
-            int remWords = (remBytes + 7) / 8;
-            for (int word = 0; word < remWords; word++) {
-                long w = 0L;
-                for (int i = 0; i < 8 && byteIndex < end; i++) {
-                    long bite = (long) arr[byteIndex] & 0xff;
-                    w |= bite << (i * 8);
-                    byteIndex++;
-                }
-                extra[word] = w;
-            }
-        }
-    }
-
-    /**
-     * Converts a {@code long} to a {@link CiBitMap}.
-     */
-    public static CiBitMap fromLong(long bitmap) {
-        CiBitMap bm = new CiBitMap(64);
-        bm.low = bitmap;
-        return bm;
-    }
-
-    /**
-     * Constructs a new bit map with the specified length.
-     *
-     * @param length the length of the bitmap
-     */
-    public CiBitMap(int length) {
-        assert length >= 0;
-        this.size = length;
-        if (length > BITS_PER_WORD) {
-            extra = new long[length >> ADDRESS_BITS_PER_WORD];
-        }
-    }
-
-    /**
-     * Sets the bit at the specified index.
-     *
-     * @param i the index of the bit to set
-     */
-    public void set(int i) {
-        if (checkIndex(i) < BITS_PER_WORD) {
-            low |= 1L << i;
-        } else {
-            int pos = wordIndex(i);
-            int index = bitInWord(i);
-            extra[pos] |= 1L << index;
-        }
-    }
-
-    /**
-     * Grows this bitmap to a new size, appending necessary zero bits.
-     *
-     * @param newLength the new length of the bitmap
-     */
-    public void grow(int newLength) {
-        if (newLength > size) {
-            // grow this bitmap to the new length
-            int newSize = newLength >> ADDRESS_BITS_PER_WORD;
-            if (newLength > 0) {
-                if (extra == null) {
-                    // extra just needs to be allocated now
-                    extra = new long[newSize];
-                } else {
-                    if (extra.length < newSize) {
-                        // extra needs to be copied
-                        long[] newExtra = new long[newSize];
-                        for (int i = 0; i < extra.length; i++) {
-                            newExtra[i] = extra[i];
-                        }
-                        extra = newExtra;
-                    } else {
-                        // nothing to do, extra is already the right size
-                    }
-                }
-            }
-            size = newLength;
-        }
-    }
-
-    private static int bitInWord(int i) {
-        return i & BIT_INDEX_MASK;
-    }
-
-    private static int wordIndex(int i) {
-        return (i >> ADDRESS_BITS_PER_WORD) - 1;
-    }
-
-    /**
-     * Clears the bit at the specified index.
-     * @param i the index of the bit to clear
-     */
-    public void clear(int i) {
-        if (checkIndex(i) < BITS_PER_WORD) {
-            low &= ~(1L << i);
-        } else {
-            int pos = wordIndex(i);
-            int index = bitInWord(i);
-            extra[pos] &= ~(1L << index);
-        }
-    }
-
-    /**
-     * Sets all the bits in this bitmap.
-     */
-    public void setAll() {
-        low = -1;
-        if (extra != null) {
-            for (int i = 0; i < extra.length; i++) {
-                extra[i] = -1;
-            }
-        }
-    }
-
-    /**
-     * Clears all the bits in this bitmap.
-     */
-    public void clearAll() {
-        low = 0;
-        if (extra != null) {
-            for (int i = 0; i < extra.length; i++) {
-                extra[i] = 0;
-            }
-        }
-    }
-
-    /**
-     * Gets the value of the bit at the specified index.
-     *
-     * @param i the index of the bit to get
-     * @return {@code true} if the bit at the specified position is {@code 1}
-     */
-    public boolean get(int i) {
-        if (checkIndex(i) < BITS_PER_WORD) {
-            return ((low >> i) & 1) != 0;
-        }
-        int pos = wordIndex(i);
-        int index = bitInWord(i);
-        long bits = extra[pos];
-        return ((bits >> index) & 1) != 0;
-    }
-
-    /**
-     * Gets the value of the bit at the specified index, returning {@code false} if the
-     * bitmap does not cover the specified index.
-     *
-     * @param i the index of the bit to get
-     * @return {@code true} if the bit at the specified position is {@code 1}
-     */
-    public boolean getDefault(int i) {
-        if (i < 0 || i >= size) {
-            return false;
-        }
-        if (i < BITS_PER_WORD) {
-            return ((low >> i) & 1) != 0;
-        }
-        int pos = wordIndex(i);
-        int index = bitInWord(i);
-        long bits = extra[pos];
-        return ((bits >> index) & 1) != 0;
-    }
-
-    /**
-     * Performs the union operation on this bitmap with the specified bitmap. That is, all bits set in either of the two
-     * bitmaps will be set in this bitmap following this operation.
-     *
-     * @param other the other bitmap for the union operation
-     */
-    public void setUnion(CiBitMap other) {
-        low |= other.low;
-        if (extra != null && other.extra != null) {
-            for (int i = 0; i < extra.length && i < other.extra.length; i++) {
-                extra[i] |= other.extra[i];
-            }
-        }
-    }
-
-    /**
-     * Performs the union operation on this bitmap with the specified bitmap. That is, a bit is set in this
-     * bitmap if and only if it is set in both this bitmap and the specified bitmap.
-     *
-     * @param other the other bitmap for this operation
-     * @return {@code true} if any bits were cleared as a result of this operation
-     */
-    public boolean setIntersect(CiBitMap other) {
-        boolean same = true;
-        long intx = low & other.low;
-        if (low != intx) {
-            same = false;
-            low = intx;
-        }
-        long[] oxtra = other.extra;
-        if (extra != null && oxtra != null) {
-            for (int i = 0; i < extra.length; i++) {
-                long a = extra[i];
-                if (i < oxtra.length) {
-                    // zero bits out of this map
-                    long ax = a & oxtra[i];
-                    if (a != ax) {
-                        same = false;
-                        extra[i] = ax;
-                    }
-                } else {
-                    // this bitmap is larger than the specified bitmap; zero remaining bits
-                    if (a != 0) {
-                        same = false;
-                        extra[i] = 0;
-                    }
-                }
-            }
-        }
-        return !same;
-    }
-
-    /**
-     * Gets the number of addressable bits in this bitmap.
-     *
-     * @return the size of this bitmap
-     */
-    public int size() {
-        return size;
-    }
-
-    private int checkIndex(int i) {
-        if (i < 0 || i >= size) {
-            throw new IndexOutOfBoundsException();
-        }
-        return i;
-    }
-
-    public void setFrom(CiBitMap other) {
-        assert this.size == other.size : "must have same size";
-
-        low = other.low;
-        if (extra != null) {
-            for (int i = 0; i < extra.length; i++) {
-                extra[i] = other.extra[i];
-            }
-        }
-    }
-
-    public void setDifference(CiBitMap other) {
-        assert this.size == other.size : "must have same size";
-
-        low &= ~other.low;
-        if (extra != null) {
-            for (int i = 0; i < extra.length; i++) {
-                extra[i] &= ~other.extra[i];
-            }
-        }
-    }
-
-    public boolean isSame(CiBitMap other) {
-        if (this.size != other.size || this.low != other.low) {
-            return false;
-        }
-
-        if (extra != null) {
-            for (int i = 0; i < extra.length; i++) {
-                if (extra[i] != other.extra[i]) {
-                    return false;
-                }
-            }
-        }
-
-        return true;
-    }
-
-    /**
-     * Returns the index of the first set bit that occurs on or after a specified start index.
-     * If no such bit exists then -1 is returned.
-     * <p>
-     * To iterate over the set bits in a {@code BitMap}, use the following loop:
-     *
-     * <pre>
-     * for (int i = bitMap.nextSetBit(0); i &gt;= 0; i = bitMap.nextSetBit(i + 1)) {
-     *     // operate on index i here
-     * }
-     * </pre>
-     *
-     * @param fromIndex the index to start checking from (inclusive)
-     * @return the index of the lowest set bit between {@code [fromIndex .. size())} or -1 if there is no set bit in this range
-     * @throws IndexOutOfBoundsException if the specified index is negative.
-     */
-    public int nextSetBit(int fromIndex) {
-        return nextSetBit(fromIndex, size());
-    }
-
-    /**
-     * Returns the index of the first set bit that occurs on or after a specified start index
-     * and before a specified end index. If no such bit exists then -1 is returned.
-     * <p>
-     * To iterate over the set bits in a {@code BitMap}, use the following loop:
-     *
-     * <pre>
-     * for (int i = bitMap.nextSetBit(0, bitMap.size()); i &gt;= 0; i = bitMap.nextSetBit(i + 1, bitMap.size())) {
-     *     // operate on index i here
-     * }
-     * </pre>
-     *
-     * @param fromIndex the index to start checking from (inclusive)
-     * @param toIndex the index at which to stop checking (exclusive)
-     * @return the index of the lowest set bit between {@code [fromIndex .. toIndex)} or -1 if there is no set bit in this range
-     * @throws IndexOutOfBoundsException if the specified index is negative.
-     */
-    public int nextSetBit(int fromIndex, int toIndex) {
-        assert fromIndex <= size() : "index out of bounds";
-        assert toIndex <= size() : "index out of bounds";
-        assert fromIndex <= toIndex : "fromIndex > toIndex";
-
-        if (fromIndex == toIndex) {
-            return -1;
-        }
-        int fromWordIndex = wordIndex(fromIndex);
-        int toWordIndex = wordIndex(toIndex - 1) + 1;
-        int resultIndex = fromIndex;
-
-        // check bits including and to the left_ of offset's position
-        int pos = bitInWord(resultIndex);
-        long res = map(fromWordIndex) >> pos;
-        if (res != 0) {
-            resultIndex += Long.numberOfTrailingZeros(res);
-            assert resultIndex >= fromIndex && resultIndex < toIndex : "just checking";
-            if (resultIndex < toIndex) {
-                return resultIndex;
-            }
-            return -1;
-        }
-        // skip over all word length 0-bit runs
-        for (fromWordIndex++; fromWordIndex < toWordIndex; fromWordIndex++) {
-            res = map(fromWordIndex);
-            if (res != 0) {
-                // found a 1, return the offset
-                resultIndex = bitIndex(fromWordIndex) + Long.numberOfTrailingZeros(res);
-                assert resultIndex >= fromIndex : "just checking";
-                if (resultIndex < toIndex) {
-                    return resultIndex;
-                }
-                return -1;
-            }
-        }
-        return -1;
-    }
-
-    private static int bitIndex(int index) {
-        return (index + 1) << ADDRESS_BITS_PER_WORD;
-    }
-
-    private long map(int index) {
-        if (index == -1) {
-            return low;
-        }
-        return extra[index];
-    }
-
-    private static boolean allZeros(int start, long[] arr) {
-        for (int i = start; i < arr.length; i++) {
-            if (arr[i] != 0) {
-                return false;
-            }
-        }
-        return true;
-    }
-
-    /**
-     * Compares this object against the specified object.
-     * The result is {@code true} if and only if {@code obj} is
-     * not {@code null} and is a {@code CiBitMap} object that has
-     * exactly the same set of bits set to {@code true} as this bit
-     * set.
-     *
-     * @param   obj   the object to compare with.
-     */
-    @Override
-    public boolean equals(Object obj) {
-        if (obj instanceof CiBitMap) {
-            CiBitMap bm = (CiBitMap) obj;
-            if (bm.low == low) {
-                if (bm.extra == null) {
-                    if (extra == null) {
-                        // Common case
-                        return true;
-                    }
-                    return allZeros(0, extra);
-                }
-                if (extra == null) {
-                    return allZeros(0, bm.extra);
-                }
-                // both 'extra' array non null:
-                int i = 0;
-                int length = Math.min(extra.length, bm.extra.length);
-                while (i < length) {
-                    if (extra[i] != bm.extra[i]) {
-                        return false;
-                    }
-                    i++;
-                }
-                if (extra.length > bm.extra.length) {
-                    return allZeros(length, extra);
-                }
-                if (extra.length < bm.extra.length) {
-                    return allZeros(length, bm.extra);
-                }
-                return true;
-            }
-        }
-        return false;
-    }
-
-    @Override
-    public int hashCode() {
-        return (int) low ^ size;
-    }
-
-    /**
-     * Returns a string representation of this bit map
-     * that is the same as the string returned by {@link BitSet#toString()}
-     * for a bit set with the same bits set as this bit map.
-     */
-    @Override
-    public String toString() {
-        StringBuilder sb = new StringBuilder(size * 2);
-        sb.append('{');
-
-        int bit = nextSetBit(0);
-        if (bit != -1) {
-            sb.append(bit);
-            for (bit = nextSetBit(bit + 1); bit >= 0; bit = nextSetBit(bit + 1)) {
-                sb.append(", ").append(bit);
-            }
-        }
-
-        sb.append('}');
-        return sb.toString();
-    }
-
-    public static int highestOneBitIndex(long value) {
-        int bit = Long.numberOfTrailingZeros(Long.highestOneBit(value));
-        if (bit == 64) {
-            return -1;
-        }
-        return bit;
-    }
-
-    /**
-     * Returns the number of bits set to {@code true} in this bit map.
-     */
-    public int cardinality() {
-        int sum = Long.bitCount(low);
-        if (extra != null) {
-            for (long word : extra) {
-                sum += Long.bitCount(word);
-            }
-        }
-        return sum;
-    }
-
-    /**
-     * Returns the "logical size" of this bit map: the index of
-     * the highest set bit in the bit map plus one. Returns zero
-     * if the bit map contains no set bits.
-     *
-     * @return  the logical size of this bit map
-     */
-    public int length() {
-        if (extra != null) {
-            for (int i = extra.length - 1; i >= 0; i--) {
-                if (extra[i] != 0) {
-                    return (highestOneBitIndex(extra[i]) + ((i + 1) * 64)) + 1;
-                }
-            }
-        }
-        return highestOneBitIndex(low) + 1;
-    }
-
-    /**
-     * Returns a string representation of this bit map with every set bit represented as {@code '1'}
-     * and every unset bit represented as {@code '0'}. The first character in the returned string represents
-     * bit 0 in this bit map.
-     *
-     * @param length the number of bits represented in the returned string. If {@code length < 0 || length > size()},
-     *            then the value of {@link #length()} is used.
-     */
-    public String toBinaryString() {
-        int length = length();
-        if (length == 0) {
-            return "";
-        }
-        StringBuilder sb = new StringBuilder(length);
-        for (int i = 0; i < length; ++i) {
-            sb.append(get(i) ? '1' : '0');
-        }
-        return sb.toString();
-    }
-
-    static final char[] hexDigits = {
-        '0', '1', '2', '3', '4', '5', '6', '7',
-        '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
-    };
-
-    private static int align(int size, int align) {
-        return (size + align - 1) & ~(align - 1);
-    }
-
-    /**
-     * Returns a string representation of this bit map in hex.
-     */
-    public String toHexString() {
-        if (size == 0) {
-            return "";
-        }
-        int hexSize = align(this.size, 4);
-        StringBuilder sb = new StringBuilder(hexSize / 4);
-        for (int i = 0; i < hexSize; i += 4) {
-            int nibble = get(i) ? 1 : 0;
-            if (get(i + 1)) {
-                nibble |= 2;
-            }
-            if (get(i + 2)) {
-                nibble |= 4;
-            }
-            if (get(i + 3)) {
-                nibble |= 8;
-            }
-
-            sb.append(hexDigits[nibble]);
-        }
-        return sb.toString();
-    }
-
-    public CiBitMap copy() {
-        CiBitMap n = new CiBitMap(BITS_PER_WORD);
-        n.low = low;
-        if (extra != null) {
-            n.extra = Arrays.copyOf(extra, extra.length);
-        }
-        n.size = size;
-        return n;
-    }
-
-    /**
-     * Copies this bit map into a given byte array.
-     *
-     * @param arr the destination
-     * @param off the byte index in {@code arr} at which to start writing
-     * @param numberOfBytes the number of bytes worth of bits to copy from this bit map.
-     *        The number of bits copied is {@code numberOfBytes * 8}. If {@code numberOfBytes}
-     *        is -1, then {@code ((size() + 7) / 8)} is used instead.
-     * @return the number of bytes written to {@code arr}
-     */
-    public int copyTo(byte[] arr, int off, int numberOfBytes) {
-        for (int i = 0; i < numberOfBytes; ++i) {
-            long word = low;
-            int byteInWord;
-            if (i >= 8) {
-                int wordIndex = (i - 8) / 8;
-                word = extra[wordIndex];
-                byteInWord = i & 0x7;
-            } else {
-                byteInWord = i;
-            }
-            assert byteInWord < 8;
-            byte b = (byte) (word >> (byteInWord * 8));
-            arr[off + i] = b;
-        }
-        return numberOfBytes;
-    }
-
-    /**
-     * Converts this bit map to a byte array. The length of the returned
-     * byte array is {@code ((size() + 7) / 8)}.
-     */
-    public byte[] toByteArray() {
-        byte[] arr = new byte[(size + 7) / 8];
-        copyTo(arr, 0, arr.length);
-        return arr;
-    }
-
-    /**
-     * Converts this bit map to a long.
-     *
-     * @throws IllegalArgumentException if {@code (size() > 64)}
-     */
-    public long toLong() {
-        if (size > 64) {
-            throw new IllegalArgumentException("bit map of size " + size + " cannot be converted to long");
-        }
-        return low;
-    }
-}
--- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CiDebugInfo.java	Sat Jun 09 16:52:12 2012 +0200
+++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CiDebugInfo.java	Sat Jun 09 17:13:21 2012 +0200
@@ -23,6 +23,7 @@
 package com.oracle.graal.api.code;
 
 import java.io.*;
+import java.util.*;
 
 /**
  * Represents the debugging information for a particular place in the code,
@@ -43,13 +44,13 @@
      * for bit {@code k} in byte {@code n}, it refers to the register whose
      * {@linkplain CiRegister#number number} is {@code (k + n * 8)}.
      */
-    public final CiBitMap registerRefMap;
+    public final BitSet registerRefMap;
 
     /**
      * The reference map for the stack frame at this point. A set bit at {@code k} in the map
      * represents stack slot number {@code k}.
      */
-    public final CiBitMap frameRefMap;
+    public final BitSet frameRefMap;
 
     /**
      * Creates a new {@code CiDebugInfo} from the given values.
@@ -58,7 +59,7 @@
      * @param registerRefMap the register map
      * @param frameRefMap the reference map for {@code frame}, which may be {@code null}
      */
-    public CiDebugInfo(CiCodePos codePos, CiBitMap registerRefMap, CiBitMap frameRefMap) {
+    public CiDebugInfo(CiCodePos codePos, BitSet registerRefMap, BitSet frameRefMap) {
         this.codePos = codePos;
         this.registerRefMap = registerRefMap;
         this.frameRefMap = frameRefMap;
--- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CiTargetMethod.java	Sat Jun 09 16:52:12 2012 +0200
+++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CiTargetMethod.java	Sat Jun 09 17:13:21 2012 +0200
@@ -547,9 +547,9 @@
         }
     }
 
-    private static void appendRefMap(StringBuilder sb, String name, CiBitMap map) {
+    private static void appendRefMap(StringBuilder sb, String name, BitSet map) {
         if (map != null) {
-            sb.append(' ').append(name).append('[').append(map.toBinaryString()).append(']');
+            sb.append(' ').append(name).append('[').append(map.toString()).append(']');
         }
     }
 }
--- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CiUtil.java	Sat Jun 09 16:52:12 2012 +0200
+++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CiUtil.java	Sat Jun 09 17:13:21 2012 +0200
@@ -577,7 +577,7 @@
         String nl = NEW_LINE;
         if (info.hasRegisterRefMap()) {
             sb.append("  reg-ref-map:");
-            CiBitMap bm = info.registerRefMap;
+            BitSet bm = info.registerRefMap;
             if (formatter != null) {
                 for (int reg = bm.nextSetBit(0); reg >= 0; reg = bm.nextSetBit(reg + 1)) {
                     sb.append(" " + formatter.formatRegister(reg));
@@ -587,7 +587,7 @@
         }
         if (info.hasStackRefMap()) {
             sb.append("frame-ref-map:");
-            CiBitMap bm = info.frameRefMap;
+            BitSet bm = info.frameRefMap;
             if (formatter != null) {
                 for (int i = bm.nextSetBit(0); i >= 0; i = bm.nextSetBit(i + 1)) {
                     sb.append(" " + formatter.formatStackSlot(i));
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScan.java	Sat Jun 09 16:52:12 2012 +0200
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScan.java	Sat Jun 09 17:13:21 2012 +0200
@@ -1652,7 +1652,7 @@
         return new IntervalWalker(this, oopIntervals, nonOopIntervals);
     }
 
-    void computeOopMap(IntervalWalker iw, LIRInstruction op, CiBitMap registerRefMap, CiBitMap frameRefMap) {
+    void computeOopMap(IntervalWalker iw, LIRInstruction op, BitSet registerRefMap, BitSet frameRefMap) {
         if (GraalOptions.TraceLinearScanLevel >= 3) {
             TTY.println("creating oop map at opId %d", op.id());
         }
@@ -1712,8 +1712,8 @@
 
 
     private void computeDebugInfo(IntervalWalker iw, final LIRInstruction op, LIRDebugInfo info) {
-        CiBitMap registerRefMap = op.hasCall() ? null : frameMap.initRegisterRefMap();
-        CiBitMap frameRefMap = frameMap.initFrameRefMap();
+        BitSet registerRefMap = op.hasCall() ? null : frameMap.initRegisterRefMap();
+        BitSet frameRefMap = frameMap.initFrameRefMap();
         computeOopMap(iw, op, registerRefMap, frameRefMap);
 
         info.forEachState(new ValueProcedure() {
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/FrameMap.java	Sat Jun 09 16:52:12 2012 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/FrameMap.java	Sat Jun 09 17:13:21 2012 +0200
@@ -297,8 +297,8 @@
     /**
      * Initializes a reference map that covers all registers of the target architecture.
      */
-    public CiBitMap initRegisterRefMap() {
-        return new CiBitMap(target.arch.registerReferenceMapBitCount);
+    public BitSet initRegisterRefMap() {
+        return new BitSet(target.arch.registerReferenceMapBitCount);
     }
 
     /**
@@ -306,8 +306,8 @@
      * slots in the frame. If the method has incoming reference arguments on the stack,
      * the reference map might grow later when such a reference is set.
      */
-    public CiBitMap initFrameRefMap() {
-        CiBitMap frameRefMap = new CiBitMap(frameSize() / target.wordSize);
+    public BitSet initFrameRefMap() {
+        BitSet frameRefMap = new BitSet(frameSize() / target.wordSize);
         for (CiStackSlot slot : objectStackBlocks) {
             setReference(slot, null, frameRefMap);
         }
@@ -323,14 +323,12 @@
      * @param registerRefMap A register reference map, as created by {@link #initRegisterRefMap()}.
      * @param frameRefMap A frame reference map, as created by {@link #initFrameRefMap()}.
      */
-    public void setReference(Value location, CiBitMap registerRefMap, CiBitMap frameRefMap) {
+    public void setReference(Value location, BitSet registerRefMap, BitSet frameRefMap) {
         if (location.kind == Kind.Object) {
             if (isRegister(location)) {
-                assert registerRefMap.size() == target.arch.registerReferenceMapBitCount;
                 registerRefMap.set(asRegister(location).number);
             } else if (isStackSlot(location)) {
                 int index = frameRefMapIndex(asStackSlot(location));
-                frameRefMap.grow(index + 1);
                 frameRefMap.set(index);
             } else {
                 assert isConstant(location);
@@ -347,10 +345,9 @@
      * @param registerRefMap A register reference map, as created by {@link #initRegisterRefMap()}.
      * @param frameRefMap A frame reference map, as created by {@link #initFrameRefMap()}.
      */
-    public void clearReference(Value location, CiBitMap registerRefMap, CiBitMap frameRefMap) {
+    public void clearReference(Value location, BitSet registerRefMap, BitSet frameRefMap) {
         if (location.kind == Kind.Object) {
             if (location instanceof CiRegisterValue) {
-                assert registerRefMap.size() == target.arch.registerReferenceMapBitCount;
                 registerRefMap.clear(asRegister(location).number);
             } else if (isStackSlot(location)) {
                 int index = frameRefMapIndex(asStackSlot(location));
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRDebugInfo.java	Sat Jun 09 16:52:12 2012 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRDebugInfo.java	Sat Jun 09 17:13:21 2012 +0200
@@ -110,7 +110,7 @@
     }
 
 
-    public void finish(CiBitMap registerRefMap, CiBitMap frameRefMap, FrameMap frameMap) {
+    public void finish(BitSet registerRefMap, BitSet frameRefMap, FrameMap frameMap) {
         debugInfo = new CiDebugInfo(topFrame, registerRefMap, frameRefMap);
 
         // Add additional stack slots for outgoing method parameters.
--- a/graal/com.oracle.max.criutils/src/com/oracle/max/criutils/CompilationPrinter.java	Sat Jun 09 16:52:12 2012 +0200
+++ b/graal/com.oracle.max.criutils/src/com/oracle/max/criutils/CompilationPrinter.java	Sat Jun 09 17:13:21 2012 +0200
@@ -106,7 +106,7 @@
     /**
      * Formats a given {@linkplain FrameState JVM frame state} as a multi line string.
      */
-    protected String debugInfoToString(CiCodePos codePos, CiBitMap registerRefMap, CiBitMap frameRefMap, CiArchitecture arch) {
+    protected String debugInfoToString(CiCodePos codePos, BitSet registerRefMap, BitSet frameRefMap, CiArchitecture arch) {
         StringBuilder sb = new StringBuilder();
 
         if (registerRefMap != null) {
--- a/src/share/vm/classfile/vmSymbols.hpp	Sat Jun 09 16:52:12 2012 +0200
+++ b/src/share/vm/classfile/vmSymbols.hpp	Sat Jun 09 17:13:21 2012 +0200
@@ -300,7 +300,7 @@
   template(com_oracle_max_cri_ci_CiTargetMethod_Safepoint,            "com/oracle/graal/api/code/CiTargetMethod$Safepoint")                   \
   template(com_oracle_max_cri_ci_CiTargetMethod_ExceptionHandler,     "com/oracle/graal/api/code/CiTargetMethod$ExceptionHandler")            \
   template(com_oracle_max_cri_ci_CiTargetMethod_Mark,                 "com/oracle/graal/api/code/CiTargetMethod$Mark")                        \
-  template(com_oracle_max_cri_ci_CiBitMap,	                          "com/oracle/graal/api/code/CiBitMap")                                   \
+  template(com_oracle_max_cri_ci_CiBitMap,	                          "java/util/BitSet")                                   \
   template(com_oracle_max_cri_ci_CiDebugInfo,                         "com/oracle/graal/api/code/CiDebugInfo")                                \
   template(com_oracle_max_cri_ci_CiFrame,                             "com/oracle/graal/api/code/CiFrame")                                    \
   template(com_oracle_max_cri_ci_CiValue,                             "com/oracle/graal/api/meta/Value")                                    \
--- a/src/share/vm/graal/graalCodeInstaller.cpp	Sat Jun 09 16:52:12 2012 +0200
+++ b/src/share/vm/graal/graalCodeInstaller.cpp	Sat Jun 09 17:13:21 2012 +0200
@@ -53,18 +53,19 @@
   }
 }
 
+const int MapWordBits = 64;
+
 static bool is_bit_set(oop bit_map, int i) {
-  const int MapWordBits = 64;
-  if (i < MapWordBits) {
-    jlong low = GraalBitMap::low(bit_map);
-    return (low & (1LL << i)) != 0;
-  } else {
-    jint extra_idx = (i - MapWordBits) / MapWordBits;
-    arrayOop extra = (arrayOop) GraalBitMap::extra(bit_map);
-    assert(extra_idx >= 0 && extra_idx < extra->length(), "unexpected index");
-    jlong word = ((jlong*) extra->base(T_LONG))[extra_idx];
-    return (word & (1LL << (i % MapWordBits))) != 0;
-  }
+  jint extra_idx = i / MapWordBits;
+  arrayOop extra = (arrayOop) GraalBitMap::words(bit_map);
+  assert(extra_idx >= 0 && extra_idx < extra->length(), "unexpected index");
+  jlong word = ((jlong*) extra->base(T_LONG))[extra_idx];
+  return (word & (1LL << (i % MapWordBits))) != 0;
+}
+
+static int bitmap_size(oop bit_map) {
+  arrayOop arr = (arrayOop) GraalBitMap::words(bit_map);
+  return arr->length() * MapWordBits;
 }
 
 // creates a hotspot oop map out of the byte arrays provided by CiDebugInfo
@@ -74,7 +75,6 @@
   oop frame_map = (oop) CiDebugInfo::frameRefMap(debug_info);
 
   if (register_map != NULL) {
-    assert(GraalBitMap::size(register_map) == (unsigned) NUM_CPU_REGS, "unexpected register_map length");
     for (jint i = 0; i < NUM_CPU_REGS; i++) {
       bool is_oop = is_bit_set(register_map, i);
       VMReg reg = get_hotspot_reg(i);
@@ -87,7 +87,7 @@
     }
   }
 
-  for (jint i = 0; i < GraalBitMap::size(frame_map); i++) {
+  for (jint i = 0; i < bitmap_size(frame_map); i++) {
     bool is_oop = is_bit_set(frame_map, i);
     // hotspot stack slots are 4 bytes
     VMReg reg = VMRegImpl::stack2reg(i * 2);
--- a/src/share/vm/graal/graalJavaAccess.hpp	Sat Jun 09 16:52:12 2012 +0200
+++ b/src/share/vm/graal/graalJavaAccess.hpp	Sat Jun 09 17:13:21 2012 +0200
@@ -154,13 +154,11 @@
   end_class                                                                             \
   start_class(CiDebugInfo)                                                              \
     oop_field(CiDebugInfo, codePos, "Lcom/oracle/graal/api/code/CiCodePos;")                \
-    oop_field(CiDebugInfo, registerRefMap, "Lcom/oracle/graal/api/code/CiBitMap;")          \
-    oop_field(CiDebugInfo, frameRefMap, "Lcom/oracle/graal/api/code/CiBitMap;")             \
+    oop_field(CiDebugInfo, registerRefMap, "Ljava/util/BitSet;")          \
+    oop_field(CiDebugInfo, frameRefMap, "Ljava/util/BitSet;")             \
   end_class                                                                             \
   start_class(GraalBitMap)                                                              \
-    int_field(GraalBitMap, size)                                                        \
-    long_field(GraalBitMap, low)                                                        \
-    oop_field(GraalBitMap, extra, "[J")                                                 \
+    oop_field(GraalBitMap, words, "[J")                                                 \
   end_class                                                                             \
   start_class(CiFrame)                                                                  \
     oop_field(CiFrame, values, "[Lcom/oracle/graal/api/meta/Value;")                      \