src/hotspot/share/opto/indexSet.hpp
author redestad
Thu, 14 Nov 2019 15:24:35 +0100
changeset 59081 95a99e617f28
parent 57632 9c523692db7e
permissions -rw-r--r--
8234003: Improve IndexSet iteration Reviewed-by: neliasso, thartmann
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49373
diff changeset
     2
 * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49373
diff changeset
    25
#ifndef SHARE_OPTO_INDEXSET_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49373
diff changeset
    26
#define SHARE_OPTO_INDEXSET_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "memory/allocation.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "memory/resourceArea.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "opto/compile.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "opto/regmask.hpp"
53961
e5b461681b88 8219922: Simplify and optimize IndexSetIterator::next using count_trailing_zeros
redestad
parents: 53244
diff changeset
    32
#include "utilities/count_trailing_zeros.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// This file defines the IndexSet class, a set of sparse integer indices.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// This data structure is used by the compiler in its liveness analysis and
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// during register allocation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
//-------------------------------- class IndexSet ----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// An IndexSet is a piece-wise bitvector.  At the top level, we have an array
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// of pointers to bitvector chunks called BitBlocks.  Each BitBlock has a fixed
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// size and is allocated from a shared free list.  The bits which are set in
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// each BitBlock correspond to the elements of the set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
class IndexSet : public ResourceObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
 friend class IndexSetIterator;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  // When we allocate an IndexSet, it starts off with an array of top level block
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  // pointers of a set length.  This size is intended to be large enough for the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  // majority of IndexSets.  In the cases when this size is not large enough,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  // a separately allocated array is used.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  // The length of the preallocated top level block array
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  enum { preallocated_block_list_size = 16 };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  // Elements of a IndexSet get decomposed into three fields.  The highest order
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  // bits are the block index, which tell which high level block holds the element.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  // Within that block, the word index indicates which word holds the element.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  // Finally, the bit index determines which single bit within that word indicates
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  // membership of the element in the set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  // The lengths of the index bitfields
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  enum { bit_index_length = 5,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
         word_index_length = 3,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
         block_index_length = 8 // not used
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  // Derived constants used for manipulating the index bitfields
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
         bit_index_offset = 0, // not used
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
         word_index_offset = bit_index_length,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
         block_index_offset = bit_index_length + word_index_length,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
         bits_per_word = 1 << bit_index_length,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
         words_per_block = 1 << word_index_length,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
         bits_per_block = bits_per_word * words_per_block,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
         bit_index_mask = right_n_bits(bit_index_length),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
         word_index_mask = right_n_bits(word_index_length)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  // These routines are used for extracting the block, word, and bit index
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  // from an element.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  static uint get_block_index(uint element) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    return element >> block_index_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  static uint get_word_index(uint element) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    return mask_bits(element >> word_index_offset,word_index_mask);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  static uint get_bit_index(uint element) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    return mask_bits(element,bit_index_mask);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  //------------------------------ class BitBlock ----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  // The BitBlock class is a segment of a bitvector set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  class BitBlock : public ResourceObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
   friend class IndexSetIterator;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
   friend class IndexSet;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
   private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    // All of BitBlocks fields and methods are declared private.  We limit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    // access to IndexSet and IndexSetIterator.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    // A BitBlock is composed of some number of 32 bit words.  When a BitBlock
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    // is not in use by any IndexSet, it is stored on a free list.  The next field
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    // is used by IndexSet to mainting this free list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    union {
24425
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 8320
diff changeset
   110
      uint32_t _words[words_per_block];
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
      BitBlock *_next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    } _data;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    // accessors
