< prev index next >

src/share/vm/utilities/bitMap.cpp

Print this page
rev 13455 : [mq]: replace_if_null
rev 13457 : [mq]: fix_popc_table


 600 
 601   idx_t startIndex = word_index(leftOffset);
 602   idx_t endIndex   = MIN2(word_index(rightOffset) + 1, size_in_words());
 603   for (idx_t index = startIndex, offset = leftOffset;
 604        offset < rightOffset && index < endIndex;
 605        offset = (++index) << LogBitsPerWord) {
 606     idx_t rest = map(index) >> (offset & (BitsPerWord - 1));
 607     for (; offset < rightOffset && rest != 0; offset++) {
 608       if (rest & 1) {
 609         if (!blk->do_bit(offset)) return false;
 610         //  resample at each closure application
 611         // (see, for instance, CMS bug 4525989)
 612         rest = map(index) >> (offset & (BitsPerWord -1));
 613       }
 614       rest = rest >> 1;
 615     }
 616   }
 617   return true;
 618 }
 619 
 620 BitMap::idx_t* BitMap::_pop_count_table = NULL;
 621 
 622 void BitMap::init_pop_count_table() {
 623   if (_pop_count_table == NULL) {
 624     BitMap::idx_t *table = NEW_C_HEAP_ARRAY(idx_t, 256, mtInternal);
 625     for (uint i = 0; i < 256; i++) {
 626       table[i] = num_set_bits(i);
 627     }
 628 
 629     if (!Atomic::conditional_store_ptr(table, &_pop_count_table)) {
 630       guarantee(_pop_count_table != NULL, "invariant");
 631       FREE_C_HEAP_ARRAY(idx_t, table);
 632     }
 633   }
 634 }
 635 
 636 BitMap::idx_t BitMap::num_set_bits(bm_word_t w) {
 637   idx_t bits = 0;
 638 
 639   while (w != 0) {
 640     while ((w & 1) == 0) {
 641       w >>= 1;
 642     }
 643     bits++;
 644     w >>= 1;
 645   }
 646   return bits;
 647 }
 648 
 649 BitMap::idx_t BitMap::num_set_bits_from_table(unsigned char c) {




 600 
 601   idx_t startIndex = word_index(leftOffset);
 602   idx_t endIndex   = MIN2(word_index(rightOffset) + 1, size_in_words());
 603   for (idx_t index = startIndex, offset = leftOffset;
 604        offset < rightOffset && index < endIndex;
 605        offset = (++index) << LogBitsPerWord) {
 606     idx_t rest = map(index) >> (offset & (BitsPerWord - 1));
 607     for (; offset < rightOffset && rest != 0; offset++) {
 608       if (rest & 1) {
 609         if (!blk->do_bit(offset)) return false;
 610         //  resample at each closure application
 611         // (see, for instance, CMS bug 4525989)
 612         rest = map(index) >> (offset & (BitsPerWord -1));
 613       }
 614       rest = rest >> 1;
 615     }
 616   }
 617   return true;
 618 }
 619 
 620 const BitMap::idx_t* BitMap::_pop_count_table = NULL;
 621 
 622 void BitMap::init_pop_count_table() {
 623   if (_pop_count_table == NULL) {
 624     BitMap::idx_t *table = NEW_C_HEAP_ARRAY(idx_t, 256, mtInternal);
 625     for (uint i = 0; i < 256; i++) {
 626       table[i] = num_set_bits(i);
 627     }
 628 
 629     if (!Atomic::replace_if_null(table, &_pop_count_table)) {
 630       guarantee(_pop_count_table != NULL, "invariant");
 631       FREE_C_HEAP_ARRAY(idx_t, table);
 632     }
 633   }
 634 }
 635 
 636 BitMap::idx_t BitMap::num_set_bits(bm_word_t w) {
 637   idx_t bits = 0;
 638 
 639   while (w != 0) {
 640     while ((w & 1) == 0) {
 641       w >>= 1;
 642     }
 643     bits++;
 644     w >>= 1;
 645   }
 646   return bits;
 647 }
 648 
 649 BitMap::idx_t BitMap::num_set_bits_from_table(unsigned char c) {


< prev index next >