0N/A/*
2122N/A * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "memory/allocation.inline.hpp"
1879N/A#include "opto/chaitin.hpp"
1879N/A#include "opto/compile.hpp"
1879N/A#include "opto/indexSet.hpp"
1879N/A#include "opto/regmask.hpp"
1879N/A
0N/A// This file defines the IndexSet class, a set of sparse integer indices.
0N/A// This data structure is used by the compiler in its liveness analysis and
0N/A// during register allocation. It also defines an iterator for this class.
0N/A
0N/A//-------------------------------- Initializations ------------------------------
0N/A
0N/AIndexSet::BitBlock IndexSet::_empty_block = IndexSet::BitBlock();
0N/A
0N/A#ifdef ASSERT
0N/A// Initialize statistics counters
2122N/Ajulong IndexSet::_alloc_new = 0;
2122N/Ajulong IndexSet::_alloc_total = 0;
0N/A
2122N/Ajulong IndexSet::_total_bits = 0;
2122N/Ajulong IndexSet::_total_used_blocks = 0;
2122N/Ajulong IndexSet::_total_unused_blocks = 0;
0N/A
0N/A// Per set, or all sets operation tracing
0N/Aint IndexSet::_serial_count = 1;
0N/A#endif
0N/A
0N/A// What is the first set bit in a 5 bit integer?
0N/Aconst byte IndexSetIterator::_first_bit[32] = {
0N/A 0, 0, 1, 0,
0N/A 2, 0, 1, 0,
0N/A 3, 0, 1, 0,
0N/A 2, 0, 1, 0,
0N/A 4, 0, 1, 0,
0N/A 2, 0, 1, 0,
0N/A 3, 0, 1, 0,
0N/A 2, 0, 1, 0
0N/A};
0N/A
0N/A// What is the second set bit in a 5 bit integer?
0N/Aconst byte IndexSetIterator::_second_bit[32] = {
0N/A 5, 5, 5, 1,
0N/A 5, 2, 2, 1,
0N/A 5, 3, 3, 1,
0N/A 3, 2, 2, 1,
0N/A 5, 4, 4, 1,
0N/A 4, 2, 2, 1,
0N/A 4, 3, 3, 1,
0N/A 3, 2, 2, 1
0N/A};
0N/A
0N/A// I tried implementing the IndexSetIterator with a window_size of 8 and
0N/A// didn't seem to get a noticeable speedup. I am leaving in the tables
0N/A// in case we want to switch back.
0N/A
0N/A/*const byte IndexSetIterator::_first_bit[256] = {
0N/A 8, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
0N/A 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
0N/A 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
0N/A 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
0N/A 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
0N/A 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
0N/A 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
0N/A 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
0N/A 7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
0N/A 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
0N/A 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
0N/A 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
0N/A 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
0N/A 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
0N/A 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
0N/A 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0
0N/A};
0N/A
0N/Aconst byte IndexSetIterator::_second_bit[256] = {
0N/A 8, 8, 8, 1, 8, 2, 2, 1, 8, 3, 3, 1, 3, 2, 2, 1,
0N/A 8, 4, 4, 1, 4, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1,
0N/A 8, 5, 5, 1, 5, 2, 2, 1, 5, 3, 3, 1, 3, 2, 2, 1,
0N/A 5, 4, 4, 1, 4, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1,
0N/A 8, 6, 6, 1, 6, 2, 2, 1, 6, 3, 3, 1, 3, 2, 2, 1,
0N/A 6, 4, 4, 1, 4, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1,
0N/A 6, 5, 5, 1, 5, 2, 2, 1, 5, 3, 3, 1, 3, 2, 2, 1,
0N/A 5, 4, 4, 1, 4, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1,
0N/A 8, 7, 7, 1, 7, 2, 2, 1, 7, 3, 3, 1, 3, 2, 2, 1,
0N/A 7, 4, 4, 1, 4, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1,
0N/A 7, 5, 5, 1, 5, 2, 2, 1, 5, 3, 3, 1, 3, 2, 2, 1,
0N/A 5, 4, 4, 1, 4, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1,
0N/A 7, 6, 6, 1, 6, 2, 2, 1, 6, 3, 3, 1, 3, 2, 2, 1,
0N/A 6, 4, 4, 1, 4, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1,
0N/A 6, 5, 5, 1, 5, 2, 2, 1, 5, 3, 3, 1, 3, 2, 2, 1,
0N/A 5, 4, 4, 1, 4, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1
0N/A};*/
0N/A
0N/A//---------------------------- IndexSet::populate_free_list() -----------------------------
0N/A// Populate the free BitBlock list with a batch of BitBlocks. The BitBlocks
0N/A// are 32 bit aligned.
0N/A
0N/Avoid IndexSet::populate_free_list() {
0N/A Compile *compile = Compile::current();
0N/A BitBlock *free = (BitBlock*)compile->indexSet_free_block_list();
0N/A
0N/A char *mem = (char*)arena()->Amalloc_4(sizeof(BitBlock) *
0N/A bitblock_alloc_chunk_size + 32);
0N/A
0N/A // Align the pointer to a 32 bit boundary.
0N/A BitBlock *new_blocks = (BitBlock*)(((uintptr_t)mem + 32) & ~0x001F);
0N/A
0N/A // Add the new blocks to the free list.
0N/A for (int i = 0; i < bitblock_alloc_chunk_size; i++) {
0N/A new_blocks->set_next(free);
0N/A free = new_blocks;
0N/A new_blocks++;
0N/A }
0N/A
0N/A compile->set_indexSet_free_block_list(free);
0N/A
0N/A#ifdef ASSERT
0N/A if (CollectIndexSetStatistics) {
2122N/A inc_stat_counter(&_alloc_new, bitblock_alloc_chunk_size);
0N/A }
0N/A#endif
0N/A}
0N/A
0N/A
0N/A//---------------------------- IndexSet::alloc_block() ------------------------
0N/A// Allocate a BitBlock from the free list. If the free list is empty,
0N/A// prime it.
0N/A
0N/AIndexSet::BitBlock *IndexSet::alloc_block() {
0N/A#ifdef ASSERT
0N/A if (CollectIndexSetStatistics) {
2122N/A inc_stat_counter(&_alloc_total, 1);
0N/A }
0N/A#endif
0N/A Compile *compile = Compile::current();
0N/A BitBlock* free_list = (BitBlock*)compile->indexSet_free_block_list();
0N/A if (free_list == NULL) {
0N/A populate_free_list();
0N/A free_list = (BitBlock*)compile->indexSet_free_block_list();
0N/A }
0N/A BitBlock *block = free_list;
0N/A compile->set_indexSet_free_block_list(block->next());
0N/A
0N/A block->clear();
0N/A return block;
0N/A}
0N/A
0N/A//---------------------------- IndexSet::alloc_block_containing() -------------
0N/A// Allocate a new BitBlock and put it into the position in the _blocks array
0N/A// corresponding to element.
0N/A
0N/AIndexSet::BitBlock *IndexSet::alloc_block_containing(uint element) {
0N/A BitBlock *block = alloc_block();
0N/A uint bi = get_block_index(element);
0N/A _blocks[bi] = block;
0N/A return block;
0N/A}
0N/A
0N/A//---------------------------- IndexSet::free_block() -------------------------
0N/A// Add a BitBlock to the free list.
0N/A
0N/Avoid IndexSet::free_block(uint i) {
0N/A debug_only(check_watch("free block", i));
0N/A assert(i < _max_blocks, "block index too large");
0N/A BitBlock *block = _blocks[i];
0N/A assert(block != &_empty_block, "cannot free the empty block");
0N/A block->set_next((IndexSet::BitBlock*)Compile::current()->indexSet_free_block_list());
0N/A Compile::current()->set_indexSet_free_block_list(block);
0N/A set_block(i,&_empty_block);
0N/A}
0N/A
0N/A//------------------------------lrg_union--------------------------------------
0N/A// Compute the union of all elements of one and two which interfere with
0N/A// the RegMask mask. If the degree of the union becomes exceeds
0N/A// fail_degree, the union bails out. The underlying set is cleared before
0N/A// the union is performed.
0N/A
0N/Auint IndexSet::lrg_union(uint lr1, uint lr2,
0N/A const uint fail_degree,
0N/A const PhaseIFG *ifg,
0N/A const RegMask &mask ) {
0N/A IndexSet *one = ifg->neighbors(lr1);
0N/A IndexSet *two = ifg->neighbors(lr2);
0N/A LRG &lrg1 = ifg->lrgs(lr1);
0N/A LRG &lrg2 = ifg->lrgs(lr2);
0N/A#ifdef ASSERT
0N/A assert(_max_elements == one->_max_elements, "max element mismatch");
0N/A check_watch("union destination");
0N/A one->check_watch("union source");
0N/A two->check_watch("union source");
0N/A#endif
0N/A
0N/A // Compute the degree of the combined live-range. The combined
0N/A // live-range has the union of the original live-ranges' neighbors set as
0N/A // well as the neighbors of all intermediate copies, minus those neighbors
0N/A // that can not use the intersected allowed-register-set.
0N/A
0N/A // Copy the larger set. Insert the smaller set into the larger.
0N/A if (two->count() > one->count()) {
0N/A IndexSet *temp = one;
0N/A one = two;
0N/A two = temp;
0N/A }
0N/A
0N/A clear();
0N/A
0N/A // Used to compute degree of register-only interferences. Infinite-stack
0N/A // neighbors do not alter colorability, as they can always color to some
0N/A // other color. (A variant of the Briggs assertion)
0N/A uint reg_degree = 0;
0N/A
0N/A uint element;
0N/A // Load up the combined interference set with the neighbors of one
0N/A IndexSetIterator elements(one);
0N/A while ((element = elements.next()) != 0) {
0N/A LRG &lrg = ifg->lrgs(element);
0N/A if (mask.overlap(lrg.mask())) {
0N/A insert(element);
0N/A if( !lrg.mask().is_AllStack() ) {
0N/A reg_degree += lrg1.compute_degree(lrg);
0N/A if( reg_degree >= fail_degree ) return reg_degree;
0N/A } else {
0N/A // !!!!! Danger! No update to reg_degree despite having a neighbor.
0N/A // A variant of the Briggs assertion.
0N/A // Not needed if I simplify during coalesce, ala George/Appel.
0N/A assert( lrg.lo_degree(), "" );
0N/A }
0N/A }
0N/A }
0N/A // Add neighbors of two as well
0N/A IndexSetIterator elements2(two);
0N/A while ((element = elements2.next()) != 0) {
0N/A LRG &lrg = ifg->lrgs(element);
0N/A if (mask.overlap(lrg.mask())) {
0N/A if (insert(element)) {
0N/A if( !lrg.mask().is_AllStack() ) {
0N/A reg_degree += lrg2.compute_degree(lrg);
0N/A if( reg_degree >= fail_degree ) return reg_degree;
0N/A } else {
0N/A // !!!!! Danger! No update to reg_degree despite having a neighbor.
0N/A // A variant of the Briggs assertion.
0N/A // Not needed if I simplify during coalesce, ala George/Appel.
0N/A assert( lrg.lo_degree(), "" );
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A return reg_degree;
0N/A}
0N/A
0N/A//---------------------------- IndexSet() -----------------------------
0N/A// A deep copy constructor. This is used when you need a scratch copy of this set.
0N/A
0N/AIndexSet::IndexSet (IndexSet *set) {
0N/A#ifdef ASSERT
0N/A _serial_number = _serial_count++;
0N/A set->check_watch("copied", _serial_number);
0N/A check_watch("initialized by copy", set->_serial_number);
0N/A _max_elements = set->_max_elements;
0N/A#endif
0N/A _count = set->_count;
0N/A _max_blocks = set->_max_blocks;
0N/A if (_max_blocks <= preallocated_block_list_size) {
0N/A _blocks = _preallocated_block_list;
0N/A } else {
0N/A _blocks =
0N/A (IndexSet::BitBlock**) arena()->Amalloc_4(sizeof(IndexSet::BitBlock**) * _max_blocks);
0N/A }
0N/A for (uint i = 0; i < _max_blocks; i++) {
0N/A BitBlock *block = set->_blocks[i];
0N/A if (block == &_empty_block) {
0N/A set_block(i, &_empty_block);
0N/A } else {
0N/A BitBlock *new_block = alloc_block();
0N/A memcpy(new_block->words(), block->words(), sizeof(uint32) * words_per_block);
0N/A set_block(i, new_block);
0N/A }
0N/A }
0N/A}
0N/A
0N/A//---------------------------- IndexSet::initialize() -----------------------------
0N/A// Prepare an IndexSet for use.
0N/A
0N/Avoid IndexSet::initialize(uint max_elements) {
0N/A#ifdef ASSERT
0N/A _serial_number = _serial_count++;
0N/A check_watch("initialized", max_elements);
0N/A _max_elements = max_elements;
0N/A#endif
0N/A _count = 0;
0N/A _max_blocks = (max_elements + bits_per_block - 1) / bits_per_block;
0N/A
0N/A if (_max_blocks <= preallocated_block_list_size) {
0N/A _blocks = _preallocated_block_list;
0N/A } else {
0N/A _blocks = (IndexSet::BitBlock**) arena()->Amalloc_4(sizeof(IndexSet::BitBlock**) * _max_blocks);
0N/A }
0N/A for (uint i = 0; i < _max_blocks; i++) {
0N/A set_block(i, &_empty_block);
0N/A }
0N/A}
0N/A
0N/A//---------------------------- IndexSet::initialize()------------------------------
0N/A// Prepare an IndexSet for use. If it needs to allocate its _blocks array, it does
0N/A// so from the Arena passed as a parameter. BitBlock allocation is still done from
0N/A// the static Arena which was set with reset_memory().
0N/A
0N/Avoid IndexSet::initialize(uint max_elements, Arena *arena) {
0N/A#ifdef ASSERT
0N/A _serial_number = _serial_count++;
0N/A check_watch("initialized2", max_elements);
0N/A _max_elements = max_elements;
0N/A#endif // ASSERT
0N/A _count = 0;
0N/A _max_blocks = (max_elements + bits_per_block - 1) / bits_per_block;
0N/A
0N/A if (_max_blocks <= preallocated_block_list_size) {
0N/A _blocks = _preallocated_block_list;
0N/A } else {
0N/A _blocks = (IndexSet::BitBlock**) arena->Amalloc_4(sizeof(IndexSet::BitBlock**) * _max_blocks);
0N/A }
0N/A for (uint i = 0; i < _max_blocks; i++) {
0N/A set_block(i, &_empty_block);
0N/A }
0N/A}
0N/A
0N/A//---------------------------- IndexSet::swap() -----------------------------
0N/A// Exchange two IndexSets.
0N/A
0N/Avoid IndexSet::swap(IndexSet *set) {
0N/A#ifdef ASSERT
0N/A assert(_max_elements == set->_max_elements, "must have same universe size to swap");
0N/A check_watch("swap", set->_serial_number);
0N/A set->check_watch("swap", _serial_number);
0N/A#endif
0N/A
0N/A for (uint i = 0; i < _max_blocks; i++) {
0N/A BitBlock *temp = _blocks[i];
0N/A set_block(i, set->_blocks[i]);
0N/A set->set_block(i, temp);
0N/A }
0N/A uint temp = _count;
0N/A _count = set->_count;
0N/A set->_count = temp;
0N/A}
0N/A
0N/A//---------------------------- IndexSet::dump() -----------------------------
0N/A// Print this set. Used for debugging.
0N/A
0N/A#ifndef PRODUCT
0N/Avoid IndexSet::dump() const {
0N/A IndexSetIterator elements(this);
0N/A
0N/A tty->print("{");
0N/A uint i;
0N/A while ((i = elements.next()) != 0) {
0N/A tty->print("L%d ", i);
0N/A }
0N/A tty->print_cr("}");
0N/A}
0N/A#endif
0N/A
0N/A#ifdef ASSERT
0N/A//---------------------------- IndexSet::tally_iteration_statistics() -----------------------------
0N/A// Update block/bit counts to reflect that this set has been iterated over.
0N/A
0N/Avoid IndexSet::tally_iteration_statistics() const {
2122N/A inc_stat_counter(&_total_bits, count());
0N/A
0N/A for (uint i = 0; i < _max_blocks; i++) {
0N/A if (_blocks[i] != &_empty_block) {
2122N/A inc_stat_counter(&_total_used_blocks, 1);
0N/A } else {
2122N/A inc_stat_counter(&_total_unused_blocks, 1);
0N/A }
0N/A }
0N/A}
0N/A
0N/A//---------------------------- IndexSet::print_statistics() -----------------------------
0N/A// Print statistics about IndexSet usage.
0N/A
0N/Avoid IndexSet::print_statistics() {
2122N/A julong total_blocks = _total_used_blocks + _total_unused_blocks;
0N/A tty->print_cr ("Accumulated IndexSet usage statistics:");
0N/A tty->print_cr ("--------------------------------------");
0N/A tty->print_cr (" Iteration:");
2122N/A tty->print_cr (" blocks visited: " UINT64_FORMAT, total_blocks);
2122N/A tty->print_cr (" blocks empty: %4.2f%%", 100.0*(double)_total_unused_blocks/total_blocks);
2122N/A tty->print_cr (" bit density (bits/used blocks): %4.2f", (double)_total_bits/_total_used_blocks);
2122N/A tty->print_cr (" bit density (bits/all blocks): %4.2f", (double)_total_bits/total_blocks);
0N/A tty->print_cr (" Allocation:");
2122N/A tty->print_cr (" blocks allocated: " UINT64_FORMAT, _alloc_new);
2122N/A tty->print_cr (" blocks used/reused: " UINT64_FORMAT, _alloc_total);
0N/A}
0N/A
0N/A//---------------------------- IndexSet::verify() -----------------------------
0N/A// Expensive test of IndexSet sanity. Ensure that the count agrees with the
0N/A// number of bits in the blocks. Make sure the iterator is seeing all elements
0N/A// of the set. Meant for use during development.
0N/A
0N/Avoid IndexSet::verify() const {
0N/A assert(!member(0), "zero cannot be a member");
0N/A uint count = 0;
0N/A uint i;
0N/A for (i = 1; i < _max_elements; i++) {
0N/A if (member(i)) {
0N/A count++;
0N/A assert(count <= _count, "_count is messed up");
0N/A }
0N/A }
0N/A
0N/A IndexSetIterator elements(this);
0N/A count = 0;
0N/A while ((i = elements.next()) != 0) {
0N/A count++;
0N/A assert(member(i), "returned a non member");
0N/A assert(count <= _count, "iterator returned wrong number of elements");
0N/A }
0N/A}
0N/A#endif
0N/A
0N/A//---------------------------- IndexSetIterator() -----------------------------
0N/A// Create an iterator for a set. If empty blocks are detected when iterating
0N/A// over the set, these blocks are replaced.
0N/A
0N/AIndexSetIterator::IndexSetIterator(IndexSet *set) {
0N/A#ifdef ASSERT
0N/A if (CollectIndexSetStatistics) {
0N/A set->tally_iteration_statistics();
0N/A }
0N/A set->check_watch("traversed", set->count());
0N/A#endif
0N/A if (set->is_empty()) {
0N/A _current = 0;
0N/A _next_word = IndexSet::words_per_block;
0N/A _next_block = 1;
0N/A _max_blocks = 1;
0N/A
0N/A // We don't need the following values when we iterate over an empty set.
0N/A // The commented out code is left here to document that the omission
0N/A // is intentional.
0N/A //
0N/A //_value = 0;
0N/A //_words = NULL;
0N/A //_blocks = NULL;
0N/A //_set = NULL;
0N/A } else {
0N/A _current = 0;
0N/A _value = 0;
0N/A _next_block = 0;
0N/A _next_word = IndexSet::words_per_block;
0N/A
0N/A _max_blocks = set->_max_blocks;
0N/A _words = NULL;
0N/A _blocks = set->_blocks;
0N/A _set = set;
0N/A }
0N/A}
0N/A
0N/A//---------------------------- IndexSetIterator(const) -----------------------------
0N/A// Iterate over a constant IndexSet.
0N/A
0N/AIndexSetIterator::IndexSetIterator(const IndexSet *set) {
0N/A#ifdef ASSERT
0N/A if (CollectIndexSetStatistics) {
0N/A set->tally_iteration_statistics();
0N/A }
0N/A // We don't call check_watch from here to avoid bad recursion.
0N/A // set->check_watch("traversed const", set->count());
0N/A#endif
0N/A if (set->is_empty()) {
0N/A _current = 0;
0N/A _next_word = IndexSet::words_per_block;
0N/A _next_block = 1;
0N/A _max_blocks = 1;
0N/A
0N/A // We don't need the following values when we iterate over an empty set.
0N/A // The commented out code is left here to document that the omission
0N/A // is intentional.
0N/A //
0N/A //_value = 0;
0N/A //_words = NULL;
0N/A //_blocks = NULL;
0N/A //_set = NULL;
0N/A } else {
0N/A _current = 0;
0N/A _value = 0;
0N/A _next_block = 0;
0N/A _next_word = IndexSet::words_per_block;
0N/A
0N/A _max_blocks = set->_max_blocks;
0N/A _words = NULL;
0N/A _blocks = set->_blocks;
0N/A _set = NULL;
0N/A }
0N/A}
0N/A
0N/A//---------------------------- List16Iterator::advance_and_next() -----------------------------
0N/A// Advance to the next non-empty word in the set being iterated over. Return the next element
0N/A// if there is one. If we are done, return 0. This method is called from the next() method
0N/A// when it gets done with a word.
0N/A
0N/Auint IndexSetIterator::advance_and_next() {
0N/A // See if there is another non-empty word in the current block.
0N/A for (uint wi = _next_word; wi < (unsigned)IndexSet::words_per_block; wi++) {
0N/A if (_words[wi] != 0) {
0N/A // Found a non-empty word.
0N/A _value = ((_next_block - 1) * IndexSet::bits_per_block) + (wi * IndexSet::bits_per_word);
0N/A _current = _words[wi];
0N/A
0N/A _next_word = wi+1;
0N/A
0N/A return next();
0N/A }
0N/A }
0N/A
0N/A // We ran out of words in the current block. Advance to next non-empty block.
0N/A for (uint bi = _next_block; bi < _max_blocks; bi++) {
0N/A if (_blocks[bi] != &IndexSet::_empty_block) {
0N/A // Found a non-empty block.
0N/A
0N/A _words = _blocks[bi]->words();
0N/A for (uint wi = 0; wi < (unsigned)IndexSet::words_per_block; wi++) {
0N/A if (_words[wi] != 0) {
0N/A // Found a non-empty word.
0N/A _value = (bi * IndexSet::bits_per_block) + (wi * IndexSet::bits_per_word);
0N/A _current = _words[wi];
0N/A
0N/A _next_block = bi+1;
0N/A _next_word = wi+1;
0N/A
0N/A return next();
0N/A }
0N/A }
0N/A
0N/A // All of the words in the block were empty. Replace
0N/A // the block with the empty block.
0N/A if (_set) {
0N/A _set->free_block(bi);
0N/A }
0N/A }
0N/A }
0N/A
0N/A // These assignments make redundant calls to next on a finished iterator
0N/A // faster. Probably not necessary.
0N/A _next_block = _max_blocks;
0N/A _next_word = IndexSet::words_per_block;
0N/A
0N/A // No more words.
0N/A return 0;
0N/A}