451 rest = rest >> 1;
452 }
453 }
454 return true;
455 }
456
457 BitMap::idx_t* BitMap::_pop_count_table = NULL;
458
459 void BitMap::init_pop_count_table() {
460 if (_pop_count_table == NULL) {
461 BitMap::idx_t *table = NEW_C_HEAP_ARRAY(idx_t, 256, mtInternal);
462 for (uint i = 0; i < 256; i++) {
463 table[i] = num_set_bits(i);
464 }
465
466 intptr_t res = Atomic::cmpxchg_ptr((intptr_t) table,
467 (intptr_t*) &_pop_count_table,
468 (intptr_t) NULL_WORD);
469 if (res != NULL_WORD) {
470 guarantee( _pop_count_table == (void*) res, "invariant" );
471 FREE_C_HEAP_ARRAY(idx_t, table, mtInternal);
472 }
473 }
474 }
475
476 BitMap::idx_t BitMap::num_set_bits(bm_word_t w) {
477 idx_t bits = 0;
478
479 while (w != 0) {
480 while ((w & 1) == 0) {
481 w >>= 1;
482 }
483 bits++;
484 w >>= 1;
485 }
486 return bits;
487 }
488
489 BitMap::idx_t BitMap::num_set_bits_from_table(unsigned char c) {
490 assert(_pop_count_table != NULL, "precondition");
491 return _pop_count_table[c];
|
451 rest = rest >> 1;
452 }
453 }
454 return true;
455 }
456
457 BitMap::idx_t* BitMap::_pop_count_table = NULL;
458
459 void BitMap::init_pop_count_table() {
460 if (_pop_count_table == NULL) {
461 BitMap::idx_t *table = NEW_C_HEAP_ARRAY(idx_t, 256, mtInternal);
462 for (uint i = 0; i < 256; i++) {
463 table[i] = num_set_bits(i);
464 }
465
466 intptr_t res = Atomic::cmpxchg_ptr((intptr_t) table,
467 (intptr_t*) &_pop_count_table,
468 (intptr_t) NULL_WORD);
469 if (res != NULL_WORD) {
470 guarantee( _pop_count_table == (void*) res, "invariant" );
471 FREE_C_HEAP_ARRAY(idx_t, table);
472 }
473 }
474 }
475
476 BitMap::idx_t BitMap::num_set_bits(bm_word_t w) {
477 idx_t bits = 0;
478
479 while (w != 0) {
480 while ((w & 1) == 0) {
481 w >>= 1;
482 }
483 bits++;
484 w >>= 1;
485 }
486 return bits;
487 }
488
489 BitMap::idx_t BitMap::num_set_bits_from_table(unsigned char c) {
490 assert(_pop_count_table != NULL, "precondition");
491 return _pop_count_table[c];
|