hotspot/src/share/vm/opto/indexSet.cpp
author stefank
Tue, 23 Nov 2010 13:22:55 -0800
changeset 7397 5b173b4ca846
parent 5547 f4b087cbb361
child 8320 544210b4dd48
permissions -rw-r--r--
6989984: Use standard include model for Hospot Summary: Replaced MakeDeps and the includeDB files with more standardized solutions. Reviewed-by: coleenp, kvn, kamg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
     2
 * Copyright (c) 1998, 2010, 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
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "memory/allocation.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "opto/chaitin.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "opto/compile.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "opto/indexSet.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "opto/regmask.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// This file defines the IndexSet class, a set of sparse integer indices.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// This data structure is used by the compiler in its liveness analysis and
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// during register allocation.  It also defines an iterator for this class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
//-------------------------------- Initializations ------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
IndexSet::BitBlock  IndexSet::_empty_block     = IndexSet::BitBlock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// Initialize statistics counters
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
uint IndexSet::_alloc_new = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
uint IndexSet::_alloc_total = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
long IndexSet::_total_bits = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
long IndexSet::_total_used_blocks = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
long IndexSet::_total_unused_blocks = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
// Per set, or all sets operation tracing
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
int IndexSet::_serial_count = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
// What is the first set bit in a 5 bit integer?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
const byte IndexSetIterator::_first_bit[32] = {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  0, 0, 1, 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  2, 0, 1, 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  3, 0, 1, 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  2, 0, 1, 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  4, 0, 1, 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  2, 0, 1, 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  3, 0, 1, 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  2, 0, 1, 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
// What is the second set bit in a 5 bit integer?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
const byte IndexSetIterator::_second_bit[32] = {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  5, 5, 5, 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  5, 2, 2, 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  5, 3, 3, 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  3, 2, 2, 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  5, 4, 4, 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  4, 2, 2, 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  4, 3, 3, 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  3, 2, 2, 1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
// I tried implementing the IndexSetIterator with a window_size of 8 and
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
// didn't seem to get a noticeable speedup.  I am leaving in the tables
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
// in case we want to switch back.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
/*const byte IndexSetIterator::_first_bit[256] = {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  8, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
const byte IndexSetIterator::_second_bit[256] = {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  8, 8, 8, 1, 8, 2, 2, 1, 8, 3, 3, 1, 3, 2, 2, 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  8, 4, 4, 1, 4, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  8, 5, 5, 1, 5, 2, 2, 1, 5, 3, 3, 1, 3, 2, 2, 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  5, 4, 4, 1, 4, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  8, 6, 6, 1, 6, 2, 2, 1, 6, 3, 3, 1, 3, 2, 2, 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  6, 4, 4, 1, 4, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  6, 5, 5, 1, 5, 2, 2, 1, 5, 3, 3, 1, 3, 2, 2, 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  5, 4, 4, 1, 4, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  8, 7, 7, 1, 7, 2, 2, 1, 7, 3, 3, 1, 3, 2, 2, 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  7, 4, 4, 1, 4, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  7, 5, 5, 1, 5, 2, 2, 1, 5, 3, 3, 1, 3, 2, 2, 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  5, 4, 4, 1, 4, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  7, 6, 6, 1, 6, 2, 2, 1, 6, 3, 3, 1, 3, 2, 2, 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  6, 4, 4, 1, 4, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  6, 5, 5, 1, 5, 2, 2, 1, 5, 3, 3, 1, 3, 2, 2, 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  5, 4, 4, 1, 4, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
};*/
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
//---------------------------- IndexSet::populate_free_list() -----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
// Populate the free BitBlock list with a batch of BitBlocks.  The BitBlocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
// are 32 bit aligned.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
void IndexSet::populate_free_list() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  Compile *compile = Compile::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  BitBlock *free = (BitBlock*)compile->indexSet_free_block_list();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  char *mem = (char*)arena()->Amalloc_4(sizeof(BitBlock) *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
                                        bitblock_alloc_chunk_size + 32);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  // Align the pointer to a 32 bit boundary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  BitBlock *new_blocks = (BitBlock*)(((uintptr_t)mem + 32) & ~0x001F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  // Add the new blocks to the free list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  for (int i = 0; i < bitblock_alloc_chunk_size; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    new_blocks->set_next(free);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    free = new_blocks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    new_blocks++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  compile->set_indexSet_free_block_list(free);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  if (CollectIndexSetStatistics) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    _alloc_new += bitblock_alloc_chunk_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
//---------------------------- IndexSet::alloc_block() ------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
// Allocate a BitBlock from the free list.  If the free list is empty,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
// prime it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
IndexSet::BitBlock *IndexSet::alloc_block() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  if (CollectIndexSetStatistics) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    _alloc_total++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  Compile *compile = Compile::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  BitBlock* free_list = (BitBlock*)compile->indexSet_free_block_list();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  if (free_list == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    populate_free_list();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    free_list = (BitBlock*)compile->indexSet_free_block_list();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  BitBlock *block = free_list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  compile->set_indexSet_free_block_list(block->next());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  block->clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  return block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
//---------------------------- IndexSet::alloc_block_containing() -------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
// Allocate a new BitBlock and put it into the position in the _blocks array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
// corresponding to element.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
IndexSet::BitBlock *IndexSet::alloc_block_containing(uint element) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  BitBlock *block = alloc_block();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  uint bi = get_block_index(element);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  _blocks[bi] = block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  return block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
//---------------------------- IndexSet::free_block() -------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
// Add a BitBlock to the free list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
void IndexSet::free_block(uint i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  debug_only(check_watch("free block", i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  assert(i < _max_blocks, "block index too large");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  BitBlock *block = _blocks[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  assert(block != &_empty_block, "cannot free the empty block");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  block->set_next((IndexSet::BitBlock*)Compile::current()->indexSet_free_block_list());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  Compile::current()->set_indexSet_free_block_list(block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  set_block(i,&_empty_block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
//------------------------------lrg_union--------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
// Compute the union of all elements of one and two which interfere with
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
// the RegMask mask.  If the degree of the union becomes exceeds
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
// fail_degree, the union bails out.  The underlying set is cleared before
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
// the union is performed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
uint IndexSet::lrg_union(uint lr1, uint lr2,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
                         const uint fail_degree,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
                         const PhaseIFG *ifg,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
                         const RegMask &mask ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  IndexSet *one = ifg->neighbors(lr1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  IndexSet *two = ifg->neighbors(lr2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  LRG &lrg1 = ifg->lrgs(lr1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  LRG &lrg2 = ifg->lrgs(lr2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  assert(_max_elements == one->_max_elements, "max element mismatch");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  check_watch("union destination");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  one->check_watch("union source");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  two->check_watch("union source");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  // Compute the degree of the combined live-range.  The combined
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  // live-range has the union of the original live-ranges' neighbors set as
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  // well as the neighbors of all intermediate copies, minus those neighbors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  // that can not use the intersected allowed-register-set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  // Copy the larger set.  Insert the smaller set into the larger.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  if (two->count() > one->count()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
    IndexSet *temp = one;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    one = two;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    two = temp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  // Used to compute degree of register-only interferences.  Infinite-stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  // neighbors do not alter colorability, as they can always color to some
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  // other color.  (A variant of the Briggs assertion)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  uint reg_degree = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  uint element;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  // Load up the combined interference set with the neighbors of one
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  IndexSetIterator elements(one);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  while ((element = elements.next()) != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    LRG &lrg = ifg->lrgs(element);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    if (mask.overlap(lrg.mask())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
      insert(element);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
      if( !lrg.mask().is_AllStack() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
        reg_degree += lrg1.compute_degree(lrg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
        if( reg_degree >= fail_degree ) return reg_degree;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
        // !!!!! Danger!  No update to reg_degree despite having a neighbor.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
        // A variant of the Briggs assertion.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
        // Not needed if I simplify during coalesce, ala George/Appel.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
        assert( lrg.lo_degree(), "" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  // Add neighbors of two as well
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  IndexSetIterator elements2(two);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  while ((element = elements2.next()) != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
    LRG &lrg = ifg->lrgs(element);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
    if (mask.overlap(lrg.mask())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
      if (insert(element)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
        if( !lrg.mask().is_AllStack() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
          reg_degree += lrg2.compute_degree(lrg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
          if( reg_degree >= fail_degree ) return reg_degree;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
          // !!!!! Danger!  No update to reg_degree despite having a neighbor.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
          // A variant of the Briggs assertion.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
          // Not needed if I simplify during coalesce, ala George/Appel.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
          assert( lrg.lo_degree(), "" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  return reg_degree;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
//---------------------------- IndexSet() -----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
// A deep copy constructor.  This is used when you need a scratch copy of this set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
IndexSet::IndexSet (IndexSet *set) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  _serial_number = _serial_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  set->check_watch("copied", _serial_number);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  check_watch("initialized by copy", set->_serial_number);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  _max_elements = set->_max_elements;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  _count = set->_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  _max_blocks = set->_max_blocks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  if (_max_blocks <= preallocated_block_list_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    _blocks = _preallocated_block_list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
    _blocks =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
      (IndexSet::BitBlock**) arena()->Amalloc_4(sizeof(IndexSet::BitBlock**) * _max_blocks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  for (uint i = 0; i < _max_blocks; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
    BitBlock *block = set->_blocks[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    if (block == &_empty_block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
      set_block(i, &_empty_block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
      BitBlock *new_block = alloc_block();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
      memcpy(new_block->words(), block->words(), sizeof(uint32) * words_per_block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
      set_block(i, new_block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
//---------------------------- IndexSet::initialize() -----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
// Prepare an IndexSet for use.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
void IndexSet::initialize(uint max_elements) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  _serial_number = _serial_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  check_watch("initialized", max_elements);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  _max_elements = max_elements;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  _count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  _max_blocks = (max_elements + bits_per_block - 1) / bits_per_block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  if (_max_blocks <= preallocated_block_list_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
    _blocks = _preallocated_block_list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
    _blocks = (IndexSet::BitBlock**) arena()->Amalloc_4(sizeof(IndexSet::BitBlock**) * _max_blocks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  for (uint i = 0; i < _max_blocks; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
    set_block(i, &_empty_block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
//---------------------------- IndexSet::initialize()------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
// Prepare an IndexSet for use.  If it needs to allocate its _blocks array, it does
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
// so from the Arena passed as a parameter.  BitBlock allocation is still done from
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
// the static Arena which was set with reset_memory().
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
void IndexSet::initialize(uint max_elements, Arena *arena) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  _serial_number = _serial_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  check_watch("initialized2", max_elements);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  _max_elements = max_elements;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
#endif // ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  _count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  _max_blocks = (max_elements + bits_per_block - 1) / bits_per_block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  if (_max_blocks <= preallocated_block_list_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
    _blocks = _preallocated_block_list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
    _blocks = (IndexSet::BitBlock**) arena->Amalloc_4(sizeof(IndexSet::BitBlock**) * _max_blocks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  for (uint i = 0; i < _max_blocks; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
    set_block(i, &_empty_block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
//---------------------------- IndexSet::swap() -----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
// Exchange two IndexSets.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
void IndexSet::swap(IndexSet *set) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  assert(_max_elements == set->_max_elements, "must have same universe size to swap");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  check_watch("swap", set->_serial_number);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  set->check_watch("swap", _serial_number);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  for (uint i = 0; i < _max_blocks; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
    BitBlock *temp = _blocks[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
    set_block(i, set->_blocks[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
    set->set_block(i, temp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
  uint temp = _count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
  _count = set->_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  set->_count = temp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
//---------------------------- IndexSet::dump() -----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
// Print this set.  Used for debugging.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
void IndexSet::dump() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  IndexSetIterator elements(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  tty->print("{");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
  uint i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  while ((i = elements.next()) != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
    tty->print("L%d ", i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  tty->print_cr("}");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
//---------------------------- IndexSet::tally_iteration_statistics() -----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
// Update block/bit counts to reflect that this set has been iterated over.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
void IndexSet::tally_iteration_statistics() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
  _total_bits += count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
  for (uint i = 0; i < _max_blocks; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
    if (_blocks[i] != &_empty_block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
      _total_used_blocks++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
      _total_unused_blocks++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
//---------------------------- IndexSet::print_statistics() -----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
// Print statistics about IndexSet usage.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
void IndexSet::print_statistics() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  long total_blocks = _total_used_blocks + _total_unused_blocks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  tty->print_cr ("Accumulated IndexSet usage statistics:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
  tty->print_cr ("--------------------------------------");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  tty->print_cr ("  Iteration:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  tty->print_cr ("    blocks visited: %d", total_blocks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  tty->print_cr ("    blocks empty: %4.2f%%", 100.0*_total_unused_blocks/total_blocks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
  tty->print_cr ("    bit density (bits/used blocks): %4.2f%%", (double)_total_bits/_total_used_blocks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  tty->print_cr ("    bit density (bits/all blocks): %4.2f%%", (double)_total_bits/total_blocks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  tty->print_cr ("  Allocation:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  tty->print_cr ("    blocks allocated: %d", _alloc_new);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
  tty->print_cr ("    blocks used/reused: %d", _alloc_total);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
//---------------------------- IndexSet::verify() -----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
// Expensive test of IndexSet sanity.  Ensure that the count agrees with the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
// number of bits in the blocks.  Make sure the iterator is seeing all elements
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
// of the set.  Meant for use during development.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
void IndexSet::verify() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
  assert(!member(0), "zero cannot be a member");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
  uint count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  uint i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
  for (i = 1; i < _max_elements; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
    if (member(i)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
      count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
      assert(count <= _count, "_count is messed up");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  IndexSetIterator elements(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
  count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  while ((i = elements.next()) != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
    count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
    assert(member(i), "returned a non member");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
    assert(count <= _count, "iterator returned wrong number of elements");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
//---------------------------- IndexSetIterator() -----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
// Create an iterator for a set.  If empty blocks are detected when iterating
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
// over the set, these blocks are replaced.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
IndexSetIterator::IndexSetIterator(IndexSet *set) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
  if (CollectIndexSetStatistics) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
    set->tally_iteration_statistics();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
  set->check_watch("traversed", set->count());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
  if (set->is_empty()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
    _current = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
    _next_word = IndexSet::words_per_block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
    _next_block = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
    _max_blocks = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
    // We don't need the following values when we iterate over an empty set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
    // The commented out code is left here to document that the omission
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
    // is intentional.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
    //_value = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
    //_words = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
    //_blocks = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
    //_set = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
    _current = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
    _value = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
    _next_block = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
    _next_word = IndexSet::words_per_block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
    _max_blocks = set->_max_blocks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
    _words = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
    _blocks = set->_blocks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
    _set = set;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
//---------------------------- IndexSetIterator(const) -----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
// Iterate over a constant IndexSet.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
IndexSetIterator::IndexSetIterator(const IndexSet *set) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
  if (CollectIndexSetStatistics) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
    set->tally_iteration_statistics();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
  // We don't call check_watch from here to avoid bad recursion.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
  //   set->check_watch("traversed const", set->count());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  if (set->is_empty()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
    _current = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
    _next_word = IndexSet::words_per_block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
    _next_block = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
    _max_blocks = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
    // We don't need the following values when we iterate over an empty set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
    // The commented out code is left here to document that the omission
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
    // is intentional.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
    //_value = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
    //_words = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
    //_blocks = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
    //_set = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
    _current = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
    _value = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
    _next_block = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
    _next_word = IndexSet::words_per_block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
    _max_blocks = set->_max_blocks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
    _words = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
    _blocks = set->_blocks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
    _set = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
//---------------------------- List16Iterator::advance_and_next() -----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
// Advance to the next non-empty word in the set being iterated over.  Return the next element
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
// if there is one.  If we are done, return 0.  This method is called from the next() method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
// when it gets done with a word.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
uint IndexSetIterator::advance_and_next() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
  // See if there is another non-empty word in the current block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
  for (uint wi = _next_word; wi < (unsigned)IndexSet::words_per_block; wi++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
    if (_words[wi] != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
      // Found a non-empty word.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
      _value = ((_next_block - 1) * IndexSet::bits_per_block) + (wi * IndexSet::bits_per_word);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
      _current = _words[wi];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
      _next_word = wi+1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
      return next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
  // We ran out of words in the current block.  Advance to next non-empty block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
  for (uint bi = _next_block; bi < _max_blocks; bi++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
    if (_blocks[bi] != &IndexSet::_empty_block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
      // Found a non-empty block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
      _words = _blocks[bi]->words();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
      for (uint wi = 0; wi < (unsigned)IndexSet::words_per_block; wi++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
        if (_words[wi] != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
          // Found a non-empty word.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
          _value = (bi * IndexSet::bits_per_block) + (wi * IndexSet::bits_per_word);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
          _current = _words[wi];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
          _next_block = bi+1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
          _next_word = wi+1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
          return next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
      // All of the words in the block were empty.  Replace
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
      // the block with the empty block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
      if (_set) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
        _set->free_block(bi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
  // These assignments make redundant calls to next on a finished iterator
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
  // faster.  Probably not necessary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
  _next_block = _max_blocks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
  _next_word = IndexSet::words_per_block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
  // No more words.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
  return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
}