annotate src/share/vm/utilities/bitMap.hpp @ 2177:3582bf76420e

6990754: Use native memory and reference counting to implement SymbolTable Summary: move symbols from permgen into C heap and reference count them Reviewed-by: never, acorn, jmasa, stefank
author coleenp
date Thu, 27 Jan 2011 16:11:27 -0800
parents f95d63e2154a
children 842b840e67db
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 844
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 844
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 844
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #ifndef SHARE_VM_UTILITIES_BITMAP_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #define SHARE_VM_UTILITIES_BITMAP_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "memory/allocation.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "utilities/top.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
31 // Forward decl;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
32 class BitMapClosure;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
33
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
34 // Operations for bitmaps represented as arrays of unsigned integers.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
35 // Bit offsets are numbered from 0 to size-1.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 class BitMap VALUE_OBJ_CLASS_SPEC {
a61af66fc99e Initial load
duke
parents:
diff changeset
38 friend class BitMap2D;
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
41 typedef size_t idx_t; // Type used for bit and word indices.
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
42 typedef uintptr_t bm_word_t; // Element type of array that represents
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
43 // the bitmap.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // Hints for range sizes.
a61af66fc99e Initial load
duke
parents:
diff changeset
46 typedef enum {
a61af66fc99e Initial load
duke
parents:
diff changeset
47 unknown_range, small_range, large_range
a61af66fc99e Initial load
duke
parents:
diff changeset
48 } RangeSizeHint;
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 private:
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
51 bm_word_t* _map; // First word in bitmap
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
52 idx_t _size; // Size of bitmap (in bits)
0
a61af66fc99e Initial load
duke
parents:
diff changeset
53
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // Puts the given value at the given offset, using resize() to size
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // the bitmap appropriately if needed using factor-of-two expansion.
a61af66fc99e Initial load
duke
parents:
diff changeset
56 void at_put_grow(idx_t index, bool value);
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // Return the position of bit within the word that contains it (e.g., if
a61af66fc99e Initial load
duke
parents:
diff changeset
60 // bitmap words are 32 bits, return a number 0 <= n <= 31).
a61af66fc99e Initial load
duke
parents:
diff changeset
61 static idx_t bit_in_word(idx_t bit) { return bit & (BitsPerWord - 1); }
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // Return a mask that will select the specified bit, when applied to the word
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // containing the bit.
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
65 static bm_word_t bit_mask(idx_t bit) { return (bm_word_t)1 << bit_in_word(bit); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 // Return the index of the word containing the specified bit.
a61af66fc99e Initial load
duke
parents:
diff changeset
68 static idx_t word_index(idx_t bit) { return bit >> LogBitsPerWord; }
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70 // Return the bit number of the first bit in the specified word.
a61af66fc99e Initial load
duke
parents:
diff changeset
71 static idx_t bit_index(idx_t word) { return word << LogBitsPerWord; }
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73 // Return the array of bitmap words, or a specific word from it.
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
74 bm_word_t* map() const { return _map; }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
75 bm_word_t map(idx_t word) const { return _map[word]; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // Return a pointer to the word containing the specified bit.
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
78 bm_word_t* word_addr(idx_t bit) const { return map() + word_index(bit); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // Set a word to a specified value or to all ones; clear a word.
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
81 void set_word (idx_t word, bm_word_t val) { _map[word] = val; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
82 void set_word (idx_t word) { set_word(word, ~(uintptr_t)0); }
a61af66fc99e Initial load
duke
parents:
diff changeset
83 void clear_word(idx_t word) { _map[word] = 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // Utilities for ranges of bits. Ranges are half-open [beg, end).
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // Ranges within a single word.
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
88 bm_word_t inverted_bit_mask_for_range(idx_t beg, idx_t end) const;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
89 void set_range_within_word (idx_t beg, idx_t end);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
90 void clear_range_within_word (idx_t beg, idx_t end);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
91 void par_put_range_within_word (idx_t beg, idx_t end, bool value);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // Ranges spanning entire words.
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
94 void set_range_of_words (idx_t beg, idx_t end);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
95 void clear_range_of_words (idx_t beg, idx_t end);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
96 void set_large_range_of_words (idx_t beg, idx_t end);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
97 void clear_large_range_of_words (idx_t beg, idx_t end);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 // The index of the first full word in a range.
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
100 idx_t word_index_round_up(idx_t bit) const;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
101
809
6e2afda171db 6849716: BitMap - performance regression introduced with G1
jcoomes
parents: 342
diff changeset
102 // Verification.
6e2afda171db 6849716: BitMap - performance regression introduced with G1
jcoomes
parents: 342
diff changeset
103 inline void verify_index(idx_t index) const NOT_DEBUG_RETURN;
6e2afda171db 6849716: BitMap - performance regression introduced with G1
jcoomes
parents: 342
diff changeset
104 inline void verify_range(idx_t beg_index, idx_t end_index) const
6e2afda171db 6849716: BitMap - performance regression introduced with G1
jcoomes
parents: 342
diff changeset
105 NOT_DEBUG_RETURN;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
106
809
6e2afda171db 6849716: BitMap - performance regression introduced with G1
jcoomes
parents: 342
diff changeset
107 // Statistics.
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
108 static idx_t* _pop_count_table;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
109 static void init_pop_count_table();
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
110 static idx_t num_set_bits(bm_word_t w);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
111 static idx_t num_set_bits_from_table(unsigned char c);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 // Constructs a bitmap with no map, and size 0.
a61af66fc99e Initial load
duke
parents:
diff changeset
116 BitMap() : _map(NULL), _size(0) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
117
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
118 // Constructs a bitmap with the given map and size.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
119 BitMap(bm_word_t* map, idx_t size_in_bits);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
120
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
121 // Constructs an empty bitmap of the given size (that is, this clears the
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
122 // new bitmap). Allocates the map array in resource area if
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
123 // "in_resource_area" is true, else in the C heap.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
124 BitMap(idx_t size_in_bits, bool in_resource_area = true);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
125
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
126 // Set the map and size.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
127 void set_map(bm_word_t* map) { _map = map; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
128 void set_size(idx_t size_in_bits) { _size = size_in_bits; }
a61af66fc99e Initial load
duke
parents:
diff changeset
129
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
130 // Allocates necessary data structure, either in the resource area
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
131 // or in the C heap, as indicated by "in_resource_area."
0
a61af66fc99e Initial load
duke
parents:
diff changeset
132 // Preserves state currently in bit map by copying data.
a61af66fc99e Initial load
duke
parents:
diff changeset
133 // Zeros any newly-addressable bits.
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
134 // If "in_resource_area" is false, frees the current map.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
135 // (Note that this assumes that all calls to "resize" on the same BitMap
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
136 // use the same value for "in_resource_area".)
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
137 void resize(idx_t size_in_bits, bool in_resource_area = true);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 // Accessing
a61af66fc99e Initial load
duke
parents:
diff changeset
140 idx_t size() const { return _size; }
a61af66fc99e Initial load
duke
parents:
diff changeset
141 idx_t size_in_words() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
142 return word_index(size() + BitsPerWord - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145 bool at(idx_t index) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 verify_index(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
147 return (*word_addr(index) & bit_mask(index)) != 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 // Align bit index up or down to the next bitmap word boundary, or check
a61af66fc99e Initial load
duke
parents:
diff changeset
151 // alignment.
a61af66fc99e Initial load
duke
parents:
diff changeset
152 static idx_t word_align_up(idx_t bit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
153 return align_size_up(bit, BitsPerWord);
a61af66fc99e Initial load
duke
parents:
diff changeset
154 }
a61af66fc99e Initial load
duke
parents:
diff changeset
155 static idx_t word_align_down(idx_t bit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
156 return align_size_down(bit, BitsPerWord);
a61af66fc99e Initial load
duke
parents:
diff changeset
157 }
a61af66fc99e Initial load
duke
parents:
diff changeset
158 static bool is_word_aligned(idx_t bit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
159 return word_align_up(bit) == bit;
a61af66fc99e Initial load
duke
parents:
diff changeset
160 }
a61af66fc99e Initial load
duke
parents:
diff changeset
161
a61af66fc99e Initial load
duke
parents:
diff changeset
162 // Set or clear the specified bit.
a61af66fc99e Initial load
duke
parents:
diff changeset
163 inline void set_bit(idx_t bit);
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
164 void clear_bit(idx_t bit);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166 // Atomically set or clear the specified bit.
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
167 bool par_set_bit(idx_t bit);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
168 bool par_clear_bit(idx_t bit);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
169
a61af66fc99e Initial load
duke
parents:
diff changeset
170 // Put the given value at the given offset. The parallel version
a61af66fc99e Initial load
duke
parents:
diff changeset
171 // will CAS the value into the bitmap and is quite a bit slower.
a61af66fc99e Initial load
duke
parents:
diff changeset
172 // The parallel version also returns a value indicating if the
a61af66fc99e Initial load
duke
parents:
diff changeset
173 // calling thread was the one that changed the value of the bit.
a61af66fc99e Initial load
duke
parents:
diff changeset
174 void at_put(idx_t index, bool value);
a61af66fc99e Initial load
duke
parents:
diff changeset
175 bool par_at_put(idx_t index, bool value);
a61af66fc99e Initial load
duke
parents:
diff changeset
176
a61af66fc99e Initial load
duke
parents:
diff changeset
177 // Update a range of bits. Ranges are half-open [beg, end).
a61af66fc99e Initial load
duke
parents:
diff changeset
178 void set_range (idx_t beg, idx_t end);
a61af66fc99e Initial load
duke
parents:
diff changeset
179 void clear_range (idx_t beg, idx_t end);
a61af66fc99e Initial load
duke
parents:
diff changeset
180 void set_large_range (idx_t beg, idx_t end);
a61af66fc99e Initial load
duke
parents:
diff changeset
181 void clear_large_range (idx_t beg, idx_t end);
a61af66fc99e Initial load
duke
parents:
diff changeset
182 void at_put_range(idx_t beg, idx_t end, bool value);
a61af66fc99e Initial load
duke
parents:
diff changeset
183 void par_at_put_range(idx_t beg, idx_t end, bool value);
a61af66fc99e Initial load
duke
parents:
diff changeset
184 void at_put_large_range(idx_t beg, idx_t end, bool value);
a61af66fc99e Initial load
duke
parents:
diff changeset
185 void par_at_put_large_range(idx_t beg, idx_t end, bool value);
a61af66fc99e Initial load
duke
parents:
diff changeset
186
a61af66fc99e Initial load
duke
parents:
diff changeset
187 // Update a range of bits, using a hint about the size. Currently only
a61af66fc99e Initial load
duke
parents:
diff changeset
188 // inlines the predominant case of a 1-bit range. Works best when hint is a
a61af66fc99e Initial load
duke
parents:
diff changeset
189 // compile-time constant.
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
190 void set_range(idx_t beg, idx_t end, RangeSizeHint hint);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
191 void clear_range(idx_t beg, idx_t end, RangeSizeHint hint);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
192 void par_set_range(idx_t beg, idx_t end, RangeSizeHint hint);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
193 void par_clear_range (idx_t beg, idx_t end, RangeSizeHint hint);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
194
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
195 // It performs the union operation between subsets of equal length
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
196 // of two bitmaps (the target bitmap of the method and the
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
197 // from_bitmap) and stores the result to the target bitmap. The
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
198 // from_start_index represents the first bit index of the subrange
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
199 // of the from_bitmap. The to_start_index is the equivalent of the
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
200 // target bitmap. Both indexes should be word-aligned, i.e. they
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
201 // should correspond to the first bit on a bitmap word (it's up to
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
202 // the caller to ensure this; the method does check it). The length
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
203 // of the subset is specified with word_num and it is in number of
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
204 // bitmap words. The caller should ensure that this is at least 2
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
205 // (smaller ranges are not support to save extra checks). Again,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
206 // this is checked in the method.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
207 //
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
208 // Atomicity concerns: it is assumed that any contention on the
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
209 // target bitmap with other threads will happen on the first and
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
210 // last words; the ones in between will be "owned" exclusively by
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
211 // the calling thread and, in fact, they will already be 0. So, the
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
212 // method performs a CAS on the first word, copies the next
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
213 // word_num-2 words, and finally performs a CAS on the last word.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
214 void mostly_disjoint_range_union(BitMap* from_bitmap,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
215 idx_t from_start_index,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
216 idx_t to_start_index,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
217 size_t word_num);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
218
0
a61af66fc99e Initial load
duke
parents:
diff changeset
219
a61af66fc99e Initial load
duke
parents:
diff changeset
220 // Clearing
a61af66fc99e Initial load
duke
parents:
diff changeset
221 void clear_large();
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
222 inline void clear();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
223
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
224 // Iteration support. Returns "true" if the iteration completed, false
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
225 // if the iteration terminated early (because the closure "blk" returned
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
226 // false).
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
227 bool iterate(BitMapClosure* blk, idx_t leftIndex, idx_t rightIndex);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
228 bool iterate(BitMapClosure* blk) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
229 // call the version that takes an interval
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
230 return iterate(blk, 0, size());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
231 }
a61af66fc99e Initial load
duke
parents:
diff changeset
232
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
233 // Looking for 1's and 0's at indices equal to or greater than "l_index",
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
234 // stopping if none has been found before "r_index", and returning
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
235 // "r_index" (which must be at most "size") in that case.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
236 idx_t get_next_one_offset_inline (idx_t l_index, idx_t r_index) const;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
237 idx_t get_next_zero_offset_inline(idx_t l_index, idx_t r_index) const;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
238
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
239 // Like "get_next_one_offset_inline", except requires that "r_index" is
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
240 // aligned to bitsizeof(bm_word_t).
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
241 idx_t get_next_one_offset_inline_aligned_right(idx_t l_index,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
242 idx_t r_index) const;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
243
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
244 // Non-inline versionsof the above.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
245 idx_t get_next_one_offset (idx_t l_index, idx_t r_index) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
246 idx_t get_next_zero_offset(idx_t l_index, idx_t r_index) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
247
a61af66fc99e Initial load
duke
parents:
diff changeset
248 idx_t get_next_one_offset(idx_t offset) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
249 return get_next_one_offset(offset, size());
a61af66fc99e Initial load
duke
parents:
diff changeset
250 }
a61af66fc99e Initial load
duke
parents:
diff changeset
251 idx_t get_next_zero_offset(idx_t offset) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
252 return get_next_zero_offset(offset, size());
a61af66fc99e Initial load
duke
parents:
diff changeset
253 }
a61af66fc99e Initial load
duke
parents:
diff changeset
254
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
255 // Returns the number of bits set in the bitmap.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
256 idx_t count_one_bits() const;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
257
a61af66fc99e Initial load
duke
parents:
diff changeset
258 // Set operations.
a61af66fc99e Initial load
duke
parents:
diff changeset
259 void set_union(BitMap bits);
a61af66fc99e Initial load
duke
parents:
diff changeset
260 void set_difference(BitMap bits);
a61af66fc99e Initial load
duke
parents:
diff changeset
261 void set_intersection(BitMap bits);
a61af66fc99e Initial load
duke
parents:
diff changeset
262 // Returns true iff "this" is a superset of "bits".
a61af66fc99e Initial load
duke
parents:
diff changeset
263 bool contains(const BitMap bits) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
264 // Returns true iff "this and "bits" have a non-empty intersection.
a61af66fc99e Initial load
duke
parents:
diff changeset
265 bool intersects(const BitMap bits) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
266
a61af66fc99e Initial load
duke
parents:
diff changeset
267 // Returns result of whether this map changed
a61af66fc99e Initial load
duke
parents:
diff changeset
268 // during the operation
a61af66fc99e Initial load
duke
parents:
diff changeset
269 bool set_union_with_result(BitMap bits);
a61af66fc99e Initial load
duke
parents:
diff changeset
270 bool set_difference_with_result(BitMap bits);
a61af66fc99e Initial load
duke
parents:
diff changeset
271 bool set_intersection_with_result(BitMap bits);
a61af66fc99e Initial load
duke
parents:
diff changeset
272
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
273 // Requires the submap of "bits" starting at offset to be at least as
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
274 // large as "this". Modifies "this" to be the intersection of its
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
275 // current contents and the submap of "bits" starting at "offset" of the
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
276 // same length as "this."
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
277 // (For expedience, currently requires the offset to be aligned to the
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
278 // bitsize of a uintptr_t. This should go away in the future though it
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
279 // will probably remain a good case to optimize.)
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
280 void set_intersection_at_offset(BitMap bits, idx_t offset);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
281
0
a61af66fc99e Initial load
duke
parents:
diff changeset
282 void set_from(BitMap bits);
a61af66fc99e Initial load
duke
parents:
diff changeset
283
a61af66fc99e Initial load
duke
parents:
diff changeset
284 bool is_same(BitMap bits);
a61af66fc99e Initial load
duke
parents:
diff changeset
285
a61af66fc99e Initial load
duke
parents:
diff changeset
286 // Test if all bits are set or cleared
a61af66fc99e Initial load
duke
parents:
diff changeset
287 bool is_full() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
288 bool is_empty() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
289
a61af66fc99e Initial load
duke
parents:
diff changeset
290
a61af66fc99e Initial load
duke
parents:
diff changeset
291 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
292 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
293 // Printing
a61af66fc99e Initial load
duke
parents:
diff changeset
294 void print_on(outputStream* st) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
295 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
296 };
a61af66fc99e Initial load
duke
parents:
diff changeset
297
a61af66fc99e Initial load
duke
parents:
diff changeset
298 // Convenience class wrapping BitMap which provides multiple bits per slot.
a61af66fc99e Initial load
duke
parents:
diff changeset
299 class BitMap2D VALUE_OBJ_CLASS_SPEC {
a61af66fc99e Initial load
duke
parents:
diff changeset
300 public:
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
301 typedef BitMap::idx_t idx_t; // Type used for bit and word indices.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
302 typedef BitMap::bm_word_t bm_word_t; // Element type of array that
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
303 // represents the bitmap.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
304 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
305 BitMap _map;
a61af66fc99e Initial load
duke
parents:
diff changeset
306 idx_t _bits_per_slot;
a61af66fc99e Initial load
duke
parents:
diff changeset
307
a61af66fc99e Initial load
duke
parents:
diff changeset
308 idx_t bit_index(idx_t slot_index, idx_t bit_within_slot_index) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
309 return slot_index * _bits_per_slot + bit_within_slot_index;
a61af66fc99e Initial load
duke
parents:
diff changeset
310 }
a61af66fc99e Initial load
duke
parents:
diff changeset
311
a61af66fc99e Initial load
duke
parents:
diff changeset
312 void verify_bit_within_slot_index(idx_t index) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
313 assert(index < _bits_per_slot, "bit_within_slot index out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
314 }
a61af66fc99e Initial load
duke
parents:
diff changeset
315
a61af66fc99e Initial load
duke
parents:
diff changeset
316 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
317 // Construction. bits_per_slot must be greater than 0.
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
318 BitMap2D(bm_word_t* map, idx_t size_in_slots, idx_t bits_per_slot);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
319
a61af66fc99e Initial load
duke
parents:
diff changeset
320 // Allocates necessary data structure in resource area. bits_per_slot must be greater than 0.
a61af66fc99e Initial load
duke
parents:
diff changeset
321 BitMap2D(idx_t size_in_slots, idx_t bits_per_slot);
a61af66fc99e Initial load
duke
parents:
diff changeset
322
a61af66fc99e Initial load
duke
parents:
diff changeset
323 idx_t size_in_bits() {
a61af66fc99e Initial load
duke
parents:
diff changeset
324 return _map.size();
a61af66fc99e Initial load
duke
parents:
diff changeset
325 }
a61af66fc99e Initial load
duke
parents:
diff changeset
326
a61af66fc99e Initial load
duke
parents:
diff changeset
327 // Returns number of full slots that have been allocated
a61af66fc99e Initial load
duke
parents:
diff changeset
328 idx_t size_in_slots() {
a61af66fc99e Initial load
duke
parents:
diff changeset
329 // Round down
a61af66fc99e Initial load
duke
parents:
diff changeset
330 return _map.size() / _bits_per_slot;
a61af66fc99e Initial load
duke
parents:
diff changeset
331 }
a61af66fc99e Initial load
duke
parents:
diff changeset
332
a61af66fc99e Initial load
duke
parents:
diff changeset
333 bool is_valid_index(idx_t slot_index, idx_t bit_within_slot_index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
334 verify_bit_within_slot_index(bit_within_slot_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
335 return (bit_index(slot_index, bit_within_slot_index) < size_in_bits());
a61af66fc99e Initial load
duke
parents:
diff changeset
336 }
a61af66fc99e Initial load
duke
parents:
diff changeset
337
a61af66fc99e Initial load
duke
parents:
diff changeset
338 bool at(idx_t slot_index, idx_t bit_within_slot_index) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
339 verify_bit_within_slot_index(bit_within_slot_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
340 return _map.at(bit_index(slot_index, bit_within_slot_index));
a61af66fc99e Initial load
duke
parents:
diff changeset
341 }
a61af66fc99e Initial load
duke
parents:
diff changeset
342
a61af66fc99e Initial load
duke
parents:
diff changeset
343 void set_bit(idx_t slot_index, idx_t bit_within_slot_index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
344 verify_bit_within_slot_index(bit_within_slot_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
345 _map.set_bit(bit_index(slot_index, bit_within_slot_index));
a61af66fc99e Initial load
duke
parents:
diff changeset
346 }
a61af66fc99e Initial load
duke
parents:
diff changeset
347
a61af66fc99e Initial load
duke
parents:
diff changeset
348 void clear_bit(idx_t slot_index, idx_t bit_within_slot_index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
349 verify_bit_within_slot_index(bit_within_slot_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
350 _map.clear_bit(bit_index(slot_index, bit_within_slot_index));
a61af66fc99e Initial load
duke
parents:
diff changeset
351 }
a61af66fc99e Initial load
duke
parents:
diff changeset
352
a61af66fc99e Initial load
duke
parents:
diff changeset
353 void at_put(idx_t slot_index, idx_t bit_within_slot_index, bool value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
354 verify_bit_within_slot_index(bit_within_slot_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
355 _map.at_put(bit_index(slot_index, bit_within_slot_index), value);
a61af66fc99e Initial load
duke
parents:
diff changeset
356 }
a61af66fc99e Initial load
duke
parents:
diff changeset
357
a61af66fc99e Initial load
duke
parents:
diff changeset
358 void at_put_grow(idx_t slot_index, idx_t bit_within_slot_index, bool value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
359 verify_bit_within_slot_index(bit_within_slot_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
360 _map.at_put_grow(bit_index(slot_index, bit_within_slot_index), value);
a61af66fc99e Initial load
duke
parents:
diff changeset
361 }
a61af66fc99e Initial load
duke
parents:
diff changeset
362
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
363 void clear();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
364 };
a61af66fc99e Initial load
duke
parents:
diff changeset
365
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
366 // Closure for iterating over BitMaps
0
a61af66fc99e Initial load
duke
parents:
diff changeset
367
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
368 class BitMapClosure VALUE_OBJ_CLASS_SPEC {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
369 public:
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
370 // Callback when bit in map is set. Should normally return "true";
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
371 // return of false indicates that the bitmap iteration should terminate.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
372 virtual bool do_bit(BitMap::idx_t offset) = 0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
373 };
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
374
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
375 #endif // SHARE_VM_UTILITIES_BITMAP_HPP