24425
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 8320
diff changeset
   115
    uint32_t* words() { return _data._words; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    void set_next(BitBlock *next) { _data._next = next; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    BitBlock *next() { return _data._next; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    // Operations.  A BitBlock supports four simple operations,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    // clear(), member(), insert(), and remove().  These methods do
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    // not assume that the block index has been masked out.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    void clear() {
24425
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 8320
diff changeset
   124
      memset(words(), 0, sizeof(uint32_t) * words_per_block);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    bool member(uint element) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
      uint word_index = IndexSet::get_word_index(element);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
      uint bit_index = IndexSet::get_bit_index(element);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
24425
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 8320
diff changeset
   131
      return ((words()[word_index] & (uint32_t)(0x1 << bit_index)) != 0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    bool insert(uint element) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
      uint word_index = IndexSet::get_word_index(element);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
      uint bit_index = IndexSet::get_bit_index(element);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
24425
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 8320
diff changeset
   138
      uint32_t bit = (0x1 << bit_index);
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 8320
diff changeset
   139
      uint32_t before = words()[word_index];
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
      words()[word_index] = before | bit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
      return ((before & bit) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    bool remove(uint element) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
      uint word_index = IndexSet::get_word_index(element);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
      uint bit_index = IndexSet::get_bit_index(element);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
24425
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 8320
diff changeset
   148
      uint32_t bit = (0x1 << bit_index);
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 8320
diff changeset
   149
      uint32_t before = words()[word_index];
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
      words()[word_index] = before & ~bit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
      return ((before & bit) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  //-------------------------- BitBlock allocation ---------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  // All IndexSets share an arena from which they allocate BitBlocks.  Unused
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  // BitBlocks are placed on a free list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  // The number of BitBlocks to allocate at a time
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  enum { bitblock_alloc_chunk_size = 50 };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  static Arena *arena() { return Compile::current()->indexSet_arena(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  static void populate_free_list();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  // Invalidate the current free BitBlock list and begin allocation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  // from a new arena.  It is essential that this method is called whenever
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  // the Arena being used for BitBlock allocation is reset.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  static void reset_memory(Compile* compile, Arena *arena) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    compile->set_indexSet_free_block_list(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    compile->set_indexSet_arena(arena);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
   // This should probably be done in a static initializer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
   _empty_block.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  friend class BitBlock;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  // A distinguished BitBlock which always remains empty.  When a new IndexSet is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  // created, all of its top level BitBlock pointers are initialized to point to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  // this.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  static BitBlock _empty_block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  //-------------------------- Members ------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  // The number of elements in the set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  uint      _count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
59081
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   193
  // The current upper limit of blocks that has been allocated and might be in use
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   194
  uint      _current_block_limit;
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   195
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  // Our top level array of bitvector segments
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  BitBlock **_blocks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  BitBlock  *_preallocated_block_list[preallocated_block_list_size];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  // The number of top level array entries in use
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  uint       _max_blocks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  // Our assertions need to know the maximum number allowed in the set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  uint       _max_elements;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  // The next IndexSet on the free list (not used at same time as count)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  IndexSet *_next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  //-------------------------- Free list operations ------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  // Individual IndexSets can be placed on a free list.  This is done in PhaseLive.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  IndexSet *next() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    return _next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  void set_next(IndexSet *next) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    _next = next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  //-------------------------- Utility methods -----------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  // Get the block which holds element
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  BitBlock *get_block_containing(uint element) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    assert(element < _max_elements, "element out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
    return _blocks[get_block_index(element)];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  // Set a block in the top level array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  void set_block(uint index, BitBlock *block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    _blocks[index] = block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  // Get a BitBlock from the free list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  BitBlock *alloc_block();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  // Get a BitBlock from the free list and place it in the top level array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  BitBlock *alloc_block_containing(uint element);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  // Free a block from the top level array, placing it on the free BitBlock list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  void free_block(uint i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  //-------------------------- Primitive set operations --------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  void clear() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    _count = 0;
59081
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   252
    for (uint i = 0; i < _current_block_limit; i++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
      BitBlock *block = _blocks[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
      if (block != &_empty_block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
        free_block(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    }
59081
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   258
    _current_block_limit = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  uint count() const { return _count; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  bool is_empty() const { return _count == 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  bool member(uint element) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    return get_block_containing(element)->member(element);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  bool insert(uint element) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    if (element == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
      return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    BitBlock *block = get_block_containing(element);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    if (block == &_empty_block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
      block = alloc_block_containing(element);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
    bool present = block->insert(element);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
    if (!present) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
      _count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
    return !present;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  bool remove(uint element) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    BitBlock *block = get_block_containing(element);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    bool present = block->remove(element);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    if (present) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
      _count--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    return present;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  //-------------------------- Compound set operations ------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  // Compute the union of all elements of one and two which interfere
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  // with the RegMask mask.  If the degree of the union becomes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  // exceeds fail_degree, the union bails out.  The underlying set is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  // cleared before the union is performed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  uint lrg_union(uint lr1, uint lr2,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
                 const uint fail_degree,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
                 const class PhaseIFG *ifg,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
                 const RegMask &mask);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  //------------------------- Construction, initialization -----------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  IndexSet() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  // This constructor is used for making a deep copy of a IndexSet.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  IndexSet(IndexSet *set);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  // Perform initialization on a IndexSet
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  void initialize(uint max_element);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  // Initialize a IndexSet.  If the top level BitBlock array needs to be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  // allocated, do it from the proffered arena.  BitBlocks are still allocated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  // from the static Arena member.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  void initialize(uint max_element, Arena *arena);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  // Exchange two sets
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  void swap(IndexSet *set);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  //-------------------------- Debugging and statistics --------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  // Output a IndexSet for debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  void dump() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  void tally_iteration_statistics() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  // BitBlock allocation statistics
8320
544210b4dd48 7017124: Fix some VM stats to avoid 32-bit overflow
kvn
parents: 7397
diff changeset
   333
  static julong _alloc_new;
544210b4dd48 7017124: Fix some VM stats to avoid 32-bit overflow
kvn
parents: 7397
diff changeset
   334
  static julong _alloc_total;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  // Block density statistics
8320
544210b4dd48 7017124: Fix some VM stats to avoid 32-bit overflow
kvn
parents: 7397
diff changeset
   337
  static julong _total_bits;
544210b4dd48 7017124: Fix some VM stats to avoid 32-bit overflow
kvn
parents: 7397
diff changeset
   338
  static julong _total_used_blocks;
544210b4dd48 7017124: Fix some VM stats to avoid 32-bit overflow
kvn
parents: 7397
diff changeset
   339
  static julong _total_unused_blocks;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  // Sanity tests
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  void verify() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  static int _serial_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  int        _serial_number;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  // Check to see if the serial number of the current set is the one we're tracing.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  // If it is, print a message.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  void check_watch(const char *operation, uint operand) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
    if (IndexSetWatch != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
      if (IndexSetWatch == -1 || _serial_number == IndexSetWatch) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
        tty->print_cr("IndexSet %d : %s ( %d )", _serial_number, operation, operand);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  void check_watch(const char *operation) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
    if (IndexSetWatch != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
      if (IndexSetWatch == -1 || _serial_number == IndexSetWatch) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
        tty->print_cr("IndexSet %d : %s", _serial_number, operation);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
  static void print_statistics();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
//-------------------------------- class IndexSetIterator --------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
// An iterator for IndexSets.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
49373
47b5652f2928 8199283: Remove ValueObj class for allocation subclassing for compiler code
coleenp
parents: 47216
diff changeset
   374
class IndexSetIterator {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
 friend class IndexSet;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  // The current word we are inspecting
24425
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 8320
diff changeset
   379
  uint32_t              _current;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
  // What element number are we currently on?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  uint                  _value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  // The index of the next word we will inspect
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  uint                  _next_word;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  // The index of the next block we will inspect
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  uint                  _next_block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
59081
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   390
  // The number of blocks in the set
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   391
  uint                  _max_blocks;
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   392
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   393
  // A pointer to the contents of the current block
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   394
  uint32_t             *_words;
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   395
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
  // A pointer to the blocks in our set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  IndexSet::BitBlock **_blocks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  // If the iterator was created from a non-const set, we replace
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  // non-canonical empty blocks with the _empty_block pointer.  If
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  // _set is NULL, we do no replacement.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  IndexSet            *_set;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  // Advance to the next non-empty word and return the next
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  // element in the set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  uint advance_and_next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  // If an iterator is built from a constant set then empty blocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
  // are not canonicalized.
59081
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   412
  IndexSetIterator(IndexSet *set) :
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   413
    _current(0),
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   414
    _value(0),
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   415
    _next_word(IndexSet::words_per_block),
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   416
    _next_block(0),
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   417
    _max_blocks(set->is_empty() ? 0 : set->_current_block_limit),
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   418
    _words(NULL),
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   419
    _blocks(set->_blocks),
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   420
    _set(set) {
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   421
  #ifdef ASSERT
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   422
    if (CollectIndexSetStatistics) {
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   423
      set->tally_iteration_statistics();
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   424
    }
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   425
    set->check_watch("traversed", set->count());
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   426
  #endif
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   427
  }
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   428
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   429
  IndexSetIterator(const IndexSet *set) :
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   430
    _current(0),
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   431
    _value(0),
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   432
    _next_word(IndexSet::words_per_block),
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   433
    _next_block(0),
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   434
    _max_blocks(set->is_empty() ? 0 : set->_current_block_limit),
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   435
    _words(NULL),
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   436
    _blocks(set->_blocks),
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   437
    _set(NULL)
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   438
  {
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   439
  #ifdef ASSERT
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   440
    if (CollectIndexSetStatistics) {
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   441
      set->tally_iteration_statistics();
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   442
    }
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   443
    // We don't call check_watch from here to avoid bad recursion.
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   444
    //   set->check_watch("traversed const", set->count());
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   445
  #endif
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   446
  }
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   447
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   448
  // Return the next element of the set.
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   449
  uint next_value() {
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   450
    uint current = _current;
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   451
    assert(current != 0, "sanity");
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   452
    uint advance = count_trailing_zeros(current);
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   453
    assert(((current >> advance) & 0x1) == 1, "sanity");
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   454
    _current = (current >> advance) - 1;
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   455
    _value += advance;
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   456
    return _value;
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   457
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
  // Return the next element of the set.  Return 0 when done.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
  uint next() {
59081
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   461
    if (_current != 0) {
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   462
      return next_value();
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   463
    } else if (_next_word < IndexSet::words_per_block || _next_block < _max_blocks) {
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   464
      return advance_and_next();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
    } else {
59081
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   466
      return 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
  }
59081
95a99e617f28 8234003: Improve IndexSet iteration
redestad
parents: 57632
diff changeset
   469
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   471
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49373
diff changeset
   472
#endif // SHARE_OPTO_INDEXSET_HPP