annotate src/share/vm/utilities/bitMap.inline.hpp @ 113:ba764ed4b6f2

6420645: Create a vm that uses compressed oops for up to 32gb heapsizes Summary: Compressed oops in instances, arrays, and headers. Code contributors are coleenp, phh, never, swamyv Reviewed-by: jmasa, kamg, acorn, tbell, kvn, rasbold
author coleenp
date Sun, 13 Apr 2008 17:43:42 -0400
parents a61af66fc99e
children 37f87013dfd8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved.
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 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 inline bool BitMap::par_set_bit(idx_t bit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
26 verify_index(bit);
a61af66fc99e Initial load
duke
parents:
diff changeset
27 volatile idx_t* const addr = word_addr(bit);
a61af66fc99e Initial load
duke
parents:
diff changeset
28 const idx_t mask = bit_mask(bit);
a61af66fc99e Initial load
duke
parents:
diff changeset
29 idx_t old_val = *addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
32 const idx_t new_val = old_val | mask;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 if (new_val == old_val) {
a61af66fc99e Initial load
duke
parents:
diff changeset
34 return false; // Someone else beat us to it.
a61af66fc99e Initial load
duke
parents:
diff changeset
35 }
a61af66fc99e Initial load
duke
parents:
diff changeset
36 const idx_t cur_val = (idx_t) Atomic::cmpxchg_ptr((void*) new_val,
a61af66fc99e Initial load
duke
parents:
diff changeset
37 (volatile void*) addr,
a61af66fc99e Initial load
duke
parents:
diff changeset
38 (void*) old_val);
a61af66fc99e Initial load
duke
parents:
diff changeset
39 if (cur_val == old_val) {
a61af66fc99e Initial load
duke
parents:
diff changeset
40 return true; // Success.
a61af66fc99e Initial load
duke
parents:
diff changeset
41 }
a61af66fc99e Initial load
duke
parents:
diff changeset
42 old_val = cur_val; // The value changed, try again.
a61af66fc99e Initial load
duke
parents:
diff changeset
43 } while (true);
a61af66fc99e Initial load
duke
parents:
diff changeset
44 }
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 inline bool BitMap::par_clear_bit(idx_t bit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
47 verify_index(bit);
a61af66fc99e Initial load
duke
parents:
diff changeset
48 volatile idx_t* const addr = word_addr(bit);
a61af66fc99e Initial load
duke
parents:
diff changeset
49 const idx_t mask = ~bit_mask(bit);
a61af66fc99e Initial load
duke
parents:
diff changeset
50 idx_t old_val = *addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 const idx_t new_val = old_val & mask;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 if (new_val == old_val) {
a61af66fc99e Initial load
duke
parents:
diff changeset
55 return false; // Someone else beat us to it.
a61af66fc99e Initial load
duke
parents:
diff changeset
56 }
a61af66fc99e Initial load
duke
parents:
diff changeset
57 const idx_t cur_val = (idx_t) Atomic::cmpxchg_ptr((void*) new_val,
a61af66fc99e Initial load
duke
parents:
diff changeset
58 (volatile void*) addr,
a61af66fc99e Initial load
duke
parents:
diff changeset
59 (void*) old_val);
a61af66fc99e Initial load
duke
parents:
diff changeset
60 if (cur_val == old_val) {
a61af66fc99e Initial load
duke
parents:
diff changeset
61 return true; // Success.
a61af66fc99e Initial load
duke
parents:
diff changeset
62 }
a61af66fc99e Initial load
duke
parents:
diff changeset
63 old_val = cur_val; // The value changed, try again.
a61af66fc99e Initial load
duke
parents:
diff changeset
64 } while (true);
a61af66fc99e Initial load
duke
parents:
diff changeset
65 }
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 inline BitMap::idx_t
a61af66fc99e Initial load
duke
parents:
diff changeset
68 BitMap::find_next_one_bit(idx_t beg_bit, idx_t end_bit) const
a61af66fc99e Initial load
duke
parents:
diff changeset
69 {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 verify_range(beg_bit, end_bit);
a61af66fc99e Initial load
duke
parents:
diff changeset
71 assert(bit_in_word(end_bit) == 0, "end_bit not word-aligned");
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73 if (beg_bit == end_bit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 return beg_bit;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 idx_t index = word_index(beg_bit);
a61af66fc99e Initial load
duke
parents:
diff changeset
78 idx_t r_index = word_index(end_bit);
a61af66fc99e Initial load
duke
parents:
diff changeset
79 idx_t res_bit = beg_bit;
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // check bits including and to the _left_ of offset's position
a61af66fc99e Initial load
duke
parents:
diff changeset
82 idx_t res = map(index) >> bit_in_word(res_bit);
a61af66fc99e Initial load
duke
parents:
diff changeset
83 if (res != (uintptr_t) NoBits) {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // find the position of the 1-bit
a61af66fc99e Initial load
duke
parents:
diff changeset
85 for (; !(res & 1); res_bit++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 res = res >> 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
87 }
a61af66fc99e Initial load
duke
parents:
diff changeset
88 assert(res_bit >= beg_bit && res_bit < end_bit, "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
89 return res_bit;
a61af66fc99e Initial load
duke
parents:
diff changeset
90 }
a61af66fc99e Initial load
duke
parents:
diff changeset
91 // skip over all word length 0-bit runs
a61af66fc99e Initial load
duke
parents:
diff changeset
92 for (index++; index < r_index; index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 res = map(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
94 if (res != (uintptr_t) NoBits) {
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // found a 1, return the offset
a61af66fc99e Initial load
duke
parents:
diff changeset
96 for (res_bit = bit_index(index); !(res & 1); res_bit++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 res = res >> 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99 assert(res & 1, "tautology; see loop condition");
a61af66fc99e Initial load
duke
parents:
diff changeset
100 assert(res_bit >= beg_bit && res_bit < end_bit, "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
101 return res_bit;
a61af66fc99e Initial load
duke
parents:
diff changeset
102 }
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104 return end_bit;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 }