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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_GC_G1_G1CARDTABLE_INLINE_HPP
26 #define SHARE_GC_G1_G1CARDTABLE_INLINE_HPP
27
28 #include "gc/g1/g1CardTable.hpp"
29 #include "gc/g1/heapRegion.hpp"
30
31 inline uint G1CardTable::region_idx_for(CardValue* p) {
32 size_t const card_idx = pointer_delta(p, _byte_map, sizeof(CardValue));
33 return (uint)(card_idx >> (HeapRegion::LogOfHRGrainBytes - card_shift));
34 }
35
36 inline void G1CardTable::mark_clean_as_dirty(size_t card_index) {
37 CardValue value = _byte_map[card_index];
38 if (value == clean_card_val()) {
39 _byte_map[card_index] = dirty_card_val();
40 }
41 }
42
43 inline void G1CardTable::mark_region_dirty(size_t start_card_index, size_t num_cards) {
44 assert(is_aligned(start_card_index, sizeof(size_t)), "Start card index must be aligned.");
45 assert(is_aligned(num_cards, sizeof(size_t)), "Number of cards to change must be evenly divisible.");
46
47 size_t const num_chunks = num_cards / sizeof(size_t);
48
49 size_t* cur_word = (size_t*)&_byte_map[start_card_index];
50 size_t* const end_word_map = cur_word + num_chunks;
51 while (cur_word < end_word_map) {
52 size_t value = *cur_word;
53 if (value == WordAllClean) {
54 *cur_word = WordAllDirty;
55 } else if (value == WordAllDirty) {
56 // do nothing.
57 } else {
58 // There is a mix of cards in there. Tread slowly.
59 CardValue* cur = (CardValue*)cur_word;
60 for (size_t i = 0; i < sizeof(size_t); i++) {
61 CardValue value = *cur;
62 if (value == clean_card_val()) {
63 *cur = dirty_card_val();
64 }
65 cur++;
66 }
67 }
68 cur_word++;
69 }
70 }
71
72 inline void G1CardTable::mark_as_scanned(size_t start_card_index, size_t num_cards) {
73 CardValue* start = &_byte_map[start_card_index];
74 CardValue* const end = start + num_cards;
75 while (start < end) {
76 CardValue value = *start;
77 assert(value == dirty_card_val(),
78 "Must have been dirty %d start " PTR_FORMAT " " PTR_FORMAT, value, p2i(start), p2i(end));
79 *start++ = g1_card_already_scanned;
80 }
81 }
82
83 #endif /* SHARE_GC_G1_G1CARDTABLE_INLINE_HPP */
|
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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_GC_G1_G1CARDTABLE_INLINE_HPP
26 #define SHARE_GC_G1_G1CARDTABLE_INLINE_HPP
27
28 #include "gc/g1/g1CardTable.hpp"
29 #include "gc/g1/heapRegion.hpp"
30
31 inline uint G1CardTable::region_idx_for(CardValue* p) {
32 size_t const card_idx = pointer_delta(p, _byte_map, sizeof(CardValue));
33 return (uint)(card_idx >> (HeapRegion::LogOfHRGrainBytes - card_shift));
34 }
35
36 inline size_t G1CardTable::mark_clean_as_dirty(size_t card_index) {
37 CardValue value = _byte_map[card_index];
38 if (value == clean_card_val()) {
39 _byte_map[card_index] = dirty_card_val();
40 return 1;
41 }
42 return 0;
43 }
44
45 inline size_t G1CardTable::mark_region_dirty(size_t start_card_index, size_t num_cards) {
46 assert(is_aligned(start_card_index, sizeof(size_t)), "Start card index must be aligned.");
47 assert(is_aligned(num_cards, sizeof(size_t)), "Number of cards to change must be evenly divisible.");
48
49 size_t result = 0;
50
51 size_t const num_chunks = num_cards / sizeof(size_t);
52
53 size_t* cur_word = (size_t*)&_byte_map[start_card_index];
54 size_t* const end_word_map = cur_word + num_chunks;
55 while (cur_word < end_word_map) {
56 size_t value = *cur_word;
57 if (value == WordAllClean) {
58 *cur_word = WordAllDirty;
59 result += sizeof(value);
60 } else if (value == WordAllDirty) {
61 // do nothing.
62 } else {
63 // There is a mix of cards in there. Tread slowly.
64 CardValue* cur = (CardValue*)cur_word;
65 for (size_t i = 0; i < sizeof(size_t); i++) {
66 CardValue value = *cur;
67 if (value == clean_card_val()) {
68 *cur = dirty_card_val();
69 result++;
70 }
71 cur++;
72 }
73 }
74 cur_word++;
75 }
76
77 return result;
78 }
79
80 inline void G1CardTable::mark_as_scanned(size_t start_card_index, size_t num_cards) {
81 CardValue* start = &_byte_map[start_card_index];
82 CardValue* const end = start + num_cards;
83 while (start < end) {
84 CardValue value = *start;
85 assert(value == dirty_card_val(),
86 "Must have been dirty %d start " PTR_FORMAT " " PTR_FORMAT, value, p2i(start), p2i(end));
87 *start++ = g1_card_already_scanned;
88 }
89 }
90
91 #endif /* SHARE_GC_G1_G1CARDTABLE_INLINE_HPP */
|