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::cmpxchg_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) {
|
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::cmpxchg(table, &_pop_count_table, (BitMap::idx_t*)NULL) != NULL) {
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) {
|