Tue, 11 May 2010 14:35:43 -0700
6931180: Migration to recent versions of MS Platform SDK
6951582: Build problems on win64
Summary: Changes to enable building JDK7 with Microsoft Visual Studio 2010
Reviewed-by: ohair, art, ccheung, dcubed
1 /*
2 * Copyright 2005-2009 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
25 #ifdef ASSERT
26 inline void BitMap::verify_index(idx_t index) const {
27 assert(index < _size, "BitMap index out of bounds");
28 }
30 inline void BitMap::verify_range(idx_t beg_index, idx_t end_index) const {
31 assert(beg_index <= end_index, "BitMap range error");
32 // Note that [0,0) and [size,size) are both valid ranges.
33 if (end_index != _size) verify_index(end_index);
34 }
35 #endif // #ifdef ASSERT
37 inline void BitMap::set_bit(idx_t bit) {
38 verify_index(bit);
39 *word_addr(bit) |= bit_mask(bit);
40 }
42 inline void BitMap::clear_bit(idx_t bit) {
43 verify_index(bit);
44 *word_addr(bit) &= ~bit_mask(bit);
45 }
47 inline bool BitMap::par_set_bit(idx_t bit) {
48 verify_index(bit);
49 volatile idx_t* const addr = word_addr(bit);
50 const idx_t mask = bit_mask(bit);
51 idx_t old_val = *addr;
53 do {
54 const idx_t new_val = old_val | mask;
55 if (new_val == old_val) {
56 return false; // Someone else beat us to it.
57 }
58 const idx_t cur_val = (idx_t) Atomic::cmpxchg_ptr((void*) new_val,
59 (volatile void*) addr,
60 (void*) old_val);
61 if (cur_val == old_val) {
62 return true; // Success.
63 }
64 old_val = cur_val; // The value changed, try again.
65 } while (true);
66 }
68 inline bool BitMap::par_clear_bit(idx_t bit) {
69 verify_index(bit);
70 volatile idx_t* const addr = word_addr(bit);
71 const idx_t mask = ~bit_mask(bit);
72 idx_t old_val = *addr;
74 do {
75 const idx_t new_val = old_val & mask;
76 if (new_val == old_val) {
77 return false; // Someone else beat us to it.
78 }
79 const idx_t cur_val = (idx_t) Atomic::cmpxchg_ptr((void*) new_val,
80 (volatile void*) addr,
81 (void*) old_val);
82 if (cur_val == old_val) {
83 return true; // Success.
84 }
85 old_val = cur_val; // The value changed, try again.
86 } while (true);
87 }
89 inline void BitMap::set_range(idx_t beg, idx_t end, RangeSizeHint hint) {
90 if (hint == small_range && end - beg == 1) {
91 set_bit(beg);
92 } else {
93 if (hint == large_range) {
94 set_large_range(beg, end);
95 } else {
96 set_range(beg, end);
97 }
98 }
99 }
101 inline void BitMap::clear_range(idx_t beg, idx_t end, RangeSizeHint hint) {
102 if (hint == small_range && end - beg == 1) {
103 clear_bit(beg);
104 } else {
105 if (hint == large_range) {
106 clear_large_range(beg, end);
107 } else {
108 clear_range(beg, end);
109 }
110 }
111 }
113 inline void BitMap::par_set_range(idx_t beg, idx_t end, RangeSizeHint hint) {
114 if (hint == small_range && end - beg == 1) {
115 par_at_put(beg, true);
116 } else {
117 if (hint == large_range) {
118 par_at_put_large_range(beg, end, true);
119 } else {
120 par_at_put_range(beg, end, true);
121 }
122 }
123 }
125 inline void BitMap::set_range_of_words(idx_t beg, idx_t end) {
126 bm_word_t* map = _map;
127 for (idx_t i = beg; i < end; ++i) map[i] = ~(uintptr_t)0;
128 }
131 inline void BitMap::clear_range_of_words(idx_t beg, idx_t end) {
132 bm_word_t* map = _map;
133 for (idx_t i = beg; i < end; ++i) map[i] = 0;
134 }
137 inline void BitMap::clear() {
138 clear_range_of_words(0, size_in_words());
139 }
142 inline void BitMap::par_clear_range(idx_t beg, idx_t end, RangeSizeHint hint) {
143 if (hint == small_range && end - beg == 1) {
144 par_at_put(beg, false);
145 } else {
146 if (hint == large_range) {
147 par_at_put_large_range(beg, end, false);
148 } else {
149 par_at_put_range(beg, end, false);
150 }
151 }
152 }
154 inline BitMap::idx_t
155 BitMap::get_next_one_offset_inline(idx_t l_offset, idx_t r_offset) const {
156 assert(l_offset <= size(), "BitMap index out of bounds");
157 assert(r_offset <= size(), "BitMap index out of bounds");
158 assert(l_offset <= r_offset, "l_offset > r_offset ?");
160 if (l_offset == r_offset) {
161 return l_offset;
162 }
163 idx_t index = word_index(l_offset);
164 idx_t r_index = word_index(r_offset-1) + 1;
165 idx_t res_offset = l_offset;
167 // check bits including and to the _left_ of offset's position
168 idx_t pos = bit_in_word(res_offset);
169 idx_t res = map(index) >> pos;
170 if (res != (uintptr_t)NoBits) {
171 // find the position of the 1-bit
172 for (; !(res & 1); res_offset++) {
173 res = res >> 1;
174 }
175 assert(res_offset >= l_offset &&
176 res_offset < r_offset, "just checking");
177 return MIN2(res_offset, r_offset);
178 }
179 // skip over all word length 0-bit runs
180 for (index++; index < r_index; index++) {
181 res = map(index);
182 if (res != (uintptr_t)NoBits) {
183 // found a 1, return the offset
184 for (res_offset = bit_index(index); !(res & 1); res_offset++) {
185 res = res >> 1;
186 }
187 assert(res & 1, "tautology; see loop condition");
188 assert(res_offset >= l_offset, "just checking");
189 return MIN2(res_offset, r_offset);
190 }
191 }
192 return r_offset;
193 }
195 inline BitMap::idx_t
196 BitMap::get_next_zero_offset_inline(idx_t l_offset, idx_t r_offset) const {
197 assert(l_offset <= size(), "BitMap index out of bounds");
198 assert(r_offset <= size(), "BitMap index out of bounds");
199 assert(l_offset <= r_offset, "l_offset > r_offset ?");
201 if (l_offset == r_offset) {
202 return l_offset;
203 }
204 idx_t index = word_index(l_offset);
205 idx_t r_index = word_index(r_offset-1) + 1;
206 idx_t res_offset = l_offset;
208 // check bits including and to the _left_ of offset's position
209 idx_t pos = res_offset & (BitsPerWord - 1);
210 idx_t res = (map(index) >> pos) | left_n_bits((int)pos);
212 if (res != (uintptr_t)AllBits) {
213 // find the position of the 0-bit
214 for (; res & 1; res_offset++) {
215 res = res >> 1;
216 }
217 assert(res_offset >= l_offset, "just checking");
218 return MIN2(res_offset, r_offset);
219 }
220 // skip over all word length 1-bit runs
221 for (index++; index < r_index; index++) {
222 res = map(index);
223 if (res != (uintptr_t)AllBits) {
224 // found a 0, return the offset
225 for (res_offset = index << LogBitsPerWord; res & 1;
226 res_offset++) {
227 res = res >> 1;
228 }
229 assert(!(res & 1), "tautology; see loop condition");
230 assert(res_offset >= l_offset, "just checking");
231 return MIN2(res_offset, r_offset);
232 }
233 }
234 return r_offset;
235 }
237 inline BitMap::idx_t
238 BitMap::get_next_one_offset_inline_aligned_right(idx_t l_offset,
239 idx_t r_offset) const
240 {
241 verify_range(l_offset, r_offset);
242 assert(bit_in_word(r_offset) == 0, "r_offset not word-aligned");
244 if (l_offset == r_offset) {
245 return l_offset;
246 }
247 idx_t index = word_index(l_offset);
248 idx_t r_index = word_index(r_offset);
249 idx_t res_offset = l_offset;
251 // check bits including and to the _left_ of offset's position
252 idx_t res = map(index) >> bit_in_word(res_offset);
253 if (res != (uintptr_t)NoBits) {
254 // find the position of the 1-bit
255 for (; !(res & 1); res_offset++) {
256 res = res >> 1;
257 }
258 assert(res_offset >= l_offset &&
259 res_offset < r_offset, "just checking");
260 return res_offset;
261 }
262 // skip over all word length 0-bit runs
263 for (index++; index < r_index; index++) {
264 res = map(index);
265 if (res != (uintptr_t)NoBits) {
266 // found a 1, return the offset
267 for (res_offset = bit_index(index); !(res & 1); res_offset++) {
268 res = res >> 1;
269 }
270 assert(res & 1, "tautology; see loop condition");
271 assert(res_offset >= l_offset && res_offset < r_offset, "just checking");
272 return res_offset;
273 }
274 }
275 return r_offset;
276 }
279 // Returns a bit mask for a range of bits [beg, end) within a single word. Each
280 // bit in the mask is 0 if the bit is in the range, 1 if not in the range. The
281 // returned mask can be used directly to clear the range, or inverted to set the
282 // range. Note: end must not be 0.
283 inline BitMap::bm_word_t
284 BitMap::inverted_bit_mask_for_range(idx_t beg, idx_t end) const {
285 assert(end != 0, "does not work when end == 0");
286 assert(beg == end || word_index(beg) == word_index(end - 1),
287 "must be a single-word range");
288 bm_word_t mask = bit_mask(beg) - 1; // low (right) bits
289 if (bit_in_word(end) != 0) {
290 mask |= ~(bit_mask(end) - 1); // high (left) bits
291 }
292 return mask;
293 }
295 inline void BitMap::set_large_range_of_words(idx_t beg, idx_t end) {
296 memset(_map + beg, ~(unsigned char)0, (end - beg) * sizeof(uintptr_t));
297 }
299 inline void BitMap::clear_large_range_of_words(idx_t beg, idx_t end) {
300 memset(_map + beg, 0, (end - beg) * sizeof(uintptr_t));
301 }
303 inline BitMap::idx_t BitMap::word_index_round_up(idx_t bit) const {
304 idx_t bit_rounded_up = bit + (BitsPerWord - 1);
305 // Check for integer arithmetic overflow.
306 return bit_rounded_up > bit ? word_index(bit_rounded_up) : size_in_words();
307 }
309 inline BitMap::idx_t BitMap::get_next_one_offset(idx_t l_offset,
310 idx_t r_offset) const {
311 return get_next_one_offset_inline(l_offset, r_offset);
312 }
314 inline BitMap::idx_t BitMap::get_next_zero_offset(idx_t l_offset,
315 idx_t r_offset) const {
316 return get_next_zero_offset_inline(l_offset, r_offset);
317 }
319 inline void BitMap2D::clear() {
320 _map.clear();
321 }