comparison graal/com.oracle.max.cri/src/com/sun/cri/ci/CiBitMap.java @ 4142:bc8527f3071c

Adjust code base to new level of warnings.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Sun, 18 Dec 2011 05:24:06 +0100
parents e233f5660da4
children f5328dda9714
comparison
equal deleted inserted replaced
4141:04d21be7a24f 4142:bc8527f3071c
28 /** 28 /**
29 * Implements a bitmap that stores a single bit for a range of integers (0-n). 29 * Implements a bitmap that stores a single bit for a range of integers (0-n).
30 */ 30 */
31 public final class CiBitMap implements Serializable { 31 public final class CiBitMap implements Serializable {
32 32
33 private static final long serialVersionUID = 2471441272241401105L;
33 private static final int ADDRESS_BITS_PER_WORD = 6; 34 private static final int ADDRESS_BITS_PER_WORD = 6;
34 private static final int BITS_PER_WORD = 1 << ADDRESS_BITS_PER_WORD; 35 private static final int BITS_PER_WORD = 1 << ADDRESS_BITS_PER_WORD;
35 private static final int BIT_INDEX_MASK = BITS_PER_WORD - 1; 36 private static final int BIT_INDEX_MASK = BITS_PER_WORD - 1;
36 37
37 public static final int DEFAULT_LENGTH = BITS_PER_WORD; 38 public static final int DEFAULT_LENGTH = BITS_PER_WORD;
158 } 159 }
159 size = newLength; 160 size = newLength;
160 } 161 }
161 } 162 }
162 163
163 private int bitInWord(int i) { 164 private static int bitInWord(int i) {
164 return i & BIT_INDEX_MASK; 165 return i & BIT_INDEX_MASK;
165 } 166 }
166 167
167 private int wordIndex(int i) { 168 private static int wordIndex(int i) {
168 return (i >> ADDRESS_BITS_PER_WORD) - 1; 169 return (i >> ADDRESS_BITS_PER_WORD) - 1;
169 } 170 }
170 171
171 /** 172 /**
172 * Clears the bit at the specified index. 173 * Clears the bit at the specified index.
422 } 423 }
423 } 424 }
424 return -1; 425 return -1;
425 } 426 }
426 427
427 private int bitIndex(int index) { 428 private static int bitIndex(int index) {
428 return (index + 1) << ADDRESS_BITS_PER_WORD; 429 return (index + 1) << ADDRESS_BITS_PER_WORD;
429 } 430 }
430 431
431 private long map(int index) { 432 private long map(int index) {
432 if (index == -1) { 433 if (index == -1) {
561 * bit 0 in this bit map. 562 * bit 0 in this bit map.
562 * 563 *
563 * @param length the number of bits represented in the returned string. If {@code length < 0 || length > size()}, 564 * @param length the number of bits represented in the returned string. If {@code length < 0 || length > size()},
564 * then the value of {@link #length()} is used. 565 * then the value of {@link #length()} is used.
565 */ 566 */
566 public String toBinaryString(int length) { 567 public String toBinaryString() {
567 if (length < 0 || length > size) { 568 int length = length();
568 length = length();
569 }
570 if (length == 0) { 569 if (length == 0) {
571 return ""; 570 return "";
572 } 571 }
573 StringBuilder sb = new StringBuilder(length); 572 StringBuilder sb = new StringBuilder(length);
574 for (int i = 0; i < length; ++i) { 573 for (int i = 0; i < length; ++i) {
587 */ 586 */
588 public String toHexString() { 587 public String toHexString() {
589 if (size == 0) { 588 if (size == 0) {
590 return ""; 589 return "";
591 } 590 }
592 int size = CiUtil.align(this.size, 4); 591 int hexSize = CiUtil.align(this.size, 4);
593 StringBuilder sb = new StringBuilder(size / 4); 592 StringBuilder sb = new StringBuilder(hexSize / 4);
594 for (int i = 0; i < size; i += 4) { 593 for (int i = 0; i < hexSize; i += 4) {
595 int nibble = get(i) ? 1 : 0; 594 int nibble = get(i) ? 1 : 0;
596 if (get(i + 1)) { 595 if (get(i + 1)) {
597 nibble |= 2; 596 nibble |= 2;
598 } 597 }
599 if (get(i + 2)) { 598 if (get(i + 2)) {
627 * The number of bits copied is {@code numberOfBytes * 8}. If {@code numberOfBytes} 626 * The number of bits copied is {@code numberOfBytes * 8}. If {@code numberOfBytes}
628 * is -1, then {@code ((size() + 7) / 8)} is used instead. 627 * is -1, then {@code ((size() + 7) / 8)} is used instead.
629 * @return the number of bytes written to {@code arr} 628 * @return the number of bytes written to {@code arr}
630 */ 629 */
631 public int copyTo(byte[] arr, int off, int numberOfBytes) { 630 public int copyTo(byte[] arr, int off, int numberOfBytes) {
632 if (numberOfBytes < 0) {
633 numberOfBytes = (size + 7) / 8;
634 }
635 for (int i = 0; i < numberOfBytes; ++i) { 631 for (int i = 0; i < numberOfBytes; ++i) {
636 long word = low; 632 long word = low;
637 int byteInWord; 633 int byteInWord;
638 if (i >= 8) { 634 if (i >= 8) {
639 int wordIndex = (i - 8) / 8; 635 int wordIndex = (i - 8) / 8;